local UIMainTop = BaseClass("UIMainTop", UIBaseContainer)
local base = UIBaseContainer
local Localization = CS.GameEntry.Localization
local Resource = CS.GameEntry.Resource
local UIMainResourceProgress = require("UI.LWMainUI.Component.UIMainTop.UIMainResourceProgress")
local UIMainItemProgress = require("UI.LWMainUI.Component.UIMainTop.UIMainItemProgress")
local UIFirstChargeBtn = require("UI.LWMainUI.Component.UIMainTop.UIFirstChargeBtn")
local UIDailyPackBtn = require("UI.LWMainUI.Component.UIMainTop.UIDailyPackBtn")
local UIGovernmentBtn = require("UI.LWMainUI.Component.UIMainTop.UIGovernmentBtn")
local UIAttackCityBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainAttackCityBtn")
local UIAttackCityS0Btn = require("UI.LWMainUI.Component.UIMainTop.UIMainAttackCityS0Btn")
local UIKingBtn = require("UI.LWMainUI.Component.UIMainTop.UIKingBtn")
local UIDoomVanguardBtn = require("UI.LWMainUI.Component.UIMainTop.UIDoomVanguardBtn")
local UIEnterDragonBattle = require("UI.LWMainUI.Component.UIMainTop.UIEnterDragonBattle")
local UIEnterEpidemicBattle = require("UI.LWMainUI.Component.UIMainTop.UIEnterEpidemicBattle")
local UIEnterDsbDuelBattle = require("UI.DsbDuelBattlefield.Misc.EnterDsbDuelBattle")
local UIMainPopupPackEntrance = require("UI.UIMain.Component.UIMainRight.UIMainPopupPackEntrance")
local UIMainAllyDuelBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainAllyDuelBtn")
local UIMainGiftBoxActivityBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainGiftBoxActivityBtn")
local UIMainScratchActivityBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainScratchActivityBtn")
local UIMainThanksGivingActivityBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainThanksGivingActivityBtn")
local UIMainActivityGroupContent = require("UI.LWMainUI.Component.UIMainTop.UIMainActivityGroupContent")
local UIMainPiggyBankBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainPiggyBankBtn")
local UIMainInfiniteGiftBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainInfiniteGiftBtn")
local UIMainGoldBrick = require("UI.LWMainUI.Component.UIMainTop.UIMainGoldBrick")
local BuffIcon = require("UI.LWMainUI.Component.UIMainLeft.BuffIcon")
local UIMainActivityTips = require("UI.LWMainUI.Component.UIMainTop.UIMainActivityTips")
local UIMainWinterStormBack = require("UI.LWMainUI.Component.UIMainTop.UIMainWinterStormBack")
local UIMainCrossServerBubbleTips = require("UI.LWMainUI.Component.UIMainTop.UIMainCrossServerBubbleTips")
local UIMainAccountBindTipBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainAccountBindTipBtn")
local LWMainUIActivityAlarmClockDispatch = require("UI.LWMainUI.Component.UIMainTop.LWMainUIActivityAlarmClockDispatch")
local UIMainCoppaAppealBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainCoppaAppealBtn")
local LWMainCityFightAlarmObj = require("UI.LWMainUI.Component.UIMainTop.LWMainCityFightAlarmObj")
local ActZoneMobilizationItem = require("UI.LWMainUI.Component.UIMainTop.ActZoneMobilizationItem")
local UIMainActMeteoriteBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainActMeteoriteBtn")
local UIMainActMigrationBtn = require("UI.LWMainUI.Component.UIMainTop.UIMainActMigrationBtn")
local UIMeteoriteNoticeItem = require("UI.UIMainMiniMap.Component.MainMiniMapMeteoriteNoticeItem")
local UILWDominatorCockatriceUnlockMainUIEntranceComponent = require("UI/UILWDominator/CockatriceUnlock/MainUI/UILWDominatorCockatriceUnlockMainUIEntranceComponent")
local resource_bar_path = "ResourceBar/layout"
local goldStore_path = "ResourceBar/goldStore"
local goldIcon_path = "ResourceBar/goldStore/goldStoreIcon/goldIcon"
local goldStoreBtn_path = "ResourceBar/goldStore/goldStoreIcon"
local goldStoreGoldCount_path = "ResourceBar/goldStore/goldStoreIcon/goldStoreCount"
local goldStoreRed_path = "ResourceBar/goldStore/goldStoreIcon/goldStoreRed"
local goldStoreRedNum_path = "ResourceBar/goldStore/goldStoreIcon/goldStoreRed/goldStoreRedNum"
local goldStoreNewFlag_path = "ResourceBar/goldStore/goldStoreIcon/goldStoreNew"
local gold_brick_path = "ResourceBar/layout/GoldBrick"
local power_text_path = "ResourceBar/layout/Power/Bg/PowerText"
local power_icon_path = "ResourceBar/layout/Power/PowerIcon"
local power_path = "ResourceBar/layout/Power"
local common_red_point_path = "ResourceBar/layout/Power/PowerCommonRedPoint"
local buff_list_root_path = "ResourceBar/layout/BuffListRoot"
local buff_list_path = "ResourceBar/layout/BuffListRoot/BuffList"
local cross_server_root_path = "ResourceBar/layout/CrossServerRoot"
local tip_bg_path = "ResourceBar/layout/CrossServerRoot/tipBg"
local move_city_root_path = "ResourceBar/layout/MoveCityRoot"
local img_icon_path = "ResourceBar/layout/MoveCityRoot/moveCityTipBg/img_icon"
local tip_text_path = "ResourceBar/layout/MoveCityRoot/moveCityTipBg/context/tipText"
local txt_time_path = "ResourceBar/layout/MoveCityRoot/moveCityTipBg/context/txt_time"
local btn_back_home_path = "ResourceBar/layout/MoveCityRoot/moveCityTipBg/btn_backHome"
local img_progress_path = "ResourceBar/layout/MoveCityRoot/moveCityTipBg/img_progress"
local move_city_tip_bg_path = "ResourceBar/layout/MoveCityRoot/moveCityTipBg"
local tip_pos_path = "ResourceBar/layout/MoveCityRoot/moveCityTipBg/tipPos"
local btn_tip_path = "ResourceBar/layout/MoveCityRoot/moveCityTipBg/btn_tip"
local new_bubble_root_path = "ResourceBar/layout/MoveCityRoot/moveCityTipBg/NewBubbleRoot"
local activityCenterBtn_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/ActivityCenterBtn"
local activityCenterBtnArea_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/ActivityCenterBtn"
local activityCenterBtnText_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/ActivityCenterBtn/ActivityCenterBtnText"
local activityCenter_common_red_point_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/ActivityCenterBtn/CommonRedPoint"
local activityCenterBtnIcon_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/ActivityCenterBtn/Bg"
local themeActivityBtn_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/ThemeActivityBtn"
local themeActivityBtnArea_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/ThemeActivityBtn"
local themeActivityBtnText_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/ThemeActivityBtn/ThemeActivityBtnTxt"
local themeActivityBtnRedPoint_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/ThemeActivityBtn/ThemeActivityBtnRed"
local themeActivityBtnRedPointNum_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/ThemeActivityBtn/ThemeActivityBtnRed/ThemeActivityBtnRedTxt"
local dailyPackBtn_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/DailyPackBtn"
local topBtns_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns"
local popupPackageBtnTemplate_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/UIPopupPackageT"
local enter_dragon_battle_path = "EnterDragonBattle"
local enter_winter_storm_path = "UIWinterStormBack"
local enter_epidemic_battle_path = "EnterEpidemicBattle"
local enter_dsb_duel_path = "DsbDuelBattle"
local enter_gift_box_activity_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/GiftBoxActivityBtn"
local enter_thanks_giving_activity_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/ThanksGivingActivityBtn"
local ui_main_activity_group_content_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/UIMainActivityGroupContent"
local account_bind_tip_btn_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/AccountBindTipBtn"
local coppa_appeal_btn_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/UIMain_icon_coppaAppeal"
local enter_scratch_activity_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/ScratchActivityBtn"
local piggy_bank_btn_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/PiggyBankBtn"
local infiniteGift_btn_path = "TopBtnsContainer/LeftColBtns/Viewport/LeftTopBtns/InfiniteGiftBtn"
local dialyPack_new_tag_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/DailyPackBtn/DailyPackNew"
local bubble_root_path = "ResourceBar/layout/CrossServerRoot/tipBg/BubbleRoot"
local zone_mobilization_btn_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/ZoneMobilizationBtn"
local meteorite_notice_root_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/MeteoriteNoticeRoot"
local dominatorCockatriceUnlockBtn_path = "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/DominatorCockatriceUnlockBtn"
local HideExtraResourceDelayTime = 1.5
local CountNumJumpTimes = 10
local ChangePerTime = 100
local DelayTime = 0.5
local ResourceCellIndexStart = 0
local AllianceCellIndexStart = 10
local ICON_PATH = "Assets/Main/Sprites/UI/UIMain/LWMainUI/%s.png"
local ResetResourceType = {
  ResourceType.Petroleum,
  ResourceType.FLINT,
  ResourceType.OBSIDIAN,
  ResourceType.Wood,
  ResourceType.Metal,
  ResourceType.Food
}
local ResourceType2FuncUnlockID = {
  [ResourceType.Wood] = LWFunctionUnlockType.MainUI_CoinBar,
  [ResourceType.Metal] = LWFunctionUnlockType.MainUI_MetalBar,
  [ResourceType.Food] = LWFunctionUnlockType.MainUI_FoodBar,
  [ResourceType.Petroleum] = LWFunctionUnlockType.MainUI_PetroleumBar
}
local RefreshPackInfo = function(self)
  if self.firstChargeBtn ~= nil then
    self.firstChargeBtn:RefreshShowState()
  end
  if self.dailyPackBtn ~= nil then
    self.dailyPackBtn:RefreshShowState()
  end
  if self.governmentBtn ~= nil then
    self.governmentBtn:RefreshShowState()
  end
  if self.attackCityBtn ~= nil then
    self.attackCityBtn:RefreshShowState()
  end
  if self.attackCityS0Btn ~= nil then
    self.attackCityS0Btn:RefreshShowState()
  end
  if self.kingBtn ~= nil then
    self.kingBtn:RefreshShowState()
  end
  self:RefreshSeasonBtnShow()
  if self.DoomVanguardBtn ~= nil then
    self.DoomVanguardBtn:RefreshShowState()
  end
  self:RefreshPopupPackageEntrances()
  self:RefreshStoreRedPoint()
  self:RefreshPiggyBankBtn()
end
local RefreshChargeBtnRedPoint = function(self)
  if self.dailyPackBtn ~= nil then
    self.dailyPackBtn:RefreshShowState()
  end
  self:RefreshStoreRedPoint()
end
local RefreshFristPayBtn = function(self)
  if self.firstChargeBtn ~= nil then
    self.firstChargeBtn:RefreshShowState()
  end
end
local RefreshActivityBtn = function(self)
  self:RefreshAlCompeteBtn()
  self:RefreshGiftBoxBtn()
  self:RefreshThanksGivingBtn()
  self:RefreshScratchBtn()
  self:RefreshPiggyBankBtn()
  self:RefreshInfiniteGiftBtn()
  self:RefreshUIMainActivityGroupContent()
  self:RefreshActivityTips()
  if self.governmentBtn ~= nil then
    self.governmentBtn:RefreshShowState()
  end
  if self.kingBtn ~= nil then
    self.kingBtn:RefreshShowState()
  end
  self:RefreshSeasonBtnShow()
  if not DataCenter.ActivityListDataManager then
    return
  end
  if not self.activityCenterBtn then
    return
  end
  if self.attackCityBtn ~= nil then
    self.attackCityBtn:RefreshShowState()
  end
  if self.attackCityS0Btn ~= nil then
    self.attackCityS0Btn:RefreshShowState()
  end
  if self.DoomVanguardBtn ~= nil then
    self.DoomVanguardBtn:RefreshShowState()
  end
  self:UpdateWhenAnim(nil)
  if self.dailyPackBtn ~= nil then
    self.dailyPackBtn:RefreshShowState()
  end
  local unlock = self.view.ctrl:GetActivityCenterBtnShow()
  if not unlock then
    self.activityCenterBtn:SetActive(false)
    return
  end
  DataCenter.ActivityListDataManager:SortActivityArr()
  local list = DataCenter.ActivityListDataManager:GetNowActivityList(false)
  if not table.IsNullOrEmpty(list) then
    self.activityCenterBtn:SetActive(true)
    if RaceEntranceUtil.IsNewMigration() then
      local iconName = DataCenter.ActivityListDataManager:GetActivityBtnIconPath()
      if not string.IsNullOrEmpty(iconName) then
        self.activityCenterBtnIcon:LoadSprite(iconName)
      else
        self.activityCenterBtnIcon:LoadSprite(string.format(ICON_PATH, "mjc_huodong_huizong"))
      end
    else
      self.activityCenterBtnIcon:LoadSprite(string.format(ICON_PATH, "mjc_huodong_huizong"))
    end
    local redDotCount, rewardCount, tipCount = DataCenter.ActivityListDataManager:GetTotalRedDotCount()
    self.activityCenterCommonRedPoint:SetNum(rewardCount, tipCount)
  else
    self.activityCenterBtn:SetActive(false)
  end
end

function UIMainTop:DelayRefreshActivityBtn()
  self.actRedDirtyFlag = true
end

local RefreshThemeActivityBtn = function(self)
  if not DataCenter.ActivityListDataManager then
    return
  end
  if not self.themeActivityBtn then
    return
  end
  local unlock = DataCenter.LWFunctionUnlockManager:CheckCanShow(LWFunctionUnlockType.MainUI_Activity)
  if not unlock then
    self.themeActivityBtn:SetActive(false)
    return
  end
  self.themeActivityBtnEndTime = 0
  DataCenter.ActivityListDataManager:SortActivityArr()
  local list = DataCenter.ActivityListDataManager:GetNowActivityList(false)
  local themeActivityList = {}
  if not table.IsNullOrEmpty(list) then
    for k, v in pairs(list) do
      if v.hideInActivityPanel and v.is_package == ActivityEntranceType.ThemeActivity then
        table.insert(themeActivityList, v)
      end
    end
  end
  if 0 < #themeActivityList then
    self.themeActivityBtn:SetActive(true)
    local redDotCount = DataCenter.ActivityListDataManager:GetTotalThemeActivityRedDotCount()
    if 0 < redDotCount then
      self.themeActivityBtnRedPoint:SetActive(true)
      self.themeActivityBtnRedPointNum:SetText(redDotCount)
    else
      self.themeActivityBtnRedPoint:SetActive(false)
    end
    self.themeActivityBtnEndTime = themeActivityList[1].endTime
  else
    self.themeActivityBtn:SetActive(false)
  end
end
local RefreshAllActivityBtn = function(self)
  RefreshActivityBtn(self)
  RefreshThemeActivityBtn(self)
  self:RefreshCoppaAppealBtn()
  self:RefreshAccountBindTipBtn()
end

function UIMainTop:RefreshStoreRedPoint()
  local showNewTag = false
  if self.goldStoreNewFlagN then
    local diamondStoreNewTag = WelfareController.EntryShowNewTag(RechargeEntryType.Store)
    self.goldStoreNewFlagN:SetActive(diamondStoreNewTag)
    showNewTag = diamondStoreNewTag
  end
  if showNewTag then
    self.goldStoreRedN:SetActive(false)
    return
  end
  local rechargeList = WelfareController.getShowTagInfosWithType(RechargeEntryType.Store)
  local redNum = 0
  for k, v in pairs(rechargeList) do
    redNum = redNum + v:getRedDotNum()
  end
  if self.goldStoreRedN then
    self.goldStoreRedN:SetActive(0 < redNum)
  end
  if self.goldStoreRedNumN then
    self.goldStoreRedNumN:SetText(redNum)
  end
end

function UIMainTop:OnCreate()
  base.OnCreate(self)
  local ok, errorMsg = pcall(function()
    self:ComponentDefine()
    self:DataDefine()
    self:ReqActivityData()
  end)
  if not ok and errorMsg then
    Logger.LogError(errorMsg)
  end
end

function UIMainTop:OnDestroy()
  self:ComponentDestroy()
  self:DataDestroy()
  base.OnDestroy(self)
end

function UIMainTop:OnEnable()
  base.OnEnable(self)
  self.active = true
end

function UIMainTop:OnDisable()
  base.OnDisable(self)
  self.active = false
end

function UIMainTop:OnBuildLevelUp()
  self:RefreshCells()
  if self.dailyPackBtn ~= nil then
    self.dailyPackBtn:RefreshShowState()
  end
end

function UIMainTop:ComponentDefine()
  self.buff_content = self:AddComponent(UIGridLayoutGroup, buff_list_path)
  self.view:RegisterFunctionUnlock(LWFunctionUnlockType.MainUI_Buff, self.buff_content)
  self.goldBrick = self:AddComponent(UIMainGoldBrick, gold_brick_path)
  self.power_root = self:AddComponent(UIBaseContainer, power_path)
  self.power_num = self:AddComponent(UIText, power_text_path)
  self.power_icon = self:AddComponent(UIText, power_icon_path)
  self.view:RegisterFunctionUnlock(LWFunctionUnlockType.MainUI_PowerBar, self.power_root.gameObject)
  self.power_root_btn = self:AddComponent(UIButton, power_path)
  self.power_root_btn:SetOnClick(function()
    self.commonRedPoint:SetViewed()
    UIUtil.OpenPowerOverviewPanel()
  end)
  self.commonRedPoint = self:AddComponent(UICommonRedPoint, common_red_point_path)
  self.commonRedPoint:SetType(CommonRedPointPriority.LevelNormal)
  self.buff_list_root = self:AddComponent(UIBaseContainer, buff_list_root_path)
  self.cross_server_root = self:AddComponent(UIBaseContainer, cross_server_root_path)
  self.crossServerTip = self:AddComponent(UIBaseComponent, tip_bg_path)
  self.crossServerTipText = self:AddComponent(UIText, tip_bg_path .. "/tipText")
  self.crossServerBackHomeBtn = self:AddComponent(UIButton, tip_bg_path .. "/backHomeBtn")
  self.crossServerBackHomeBtn:SetOnClick(function()
    if LuaEntry.Player:IsInSelfServer() then
      CrossServerUtil.BackToSrcServer()
    else
      CrossServerUtil.JumpToServerByServerId(LuaEntry.Player:GetSelfServerId(), MoveCrossServerType.BackToSrcServer, LuaEntry.Player:GetMainWorldPos())
    end
  end)
  self.crossServerMaxBtn = self:AddComponent(UIButton, tip_bg_path .. "/maxBtn")
  self.crossServerMaxBtn:SetOnClick(function()
    if self.enter_dragon_battle and self.enter_dragon_battle:IsSmallShow() then
      self.enter_dragon_battle:SetMaxShow()
    elseif self.enter_winter_storm and self.enter_winter_storm:IsSmallShow() then
      self.enter_winter_storm:SetMaxShow()
    elseif self.enter_epidemic_battle and self.enter_epidemic_battle:IsSmallShow() then
      self.enter_epidemic_battle:SetMaxShow()
    end
  end)
  self.cross_server_root:SetActive(false)
  self.crossServerTip:SetActive(false)
  if not IsNull(self.transform:Find(bubble_root_path)) then
    self.crossServerBubbleRoot = self:AddComponent(UIMainCrossServerBubbleTips, bubble_root_path)
    self.crossServerBubbleRoot:SetActive(false)
  end
  self.move_city_root = self:AddComponent(UIBaseContainer, move_city_root_path)
  self.img_icon = self:AddComponent(UIImage, img_icon_path)
  self.tip_text = self:AddComponent(UITextMeshProUGUIEx, tip_text_path)
  self.txt_time = self:AddComponent(UITextMeshProUGUIEx, txt_time_path)
  self.btn_back_home = self:AddComponent(UIButton, btn_back_home_path)
  if not IsNull(self.transform:Find(new_bubble_root_path)) then
    self.new_bubble_root = self:AddComponent(UIMainCrossServerBubbleTips, new_bubble_root_path)
    self.new_bubble_root:SetActive(false)
  end
  self.img_progress = self:AddComponent(UIImage, img_progress_path)
  self.move_city_tip_bg = self:AddComponent(UIBaseContainer, move_city_tip_bg_path)
  self.tip_pos = self:AddComponent(UIBaseContainer, tip_pos_path)
  self.btn_tip = self:AddComponent(UIButton, btn_tip_path)
  self.move_city_root:SetActive(false)
  self.btn_back_home:SetOnClick(function()
    local selfServerId = LuaEntry.Player:GetSelfServerId()
    local curServerId = LuaEntry.Player:GetCurServerId()
    local isBigMapMode, curSameGroup, srcSameGroup, loginSameGroup = SeasonUtil.InSeasonBigMapMode(curServerId)
    if isBigMapMode and not srcSameGroup then
      CrossServerUtil.BackToSrcServer()
    elseif LuaEntry.Player:IsInSelfServer() then
      CrossServerUtil.BackToSrcServer()
    else
      CrossServerUtil.JumpToServerByServerId(selfServerId, MoveCrossServerType.BackToSrcServer, LuaEntry.Player:GetMainWorldPos())
    end
  end)
  self.btn_tip:SetOnClick(function()
    if self.new_bubble_root then
      self.new_bubble_root:ImmediatelyStop()
    end
    UIManager:GetInstance():OpenWindow(UIWindowNames.LWUIMoveCityTip, {anim = false}, {
      bg = self.move_city_tip_bg.rectTransform,
      position = self.tip_pos.rectTransform.position
    })
  end)
  self.resourceCells_bar = self:AddComponent(UIBaseContainer, resource_bar_path)
  if Config.IsPC() then
    CS.RectTransformUtils.ApplyAnchorPreset(self.resourceCells_bar.rectTransform, CS.UnityEngine.TextAnchor.UpperLeft, true, true)
  end
  self.goldStoreN = self:AddComponent(UIBaseContainer, goldStore_path)
  self.goldStoreN:SetActive(true)
  self.goldIcon = self:AddComponent(UIImage, goldIcon_path)
  self.goldStoreBtnN = self:AddComponent(UIButton, goldStoreBtn_path)
  self.isOn = true
  self.goldStoreBtnN:SetOnClick(function()
    self.view.ctrl:OnClickGoldBtn()
    UIManager:GetInstance():OpenWindow(UIWindowNames.LWBuyDiamond, {anim = true}, nil, nil, RechargeEntryType.Store)
  end)
  self.goldStoreGoldCountN = self:AddComponent(UIText, goldStoreGoldCount_path)
  self.goldStoreRedN = self:AddComponent(UIBaseContainer, goldStoreRed_path)
  self.goldStoreRedNumN = self:AddComponent(UIText, goldStoreRedNum_path)
  self.goldStoreNewFlagN = self:AddComponent(UIImage, goldStoreNewFlag_path)
  self.rightTopBtnsRoot = self:AddComponent(UIBaseContainer, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns")
  self.governmentBtn = self:AddComponent(UIGovernmentBtn, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/KingActivity")
  self.attackCityBtn = self:AddComponent(UIAttackCityBtn, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/AttackCityActivity")
  self.attackCityS0Btn = self:AddComponent(UIAttackCityS0Btn, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/AttackCityActivityNew")
  self.kingBtn = self:AddComponent(UIKingBtn, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/NewKingActivity")
  self.firstChargeBtn = self:AddComponent(UIFirstChargeBtn, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/FirstChargeBtn")
  self.DoomVanguardBtn = self:AddComponent(UIDoomVanguardBtn, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/DoomVanguardBtn")
  self.activityCenterBtn = self:AddComponent(UIBaseContainer, activityCenterBtn_path)
  self.activityCenterBtnArea = self:AddComponent(UIButton, activityCenterBtnArea_path)
  self.activityCenterBtnArea:SetOnClick(function()
    self.activityCenterCommonRedPoint:SetViewed()
    GoToUtil.GotoOpenView(UIWindowNames.UIActivityCenterTable)
  end)
  self.activityCenterBtnIcon = self:AddComponent(UIImage, activityCenterBtnIcon_path)
  self.activityCenterBtnText = self:AddComponent(UIText, activityCenterBtnText_path)
  self.activityCenterBtnText:SetLocalText(2000046)
  self.activityCenterCommonRedPoint = self:AddComponent(UICommonRedPoint, activityCenter_common_red_point_path)
  self.activityCenterCommonRedPoint:SetType(CommonRedPointPriority.Level1)
  self.dailyPackBtn = self:AddComponent(UIDailyPackBtn, dailyPackBtn_path)
  self.topBtns = self:AddComponent(UIBaseContainer, topBtns_path)
  self.popupPackageBtn = self:AddComponent(UIMainPopupPackEntrance, popupPackageBtnTemplate_path)
  self.themeActivityBtn = self:AddComponent(UIBaseContainer, themeActivityBtn_path)
  self.themeActivityBtnArea = self:AddComponent(UIButton, themeActivityBtnArea_path)
  self.themeActivityBtnArea:SetOnClick(function()
    GoToUtil.GotoOpenView(UIWindowNames.UIThemeActivityTable)
  end)
  self.themeActivityBtnText = self:AddComponent(UIText, themeActivityBtnText_path)
  self.themeActivityBtnRedPoint = self:AddComponent(UIBaseContainer, themeActivityBtnRedPoint_path)
  self.themeActivityBtnRedPointNum = self:AddComponent(UIText, themeActivityBtnRedPointNum_path)
  self.view:RegisterFunctionUnlock(LWFunctionUnlockType.MainUI_GoldBar, self.goldStoreN.gameObject)
  self.view:RegisterFunctionUnlock(LWFunctionUnlockType.MainUI_FirstPay, self.firstChargeBtn.gameObject)
  self.gift_box_activity_btn = self:AddComponent(UIMainGiftBoxActivityBtn, enter_gift_box_activity_path)
  self.gift_box_activity_btn:SetActive(false)
  self.thanks_giving_activity_btn = self:AddComponent(UIMainThanksGivingActivityBtn, enter_thanks_giving_activity_path)
  self.thanks_giving_activity_btn:SetActive(false)
  self.ui_main_activity_group_content = self:AddComponent(UIMainActivityGroupContent, ui_main_activity_group_content_path)
  self.scratch_activity_btn = self:AddComponent(UIMainScratchActivityBtn, enter_scratch_activity_path)
  self.scratch_activity_btn:SetActive(false)
  self.piggy_bank_btn = self:AddComponent(UIMainPiggyBankBtn, piggy_bank_btn_path)
  self.piggy_bank_btn:SetActive(false)
  self.allyDuelBtn = self:AddComponent(UIMainAllyDuelBtn, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/AllyDuel")
  self.actMeteoriteBtn = self:AddComponent(UIMainActMeteoriteBtn, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/ActMeteoriteBtn")
  self.actMigrationBtn = self:AddComponent(UIMainActMigrationBtn, "TopBtnsContainer/RightColBtns/Viewport/RightTopBtns/ActMigrationBtn")
  self.infiniteGiftBtn = self:AddComponent(UIMainInfiniteGiftBtn, infiniteGift_btn_path)
  self.dialyPackNew = self:AddComponent(UIBaseContainer, dialyPack_new_tag_path)
  self.meteoriteNoticeRoot = self.transform:Find(meteorite_notice_root_path)
  if IsNotNull(self.meteoriteNoticeRoot) then
    self.meteoriteNoticeRoot.gameObject:SetActive(false)
  end
  self.activityTips = self:AddComponent(UIMainActivityTips, "TopBtnsContainer/ActivityTips")
  self.accountBindTipBtn = self:AddComponent(UIMainAccountBindTipBtn, account_bind_tip_btn_path)
  self.accountBindTipBtn:SetActive(false)
  self.coppaAppealBtn = self:AddComponent(UIMainCoppaAppealBtn, coppa_appeal_btn_path)
  self.coppaAppealBtn:SetActive(false)
  self.zone_mobilization_btn = self:AddComponent(ActZoneMobilizationItem, zone_mobilization_btn_path)
  self.alarmClockDispatch = self:AddComponent(LWMainUIActivityAlarmClockDispatch, "")
end

function UIMainTop:ComponentDestroy()
  self:DestroyBuff()
  if self.epidemicReq ~= nil then
    self.epidemicReq:Destroy()
    self.epidemicReq = nil
  end
  self.enter_epidemic_battle = nil
  if self.winterReq ~= nil then
    self.winterReq:Destroy()
    self.winterReq = nil
  end
  self.enter_winter_storm = nil
  if self.dragonReq ~= nil then
    self.dragonReq:Destroy()
    self.dragonReq = nil
  end
  self.enter_dragon_battle = nil
  if self.dsbDuelReq ~= nil then
    self.dsbDuelReq:Destroy()
    self.dsbDuelReq = nil
  end
  self.enter_dsb_duel_battle = nil
  self.buff_content = nil
  self.power_icon = nil
  self.power_num = nil
  self.resourceCells_bar = nil
  self.goldStoreN = nil
  self.goldStoreBtnN = nil
  self.goldStoreGoldCountN = nil
  self.goldStoreRedN = nil
  self.goldStoreRedNumN = nil
  self.goldStoreNewFlagN = nil
  self.firstChargeBtn = nil
  self.governmentBtn = nil
  self.attackCityBtn = nil
  self.attackCityS0Btn = nil
  self.kingBtn = nil
  self.SeasonBtn = nil
  self.OffSeasonBtn = nil
  self.DoomVanguardBtn = nil
  self.farmerBtn = nil
  self.activityCenterBtn = nil
  self.activityCenterBtnIcon = nil
  self.activityCenterBtnArea = nil
  self.activityCenterBtnText = nil
  self.activityCenterCommonRedPoint = nil
  self.themeActivityBtn = nil
  self.themeActivityBtnArea = nil
  self.themeActivityBtnText = nil
  self.themeActivityBtnRedPoint = nil
  self.themeActivityBtnRedPointNum = nil
  self.dailyPackBtn = nil
  self.topBtns = nil
  self.popupPackageBtn = nil
  self.activityGotoTip = nil
  self.activityGotoTipText = nil
  self.activityGotoTipGotoBtn = nil
  self.jumpAction = nil
  self.meteoriteNotice = nil
  self.seasonResDownload = nil
  self.rightTopBtnsRoot = nil
  self.zone_mobilization_btn = nil
  self.dominatorCockatriceUnlockBtn = nil
  self.move_city_root = nil
  self.img_icon = nil
  self.tip_text = nil
  self.txt_time = nil
  self.btn_back_home = nil
  self.tip_pos = nil
  self.img_progress = nil
  self.move_city_tip_bg = nil
  self.btn_tip = nil
  self.new_bubble_root = nil
  self:DestroyActivityAlarmClockView()
  self:DestroyCityFightAlarmView()
  self:DestroyDominatorEntrance()
  self.alarmClockDispatch = nil
end

function UIMainTop:DataDefine()
  self._resNumShow = 0
  self._resNumTarget = 0
  self._resNumDelta = 0
  self._lastSetTime = 0
  
  function self.delay_timer_action()
    self:DelayRefreshTimerBallBack()
  end
  
  self.delayTimer = nil
  self.showList = {}
  self.needWaitLoadCount = 0
  self.resourceCells = {}
  self.itemCells = {}
  self.resourceItemCells = {}
  self.allianceItemCells = {}
  self.showGoldStore = true
  self.cacheGoldStoreType = nil
  
  function self.delay_refresh_resource_timer_action()
    self:DelayRefreshResourceTimerBallBack()
  end
  
  self.delayRefreshResourceTimer = nil
  self.isInPve = false
  self.prevStrComRedPointCount = 0
  self.sortedActivityCheckerList = {}
  self.buff_content_item_max = toInt(LuaEntry.DataConfig:TryGetNum("interface_buff_icon", "k1", 8))
  if self.buff_content_item_max < 1 then
    self.buff_content_item_max = 8
  end
  self.themeActivityBtnTextStr = nil
  self.actRedDirtyFlag = false
end

function UIMainTop:DataDestroy()
  self.allianceItemCells = {}
  self.sortedActivityCheckerList = {}
  self.delay_refresh_resource_timer_action = nil
  self.prevStrComRedPointCount = 0
  self.jumpAction = nil
  self.actRedDirtyFlag = nil
end

function UIMainTop:ReqActivityData()
  DataCenter.LWZoneMobilizationManager:RequestZoneMobilizationDonatedInfoData(4)
end

function UIMainTop:ReInit()
  self:DeleteDelayRefreshTimer()
  self:DeleteDelayRefreshResourceTimer()
  self._resNumShow = self.view.ctrl:GetGoldNum()
  self._resNumTarget = self._resNumShow
  self.goldStoreGoldCountN:SetText(string.GetFormattedGoldNum(self._resNumShow))
  local param = {}
  param.list = ResetResourceType
  param.uiName = UIWindowNames.UIMain .. "Default"
  self.showList = {param}
  self:RefreshCells()
  RefreshAllActivityBtn(self)
  RefreshPackInfo(self)
  self:RefreshCoppaAppealBtn()
  self:RefreshStoreRedPoint()
  self:RefreshCrossServerTip()
  self:RefreshBuff()
  self:RefreshPower()
  self:RefreshPowerRed()
  self:RefreshShowActivityAlarmClockView()
  self:RefresSeasonResourceDownloadBtn()
  self:RefreshZoneMobilizationAct()
  self:RefreshDominatorEntrance()
end

function UIMainTop:GetPowerPosition()
  return self.power_icon.gameObject.transform.position
end

function UIMainTop:RefreshPower()
  local playerPower = LuaEntry.Player.power
  self.power_num:SetText(string.GetFormattedSeperatorNum(math.floor(playerPower)))
end

function UIMainTop:RefreshPowerRed()
  local seasonNum = SeasonUtil.GetSeason()
  self.commonRedPoint:SetDefaultVisible(DataCenter.LWDevelopRecommendManager:IsShowEntranceRed() and seasonNum <= 2)
end

function UIMainTop:OnGoldBrickUpdate()
  if self.goldBrick then
    local status = self.goldBrick:GetActive()
    self.goldBrick:Refresh()
    if self.goldBrick:GetActive() ~= status then
      self:RefreshCells()
    end
  end
end

function UIMainTop:RefreshCrossServerTip()
  local player = LuaEntry.Player
  local mySourceServerId = player:GetSourceServerId()
  local loginServerId = player:GetSelfServerId()
  local curServerId = player:GetCurServerId()
  local curScene = CS.SceneManager.CurrSceneID
  local isBigMapMode, curSameGroup, srcSameGroup, loginSameGroup = SeasonUtil.InSeasonBigMapMode(curServerId)
  if isBigMapMode and srcSameGroup and loginSameGroup then
    self.move_city_root:SetActive(false)
    self.cross_server_root:SetActive(false)
    self.crossServerTip:SetActive(false)
    self.crossServerMaxBtn:SetActive(false)
  elseif (curServerId ~= mySourceServerId or loginServerId ~= mySourceServerId) and curScene == SceneManagerSceneID.World or loginServerId ~= mySourceServerId and curScene == SceneManagerSceneID.City then
    self.cross_server_root:SetActive(false)
    self.move_city_root:SetActive(true)
    self.tip_text:SetLocalText("world_cross_teleport_tips_1004", curServerId)
    local canMoveCity = MoveCityUtil.CanMoveCity()
    self.img_progress:SetActive(canMoveCity)
    local cdTime, cd = CrossServerUtil.GetCrossMoveCD()
    local canShowCd = 0 < cdTime and canMoveCity
    self.img_progress:SetFillAmount(canShowCd and 1 - cdTime / cd or 1)
    self.txt_time:SetActive(canShowCd)
    if canShowCd then
      self.txt_time:SetText(UITimeManager:GetInstance():GetFormattedTime(cdTime / 1000))
    end
  elseif self.enter_dragon_battle and self.enter_dragon_battle:IsSmallShow() or self.enter_winter_storm and self.enter_winter_storm:IsSmallShow() or self.enter_epidemic_battle and self.enter_epidemic_battle:IsSmallShow() then
    self.move_city_root:SetActive(false)
    self.cross_server_root:SetActive(true)
    self.crossServerTip:SetActive(true)
    self.crossServerBackHomeBtn:SetActive(false)
    self.crossServerMaxBtn:SetActive(true)
    self.crossServerTipText:SetLocalText("Desert_strom_tips1028")
  else
    self.move_city_root:SetActive(false)
    self.cross_server_root:SetActive(false)
    self.crossServerTip:SetActive(false)
    self.crossServerMaxBtn:SetActive(false)
  end
  self:RefreshBuff()
end

function UIMainTop:PrepareBuffData()
  local buff_content_item_max = toInt(self.buff_content_item_max)
  if buff_content_item_max < 1 then
    buff_content_item_max = 8
  end
  local buffDatas = DataCenter.StatusManager:GetAllBuffData(true)
  if buff_content_item_max <= #buffDatas then
    return buffDatas
  end
  local flags = DataCenter.WarFlagDataManager:GetAllFlagAffectMe()
  buffDatas = table.mergeArray(buffDatas, flags)
  if buff_content_item_max <= #buffDatas then
    return buffDatas
  end
  local temperatureBuffs = DataCenter.TemperatureManager:GetMyTemperatureBuff()
  table.extendArray(buffDatas, temperatureBuffs)
  if buff_content_item_max <= #buffDatas then
    return buffDatas
  end
  local officialPositionBuffViewData = DataCenter.GovernmentManager:GetOfficialPositionBuffViewData()
  if officialPositionBuffViewData ~= nil then
    table.insert(buffDatas, 1, officialPositionBuffViewData)
  end
  if buff_content_item_max <= #buffDatas then
    return buffDatas
  end
  local inSeason = SeasonUtil.IsInSeason()
  if inSeason then
    local theSeasonType = SeasonUtil.GetSeasonType()
    local numResistance = SeasonUtil.GetSelfSeasonResistanceValue()
    if 0 < numResistance then
      local buffViewData = {}
      buffViewData.name = Localization:GetString("alliance_science_name011")
      buffViewData.icon = "Assets/Main/Sprites/UI/LWCommon/Sprite/zyf_saijikaifa_dangqiankangxing_icon.png"
      buffViewData.desc = Localization:GetString("season_trends_info002")
      table.insert(buffDatas, buffViewData)
    end
    if buff_content_item_max <= #buffDatas then
      return buffDatas
    end
    if theSeasonType == SeasonMapType.Mummy then
      local v94081 = LuaEntry.Effect:GetGameEffect(94081)
      if v94081 ~= 0 then
        local effectLine = LocalController:instance():getLine(TableName.LW_Effect_Number, 94081)
        if effectLine then
          local buffViewData = {}
          buffViewData.name = Localization:GetString(effectLine.name)
          buffViewData.icon = "Assets/Main/SeasonRes/Shared/Sprites/UIMummy/ljq_saijis3_huanxing_buff.png"
          buffViewData.desc = Localization:GetString(effectLine.desc)
          table.insert(buffDatas, buffViewData)
        end
      end
      if DataCenter.SandWormHuntDataManager:IsMyBaseWormWrap() then
        table.insert(buffDatas, {
          icon = "Assets/Main/SeasonRes/S3/Sprites/Sandworm/mjc_S3_sc_zhuye_icon.png"
        })
      end
    elseif theSeasonType == SeasonMapType.Darkness then
      local stateMeta = LocalController:instance():getLine(TableName.StatusTab, 704201)
      if stateMeta then
        local buffViewData = {}
        buffViewData.icon = stateMeta.icon
        buffViewData.name = Localization:GetString(stateMeta.name)
        buffViewData.desc = Localization:GetString(stateMeta.description)
        table.insert(buffDatas, buffViewData)
      end
    end
    if buff_content_item_max <= #buffDatas then
      return buffDatas
    end
    local effectList = DataCenter.SeasonFarmerManager:GetCityAttachmentEffectInfo()
    if effectList and effectList.effect then
      for effectId, effectValue in pairs(effectList.effect) do
        local effectValueExist = 0
        if effectValueExist == 0 then
          local builders_alliance_buff = GetTableData(TableName.LW_Effect_Number, effectId, "builders_alliance_buff")
          if builders_alliance_buff then
            local name, desc, iconPath = string.match(builders_alliance_buff, "([^;|]+)[;|]([^;|]+)[;|]([^;|]+)")
            if name and desc and iconPath then
              local buffViewData = {}
              buffViewData.icon = iconPath
              buffViewData.name = Localization:GetString(name)
              buffViewData.desc = Localization:GetString(desc)
              table.insert(buffDatas, buffViewData)
            end
          end
        end
      end
    end
    if buff_content_item_max <= #buffDatas then
      return buffDatas
    end
    local sort_buff = {}
    if effectList and effectList.state then
      for _, stateId in pairs(effectList.state) do
        local stateMeta = LocalController:instance():getLine(TableName.StatusTab, stateId)
        if stateMeta then
          local buffViewData = {}
          buffViewData.order = toInt(stateMeta.order) + 1
          buffViewData.icon = stateMeta.icon
          buffViewData.name = Localization:GetString(stateMeta.name)
          buffViewData.desc = Localization:GetString(stateMeta.description)
          table.insert(sort_buff, buffViewData)
        end
      end
      table.sort(sort_buff, function(a, b)
        return a.order > b.order
      end)
    end
    table.extendArray(buffDatas, sort_buff)
    if buff_content_item_max <= #buffDatas then
      return buffDatas
    end
    sort_buff = {}
    local GlobalState = DataCenter.SeasonDataManager:GetGlobalStatus()
    if GlobalState then
      for k, v in pairs(GlobalState) do
        if v and v.effects and v.reason and v.stateId then
          local stateMeta = LocalController:instance():getLine(TableName.StatusTab, v.stateId)
          if stateMeta then
            local buffViewData = {}
            buffViewData.order = toInt(stateMeta.order) + 1
            buffViewData.icon = stateMeta.icon
            buffViewData.name = Localization:GetString(stateMeta.name)
            buffViewData.desc = Localization:GetString(stateMeta.description)
            table.insert(sort_buff, buffViewData)
          end
        end
      end
      table.sort(sort_buff, function(a, b)
        return a.order > b.order
      end)
    end
    table.extendArray(buffDatas, sort_buff)
    if buff_content_item_max <= #buffDatas then
      return buffDatas
    end
    local sunrise = DataCenter.BloodyNightDataManager:IsSunrise()
    if not sunrise then
      sort_buff = {}
      local lightBuffDict = DataCenter.SeasonLightDataManager:GetAllLightBuff()
      if lightBuffDict then
        for stateId, lightStatus in pairs(lightBuffDict) do
          local stateMeta = LocalController:instance():getLine(TableName.StatusTab, stateId)
          if stateMeta and (0 < toInt(stateMeta.type3) or stateId == 704101) then
            local buffViewData = {}
            buffViewData.order = toInt(stateMeta.order) + 1
            buffViewData.icon = stateMeta.icon
            buffViewData.name = Localization:GetString(stateMeta.name)
            buffViewData.desc = Localization:GetString(stateMeta.description)
            if lightStatus and lightStatus.lightPlayer then
              buffViewData.playerData = lightStatus.lightPlayer
            end
            table.insert(sort_buff, buffViewData)
          end
        end
        table.sort(sort_buff, function(a, b)
          return a.order > b.order
        end)
      end
      table.extendArray(buffDatas, sort_buff)
      if buff_content_item_max <= #buffDatas then
        return buffDatas
      end
    end
  end
  local sort_buff = {}
  local GlobalState = DataCenter.ServerStatusManager:GetGlobalStatus()
  if GlobalState then
    for k, v in pairs(GlobalState) do
      if v and v.effects and v.reason and v.stateId then
        local stateMeta = LocalController:instance():getLine(TableName.StatusTab, v.stateId)
        if stateMeta then
          local buffViewData = {}
          buffViewData.order = toInt(stateMeta.order) + 1
          buffViewData.icon = stateMeta.icon
          buffViewData.name = Localization:GetString(stateMeta.name)
          buffViewData.desc = Localization:GetString(stateMeta.description)
          table.insert(sort_buff, buffViewData)
        end
      end
    end
    table.sort(sort_buff, function(a, b)
      return a.order > b.order
    end)
  end
  table.extendArray(buffDatas, sort_buff)
  if buff_content_item_max <= #buffDatas then
    return buffDatas
  end
  local collectLimitBuffData = DataCenter.CollectRewardDataManager:GetNowCollectLimitBuffData()
  if collectLimitBuffData ~= nil then
    table.insert(buffDatas, collectLimitBuffData)
  end
  local tradeBuff = DataCenter.SeasonTradeDataManager:GetShowBuffData()
  if tradeBuff ~= nil then
    table.insert(buffDatas, tradeBuff)
  end
  return buffDatas
end

function UIMainTop:RefreshBuff()
  if self.delayTimeRefreshBuff == nil then
    local pThis = self
    self.delayTimeRefreshBuff = TimerManager:GetInstance():DelayInvoke(function()
      pThis.delayTimeRefreshBuff = nil
      CommonUtil.ProtectCall(function()
        pThis:DelayRefreshBuff()
      end)
    end, 0.1)
  end
end

function UIMainTop:DelayRefreshBuff()
  local shows = self:PrepareBuffData()
  local lastBuffDataShown = self.lastBuffDataShown
  if lastBuffDataShown ~= nil and shows ~= nil and #lastBuffDataShown == #shows then
    local is_same = true
    for index, new_data in ipairs(shows) do
      local old = lastBuffDataShown[index]
      if old == nil or old.id ~= new_data.id or old.icon ~= new_data.icon or old.name ~= new_data.name or old.desc ~= new_data.desc or old.order ~= new_data.order or old.endTime ~= new_data.endTime or old.totalTime ~= new_data.totalTime or old.effectScale ~= new_data.effectScale or old.showEffectPath ~= new_data.showEffectPath then
        is_same = false
        break
      end
    end
    if is_same then
      self.buff_list_root:SetActive(0 < #lastBuffDataShown)
      self.buff_content:SetActive(0 < #lastBuffDataShown)
      return
    end
  end
  self:DestroyBuff()
  local buff_content_item_max = toInt(self.buff_content_item_max)
  local count = 0
  self.lastBuffDataShown = shows
  self.buffIcons = {}
  if shows ~= nil then
    if buff_content_item_max < 1 then
      buff_content_item_max = 8
    end
    count = #shows
    if buff_content_item_max < count then
      count = buff_content_item_max
    end
    for i = 1, count do
      local theIconPath
      local hideFrame = false
      local playerData
      if i >= buff_content_item_max then
        hideFrame = true
        theIconPath = "Assets/Main/Sprites/UI/LWCommon/Sprite/zyf_zhujiemian_buff_button.png"
      else
        hideFrame = false
        if shows[i].meta then
          theIconPath = shows[i].meta.icon
        elseif shows[i].icon then
          theIconPath = shows[i].icon
        end
      end
      if shows[i].playerData then
        playerData = shows[i].playerData
      end
      self.buffIcons[i] = self:GameObjectInstantiateAsync(UIAssets.BuffIcon, function(request)
        if request.isError then
          return
        end
        local go = request.gameObject
        go.gameObject:SetActive(true)
        go.transform:SetParent(self.buff_content.transform)
        go.transform:Set_localScale(ResetScale.x, ResetScale.y, ResetScale.z)
        go.name = "BuffIcon" .. i
        local cell = self.buff_content:AddComponent(BuffIcon, go.name)
        cell:SetIcon(theIconPath)
        cell:HideFrame(hideFrame)
        if not string.IsNullOrEmpty(shows[i].showEffectPath) then
          cell:ShowBuffEffectView(shows[i].showEffectPath, shows[i].effectScale)
        end
        if playerData then
          cell:SetPlayerData(playerData, 0.275)
        end
      end)
    end
  end
  local row = 0
  if count <= 0 then
    self.buff_list_root:SetActive(false)
    self.buff_content:SetActive(false)
  else
    row = 1
    self.buff_list_root:SetActive(true)
    self.buff_content:SetActive(true)
  end
  EventManager:GetInstance():Broadcast(EventId.MSG_ITME_STATUS_TIME_CHANGE)
end

function UIMainTop:DestroyBuff()
  self.lastBuffDataShown = nil
  self.buff_content:RemoveComponents(BuffIcon)
  if self.buffIcons ~= nil then
    for k, v in pairs(self.buffIcons) do
      if v ~= nil then
        self:GameObjectDestroy(v)
      end
    end
    self.buffIcons = {}
  end
end

function UIMainTop:DelayRefreshResource(time)
  self:AddDelayRefreshResourceTimer(time)
end

function UIMainTop:AddDelayRefreshResourceTimer(time)
  self:DeleteDelayRefreshResourceTimer()
  self.delayRefreshResourceTimer = TimerManager:GetInstance():GetTimer(time, self.delay_refresh_resource_timer_action, self, true, false, false)
  self.delayRefreshResourceTimer:Start()
end

function UIMainTop:RefreshResource()
  if self.isInPve == true then
    return
  end
  if self.delayRefreshResourceTimer == nil then
    self:RefreshCells()
    for k, v in pairs(self.resourceCells) do
      if v.model ~= nil then
        v.model:Refresh()
      end
    end
  end
end

function UIMainTop:RefreshCells()
  self.needWaitLoadCount = 0
  local count = table.count(self.showList)
  local param = self.showList[count]
  local have = {}
  local needRemove = {}
  local inSeason = false
  local seasonType = SeasonMapType.Nothing
  local info = DataCenter.SeasonDataManager:GetUserSeasonInfo()
  if info then
    inSeason = info:ServerInReady() and info:InNormalMode()
    if inSeason then
      seasonType = info:GetServerType(false)
    end
  end
  if param.list ~= nil then
    for k, v in ipairs(param.list) do
      local unlocked = true
      local funcUnlockID = ResourceType2FuncUnlockID[v]
      if funcUnlockID ~= nil then
        unlocked = DataCenter.LWFunctionUnlockManager:CheckCanShow(funcUnlockID)
      end
      if not inSeason and (ResourceType.OBSIDIAN == v or ResourceType.FLINT == v) then
        unlocked = false
      elseif seasonType ~= SeasonMapType.Nothing and CS.SDKManager.IS_UNITY_EDITOR() then
        unlocked = true
      elseif ResourceType.OBSIDIAN == v and LuaEntry.Resource:GetCntByResType(v) == 0 then
        unlocked = false
      elseif ResourceType.FLINT == v and LuaEntry.Resource:GetCntByResType(v) == 0 then
        unlocked = false
      end
      if unlocked then
        have[v] = true
        self:AddOneResourceCell(v, false)
      end
    end
  end
  for k, v in pairs(self.resourceCells) do
    if not have[v.param.resourceType] then
      table.insert(needRemove, k)
    end
  end
  for k, v in ipairs(needRemove) do
    self:RemoveOneResourceCell(v)
  end
  have = {}
  needRemove = {}
  if param.allianceList ~= nil then
    for k, v in ipairs(param.allianceList) do
      have[v] = true
      self:AddOneAllianceItemCell(v)
    end
  end
  for k, v in pairs(self.allianceItemCells) do
    if not have[v.param.aItemType] then
      table.insert(needRemove, k)
    end
  end
  for k, v in ipairs(needRemove) do
    self:RemoveOneAllianceItemCell(v)
  end
  self:CheckLoadCount()
end

function UIMainTop:AddOneResourceCell(resourceType, showExpandAnimation, showExpandParam)
  local param = {}
  param.resourceType = resourceType
  if resourceType ~= ResourceType.BatteryPower then
    param.iconName = self.view.ctrl:GetResourceIconName(resourceType)
  end
  param.showExpandAnimation = showExpandAnimation
  param.showExpandParam = showExpandParam
  param.parent = self
  if self.resourceCells[resourceType] == nil then
    self.resourceCells[resourceType] = {}
  end
  self.resourceCells[resourceType].param = param
  if self.resourceCells[resourceType].model ~= nil then
    self.resourceCells[resourceType].model:ChangeParam(param)
  elseif self.resourceCells[resourceType].inst == nil then
    self.needWaitLoadCount = self.needWaitLoadCount + 1
    self.resourceCells[resourceType].inst = self:GameObjectInstantiateAsync(UIAssets.UIMainTopResourceCell, function(request)
      self.needWaitLoadCount = self.needWaitLoadCount - 1
      if request.isError then
        self.resourceCells[resourceType] = nil
        return
      end
      local go = request.gameObject
      go.transform:SetParent(self.resourceCells_bar.transform)
      go.transform:Set_localScale(ResetScale.x, ResetScale.y, ResetScale.z)
      go.transform:Set_sizeDelta(166, 52)
      local nameStr = tostring(resourceType)
      go.name = nameStr
      local model = self.resourceCells_bar:AddComponent(UIMainResourceProgress, nameStr)
      self.resourceCells[resourceType].model = model
      model:ReInit(self.resourceCells[resourceType].param)
      go.transform:SetSiblingIndex(ResourceCellIndexStart)
      self:CheckLoadCount()
    end)
  else
    self.needWaitLoadCount = self.needWaitLoadCount + 1
  end
end

function UIMainTop:RemoveOneResourceCell(id)
  if self.resourceCells[id] ~= nil then
    if self.resourceCells[id].model ~= nil then
      self.resourceCells_bar:RemoveComponent(tostring(id), UIMainResourceProgress)
      self.resourceCells[id].model:OnDestroy()
    end
    if self.resourceCells[id].inst ~= nil then
      self:GameObjectDestroy(self.resourceCells[id].inst)
    end
    self.resourceCells[id] = nil
  end
end

function UIMainTop:SetOneResourceCellActive(resourceType, active)
  if self.resourceCells[resourceType] ~= nil and self.resourceCells[resourceType].model ~= nil then
    self.resourceCells[resourceType].model:SetActive(active)
  end
end

function UIMainTop:AddOneAllianceItemCell(aItemType)
  local param = {}
  param.aItemType = aItemType
  if self.allianceItemCells[aItemType] == nil then
    self.allianceItemCells[aItemType] = {}
  end
  self.allianceItemCells[aItemType].param = param
  if self.allianceItemCells[aItemType].model ~= nil then
    self.allianceItemCells[aItemType].model:ChangeParam(param)
  elseif self.allianceItemCells[aItemType].inst == nil then
    self.needWaitLoadCount = self.needWaitLoadCount + 1
    self.allianceItemCells[aItemType].inst = self:GameObjectInstantiateAsync(UIAssets.UIMainTopResourceCell, function(request)
      self.needWaitLoadCount = self.needWaitLoadCount - 1
      if request.isError then
        self.allianceItemCells[aItemType] = nil
        return
      end
      local go = request.gameObject
      go.transform:SetParent(self.resourceCells_bar.transform)
      go.transform:Set_localScale(ResetScale.x, ResetScale.y, ResetScale.z)
      local nameStr = tostring(aItemType)
      go.name = nameStr
      local model = self.resourceCells_bar:AddComponent(UIMainItemProgress, nameStr)
      self.allianceItemCells[aItemType].model = model
      model:ReInit(self.allianceItemCells[aItemType].param)
      go.transform:SetSiblingIndex(AllianceCellIndexStart)
      self:CheckLoadCount()
    end)
  else
    self.needWaitLoadCount = self.needWaitLoadCount + 1
  end
end

function UIMainTop:RemoveOneAllianceItemCell(id)
  if self.allianceItemCells[id] ~= nil then
    if self.allianceItemCells[id].model ~= nil then
      self.resourceCells_bar:RemoveComponent(tostring(id), UIMainItemProgress)
      self.allianceItemCells[id].model:OnDestroy()
    end
    if self.allianceItemCells[id].inst ~= nil then
      self:GameObjectDestroy(self.allianceItemCells[id].inst)
    end
    self.allianceItemCells[id] = nil
  end
end

function UIMainTop:CheckLoadCount()
  local count = table.count(self.showList)
  if 0 < count then
    local param = self.showList[count]
    for k, v in ipairs(param.list) do
      if self.resourceCells[v] ~= nil and self.resourceCells[v].model ~= nil then
        self.resourceCells[v].model.transform:SetSiblingIndex(ResourceCellIndexStart)
      end
    end
    if param.allianceList ~= nil then
      for k, v in ipairs(param.allianceList) do
        if self.allianceItemCells[v] ~= nil and self.allianceItemCells[v].model ~= nil then
          self.allianceItemCells[v].model.transform:SetSiblingIndex(AllianceCellIndexStart)
        end
      end
    end
  end
end

function UIMainTop:DelayRefreshTimerBallBack()
  self:DeleteDelayRefreshTimer()
  self.goldStoreGoldCountN:SetText(string.GetFormattedGoldNum(self._resNumShow))
end

function UIMainTop:DeleteDelayRefreshTimer()
  if self.delayTimer ~= nil then
    self.delayTimer:Stop()
    self.delayTimer = nil
  end
end

function UIMainTop:DelayRefreshResourceTimerBallBack()
  self:DeleteDelayRefreshResourceTimer()
  self:RefreshCells()
end

function UIMainTop:DeleteDelayRefreshResourceTimer()
  if self.delayRefreshResourceTimer ~= nil then
    self.delayRefreshResourceTimer:Stop()
    self.delayRefreshResourceTimer = nil
  end
end

function UIMainTop:RefreshGoldNum()
  if self.isInPve == true then
    return
  end
  self._resNumTarget = self.view.ctrl:GetGoldNum()
  if self._resNumShow ~= self._resNumTarget then
    self._resNumDelta = (self._resNumTarget - self._resNumShow) / CountNumJumpTimes
    if math.modf(self._resNumDelta) == 0 then
      self._resNumDelta = self._resNumDelta > 0 and 1 or -1
    else
      self._resNumDelta = math.modf(self._resNumDelta)
    end
    self._lastSetTime = UITimeManager:GetInstance():GetServerTime()
  else
    self.goldStoreGoldCountN:SetText(string.GetFormattedGoldNum(self._resNumShow))
  end
end

function UIMainTop:Update1000MS()
  if SceneUtils.GetIsInWorld() then
    local theSeasonType = SeasonUtil.GetSeasonType()
    if theSeasonType == SeasonMapType.CityStronghold or theSeasonType == SeasonMapType.Snow or theSeasonType == SeasonMapType.Darkness then
      local x, y = self.resourceCells_bar.rectTransform:Get_sizeDelta()
      if self.resourceCells_bar_height ~= y then
        self.resourceCells_bar_height = y
        EventManager:GetInstance():Broadcast(EventId.PostLayoutSizeChanged, {
          t = LayoutSizeChangeType.MainUIResourceBar,
          w = x,
          h = y
        })
      end
    end
  end
  if self.actRedDirtyFlag then
    self.actRedDirtyFlag = false
    self:RefreshUIMainActivityGroupContent()
  end
  if self.txt_time:GetActive() then
    local cdTime = CrossServerUtil.GetCrossMoveCD()
    local canShowCd = 0 < cdTime
    self.txt_time:SetActive(canShowCd)
    if canShowCd then
      self.txt_time:SetText(UITimeManager:GetInstance():GetFormattedTime(cdTime / 1000))
    end
  end
end

function UIMainTop:Update()
  if self._resNumShow ~= self._resNumTarget then
    local tempT = UITimeManager:GetInstance():GetServerTime()
    if tempT - self._lastSetTime >= ChangePerTime then
      self._lastSetTime = tempT
      self._resNumShow = self._resNumShow + self._resNumDelta
      if self._resNumDelta > 0 and self._resNumShow > self._resNumTarget then
        self._resNumShow = self._resNumTarget
      elseif self._resNumDelta < 0 and self._resNumShow < self._resNumTarget then
        self._resNumShow = self._resNumTarget
      end
      self.goldStoreGoldCountN:SetText(string.GetFormattedGoldNum(self._resNumShow))
      if self._resNumShow == self._resNumTarget then
        self:AddDelayRefreshTimer()
      end
    end
  end
  if self.themeActivityBtnEndTime and 0 < self.themeActivityBtnEndTime then
    local curTime = UITimeManager:GetInstance():GetServerTime()
    local timeLeft = self.themeActivityBtnEndTime - curTime
    if 0 < timeLeft then
      local timeStr = UITimeManager:GetInstance():MilliSecondToFmtString(timeLeft)
      self:SetThemeActivityBtnText(timeStr)
    else
      self:SetThemeActivityBtnText("")
    end
  else
    self:SetThemeActivityBtnText("")
  end
  if self.img_progress:GetActive() then
    local cdTime, cd = CrossServerUtil.GetCrossMoveCD()
    self.img_progress:SetFillAmount(0 < cdTime and 1 - cdTime / cd or 1)
  end
end

function UIMainTop:SetThemeActivityBtnText(str)
  if self.themeActivityBtnTextStr ~= str then
    self.themeActivityBtnTextStr = str
    self.themeActivityBtnText:SetText(str)
  end
end

function UIMainTop:AddDelayRefreshTimer()
  self:DeleteDelayRefreshTimer()
  self.delayTimer = TimerManager:GetInstance():GetTimer(DelayTime, self.delay_timer_action, self, true, false, false)
  self.delayTimer:Start()
end

function UIMainTop:GetResourcePos(resourceType)
  CS.UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self.resourceCells_bar.rectTransform)
  if self.resourceCells[resourceType] ~= nil and self.resourceCells[resourceType].model ~= nil then
    return self.resourceCells[resourceType].model:GetResourcePos()
  end
  if self.itemCells[resourceType] ~= nil and self.itemCells[resourceType].model ~= nil then
    return self.itemCells[resourceType].model:GetResourcePos()
  end
  return self.resourceCells_bar.transform.position
end

function UIMainTop:GetAllianceItemPos(aItemType)
  CS.UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self.resourceCells_bar.rectTransform)
  if self.allianceItemCells[aItemType] ~= nil and self.allianceItemCells[aItemType].model ~= nil then
    return self.allianceItemCells[aItemType].model:GetResourcePos()
  end
  local alBtnPos = UIUtil.GetUIMainSavePos(UIMainSavePosType.AllianceBtn)
  if alBtnPos ~= nil then
    return alBtnPos
  end
  return self.resourceCells_bar.transform.position
end

function UIMainTop:GetGoodsPos()
  return self.goldStoreN.transform.position
end

function UIMainTop:GetGoldBtnPos()
  return self.goldStoreN.transform.position
end

function UIMainTop:OnQueryLayoutSize(data)
  if data ~= nil and data.t == LayoutSizeChangeType.MainUIResourceBar and type(data.f) == "function" then
    local x, y = self.resourceCells_bar.rectTransform:Get_sizeDelta()
    pcall(data.f, x, y)
  end
end

function UIMainTop:OnAddListener()
  base.OnAddListener(self)
  self:AddUIListener(EventId.QueryLayoutSize, self.OnQueryLayoutSize)
  self:AddUIListener(EventId.OnPackageInfoUpdated, RefreshPackInfo)
  self:AddUIListener(EventId.RefreshWelfareRedDot, RefreshChargeBtnRedPoint)
  self:AddUIListener(EventId.MainLvUp, self.OnMainLevelUp)
  self:AddUIListener(EventId.MainTaskSuccess, RefreshAllActivityBtn)
  self:AddUIListener(EventId.MainTaskUpdate, RefreshAllActivityBtn)
  self:AddUIListener(EventId.RefreshActivityRedDot, RefreshAllActivityBtn)
  self:AddUIListener(EventId.BuildLevelUp, RefreshAllActivityBtn)
  self:AddUIListener(EventId.UpdateFirstPayState, RefreshFristPayBtn)
  self:AddUIListener(EventId.RefreshActivityDetailData, RefreshAllActivityBtn)
  self:AddUIListener(EventId.DragonInfoRefresh, RefreshAllActivityBtn)
  self:AddUIListener(EventId.OnAllyDrillStageChange, RefreshAllActivityBtn)
  self:AddUIListener(EventId.CrossKingScheduleRefresh, RefreshAllActivityBtn)
  self:AddUIListener(EventId.ActGiftBoxOpen, RefreshAllActivityBtn)
  self:AddUIListener(EventId.ActGiftBoxDel, RefreshAllActivityBtn)
  self:AddUIListener(EventId.OnRecvNewActivityInfo, RefreshAllActivityBtn)
  self:AddUIListener(EventId.OnFunctionOnAnimFinsh, RefreshActivityBtn)
  self:AddUIListener(EventId.OnEnterWorld, self.OnEnterWorld)
  self:AddUIListener(EventId.OnEnterCity, self.OnEnterCity)
  self:AddUIListener(EventId.UpdateMainAllianceRedCount, self.OnUpdateMainAllianceRedCount)
  self:AddUIListener(EventId.EnterDiamondStore, self.HideStoreNewTag)
  self:AddUIListener(EventId.OnPassDay, self.OnPassDay)
  self:AddUIListener(EventId.GoldBrickUpdate, self.OnGoldBrickUpdate)
  self:AddUIListener(EventId.ShowCrossServerTip, self.RefreshCrossServerTip)
  self:AddUIListener(EventId.LuaEntryEffectRefreshStatus, self.RefreshBuff)
  self:AddUIListener(EventId.SetMainWorldPointId, self.RefreshBuff)
  self:AddUIListener(EventId.WarFlagAdd, self.RefreshBuff)
  self:AddUIListener(EventId.MyBaseTemperatureConfigChange, self.RefreshBuff)
  self:AddUIListener(EventId.MyBasePhaseChange, self.RefreshBuff)
  self:AddUIListener(EventId.PlayerPowerInfoUpdated, self.RefreshPower)
  self:AddUIListener(EventId.ShowCrossServerBubbleTips, self.OnShowCrossServerBubbleTips)
  self:AddUIListener(EventId.DevelopRecommendEntranceRedUpdate, self.OnDevelopRecommendEntranceRedUpdate)
  self:AddUIListener(EventId.AccountBindTipChanged, self.OnAccountBindTipChanged)
  self:AddUIListener(EventId.SelfOfficialPositionChange, self.RefreshBuff)
  self:AddUIListener(EventId.SelfCollectLimitLevelChange, self.RefreshBuff)
  self:AddUIListener(EventId.GetActivityAlarmClockData, self.RefreshShowActivityAlarmClockView)
  self:AddUIListener(EventId.UpdateActivityAlarmClockData, self.RefreshShowActivityAlarmClockView)
  self:AddUIListener(EventId.CityFightAlarm, self.RefreshShowCityFightAlarmView)
  self:AddUIListener(EventId.SandWormWrapRefresh, self.RefreshBuff)
  self:AddUIListener(EventId.BloodyNightActivityRefresh, self.RefreshBuff)
  self:AddUIListener(EventId.LWUnpackResourceRewardUpdate, self.RefresSeasonResourceDownloadBtn)
  self:AddUIListener(EventId.GetZoneMobilizationInfoData, self.RefreshZoneMobilizationAct)
  self:AddUIListener(EventId.ReceivePushRequestZoneMobilizationData, self.OnReceivePushMsgRequestZoneMobilizationData)
  self:AddUIListener(EventId.LWSeasonResourceDownloadStart, self.RefresSeasonResourceDownloadBtn)
  self:AddUIListener(EventId.ActMigrationInfoUpdate, self.RefreshAlCompeteBtn)
  self:AddUIListener(EventId.MeteoriteBattleNotice, self.RefreshMeteoriteNotice)
  self:AddUIListener(EventId.UseItemSuccess, self.DelayRefreshActivityBtn)
  self:AddUIListener(EventId.DominatorCommonGuideProgressChanged, self.RefreshDominatorEntrance)
  self:AddUIListener(EventId.BattlefieldActStateChanged, self.OnBattlefieldActStateChanged)
  self:AddUIListener(EventId.UIPrivacy_Confirm, self.RefreshCoppaAppealBtn)
end

function UIMainTop:OnRemoveListener()
  base.OnRemoveListener(self)
  self:RemoveUIListener(EventId.QueryLayoutSize, self.OnQueryLayoutSize)
  self:RemoveUIListener(EventId.OnPackageInfoUpdated, RefreshPackInfo)
  self:RemoveUIListener(EventId.RefreshWelfareRedDot, RefreshChargeBtnRedPoint)
  self:RemoveUIListener(EventId.MainLvUp, self.OnMainLevelUp)
  self:RemoveUIListener(EventId.MainTaskSuccess, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.MainTaskUpdate, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.RefreshActivityRedDot, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.BuildLevelUp, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.UpdateFirstPayState, RefreshFristPayBtn)
  self:RemoveUIListener(EventId.RefreshActivityDetailData, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.DragonInfoRefresh, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.OnAllyDrillStageChange, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.CrossKingScheduleRefresh, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.ActGiftBoxOpen, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.ActGiftBoxDel, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.OnRecvNewActivityInfo, RefreshAllActivityBtn)
  self:RemoveUIListener(EventId.OnFunctionOnAnimFinsh, RefreshActivityBtn)
  self:RemoveUIListener(EventId.OnEnterWorld, self.OnEnterWorld)
  self:RemoveUIListener(EventId.OnEnterCity, self.OnEnterCity)
  self:RemoveUIListener(EventId.UpdateMainAllianceRedCount, self.OnUpdateMainAllianceRedCount)
  self:RemoveUIListener(EventId.EnterDiamondStore, self.HideStoreNewTag)
  self:RemoveUIListener(EventId.OnPassDay, self.OnPassDay)
  self:RemoveUIListener(EventId.GoldBrickUpdate, self.OnGoldBrickUpdate)
  self:RemoveUIListener(EventId.ShowCrossServerTip, self.RefreshCrossServerTip)
  self:RemoveUIListener(EventId.LuaEntryEffectRefreshStatus, self.RefreshBuff)
  self:RemoveUIListener(EventId.SetMainWorldPointId, self.RefreshBuff)
  self:RemoveUIListener(EventId.WarFlagAdd, self.RefreshBuff)
  self:RemoveUIListener(EventId.MyBaseTemperatureConfigChange, self.RefreshBuff)
  self:RemoveUIListener(EventId.MyBasePhaseChange, self.RefreshBuff)
  self:RemoveUIListener(EventId.PlayerPowerInfoUpdated, self.RefreshPower)
  self:RemoveUIListener(EventId.ShowCrossServerBubbleTips, self.OnShowCrossServerBubbleTips)
  self:RemoveUIListener(EventId.DevelopRecommendEntranceRedUpdate, self.OnDevelopRecommendEntranceRedUpdate)
  self:RemoveUIListener(EventId.AccountBindTipChanged, self.OnAccountBindTipChanged)
  self:RemoveUIListener(EventId.SelfOfficialPositionChange, self.RefreshBuff)
  self:RemoveUIListener(EventId.SelfCollectLimitLevelChange, self.RefreshBuff)
  self:RemoveUIListener(EventId.GetActivityAlarmClockData, self.RefreshShowActivityAlarmClockView)
  self:RemoveUIListener(EventId.UpdateActivityAlarmClockData, self.RefreshShowActivityAlarmClockView)
  self:RemoveUIListener(EventId.CityFightAlarm, self.RefreshShowCityFightAlarmView)
  self:RemoveUIListener(EventId.SandWormWrapRefresh, self.RefreshBuff)
  self:RemoveUIListener(EventId.BloodyNightActivityRefresh, self.RefreshBuff)
  self:RemoveUIListener(EventId.LWUnpackResourceRewardUpdate, self.RefresSeasonResourceDownloadBtn)
  self:RemoveUIListener(EventId.GetZoneMobilizationInfoData, self.RefreshZoneMobilizationAct)
  self:RemoveUIListener(EventId.ReceivePushRequestZoneMobilizationData, self.OnReceivePushMsgRequestZoneMobilizationData)
  self:RemoveUIListener(EventId.LWSeasonResourceDownloadStart, self.RefresSeasonResourceDownloadBtn)
  self:RemoveUIListener(EventId.ActMigrationInfoUpdate, self.RefreshAlCompeteBtn)
  self:RemoveUIListener(EventId.MeteoriteBattleNotice, self.RefreshMeteoriteNotice)
  self:RemoveUIListener(EventId.UseItemSuccess, self.DelayRefreshActivityBtn)
  self:RemoveUIListener(EventId.DominatorCommonGuideProgressChanged, self.RefreshDominatorEntrance)
  self:RemoveUIListener(EventId.BattlefieldActStateChanged, self.OnBattlefieldActStateChanged)
  self:RemoveUIListener(EventId.UIPrivacy_Confirm, self.RefreshCoppaAppealBtn)
end

function UIMainTop:OnUpdateMainAllianceRedCount()
  if not LuaEntry.Player:IsInAlliance() then
    if self.enter_dragon_battle then
      self.enter_dragon_battle:SetActive(false)
    end
    if self.enter_epidemic_battle then
      self.enter_epidemic_battle:SetActive(false)
    end
  end
end

function UIMainTop:RefreshSeasonBtnShow()
  local flag = false
  if self.SeasonBtn ~= nil then
    flag = self.SeasonBtn:RefreshShowState()
  end
  if self.OffSeasonBtn ~= nil then
    self.OffSeasonBtn:RefreshShowState(flag)
  end
  if self.farmerBtn ~= nil then
    self.farmerBtn:RefreshShowState()
  end
end

function UIMainTop:OnEnterWorld()
  self:CheckDragonEnter()
  self:CheckWinterStormEnter()
  self:CheckEpidemicEnter()
  self:CheckDsbDuelEnter()
  if self.governmentBtn ~= nil then
    self.governmentBtn:RefreshShowState()
  end
  if self.kingBtn ~= nil then
    self.kingBtn:RefreshShowState()
  end
  self:RefreshSeasonBtnShow()
end

function UIMainTop:OnEnterCity()
  self:CheckDragonEnter()
  self:CheckWinterStormEnter()
  self:CheckEpidemicEnter()
  self:CheckDsbDuelEnter()
  self:RefreshCoppaAppealBtn()
end

function UIMainTop:UpdateWhenAnim(animName)
  local stackCount = UIManager:GetInstance():GetStackWindowCount()
  if 1 < stackCount and animName ~= UIMainAnimType.AllShow or animName == UIMainAnimType.AllHide then
    if self.enter_dragon_battle then
      self.enter_dragon_battle:SetActive(false)
    end
    if self.enter_dsb_duel_battle then
      self.enter_dsb_duel_battle:SetActive(false)
    end
    if self.enter_winter_storm then
      self.enter_winter_storm:SetActive(false)
    end
    if self.enter_epidemic_battle then
      self.enter_epidemic_battle:SetActive(false)
    end
  else
    self:CheckDragonEnter()
    self:CheckWinterStormEnter()
    self:CheckEpidemicEnter()
    self:CheckDsbDuelEnter()
  end
  if animName == UIMainAnimType.LeftRightBottomHide then
    self.buff_content:SetActive(false)
    self.buff_list_root:SetActive(false)
    self.power_root:SetActive(false)
    self.cross_server_root:SetActive(false)
    self.crossServerTip:SetActive(false)
  elseif animName and animName ~= UIMainAnimType.AllHide then
    self.power_root:SetActive(DataCenter.LWFunctionUnlockManager:CheckCanShow(LWFunctionUnlockType.MainUI_PowerBar))
    self:RefreshCrossServerTip()
  end
  if animName == UIMainAnimType.AllHide or animName == UIMainAnimType.LeftRightBottomHide then
    self.activityTips:InterruptTips()
  end
end

function UIMainTop:RefreshPopupPackageEntrances()
  local showRecharegs = WelfareController.GetPopupPackages()
  self.popupRecharges = showRecharegs
  if table.IsNullOrEmpty(showRecharegs) then
    if self.popupPackageBtn ~= nil then
      self.popupPackageBtn:SetActive(false)
    end
    return
  end
  if self.popupPackageBtn ~= nil then
    self.popupPackageBtn:SetActive(true)
    self.popupPackageBtn:SetEntrance(self.popupRecharges)
  end
end

function UIMainTop:RefreshAllianceItemSignal()
  for k, v in pairs(self.allianceItemCells) do
    if v.model ~= nil then
      v.model:Refresh()
    end
  end
end

function UIMainTop:ShowExtraResource(data)
  self:RemoveListParamByUIName(data.uiName)
  local hasAdd = {}
  local param = {}
  param.list = {}
  param.uiName = data.uiName
  param.itemList = data.itemList
  param.resourceItemList = data.resourceItemList
  param.allianceList = data.allianceList
  param.noUseResetResource = data.noUseResetResource
  param.hideBtnList = data.hideBtnList
  param.hideResList = data.hideResList
  if param.hideBtnList ~= nil then
    for k, v in ipairs(param.hideBtnList) do
      self:SetBtnVisible(v, false)
    end
  end
  if param.hideResList ~= nil then
    for k, v in ipairs(param.hideResList) do
      self:SetOneResourceCellActive(v, false)
    end
  end
  if not param.noUseResetResource then
    for k, v in ipairs(ResetResourceType) do
      if hasAdd[v] == nil then
        hasAdd[v] = true
        table.insert(param.list, v)
      end
    end
  end
  if data.list ~= nil then
    for k, v in ipairs(data.list) do
      if hasAdd[v] == nil then
        hasAdd[v] = true
        table.insert(param.list, v)
      end
    end
  end
  table.sort(param.list, function(a, b)
    if UIMainResourceSort[a] == nil then
      return false
    end
    if UIMainResourceSort[b] == nil then
      return true
    end
    return UIMainResourceSort[a] > UIMainResourceSort[b]
  end)
  table.insert(self.showList, param)
  self.buff_list_root:SetActive(false)
  self.cross_server_root:SetActive(false)
  self:RefreshCells()
end

function UIMainTop:HideExtraResource(uiName)
  self:RemoveListParamByUIName(uiName)
  if uiName == UIWindowNames.UIFarm or uiName == UIWindowNames.UIFarmGather or uiName == "BuildTimeTip" then
    self:DelayRefreshResource(HideExtraResourceDelayTime)
  else
    self:RefreshCells()
    self:RefreshCrossServerTip()
    self:RefreshBuff()
  end
end

function UIMainTop:RemoveListParamByUIName(uiName)
  local removeIndex, param
  for k, v in ipairs(self.showList) do
    if v.uiName == uiName then
      param = v
      removeIndex = k
      break
    end
  end
  if removeIndex ~= nil then
    table.remove(self.showList, removeIndex)
  end
  if param ~= nil then
    if param.hideBtnList ~= nil then
      for k, v in ipairs(param.hideBtnList) do
        self:SetBtnVisible(v, true)
      end
    end
    if param.hideResList ~= nil then
      for k, v in ipairs(param.hideResList) do
        self:SetOneResourceCellActive(v, true)
      end
    end
  end
end

function UIMainTop:SetBtnVisible(btnType, visible)
  if self:CanControlVisibleByBtnType(btnType) then
    local btn = self:GetBtnByBtnType(btnType)
    if btn ~= nil then
      btn:SetActive(visible)
    end
  end
end

function UIMainTop:CanControlVisibleByBtnType(btnType)
  if btnType == UIMainTopBtnType.Stamina then
    return true
  elseif btnType == UIMainTopBtnType.Goods then
    return self.view.ctrl:IsShowUIMainMiddleLevel()
  elseif btnType == UIMainTopBtnType.Gold then
    return DataCenter.UnlockBtnManager:IsShowBtn(UnlockBtnType.Resource)
  end
  return true
end

function UIMainTop:GetBtnByBtnType(btnType)
  if btnType == UIMainTopBtnType.Stamina then
    return nil
  elseif btnType == UIMainTopBtnType.Goods then
    return nil
  elseif btnType == UIMainTopBtnType.Gold then
    return nil
  end
end

function UIMainTop:RefreshAlCompeteBtn()
  self.allyDuelBtn:RefreshAlCompeteBtn()
  self.actMeteoriteBtn:RefreshAlCompeteBtn()
  self.actMigrationBtn:RefreshAlCompeteBtn()
end

local RefreshMeteoriteNoticeComp = function(comp)
  if not comp then
    return
  end
  local currenrNotice = DataCenter.ActMeteoriteBattleManager:GetCurrentNotice()
  if not currenrNotice then
    comp:Close()
    return
  end
  if comp then
    comp:Refresh(currenrNotice)
  end
end

function UIMainTop:RefreshMeteoriteNotice()
  if IsNull(self.meteoriteNoticeRoot) then
    return
  end
  local battleInfo = DataCenter.ActMeteoriteBattleManager:GetBattleWorldInfo()
  if not battleInfo then
    if self.meteoriteNotice then
      self.meteoriteNotice:Close()
    else
      self.meteoriteNoticeRoot.gameObject:SetActive(false)
    end
  elseif not self.meteoriteNotice then
    self.meteoriteNotice = self:LoadComponentAsync(MeteoriteBattleUtils.NoticeItemRenderLuaPath, UIAssets.UIMeteoriteNoticeItemRenderer, self.meteoriteNoticeRoot, function()
      RefreshMeteoriteNoticeComp(self.meteoriteNotice)
    end, nil, self.meteoriteNoticeRoot.gameObject)
  else
    RefreshMeteoriteNoticeComp(self.meteoriteNotice)
  end
end

function UIMainTop:RefreshGiftBoxBtn()
  self.gift_box_activity_btn:Refresh()
end

function UIMainTop:RefreshThanksGivingBtn()
  self.thanks_giving_activity_btn:Refresh()
end

function UIMainTop:RefreshUIMainActivityGroupContent(IsPassDayRefresh)
  if not self.ui_main_activity_group_content then
    return
  end
  local prevActive = self.ui_main_activity_group_content:GetActive()
  local curActive = self.ui_main_activity_group_content:Refresh()
  if IsPassDayRefresh == true then
    self.ui_main_activity_group_content:OnPassDayRefresh()
  end
  if (prevActive ~= curActive or curActive) and self.topBtns then
    CS.UnityEngine.UI.LayoutRebuilder.ForceRebuildLayoutImmediate(self.topBtns.transform)
  end
end

function UIMainTop:RefreshScratchBtn()
  self.scratch_activity_btn:Refresh()
end

function UIMainTop:RefreshPiggyBankBtn()
  self.piggy_bank_btn:Refresh()
end

function UIMainTop:RefreshInfiniteGiftBtn()
  self.infiniteGiftBtn:Refresh()
end

function UIMainTop:OnLeagueMatchStageChangeSignal()
  self:RefreshAlCompeteBtn()
end

function UIMainTop:HideStoreNewTag()
  if self.goldStoreNewFlagN then
    self.goldStoreNewFlagN:SetActive(false)
    WelfareController.SetShowNewTagRecord(RechargeEntryType.Store)
  end
  self:RefreshStoreRedPoint()
end

function UIMainTop:OnPassDay()
  self:RefreshStoreRedPoint()
  if self.dailyPackBtn ~= nil then
    self.dailyPackBtn:RefreshNewTag()
  end
  RefreshAllActivityBtn(self)
  self:RefreshUIMainActivityGroupContent(true)
end

function UIMainTop:RefreshActivityTips()
  self.activityTips:Refresh()
end

function UIMainTop:GetBtnPosByType(mainUITipType)
  if mainUITipType == MainUITipType.Activity then
    if self.activityCenterBtn:GetActive() then
      return self.activityCenterBtn.transform.position
    end
  elseif mainUITipType == MainUITipType.Gift then
    if self.dailyPackBtn:GetActive() then
      return self.dailyPackBtn.transform.position
    end
  elseif mainUITipType == MainUITipType.AllyCity then
    if self.governmentBtn:GetActive() then
      return self.governmentBtn.transform.position
    elseif self.attackCityBtn:GetActive() then
      return self.attackCityBtn.transform.position
    end
  elseif mainUITipType == MainUITipType.WarZone then
    if self.kingBtn:GetActive() then
      return self.kingBtn.transform.position
    end
  elseif mainUITipType == MainUITipType.AllyDuel then
    if self.allyDuelBtn:GetActive() then
      return self.allyDuelBtn.transform.position
    end
  elseif mainUITipType == MainUITipType.Season then
  elseif mainUITipType == MainUITipType.AccountBind then
    if self.accountBindTipBtn:GetActive() then
      return self.accountBindTipBtn.transform.position
    end
  elseif mainUITipType == MainUITipType.MeteoriteBattle then
    if self.actMeteoriteBtn:GetActive() then
      return self.actMeteoriteBtn.transform.position
    end
  elseif mainUITipType == MainUITipType.AttackCityS0 then
    if self.attackCityS0Btn:GetActive() then
      return self.attackCityS0Btn.transform.position
    end
  else
    local position
    if self.ui_main_activity_group_content and self.ui_main_activity_group_content:GetBtnByGroupId(mainUITipType) then
      local targetBtn = self.ui_main_activity_group_content:GetBtnByGroupId(mainUITipType)
      position = targetBtn.transform.position
    end
    return position
  end
  return nil
end

function UIMainTop:OnShowCrossServerBubbleTips(languageId)
  if self.move_city_root:GetActive() then
    if UIManager:GetInstance():GetWindow(UIWindowNames.LWUIMoveCityTip) ~= nil then
      UIManager:GetInstance():DestroyWindow(UIWindowNames.LWUIMoveCityTip)
    end
    self.new_bubble_root:ShowBubbleTips(languageId)
  elseif self.crossServerBubbleRoot then
    self.crossServerBubbleRoot:ShowBubbleTips(languageId)
  end
end

function UIMainTop:OnDevelopRecommendEntranceRedUpdate()
  self:RefreshPowerRed()
end

function UIMainTop:OnAccountBindTipChanged()
  self:RefreshAccountBindTipBtn()
end

function UIMainTop:OnMainLevelUp()
  RefreshAllActivityBtn(self)
  self:RefreshPowerRed()
end

function UIMainTop:GetBuffIconPosByIndex(index)
  local pos = self.buff_content.transform.position
  return pos
end

function UIMainTop:RefreshAccountBindTipBtn()
  self.accountBindTipBtn:Refresh()
  self:RefreshActivityTips()
end

function UIMainTop:RefreshCoppaAppealBtn()
  if not self.coppaAppealBtn then
    return
  end
  local canShow = CoppaUtil.IsShowCoppaBtnInMainUI()
  if not canShow then
    if self.coppaAppealBtn:GetActive() then
      self.coppaAppealBtn:SetActive(false)
    end
    return
  end
  self.coppaAppealBtn:SetActive(true)
  self.coppaAppealBtn:Refresh()
end

function UIMainTop:CheckWinterStormEnter()
  if self.enter_winter_storm then
    self.enter_winter_storm:Refresh()
    return
  end
  if self.winterReq ~= nil then
    return
  end
  local remainTime = DataCenter.ActWinterStormManager:GetInBattleWorldLeftTime()
  if remainTime <= 0 then
    return
  end
  local request = Resource:InstantiateAsync("Assets/Main/Prefabs/UI/ActivityCenter/WinterStorm/LWWinterStormBack.prefab")
  self.winterReq = request
  request:completed("+", function(req)
    local _go = req.gameObject
    if IsNull(_go) then
      if self.winterReq ~= nil then
        self.winterReq:Destroy()
        self.winterReq = nil
      end
      return
    end
    _go.name = enter_winter_storm_path
    local pTF = _go.transform
    local pName = "EnterBattleField"
    local node = self.transform:Find(pName)
    pTF:SetParent(node)
    pTF:Set_localPosition(0, -100, 0)
    pTF:Set_localScale(1, 1, 1)
    self.enter_winter_storm = self:AddComponent(UIMainWinterStormBack, pName .. "/" .. enter_winter_storm_path)
    self.enter_winter_storm:Refresh()
  end)
end

function UIMainTop:CheckDragonEnter()
  local canShow = DataCenter.ActDragonManager:CanShowEnter()
  if self.enter_dragon_battle then
    self.enter_dragon_battle:SetActive(canShow)
    if canShow then
      self.enter_dragon_battle:Refresh()
    end
    return
  end
  if not canShow or self.dragonReq ~= nil then
    return
  end
  local request = Resource:InstantiateAsync("Assets/Main/Prefabs/UI/LWMainUI/EnterDragonBattle.prefab")
  self.dragonReq = request
  request:completed("+", function(req)
    local _go = req.gameObject
    if IsNull(_go) then
      if self.dragonReq ~= nil then
        self.dragonReq:Destroy()
        self.dragonReq = nil
      end
      return
    end
    _go.name = enter_dragon_battle_path
    local pTF = _go.transform
    local pName = "EnterBattleField"
    local node = self.transform:Find(pName)
    pTF:SetParent(node)
    pTF:Set_localPosition(0, 0, 0)
    pTF:Set_localScale(1, 1, 1)
    self.enter_dragon_battle = self:AddComponent(UIEnterDragonBattle, pName .. "/" .. enter_dragon_battle_path)
    canShow = DataCenter.ActDragonManager:CanShowEnter()
    self.enter_dragon_battle:SetActive(canShow)
    if canShow then
      self.enter_dragon_battle:Refresh()
    end
  end)
end

function UIMainTop:CheckEpidemicEnter()
  local canShow = DataCenter.ActEpidemicZoneManager:CanShowEnter()
  if self.enter_epidemic_battle then
    self.enter_epidemic_battle:SetActive(canShow)
    if canShow then
      self.enter_epidemic_battle:Refresh()
    end
    return
  end
  if not canShow or self.epidemicReq ~= nil then
    return
  end
  local request = Resource:InstantiateAsync("Assets/Main/Prefabs/UI/BF_Epidemic/Common/EnterEpidemicBattle.prefab")
  self.epidemicReq = request
  request:completed("+", function(req)
    local _go = req.gameObject
    if IsNull(_go) then
      if self.epidemicReq ~= nil then
        self.epidemicReq:Destroy()
        self.epidemicReq = nil
      end
      return
    end
    _go.name = enter_epidemic_battle_path
    local pTF = _go.transform
    local pName = "EnterBattleField"
    local node = self.transform:Find(pName)
    pTF:SetParent(node)
    pTF:Set_localPosition(0, 0, 0)
    pTF:Set_localScale(1, 1, 1)
    self.enter_epidemic_battle = self:AddComponent(UIEnterEpidemicBattle, pName .. "/" .. enter_epidemic_battle_path)
    canShow = DataCenter.ActEpidemicZoneManager:CanShowEnter()
    self.enter_epidemic_battle:SetActive(canShow)
    if canShow then
      self.enter_epidemic_battle:Refresh()
    end
  end)
end

function UIMainTop:CheckDsbDuelEnter()
  local canShow = DataCenter.BattlefieldDsbDuelManager:CanShowEnter()
  if self.enter_dsb_duel_battle then
    self.enter_dsb_duel_battle:SetActive(canShow)
    if canShow then
      self.enter_dsb_duel_battle:Refresh()
    end
    return
  end
  if not canShow or self.dsbDuelReq ~= nil then
    return
  end
  local request = Resource:InstantiateAsync("Assets/Main/Prefabs/UI/BF_Dsb_Duel/Battlefield/EnterDsbDuelBattle.prefab")
  self.dsbDuelReq = request
  request:completed("+", function(req)
    local _go = req.gameObject
    if IsNull(_go) then
      if self.dsbDuelReq ~= nil then
        self.dsbDuelReq:Destroy()
        self.dsbDuelReq = nil
      end
      return
    end
    _go.name = enter_dsb_duel_path
    local pTF = _go.transform
    local pName = "EnterBattleField"
    local node = self.transform:Find(pName)
    pTF:SetParent(node)
    pTF:Set_localPosition(0, 0, 0)
    pTF:Set_localScale(1, 1, 1)
    self.enter_dsb_duel_battle = self:AddComponent(UIEnterDsbDuelBattle, pName .. "/" .. enter_dsb_duel_path)
    canShow = DataCenter.BattlefieldDsbDuelManager:CanShowEnter()
    self.enter_dsb_duel_battle:SetActive(canShow)
    if canShow then
      self.enter_dsb_duel_battle:Refresh()
    end
  end)
end

function UIMainTop:RefreshShowActivityAlarmClockView()
  self.alarmClockDispatch:RefreshShowActivityAlarmClockView()
end

function UIMainTop:DestroyActivityAlarmClockView()
  self.alarmClockDispatch:DestroyActivityAlarmClockView()
end

function UIMainTop:RefreshShowCityFightAlarmView()
  local declareInfo = DataCenter.AllianceDeclareWarManager:GetSelfDeclareWarData()
  if not declareInfo or not declareInfo.content then
    return
  end
  local cityId = declareInfo.content
  if self.cityFightAlarmReq == nil then
    self.cityFightAlarmReq = Resource:InstantiateAsync("Assets/Main/Prefabs/UI/UICityEvent/LWMainCityFightAlarmObj.prefab")
    self.cityFightAlarmReq:completed("+", function(req)
      local gameObject = req.gameObject
      if IsNull(gameObject) then
        self:DestroyCityFightAlarmView()
        return
      end
      gameObject.transform:SetParent(self.transform)
      gameObject.transform:Set_localScale(1, 1, 1)
      gameObject.transform:Set_anchoredPosition(-21, -63, 0)
      local name = "LWMainCityFightAlarmObj"
      gameObject.name = name
      self.cityFightAlarmObj = self:AddComponent(LWMainCityFightAlarmObj, name)
      self.cityFightAlarmObj:ReInit(cityId)
    end)
  elseif self.cityFightAlarmObj ~= nil then
    self.cityFightAlarmObj:ReInit(cityId)
  end
end

function UIMainTop:HideCityFightAlarmView()
  if self.cityFightAlarmObj ~= nil then
    self.cityFightAlarmObj:SetActive(false)
  end
end

function UIMainTop:DestroyCityFightAlarmView()
  if self.cityFightAlarmReq ~= nil then
    self.cityFightAlarmReq:Destroy()
    self.cityFightAlarmReq = nil
  end
  self.cityFightAlarmReq = nil
end

function UIMainTop:RefreshSeasonBtns()
  local seasonType = SeasonUtil.GetSeasonType()
  if self.farmerBtn == nil and seasonType ~= SeasonMapType.Nothing then
    local luaPath = "UI.LWMainUI.Component.UIMainTop.UIFarmerBtn"
    local prefabPath = "Assets/Main/Prefabs/UI/LWSeason/UIFarmerBtn.prefab"
    self.farmerBtn = UIBaseComponent.LoadComponentAsync(self, luaPath, prefabPath, self.rightTopBtnsRoot, function(view, go, stove_center_level)
      if IsNotNull(self.meteoriteNoticeRoot) then
        self.meteoriteNoticeRoot:SetAsLastSibling()
      end
    end)
    self.farmerBtn:SetActive(false)
  end
  if self.SeasonBtn == nil and (seasonType ~= SeasonMapType.Nothing or SeasonUtil.IsInSeasonPrepareMode()) then
    local luaPath = "UI.LWMainUI.Component.UIMainTop.UISeasonBtn"
    local prefabPath = "Assets/Main/Prefabs/UI/LWSeason/LWSeasonBtn.prefab"
    self.SeasonBtn = UIBaseComponent.LoadComponentAsync(self, luaPath, prefabPath, self.rightTopBtnsRoot, function(view, go, stove_center_level)
      if IsNotNull(self.meteoriteNoticeRoot) then
        self.meteoriteNoticeRoot:SetAsLastSibling()
      end
    end)
    self.SeasonBtn:SetActive(false)
  end
  if self.OffSeasonBtn == nil and seasonType ~= SeasonMapType.Nothing then
    local luaPath = "UI.LWMainUI.Component.UIMainTop.UIOffSeasonBtn"
    local prefabPath = "Assets/Main/Prefabs/UI/LWSeason/LWOffSeasonBtn.prefab"
    self.OffSeasonBtn = UIBaseComponent.LoadComponentAsync(self, luaPath, prefabPath, self.rightTopBtnsRoot, function(view, go, stove_center_level)
      if IsNotNull(self.meteoriteNoticeRoot) then
        self.meteoriteNoticeRoot:SetAsLastSibling()
      end
    end)
    self.OffSeasonBtn:SetActive(false)
  end
  self:RefreshSeasonBtnShow()
end

function UIMainTop:ShowSeasonResDownloadBtn()
  if self.seasonResDownload == nil then
    local prefabPath = "Assets/Main/Prefabs/UI/LWSeason/LWSeasonResourceDownloadBtn.prefab"
    local luaPath = "UI.LWMainUI.Component.UIMainTop.UISeasonResDownloadBtn"
    self.seasonResDownload = UIBaseComponent.LoadComponentAsync(self, luaPath, prefabPath, self.rightTopBtnsRoot)
    self.seasonResDownload:ReInit()
  end
end

function UIMainTop:RefresSeasonResourceDownloadBtn()
  local mainLv = toInt(DataCenter.BuildManager.MainLv)
  if mainLv >= SEASON_MIN_LEVEL then
    self:RefreshSeasonBtns()
  end
  if SeasonUtil.CheckSeasonResourceBtnShowState() then
    self:ShowSeasonResDownloadBtn()
  elseif self.seasonResDownload then
    self.seasonResDownload:SetActive(false)
  end
end

local RefreshZoneMobilizationAct = function(self)
  if self.zone_mobilization_btn then
    self.zone_mobilization_btn:ReInit()
  end
end
local OnReceivePushMsgRequestZoneMobilizationData = function(self, message)
  if message then
    if message.firstOpen then
      DataCenter.LWZoneMobilizationManager:RequestZoneMobilizationDonatedInfoData(1)
    elseif message.tabType then
      DataCenter.LWZoneMobilizationManager:RequestZoneMobilizationDonatedInfoData(message.tabType)
    end
  end
end

function UIMainTop:RefreshDominatorEntrance()
  if self.dominatorCockatriceUnlockBtn == nil then
    local isShow = DataCenter.DominatorCockatriceUnlockManager:IsShowMainUIEntrance()
    if isShow and self.dominatorEntranceReq == nil then
      local prefabPath = "Assets/Main/Prefabs/UI/LWMainUI/DominatorUnlockBtn.prefab"
      self.dominatorEntranceReq = self:GameObjectInstantiateAsync(prefabPath, function(request)
        if request.isError then
          return
        end
        local go = request.gameObject
        go.transform:SetParent(self.rightTopBtnsRoot.transform)
        go.transform:Set_localScale(ResetScale.x, ResetScale.y, ResetScale.z)
        go.name = "DominatorCockatriceUnlockBtn"
        self.dominatorCockatriceUnlockBtn = self.rightTopBtnsRoot:AddComponent(UILWDominatorCockatriceUnlockMainUIEntranceComponent, go.name)
        self.dominatorCockatriceUnlockBtn:ReInit()
      end)
    end
  else
    self.dominatorCockatriceUnlockBtn:ReInit()
  end
end

function UIMainTop:DestroyDominatorEntrance()
  if self.dominatorEntranceReq ~= nil then
    self.dominatorEntranceReq:Destroy()
    self.dominatorEntranceReq = nil
  end
end

function UIMainTop:OnBattlefieldActStateChanged()
  self:CheckDragonEnter()
  self:CheckWinterStormEnter()
  self:CheckEpidemicEnter()
  self:CheckDsbDuelEnter()
end

UIMainTop.RefreshZoneMobilizationAct = RefreshZoneMobilizationAct
UIMainTop.OnReceivePushMsgRequestZoneMobilizationData = OnReceivePushMsgRequestZoneMobilizationData
return UIMainTop
