From 4d7cd6e0456c918a9fba41c7a2d57385abe9d253 Mon Sep 17 00:00:00 2001 From: puxuan <413323644@qq.com> Date: Mon, 7 Jul 2025 21:38:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BB=E7=95=8C=E9=9D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lua/app/ui/main_city/component/main_comp.lua | 349 +++++++------------ 1 file changed, 129 insertions(+), 220 deletions(-) diff --git a/lua/app/ui/main_city/component/main_comp.lua b/lua/app/ui/main_city/component/main_comp.lua index 5a17619b..4d53c5d3 100644 --- a/lua/app/ui/main_city/component/main_comp.lua +++ b/lua/app/ui/main_city/component/main_comp.lua @@ -5,105 +5,13 @@ local UISpineObject = require "app/bf/unity/ui_spine_object" -- local CHAPTER_PATH = "assets/arts/textures/background/chapter/%s.png" local HERO_SPINE_ASSET_PATH = "assets/arts/spines/characters/%s/%s_skeletondata.asset" local CHAPTER_PATH = "assets/arts/textures/background/main/%s.png" +local CHAPTER_PAGE = 5 local BOX_ICON = { "common_chest_1", "common_chest_4" } -function MainComp:init() - local uiMap = self:getBaseObject():genAllChildren() - - self.chapterImg = uiMap["main_comp.img"] - self.chapterNameTx = uiMap["main_comp.name_tx"] - self.chapterWavetx = uiMap["main_comp.record_tx"] - self.leftArrow = uiMap["main_comp.middle_bg.left_arrow"] - local leftArrowBtn = uiMap["main_comp.middle_bg.left_arrow.btn"] - leftArrowBtn:addClickListener(function() - if DataManager.ChapterData:goLastChapter() then - self:refresh() - end - end) - self.rightArrow = uiMap["main_comp.middle_bg.right_arrow"] - local rightArrowBtn = uiMap["main_comp.middle_bg.right_arrow.btn"] - rightArrowBtn:addClickListener(function() - if DataManager.ChapterData:goNextChapter() then - self:refresh() - end - end) - - uiMap["main_comp.effect_node.ui_spine_obj"]:playAnim("idle", true, false) - - self.chapterBg = uiMap["main_comp.bg"] - self.chapterBg:setAnchoredPositionX(-720) - self.bossSmoke = uiMap["main_comp.boss_smoke"] - self.bossSmoke:setAnchoredPositionX(10000) - self.smokeNodeTop = uiMap["main_comp.smoke_node_1"] - self.monsterNodeTop = uiMap["main_comp.monster_node_1"] - self.bossNode = uiMap["main_comp.boss_node"] - self.bossNode:setActive(false) - self.bossSpine = uiMap["main_comp.boss_node.boss"] - self.smokeNodeDown = uiMap["main_comp.smoke_node_2"] - self.monsterNodeDown = uiMap["main_comp.monster_node_2"] - self.dialogueTx = uiMap["main_comp.dialogue_node.bg.text"] - self.dialogueBg = uiMap["main_comp.dialogue_node.bg"] - self.dialogueNode = uiMap["main_comp.dialogue_node"] - self.dialogueNode:setAnchoredPositionX(0) - self.monsterSpineTopPool = {} - self.monsterSpineDownPool = {} - self.monsterSpineTopList = {} - self.monsterSpineDownList = {} - -- self.monsterShadowPool = {} - self.monsterSmokePool = {} - self.startMonsterAction = true - - self.fightBtn = uiMap["main_comp.fight_btn"] - -- 体力消耗 - self.fightCost = uiMap["main_comp.fight_btn.cost"] - self.costTxCost = uiMap["main_comp.fight_btn.cost.tx_cost"] - -- 按钮文本 - self.txFight = uiMap["main_comp.fight_btn.tx_desc"] - self.fightBtn:addClickListener(function () - ModuleManager.ChapterManager:startFight() - end) - - self.chapterMiddleBg = uiMap["main_comp.middle_bg"] - self.chapterTx = uiMap["main_comp.middle_bg.chapter_tx"] - self.chapterMaxTx = uiMap["main_comp.middle_bg.max_tx"] - self.chapterInfoBtn = uiMap["main_comp.middle_bg.info_btn"] - self.chapterBoxBtn = uiMap["main_comp.middle_bg.box_btn"] - self.chapterPageBtns = {} - self.chapterPageBtnCheckImgs = {} - self.chapterPageBtnDescTxs = {} - for i = 1, 5 do - self.chapterPageBtns[i] = uiMap["main_comp.middle_bg.page_btn_" .. i] - self.chapterPageBtnCheckImgs[i] = uiMap["main_comp.middle_bg.page_btn_" .. i .. ".check_img"] - self.chapterPageBtnDescTxs[i] = uiMap["main_comp.middle_bg.page_btn_" .. i .. ".desc_tx"] - end - - uiMap["main_comp.arena_btn"]:addClickListener(function() - ModuleManager.ArenaManager:reqArenaInfo(true) - end) - uiMap["main_comp.daily_challenge_btn"]:addClickListener(function() - ModuleManager.DailyChallengeManager:showDailyChallengeUI() - end) -end - -function MainComp:refresh() - self:refreshChapter() -end - -function MainComp:refreshChapter(force) - local chapterId = DataManager.ChapterData:getChapterId() - if self.currChapterId ~= chapterId or force then - self:refreshChapterInfo() - self:refreshFightBtn() - self:doBossAction() - end - self:doChapterMove() - self:doMonsterAction() -end - function MainComp:onOpen() self.startMonsterAction = true if self.bossNode then @@ -143,6 +51,118 @@ function MainComp:onClose() self.smokeNodeDown:removeAllChildren() end +function MainComp:init() + local uiMap = self:getBaseObject():genAllChildren() + + uiMap["main_comp.arena_btn.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.ARENA_DESC_1)) + uiMap["main_comp.daily_challenge_btn.text"]:setText(I18N:getGlobalText(I18N.GlobalConst.DAILY_CHALLENGE)) + + self.chapterBg = uiMap["main_comp.bg"] + self.chapterBg:setAnchoredPositionX(-720) + self.bossSmoke = uiMap["main_comp.boss_smoke"] + self.bossSmoke:setAnchoredPositionX(10000) + self.smokeNodeTop = uiMap["main_comp.smoke_node_1"] + self.monsterNodeTop = uiMap["main_comp.monster_node_1"] + self.bossNode = uiMap["main_comp.boss_node"] + self.bossNode:setActive(false) + self.bossSpine = uiMap["main_comp.boss_node.boss"] + self.smokeNodeDown = uiMap["main_comp.smoke_node_2"] + self.monsterNodeDown = uiMap["main_comp.monster_node_2"] + self.monsterSpineTopPool = {} + self.monsterSpineDownPool = {} + self.monsterSpineTopList = {} + self.monsterSpineDownList = {} + -- self.monsterShadowPool = {} + self.monsterSmokePool = {} + self.startMonsterAction = true + + self.fightBtn = uiMap["main_comp.fight_btn"] + -- 体力消耗 + self.fightCost = uiMap["main_comp.fight_btn.cost"] + self.costTxCost = uiMap["main_comp.fight_btn.cost.tx_cost"] + -- 按钮文本 + self.txFight = uiMap["main_comp.fight_btn.tx_desc"] + self.fightBtn:addClickListener(function () + ModuleManager.ChapterManager:startFight() + end) + + self.leftArrowBtn = uiMap["main_comp.middle_bg.left_arrow.btn"] + self.rightArrowBtn = uiMap["main_comp.middle_bg.right_arrow.btn"] + + self.leftBtn = uiMap["main_comp.left_btn"] + self.rightBtn = uiMap["main_comp.right_btn"] + + self.chapterMiddleBg = uiMap["main_comp.middle_bg"] + self.chapterTx = uiMap["main_comp.middle_bg.chapter_tx"] + self.chapterMaxTx = uiMap["main_comp.middle_bg.max_tx"] + self.chapterInfoBtn = uiMap["main_comp.middle_bg.info_btn"] + self.chapterBoxBtn = uiMap["main_comp.middle_bg.box_btn"] + self.chapterSelectImg = uiMap["main_comp.middle_bg.select_img"] + self.chapterPageBtns = {} + self.chapterPageBtnCheckImgs = {} + self.chapterPageBtnDescTxs = {} + self.chapterPageBtnMaskImgs = {} + for i = 1, CHAPTER_PAGE do + self.chapterPageBtns[i] = uiMap["main_comp.middle_bg.page_btn_" .. i] + self.chapterPageBtnCheckImgs[i] = uiMap["main_comp.middle_bg.page_btn_" .. i .. ".check_img"] + self.chapterPageBtnDescTxs[i] = uiMap["main_comp.middle_bg.page_btn_" .. i .. ".desc_tx"] + self.chapterPageBtnMaskImgs[i] = uiMap["main_comp.middle_bg.page_btn_" .. i .. ".mask_img"] + self.chapterPageBtns[i]:addClickListener(function() + local chapterId = DataManager.ChapterData:getChapterId() + local selChapterId = ((chapterId - 1) // CHAPTER_PAGE) * CHAPTER_PAGE + i + DataManager.ChapterData:setChapterId(selChapterId) + self:refresh() + end) + end + + uiMap["main_comp.arena_btn"]:addClickListener(function() + ModuleManager.ArenaManager:reqArenaInfo(true) + end) + uiMap["main_comp.daily_challenge_btn"]:addClickListener(function() + ModuleManager.DailyChallengeManager:showDailyChallengeUI() + end) + self.leftArrowBtn:addClickListener(function() + local chapterId = DataManager.ChapterData:getChapterId() + DataManager.ChapterData:setChapterId(chapterId - CHAPTER_PAGE) + self:refresh() + end) + self.rightArrowBtn:addClickListener(function() + local chapterId = DataManager.ChapterData:getChapterId() + DataManager.ChapterData:setChapterId(chapterId + CHAPTER_PAGE) + self:refresh() + end) + self.leftBtn:addClickListener(function() + end) + self.rightBtn:addClickListener(function() + end) +end + +function MainComp:refresh() + self:refreshChapter() +end + +function MainComp:refreshChapter(force) + local chapterId = DataManager.ChapterData:getChapterId() + self.currChapterId = chapterId + if self.currChapterId ~= chapterId or force then + self:refreshFightBtn() + self:doBossAction() + end + self:refreshChapterInfo() + self:doChapterMove() + self:doMonsterAction() + self:refreshChapterBtn() +end + +function MainComp:refreshChapterBtn() + local chapterId = DataManager.ChapterData:getChapterId() + local chapterMaxId = DataManager.ChapterData:getMaxChapterId() + local page = (chapterId - 1) // CHAPTER_PAGE + local maxPage = chapterMaxId // CHAPTER_PAGE + self.leftArrowBtn:setActive(page > 0) + self.rightArrowBtn:setActive(page < maxPage) +end + function MainComp:refreshFightBtn() -- 体力消耗 local cost = DataManager.ChapterData:getFightCost() @@ -153,139 +173,28 @@ end function MainComp:refreshChapterInfo() local chapterId = DataManager.ChapterData:getChapterId() - local idx = (chapterId - 1) % 5 + 1 - for i = 1, 5 do + local chapterMaxId = DataManager.ChapterData:getMaxChapterId() + local idx = (chapterId - 1) % CHAPTER_PAGE + 1 + for i = 1, CHAPTER_PAGE do if idx == i then - else + self.chapterSelectImg:setAnchoredPositionX((i - 3) * 98) end - end -end - -function MainComp:refreshChapterInfo2() - local chapterId = DataManager.ChapterData:getChapterId() - if DataManager.ChapterData:getIsFirstChapter(chapterId) then -- 第一章不需要左箭头 - self.leftArrow:setVisible(false) - self.rightArrow:setVisible(DataManager.ChapterData:getMaxChapterId() >= 1) - elseif chapterId == DataManager.ChapterData:getMaxChapterId() + 1 then -- 只能看打的最远的关卡 - self.leftArrow:setVisible(true) - self.rightArrow:setVisible(false) - else - self.leftArrow:setVisible(true) - self.rightArrow:setVisible(not DataManager.ChapterData:isFinalChapter(chapterId)) + self.chapterPageBtnDescTxs[i]:setText(i) + local selChapterId = ((chapterId - 1) // CHAPTER_PAGE) * CHAPTER_PAGE + i + self.chapterPageBtnCheckImgs[i]:setActive(selChapterId <= chapterMaxId) + self.chapterPageBtnMaskImgs[i]:setActive(selChapterId > (chapterMaxId + 1)) end - self.currChapterId = chapterId - local chapterInfo = ConfigManager:getConfig("chapter")[chapterId] local chapterI18NInfo = I18N:getConfig("chapter")[chapterId] - if chapterInfo then - local monsterIdList = chapterInfo.monster_id - if monsterIdList then - local bossId = monsterIdList[1] - if bossId then - local monsterCfg = ConfigManager:getConfig("monster_base") - local monsterInfo = monsterCfg[bossId] - if monsterInfo then - -- self.dialogueBg:setAnchoredPositionY(monsterInfo.blood * monsterInfo.ui/10 + 20) - end - end - end - -- main_bg_1 - -- self.chapterBg:setTexture(string.format(CHAPTER_PATH, chapterInfo.scenes_a)) end - self.chapterBg:setTexture(string.format(CHAPTER_PATH, "main_bg_1")) + if chapterI18NInfo then + self.chapterTx:setText(chapterI18NInfo.name) end - if chapterI18NInfo then - self.chapterNameTx:setText(chapterI18NInfo.name) - end - self.chapterWavetx:setText(I18N:getGlobalText(I18N.GlobalConst.CHAPTER_DESC_1, DataManager.ChapterData:getChapterMaxWave())) - - local slider = uiMap["main_comp.progress_bg.slider"] - if not self.boxObjs then - self.boxObjs = {} - for i = 1, 3 do - self.boxObjs[i] = { - box = uiMap["main_comp.progress_bg.box_" .. i], - desc = uiMap["main_comp.progress_bg.box_desc_" .. i], - spineObj = uiMap["main_comp.progress_bg.spine_node.ui_spine_obj_" .. i], - boxIcon = uiMap["main_comp.progress_bg.box_" .. i .. ".box_icon"] - } - end - end - - local mysteryBoxCount = DataManager.ChapterData:getChapterMysteryBoxRewardCount(chapterId) - local mysteryBoxBg = uiMap["main_comp.img.bg"] - mysteryBoxBg:setVisible(mysteryBoxCount > 0) - local mysteryBoxIcon = uiMap["main_comp.img.mystery_box_icon"] - mysteryBoxIcon:setVisible(mysteryBoxCount > 0) - if mysteryBoxCount > 0 then - local gotCount = DataManager.ChapterData:getChapterMysteryBoxGotCount(chapterId) - local desc = I18N:getGlobalText(I18N.GlobalConst.CHAPTER_DESC_2, gotCount, mysteryBoxCount) - uiMap["main_comp.img.mystery_box_icon.desc"]:setText(desc) - end - - local rewardChapterId = DataManager.ChapterData:getIsHaveRewardsMinId() - if rewardChapterId > chapterId then - rewardChapterId = chapterId - end - - local curMaxWave = DataManager.ChapterData:getChapterMaxWave(rewardChapterId) - local boxCount = DataManager.ChapterData:getChapterBoxCount(rewardChapterId) - local unitValue = 1 / boxCount - local sliderValue = 0 - local lastValue = 0 - for i = 1, boxCount do - if curMaxWave < lastValue then - break - end - local maxWave = DataManager.ChapterData:getChapterBoxNum(rewardChapterId, i) - local wave = math.min(curMaxWave, maxWave) - sliderValue = sliderValue + unitValue * (wave - lastValue) / (maxWave - lastValue) - lastValue = maxWave - end - slider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = sliderValue - - for index, objs in ipairs(self.boxObjs) do - local show = boxCount >= index - objs.box:setActive(show) - objs.desc:setActive(show) - objs.spineObj:setVisible(false) - if show then - local needWave = DataManager.ChapterData:getChapterBoxNum(rewardChapterId, index) - local x = 370 * (index / boxCount) - local rewards = DataManager.ChapterData:getChapterBoxRewards(rewardChapterId, index) - local num = DataManager.ChapterData:getChapterBoxNum(rewardChapterId, index) - local rewardGot = DataManager.ChapterData:getChapterBoxRewardGot(rewardChapterId, index) - local icon = BOX_ICON[1] - if rewardGot then - icon = BOX_ICON[2] - end - objs.box:addClickListener(function() - if needWave <= curMaxWave and not rewardGot then - objs.spineObj:setVisible(true) - objs.spineObj:playAnimComplete("open", false, false, function() - ModuleManager.ChapterManager:openBox(rewardChapterId, index) - end) - else - ModuleManager.TipsManager:showRewardsTips(rewards, nil, objs.box) - end - end) - objs.boxIcon:setSprite(GConst.ATLAS_PATH.COMMON, icon) - objs.box:setAnchoredPositionX(x) - if needWave <= curMaxWave and not rewardGot then - objs.spineObj:setVisible(true) - objs.spineObj:playAnim("idle", true, false) - objs.spineObj:setAnchoredPositionX(x) - objs.boxIcon:setVisible(false) - else - objs.spineObj:setVisible(false) - objs.boxIcon:setVisible(true) - end - objs.desc:setAnchoredPositionX(x) - if boxCount == index then - objs.desc:setText(I18N:getGlobalText(I18N.GlobalConst.MAIN_DESC_1, rewardChapterId)) - else - objs.desc:setText(num) - end - end + if chapterId <= chapterMaxId then + self.chapterMaxTx:setText(I18N:getGlobalText(I18N.GlobalConst.DUNGEON_ARMOR_DESC_7)) + elseif chapterId == chapterMaxId + 1 then + self.chapterMaxTx:setText(I18N:getGlobalText(I18N.GlobalConst.CHAPTER_DESC_1, DataManager.ChapterData:getChapterMaxWave())) + else + self.chapterMaxTx:setText(I18N:getGlobalText(I18N.GlobalConst.EQUIP_DESC_22)) end end