2023-04-07 20:50:11 +08:00

62 lines
1.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: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: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()
end
function MainComp:onFightBtnClick()
ModuleManager.BattleManager:playBattle(nil, 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
return MainComp