local UIMainTroops = BaseClass("UIMainTroops", UIBaseContainer)
local base = UIBaseContainer
local Localization = CS.GameEntry.Localization
local common_red_point_path = "btn/CommonRedPoint"
local text_path = "btn/text"
local btn_path = "btn"
local harmer_path = "btn/icon"
local EMPTY_ICON = "Assets/Main/Sprites/UI/UIBuildQueue/zyf_chengjian_dikuai.png"
local OnCreate = function(self)
  base.OnCreate(self)
  self:ComponentDefine()
  self:DataDefine()
  self:Refresh()
end
local OnDestroy = function(self)
  self:ComponentDestroy()
  self:DataDestroy()
  base.OnDestroy(self)
end
local ComponentDefine = function(self)
  self.view:RegisterFunctionUnlock(LWFunctionUnlockType.MainUI_BuildQueue, self.gameObject)
  self.commonRedPoint = self:AddComponent(UICommonRedPoint, common_red_point_path)
  self.commonRedPoint:SetType(CommonRedPointPriority.LevelNormal)
  self.commonRedPoint:SetId(CommonRedPointId.MainUI_BuildQueue)
  self.text = self:AddComponent(UIText, text_path)
  self.btn = self:AddComponent(UIButton, btn_path)
  self.harmer = self:AddComponent(UIBaseContainer, harmer_path)
  self.btn:SetOnClick(BindCallback(self, self.OnClickView))
end
local ComponentDestroy = function(self)
end
local DataDefine = function(self)
end
local DataDestroy = function(self)
end
local OnAddListener = function(self)
  base.OnAddListener(self)
  self:AddUIListener(EventId.RefreshUIBuildQueue, self.Refresh)
  self:AddUIListener(EventId.ShowBuildQueueTip, self.ShowBubble)
end
local OnRemoveListener = function(self)
  base.OnRemoveListener(self)
  self:RemoveUIListener(EventId.RefreshUIBuildQueue, self.Refresh)
  self:RemoveUIListener(EventId.ShowBuildQueueTip, self.ShowBubble)
end
local Refresh = function(self)
  if SceneUtils.GetIsInWorld() then
    self.gameObject:SetActive(false)
    return
  end
  local unlock = DataCenter.LWFunctionUnlockManager:CheckCanShow(LWFunctionUnlockType.MainUI_BuildQueue)
  self.gameObject:SetActive(unlock and DataCenter.BuildQueueManager:CheckMainUICanShow())
  if unlock then
    self.commonRedPoint:SetDefaultVisible(DataCenter.BuildQueueManager:GetFreeQueueUuid() > 0)
    local isInUnlimitedMode = DataCenter.BuildQueueManager:IsInUnlimitedMode()
    if isInUnlimitedMode then
      self.text:SetText(string.format("%d/%s", DataCenter.BuildQueueManager:GetOccupideQueueNum(), "\226\136\158"))
    else
      self.text:SetText(string.format("%d/%d", DataCenter.BuildQueueManager:GetOccupideQueueNum(), DataCenter.BuildQueueManager:GetAllCanUseQueueNum()))
    end
  end
end
local OnClickView = function(self)
  self.commonRedPoint:SetViewed()
  UIManager:GetInstance():OpenWindow(UIWindowNames.UIBuildQueue)
end
local OnEnable = function(self)
  base.OnEnable(self)
end
local OnDisable = function(self)
  base.OnDisable(self)
end
local ReInit = function(self)
  self:Refresh()
end
local ShowBubble = function(self)
  local window = UIManager:GetInstance():GetWindow(UIWindowNames.UILWWorkerQueue)
  if window == nil then
    UIManager:GetInstance():OpenWindow(UIWindowNames.UILWWorkerQueue)
  end
end
local CloseBubble = function(self)
end
UIMainTroops.OnDestroy = OnDestroy
UIMainTroops.OnCreate = OnCreate
UIMainTroops.ComponentDefine = ComponentDefine
UIMainTroops.DataDestroy = DataDestroy
UIMainTroops.ComponentDestroy = ComponentDestroy
UIMainTroops.DataDefine = DataDefine
UIMainTroops.OnEnable = OnEnable
UIMainTroops.OnDisable = OnDisable
UIMainTroops.OnClickView = OnClickView
UIMainTroops.ReInit = ReInit
UIMainTroops.Refresh = Refresh
UIMainTroops.OnAddListener = OnAddListener
UIMainTroops.OnRemoveListener = OnRemoveListener
UIMainTroops.ShowBubble = ShowBubble
UIMainTroops.CloseBubble = CloseBubble
return UIMainTroops
