218 lines
6.7 KiB
Lua
218 lines
6.7 KiB
Lua
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 BOTTOM_HEIGHT = 120
|
|
|
|
function MainComp:init()
|
|
self.uiMap = self:getBaseObject():genAllChildren()
|
|
|
|
self:refreshModule(GConst.MainCityConst.MAIN_MODULE.CHAPTER)
|
|
self:initStageFormation()
|
|
|
|
end
|
|
|
|
function MainComp:refreshModule(selectModule)
|
|
if not self.moduleMap then
|
|
self.moduleMap = {}
|
|
-- 章节
|
|
local chapterComp = self.uiMap["main_comp.chapter_comp"]
|
|
self.chapterComp = CellManager:addCellComp(chapterComp, CHAPTER_COMP)
|
|
self.chapterComp:initWithParentUI(self)
|
|
self.moduleMap[GConst.MainCityConst.MAIN_MODULE.CHAPTER] = self.chapterComp
|
|
-- 每日挑战
|
|
local dailyChallengeComp = self.uiMap["main_comp.daily_challenge_comp"]
|
|
self.dailyChallengeComp = CellManager:addCellComp(dailyChallengeComp, DAILY_CHALLENGE_COMP)
|
|
self.dailyChallengeComp:initWithParentUI(self)
|
|
self.moduleMap[GConst.MainCityConst.MAIN_MODULE.DAILY_CHALLENGE] = self.dailyChallengeComp
|
|
end
|
|
|
|
if self.curModuleType ~= selectModule then
|
|
self.curModuleType = selectModule
|
|
if self.curModuleType == GConst.MainCityConst.MAIN_MODULE.CHAPTER then
|
|
-- 切换到主线章节
|
|
EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.GO_CHAPTER)
|
|
elseif self.curModuleType == GConst.MainCityConst.MAIN_MODULE.DAILY_CHALLENGE then
|
|
-- 切换到每日挑战
|
|
EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.GO_DAILY_CHALLENGE)
|
|
if not Datamanager.TutorialData:getIsInTutorial() and DataManager.DailyChallengeData:getIsPopTask() then
|
|
ModuleManager.DailyChallengeManager:showBattleTaskUI()
|
|
end
|
|
end
|
|
end
|
|
|
|
for idx, cell in pairs(self.moduleMap) do
|
|
cell:getBaseObject():setActive(self.curModuleType == idx)
|
|
end
|
|
local heroBg = self.uiMap["main_comp.hero_bg"]
|
|
local heroBgPosY = heroBg:fastGetAnchoredPositionY()
|
|
local sWidth, sHeight = GFunc.getUIExpandScreenSize()
|
|
local hSHeight = sHeight / 2
|
|
self.btnPosY = (heroBgPosY + (BOTTOM_HEIGHT / 2 - hSHeight)) / 2
|
|
self:refreshBtns()
|
|
end
|
|
|
|
function MainComp:refreshBtns()
|
|
self:refreshFightBtn()
|
|
self:refreshLeftBtn()
|
|
self:refreshRightBtn()
|
|
end
|
|
|
|
function MainComp:refreshFightBtn()
|
|
local moduleCell = self.moduleMap[self.curModuleType]
|
|
|
|
self.uiMap["main_comp.fight_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.START_DESC))
|
|
local cost = moduleCell:getHpCost()
|
|
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(moduleCell.onClickFight)
|
|
self.uiMap["main_comp.fight_btn"]:setAnchoredPositionY(self.btnPosY)
|
|
|
|
local remainCount = moduleCell:getTodayRemainCount()
|
|
if remainCount >= 0 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, remainCount))
|
|
else
|
|
self.uiMap["main_comp.fight_btn.num_tx"]:setActive(false)
|
|
end
|
|
end
|
|
|
|
function MainComp:refreshLeftBtn()
|
|
if self.leftBtn == nil then
|
|
self.leftBtn = self.uiMap["main_comp.left_btn"]
|
|
end
|
|
self.leftBtn:setActive(false)
|
|
self.leftBtn:setAnchoredPositionY(self.btnPosY)
|
|
|
|
local leftIdx = self:getCurLeftModuleIdx()
|
|
if leftIdx == nil then
|
|
return
|
|
end
|
|
local moduleCell = self.moduleMap[leftIdx]
|
|
if not moduleCell:getIsOpen() then
|
|
return
|
|
end
|
|
|
|
self.leftBtn:setActive(true)
|
|
local iconAtlas, iconName = moduleCell:getEntranceIcon()
|
|
self.uiMap["main_comp.left_btn.desc"]:setText(moduleCell:getEntranceName())
|
|
self.uiMap["main_comp.left_btn.icon"]:setSprite(iconAtlas, iconName)
|
|
self.leftBtn:addClickListener(function()
|
|
self:refreshModule(leftIdx)
|
|
end)
|
|
if moduleCell:getShowEntranceRedPoint() then
|
|
self.leftBtn:addRedPoint(65, 35, 0.6)
|
|
else
|
|
self.leftBtn:removeRedPoint()
|
|
end
|
|
end
|
|
|
|
function MainComp:refreshRightBtn()
|
|
if self.rightBtn == nil then
|
|
self.rightBtn = self.uiMap["main_comp.right_btn"]
|
|
end
|
|
self.rightBtn:setActive(false)
|
|
self.rightBtn:setAnchoredPositionY(self.btnPosY)
|
|
|
|
local rightIdx = self:getCurRightModuleIdx()
|
|
if rightIdx == nil then
|
|
return
|
|
end
|
|
local moduleCell = self.moduleMap[rightIdx]
|
|
if not moduleCell:getIsOpen() then
|
|
return
|
|
end
|
|
|
|
self.rightBtn:setActive(true)
|
|
local iconAtlas, iconName = moduleCell:getEntranceIcon()
|
|
self.uiMap["main_comp.right_btn.desc"]:setText(moduleCell:getEntranceName())
|
|
self.uiMap["main_comp.right_btn.icon"]:setSprite(iconAtlas, iconName)
|
|
self.rightBtn:addClickListener(function()
|
|
self:refreshModule(rightIdx)
|
|
end)
|
|
if moduleCell:getShowEntranceRedPoint() then
|
|
self.rightBtn:addRedPoint(-65, 35, 0.6)
|
|
else
|
|
self.rightBtn:removeRedPoint()
|
|
end
|
|
end
|
|
|
|
function MainComp:getCurLeftModuleIdx()
|
|
if self.curModuleType == 1 then
|
|
return nil
|
|
end
|
|
|
|
return self.curModuleType - 1
|
|
end
|
|
|
|
function MainComp:getCurRightModuleIdx()
|
|
local totalModuleNum = GFunc.getTableLength(GConst.MainCityConst.MAIN_MODULE)
|
|
if self.curModuleType == totalModuleNum then
|
|
return nil
|
|
end
|
|
|
|
return self.curModuleType + 1
|
|
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()
|
|
self:refreshChallenge()
|
|
end
|
|
|
|
function MainComp:getCurModuleType()
|
|
return self.curModuleType
|
|
end
|
|
|
|
function MainComp:refreshChapter(force)
|
|
self.chapterComp:refreshChapter(force)
|
|
end
|
|
|
|
function MainComp:refreshChallenge()
|
|
self:refreshBtns()
|
|
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, 1)
|
|
heroCell:refresh(heroEntity)
|
|
heroCell:addClickListener(function()
|
|
ModuleManager.HeroManager:showHeroDetailUI(heroEntity:getCfgId())
|
|
end)
|
|
else
|
|
heroCell:setVisible(false)
|
|
end
|
|
else
|
|
heroCell:setVisible(false)
|
|
end
|
|
end
|
|
end
|
|
|
|
function MainComp:getDailyChallengeIconPos()
|
|
if self:getCurLeftModuleIdx() == GConst.MainCityConst.MAIN_MODULE.DAILY_CHALLENGE then
|
|
return self.leftBtn:getPosition()
|
|
end
|
|
if self:getCurRightModuleIdx() == GConst.MainCityConst.MAIN_MODULE.DAILY_CHALLENGE then
|
|
return self.rightBtn:getPosition()
|
|
end
|
|
end
|
|
|
|
return MainComp |