local BuildLabelTipManager = BaseClass("BuildLabelTipManager", Singleton)
local ResourceManager = CS.GameEntry.Resource
local BuildLabelTip = require("Scene.BuildLabel.BuildLabelTip")
local __init = function(self)
  self.allTips = {}
  self.OnCreateTips = {}
  self:AddListener()
end
local __delete = function(self)
  for k, v in pairs(self.allTips) do
    local request = v.request
    v.script:OnDestroy()
    request:Destroy()
  end
  self.allTips = nil
  self:RemoveListener()
end
local AddListener = function(self)
  EventManager:GetInstance():AddListener(EventId.CheckShowMainBuildLabel, self.BuildInViewSignal)
  EventManager:GetInstance():AddListener(EventId.BUILD_OUT_VIEW, self.BuildOutViewSignal)
end
local RemoveListener = function(self)
  EventManager:GetInstance():RemoveListener(EventId.CheckShowMainBuildLabel, self.BuildInViewSignal)
  EventManager:GetInstance():RemoveListener(EventId.BUILD_OUT_VIEW, self.BuildOutViewSignal)
end
local RemoveOneEffect = function(self, bUuid)
  local temp = self.allTips[bUuid]
  if temp ~= nil then
    local request = temp.request
    temp.script:OnDestroy()
    request:Destroy()
    self.allTips[bUuid] = nil
  end
end
local BuildInViewSignal = function(uuid)
  BuildLabelTipManager:GetInstance():CheckShowEffect(tonumber(uuid))
end
local BuildOutViewSignal = function(uuid)
  BuildLabelTipManager:GetInstance():RemoveOneEffect(tonumber(uuid))
end
local CheckShowEffect = function(self, bUuid)
  local info = CS.SceneManager.World:GetPointInfoByUuid(bUuid)
  if info ~= nil then
    cast(info, typeof(CS.BuildPointInfo))
    if info.itemId == BuildingTypes.FUN_BUILD_MAIN then
      local param = {}
      param.posIndex = info.mainIndex
      param.abbr = info.alAbbr
      param.name = info.playerName
      param.State = info:GetPlayerType()
      if self.allTips[bUuid] == nil and self.OnCreateTips[bUuid] == nil then
        local request = ResourceManager:InstantiateAsync(UIAssets.BuildLabelTip)
        local par = {}
        par.request = request
        self.OnCreateTips[bUuid] = request
        request:completed("+", function()
          self.OnCreateTips[bUuid] = nil
          if request.isError then
            return
          end
          request.gameObject:SetActive(true)
          request.gameObject.transform:SetParent(CS.SceneManager.World.DynamicObjNode)
          request.gameObject.transform:Set_localScale(ResetScale.x, ResetScale.y, ResetScale.z)
          local effect = BuildLabelTip.New()
          effect:OnCreate(request)
          effect:ReInit(param)
          par.script = effect
          self.allTips[bUuid] = par
        end)
      elseif self.allTips[bUuid] ~= nil then
        self.allTips[bUuid].script:ReInit(param)
      end
    end
  end
end
BuildLabelTipManager.__init = __init
BuildLabelTipManager.__delete = __delete
BuildLabelTipManager.AddListener = AddListener
BuildLabelTipManager.RemoveListener = RemoveListener
BuildLabelTipManager.BuildInViewSignal = BuildInViewSignal
BuildLabelTipManager.BuildOutViewSignal = BuildOutViewSignal
BuildLabelTipManager.RemoveOneEffect = RemoveOneEffect
BuildLabelTipManager.CheckShowEffect = CheckShowEffect
return BuildLabelTipManager
