local this = class("settingAdapter")
local _optionDataTpl = L_GameTpl:getOptionDataTpl()

function this:ctor()
end

function this:adapt(id, value)
  if self[id] then
    self[id](self, value)
  else
  end
end

function this:initText(value)
  local lang = L_Const.settingText[L_Const.settingType.text][tonumber(value)] or C_I18NConst.LanguageChs
  if C_Define.language == lang then
    return
  end
  C_Define.language = lang
  L_Lang:clear()
  C_LuaManager.LoadLuaLanguage()
  C_LText.RefreshLanguage()
  C_LTextMeshProUGUI.RefreshLanguage()
  C_LLangImage.ChangeLanguage()
  L_GameTpl:changeLanguage()
end

function this:setQualityValue(value, settings, factor)
  value = tostring(value)
  for i, v in pairs(settings) do
    local val = v[value]
    if val then
      if factor then
        val = tostring(val * factor)
      end
      C_DeviceGradingManager.SetQualityValue(i, val)
    end
  end
end

function this:setKey(id, value)
end

function this:calResolutionFactor()
  return 1
end

this[L_Const.settingType.cameraSpeed] = function(self, value)
  L_CameraManager:setCameraSpeed()
end
this[L_Const.settingType.uiOffset] = function(self, value)
end
this[L_Const.settingType.softCamera] = function(self, value)
  local camController = L_CameraManager:getCurCamController()
  if camController and camController:getMode() == L_Const.cameraMode.world then
    camController:refreshSoftCamera()
  end
end
this[L_Const.settingType.bgm] = function(self, value)
  local tpl = _optionDataTpl:getTplById(L_Const.settingType.bgm)
  local list = _optionDataTpl:getOptionPara2(tpl)
  value = value / list[2]
  C_AudioManager.SetRTPCValue(L_Const.wwiseSoundGroup.bgm, value * 100)
  C_LoginMovieHelper.SetBGMVolume(value)
end
this[L_Const.settingType.se] = function(self, value)
  local tpl = _optionDataTpl:getTplById(L_Const.settingType.se)
  local list = _optionDataTpl:getOptionPara2(tpl)
  value = value / list[2]
  C_AudioManager.SetRTPCValue(L_Const.wwiseSoundGroup.worldSe, value * 100)
  C_AudioManager.SetRTPCValue(L_Const.wwiseSoundGroup.uiSe, value * 100)
end
this[L_Const.settingType.cv] = function(self, value)
  local tpl = _optionDataTpl:getTplById(L_Const.settingType.cv)
  local list = _optionDataTpl:getOptionPara2(tpl)
  value = value / list[2]
  C_AudioManager.SetRTPCValue(L_Const.wwiseSoundGroup.cv, value * 100)
end
this[L_Const.settingType.mute] = function(self, value)
  value = tostring(value) == "true" and 0 or 1
  C_AudioManager.SetRTPCValue(L_Const.wwiseSoundGroup.all, value * 100)
  C_LoginMovieHelper.SetMuteStatus(value)
end
this[L_Const.settingType.text] = function(self, value)
  self:initText(value)
  local u32 = L_Const.mailLanguage[L_Const.settingText[L_Const.settingType.text][value]]
  L_MailStore:req_changeCSProtoSetLanguage(u32)
end
this[L_Const.settingType.indicatorHud] = function(self, value)
end
this[L_Const.settingType.language] = function(self, value)
  local lang = L_Const.settingText[L_Const.settingType.language][tonumber(value)]
  C_AudioManager.SetAudioLanguage(lang)
end
this[L_Const.settingType.resolution] = function(self, id)
end
this[L_Const.settingType.frame] = function(self, value)
  C_DeviceGradingManager.SetQualityValue("ProjectFPS", "60")
end
this[L_Const.settingType.image] = function(self, value)
  local level = tonumber(value)
  C_DeviceGradingManager.SetQualityPreset(level - 1)
end
this[L_Const.settingType.renderSet] = function(self, value)
  self:setQualityValue(value, L_Const.settingType_Render_pc)
end
this[L_Const.settingType.renderAccuracy] = function(self, value)
  local v = tonumber(value) or 100
  if v < 10 then
    self:setQualityValue(value, L_Const.settingType_RenderScale_pc)
  else
    v = v / 100
    C_DeviceGradingManager.SetQualityValue("PipelineRenderScale", tostring(v))
  end
end
this[L_Const.settingType.shadow] = function(self, value)
  self:setQualityValue(value, L_Const.settingType_Shadow_pc)
end
this[L_Const.settingType.module] = function(self, value)
  self:setQualityValue(value, L_Const.settingType_Model_pc)
end
this[L_Const.settingType.specialEffects] = function(self, value)
  self:setQualityValue(value, L_Const.settingType_Effects_pc)
end
this[L_Const.settingType.antiAliasing] = function(self, value)
  value = L_Const.settingText[L_Const.settingType.antiAliasing][value]
  C_DeviceGradingManager.SetQualityValue(C_QualityConstants.ANTI_ALISING, value)
end
this[L_Const.settingType.vSync] = function(self, value)
  value = tonumber(value)
  if value == 2 then
    Unity.QualitySettings.vSyncCount = 1
  else
    Unity.QualitySettings.vSyncCount = 0
  end
end
this[L_Const.settingType.battleCameraAlign] = function(self, value)
  local val = tostring(value) == "false"
  C_CameraManager.resetIgnore = val
end
this[L_Const.settingType.ultimateSkillAnim] = function(self, value)
  local val = tostring(value) == "false"
  C_CameraManager.herotimelineIgnore = val
end
this[L_Const.settingType.petSkillAnim] = function(self, value)
  local val = tostring(value) == "false"
  C_CameraManager.pettimelineIgnore = val
end
this[L_Const.settingType.petSummonCamera] = function(self, value)
  local val = tostring(value) == "false"
  C_CameraManager.petZhihuiIgnore = val
end
this[L_Const.settingType.breakCamera] = function(self, value)
  local val = tostring(value) == "false"
  C_CameraManager.breakIgnore = val
end
this[L_Const.settingType.switchCamera] = function(self, value)
  local val = tostring(value) == "false"
  C_CameraManager.switchFovTimelineIgnore = val
end
this[L_Const.settingType.petTogetherSkillCamera] = function(self, value)
  local val = tostring(value) == "false"
  C_CameraManager.petTogetherSkillIgnore = val
end
this[L_Const.settingType.bright] = function(self, value)
  L_SettingStore:setbright(value)
end
this[L_Const.settingType.saturation] = function(self, value)
  L_SettingStore:setSaturation(value)
end
this[L_Const.settingType.contrast] = function(self, value)
  L_SettingStore:setContrast(value)
end
this[L_Const.settingType.npcDensityLevel] = function(self, value)
end
return this
