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.MAIN,-- 图集路径 ["icon"] = "main_dec_1",-- 图片名 ["numFunc"] = function()-- 挑战按钮显示数值 return DataManager.DailyChallengeData:getChallengeHpCost() end, ["clickFunc"] = function()-- 点击回调 ModuleManager.DailyChallengeManager:startChallenge() end, ["redDot"] = function()-- 显示红点 return DataManager.DailyChallengeData:isMeetChallenge() end, ["fightNum"] = function()-- 显示今日剩余次数 return DataManager.DailyChallengeData:getTodayRemainLimitCount() end, }, [2] = { ["type"] = GConst.MainCityConst.BOTTOM_MODULE_KEY.CHAPTER, ["title"] = "主线章节", ["atlas"] = GConst.ATLAS_PATH.COMMON, ["icon"] = "common_dec_1", ["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"]) if module["fightNum"] ~= nil then self.uiMap["main_comp.fight_btn.num_tx"]:setActive(true) self.uiMap["main_comp.fight_btn.num_tx"]:setText(I18N:getGlobalText(I18N.GlobalConst.TODAY_REMAIN_TIMES, module["fightNum"]())) else self.uiMap["main_comp.fight_btn.num_tx"]:setActive(false) end end function MainComp:refreshLeftBtn() local module = MODULE_DATA[self:getCurLeftModuleIdx()] local leftBtn = self.uiMap["main_comp.left_btn"] if module == nil then leftBtn:setActive(false) return end leftBtn:setActive(true) self.uiMap["main_comp.left_btn.desc"]:setText(module["title"]) self.uiMap["main_comp.left_btn.icon"]:setSprite(module["atlas"],module["icon"]) leftBtn:addClickListener(function() self.curModuleType = module["type"] self:refreshBtns() self:refreshModuleComp() end) if module["redDot"] ~= nil and module["redDot"]() then leftBtn:addRedPoint(65, 35, 0.6) else leftBtn:removeRedPoint() end end function MainComp:refreshRightBtn() local module = MODULE_DATA[self:getCurRightModuleIdx()] local rightBtn = self.uiMap["main_comp.right_btn"] if module == nil then rightBtn:setActive(false) return end rightBtn:setActive(true) self.uiMap["main_comp.right_btn.desc"]:setText(module["title"]) self.uiMap["main_comp.right_btn.icon"]:setSprite(module["atlas"],module["icon"]) rightBtn:addClickListener(function() self.curModuleType = module["type"] self:refreshBtns() self:refreshModuleComp() end) if module["redDot"] ~= nil and module["redDot"]() then rightBtn:addRedPoint(-65, 35, 0.6) else rightBtn:removeRedPoint() 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:refreshChallenge() self.dailyChallengeComp:refreshShow() 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