local MainComp = class("MainComp", LuaComponent) local CHAPTER_COMP = "app/ui/main_city/component/chapter_comp" local DAILY_CHALLENGE_COMP = "app/ui/main_city/component/daily_challenge_comp" local MODULE_DATA = { [1] = { ["type"] = GConst.MainCityConst.BOTTOM_MODULE_KEY.DAILY_CHALLENGE, ["title"] = "每日挑战",-- 标题 ["atlas"] = GConst.ATLAS_PATH.ICON_ITEM,-- 图集路径 ["icon"] = "1",-- 图片名 ["numFunc"] = function()-- 挑战按钮显示数值 return nil end, ["clickFunc"] = function()-- 点击回调 Logger.logHighlight("点击每日挑战") end }, [2] = { ["type"] = GConst.MainCityConst.BOTTOM_MODULE_KEY.CHAPTER, ["title"] = "主线章节", ["atlas"] = GConst.ATLAS_PATH.ICON_ITEM, ["icon"] = "2", ["numFunc"] = function() return DataManager.ChapterData:getFightCost() end, ["clickFunc"] = function() ModuleManager.ChapterManager:startFight() end } } function MainComp:init() self.uiMap = self:getBaseObject():genAllChildren() self.curModuleType = GConst.MainCityConst.BOTTOM_MODULE_KEY.CHAPTER self:initStageFormation() self:refreshBtns() self:refreshModuleComp() end function MainComp:refreshModuleComp() if not self.chapterComp then -- 章节 local chapterComp = self.uiMap["main_comp.chapter_comp"] chapterComp:initPrefabHelper() chapterComp:genAllChildren() self.chapterComp = chapterComp:addLuaComponent(CHAPTER_COMP) self.chapterComp.root = self end if not self.dailyChallengeComp then -- 每日挑战 local dailyChallengeComp = self.uiMap["main_comp.daily_challenge_comp"] dailyChallengeComp:initPrefabHelper() dailyChallengeComp:genAllChildren() dailyChallengeComp:setActive(false) self.dailyChallengeComp = dailyChallengeComp:addLuaComponent(DAILY_CHALLENGE_COMP) self.dailyChallengeComp.root = self end self.chapterComp:getBaseObject():setActive(false) self.dailyChallengeComp:getBaseObject():setActive(false) if self.curModuleType == GConst.MainCityConst.BOTTOM_MODULE_KEY.CHAPTER then self.chapterComp:getBaseObject():setActive(true) elseif self.curModuleType == GConst.MainCityConst.BOTTOM_MODULE_KEY.DAILY_CHALLENGE then self.dailyChallengeComp:getBaseObject():setActive(true) end end function MainComp:refreshBtns() self:refreshFightBtn() self:refreshLeftBtn() self:refreshRightBtn() end function MainComp:refreshFightBtn() local module = nil for type, data in pairs(MODULE_DATA) do if self.curModuleType == type then module = data end end if not module then return end self.uiMap["main_comp.fight_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.START_DESC)) local cost = module["numFunc"]() if cost then self.uiMap["main_comp.fight_btn.desc_2"]:setText(GFunc.getRewardNum(cost)) else self.uiMap["main_comp.fight_btn.desc_2"]:setText("0") end self.uiMap["main_comp.fight_btn"]:addClickListener(module["clickFunc"]) end function MainComp:refreshLeftBtn() local module = MODULE_DATA[self:getCurLeftModuleIdx()] if module == nil then self.uiMap["main_comp.left_btn"]:setActive(false) return end self.uiMap["main_comp.left_btn"]:setActive(true) self.uiMap["main_comp.left_btn.desc"]:setText(module["title"]) self.uiMap["main_comp.left_btn.icon"]:setSprite(module["atlas"],module["icon"]) self.uiMap["main_comp.left_btn"]:addClickListener(function() self.curModuleType = module["type"] self:refreshBtns() self:refreshModuleComp() end) end function MainComp:refreshRightBtn() local module = MODULE_DATA[self:getCurRightModuleIdx()] if module == nil then self.uiMap["main_comp.right_btn"]:setActive(false) return end self.uiMap["main_comp.right_btn"]:setActive(true) self.uiMap["main_comp.right_btn.desc"]:setText(module["title"]) self.uiMap["main_comp.right_btn.icon"]:setSprite(module["atlas"],module["icon"]) self.uiMap["main_comp.right_btn"]:addClickListener(function() self.curModuleType = module["type"] self:refreshBtns() self:refreshModuleComp() end) end function MainComp:getCurLeftModuleIdx() for idx, data in pairs(MODULE_DATA) do if self.curModuleType == data["type"] then if idx == 1 then return nil else return idx - 1 end end end end function MainComp:getCurRightModuleIdx() for idx, data in pairs(MODULE_DATA) do if self.curModuleType == data["type"] then if idx == #MODULE_DATA then return nil else return idx + 1 end end 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:refresh() self:refreshStageFormaion() end function MainComp:refreshChapter(force) self.chapterComp:refreshChapter(force) 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:setVisible(true, 0.84) heroCell:refresh(heroEntity) heroCell:addClickListener(function() ModuleManager.HeroManager:showHeroDetailUI(heroEntity:getCfgId()) end) else heroCell:setVisible(false) end else heroCell:setVisible(false) end end end return MainComp