ESO Lua File v100011

common/gammaadjust/gammaadjust.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
local currentGamma = GetCVar("GAMMA_ADJUSTMENT")
local function GammaDialogInitialize(dialogControl)
    ZO_Dialogs_RegisterCustomDialog("ADJUST_GAMMA_DIALOG",
    {
        customControl = dialogControl,
        mustChoose = true,
        title =
        {
            text = "",
        },
        buttons =
        {
            [1] =
            {
                control = GetControl(dialogControl, "ConfirmGamma"),
                text = SI_GAMMA_CONFIRM,
                noReleaseOnClick = true, -- Don't release because the scene needs to fade out, will release later
                callback =  function(dialog)
                                SetCVar("GAMMA_ADJUSTMENT", tostring(currentGamma))
                                SCENE_MANAGER:Hide("gammaAdjust")
                            end,
            },
        }                                   
    })
end
-- Gamma Scene and Fragment management
do
    local ZO_GammaAdjustFragment = ZO_FadeSceneFragment:Subclass()
    function ZO_GammaAdjustFragment:New(control)
        local fragment = ZO_FadeSceneFragment.New(self, control, 1500)
        fragment.dialog = control
        local oldStop = fragment.animationReverseOnStop
        fragment.animationReverseOnStop = function()
                                        --Have to release the dialog before the stop handler hides it or it won't decrease the number of top levels
                                        ZO_Dialogs_ReleaseDialog("ADJUST_GAMMA_DIALOG")
                                        oldStop()
                                    end
        return fragment
    end
    function ZO_GammaAdjustFragment:Show()
        currentGamma = GetCVar("GAMMA_ADJUSTMENT")
        ZO_Dialogs_ShowDialog("ADJUST_GAMMA_DIALOG")
        -- Tweak custom dialog controls
        local dialog = self.dialog
        local confirm = dialog:GetNamedChild("ConfirmGamma")
        local slider = dialog:GetNamedChild("Slider")
        if ZO_GammaAdjust_ShouldShow() then
            slider:SetValue(113)
        else
            slider:SetValue(currentGamma)
        end
        confirm:ClearAnchors()
        confirm:SetAnchor(TOP, dialog:GetNamedChild("Slider"), BOTTOM, 0, 20)
        dialog:GetNamedChild("Divider"):SetHidden(true)
        dialog:GetNamedChild("BG"):SetHidden(true)
        dialog:GetNamedChild("ModalUnderlay"):SetColor(0, 0, 0, 1)
        -- Call base class for animations after everything has been tweaked
        ZO_FadeSceneFragment.Show(self)
    end
    function ZO_GammaAdjustFragment:OnHidden()
        ZO_FadeSceneFragment.OnHidden(self)
        if PregameStateManager_GetCurrentState then
            local currentState = PregameStateManager_GetCurrentState()
            if currentState == "GammaAdjust" then
                SetCVar("PregameGammaCheckEnabled", "false")
                PregameStateManager_AdvanceState()
            elseif currentState == "AccountLogin" then
                SCENE_MANAGER:Show("gameMenuPregame")
            elseif currentState == "CharacterSelect" then
                SCENE_MANAGER:Show("gameMenuCharacterSelect")
            elseif currentState == "CharacterCreate" then
                SCENE_MANAGER:Show("gameMenuCharacterCreate")
            else
                -- WTF
            end
        else
            SCENE_MANAGER:Show("gameMenuInGame")
        end
    end
    function CreateGammaSceneFragment(control)
        GAMMA_SCENE_FRAGMENT = ZO_GammaAdjustFragment:New(control)
    end
end
    if(not self.dialogInitialized) then
        self.dialogInitialized = true
        GammaDialogInitialize(self)
        CreateGammaSceneFragment(self)
    end
end
local imageData =
{
    { "ZO_GammaAdjustReferenceImage1", 2 / 255 },
    { "ZO_GammaAdjustReferenceImage2", 7 / 255 },
    { "ZO_GammaAdjustReferenceImage3", 20 / 255 },
}
local function GammaToLinear(gamma)
    if(gamma <= 0.04045) then
        return (gamma / 12.92)
    else
        return zo_pow(zo_abs(gamma + 0.055) / 1.055, 2.4)
    end
end
local function LinearToGamma(linear)
    if(linear <= 0.0031308) then
        return (linear * 12.92)
    else
        return (1.055 * zo_pow(zo_abs(linear), 1 / 2.4) - 0.055)
    end
end
    currentGamma = value
    for index, setupData in ipairs(imageData) do
        local image = GetControl(setupData[1])
        local linearAlpha = GammaToLinear(setupData[2])
        local correctedLinear = zo_pow(linearAlpha, 100 / currentGamma)
        local gammaAlpha = LinearToGamma(correctedLinear)
        image:SetColor(1, 1, 1, gammaAlpha)
    end    
end
    slider:SetValue(slider:GetValue() + delta)
end
    return GetCVar("PregameGammaCheckEnabled") == "1"
end