2023-04-11 20:11:35 +08:00

90 lines
2.8 KiB
Lua

local MainComp = class("MainComp", LuaComponent)
local CHAPTER_PATH = "assets/arts/textures/background/chapter/%s.png"
function MainComp:init()
self.uiMap = self:getBaseObject():genAllChildren()
self:initChapter()
self:initStageFormation()
self:initGM()
end
function MainComp:initChapter()
self.chapterImg = self.uiMap["main_comp.chapter.img"]
self.chapterNameTx = self.uiMap["main_comp.chapter.name_tx"]
self.leftArrow = self.uiMap["main_comp.chapter.left_arrow"]
self.leftArrow:addClickListener(function()
if DataManager.ChapterData:goLastChapter() then
self:refresh()
end
end)
self.rightArrow = self.uiMap["main_comp.chapter.right_arrow"]
self.rightArrow:addClickListener(function()
if DataManager.ChapterData:goNextChapter() then
self:refresh()
end
end)
local fightBtn = self.uiMap["main_comp.fight_btn"]
fightBtn:addClickListener(function()
self:onFightBtnClick()
end)
end
function MainComp:initStageFormation()
self.heroCells = {
self.uiMap["main_comp.hero_bg.hero_cell_1"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL),
self.uiMap["main_comp.hero_bg.hero_cell_2"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL),
self.uiMap["main_comp.hero_bg.hero_cell_3"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL),
self.uiMap["main_comp.hero_bg.hero_cell_4"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL),
self.uiMap["main_comp.hero_bg.hero_cell_5"]:addLuaComponent(GConst.TYPEOF_LUA_CLASS.HERO_CELL),
}
end
function MainComp:initGM()
self.btnGM = self.uiMap["main_comp.gm_btn"]
self.btnGM:setVisible(not Platform:getIsPublishChannel(), 2)
self.btnGM:addClickListener(function()
ModuleManager.DevToolManager:showOrHideDevListUI()
end)
end
function MainComp:refresh()
self:refreshChapter()
self:refreshStageFormaion()
end
function MainComp:onFightBtnClick()
ModuleManager.BattleManager:playBattle(GConst.BattleConst.BATTLE_TYPE.STAGE)
end
function MainComp:refreshChapter()
local chapterId = DataManager.ChapterData:getChapterId()
if self.currChapterId ~= chapterId then
self.currChapterId = chapterId
local chapterInfo = ConfigManager:getConfig("chapter")[chapterId]
local chapterI18NInfo = I18N:getConfig("chapter")[chapterId]
if chapterInfo then
self.chapterImg:setTexture(string.format(CHAPTER_PATH, chapterInfo.icon))
end
if chapterI18NInfo then
self.chapterNameTx:setText(chapterI18NInfo.name)
end
end
end
function MainComp:refreshStageFormaion()
local formation = DataManager.FormationData:getStageFormation()
for i, heroCell in ipairs(self.heroCells) do
if formation[i] then
local heroEntity = DataManager.HeroData:getHeroById(formation[i])
if heroEntity then
heroCell:refresh(heroEntity)
else
heroCell:setVisible(false)
end
else
heroCell:setVisible(false)
end
end
end
return MainComp