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] = "HOME", [2] = "HERO", } local MAIN_COMP_INDEX = 1 function MainCityUI:getUIType() return UIManager.UI_TYPE.MAIN end function MainCityUI:getBGMId() return AudioManager.BGM_ID.MAINCITY 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:onReshow() self:checkMainPop() 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, true) 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() elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then self.subComps[self.selectedIndex]:refreshStageFormaion() end end) self:bind(DataManager.BagData.ItemData, "dirty", function(binder, value) if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN and self.subComps[self.selectedIndex] then self.subComps[self.selectedIndex]:refreshStageFormaion() end 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.lineObjs = {} for i = 1, 2 do 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 if self.selectedIndex == 2 then uiMap["main_ui.bottom_node.icons.ui_spine_obj_l"]:playAnim("born", false, false) else uiMap["main_ui.bottom_node.icons.ui_spine_obj_r"]:playAnim("born", false, false) 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 -- uiMap["main_ui.bottom_node.icons.ui_spine_obj_l"]:playAnim("born", false, false) uiMap["main_ui.bottom_node.icons.ui_spine_obj_l"]:setTimeScale(0.3) -- uiMap["main_ui.bottom_node.icons.ui_spine_obj_r"]:playAnim("born", false, false) uiMap["main_ui.bottom_node.icons.ui_spine_obj_r"]:setTimeScale(0.3) 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(true) else self:refreshBottomCell(false) end end function MainCityUI:refreshBottomCell(showAni) for i, cell in ipairs(self.bottomBtnCells) do cell:refresh(I18N:getGlobalText("MAIN_BTN_" .. i), i == self.selectedIndex, showAni) 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:checkMainPop() -- 引导 if self:checkTutorial() then return end end -- 检查引导 function MainCityUI:checkTutorial() if DataManager.ChapterData:getMaxChapterId() == 1 then if ModuleManager.TutorialManager:checkFuncTutorial(GConst.TutorialConst.PASS_ONE_CHAPTER) then return end end if DataManager.ChapterData:boxCanGet(2, 1) then if ModuleManager.TutorialManager:checkFuncTutorial(GConst.TutorialConst.TWO_CHAPTER_BOX_CAN_GOT) then return end end if DataManager.ChapterData:getMaxChapterId() == 2 then if ModuleManager.TutorialManager:checkFuncTutorial(GConst.TutorialConst.PASS_THREE_CHAPTER) then return end end end return MainCityUI