local this = class("cameraController_world", require("ui.manager.camera.controller.cameraController"))

function this:ctor(mode)
  this.super.ctor(self, mode)
  self.cameraTactics = C_CameraManager.CreateBigWorldTactics()
  C_CameraManager.CreateLookAtTactics()
  self.virCamera = self.cameraTactics.cinemachineCameraPrefab:GetComponent(typeof(C_CinemachineVirtualCamera))
  self.fixedFollow = self.cameraTactics.cinemachineCameraPrefab:GetComponent(typeof(C_CameraFixedFollow))
end

function this:switchIn(preMode, params)
  if self.virCamera then
    local goVir = self.virCamera.gameObject
    goVir:ActiveTrans(true)
    if params.povH then
      self.cameraTactics:SetCameraPOVHorizontal(params.povH)
    end
    if params.povV then
      self.cameraTactics:SetCameraPOVVertical(params.povV)
    end
    if params.distance then
      self.cameraTactics:SetCameraDis(params.distance)
    end
  end
  local preCamera = C_CameraManager.GetCommonTactics()
  if preCamera then
    preCamera:SetEnabled(false)
  end
  self.cameraTactics:SetEnabled(true)
  if L_PlayerManager:getMainControlEntity() then
    self:refreshVirCameraOffset(L_PlayerManager:getMainControlEntity())
  end
end

function this:switchOut(nextMode)
  if self.virCamera then
  end
end

function this:bindEntity(entity)
  if entity == L_PlayerManager:getMainControlEntity() then
    C_CameraManager.SetFollowTarget(nil)
  else
    C_CameraManager.SetFollowTarget(entity:getTransform())
  end
  self:refreshVirCameraOffset(entity)
end

function this:bindGameObject(go)
  C_CameraManager.SetFollowTarget(go.transform)
end

function this:refreshVirCameraOffset(entity)
end

function this:onDestroy()
  this.super.onDestroy(self)
  if L_CommonUtil.isValid(self.goBindPoint) then
    C_GameObject.Destroy(self.goBindPoint)
  end
  self.goBindPoint = nil
end

function this:initVirCamera()
  self:setCameraSpeed()
  self:refreshSoftCamera()
end

function this:refreshSoftCamera()
  local set = tonumber(L_SettingStore:getSetData(L_Const.settingType.softCamera))
  local SOFT_CAMERA_SET = L_GameClientTpl:getValue("SOFT_CAMERA_SET")
  local SOFT_CAMERA_TIME = L_GameClientTpl:getValue("SOFT_CAMERA_TIME")
  local dump = SOFT_CAMERA_SET[set + 1]
  local time = SOFT_CAMERA_TIME[set + 1]
  self.cameraTactics:SetDamping(dump[1] * 0.01, dump[2] * 0.01, dump[3] * 0.01, time[1] * 0.01, time[2] * 0.01)
end

function this:setBlendStyle(style, time)
  C_CameraManager.SetBrainBlendStyle(style)
  C_CameraManager.SetBrainBlendTime(time / 1000)
end

function this:setCameraSpeed()
  local speed = L_SettingStore:getSetData(L_Const.settingType.cameraSpeed)
  self.cameraTactics:SetCameraSpeed(tonumber(speed) * 0.4)
end

return this
