From 77d01818ed83178faf7dddb3fc3aefd1f9843d18 Mon Sep 17 00:00:00 2001 From: puxuan <413323644@qq.com> Date: Fri, 5 Sep 2025 14:26:16 +0800 Subject: [PATCH] fix bug --- lua/app/module/chapter/chapter_manager.lua | 12 ++-- .../ui/main_city/cell/chapter_box_cell.lua | 2 +- lua/app/ui/main_city/component/main_comp.lua | 11 +++- lua/app/ui/tips/reward_box.lua | 8 +-- lua/app/userdata/chapter/chapter_data.lua | 62 +++++++++++++++---- 5 files changed, 67 insertions(+), 28 deletions(-) diff --git a/lua/app/module/chapter/chapter_manager.lua b/lua/app/module/chapter/chapter_manager.lua index bf98c10b..b40bbc15 100644 --- a/lua/app/module/chapter/chapter_manager.lua +++ b/lua/app/module/chapter/chapter_manager.lua @@ -1,14 +1,12 @@ local ChapterManager = class("ChapterManager", BaseModule) function ChapterManager:openBox(chapterId, index) - if DataManager.ChapterData:getChapterBoxRewardGot(chapterId, index) then + if not DataManager.ChapterData:getChapterBoxCanGet() then return end - local parmas = { - chapter_id = chapterId, - wave = index, - } + local parmas = {} + parmas.boxes = DataManager.ChapterData:getChapterBoxCanGetInfo() self:sendMessage(ProtoMsgType.FromMsgEnum.ChapterBoxRewardReq, parmas, {}, self.openBoxFinish, BIReport.ITEM_GET_TYPE.CHAPTER_BOX) end @@ -16,9 +14,9 @@ function ChapterManager:openBoxFinish(result) if result.err_code == GConst.ERROR_STR.SUCCESS then local reqData = result.reqData GFunc.showRewardBox(result.rewards) - DataManager.ChapterData:openBox(reqData.chapter_id, reqData.wave) + DataManager.ChapterData:openBox() - BIReport:postChapterOpenBox(reqData.chapter_id, DataManager.ChapterData:getChapterBoxNum(reqData.chapter_id, reqData.wave), result.rewards) + -- BIReport:postChapterOpenBox(reqData.chapter_id, DataManager.ChapterData:getChapterBoxNum(reqData.chapter_id, reqData.wave), result.rewards) ModuleManager.TaskManager:addTaskProgress(GConst.TaskConst.TASK_TYPE.X_OPEN_CHAPTER_BOX) end diff --git a/lua/app/ui/main_city/cell/chapter_box_cell.lua b/lua/app/ui/main_city/cell/chapter_box_cell.lua index 2a3490ed..cc75b0d4 100644 --- a/lua/app/ui/main_city/cell/chapter_box_cell.lua +++ b/lua/app/ui/main_city/cell/chapter_box_cell.lua @@ -15,7 +15,7 @@ function ChapterBoxCell:init() self.claimImgTx:setText(I18N:getGlobalText(I18N.GlobalConst.BTN_DONE)) self.claimBtn:addClickListener(function() - ModuleManager.ChapterManager:openBox(self.chapterId, self.idx) + ModuleManager.ChapterManager:openBox() end) end diff --git a/lua/app/ui/main_city/component/main_comp.lua b/lua/app/ui/main_city/component/main_comp.lua index 95ef9fc9..73667019 100644 --- a/lua/app/ui/main_city/component/main_comp.lua +++ b/lua/app/ui/main_city/component/main_comp.lua @@ -117,8 +117,13 @@ function MainComp:init() -- MaincityManager:showChapterBoxUI(chapterId) uiMap["main_comp.middle_bg.box_btn"]:addClickListener(function() - local chapterId = DataManager.ChapterData:getChapterId() - ModuleManager.MaincityManager:showChapterBoxUI(chapterId) + local canGet = DataManager.ChapterData:getChapterBoxCanGet() + if canGet then + ModuleManager.ChapterManager:openBox() + else + local chapterId = DataManager.ChapterData:getChapterId() + ModuleManager.MaincityManager:showChapterBoxUI(chapterId) + end end) uiMap["main_comp.middle_bg.info_btn"]:addClickListener(function() local chapterId = DataManager.ChapterData:getChapterId() @@ -306,7 +311,7 @@ function MainComp:refreshRedPoint() self.dailyChallengeBtn:removeRedPoint() end - if DataManager.ChapterData:showRedPoint() then + if DataManager.ChapterData:getChapterBoxCanGet() then self.chapterBoxBtn:addRedPoint(20, 20, 1) else self.chapterBoxBtn:removeRedPoint() diff --git a/lua/app/ui/tips/reward_box.lua b/lua/app/ui/tips/reward_box.lua index e4495001..7ef1573b 100644 --- a/lua/app/ui/tips/reward_box.lua +++ b/lua/app/ui/tips/reward_box.lua @@ -1,7 +1,7 @@ local BaseTips = require "app/ui/tips/base_tips" local RewardBox = class("RewardBox", BaseTips) -local CELL_WIDTH = 130 +local CELL_WIDTH = 120 local CELL_NUM = 5 function RewardBox:ctor(params) @@ -39,16 +39,16 @@ function RewardBox:onLoadRootComplete() uiMap["reward_box.continue_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.CLICK_CLOSE_DESC)) self:_refreshScrollRect() - uiMap["reward_box.effect_node.ui_spine_obj"]:playAnim("idle", false, false) + uiMap["reward_box.effect_node.ui_spine_obj"]:playAnim("idle", true, true) end function RewardBox:_refreshScrollRect() if #self.params.rewards <= 5 then - self.scrollView:setSizeDeltaX(#self.params.rewards*CELL_WIDTH) + self.scrollView:setSizeDelta(#self.params.rewards*CELL_WIDTH, 120) self.scrollRect:setPerLineNum(#self.params.rewards) self.scrollRect:refillCells(#self.params.rewards, true) else - self.scrollView:setSizeDeltaX(CELL_WIDTH*5) + self.scrollView:setSizeDelta(CELL_WIDTH*5, 314) self.scrollRect:setPerLineNum(CELL_NUM) self.scrollRect:refillCells(#self.params.rewards, true) end diff --git a/lua/app/userdata/chapter/chapter_data.lua b/lua/app/userdata/chapter/chapter_data.lua index 18817e34..43266edc 100644 --- a/lua/app/userdata/chapter/chapter_data.lua +++ b/lua/app/userdata/chapter/chapter_data.lua @@ -16,6 +16,8 @@ function ChapterData:clear() self.trailHeroId = nil self.trailChapterId = nil self.trailAtkInfo = nil + self.boxCanGetState = nil + self.canGetBoxInfo = nil end function ChapterData:init(data, notChangeChapterId) @@ -47,6 +49,8 @@ function ChapterData:init(data, notChangeChapterId) end self.data.chapterInfo = data.chapter_info or {} + self.boxCanGetState = nil + self.canGetBoxInfo = {} end function ChapterData:getIsFirstChapter(chapterId) @@ -150,6 +154,45 @@ function ChapterData:getChapterBoxNum(chapterId, index) return 1 end +function ChapterData:getChapterBoxCanGet() + if self.boxCanGetState == nil then + self:calcChapterBoxCanGet() + end + return self.boxCanGetState or false +end + +function ChapterData:calcChapterBoxCanGet() + for chapterId = 1, self.data.maxChapterId do + for ii = 1, 3 do + local canGet = not self:getChapterBoxRewardGot(chapterId, ii) + if canGet then + self.boxCanGetState = true + return + end + end + end + self.boxCanGetState = false +end + +function ChapterData:getChapterBoxCanGetInfo() + self.canGetBoxInfo = {} + local maxChapterId = self:getNextChapter(self.data.maxChapterId) + for chapterId = 1, maxChapterId do + local boxes = {} + for i = 1, 3 do + local canGet = not self:getChapterBoxRewardGot(chapterId, i) and self:boxCanGet(chapterId, i) + Logger.logHighlight("chapterId: = %s i = %s canGet = %s", chapterId, i, canGet) + if canGet then + table.insert(boxes, i) + end + end + if #boxes > 0 then + table.insert(self.canGetBoxInfo, {id = chapterId, boxes = boxes}) + end + end + return self.canGetBoxInfo +end + function ChapterData:getChapterBoxRewardGot(chapterId, index) chapterId = chapterId or self:getChapterId() local info = self.data.chapterInfo[chapterId] @@ -297,21 +340,14 @@ function ChapterData:getChapterPassed(chapterId) end end -function ChapterData:openBox(chapterId, index) - if not self.data.chapterInfo[chapterId] then - self.data.chapterInfo[chapterId] = { - total_count = 0, - index = {}, - mystery_box_idx = {} - } - end - for _, idx in ipairs(self.data.chapterInfo[chapterId].index) do - if idx == index then - return +function ChapterData:openBox() + for chapterId = 1, self.data.maxChapterId do + self.data.chapterInfo[chapterId] = self.data.chapterInfo[chapterId] or {total_count = 0, index = {}, mystery_box_idx = {}} + for i = 1, 3 do + self.data.chapterInfo[chapterId].index[i] = i end end - - table.insert(self.data.chapterInfo[chapterId].index, index) + self.boxCanGetState = nil self:setDirty() end