Merge branch 'dev_chapter' into dev_hero

This commit is contained in:
puxuan 2025-07-07 21:39:51 +08:00
commit 32532ed93c
2 changed files with 143 additions and 207 deletions

View File

@ -5,7 +5,7 @@ CurrencyBar.cellWidth = 162
CurrencyBar.cellHeight = 40
local OFFSET_X = -20
local OFFSET_Y = -40
local OFFSET_Y = -110
function CurrencyBar:init()
self.currVisible = true

View File

@ -5,216 +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()
self.uiMap = self:getBaseObject():genAllChildren()
self.chapterImg = self.uiMap["main_comp.img"]
self.chapterNameTx = self.uiMap["main_comp.name_tx"]
self.chapterWavetx = self.uiMap["main_comp.record_tx"]
self.leftArrow = self.uiMap["main_comp.left_arrow"]
local leftArrowBtn = self.uiMap["main_comp.left_arrow.btn"]
leftArrowBtn:addClickListener(function()
if DataManager.ChapterData:goLastChapter() then
self:refresh()
end
end)
self.rightArrow = self.uiMap["main_comp.right_arrow"]
local rightArrowBtn = self.uiMap["main_comp.right_arrow.btn"]
rightArrowBtn:addClickListener(function()
if DataManager.ChapterData:goNextChapter() then
self:refresh()
end
end)
self.uiMap["main_comp.effect_node.ui_spine_obj"]:playAnim("idle", true, false)
self.chapterBg = self.uiMap["main_comp.bg"]
self.chapterBg:setAnchoredPositionX(-720)
self.bossSmoke = self.uiMap["main_comp.boss_smoke"]
self.bossSmoke:setAnchoredPositionX(10000)
self.smokeNodeTop = self.uiMap["main_comp.smoke_node_1"]
self.monsterNodeTop = self.uiMap["main_comp.monster_node_1"]
self.bossNode = self.uiMap["main_comp.boss_node"]
self.bossNode:setActive(false)
self.bossSpine = self.uiMap["main_comp.boss_node.boss"]
self.smokeNodeDown = self.uiMap["main_comp.smoke_node_2"]
self.monsterNodeDown = self.uiMap["main_comp.monster_node_2"]
self.dialogueTx = self.uiMap["main_comp.dialogue_node.bg.text"]
self.dialogueBg = self.uiMap["main_comp.dialogue_node.bg"]
self.dialogueNode = self.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 = self.uiMap["main_comp.fight_btn"]
-- 体力消耗
self.fightCost = self.uiMap["main_comp.fight_btn.cost"]
self.costTxDesc = self.uiMap["main_comp.fight_btn.cost.tx_desc"]
self.costTxCost = self.uiMap["main_comp.fight_btn.cost.tx_cost"]
-- 按钮文本
self.txFight = self.uiMap["main_comp.fight_btn.tx_desc"]
self.fightBtn:addClickListener(function ()
ModuleManager.ChapterManager:startFight()
end)
self.uiMap["main_comp.arena_btn"]:addClickListener(function()
ModuleManager.ArenaManager:reqArenaInfo(true)
end)
self.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
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))
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"))
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 = self.uiMap["main_comp.progress_bg.slider"]
if not self.boxObjs then
self.boxObjs = {}
for i = 1, 3 do
self.boxObjs[i] = {
box = self.uiMap["main_comp.progress_bg.box_" .. i],
desc = self.uiMap["main_comp.progress_bg.box_desc_" .. i],
spineObj = self.uiMap["main_comp.progress_bg.spine_node.ui_spine_obj_" .. i],
boxIcon = self.uiMap["main_comp.progress_bg.box_" .. i .. ".box_icon"]
}
end
end
local mysteryBoxCount = DataManager.ChapterData:getChapterMysteryBoxRewardCount(chapterId)
local mysteryBoxBg = self.uiMap["main_comp.img.bg"]
mysteryBoxBg:setVisible(mysteryBoxCount > 0)
local mysteryBoxIcon = self.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)
self.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
end
self:refreshFightBtn()
self:doBossAction()
end
self:doChapterMove()
self:doMonsterAction()
end
function MainComp:onOpen()
self.startMonsterAction = true
if self.bossNode then
@ -254,14 +51,153 @@ 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()
self.fightCost:setActive(true)
self.costTxDesc:setText(I18N:getGlobalText(I18N.GlobalConst.START_DESC))
self.txFight:setText(I18N:getGlobalText(I18N.GlobalConst.START_DESC))
self.costTxCost:setText(GFunc.getRewardNum(cost))
end
function MainComp:refreshChapterInfo()
local chapterId = DataManager.ChapterData:getChapterId()
local chapterMaxId = DataManager.ChapterData:getMaxChapterId()
local idx = (chapterId - 1) % CHAPTER_PAGE + 1
for i = 1, CHAPTER_PAGE do
if idx == i then
self.chapterSelectImg:setAnchoredPositionX((i - 3) * 98)
end
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
local chapterI18NInfo = I18N:getConfig("chapter")[chapterId]
if chapterI18NInfo then
self.chapterTx:setText(chapterI18NInfo.name)
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
-- region 动画
function MainComp:doChapterMove()
if self.chapterMoveSeq then