local WorldNewsTips = require("Scene.WorldNewsTip.WorldNewsTips")
local WorldNewsTipsManager = BaseClass("WorldNewsTipsManager", Singleton)
local ResourceManager = CS.GameEntry.Resource
local __init = function(self)
  self.allShowEffect = {}
  self.OnCreateShowEffect = {}
  self:AddListener()
end
local __delete = function(self)
  for k, v in pairs(self.allShowEffect) do
    local request = v.request
    v:OnDestroy()
    request:Destroy()
  end
  self.allShowEffect = nil
  for k, v in pairs(self.OnCreateShowEffect) do
    v:Destroy()
  end
  self.OnCreateShowEffect = nil
  self:RemoveListener()
end
local AddListener = function(self)
  EventManager:GetInstance():AddListener(EventId.PveLevelEnter, self.RemoveAllTips)
  EventManager:GetInstance():AddListener(EventId.UpdateWorldZoneNews, self.ShowZoneNewsIconShow)
  EventManager:GetInstance():AddListener(EventId.ChangeCameraLod, self.ChangeCameraLodSignal)
end
local RemoveListener = function(self)
  EventManager:GetInstance():RemoveListener(EventId.PveLevelEnter, self.RemoveAllTips)
  EventManager:GetInstance():RemoveListener(EventId.UpdateWorldZoneNews, self.ShowZoneNewsIconShow)
  EventManager:GetInstance():RemoveListener(EventId.ChangeCameraLod, self.ChangeCameraLodSignal)
end
local ChangeCameraLodSignal = function(lod)
  WorldNewsTipsManager:GetInstance():UpdateLod(lod)
end
local RemoveAllTips = function(data)
  WorldNewsTipsManager:GetInstance():RemoveAllShowIcon()
end
local UpdateLod = function(self, lod)
  if self.lodCache ~= lod then
    self.lodCache = lod
    if self.lodCache >= 8 then
      DataCenter.WorldNewsDataManager:SendRequest()
    else
      self:RemoveAllShowIcon()
    end
  end
end
local RemoveAllShowIcon = function(self)
  for k, v in pairs(self.allShowEffect) do
    local request = v.request
    v:OnDestroy()
    request:Destroy()
  end
  self.allShowEffect = {}
  for k, v in pairs(self.OnCreateShowEffect) do
    v:Destroy()
  end
  self.OnCreateShowEffect = {}
end
local RemoveOneShowIcon = function(self, id)
  if self.allShowEffect ~= nil and self.allShowEffect[id] ~= nil then
    local tips = self.allShowEffect[id]
    local request = tips.request
    tips:OnDestroy()
    request:Destroy()
    self.allShowEffect[id] = nil
  end
  if self.OnCreateShowEffect[id] ~= nil then
    self.OnCreateShowEffect[id]:Destroy()
    self.OnCreateShowEffect[id] = nil
  end
end
local InitShowList = function(self)
  local infoList = DataCenter.WorldNewsDataManager:GetAreaInfoList()
  local deleteList = {}
  for k, v in pairs(self.OnCreateShowEffect) do
    if infoList[k] == nil then
      table.insert(deleteList, k)
    end
  end
  for k, v in pairs(self.allShowEffect) do
    if infoList[k] == nil then
      table.insert(deleteList, k)
    end
  end
  for k, v in pairs(deleteList) do
    self:RemoveOneShowIcon(v)
  end
  for k, v in pairs(infoList) do
    if self.allShowEffect[k] == nil and self.OnCreateShowEffect[k] == nil then
      local request = ResourceManager:InstantiateAsync(UIAssets.WorldNewsTips)
      self.OnCreateShowEffect[k] = request
      request:completed("+", function()
        self.OnCreateShowEffect[k] = 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 = WorldNewsTips.New()
        effect:OnCreate(request)
        effect:SetData(v)
        self.allShowEffect[k] = effect
      end)
    end
  end
end
local ShowZoneNewsIconShow = function(data)
  WorldNewsTipsManager:GetInstance():InitShowList()
end
WorldNewsTipsManager.__init = __init
WorldNewsTipsManager.__delete = __delete
WorldNewsTipsManager.AddListener = AddListener
WorldNewsTipsManager.RemoveListener = RemoveListener
WorldNewsTipsManager.ChangeCameraLodSignal = ChangeCameraLodSignal
WorldNewsTipsManager.UpdateLod = UpdateLod
WorldNewsTipsManager.RemoveAllShowIcon = RemoveAllShowIcon
WorldNewsTipsManager.ShowZoneNewsIconShow = ShowZoneNewsIconShow
WorldNewsTipsManager.RemoveOneShowIcon = RemoveOneShowIcon
WorldNewsTipsManager.InitShowList = InitShowList
WorldNewsTipsManager.RemoveAllTips = RemoveAllTips
return WorldNewsTipsManager
