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 HERO_MODEL_PATH = "assets/prefabs/models/maincity/role_show.prefab" local ROLE_SHOW_COMP = "app/ui/main_city/component/role_show_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:currencyParams() if self.cheat then local params = {} params.itemIds = {} return params end self.selectedIndex = self.selectedIndex or MAIN_COMP_INDEX local params = {} params.showType = GConst.CURRENCY_TYPE.HORIZONTAL if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.COMMERCE then params.itemIds = { GConst.ItemConst.ITEM_ID_GOLD, GConst.ItemConst.ITEM_ID_GEM, GConst.ItemConst.ITEM_ID_VIT, } elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.EQUIP then params.itemIds = { GConst.ItemConst.ITEM_ID_GOLD, GConst.ItemConst.ITEM_ID_GEM, GConst.ItemConst.ITEM_ID_VIT, } elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then params.itemIds = { GConst.ItemConst.ITEM_ID_GOLD, GConst.ItemConst.ITEM_ID_GEM, GConst.ItemConst.ITEM_ID_VIT, } elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.TALENT then params.itemIds = { GConst.ItemConst.ITEM_ID_GOLD, GConst.ItemConst.ITEM_ID_GEM, GConst.ItemConst.ITEM_ID_TALENT_ID, } elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.CHALLENGE then params.itemIds = { GConst.ItemConst.ITEM_ID_GOLD, GConst.ItemConst.ITEM_ID_GEM, GConst.ItemConst.ITEM_ID_VIT, } end return params, true 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() self:changeModel() -- 主界面 self:changeHero() -- 装备界面 end function MainCityUI:_addListeners() self:addEventListener(EventManager.CUSTOM_EVENT.MAIN_UI_CHECK_POP, function() self:checkMainPop() end) end function MainCityUI:_bind() self:bind(DataManager.StageData, "isDirty", function() if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then self.subComps[self.selectedIndex]:refreshChapter() 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.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 if i == GConst.MainCityConst.BOTTOM_PAGE.COMMERCE then if self.showSummon and self.showSummon > 0 then comp:refresh(self.showSummon) self.showSummon = nil elseif self.showStoreIdx and self.showStoreIdx > 0 then comp:refresh(self.showStoreIdx, nil, self.storeOffsetY) self.showStoreIdx = nil self.storeOffsetY = nil else comp:refresh() end elseif i == GConst.MainCityConst.BOTTOM_PAGE.MAIN then comp:refresh(self.patternIdx) self.patternIdx = nil else comp:refresh() end self:updateTime() end end local params = {} params.showType = GConst.CURRENCY_TYPE.HORIZONTAL self:updateCurrencyBar() self:changeHero() if self.selectedIndex == MAIN_COMP_INDEX then self:checkMainPop() end end function MainCityUI:changeModel() end function MainCityUI:changeHero() if self.selectedIndex ~= GConst.MainCityConst.BOTTOM_PAGE.EQUIP or self._baseVisible == false then if self.heroModelComp then self.heroModelComp:setActive(false) end return end local entity = DataManager.HeroData:getUniqueHero() local showSpecialIdle = false local eid = entity:getWearedEquips()[GConst.EquipConst.WEAPON_PART] if eid then local eEntity = DataManager.BagData.EquipData:getEquipByEid(eid) if eEntity and eEntity:getHeroPose() == entity:getHid() then showSpecialIdle = true end end if self.heroModelComp then self.heroModelComp:setActive(true) end if not self.heroModelComp then self:loadUIModelRoot(HERO_MODEL_PATH, function(obj) if self.heroModelComp then obj:destroy() return end self.heroModelComp = obj:addLuaComponent(ROLE_SHOW_COMP) self.heroModelComp:getCameraRenderTexture(function(texture) if self:isClosed() then return end if entity then self.heroModelComp:showHero(entity:getHid(), entity:getWeaponId(), function() -- if showSpecialIdle and self.heroModelComp.modelObj then -- self.heroModelComp.modelObj:play("zs_idle", -1, 0) -- end if self.heroModelComp.modelObj then self.heroModelComp.modelObj:play("idle_display", -1, 0) end end) end self.heroShowTexture = texture if self.equipComp then self.equipComp:setRt(self.heroShowTexture) self.equipComp:setRoleShowComp(self.heroModelComp) end end) end) else if entity:getHid() then self.heroModelComp:showHero(entity:getHid(), entity:getWeaponId(), function() -- if showSpecialIdle and self.heroModelComp.modelObj then -- self.heroModelComp.modelObj:play("zs_idle", -1, 0) -- end if self.heroModelComp.modelObj then self.heroModelComp.modelObj:play("idle_display", -1, 0) end end) end end end function MainCityUI:updateTime() if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.COMMERCE or self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then self.subComps[self.selectedIndex]:updateTime() end self:checkRedPoint() 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:checkRedPoint() -- 装备 -- if DataManager.BagData.EquipData:getRedPoint() or DataManager.HeroData:getRedPoint() then -- self.bottomBtnIcons[GConst.MainCityConst.BOTTOM_PAGE.EQUIP]:addRedPoint(40, 40, 0.7) -- else -- self.bottomBtnIcons[GConst.MainCityConst.BOTTOM_PAGE.EQUIP]:removeRedPoint() -- end -- -- 主线挑战 -- if ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.CHALLENGE, true) and DataManager.ChallengeData:showRedPoint() then -- self.bottomBtnIcons[GConst.MainCityConst.BOTTOM_PAGE.CHALLENGE]:addRedPoint(40, 40, 0.7) -- else -- self.bottomBtnIcons[GConst.MainCityConst.BOTTOM_PAGE.CHALLENGE]:removeRedPoint() -- 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:checkUndoneBattle() local saveData = LocalData:getBattlePointData() if saveData and saveData.battleType then if not saveData.version or saveData.version ~= Platform:getClientVersion() then -- 版本号不相同时,删除数据 DataManager.BattleData:savePointData() return end if saveData.battleType == ModuleManager.BattleManager.BATTLE_TYPE.STAGE then local chapterId = tonumber(saveData.chapterId) local config = ConfigManager:getConfig("chapter")[chapterId] if not config then DataManager.BattleData:savePointData() return end end -- 主线挑战不重连 if saveData.battleType == ModuleManager.BattleManager.BATTLE_TYPE.CHALLENGE then DataManager.BattleData:savePointData() return end local function enterBattle() self.hasUnDoneBattle = false if saveData.battleType == ModuleManager.BattleManager.BATTLE_TYPE.STAGE then DataManager.StageData:changeChapterId(tonumber(saveData.chapterId)) end ModuleManager.BattleManager:playBattle(saveData.battleType, saveData, nil, function() UIManager:closeAllUI() ModuleManager.MaincityManager:showMainCityUI() end) end if not DataManager.TutorialData:getIsFuncTutorialFinished(DataManager.TutorialData.FIRST_FIGHT_END_ID) then enterBattle() else GFunc.showMessageBox({ boxType = GConst.MESSAGE_BOX_TYPE.MB_OK_CANCEL, content = I18N:getGlobalText(I18N.GlobalConst.BATTLE_RECONNECT), okFunc = function() enterBattle() end, cancelFunc = function() DataManager.BattleData:savePointData() self.hasUnDoneBattle = false self:checkTutorial() end }) -- 有未完成的战斗,记录状态 self.hasUnDoneBattle = true 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 self.hasUnDoneBattle then return end -- 检查抽卡引导 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