From b0bf0ec03618b6141d196dd61844ed2a7afc9629 Mon Sep 17 00:00:00 2001 From: Aiteron Date: Tue, 23 Nov 2021 14:36:29 +0500 Subject: [PATCH 01/13] ModNewsAPI --- .../media/lua/client/CommunityAPI.lua | 1 + .../lua/client/ModNewsAPI/LoadModNewsData.lua | 28 +++ .../client/ModNewsAPI/ModNewsAPIClient.lua | 23 +++ .../lua/client/ModNewsAPI/ModNewsButton.lua | 68 +++++++ .../lua/client/ModNewsAPI/ModNewsPanel.lua | 177 ++++++++++++++++++ .../media/ui/ModNews/notifyIcon.png | Bin 0 -> 8909 bytes 6 files changed, 297 insertions(+) create mode 100644 Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/LoadModNewsData.lua create mode 100644 Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua create mode 100644 Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsButton.lua create mode 100644 Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua create mode 100644 Contents/mods/CommunityAPI/media/ui/ModNews/notifyIcon.png diff --git a/Contents/mods/CommunityAPI/media/lua/client/CommunityAPI.lua b/Contents/mods/CommunityAPI/media/lua/client/CommunityAPI.lua index bbf3e78..bc5b118 100644 --- a/Contents/mods/CommunityAPI/media/lua/client/CommunityAPI.lua +++ b/Contents/mods/CommunityAPI/media/lua/client/CommunityAPI.lua @@ -3,6 +3,7 @@ require("CommunityAPIShared") CommunityAPI.Client = { ItemTooltip = require("ItemTooltipAPI/ItemTooltipAPIClient"), Light = require("LightAPI/LightAPIClient"), + ModNews = require("ModNewsAPI/ModNewsAPIClient"), ModSetting = require("ModSettingAPI/ModSettingAPIClient"), Spawner = require("SpawnerAPI/SpawnerAPIClient"), WorldSound = require("WorldSoundAPI/WorldSoundAPIClient"), diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/LoadModNewsData.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/LoadModNewsData.lua new file mode 100644 index 0000000..a9d9d7a --- /dev/null +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/LoadModNewsData.lua @@ -0,0 +1,28 @@ +require("CommunityAPI") +local ModNewsAPI = CommunityAPI.Client.ModNews +local JsonAPI = CommunityAPI.Utils.Json + +local function ModNewsAPILoadData() + local fileReader = getFileReader("CAPI_modNewsData.txt", true) + if not fileReader then return end + local line = fileReader:readLine() + local modNewsData = nil + if line ~= nil then + modNewsData = JsonAPI.Decode(line) + end + fileReader:close() + + if modNewsData ~= nil and type(modNewsData) == "table" then + for modID, modData in pairs(modNewsData) do + for articleName, data in pairs(modData) do + if ModNewsAPI.Data[modID] ~= nil and ModNewsAPI.Data[modID][articleName] ~= nil then + if data.isViewed and data.lastUpdateDate == ModNewsAPI.Data[modID][articleName].lastUpdateDate then + ModNewsAPI.Data[modID][articleName].isViewed = true + end + end + end + end + end +end + +Events.OnGameBoot.Add(ModNewsAPILoadData) \ No newline at end of file diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua new file mode 100644 index 0000000..37cbd62 --- /dev/null +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua @@ -0,0 +1,23 @@ + +---@class ModNewsAPI +local ModNewsAPI = {} +ModNewsAPI.Data = {} + +---@param modID string +---@param articleName string +---@param articleTextName string Article text name from Translate +---@param lastUpdateDate string String with date of last update. If you changed article and want to notify that article updated - change this param +---@return nil +function ModNewsAPI.AddArticle(modID, articleName, articleTextName, lastUpdateDate) + if ModNewsAPI.Data[modID] == nil then + ModNewsAPI.Data[modID] = {} + end + ModNewsAPI.Data[modID][articleName] = {} + ModNewsAPI.Data[modID][articleName].modID = modID + ModNewsAPI.Data[modID][articleName].articleName = articleName + ModNewsAPI.Data[modID][articleName].articleTextName = articleTextName + ModNewsAPI.Data[modID][articleName].lastUpdateDate = lastUpdateDate + ModNewsAPI.Data[modID][articleName].isViewed = false +end + +return ModNewsAPI \ No newline at end of file diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsButton.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsButton.lua new file mode 100644 index 0000000..9d9457e --- /dev/null +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsButton.lua @@ -0,0 +1,68 @@ +require("CommunityAPI") +local ModNewsAPI = CommunityAPI.Client.ModNews + +local FONT_HGT_MEDIUM = getTextManager():getFontHeight(UIFont.Medium) + +local function renderModNewsButton(self) + ISButton.render(self) + + local isNewArticles = false + for _, modData in pairs(ModNewsAPI.Data) do + for _, articleData in pairs(modData) do + if articleData.isViewed == false then + isNewArticles = true + end + end + end + + if isNewArticles then + local x = - self.notifyIcon:getWidthOrig()/2 + self.width + local y = - self.notifyIcon:getHeightOrig()/2 - 2 + self:drawTexture(self.notifyIcon, x, y, 1, 1, 1, 1) + end +end + +local function onClickModNews(self) + local w = self.width * 0.8 + local h = self.height * 0.8 + local modNewsPanel = ModNewsPanel:new((self.width - w)/2, (self.height - h)/2, w, h) + modNewsPanel.backgroundColor = {r=0, g=0, b=0, a=0.95} + modNewsPanel.borderColor = {r=1, g=1, b=1, a=0.5} + modNewsPanel:initialise() + modNewsPanel:instantiate() + modNewsPanel:setCapture(true) + modNewsPanel:setAlwaysOnTop(true) + modNewsPanel:setAnchorRight(true) + modNewsPanel:setAnchorLeft(true) + modNewsPanel:setAnchorBottom(true) + modNewsPanel:setAnchorTop(true) + modNewsPanel:addToUIManager() +end + +-- Hook +local defaultMainScreen_instantiate = MainScreen.instantiate +function MainScreen:instantiate() + defaultMainScreen_instantiate(self) + + self.modNewsDetail = ISButton:new(self.width - 40 - 400, self.height - FONT_HGT_MEDIUM - 20, 120, FONT_HGT_MEDIUM + 1 * 2, getText("UI_modNews_button"), self, onClickModNews) + self.modNewsDetail.font = UIFont.Medium + self.modNewsDetail:initialise() + self.modNewsDetail.borderColor = {r=1, g=1, b=1, a=0.7} + self.modNewsDetail.textColor = {r=1, g=1, b=1, a=0.7} + self:addChild(self.modNewsDetail) + self.modNewsDetail:setAnchorLeft(false) + self.modNewsDetail:setAnchorTop(false) + self.modNewsDetail:setAnchorRight(true) + self.modNewsDetail:setAnchorBottom(true) + self.modNewsDetail.notifyIcon = getTexture("media/ui/ModNews/notifyIcon.png") + self.modNewsDetail.render = renderModNewsButton +end + +-- Hook +local defaultMainScreen_setBottomPanelVisible = MainScreen.setBottomPanelVisible +function MainScreen:setBottomPanelVisible(visible) + defaultMainScreen_setBottomPanelVisible(self, visible) + if self.parent and self.parent.modNewsDetail then + self.parent.modNewsDetail:setVisible(visible) + end +end \ No newline at end of file diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua new file mode 100644 index 0000000..2b864a8 --- /dev/null +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua @@ -0,0 +1,177 @@ +require("CommunityAPI") +local ModNewsAPI = CommunityAPI.Client.ModNews +local JsonAPI = CommunityAPI.Utils.Json + +ModNewsPanel = ISPanelJoypad:derive("ModNewsPanel") + +local FONT_HGT_SMALL = getTextManager():getFontHeight(UIFont.Small) +local FONT_HGT_MEDIUM = getTextManager():getFontHeight(UIFont.Medium) + +function ModNewsPanel:createChildren() + self.modListBox = ISScrollingListBox:new(25, 50, self.width*0.2, self.height - 100) + self.modListBox:initialise() + self.modListBox:instantiate() + self.modListBox:setFont(UIFont.Medium, 2) + self.modListBox:setAnchorLeft(true) + self.modListBox:setAnchorRight(true) + self.modListBox:setAnchorTop(true) + self.modListBox:setAnchorBottom(true) + self.modListBox.doDrawItem = self.modListBoxItemDraw + self.modListBox.drawBorder = true + self.modListBox:setOnMouseDownFunction(self, self.onModListClick) + self:addChild(self.modListBox) + + local lWid = getTextManager():MeasureStringX(UIFont.Medium, getText("UI_NewGame_Mods")) + self.modsLabel = ISLabel:new(25 + self.modListBox.width/2 - lWid/2, 16, FONT_HGT_MEDIUM, getText("UI_NewGame_Mods"), 1, 1, 1, 1, UIFont.Medium, true) + self.modsLabel:initialise() + self.modsLabel:instantiate() + self:addChild(self.modsLabel) + + self.modArticleList = ISScrollingListBox:new(self.modListBox:getRight() + 25, 50, self.width*0.2, self.height - 100) + self.modArticleList:initialise() + self.modArticleList:instantiate() + self.modArticleList:setFont(UIFont.Medium, 2) + self.modArticleList:setAnchorLeft(true) + self.modArticleList:setAnchorRight(true) + self.modArticleList:setAnchorTop(true) + self.modArticleList:setAnchorBottom(true) + self.modArticleList.doDrawItem = self.modArticleItemDraw + self.modArticleList.drawBorder = true + self.modArticleList:setOnMouseDownFunction(self, self.onArcticleListClick) + self:addChild(self.modArticleList) + + lWid = getTextManager():MeasureStringX(UIFont.Medium, getText("UI_modNews_articleLabel")) + self.articleLabel = ISLabel:new(self.modArticleList:getX() + self.modArticleList.width/2 - lWid/2, 16, FONT_HGT_MEDIUM, getText("UI_modNews_articleLabel"), 1, 1, 1, 1, UIFont.Medium, true) + self.articleLabel:initialise() + self.articleLabel:instantiate() + self:addChild(self.articleLabel) + + local buttonHgt = FONT_HGT_SMALL + 3 * 2 + self.backButton = ISButton:new(16, self.height - 10 - buttonHgt, 100, buttonHgt, getText("UI_btn_back"), self, self.onOptionMouseDown) + self.backButton.internal = "BACK" + self.backButton:initialise() + self.backButton:instantiate() + self.backButton:setAnchorLeft(true) + self.backButton:setAnchorTop(false) + self.backButton:setAnchorBottom(true) + self.backButton.borderColor = {r=1, g=1, b=1, a=0.1} + self:addChild(self.backButton) + + self.articleText = ISRichTextPanel:new(self.modArticleList:getRight() + 50, 0, self.width - self.modArticleList:getRight() - 50, self.height) + self.articleText.marginRight = self.articleText.marginLeft + self.articleText:initialise() + self:addChild(self.articleText) + self.articleText:addScrollBars() + + self.articleText.background = false + self.articleText.clip = true + self.articleText.autosetheight = false + self.articleText.text = "" + self.articleText:paginate() + + self:populateModList() +end + +function ModNewsPanel:onModListClick() + self:populateArticleList() +end + +function ModNewsPanel:onArcticleListClick() + local item = self.modArticleList.items[self.modArticleList.selected].item + self:updateSettingView(item) + ModNewsAPI.Data[item.modID][item.articleName].isViewed = true +end + +function ModNewsPanel:updateSettingView(item) + self.articleText.text = getText(item.articleTextName) + self.articleText:paginate() +end + +function ModNewsPanel:populateArticleList() + local item = self.modListBox.items[self.modListBox.selected].item + self.modArticleList:clear() + + for articleName, data in pairs(item) do + self.modArticleList:addItem(articleName, data) + end +end + +function ModNewsPanel:populateModList() + self.modListBox:clear() + + for modID, modArticleData in pairs(ModNewsAPI.Data) do + local modInfo = getModInfoByID(modID) + if modInfo == nil then + self.modListBox:addItem("IncorrectModID - " .. modID, modArticleData) + else + self.modListBox:addItem(modInfo:getName(), modArticleData) + end + end +end + +function ModNewsPanel:modListBoxItemDraw(y, item) + local dy = (self.itemheight - FONT_HGT_MEDIUM) / 2 + self:drawText(item.text, 16, y + dy, 1, 1, 1, 1, UIFont.Medium) + self:drawRectBorder(0, y, self:getWidth(), self.itemheight, 0.5, self.borderColor.r, self.borderColor.g, self.borderColor.b) + + for _, data in pairs(item.item) do + if ModNewsAPI.Data[data.modID][data.articleName].isViewed == false then + self:drawText("[!!!]", self.width - 50, y + dy, 0, 1, 0, 1, UIFont.Medium) + end + end + return y + self.itemheight +end + +function ModNewsPanel:modArticleItemDraw(y, item) + local dy = (self.itemheight - FONT_HGT_MEDIUM) / 2 + self:drawText(item.text, 16, y + dy, 1, 1, 1, 1, UIFont.Medium) + self:drawRectBorder(0, y, self:getWidth(), self.itemheight, 0.5, self.borderColor.r, self.borderColor.g, self.borderColor.b) + + if ModNewsAPI.Data[item.item.modID][item.item.articleName].isViewed == false then + self:drawText("[!!!]", self.width - 50, y + dy, 0, 1, 0, 1, UIFont.Medium) + end + + return y + self.itemheight +end + +function ModNewsPanel:onOptionMouseDown(button, x, y) + if button.internal == "BACK" then + self:setVisible(false) + self:removeFromUIManager() + + local fileWriter = getFileWriter("CAPI_modNewsData.txt", true, false) + fileWriter:write(JsonAPI.Encode(ModNewsAPI.Data)) + fileWriter:close() + end +end + +function ModNewsPanel:instantiate() + self.javaObject = UIElement.new(self) + self.javaObject:setX(self.x) + self.javaObject:setY(self.y) + self.javaObject:setHeight(self.height) + self.javaObject:setWidth(self.width) + self.javaObject:setAnchorLeft(self.anchorLeft) + self.javaObject:setAnchorRight(self.anchorRight) + self.javaObject:setAnchorTop(self.anchorTop) + self.javaObject:setAnchorBottom(self.anchorBottom) + self:createChildren() +end + +function ModNewsPanel:new(x, y, width, height) + local o = {} + o = ISPanelJoypad:new(x, y, width, height) + setmetatable(o, self) + self.__index = self + + o.backgroundColor = {r=0, g=0, b=0, a=0.0} + o.borderColor = {r=1, g=1, b=1, a=0.0} + o.itemheightoverride = {} + o.anchorLeft = true + o.anchorRight = false + o.anchorTop = true + o.anchorBottom = false + o.colorPanel = {} + + return o +end \ No newline at end of file diff --git a/Contents/mods/CommunityAPI/media/ui/ModNews/notifyIcon.png b/Contents/mods/CommunityAPI/media/ui/ModNews/notifyIcon.png new file mode 100644 index 0000000000000000000000000000000000000000..57bc9cda4b45b0e215ea6761976837d0eeee9e56 GIT binary patch literal 8909 zcmeHLcT`hp(+`4xGzGCBtj3@eAr%NDH0hv#RHdpZHw98K2^~ZbY)BJDrAZM5rHP^f zQfw5dE+~S4)Kyf9h=?Nc-hk`sxBI>4+jHLckMEp?lQuKYZ)Sea%-rYR<94}_fbN2G z-bwNml93DCHLk|1Ly$+2sfoXkKYgl6s?C1q(rK$6*x?l2EONz8rF(4Qi+gW%K-Bu| z=)8^|PF29ewJE#}AIkR)g?v^^Z+(BNZdXWH*@VHtRjlQO17Ew-4H@I@8{ z7ZhG~O{VSs{LbX9e`8$doYiI5>HXbF;2WeSV`Q zXK0{KIRC|)N5q>p&yyJ+#(_^7t*4$5$?>g%&kqF|)^@l0y*2PYa@eo+X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fi;+STg z9?7h>7jB7`UIE!!;>mcElfux~oshWQd^}o4%ro9_OR`d-TV7#%IHq4o=JJzeIwBD1 zRL<&#_qB3u?|v%~eO~lH5PBA|ygOF#u}XZSfHuomNxAZNrqxsTyrZpp0y?GW1fX%R zYR=6->6o)fBWBO6`1B-dxF@hR*^6UG3W`p9y;D7>TRgAHh*A7QlN5}dj z>xRs*YR~2>aocZxda6%8gQVc*-*(0}uh@_8^VkfNtTHz^3E5Y5dYfSw;?;bPt@e1K zig-;)zS}WVYg&v)q0`wpm$tdRXGHJ$jVWyH4;t!wM7g_(8wZVV79MSs91%FCj>b-X zF8$agZ**G^B8)=MZmi!WEA{F4y)GA>J?kdDGo<$n-?cWFom&`H)*L#Tu>D9-P)*3j z_3K4-QgIG`GWeKxV%}D>iT27(d+OP|o{?>dEv?&(UL9cXP26>oS>U!}{DnxN8~rOF zlrEcgHZ5|QZ^|Xj*EA8SjSzfy%qO*e$yR%HjBi}WVWnshH8lb0;*wu!rN0ilYu}se zgE+{E4aeGRrriq9%)HlbNZR0bp?DLoJ!}(=9=Z*tYpvU@64a?r%Bd)tWtoa zZ0__LD<2z4ZA}-1th%;RAd6y7+d!xLy`oK7tMrD#Yj&%Pxb_6qAJiEqjJ;mpuuecp zOLI~owr}l@oI*KjTUV)fnwZ6BNKeEN?@FI_A Date: Tue, 23 Nov 2021 14:39:32 +0500 Subject: [PATCH 02/13] Added translate --- .../CommunityAPI/media/lua/shared/Translate/EN/UI_EN.txt | 5 ++++- .../CommunityAPI/media/lua/shared/Translate/RU/UI_RU.txt | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Contents/mods/CommunityAPI/media/lua/shared/Translate/EN/UI_EN.txt b/Contents/mods/CommunityAPI/media/lua/shared/Translate/EN/UI_EN.txt index bfdc81d..44eabfd 100644 --- a/Contents/mods/CommunityAPI/media/lua/shared/Translate/EN/UI_EN.txt +++ b/Contents/mods/CommunityAPI/media/lua/shared/Translate/EN/UI_EN.txt @@ -8,5 +8,8 @@ UI_EN = { UI_EMS_CopyLink = "Copy link" UI_EMS_CopyLocation = "Copy location", UI_EMS_CopyID = "Copy ID", - UI_EMS_CopyWorkshopID = "Copy Workshop ID" + UI_EMS_CopyWorkshopID = "Copy Workshop ID", + + UI_modNews_button = "Mod Info", + UI_modNews_articleLabel = "Articles", } diff --git a/Contents/mods/CommunityAPI/media/lua/shared/Translate/RU/UI_RU.txt b/Contents/mods/CommunityAPI/media/lua/shared/Translate/RU/UI_RU.txt index fc4c152..a312337 100644 --- a/Contents/mods/CommunityAPI/media/lua/shared/Translate/RU/UI_RU.txt +++ b/Contents/mods/CommunityAPI/media/lua/shared/Translate/RU/UI_RU.txt @@ -8,5 +8,8 @@ UI_RU = { UI_EMS_CopyLink = "Копировать ссылку" UI_EMS_CopyLocation = "Копировать расположение", UI_EMS_CopyID = "Копировать ID", - UI_EMS_CopyWorkshopID = "Копировать Workshop ID" + UI_EMS_CopyWorkshopID = "Копировать Workshop ID", + + UI_modNews_button = "Мод Инфо", + UI_modNews_articleLabel = "Статьи" } From 4b62fbaffe5ffa3035f510588fbbfccc70edae17 Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 10:42:28 -0500 Subject: [PATCH 03/13] Removed and added directly into ModNewsAPIClient.lua --- .../lua/client/ModNewsAPI/LoadModNewsData.lua | 28 ------------------- 1 file changed, 28 deletions(-) delete mode 100644 Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/LoadModNewsData.lua diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/LoadModNewsData.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/LoadModNewsData.lua deleted file mode 100644 index a9d9d7a..0000000 --- a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/LoadModNewsData.lua +++ /dev/null @@ -1,28 +0,0 @@ -require("CommunityAPI") -local ModNewsAPI = CommunityAPI.Client.ModNews -local JsonAPI = CommunityAPI.Utils.Json - -local function ModNewsAPILoadData() - local fileReader = getFileReader("CAPI_modNewsData.txt", true) - if not fileReader then return end - local line = fileReader:readLine() - local modNewsData = nil - if line ~= nil then - modNewsData = JsonAPI.Decode(line) - end - fileReader:close() - - if modNewsData ~= nil and type(modNewsData) == "table" then - for modID, modData in pairs(modNewsData) do - for articleName, data in pairs(modData) do - if ModNewsAPI.Data[modID] ~= nil and ModNewsAPI.Data[modID][articleName] ~= nil then - if data.isViewed and data.lastUpdateDate == ModNewsAPI.Data[modID][articleName].lastUpdateDate then - ModNewsAPI.Data[modID][articleName].isViewed = true - end - end - end - end - end -end - -Events.OnGameBoot.Add(ModNewsAPILoadData) \ No newline at end of file From 6909b761c7361fe1e243e31c077b87f3c9931ba1 Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 10:42:33 -0500 Subject: [PATCH 04/13] Create README.md --- .../media/lua/client/ModNewsAPI/README.md | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md new file mode 100644 index 0000000..3277bcf --- /dev/null +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md @@ -0,0 +1,13 @@ +# ModNewsAPI +**Developer:** Aiteron +**Contributors:** - +**Package:** CommunityAPI.Client.ModNews + +## Description +Add news article for your mod updates. + +## Methods +To-do + +## Examples +To-do \ No newline at end of file From 6c87098867627ebfbe20502b672bc31a9be073ab Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 10:43:04 -0500 Subject: [PATCH 05/13] Changed Data to be private and added methods to access --- .../client/ModNewsAPI/ModNewsAPIClient.lua | 76 ++++++++++++++++--- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua index 37cbd62..a2d9b80 100644 --- a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua @@ -1,23 +1,77 @@ +local JsonAPI = require("CommunityAPI/JsonUtils") ---@class ModNewsAPI local ModNewsAPI = {} -ModNewsAPI.Data = {} +local Data = {} ----@param modID string ----@param articleName string +--- Load the data +local function ModNewsAPILoadData() + local fileReader = getFileReader("CAPI_modNewsData.txt", true) + if not fileReader then return end + local line = fileReader:readLine() + local modNewsData = nil + if line ~= nil then + modNewsData = JsonAPI.Decode(line) + end + fileReader:close() + + if modNewsData ~= nil and type(modNewsData) == "table" then + for modID, modData in pairs(modNewsData) do + for articleName, data in pairs(modData) do + if Data[modID] ~= nil and Data[modID][articleName] ~= nil then + if data.isViewed and data.lastUpdateDate == Data[modID][articleName].lastUpdateDate then + Data[modID][articleName].isViewed = true + end + end + end + end + end +end +Events.OnGameBoot.Add(ModNewsAPILoadData) + +--- Add a new Article for your mod +---@param modID string The mod ID +---@param articleName string The article Name ---@param articleTextName string Article text name from Translate ---@param lastUpdateDate string String with date of last update. If you changed article and want to notify that article updated - change this param ---@return nil function ModNewsAPI.AddArticle(modID, articleName, articleTextName, lastUpdateDate) - if ModNewsAPI.Data[modID] == nil then - ModNewsAPI.Data[modID] = {} + if Data[modID] == nil then + Data[modID] = {} + end + Data[modID][articleName] = {} + Data[modID][articleName].modID = modID + Data[modID][articleName].articleName = articleName + Data[modID][articleName].articleTextName = articleTextName + Data[modID][articleName].lastUpdateDate = lastUpdateDate + Data[modID][articleName].isViewed = false +end + +--- Get all Data (readonly) +---@return table +function ModNewsAPI.GetAll() + return copyTable(Data) +end + +--- Get a specific mod article (readonly) +---@param modID string The mod ID +---@param articleName string The article Name +---@return table +function ModNewsAPI.GetArticle(modID, articleName) + if Data[modID] and Data[modID][articleName] then + return copyTable(Data[modID][articleName]) + end +end + +--- Set an article as read +---@param modID string The mod ID +---@param articleName string The article Name +---@return boolean True if success +function ModNewsAPI.SetArticleAsViewed(modID, articleName) + if Data[modID] and Data[modID][articleName] then + Data[modID][articleName].isViewed = true + return true end - ModNewsAPI.Data[modID][articleName] = {} - ModNewsAPI.Data[modID][articleName].modID = modID - ModNewsAPI.Data[modID][articleName].articleName = articleName - ModNewsAPI.Data[modID][articleName].articleTextName = articleTextName - ModNewsAPI.Data[modID][articleName].lastUpdateDate = lastUpdateDate - ModNewsAPI.Data[modID][articleName].isViewed = false end return ModNewsAPI \ No newline at end of file From 5416c91f81e9f75c2c0617d249dfa929724cc7fc Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 10:43:29 -0500 Subject: [PATCH 06/13] Update and set to local --- .../lua/client/ModNewsAPI/ModNewsPanel.lua | 20 ++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua index 2b864a8..3f200db 100644 --- a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua @@ -2,7 +2,7 @@ require("CommunityAPI") local ModNewsAPI = CommunityAPI.Client.ModNews local JsonAPI = CommunityAPI.Utils.Json -ModNewsPanel = ISPanelJoypad:derive("ModNewsPanel") +local ModNewsPanel = ISPanelJoypad:derive("ModNewsPanel") local FONT_HGT_SMALL = getTextManager():getFontHeight(UIFont.Small) local FONT_HGT_MEDIUM = getTextManager():getFontHeight(UIFont.Medium) @@ -79,7 +79,7 @@ end function ModNewsPanel:onArcticleListClick() local item = self.modArticleList.items[self.modArticleList.selected].item self:updateSettingView(item) - ModNewsAPI.Data[item.modID][item.articleName].isViewed = true + ModNewsAPI.SetArticleAsRead(item.modID, item.articleName) end function ModNewsPanel:updateSettingView(item) @@ -99,7 +99,8 @@ end function ModNewsPanel:populateModList() self.modListBox:clear() - for modID, modArticleData in pairs(ModNewsAPI.Data) do + local Data = ModNewsAPI.GetAll() + for modID, modArticleData in pairs(Data) do local modInfo = getModInfoByID(modID) if modInfo == nil then self.modListBox:addItem("IncorrectModID - " .. modID, modArticleData) @@ -115,7 +116,8 @@ function ModNewsPanel:modListBoxItemDraw(y, item) self:drawRectBorder(0, y, self:getWidth(), self.itemheight, 0.5, self.borderColor.r, self.borderColor.g, self.borderColor.b) for _, data in pairs(item.item) do - if ModNewsAPI.Data[data.modID][data.articleName].isViewed == false then + local article = ModNewsAPI.GetArticle(data.modID, data.articleName) + if article and article.isViewed == false then self:drawText("[!!!]", self.width - 50, y + dy, 0, 1, 0, 1, UIFont.Medium) end end @@ -127,7 +129,8 @@ function ModNewsPanel:modArticleItemDraw(y, item) self:drawText(item.text, 16, y + dy, 1, 1, 1, 1, UIFont.Medium) self:drawRectBorder(0, y, self:getWidth(), self.itemheight, 0.5, self.borderColor.r, self.borderColor.g, self.borderColor.b) - if ModNewsAPI.Data[item.item.modID][item.item.articleName].isViewed == false then + local article = ModNewsAPI.GetArticle(item.item.modID, item.item.articleName) + if article and article.isViewed == false then self:drawText("[!!!]", self.width - 50, y + dy, 0, 1, 0, 1, UIFont.Medium) end @@ -139,8 +142,9 @@ function ModNewsPanel:onOptionMouseDown(button, x, y) self:setVisible(false) self:removeFromUIManager() + local Data = ModNewsAPI.GetAll() local fileWriter = getFileWriter("CAPI_modNewsData.txt", true, false) - fileWriter:write(JsonAPI.Encode(ModNewsAPI.Data)) + fileWriter:write(JsonAPI.Encode(Data)) fileWriter:close() end end @@ -174,4 +178,6 @@ function ModNewsPanel:new(x, y, width, height) o.colorPanel = {} return o -end \ No newline at end of file +end + +return ModNewsPanel From 5b95f5b16dfff679f1f9a14d24f0899106584f4a Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 10:43:52 -0500 Subject: [PATCH 07/13] Require ModNewsPanel and updated to use api methods --- .../lua/client/ModNewsAPI/ModNewsButton.lua | 30 ++++++++++--------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsButton.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsButton.lua index 9d9457e..af2a59b 100644 --- a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsButton.lua +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsButton.lua @@ -1,13 +1,15 @@ require("CommunityAPI") local ModNewsAPI = CommunityAPI.Client.ModNews +local ModNewsPanel = require("ModNewsAPI/ModNewsPanel") local FONT_HGT_MEDIUM = getTextManager():getFontHeight(UIFont.Medium) local function renderModNewsButton(self) ISButton.render(self) - + + local Data = ModNewsAPI.GetAll() local isNewArticles = false - for _, modData in pairs(ModNewsAPI.Data) do + for _, modData in pairs(Data) do for _, articleData in pairs(modData) do if articleData.isViewed == false then isNewArticles = true @@ -25,18 +27,18 @@ end local function onClickModNews(self) local w = self.width * 0.8 local h = self.height * 0.8 - local modNewsPanel = ModNewsPanel:new((self.width - w)/2, (self.height - h)/2, w, h) - modNewsPanel.backgroundColor = {r=0, g=0, b=0, a=0.95} - modNewsPanel.borderColor = {r=1, g=1, b=1, a=0.5} - modNewsPanel:initialise() - modNewsPanel:instantiate() - modNewsPanel:setCapture(true) - modNewsPanel:setAlwaysOnTop(true) - modNewsPanel:setAnchorRight(true) - modNewsPanel:setAnchorLeft(true) - modNewsPanel:setAnchorBottom(true) - modNewsPanel:setAnchorTop(true) - modNewsPanel:addToUIManager() + local newsPanel = ModNewsPanel:new((self.width - w)/2, (self.height - h)/2, w, h) + newsPanel.backgroundColor = {r=0, g=0, b=0, a=0.95} + newsPanel.borderColor = {r=1, g=1, b=1, a=0.5} + newsPanel:initialise() + newsPanel:instantiate() + newsPanel:setCapture(true) + newsPanel:setAlwaysOnTop(true) + newsPanel:setAnchorRight(true) + newsPanel:setAnchorLeft(true) + newsPanel:setAnchorBottom(true) + newsPanel:setAnchorTop(true) + newsPanel:addToUIManager() end -- Hook From 42c647e138ae53066a80b5d52574e8caaa5d2043 Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 10:46:23 -0500 Subject: [PATCH 08/13] Fixed method name --- .../CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua index 3f200db..f7ecfde 100644 --- a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua @@ -79,7 +79,7 @@ end function ModNewsPanel:onArcticleListClick() local item = self.modArticleList.items[self.modArticleList.selected].item self:updateSettingView(item) - ModNewsAPI.SetArticleAsRead(item.modID, item.articleName) + ModNewsAPI.SetArticleAsViewed(item.modID, item.articleName) end function ModNewsPanel:updateSettingView(item) From 0315c859dddb1fa583313aa6bb575a7ce27ee5df Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 10:54:45 -0500 Subject: [PATCH 09/13] Update README.md --- .../media/lua/client/ModNewsAPI/README.md | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md index 3277bcf..c0e346d 100644 --- a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md @@ -7,7 +7,32 @@ Add news article for your mod updates. ## Methods -To-do + +### AddArticle(modID, articleName, articleTextName, lastUpdateDate) +Add a new Article for your mod + +| Param | Type | Description | +|-----------------|--------|---------------------------------------------------------------------------------------------------------------------| +| modID | string | The mod ID | +| articleName | string | The article Name | +| articleTextName | string | Article text name from Translate | +| lastUpdateDate | string | String with date of last update. If you changed article and want to notify that article updated - change this param | ## Examples -To-do \ No newline at end of file +```lua +require("CommunityAPI") +local ModNewsAPI = CommunityAPI.Client.ModNews + +--- Add an article for your mod +ModNewsAPI.AddArticle( + "MyModId", + "The article name in the list", + "The article text here\nwith line breaks if desired", + "November 1st, 2021"); + +ModNewsAPI.AddArticle( + "MyModId", + getText("Translate_Article_Name"), + getText("Translate_Article_Text"), + "November 1st, 2021"); +``` \ No newline at end of file From 3a71e9e47c1499d80b65e1e5611123e0e0aa23fa Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 11:01:03 -0500 Subject: [PATCH 10/13] Added GetArticleIsViewed method --- .../lua/client/ModNewsAPI/ModNewsAPIClient.lua | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua index a2d9b80..4f3c1cd 100644 --- a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsAPIClient.lua @@ -63,14 +63,22 @@ function ModNewsAPI.GetArticle(modID, articleName) end end ---- Set an article as read +--- Check if an article is viewed already +---@param modID string The mod ID +---@param articleName string The article Name +---@return boolean True if viewed +function ModNewsAPI.GetArticleIsViewed(modID, articleName) + if Data[modID] and Data[modID][articleName] then + return Data[modID][articleName].isViewed + end +end + +--- Set an article as viewed ---@param modID string The mod ID ---@param articleName string The article Name ----@return boolean True if success function ModNewsAPI.SetArticleAsViewed(modID, articleName) if Data[modID] and Data[modID][articleName] then Data[modID][articleName].isViewed = true - return true end end From 4e3d6e206ec0ad3e5ea613c781ae24bb0cdab60a Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 11:01:22 -0500 Subject: [PATCH 11/13] Use GetArticleIsViewed instead of getting the article --- .../media/lua/client/ModNewsAPI/ModNewsPanel.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua index f7ecfde..246276f 100644 --- a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/ModNewsPanel.lua @@ -116,8 +116,8 @@ function ModNewsPanel:modListBoxItemDraw(y, item) self:drawRectBorder(0, y, self:getWidth(), self.itemheight, 0.5, self.borderColor.r, self.borderColor.g, self.borderColor.b) for _, data in pairs(item.item) do - local article = ModNewsAPI.GetArticle(data.modID, data.articleName) - if article and article.isViewed == false then + local isViewed = ModNewsAPI.GetArticleIsViewed(data.modID, data.articleName) + if isViewed == false then self:drawText("[!!!]", self.width - 50, y + dy, 0, 1, 0, 1, UIFont.Medium) end end @@ -129,8 +129,8 @@ function ModNewsPanel:modArticleItemDraw(y, item) self:drawText(item.text, 16, y + dy, 1, 1, 1, 1, UIFont.Medium) self:drawRectBorder(0, y, self:getWidth(), self.itemheight, 0.5, self.borderColor.r, self.borderColor.g, self.borderColor.b) - local article = ModNewsAPI.GetArticle(item.item.modID, item.item.articleName) - if article and article.isViewed == false then + local isViewed = ModNewsAPI.GetArticleIsViewed(item.item.modID, item.item.articleName) + if isViewed == false then self:drawText("[!!!]", self.width - 50, y + dy, 0, 1, 0, 1, UIFont.Medium) end From 64b5522097a1e105960dbe9c19a7e75d9568bedb Mon Sep 17 00:00:00 2001 From: Konijima Date: Tue, 23 Nov 2021 11:01:34 -0500 Subject: [PATCH 12/13] Update README.md --- Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md index c0e346d..efe4712 100644 --- a/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md +++ b/Contents/mods/CommunityAPI/media/lua/client/ModNewsAPI/README.md @@ -30,6 +30,7 @@ ModNewsAPI.AddArticle( "The article text here\nwith line breaks if desired", "November 1st, 2021"); +--- Add a translatable article for your mod ModNewsAPI.AddArticle( "MyModId", getText("Translate_Article_Name"), From 9dc9b903963850811a97b277691e733a8cfb4465 Mon Sep 17 00:00:00 2001 From: Aiteron Date: Wed, 24 Nov 2021 07:42:23 +0500 Subject: [PATCH 13/13] Added site parser --- .../lua/shared/CommunityAPI/StringUtils.lua | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/Contents/mods/CommunityAPI/media/lua/shared/CommunityAPI/StringUtils.lua b/Contents/mods/CommunityAPI/media/lua/shared/CommunityAPI/StringUtils.lua index ae896f7..0948efc 100644 --- a/Contents/mods/CommunityAPI/media/lua/shared/CommunityAPI/StringUtils.lua +++ b/Contents/mods/CommunityAPI/media/lua/shared/CommunityAPI/StringUtils.lua @@ -37,4 +37,25 @@ function StringUtils.NumberToDecimalString(value, _decimal) return string.format("%.".._decimal.."f", value); end +---Parse each line of site html file by parseLineFunc +---@param url string Url ("https://" or "http://") +---@param parseLineFunc function Get line and return useful data item (not empty string or any object) else nil or empty string +---@return table any List with all useful data items +function StringUtils.ParseSite(url, parseLineFunc) + local siteData = getUrlInputStream(url) + local resultData = {} + + if siteData ~= nil then + local currentLine = siteData:readLine() + while currentLine ~= nil do + local dataItem = parseLineFunc(currentLine) + if dataItem ~= nil and dataItem ~= "" then + table.insert(resultData, dataItem) + end + currentLine = siteData:readLine() + end + end + return resultData +end + return StringUtils \ No newline at end of file