SetViewEffectState = class("SetViewEffectState",SubView)

local resolutionLabTab = {}
local resolutionIndex = 1

local refreshRateLabTab = {}
local refreshRateIndex = 1

function SetViewEffectState:Init ()
     self:FindObj()
     self:AddEvts()
     self:Show()
end

function SetViewEffectState:FindObj ()

    if self:FindGO("OutlineSet/OutlineToggle") then
        self.outlineToggle = self:FindGO("OutlineSet/OutlineToggle"):GetComponent("UIToggle")
        self.effectToggle = self:FindGO("EffectSet/EffectToggle"):GetComponent("UIToggle")
        self.toonLightToggle = self:FindGO("ToonLightSet/ToonLightToggle"):GetComponent("UIToggle")
        self.slimToggle = self:FindGO("SlimToggle"):GetComponent("UIToggle")
        self.selfPeakToggle = self:FindGO("SelfPeakToggle"):GetComponent("UIToggle")
        self.otherPeakToggle = self:FindGO("OtherPeakToggle"):GetComponent("UIToggle")
        self.screenCountToggleLow = self:FindGO("ScreenCountToggleLow"):GetComponent("UIToggle")
    	self.screenCountToggleMid = self:FindGO("ScreenCountToggleMid"):GetComponent("UIToggle")
    	self.screenCountToggleHigh = self:FindGO("ScreenCountToggleHigh"):GetComponent("UIToggle")
        self.ShowOtherNameToggle = self:FindGO("ShowOtherNameToggle"):GetComponent("UIToggle")
        self.ShowOtherCharToggle = self:FindGO("ShowOtherCharToggle"):GetComponent("UIToggle")
        self.ResolutionFilter = self:FindGO("ResolutionFilter"):GetComponent("UIPopupList")
        self.RefreshRateFilter = self:FindGO("RefreshRateFilter"):GetComponent("UIPopupList")
    end
end

function SetViewEffectState:AddEvts()
    if self.ResolutionFilter then
        EventDelegate.Add(self.ResolutionFilter.onChange, function()
            resolutionIndex = resolutionLabTab[self.ResolutionFilter.value]
        end)
    end
    if self.RefreshRateFilter then
        EventDelegate.Add(self.RefreshRateFilter.onChange, function()
            refreshRateIndex = refreshRateLabTab[self.RefreshRateFilter.value]
        end)
    end
end

function SetViewEffectState:SettingUI()

    if self.ResolutionFilter then
        self.ResolutionFilter:Clear()
        resolutionLabTab = {}
        local rsTab = Game.GetResolutionNames()
        for i=1,#rsTab do
            local str = rsTab[i]
            self.ResolutionFilter:AddItem(str)
            resolutionLabTab[str] = i
        end

        self.RefreshRateFilter:Clear()
        refreshRateLabTab = {}
        local rrTab = Game.GetRefreshRateNames()
        for i=1,#rrTab do
            local str = rrTab[i]
            self.RefreshRateFilter:AddItem(str)
            refreshRateLabTab[str] = i
        end

        local setting = FunctionPerformanceSetting.Me()
        local screenCount = setting:GetSetting().screenCount

        self.outlineToggle.value = setting:GetSetting().outLine
        self.toonLightToggle.value = setting:GetSetting().toonLight
        self.effectToggle.value = not setting:GetSetting().effectLow
        self.selfPeakToggle.value = setting:GetSetting().selfPeak
        self.otherPeakToggle.value = setting:GetSetting().otherPeak
        self.ShowOtherNameToggle.value = setting:GetSetting().isShowOtherName
        self.ShowOtherCharToggle.value = setting:GetSetting().showOtherChar
        self.ResolutionFilter.value = rsTab[setting:GetSetting().resolution]
        resolutionIndex = setting:GetSetting().resolution
        self.RefreshRateFilter.value = rrTab[setting:GetSetting().refreshRate]
        refreshRateIndex = setting:GetSetting().refreshRate
        self.screenCountToggleMid.value = screenCount == GameConfig.Setting.ScreenCountMid and true or false
        self.screenCountToggleHigh.value = screenCount == GameConfig.Setting.ScreenCountHigh and true or false
        self.screenCountToggleLow.value = screenCount == GameConfig.Setting.ScreenCountLow and true or false

        local option = Game.Myself.data.userdata:Get(UDEnum.OPTION)
        if option ~= nil then
            self.slimToggle.value = BitUtil.band(option, SceneUser2_pb.EOPTIONTYPE_USE_SLIM) > 0
        else
            self.slimToggle.value = true
        end
    end
end

function SetViewEffectState:Show ()
    self:SettingUI()
end

function SetViewEffectState:Save ()
    self:SetNormalModeData()
end

function SetViewEffectState:SetNormalModeData()
    local setting = FunctionPerformanceSetting.Me()
    local screenCount
    if self.screenCountToggleMid.value == true then
        screenCount = GameConfig.Setting.ScreenCountMid
    elseif self.screenCountToggleHigh.value == true then
        screenCount = GameConfig.Setting.ScreenCountHigh
    else
        screenCount = GameConfig.Setting.ScreenCountLow
    end

    setting:SetBegin()
    setting:SetOutLine(self.outlineToggle.value)
    setting:SetToonLight(self.toonLightToggle.value)
    setting:SetEffectLow(not self.effectToggle.value)
    setting:SetSlim(self.slimToggle.value)
    setting:SetSelfPeak(self.selfPeakToggle.value)
    setting:SetOtherPeak(self.otherPeakToggle.value)
    setting:SetScreenCount(screenCount)
    setting:SetShowOtherName(self.ShowOtherNameToggle.value)
    setting:SetShowOtherChar(self.ShowOtherCharToggle.value)
    setting:SetResolution(resolutionIndex)
    setting:SetRefreshRate(refreshRateIndex)
    setting:SetEnd()
end

function SetViewEffectState:Exit ()

end

function SetViewEffectState:SwitchOn ()

end

function SetViewEffectState:SwitchOff ()

end
