248 lines
7.9 KiB
Lua
248 lines
7.9 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 DUNGEON_COMP = "app/ui/main_city/component/dungeon_comp"
|
|
|
|
local BOTTOM_HEIGHT = 120
|
|
|
|
function MainComp:init()
|
|
self.uiMap = self:getBaseObject():genAllChildren()
|
|
|
|
self:initStageFormation()
|
|
self:refreshModule(ModuleManager.MaincityManager:getCurModule())
|
|
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
|
|
-- 活动副本
|
|
local dungeonComp = self.uiMap["main_comp.dungeon_comp"]
|
|
self.dungeonComp = CellManager:addCellComp(dungeonComp, DUNGEON_COMP)
|
|
self.dungeonComp:initWithParentUI(self)
|
|
self.moduleMap[GConst.MainCityConst.MAIN_MODULE.DUNGEON] = self.dungeonComp
|
|
end
|
|
|
|
if self.curModuleType ~= selectModule then
|
|
self.curModuleType = selectModule
|
|
ModuleManager.MaincityManager:setCurModule(self.curModuleType)
|
|
self:setFormationVisible(true)
|
|
|
|
if self.curModuleType == GConst.MainCityConst.MAIN_MODULE.CHAPTER then
|
|
-- 切换到主线章节
|
|
elseif self.curModuleType == GConst.MainCityConst.MAIN_MODULE.DAILY_CHALLENGE then
|
|
-- 切换到每日挑战
|
|
if not DataManager.TutorialData:getIsInTutorial() and DataManager.DailyChallengeData:getIsPopTask() then
|
|
ModuleManager.DailyChallengeManager:showBattleTaskUI()
|
|
end
|
|
elseif self.curModuleType == GConst.MainCityConst.MAIN_MODULE.DUNGEON then
|
|
-- 切换到活动副本
|
|
self:setFormationVisible(false)
|
|
end
|
|
EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.CHANGE_MAIN_COMP_MODULE, self.curModuleType)
|
|
end
|
|
|
|
for idx, cell in pairs(self.moduleMap) do
|
|
cell:getBaseObject():setActive(self.curModuleType == idx)
|
|
end
|
|
|
|
self:refreshBtns()
|
|
end
|
|
|
|
function MainComp:refreshBtns()
|
|
self:refreshFightBtn()
|
|
self:refreshLeftBtn()
|
|
self:refreshRightBtn()
|
|
end
|
|
|
|
function MainComp:refreshFightBtn()
|
|
local moduleCell = self.moduleMap[self.curModuleType]
|
|
|
|
local cost = moduleCell:getHpCost()
|
|
if cost then
|
|
self.uiMap["main_comp.fight_btn"]:setActive(true)
|
|
self.uiMap["main_comp.fight_btn"]:addClickListener(moduleCell.onClickFight)
|
|
self.uiMap["main_comp.fight_btn"]:setAnchoredPositionY(self.btnPosY)
|
|
self.uiMap["main_comp.fight_btn.desc"]:setText(I18N:getGlobalText(I18N.GlobalConst.START_DESC))
|
|
self.uiMap["main_comp.fight_btn.desc_2"]:setText(GFunc.getRewardNum(cost))
|
|
else
|
|
self.uiMap["main_comp.fight_btn"]:setActive(false)
|
|
return
|
|
end
|
|
|
|
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 bgAtlas, bgName = moduleCell:getEntranceBg()
|
|
self.uiMap["main_comp.left_btn.bg"]:setSprite(bgAtlas, bgName)
|
|
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, function()
|
|
self.uiMap["main_comp.left_btn.icon"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
|
|
end)
|
|
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 bgAtlas, bgName = moduleCell:getEntranceBg()
|
|
self.uiMap["main_comp.right_btn.bg"]:setSprite(bgAtlas, bgName)
|
|
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, function()
|
|
self.uiMap["main_comp.right_btn.icon"]:getComponent(GConst.TYPEOF_UNITY_CLASS.UI_IMAGE):SetNativeSize()
|
|
end)
|
|
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 = table.nums(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),
|
|
}
|
|
|
|
self.heroFormation = self.uiMap["main_comp.hero_bg"]
|
|
local heroBgPosY = self.heroFormation:fastGetAnchoredPositionY()
|
|
local sWidth, sHeight = GFunc.getUIExpandScreenSize()
|
|
local hSHeight = sHeight / 2
|
|
self.btnPosY = (heroBgPosY + (BOTTOM_HEIGHT / 2 - hSHeight)) / 2
|
|
end
|
|
|
|
function MainComp:setFormationVisible(visible)
|
|
self.heroFormation:setVisible(visible)
|
|
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:refreshDungeon()
|
|
self:refreshBtns()
|
|
self.dungeonComp: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 |