local WorldBattleBuff = BaseClass("WorldBattleBuff")
local default_show_time = 0.8
local Localization = CS.GameEntry.Localization
local OnCreate = function(self, go)
  if go ~= nil then
    self.request = go
    self.gameObject = go.gameObject
    self.transform = go.gameObject.transform
  end
  self:ComponentDefine()
end
local OnDestroy = function(self)
  self:RemoveTimer()
  self:ComponentDestroy()
end
local ComponentDefine = function(self)
  self.isDoAnim = false
  self.simpleAnim = self.transform:GetComponentInChildren(typeof(CS.SimpleAnimation), true)
  self.arrowTrans = self.transform:Find("num/layout").gameObject
  self.des_name = self.transform:Find("num"):GetComponent(typeof(CS.SuperTextMesh))
  self.addArrow = self.transform:Find("num/layout/add"):GetComponent(typeof(CS.UnityEngine.SpriteRenderer))
  self.addArrow.gameObject:SetActive(false)
  self.decArrow = self.transform:Find("num/layout/dec"):GetComponent(typeof(CS.UnityEngine.SpriteRenderer))
  self.decArrow.gameObject:SetActive(false)
  
  function self.__update_handle()
    self:Update()
  end
  
  UpdateManager:GetInstance():AddUpdate(self.__update_handle)
end
local ComponentDestroy = function(self)
  self.arrowTrans = nil
  self.addArrow = nil
  self.decArrow = nil
end
local RemoveTimer = function(self)
  if self.__update_handle ~= nil then
    UpdateManager:GetInstance():RemoveUpdate(self.__update_handle)
    self.__update_handle = nil
  end
end
local ReInit = function(self, param)
  self.data = param
  local posV3 = SceneUtils.TileIndexToWorld(param.pointId)
  self.transform.position = posV3
  self.des_name.text = Localization:GetString(param.desc)
  local nameWidth = self.des_name:GetWidth()
  local v3 = Vector3.New(self.des_name.gameObject.transform.position.x + nameWidth * 2 / 3, self.arrowTrans.transform.position.y, self.arrowTrans.transform.position.z)
  self.arrowTrans.transform.position = v3
  if param.isAdd == true then
    self.addArrow.gameObject:SetActive(true)
    self.decArrow.gameObject:SetActive(false)
    if param.isGreen == true then
      self.des_name.color32 = WorldGreenColor32
      self.addArrow:LoadSprite("Assets/Main/Sprites/UI/UIWorldBattle/UIWorldBattle_img_green_arrow.png")
    else
      self.des_name.color32 = WorldRedColor32
      self.addArrow:LoadSprite("Assets/Main/Sprites/UI/UIWorldBattle/UIWorldBattle_img_red_arrow.png")
    end
  else
    self.addArrow.gameObject:SetActive(false)
    self.decArrow.gameObject:SetActive(true)
    if param.isGreen == true then
      self.des_name.color32 = WorldGreenColor32
      self.decArrow:LoadSprite("Assets/Main/Sprites/UI/UIWorldBattle/UIWorldBattle_img_green_arrow.png")
    else
      self.des_name.color32 = WorldRedColor32
      self.decArrow:LoadSprite("Assets/Main/Sprites/UI/UIWorldBattle/UIWorldBattle_img_red_arrow.png")
    end
  end
  self.curTime = 0
  self.isDoAnim = true
  self.simpleAnim:Play("normal")
  self.simpleAnim:PlayQueued("show")
  self:Update()
end
local Update = function(self)
  if self.isDoAnim then
    self.curTime = self.curTime + Time.deltaTime
    if self.curTime > default_show_time then
      self.isDoAnim = false
      WorldBattleBuffManager:GetInstance():CheckRemove(self.data.uuid)
    end
  end
end
WorldBattleBuff.OnCreate = OnCreate
WorldBattleBuff.OnDestroy = OnDestroy
WorldBattleBuff.ComponentDefine = ComponentDefine
WorldBattleBuff.ComponentDestroy = ComponentDestroy
WorldBattleBuff.Update = Update
WorldBattleBuff.RemoveTimer = RemoveTimer
WorldBattleBuff.ReInit = ReInit
return WorldBattleBuff
