diff --git a/lua/app/config/strings/cn/global.lua b/lua/app/config/strings/cn/global.lua index 834f0247..bf38bcbe 100644 --- a/lua/app/config/strings/cn/global.lua +++ b/lua/app/config/strings/cn/global.lua @@ -11,6 +11,8 @@ local localization_global = ["BTN_TEXT_CANCEL"] = "取消", ["BTN_TEXT_OK"] = "确定", ["BATTLE_DESC_1"] = "是否退出战斗", + + ["START_DESC"] = "开始", } return localization_global \ No newline at end of file diff --git a/lua/app/module/battle/controller/battle_controller_stage.lua b/lua/app/module/battle/controller/battle_controller_stage.lua index 4a70b8dd..6f64e95d 100644 --- a/lua/app/module/battle/controller/battle_controller_stage.lua +++ b/lua/app/module/battle/controller/battle_controller_stage.lua @@ -2,7 +2,7 @@ local BattleController = require "app/module/battle/controller/battle_controller local BattleControllerStage = class("BattleControllerStage", BattleController) function BattleController:getChapterId() - return 1 -- 临时 + return DataManager.ChapterData:getChapterId() end function BattleControllerStage:getInitBoard() diff --git a/lua/app/ui/main_city/component/main_comp.lua b/lua/app/ui/main_city/component/main_comp.lua index e952236e..06db7c90 100644 --- a/lua/app/ui/main_city/component/main_comp.lua +++ b/lua/app/ui/main_city/component/main_comp.lua @@ -1,6 +1,11 @@ local MainComp = class("MainComp", LuaComponent) local CHAPTER_PATH = "assets/arts/textures/background/chapter/%s.png" +local BOX_ICON = { + "common_chest_1", + "common_chest_2" +} + function MainComp:init() self.uiMap = self:getBaseObject():genAllChildren() self:initChapter() @@ -56,9 +61,9 @@ function MainComp:onFightBtnClick() ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE) end -function MainComp:refreshChapter() +function MainComp:refreshChapter(force) local chapterId = DataManager.ChapterData:getChapterId() - if self.currChapterId ~= chapterId then + if self.currChapterId ~= chapterId or force then self.currChapterId = chapterId local chapterInfo = ConfigManager:getConfig("chapter")[chapterId] local chapterI18NInfo = I18N:getConfig("chapter")[chapterId] @@ -68,6 +73,45 @@ function MainComp:refreshChapter() if chapterI18NInfo then self.chapterNameTx:setText(chapterI18NInfo.name) end + + local slider = self.uiMap["main_comp.chapter.progress_bg.slider"] + if not self.boxObjs then + self.boxObjs = {} + for i = 1, 3 do + self.boxObjs[i] = { + box = self.uiMap["main_comp.chapter.progress_bg.box_" .. i], + desc = self.uiMap["main_comp.chapter.progress_bg.box_desc_" .. i] + } + end + end + + local boxCount = DataManager.ChapterData:getChapterBoxCount() + slider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = DataManager.ChapterData:getChapterMaxWave() / boxCount + for index, objs in ipairs(self.boxObjs) do + local show = boxCount >= index + objs.box:setActive(show) + objs.desc:setActive(show) + if show then + local x = 370 * (index / boxCount) + local rewards = DataManager.ChapterData:getChapterBoxByIndex(nil, index) + local num = DataManager.ChapterData:getChapterBoxNum(nil, index) + local rewardGot = DataManager.ChapterData:getChapterBoxRewardGot(nil, index) + local icon = BOX_ICON[1] + if rewardGot then + icon = BOX_ICON[2] + end + objs.box:addClickListener(function() + ModuleManager.TipsManager:showRewardsTips(rewards, nil, objs.box) + end) + objs.box:setSprite(GConst.ATLAS_PATH.COMMON, icon) + objs.box:setAnchoredPositionX(x) + objs.desc:setAnchoredPositionX(x) + objs.desc:setText(num) + end + end + + self.uiMap["main_comp.fight_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.START_DESC)) + self.uiMap["main_comp.fight_btn.desc_2"]:setText(DataManager.ChapterData:getFightCost()) end end diff --git a/lua/app/userdata/chapter/chapter_data.lua b/lua/app/userdata/chapter/chapter_data.lua index d5c148a8..f9910894 100644 --- a/lua/app/userdata/chapter/chapter_data.lua +++ b/lua/app/userdata/chapter/chapter_data.lua @@ -6,16 +6,22 @@ function ChapterData:ctor() self.data.chapterId = MIN_CHAPTER_ID self.data.maxChapterId = 0 self.data.isDirty = false + self.data.chapterBoxInfo = {} + self.data.chapterFightInfo = {} end function ChapterData:clear() self.data.chapterId = MIN_CHAPTER_ID self.data.maxChapterId = 0 + self.data.chapterBoxInfo = {} + self.data.chapterFightInfo = {} end function ChapterData:init(data) self.data.chapterId = data and data.chapterId or MIN_CHAPTER_ID self.data.maxChapterId = data and data.maxChapterId or self.data.chapterId - 1 + -- self.data.chapterBoxInfo = {} + -- self.data.chapterFightInfo = {} end function ChapterData:getChapterId() @@ -59,4 +65,69 @@ function ChapterData:getChapterCfg() return self.chapterCfg end +function ChapterData:getChapterBoxCount(chapterId) + chapterId = chapterId or self:getChapterId() + local cfg = self:getChapterCfg()[chapterId] + if cfg and cfg.box_num then + return #cfg.box_num + end + + return 1 +end + +function ChapterData:getChapterBoxNum(chapterId, index) + chapterId = chapterId or self:getChapterId() + local cfg = self:getChapterCfg()[chapterId] + if cfg and cfg.box_num then + return cfg.box_num[index] + end +end + +function ChapterData:getChapterBoxByIndex(chapterId, index) + chapterId = chapterId or self:getChapterId() + if not self:getChapterBoxNum(chapterId, index) then + return + end + + local cfg = self:getChapterCfg()[chapterId] + if cfg then + return cfg["box_reward_" .. index] + end +end + +function ChapterData:getChapterBoxRewardGot(chapterId, index) + chapterId = tostring(chapterId or self:getChapterId()) + local list = self.data.chapterBoxInfo[chapterId] + if not list then + return false + end + + for _, idx in ipairs(list) do + if idx == index then + return true + end + end + + return false +end + +function ChapterData:getChapterMaxWave(chapterId) + chapterId = tostring(chapterId or self:getChapterId()) + if self.data.chapterFightInfo[chapterId] then + return self.data.chapterFightInfo[chapterId].maxWave + end + + return 0 +end + +function ChapterData:getFightCost(chapterId) + chapterId = chapterId or self:getChapterId() + local cfg = self:getChapterCfg()[chapterId] + if cfg and cfg.cost then + return cfg.cost.num + end + + return 0 +end + return ChapterData \ No newline at end of file