local uiCtrl = require_ex('UI/Panels/Base/UICtrl') local PANEL_ID = PanelId.AdventureBook local PHASE_ID = PhaseId.AdventureBook AdventureBookCtrl = HL.Class('AdventureBookCtrl', uiCtrl.UICtrl) local DUNGEON_TAB_INDEX = 3 AdventureBookCtrl.m_genTabCells = HL.Field(HL.Forward("UIListCache")) AdventureBookCtrl.m_tabInfos = HL.Field(HL.Table) AdventureBookCtrl.m_curTabIndex = HL.Field(HL.Number) << -1 AdventureBookCtrl.m_createArg = HL.Field(HL.Table) AdventureBookCtrl.s_messages = HL.StaticField(HL.Table) << { [MessageConst.ON_CHANGE_ADVENTURE_BOOK_TAB] = 'ChangeTab', [MessageConst.ADVENTURE_BOOK_SELECT_TAB] = '_OnReceiveSelectTab', } AdventureBookCtrl.OnCreate = HL.Override(HL.Any) << function(self, arg) self.m_genTabCells = UIUtils.genCellCache(self.view.tabs.tabCell) self.view.btnClose.onClick:AddListener(function() PhaseManager:PopPhase(PHASE_ID) end) self:BindInputPlayerAction("common_open_adventure_book", function() PhaseManager:PopPhase(PHASE_ID) end) self.m_createArg = arg self:_InitTabs() self.view.moneyCell:InitMoneyCell("item_bp_double_reward", nil, false) self.view.moneyCell2:InitMoneyCell(Tables.globalConst.apItemId) self.view.moneyCell2.view.button.onClick:RemoveAllListeners() self.view.moneyCell2.view.button.onClick:AddListener(function() if DeviceInfo.usingController then Notify(MessageConst.HIDE_ITEM_TIPS) return else local curStamina = GameInstance.player.inventory.curStamina local maxStamina = GameInstance.player.inventory.maxStamina if curStamina >= maxStamina then Notify(MessageConst.SHOW_TOAST, Language.LUA_STAMINA_FULL_HINT) else local active = self.view.moneyCell2.view.tip.gameObject.activeSelf self.view.moneyCell2.view.tip.gameObject:SetActive(not active) end end AudioAdapter.PostEvent("au_ui_btn_ap_info") end) self.view.walletContent.onIsFocusedChange:AddListener(function(isFocused) if isFocused then logger.info("[adventure] 聚焦到货币栏") Notify(MessageConst.ON_ADVENTURE_BOOK_FOCUS_WALLET) else logger.info("[adventure] 停止聚焦到货币栏") Notify(MessageConst.ON_ADVENTURE_BOOK_NOT_FOCUS_WALLET) end end) self.view.walletContent.getDefaultSelectableFunc = function() return self.view.moneyCell2.view.button end end AdventureBookCtrl.ChangeTab = HL.Method(HL.Any) << function(self, arg) local panelId = PanelId[arg.panelId] self.m_curTabIndex = self:_GetCurTabIndexByPanelId(panelId) local cell = self.m_genTabCells:Get(self.m_curTabIndex) cell.toggle.isOn = true self:_OnTabClick(self.m_curTabIndex, true) if arg.dungeonTab and panelId == PanelId.AdventureDungeon then if self.m_phase.m_panel2Item[PanelId.AdventureDungeon] ~= nil then Notify(MessageConst.ON_CHANGE_ADVENTURE_DUNGEON_TAB, arg.dungeonTab) else self.m_phase.m_dungeonTab = arg.dungeonTab end end end AdventureBookCtrl._OnReceiveSelectTab = HL.Method(HL.Any) << function(self, arg) local tabId = unpack(arg) self.m_curTabIndex = self:_GetCurTabIndexByTabId(tabId) local cell = self.m_genTabCells:Get(self.m_curTabIndex) cell.toggle.isOn = true self:_OnTabClick(self.m_curTabIndex, true) if arg.dungeonTab and panelId == PanelId.AdventureDungeon then Notify(MessageConst.ON_CHANGE_ADVENTURE_DUNGEON_TAB, arg.dungeonTab) end end AdventureBookCtrl._OnPhaseItemBind = HL.Override() << function(self) if self.m_createArg and self.m_createArg.panelId then self:ChangeTab(self.m_createArg) self.m_createArg = nil else self:_OnTabClick(self.m_curTabIndex, true) end end AdventureBookCtrl._InitTabs = HL.Method() << function(self) self:_InitTabInfos() self:_InitTabIndex() self.m_genTabCells:Refresh(#self.m_tabInfos, function(cell, luaIndex) local info = self.m_tabInfos[luaIndex] cell.gameObject.name = "AdventureBookTab_"..luaIndex UIUtils.setTabIcons(cell,UIConst.UI_SPRITE_ADVENTURE,info.icon) cell.selectedNameTxt.text = info.tabName cell.defaultNameTxt.text = info.tabName if not string.isEmpty(info.redDot) then if info.redDotArg then cell.redDot:InitRedDot(info.redDot, info.redDotArg) else cell.redDot:InitRedDot(info.redDot) end end if luaIndex == self.m_curTabIndex then cell.stateController:SetState("Select") else cell.stateController:SetState("Unselected") end cell.toggle.isOn = luaIndex == self.m_curTabIndex cell.toggle.onValueChanged:RemoveAllListeners() cell.toggle.onValueChanged:AddListener(function(isOn) local cell = self.m_genTabCells:Get(luaIndex) local stateCtrl = cell.stateController if isOn then stateCtrl:SetState("Select") self:_OnTabClick(luaIndex) else stateCtrl:SetState("Unselected") end end) end) end AdventureBookCtrl._InitTabInfos = HL.Method() << function(self) self.m_tabInfos = { { id = "AdventureStage", icon = "icon_adventure_book", titleName = Language.ui_AdventureStagePanel_title, tabName = Language.ui_AdventurePanel_title_adventurebook, panelId = PanelId.AdventureStage, redDot = "AdventureBookTabStage", checkRedDot = AdventureBookUtils.CheckRedDotAdventureBookTabStage }, { id = "AdventureDaily", icon = "icon_adventure_daily", titleName = Language.ui_AdventureDailyPanel_title, tabName = Language.ui_AdventurePanel_title_daily, panelId = PanelId.AdventureDaily, redDot = "AdventureBookTabDaily", checkRedDot = AdventureBookUtils.CheckRedDotAdventureBookTabDaily }, } if(Utils.isSystemUnlocked(GEnums.UnlockSystemType.Dungeon) and AdventureBookUtils.HaveDungeon()) then table.insert(self.m_tabInfos, { id = "AdventureDungeon", icon = "icon_adventure_dungeon", titleName = Language.ui_AdventureDungeonPanel_title, tabName = Language.ui_AdventurePanel_title_dungeon, panelId = PanelId.AdventureDungeon, redDot = "AdventureBookTabDungeon", checkRedDot = AdventureBookUtils.CheckRedDotAdventureBookTabDungeon }) end if(Utils.isSystemUnlocked(GEnums.UnlockSystemType.BattleTraining)) then table.insert(self.m_tabInfos, { id = "AdventureTraining", icon = "icon_adventure_training", titleName = Language.ui_AdventureTrainingPanel_title, tabName = Language.ui_AdventurePanel_title_training, panelId = PanelId.AdventureTraining, redDot = "AdventureBookTabTrain", checkRedDot = AdventureBookUtils.CheckRedDotAdventureBookTabTrain }) end if(Utils.isSystemUnlocked(GEnums.UnlockSystemType.FacTechTree)) then local canShow = false for _, cfg in pairs(Tables.domainDataTable) do if not GameInstance.player.facTechTreeSystem:PackageIsLocked(cfg.facTechPackageId) and not GameInstance.player.facTechTreeSystem:PackageIsHidden(cfg.facTechPackageId) then canShow = true break end end if canShow then table.insert(self.m_tabInfos, { id = "AdventureBlackbox", icon = "icon_adventure_blackbox", titleName = Language.ui_AdventureBlackboxPanel_title, tabName = Language.ui_AdventurePanel_title_blackbox, panelId = PanelId.AdventureBlackbox, redDot = "AdventureBookTabBlackbox", checkRedDot = AdventureBookUtils.CheckRedDotAdventureBookTabBlackbox }) end end if(Utils.isSystemUnlocked(GEnums.UnlockSystemType.WeekRaidIntro)) then table.insert(self.m_tabInfos, { id = "AdventureRacingDungeon", icon = "icon_adventure_racingdungeon", titleName = Language.ui_AdventureRacingPanel_title, tabName = Language.ui_AdventurePanel_title_racing, panelId = PanelId.AdventureRacingDungeon, redDot = "AdventureBookTabWeekRaid", checkRedDot = AdventureBookUtils.CheckRedDotAdventureBookTabWeekRaid, }) end end AdventureBookCtrl._InitTabIndex = HL.Method() << function(self) for i, v in ipairs(self.m_tabInfos) do if v.redDot and v.checkRedDot then local showRedDot = v.checkRedDot() if showRedDot then self.m_curTabIndex = i return end end end for i, v in ipairs(self.m_tabInfos) do if v.panelId == PanelId.AdventureDungeon then self.m_curTabIndex = i return end end self.m_curTabIndex = 1 end AdventureBookCtrl._GetCurTabIndexByPanelId = HL.Method(HL.Number).Return(HL.Number) << function(self, panelId) local index = 1 for _, info in pairs(self.m_tabInfos) do if info.panelId == panelId then return index end index = index + 1 end return 1 end AdventureBookCtrl._GetCurTabIndexByTabId = HL.Method(HL.String).Return(HL.Number) << function(self, tabId) local index = 1 for _, info in pairs(self.m_tabInfos) do if info.id == tabId then return index end index = index + 1 end return 1 end AdventureBookCtrl._OnTabClick = HL.Method(HL.Number, HL.Opt(HL.Boolean)) << function(self, luaIndex, isInit) if self.m_curTabIndex == luaIndex and not isInit then return end local changeToLeft = luaIndex < self.m_curTabIndex local prevTabInfo = self.m_tabInfos[self.m_curTabIndex] if prevTabInfo.panelId == PanelId.AdventureDaily then self:Notify(MessageConst.P_ON_ADVENTURE_DAILY_CLOSE_REWARD_TIPS) end self.m_curTabIndex = luaIndex local curTabInfo = self.m_tabInfos[luaIndex] self.view.moneyCell.gameObject:SetActive(curTabInfo.panelId == PanelId.AdventureDungeon) self.view.moneyCell2.gameObject:SetActive(curTabInfo.panelId == PanelId.AdventureDungeon) self.view.keyHint.gameObject:SetActive(curTabInfo.panelId == PanelId.AdventureDungeon) self.view.walletContent.gameObject:SetActive(curTabInfo.panelId == PanelId.AdventureDungeon) self.m_phase:OnTabChange({ panelId = curTabInfo.panelId, changeToLeft = changeToLeft }) end HL.Commit(AdventureBookCtrl)