321 lines
10 KiB
Lua
321 lines
10 KiB
Lua
local MainCityUI = class("MainCityUI", BaseUI)
|
|
|
|
local BF_UI_HELPER = GConst.TYPEOF_UNITY_CLASS.BF_UI_HELPER
|
|
local HERO_COMP = "app/ui/hero/hero_comp"
|
|
local MAIN_COMP = "app/ui/main_city/component/main_comp"
|
|
local STAGE_COMP = "app/ui/stage/stage_comp"
|
|
|
|
local BOTTOM_BTN_CELL = "app/ui/main_city/cell/bottom_btn_cell"
|
|
|
|
MainCityUI.CLICK_BTN_TYPE = {
|
|
[1] = "SHOP",
|
|
[2] = "EQUIP",
|
|
[3] = "HOME",
|
|
[4] = "TALENT",
|
|
[5] = "CHALLENGE",
|
|
}
|
|
|
|
local MAIN_COMP_INDEX = 1
|
|
|
|
function MainCityUI:getUIType()
|
|
return UIManager.UI_TYPE.MAIN
|
|
end
|
|
|
|
function MainCityUI:getCurrencyParams()
|
|
if self.currencyParams == nil then
|
|
self.currencyParams = {
|
|
itemIds = {}
|
|
}
|
|
end
|
|
self.selectedIndex = self.selectedIndex or MAIN_COMP_INDEX
|
|
self.currencyParams.showType = GConst.CURRENCY_TYPE.HORIZONTAL
|
|
for k, v in ipairs(self.currencyParams.itemIds) do
|
|
table.remove(self.currencyParams.itemIds)
|
|
end
|
|
if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then
|
|
self.currencyParams.itemIds[1] = GConst.ItemConst.ITEM_ID_VIT
|
|
self.currencyParams.itemIds[2] = GConst.ItemConst.ITEM_ID_GOLD
|
|
elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.HERO then
|
|
self.currencyParams.itemIds[1] = GConst.ItemConst.ITEM_ID_VIT
|
|
self.currencyParams.itemIds[2] = GConst.ItemConst.ITEM_ID_GOLD
|
|
end
|
|
return self.currencyParams
|
|
end
|
|
|
|
function MainCityUI:getPrefabPath()
|
|
return "assets/prefabs/ui/main_city/main_ui.prefab"
|
|
end
|
|
|
|
function MainCityUI:ctor(params)
|
|
self.isFirstEnter = params and params.isFirstEnter
|
|
self.targetIndex = params and params.targetIndex
|
|
end
|
|
|
|
function MainCityUI:onLoadRootComplete()
|
|
local uiMap = self.root:genAllChildren()
|
|
self.bottomBgSelected = uiMap["main_ui.bottom_node.bottom_bg_selected"]
|
|
self.bottomBgSelected:setLocalPositionX(-178)
|
|
|
|
self:_display()
|
|
self:_addListeners()
|
|
self:_bind()
|
|
self:updateTime()
|
|
|
|
self:scheduleGlobal(function()
|
|
self:updateTime()
|
|
end, 1)
|
|
end
|
|
|
|
function MainCityUI:onSetUIOrder()
|
|
if self.subComps then
|
|
for index, comp in pairs(self.subComps) do
|
|
local order = self._baseRootCanvas.sortingOrder
|
|
local uiHelper = comp:getGameObject():GetComponent(BF_UI_HELPER)
|
|
if uiHelper then
|
|
uiHelper:SetSortingOrder(order + 1)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function MainCityUI:_display()
|
|
self:initBottomUI()
|
|
self:initComp()
|
|
self:refreshBottom()
|
|
end
|
|
|
|
function MainCityUI:_addListeners()
|
|
self:addEventListener(EventManager.CUSTOM_EVENT.MAIN_UI_CHECK_POP, function()
|
|
self:checkMainPop()
|
|
end)
|
|
end
|
|
|
|
function MainCityUI:_bind()
|
|
self:bind(DataManager.ChapterData, "isDirty", function()
|
|
if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then
|
|
self.subComps[self.selectedIndex]:refreshChapter(true)
|
|
end
|
|
end)
|
|
self:bind(DataManager.PlayerData, "dirty", function(binder, value)
|
|
self:refreshRoleInfo()
|
|
end, true)
|
|
self:bind(DataManager.PlayerData, "lvUpDirty", function(binder, value)
|
|
self:checkMainPop()
|
|
end)
|
|
self:bind(DataManager.FormationData, "dirty", function(binder, value)
|
|
if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.HERO then
|
|
self.subComps[self.selectedIndex]:refresh()
|
|
end
|
|
end)
|
|
|
|
self:bind(DataManager.HeroData, "isDirty", function(binder, value)
|
|
if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.HERO then
|
|
self.subComps[self.selectedIndex]:refresh()
|
|
end
|
|
end)
|
|
|
|
-- self:bind(DataManager.BagData.ItemData, "dirty", function(binder, value)
|
|
-- UIManager:refreshCurrencyBarTxt()
|
|
-- end)
|
|
|
|
|
|
-- self:addEventListener(EventManager.CUSTOM_EVENT.CHANGE_MAIN_CITY_PAGE_VIT, function(params)
|
|
-- params = params or {}
|
|
-- local page = params.page or self.selectedIndex
|
|
-- if page == GConst.MainCityConst.BOTTOM_PAGE.COMMERCE then
|
|
-- self.showStoreIdx = params.storeIdx
|
|
-- elseif page == GConst.MainCityConst.BOTTOM_PAGE.MAIN then
|
|
-- self.patternIdx = params.patternIdx
|
|
-- end
|
|
-- self:refreshBottom(page, false)
|
|
-- self:refreshRoleInfo()
|
|
-- end)
|
|
|
|
-- self:addEventListener(EventManager.CUSTOM_EVENT.CHANGE_MAIN_CITY_PAGE, function(params)
|
|
-- params = params or {}
|
|
-- local page = params.page or self.selectedIndex
|
|
-- if page == GConst.MainCityConst.BOTTOM_PAGE.COMMERCE then
|
|
-- self.showStoreIdx = params.storeIdx
|
|
-- self.storeOffsetY = params.storeOffsetY
|
|
-- elseif page == GConst.MainCityConst.BOTTOM_PAGE.MAIN then
|
|
-- self.patternIdx = params.patternIdx
|
|
-- end
|
|
-- self:refreshBottom(page, true)
|
|
-- self:refreshRoleInfo()
|
|
-- end)
|
|
end
|
|
|
|
function MainCityUI:initBottomUI()
|
|
local uiMap = self.root:genAllChildren()
|
|
self.darkImg = uiMap["main_ui.bottom_node.dark_img"]
|
|
self.bottomBtnCells = {}
|
|
self.bottomBtnIcons = {}
|
|
self.lineObjs = {}
|
|
for i = 1, 2 do
|
|
self.bottomBtnIcons[i] = uiMap["main_ui.bottom_node.bottom_btn_cell_" .. i .. ".icon"]
|
|
local cellCom = CellManager:addCellComp(uiMap["main_ui.bottom_node.bottom_btn_cell_" .. i], BOTTOM_BTN_CELL)
|
|
cellCom:addClickListener(function()
|
|
if self.selectedIndex == i then
|
|
return
|
|
end
|
|
|
|
if i <= #MainCityUI.CLICK_BTN_TYPE then
|
|
BIReport:postHomeBtnCilck(BIReport.CLICK_BTN_TYPE[MainCityUI.CLICK_BTN_TYPE[i]])
|
|
end
|
|
|
|
self:refreshBottom(i, true)
|
|
end)
|
|
table.insert(self.bottomBtnCells, cellCom)
|
|
|
|
local lineObj = uiMap["main_ui.bottom_node.line_node.line_" .. i]
|
|
if lineObj then
|
|
table.insert(self.lineObjs, lineObj)
|
|
end
|
|
end
|
|
end
|
|
|
|
function MainCityUI:initComp()
|
|
if not self.subComps then
|
|
local uiMap = self.root:genAllChildren()
|
|
self.subComps = {}
|
|
-- 主城
|
|
local mainComp = uiMap["main_ui.sub_ui_node.main_comp"]
|
|
mainComp:initPrefabHelper()
|
|
mainComp:genAllChildren()
|
|
self.mainComp = mainComp:addLuaComponent(MAIN_COMP)
|
|
self.subComps[GConst.MainCityConst.BOTTOM_PAGE.MAIN] = self.mainComp
|
|
-- 招式养成
|
|
local heroComp = uiMap["main_ui.sub_ui_node.hero_ui"]
|
|
heroComp:initPrefabHelper()
|
|
heroComp:genAllChildren()
|
|
self.subComps[GConst.MainCityConst.BOTTOM_PAGE.HERO] = heroComp:addLuaComponent(HERO_COMP)
|
|
self:onSetUIOrder()
|
|
end
|
|
end
|
|
|
|
function MainCityUI:refreshBottom(selectedIndex, playAnim)
|
|
if self.targetIndex then
|
|
selectedIndex = self.targetIndex
|
|
playAnim = true
|
|
self.targetIndex = nil
|
|
end
|
|
|
|
if selectedIndex and (not self.subComps[selectedIndex]) then
|
|
return
|
|
end
|
|
local oldIndex = self.selectedIndex
|
|
self.selectedIndex = selectedIndex and selectedIndex or MAIN_COMP_INDEX
|
|
self:switchComp()
|
|
|
|
-- 动效
|
|
if playAnim and (oldIndex ~= selectedIndex) then
|
|
local targetX = self.bottomBtnCells[self.selectedIndex]:getCurLocalPosX()
|
|
local isLeft = self.selectedIndex < oldIndex
|
|
local offset = isLeft and -20 or 20
|
|
GFunc.goTargetPosXShake(self.bottomBgSelected, nil, targetX, offset)
|
|
self:refreshBottomCell()
|
|
end
|
|
end
|
|
|
|
function MainCityUI:refreshBottomCell()
|
|
for i, cell in ipairs(self.bottomBtnCells) do
|
|
cell:refresh(I18N:getGlobalText("MAIN_BTN_" .. i), i == self.selectedIndex, i)
|
|
end
|
|
end
|
|
|
|
function MainCityUI:switchComp(index)
|
|
index = index or self.selectedIndex
|
|
for i, comp in pairs(self.subComps) do
|
|
comp:getBaseObject():setActive(i == index)
|
|
if i == index then
|
|
comp:refresh()
|
|
self:updateTime()
|
|
end
|
|
end
|
|
self:updateCurrencyBar()
|
|
if self.selectedIndex == MAIN_COMP_INDEX then
|
|
self:checkMainPop()
|
|
end
|
|
end
|
|
|
|
function MainCityUI:updateTime()
|
|
end
|
|
|
|
function MainCityUI:refreshRoleInfo()
|
|
local uiMap = self.root:genAllChildren()
|
|
local v, _, _2 = DataManager.PlayerData:getExpPer()
|
|
uiMap["main_ui.role_node.role_cell.setting.lv"]:setText(DataManager.PlayerData:getLv())
|
|
uiMap["main_ui.role_node.role_cell.slider"]:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = v
|
|
uiMap["main_ui.role_node.role_cell.setting"]:addClickListener(function()
|
|
ModuleManager.GameSettingManager:showSettingUI()
|
|
end)
|
|
end
|
|
|
|
function MainCityUI:checkFuncOpen()
|
|
-- if not self.lvUpHide then
|
|
-- return
|
|
-- end
|
|
-- for k,v in pairs(ModuleManager.MODULE_KEY) do
|
|
-- if not DataManager.PlayerData:isShowFuncOpen(v) and ModuleManager:getIsOpen(v, true) then
|
|
-- local params = {}
|
|
-- params.funcType = v
|
|
-- params.callback = function ()
|
|
-- self:checkFuncOpen()
|
|
-- end
|
|
-- ModuleManager.MaincityManager:showFuncOpenUI(params)
|
|
-- return
|
|
-- end
|
|
-- end
|
|
end
|
|
|
|
function MainCityUI:checkMainPop()
|
|
-- local topUI = UIManager:getTopUIObj()
|
|
-- if topUI:getUIIndex() ~= self:getUIIndex() then
|
|
-- return
|
|
-- end
|
|
|
|
-- -- 功能解锁(todo 把所有的找出来,免得每次关闭界面都要走一遍)
|
|
-- for k,v in pairs(ModuleManager.MODULE_KEY) do
|
|
-- if ModuleManager:showPop(v) and (not DataManager.PlayerData:isShowFuncOpen(v)) and ModuleManager:getIsOpen(v, true) then
|
|
-- local params = {}
|
|
-- params.funcType = v
|
|
-- ModuleManager.MaincityManager:showFuncOpenUI(params)
|
|
-- return
|
|
-- end
|
|
-- end
|
|
|
|
-- -- 章节解锁
|
|
-- if ModuleManager.StageManager:showChapterUnlockUI() then
|
|
-- return
|
|
-- end
|
|
-- -- 活动弹窗
|
|
-- if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then
|
|
-- if ModuleManager.ActivityPopManager:checkActivityPop() then
|
|
-- return
|
|
-- end
|
|
-- end
|
|
|
|
-- -- 引导
|
|
-- if self:checkTutorial() then
|
|
-- return
|
|
-- end
|
|
end
|
|
|
|
-- 检查引导
|
|
function MainCityUI:checkTutorial()
|
|
-- -- 检查抽卡引导
|
|
-- if not DataManager.TutorialData:getIsFuncTutorialFinished(DataManager.TutorialData.SUMMON_ID) then
|
|
-- self.showSummon = 4
|
|
-- ModuleManager.TutorialManager:checkFuncTutorial(DataManager.TutorialData.SUMMON_ID)
|
|
-- return
|
|
-- end
|
|
|
|
-- if not DataManager.TutorialData:getIsFuncTutorialFinished(DataManager.TutorialData.FIGHT_FAIL_ID) then
|
|
-- if DataManager.PlayerData:getStageFailCount() == 1 then -- 首次章节战败
|
|
-- ModuleManager.TutorialManager:checkFuncTutorial(DataManager.TutorialData.FIGHT_FAIL_ID)
|
|
-- return
|
|
-- end
|
|
-- end
|
|
end
|
|
|
|
return MainCityUI |