From 35440839e91bf12be07d52efa54e5f5e420b56b8 Mon Sep 17 00:00:00 2001 From: puxuan <413323644@qq.com> Date: Mon, 14 Jul 2025 20:47:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E7=95=8C=E9=9D=A2=E7=AE=B1=E5=AD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/module/maincity/maincity_manager.lua | 4 + .../ui/main_city/cell/chapter_box_cell.lua | 56 ++++++++++++++ .../main_city/cell/chapter_box_cell.lua.meta | 10 +++ lua/app/ui/main_city/chapter_box_ui.lua | 73 +++++++++++++++++++ lua/app/ui/main_city/chapter_box_ui.lua.meta | 10 +++ lua/app/ui/main_city/component/main_comp.lua | 11 ++- lua/app/userdata/chapter/chapter_data.lua | 29 ++++++-- 7 files changed, 185 insertions(+), 8 deletions(-) create mode 100644 lua/app/ui/main_city/cell/chapter_box_cell.lua create mode 100644 lua/app/ui/main_city/cell/chapter_box_cell.lua.meta create mode 100644 lua/app/ui/main_city/chapter_box_ui.lua create mode 100644 lua/app/ui/main_city/chapter_box_ui.lua.meta diff --git a/lua/app/module/maincity/maincity_manager.lua b/lua/app/module/maincity/maincity_manager.lua index 4a72e316..d4935f63 100644 --- a/lua/app/module/maincity/maincity_manager.lua +++ b/lua/app/module/maincity/maincity_manager.lua @@ -13,6 +13,10 @@ function MaincityManager:showModuleUnlockUI() UIManager:showUI("app/ui/main_city/module_unlock_ui", {chapterId = chapterId}) end +function MaincityManager:showChapterBoxUI(chapterId) + UIManager:showUI("app/ui/main_city/chapter_box_ui", {chapterId = chapterId}) +end + -- 从登录界面第一次进入主城 function MaincityManager:firstEnterMainCity() if (EDITOR_MODE or not Platform:getIsPublishChannel()) and LocalData:getTutorialSkip() > 0 then diff --git a/lua/app/ui/main_city/cell/chapter_box_cell.lua b/lua/app/ui/main_city/cell/chapter_box_cell.lua new file mode 100644 index 00000000..2d93e4f8 --- /dev/null +++ b/lua/app/ui/main_city/cell/chapter_box_cell.lua @@ -0,0 +1,56 @@ +local ChapterBoxCell = class("ChapterBoxCell", BaseCell) + +function ChapterBoxCell:init() + local uiMap = self:getUIMap() + + self.titleTx = uiMap["cell.title_tx"] + self.claimBtn = uiMap["cell.claim_btn"] + self.claimBtnTx = uiMap["cell.claim_btn.text"] + self.claimImg = uiMap["cell.claim_img"] + self.claimImgTx = uiMap["cell.claim_img.text"] + self.rewardCells = {} + for i = 1, 2 do + self.rewardCells[i] = CellManager:addCellComp(uiMap["cell.reward_cell_" .. i], GConst.TYPEOF_LUA_CLASS.REWARD_CELL) + end + self.claimImgTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_DONE)) + + self.claimBtn:addClickListener(function() + ModuleManager.ChapterManager:openBox(self.chapterId, self.idx) + end) +end + +function ChapterBoxCell:refresh(chapterId, idx) + local list = DataManager.ChapterData:getChapterBoxRewardList(chapterId) + local rewardCfg = list[idx] + if rewardCfg == nil then + return + end + self.chapterId = chapterId + self.idx = idx + self.titleTx:setText(I18N:getGlobalText(I18N.GlobalConst.GET_REWARDS_DESC, idx)) + + local hadGot = DataManager.ChapterData:getChapterBoxRewardGot(chapterId, idx) + if hadGot then + self.claimBtn:setActive(false) + self.claimImg:setActive(true) + else + self.claimBtn:setActive(true) + self.claimImg:setActive(false) + + if DataManager.ChapterData:boxCanGet(chapterId, idx) then + self.claimBtn:setTouchEnable(true) + self.claimBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_blue_1") + self.claimBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_CLAIM)) + else + self.claimBtn:setTouchEnable(false) + self.claimBtn:setSprite(GConst.ATLAS_PATH.COMMON, "common_btn_grey_1") + self.claimBtnTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_CLAIM)) + end + end + + for i = 1, 2 do + self.rewardCells[i]:refreshByConfig(rewardCfg[i], hadGot, hadGot) + end +end + +return ChapterBoxCell \ No newline at end of file diff --git a/lua/app/ui/main_city/cell/chapter_box_cell.lua.meta b/lua/app/ui/main_city/cell/chapter_box_cell.lua.meta new file mode 100644 index 00000000..791d9c4b --- /dev/null +++ b/lua/app/ui/main_city/cell/chapter_box_cell.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 7eddb98373b464f679b5589c4a0e004b +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/ui/main_city/chapter_box_ui.lua b/lua/app/ui/main_city/chapter_box_ui.lua new file mode 100644 index 00000000..c14608d0 --- /dev/null +++ b/lua/app/ui/main_city/chapter_box_ui.lua @@ -0,0 +1,73 @@ +local ChapterBoxUI = class("ChapterBoxUI", BaseUI) + +function ChapterBoxUI:isFullScreen() + return false +end + +function ChapterBoxUI:getPrefabPath() + return "assets/prefabs/ui/main_city/chapter_box_ui.prefab" +end + +function ChapterBoxUI:ctor(params) + self.chapterId = params.chapterId + + -- local chapterId = DataManager.ChapterData:getChapterId() + -- local chapterMaxId = DataManager.ChapterData:getMaxChapterId() + -- local idx = DataManager.ChapterData:getChapterIdIdx(chapterId) +end + +function ChapterBoxUI:onLoadRootComplete() + local uiMap = self.root:genAllChildren() + + uiMap["chapter_box_ui.bg.close_btn"]:addClickListener(function() + self:closeUI() + end) + + self.selImg = uiMap["chapter_box_ui.bg.sel_img"] + self.maxWaveTx = uiMap["chapter_box_ui.bg.max_wave_tx"] + + -- uiMap["chapter_box_ui.bg.title_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.HERO_TRIAL_DESC_1)) + uiMap["chapter_box_ui.bg.title_tx"]:setText("通关奖励") + + self.page = DataManager.ChapterData:getChapterIdPage(self.chapterId) + self.pageIdx = DataManager.ChapterData:getChapterIdIdx(self.chapterId) + self.chapterTxs = {} + for i = 1, 5 do + self.chapterTxs[i] = uiMap["chapter_box_ui.bg.chapter_tx_" .. i] + self.chapterTxs[i]:addClickListener(function() + if self.pageIdx == i then + return + end + self.pageIdx = i + self:onRefresh() + end) + end + self.scrollRect = uiMap["chapter_box_ui.bg.scrollrect"] + self.scrollRectComp = self.scrollRect:addLuaComponent(GConst.TYPEOF_LUA_CLASS.SCROLL_RECT_BASE) + self.scrollRectComp:addInitCallback(function() + return "app/ui/main_city/cell/chapter_box_cell" + end) + self.scrollRectComp:addRefreshCallback(function(index, cell) + cell:refresh(self.chapterId, index) + end) + self.scrollRectComp:setTotalCount(0) + + self:bind(DataManager.ChapterData, "isDirty", function() + self:onRefresh() + end) +end + +function ChapterBoxUI:onRefresh() + self.chapterId = DataManager.ChapterData:getChapterIdByPageAndIdx(self.page, self.pageIdx) + for i = 1, 5 do + self.chapterTxs[i]:setText(self.page .. "-" .. i) + end + self.selImg:setAnchoredPositionX((self.pageIdx - 3) * 118) + local list = DataManager.ChapterData:getChapterBoxRewardList(self.chapterId) + self.scrollRectComp:refillCells(#list) + + self.maxWaveTx:setText(I18N:getGlobalText(I18N.GlobalConst.CHAPTER_DESC_1, DataManager.ChapterData:getChapterMaxWave(self.chapterId))) + +end + +return ChapterBoxUI \ No newline at end of file diff --git a/lua/app/ui/main_city/chapter_box_ui.lua.meta b/lua/app/ui/main_city/chapter_box_ui.lua.meta new file mode 100644 index 00000000..9df59bda --- /dev/null +++ b/lua/app/ui/main_city/chapter_box_ui.lua.meta @@ -0,0 +1,10 @@ +fileFormatVersion: 2 +guid: 924a26de3ff22406786955f049da44a4 +ScriptedImporter: + internalIDToNameTable: [] + externalObjects: {} + serializedVersion: 2 + userData: + assetBundleName: + assetBundleVariant: + script: {fileID: 11500000, guid: 3b8b241bab4a4ac9a22fcce9c64f1242, type: 3} diff --git a/lua/app/ui/main_city/component/main_comp.lua b/lua/app/ui/main_city/component/main_comp.lua index 51d70f04..10415999 100644 --- a/lua/app/ui/main_city/component/main_comp.lua +++ b/lua/app/ui/main_city/component/main_comp.lua @@ -118,7 +118,16 @@ function MainComp:init() self:refresh() end) end + -- MaincityManager:showChapterBoxUI(chapterId) + uiMap["main_comp.middle_bg.box_btn"]:addClickListener(function() + local chapterId = DataManager.ChapterData:getChapterId() + ModuleManager.MaincityManager:showChapterBoxUI(chapterId) + end) + uiMap["main_comp.middle_bg.info_btn"]:addClickListener(function() + local chapterId = DataManager.ChapterData:getChapterId() + ModuleManager.MaincityManager:showChapterBoxUI(chapterId) + end) uiMap["main_comp.arena_btn"]:addClickListener(function() ModuleManager.ArenaManager:reqArenaInfo(true) end) @@ -181,7 +190,7 @@ end function MainComp:refreshChapterInfo() local chapterId = DataManager.ChapterData:getChapterId() local chapterMaxId = DataManager.ChapterData:getMaxChapterId() - local idx = (chapterId - 1) % CHAPTER_PAGE + 1 + local idx = DataManager.ChapterData:getChapterIdIdx(chapterId) for i = 1, CHAPTER_PAGE do if idx == i then self.chapterSelectImg:setAnchoredPositionX((i - 3) * 98) diff --git a/lua/app/userdata/chapter/chapter_data.lua b/lua/app/userdata/chapter/chapter_data.lua index 561848f4..e24f6311 100644 --- a/lua/app/userdata/chapter/chapter_data.lua +++ b/lua/app/userdata/chapter/chapter_data.lua @@ -2,6 +2,7 @@ local ChapterData = class("ChapterData", BaseData) ChapterData.MIN_CHAPTER_ID = 1 local MIN_CHAPTER_ID = ChapterData.MIN_CHAPTER_ID +local CHAPTER_PAGE = 5 function ChapterData:ctor() self.data.chapterId = MIN_CHAPTER_ID @@ -76,6 +77,21 @@ function ChapterData:setChapterId(chapterId) self.data.chapterId = chapterId end +function ChapterData:getChapterIdIdx(chapterId) + local idx = (chapterId - 1) % CHAPTER_PAGE + 1 + return idx +end + +function ChapterData:getChapterIdPage(chapterId) + local page = (chapterId - 1) // CHAPTER_PAGE + return page +end + +function ChapterData:getChapterIdByPageAndIdx(page, idx) + local chapterId = page * CHAPTER_PAGE + idx + return chapterId +end + function ChapterData:getNextChapter(chapterId) local chapterInfo = self:getChapterCfg()[chapterId] if chapterInfo == nil then @@ -174,16 +190,15 @@ function ChapterData:boxCanGet(chapterId, index) return needWave <= curMaxWave end -function ChapterData:getChapterBoxRewards(chapterId, index) - chapterId = chapterId or self:getChapterId() - if not self:getChapterBoxNum(chapterId, index) then - return - end - +function ChapterData:getChapterBoxRewardList(chapterId) + local list = {} local cfg = self:getChapterCfg()[chapterId] if cfg then - return cfg["box_reward_" .. index] + for i = 1, 3 do + table.insert(list, cfg["box_reward_" .. i]) + end end + return list end function ChapterData:getChapterMaxWave(chapterId)