local UIPrefabObject = require "app/bf/unity/uiprefab_object" local MainCityUI = class("MainCityUI", BaseUI) local SIDE_BAR_BORDER_OFFSET = 22 local SIDE_BAR_INTERVAL = 28 local SIDE_BAR_ARROW_INTERVAL = 20 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 SHOP_COMP = "app/ui/shop/shop_comp" local BOTTOM_BTN_CELL = "app/ui/main_city/cell/bottom_btn_cell" MainCityUI.CLICK_BTN_TYPE = { [1] = "HOME", [2] = "HERO", [3] = "SHOP", } 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_GOLD self.currencyParams.itemIds[2] = GConst.ItemConst.ITEM_ID_GEM self.currencyParams.itemIds[3] = GConst.ItemConst.ITEM_ID_VIT elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.HERO then self.currencyParams.itemIds[1] = GConst.ItemConst.ITEM_ID_GOLD self.currencyParams.itemIds[2] = GConst.ItemConst.ITEM_ID_VIT elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.SHOP then self.currencyParams.itemIds[1] = GConst.ItemConst.ITEM_ID_GOLD self.currencyParams.itemIds[2] = GConst.ItemConst.ITEM_ID_GEM self.currencyParams.itemIds[3] = GConst.ItemConst.ITEM_ID_VIT 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.uiMap = uiMap self.bottomBgSelected = uiMap["main_ui.bottom_node.bottom_bg_selected"] self.bottomBgSelected:setLocalPositionX(0) self:_display() self:_addListeners() self:_bind() self:refreshBottomRp() self:updateTime() self:scheduleGlobal(function() self:updateSideBarStatus() self:updateTime() end, 1) end function MainCityUI:onRefresh() self:refreshAllSideBars() self:refreshSettingBtn() end function MainCityUI:refreshAllSideBars() self:refreshLeftBtns() self:refreshRightBtns() self:updateSideBarStatus() end function MainCityUI:onReshow() self:checkMainPop() self:checkSideBarOpenStatus() 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:initLeftRightBtns() self:initPlayerInfo() self:initTopNode() self:refreshBottom() end function MainCityUI:_addListeners() self:addEventListener(EventManager.CUSTOM_EVENT.TIME_TRIGGERED_NEW_EMAIL, function() local time = math.random(10000, 30000) / 20000 ModuleManager.MailManager:performWithDelayGlobal(function() ModuleManager.MailManager:getTriggeredTimeMail() end, time) end) self:addEventListener(EventManager.CUSTOM_EVENT.TUTORIAL_TASK_STOP, function() -- 引导完成时 检测主界面的弹窗是否要触发 self:checkGift() end) self:addEventListener(EventManager.CUSTOM_EVENT.GO_SHOP, function(params) if ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.MALL, false) then local page = params and params.page or GConst.ShopConst.PAGE_TYPE.MAIN -- 默认主要商品 local subType = params.subType if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.SHOP then if self.subComps and self.subComps[GConst.MainCityConst.BOTTOM_PAGE.SHOP] then self.subComps[GConst.MainCityConst.BOTTOM_PAGE.SHOP]:switchPage(page) if page == GConst.ShopConst.PAGE_TYPE.MAIN and subType then self.subComps[GConst.MainCityConst.BOTTOM_PAGE.SHOP]:goSubType(subType) end end return end self.bottomBtnSpines[GConst.MainCityConst.BOTTOM_PAGE.SHOP]:playAnimComplete("born1", false, false, function() self.bottomBtnSpines[GConst.MainCityConst.BOTTOM_PAGE.SHOP]:playAnimComplete("born2", false, false, function() self.bottomBtnSpines[GConst.MainCityConst.BOTTOM_PAGE.SHOP]:playAnim("idle", false, false) end) end) self:refreshBottom(GConst.MainCityConst.BOTTOM_PAGE.SHOP, true) if self.subComps and self.subComps[GConst.MainCityConst.BOTTOM_PAGE.SHOP] then self.subComps[GConst.MainCityConst.BOTTOM_PAGE.SHOP]:switchPage(page) if page == GConst.ShopConst.PAGE_TYPE.MAIN and subType then self.subComps[GConst.MainCityConst.BOTTOM_PAGE.SHOP]:goSubType(subType) end end end end) self:addEventListener(EventManager.CUSTOM_EVENT.GO_DAILY_CHALLENGE, function() if self.selectedIndex ~= GConst.MainCityConst.BOTTOM_PAGE.MAIN then return end self:refreshBounty() end) self:addEventListener(EventManager.CUSTOM_EVENT.GO_CHAPTER, function() if self.selectedIndex ~= GConst.MainCityConst.BOTTOM_PAGE.MAIN then return end self:refreshBounty() end) DataManager.MailData:checkNewMail() end function MainCityUI:_bind() self:bind(DataManager.ChapterData, "isDirty", function() if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then if self.subComps[self.selectedIndex] then self.subComps[self.selectedIndex]:refreshChapter(true) end end end, true) self:bind(DataManager.PlayerData, "dirty", function(binder, value) self:refreshPlayerInfo() end, true) 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 if self.subComps[self.selectedIndex] then self.subComps[self.selectedIndex]:refresh() end self:refreshBottomRp() elseif self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then if self.subComps[self.selectedIndex] then self.subComps[self.selectedIndex]:refreshStageFormaion() end 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 if self.subComps[self.selectedIndex] then self.subComps[self.selectedIndex]:refreshStageFormaion() self.subComps[self.selectedIndex]:refreshBtns() end end end) self:bind(DataManager.DailyTaskData, "redPointFlag", function() self:refreshTask() end) self:bind(DataManager.BountyData, "dirty", function() self:refreshBounty() end) self:bind(DataManager.MailData, "redPoint", function() self:refreshSettingBtn() end) self:bind(DataManager.ShopData, "isDirty", function() if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.SHOP and self.subComps[self.selectedIndex] then if self.subComps[self.selectedIndex] then self.subComps[self.selectedIndex]:refresh() end end self:refreshBottomRp() end) self:bind(DataManager.SummonData, "isDirty", function() if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.SHOP and self.subComps[self.selectedIndex] then if self.subComps[self.selectedIndex] then self.subComps[self.selectedIndex]:refresh() end end end) self:bind(DataManager.DailyChallengeData, "isDirty", function() if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.MAIN then if self.subComps[self.selectedIndex] then self.subComps[self.selectedIndex]:refreshChallenge() end end end) end function MainCityUI:initBottomUI() local uiMap = self.root:genAllChildren() self.bottomBtnCells = {} self.bottomBtnSpines = {} for i = 1, 3 do local cellCom = CellManager:addCellComp(uiMap["main_ui.bottom_node.bottom_btn_cell_" .. i], BOTTOM_BTN_CELL) cellCom:addClickListener(function() if i == 3 then -- 商城有开启条件 if not ModuleManager:getIsOpen(ModuleManager.MODULE_KEY.MALL, false) then return end end 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.bottomBtnSpines[i]:playAnimComplete("born1", false, false, function() self.bottomBtnSpines[i]:playAnimComplete("born2", false, false, function() self.bottomBtnSpines[i]:playAnim("idle", false, false) end) end) self:refreshBottom(i, true) end) table.insert(self.bottomBtnCells, cellCom) self.bottomBtnSpines[i] = uiMap["main_ui.bottom_node.icons.ui_spine_obj_" .. i] self.bottomBtnSpines[i]:playAnim("idle", false, false) 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() -- 商城 local shopComp = uiMap["main_ui.sub_ui_node.shop_comp"] shopComp:initPrefabHelper() shopComp:genAllChildren() self.subComps[GConst.MainCityConst.BOTTOM_PAGE.SHOP] = shopComp:addLuaComponent(SHOP_COMP) 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 oldIndex ~= selectedIndex then EventManager:dispatchEvent(EventManager.CUSTOM_EVENT.CHANGE_MAIN_CITY_PAGE, self.selectedIndex) end -- 动效 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:initLeftRightBtns() self.leftNode = self.uiMap["main_ui.left_node"] self.leftSideBar = self.uiMap["main_ui.left_node.side_bar"] self.leftArrowBtn = self.uiMap["main_ui.left_node.arrow_node"] self.leftArrowBtn:addClickListener(function() self:openOrCloseLeftSideBar() end) self.leftArrowImg = self.uiMap["main_ui.left_node.arrow_node.arrow"] self.rightNode = self.uiMap["main_ui.right_node"] self.rightSideBar = self.uiMap["main_ui.right_node.side_bar"] self.rightArrowBtn = self.uiMap["main_ui.right_node.arrow_node"] self.rightArrowBtn:addClickListener(function() self:openOrCloseRightSideBar() end) self.rightArrowImg = self.uiMap["main_ui.right_node.arrow_node.arrow"] self.sideBarCellObject = self.uiMap["main_ui.cache_node.side_bar_cell"] local w, h = self.sideBarCellObject:fastGetSizeDelta() self.sideBarHeight = h if self.leftBarList == nil then self.leftBarList = {} end if self.rightBarList == nil then self.rightBarList = {} end if self.sideBarClassMap == nil then self.sideBarClassMap = {} end if self.sideBarCellMap == nil then self.sideBarCellMap = {} end self:recycleSideBarCells(self.leftSideBar) self:recycleSideBarCells(self.rightSideBar) end function MainCityUI:recycleSideBarCells(list) local childList = list:getChildList() if childList and #childList > 0 then local count = #childList for i = count, 1, -1 do local child = childList[i] local name = child:getName() if name and name ~= "" then child:setVisible(false) self.sideBarCellMap[name] = child:getLuaComponent(name) else child:destroy() table.remove(childList, i) end end end end function MainCityUI:addSideBarCellComp(cellClassPath) local prefab = CS.UnityEngine.Object.Instantiate(self.sideBarCellObject:getGameObject()) local prefabObject = UIPrefabObject:create() prefabObject:initWithPrefab(GConst.EMPTY_STRING, prefab) prefabObject:initPrefabHelper() prefabObject:genAllChildren() prefabObject:setName(cellClassPath) return prefabObject:addLuaComponent(cellClassPath) end function MainCityUI:openOrCloseLeftSideBar() ModuleManager.MaincityManager:changeMainCityLeftSideBarOpenOrClose() if self.isShowLeftSideBarArrowRedPoint ~= nil then local isShowLeftSideBarArrowRedPoint = self.isShowLeftSideBarArrowRedPoint self.isShowLeftSideBarArrowRedPoint = nil self:setLeftSideBarArrowRedPoint(isShowLeftSideBarArrowRedPoint) end end function MainCityUI:refreshLeftBtns() self:clearSideBarList(self.leftBarList) local list = GConst.MainCityConst.LEFT_SIDE_BARS if #list <= 0 then return end local isClose = ModuleManager.MaincityManager:getIsMainCityLeftSideBarClose() for k, v in ipairs(list) do local CellClass = self.sideBarClassMap[v] if CellClass == nil then CellClass = require(v) self.sideBarClassMap[v] = CellClass end if CellClass:getIsOpen() then local cell = self.sideBarCellMap[v] if cell == nil then cell = self:addSideBarCellComp(v) cell:getBaseObject():setParent(self.leftSideBar, false) end cell:initWithParentUI(self, v, true) table.insert(self.leftBarList, cell) end end local sideBarShowCount = #self.leftBarList if sideBarShowCount <= 0 then self.leftNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS) return end self.leftNode:setAnchoredPositionX(0) local y = -SIDE_BAR_BORDER_OFFSET - self.sideBarHeight/2 if isClose then -- 只显示3个 local minCount = GConst.MainCityConst.SIDE_BAR_MIN_COUNT for i = 1, minCount do local sideBarBtn = self.leftBarList[i] if i <= sideBarShowCount then sideBarBtn:setAnchoredPositionY(y) sideBarBtn:refresh() sideBarBtn:setActive(true) sideBarBtn:setVisible(true) y = y - self.sideBarHeight - SIDE_BAR_INTERVAL end end for i = minCount + 1, sideBarShowCount do self.leftBarList[i]:refresh() self.leftBarList[i]:setActive(true) self.leftBarList[i]:setVisible(false) end else for k, v in ipairs(self.leftBarList) do v:setAnchoredPositionY(y) v:refresh() v:setActive(true) v:setVisible(true) y = y - self.sideBarHeight - SIDE_BAR_INTERVAL end end if sideBarShowCount <= GConst.MainCityConst.SIDE_BAR_MIN_COUNT then -- 小于3个不显示箭头 y = y + self.sideBarHeight / 2 self.leftSideBar:setSizeDeltaY(-y) self.leftArrowBtn:stopClickAnimation() self.leftArrowBtn:setVisible(false) else local arrowHeight = self.leftArrowBtn:getRectHeight() y = y + self.sideBarHeight/2 - SIDE_BAR_ARROW_INTERVAL - arrowHeight self.leftSideBar:setSizeDeltaY(-y) self.leftArrowImg:setLocalScale(1, isClose and -1 or 1, 1) self.leftArrowBtn:setVisible(true) self.leftArrowBtn:setAnchoredPositionY(self.leftSideBar:fastGetAnchoredPositionY() + y + arrowHeight/2 + SIDE_BAR_BORDER_OFFSET) end end function MainCityUI:openOrCloseRightSideBar() ModuleManager.MaincityManager:changeMainCityRightSideBarOpenOrClose() if self.isShowRightSideBarArrowRedPoint ~= nil then local isShowRightSideBarArrowRedPoint = self.isShowRightSideBarArrowRedPoint self.isShowRightSideBarArrowRedPoint = nil self:setRightSideBarArrowRedPoint(isShowRightSideBarArrowRedPoint) end end function MainCityUI:refreshRightBtns() self:clearSideBarList(self.rightBarList) local list = GConst.MainCityConst.RIGHT_SIDE_BARS if #list <= 0 then return end local isClose = ModuleManager.MaincityManager:getIsMainCityRightSideBarClose() for k, v in ipairs(list) do local CellClass = self.sideBarClassMap[v] if CellClass == nil then CellClass = require(v) self.sideBarClassMap[v] = CellClass end if CellClass:getIsOpen() then local cell = self.sideBarCellMap[v] if cell == nil then cell = self:addSideBarCellComp(v) cell:getBaseObject():setParent(self.rightSideBar, false) end cell:initWithParentUI(self, v, false) table.insert(self.rightBarList, cell) end end local sideBarShowCount = #self.rightBarList if #self.rightBarList <= 0 then self.rightNode:setAnchoredPositionX(GConst.NOT_VISIBLE_POS) return end self.rightNode:setAnchoredPositionX(0) local y = -SIDE_BAR_BORDER_OFFSET - self.sideBarHeight/2 if isClose then -- 只显示一个 local minCount = GConst.MainCityConst.SIDE_BAR_MIN_COUNT for i = 1, minCount do local sideBarBtn = self.rightBarList[i] if i <= sideBarShowCount then sideBarBtn:setAnchoredPositionY(y) sideBarBtn:refresh() sideBarBtn:setActive(true) sideBarBtn:setVisible(true) y = y - self.sideBarHeight - SIDE_BAR_INTERVAL end end for i = minCount + 1, sideBarShowCount do self.rightBarList[i]:refresh() self.rightBarList[i]:setActive(true) self.rightBarList[i]:setVisible(false) end else for k, v in ipairs(self.rightBarList) do v:setAnchoredPositionY(y) v:refresh() v:setActive(true) v:setVisible(true) y = y - self.sideBarHeight - SIDE_BAR_INTERVAL end end if sideBarShowCount <= GConst.MainCityConst.SIDE_BAR_MIN_COUNT then y = y + self.sideBarHeight / 2 self.rightSideBar:setSizeDeltaY(-y) self.rightArrowBtn:stopClickAnimation() self.rightArrowBtn:setVisible(false) else local arrowHeight = self.rightArrowBtn:getRectHeight() y = y + self.sideBarHeight / 2 - SIDE_BAR_ARROW_INTERVAL - arrowHeight self.rightSideBar:setSizeDeltaY(-y) self.rightArrowImg:setLocalScale(1, isClose and -1 or 1, 1) self.rightArrowBtn:setVisible(true) self.rightArrowBtn:setAnchoredPositionY(self.rightSideBar:fastGetAnchoredPositionY() + y + arrowHeight/2 + SIDE_BAR_BORDER_OFFSET) end end function MainCityUI:clearSideBarList(sideBarList) local count = #sideBarList for i = 1, count do local cell = table.remove(sideBarList) cell:setActive(false) cell:setVisible(false) self.sideBarCellMap[cell:getCellPath()] = cell end end function MainCityUI:setSideBarVisible(visible) self.leftNode:setVisible(visible) self.rightNode:setVisible(visible) end function MainCityUI:initPlayerInfo() self.playerSlider = self.uiMap["main_ui.player_node.slider"] self.playerLvTx = self.uiMap["main_ui.player_node.lv"] end function MainCityUI:refreshPlayerInfo() local lv = DataManager.PlayerData:getLv() self.playerLvTx:setText(GConst.INT_TO_STRING[lv] or tostring(lv)) self.playerSlider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = DataManager.PlayerData:getExpPercent() end function MainCityUI:initTopNode() self.topNode = self.uiMap["main_ui.top_node"] self:initTask() self:initBounty() self:initSetting() end function MainCityUI:initTask() self.taskBtn = self.uiMap["main_ui.top_node.task_btn"] self.taskBtn:addClickListener(function() ModuleManager.TaskManager:showTaskMainUI() end) end function MainCityUI:initBounty() self.bountyNode = self.uiMap["main_ui.top_node.bounty_node"] self.bountyBanner = self.uiMap["main_ui.top_node.bounty_node.banner"] self.bountyBanner:addClickListener(function() ModuleManager.BountyManager:showBountyMainUI() end) self.bountyRewardSpine = self.uiMap["main_ui.top_node.bounty_node.banner.spine"] self.bountyBannerInfo = self.uiMap["main_ui.top_node.bounty_node.banner.info"] self.bountyBannerDescTx = self.uiMap["main_ui.top_node.bounty_node.banner.desc"] self.bountyBannerSlider = self.uiMap["main_ui.top_node.bounty_node.banner.info.progress_bg.slider"] self.bountyBannerSliderTx = self.uiMap["main_ui.top_node.bounty_node.banner.info.progress_bg.slider_tx"] self.bountyBannerLvTx = self.uiMap["main_ui.top_node.bounty_node.banner.info.progress_bg.lv_tx"] self.uiMap["main_ui.top_node.bounty_node.banner.info.name"]:setText(I18N:getGlobalText(I18N.GlobalConst.BOUNTY_TITLE)) end function MainCityUI:initSetting() self.settingbtn = self.uiMap["main_ui.top_node.setting_btn"] self.settingbtn:addClickListener(function() ModuleManager.GameSettingManager:showSelectOtherBtnUI() end) end function MainCityUI:setTopNodeVisible(visible) self.topNode:setVisible(visible) end function MainCityUI:refreshTopNode() self:refreshBounty() self:refreshTask() end function MainCityUI:refreshBounty() local isOpen = DataManager.BountyData:getIsOpen() if not isOpen or self.mainComp:getCurModuleType() == GConst.MainCityConst.MAIN_MODULE.DAILY_CHALLENGE then self.bountyNode:setVisible(false) self.bountyRewardSpine:getSkeletonGraphic().enabled = false return end self.bountyNode:setVisible(true) if DataManager.BountyData:getIfCanClaimReward() then self.bountyRewardSpine:setVisible(true) self.bountyRewardSpine:playAnim("idle", true) self.bountyRewardSpine:getSkeletonGraphic().enabled = true self.bountyBannerInfo:setVisible(false) self.bountyBannerDescTx:setText(I18N:getGlobalText(I18N.GlobalConst.COLLET_REWARDS)) else self.bountyRewardSpine:setVisible(false) self.bountyRewardSpine:getSkeletonGraphic().enabled = false local bannerName = DataManager.BountyData:getBannerName() self.bountyBanner:setSprite(GConst.ATLAS_PATH.BOUNTY, bannerName) self.bountyBannerInfo:setVisible(true) self.bountyBannerDescTx:setText(GConst.EMPTY_STRING) local exp = DataManager.BountyData:getExp() local lvUpExp = DataManager.BountyData:getLvUpExp() local level = DataManager.BountyData:getLevel() local maxLevel = DataManager.BountyData:getMaxLevel() self.bountyBannerSliderTx:setText(exp .. "/" .. lvUpExp) self.bountyBannerSlider:getComponent(GConst.TYPEOF_UNITY_CLASS.BF_SLIDER).value = exp / lvUpExp if level >= maxLevel then self.bountyBannerLvTx:setText(I18N:getGlobalText(I18N.GlobalConst.STR_MAX)) else self.bountyBannerLvTx:setText(tostring(level)) end end end function MainCityUI:refreshTask() local isOpen = DataManager.DailyTaskData:getIsOpen() if not isOpen then self.taskBtn:setVisible(false) return end self.taskBtn:setVisible(true) local showRedPoint = DataManager.DailyTaskData:getIsShowRedPoint() if showRedPoint then self.taskBtn:addRedPoint(38, 34, 0.7) else self.taskBtn:removeRedPoint() 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() self:setTopNodeVisible(true) self:refreshTopNode() self:setSideBarVisible(true) else self:setTopNodeVisible(false) self:setSideBarVisible(false) end end function MainCityUI:updateTime() if self.selectedIndex == GConst.MainCityConst.BOTTOM_PAGE.SHOP and self.subComps[self.selectedIndex] then if self.subComps[self.selectedIndex] then self.subComps[self.selectedIndex]:refreshTime() end end self.inSideBarUpdate = true if self.leftBarList then for k, v in ipairs(self.leftBarList) do v:updateTime() end end if self.waitRefreshSideBar then self:refreshLeftBtns() self.waitRefreshSideBar = false end if self.rightBarList then for k, v in ipairs(self.rightBarList) do v:updateTime() end end self.inSideBarUpdate = false if self.waitRefreshSideBar then self:refreshRightBtns() self.waitRefreshSideBar = false end end function MainCityUI:updateSideBarStatus() if self.leftBarList then local minCount = GConst.MainCityConst.SIDE_BAR_MIN_COUNT for i = 1, minCount do local sideBarBtn = self.leftBarList[i] if sideBarBtn then if sideBarBtn:getIsShowRedPoint() then sideBarBtn:showRedPoint() else sideBarBtn:hideRedPoint() end end end local sideBarCount = #self.leftBarList if sideBarCount > minCount then local count = 0 for i = minCount + 1, sideBarCount do if self.leftBarList[i]:getIsShowRedPoint() then self.leftBarList[i]:showRedPoint() count = count + 1 else self.leftBarList[i]:hideRedPoint() end end if count > 0 then self:setLeftSideBarArrowRedPoint(true) else self:setLeftSideBarArrowRedPoint(false) end else self:setLeftSideBarArrowRedPoint(false) end end if self.rightBarList then local minCount = GConst.MainCityConst.SIDE_BAR_MIN_COUNT for i = 1, minCount do local sideBarBtn = self.rightBarList[i] if sideBarBtn then if sideBarBtn:getIsShowRedPoint() then sideBarBtn:showRedPoint() else sideBarBtn:hideRedPoint() end end end local sideBarCount = #self.rightBarList if sideBarCount > minCount then local count = 0 for i = minCount + 1, sideBarCount do if self.rightBarList[i]:getIsShowRedPoint() then self.rightBarList[i]:showRedPoint() count = count + 1 else self.rightBarList[i]:hideRedPoint() end end if count > 0 then self:setRightSideBarArrowRedPoint(true) else self:setRightSideBarArrowRedPoint(false) end else self:setRightSideBarArrowRedPoint(false) end end end function MainCityUI:setLeftSideBarArrowRedPoint(isShow) if self.isShowLeftSideBarArrowRedPoint == isShow then return end if isShow then if ModuleManager.MaincityManager:getIsMainCityLeftSideBarClose() then self.leftArrowBtn:addRedPoint(19, 10, 0.6) else self.leftArrowBtn:removeRedPoint() end else self.leftArrowBtn:removeRedPoint() end end function MainCityUI:setRightSideBarArrowRedPoint(isShow) if self.isShowRightSideBarArrowRedPoint == isShow then return end if isShow then if ModuleManager.MaincityManager:getIsMainCityRightSideBarClose() then self.rightArrowBtn:addRedPoint(19, 10, 0.6) else self.rightArrowBtn:removeRedPoint() end else self.rightArrowBtn:removeRedPoint() end end function MainCityUI:closeSideBarBtn(isLeft) if self.inSideBarUpdate then self.waitRefreshSideBar = true else self.waitRefreshSideBar = false if isLeft then self:refreshLeftBtns() else self:refreshRightBtns() end end end function MainCityUI:refreshBottomRp() local uiMap = self.root:genAllChildren() local heroRpObj = uiMap["main_ui.bottom_node.icons.ui_spine_obj_2.rp_node"] if DataManager.HeroData:getRp() then heroRpObj:addRedPoint(0, 0, 0.7) else heroRpObj:removeRedPoint() end local shopRpObj = uiMap["main_ui.bottom_node.icons.ui_spine_obj_3.rp_node"] if DataManager.ShopData:getRp() then shopRpObj:addRedPoint(0, 0, 0.7) else shopRpObj:removeRedPoint() end end function MainCityUI:refreshSettingBtn() if DataManager.MailData:getIsOpen() and DataManager.MailData:getRedPoint() then self.settingbtn:addRedPoint(40, 40, 0.7) else self.settingbtn:removeRedPoint() end end function MainCityUI:checkSideBarOpenStatus() -- 检查目前没开的侧边栏功能是否有可以开启的 for k, CellClass in pairs(self.sideBarClassMap) do local cell = self.sideBarCellMap[k] if cell and cell:getIsActive() then if not CellClass:getIsOpen() then return self:refreshAllSideBars() end else if CellClass:getIsOpen() then return self:refreshAllSideBars() end end end end -- 弹窗优先级: 升级>功能弹窗>英雄解锁弹窗>礼包弹窗>引导 function MainCityUI:checkMainPop() -- 检查是否升级 if DataManager.PlayerData:getIfCanLevelUp() then ModuleManager.PlayerManager:levelUp() return end -- 检查功能弹窗 if DataManager.PlayerData:getIfCanShowModuleUnlock() then ModuleManager.MaincityManager:showModuleUnlockUI() return end -- 是否是否有英雄解锁弹窗 if DataManager.HeroData:getIfCanShowHeroUnlock() then local list = DataManager.HeroData:getHeroChapterUnlockList() DataManager.HeroData:markShowHeroUnlock() if list and #list > 0 then ModuleManager.HeroManager:showHeroUnlockUI(list) return end end -- 引导 if self:checkTutorial() then return end -- 礼包 if self:checkGift() then return end end -- 检查引导 function MainCityUI:checkTutorial() if DataManager.ChapterData:getMaxChapterId() == 1 then if ModuleManager.TutorialManager:checkFuncTutorial(GConst.TutorialConst.PASS_ONE_CHAPTER) then return true end end if DataManager.ChapterData:boxCanGet(2, 1) then if ModuleManager.TutorialManager:checkFuncTutorial(GConst.TutorialConst.TWO_CHAPTER_BOX_CAN_GOT) then return true end end if DataManager.ChapterData:getMaxChapterId() == 2 then if ModuleManager.TutorialManager:checkFuncTutorial(GConst.TutorialConst.PASS_THREE_CHAPTER) then return true end end if DataManager.DailyChallengeData:isOpen() then if ModuleManager.TutorialManager:checkFuncTutorial(GConst.TutorialConst.UNLOCK_DAILY_CHALLENGE) then return true end end end -- 检查礼包(首充/章节/新手/助力/成长/金币顺序) function MainCityUI:checkGift() -- 引导其间不处理 if DataManager.TutorialData:getIsHaveTutorial() then return end -- 章节礼包 local chapterPopUpGifts = DataManager.ShopData:getPopUpGiftByType(PayManager.PURCHARSE_TYPE.CHAPTER_GIFT) -- 通用礼包 local beginnerGiftIds local levelUpGiftIds local firstRechargeIds local actPopUpGifts = DataManager.ShopData:getPopUpGiftByType(PayManager.PURCHARSE_TYPE.ACT_GIFT) if actPopUpGifts and #actPopUpGifts > 0 then -- 先遍历找出符合弹出的类型 for _, actId in ipairs(actPopUpGifts) do local cfgInfo = DataManager.ShopData:getActGiftConfig()[actId] if cfgInfo then -- 新手礼包 if cfgInfo.type == PayManager.PURCHARSE_ACT_TYPE.BEGINNER_GIFT then if not beginnerGiftIds then beginnerGiftIds = {} end table.insert(beginnerGiftIds, actId) end -- 助力礼包 if cfgInfo.type == PayManager.PURCHARSE_ACT_TYPE.LEVEL_UP_GIFT then if not levelUpGiftIds then levelUpGiftIds = {} end table.insert(levelUpGiftIds, actId) end -- 首充礼包 if cfgInfo.type == PayManager.PURCHARSE_ACT_TYPE.FIRST_RECHARGE then if not firstRechargeIds then firstRechargeIds = {} end table.insert(firstRechargeIds, actId) end end end end -- 特殊的 成长礼包 local growUpPopUpGifts = DataManager.ShopData:getPopUpGiftByType(PayManager.PURCHARSE_TYPE.GROW_UP_GIFT) -- 按顺序弹出(首充/章节/新手/助力/成长/金币顺序) -- 首充礼包 if firstRechargeIds and #firstRechargeIds > 0 then ModuleManager.ShopManager:triggerGiftPopUI(PayManager.PURCHARSE_TYPE.ACT_GIFT, firstRechargeIds[1]) return true end -- 章节礼包 if chapterPopUpGifts and #chapterPopUpGifts > 0 then ModuleManager.ShopManager:triggerGiftPopUI(PayManager.PURCHARSE_TYPE.CHAPTER_GIFT, chapterPopUpGifts[1]) return true end -- 新手礼包 if beginnerGiftIds and #beginnerGiftIds > 0 then ModuleManager.ShopManager:triggerGiftPopUI(PayManager.PURCHARSE_TYPE.ACT_GIFT, beginnerGiftIds[1]) return true end -- 助力礼包 if levelUpGiftIds and #levelUpGiftIds then ModuleManager.ShopManager:triggerGiftPopUI(PayManager.PURCHARSE_TYPE.ACT_GIFT, levelUpGiftIds[1]) return true end -- 成长礼包 if growUpPopUpGifts and #growUpPopUpGifts > 0 then ModuleManager.ShopManager:triggerGiftPopUI(PayManager.PURCHARSE_TYPE.GROW_UP_GIFT, growUpPopUpGifts[1]) return true end end function MainCityUI:getTaskIconPos() return self.taskBtn:getPosition() end function MainCityUI:getMallIconPos() return self.bottomBtnSpines[GConst.MainCityConst.BOTTOM_PAGE.SHOP]:getPosition() end function MainCityUI:getDailyChallengeIconPos() return self.subComps[GConst.MainCityConst.BOTTOM_PAGE.MAIN]:getDailyChallengeIconPos() end function MainCityUI:getSideBarActIconPos(moduleKey) for name, cell in pairs(self.leftBarList) do if moduleKey == cell:getModuleKey() then return cell:getBaseObject():getPosition() end end for name, cell in pairs(self.rightBarList) do if moduleKey == cell:getModuleKey() then return cell:getBaseObject():getPosition() end end return nil end function MainCityUI:isInSideBarLeft(moduleKey) for name, cell in pairs(self.leftBarList) do if moduleKey == cell:getModuleKey() then return true end end return false end function MainCityUI:isInSideBarRight(moduleKey) for name, cell in pairs(self.rightBarList) do if moduleKey == cell:getModuleKey() then return true end end return false end function MainCityUI:isActivSideBarModule(moduleKey) for name, cell in pairs(self.leftBarList) do if moduleKey == cell:getModuleKey() then return cell:getIsActive() and cell:getIsVisible() end end for name, cell in pairs(self.rightBarList) do if moduleKey == cell:getModuleKey() then return cell:getIsActive() and cell:getIsVisible() end end return nil end return MainCityUI