ESO Lua File v100010

pregame/accountlogin/eula.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
local g_dialogInfo
local function EULADialogInitialize(dialogControl, eulaText)
    g_dialogInfo =
    {
        customControl = dialogControl,
        mainText = {
            text = eulaText
        },
        mustChoose = true,
        title =
        {
            text = SI_WINDOW_TITLE_EULA,
        },
        buttons =
        {
            [1] =
            {
                control = GetControl(dialogControl, "Agree"),
                text = SI_EULA_BUTTON_AGREE,
                noReleaseOnClick = true, -- Don't release because the scene needs to fade out, will release later
                callback =  function(dialog)
                                AgreeToEULA()
                                SCENE_MANAGER:Hide("eula")
                            end,
            },
        
            [2] =
            {
                control =   GetControl(dialogControl, "Disagree"),
                text =      SI_EULA_BUTTON_DISAGREE,
                callback =  function(dialog)
                                PregameQuit()
                            end,
            }
        }
    }
    ZO_Dialogs_RegisterCustomDialog("SHOW_EULA", g_dialogInfo)
end
local function CheckEnableAgreeButton(agreeButton, scroll, verticalOffset)
    if(not agreeButton.enabledOnce) then
        if(verticalOffset == nil) then
            local _
            _, verticalOffset = scroll:GetScrollOffsets()
        end
        local _, verticalExtent = scroll:GetScrollExtents()
        agreeButton.enabledOnce = (verticalExtent == 0) or zo_floatsAreEqual(verticalOffset, verticalExtent, 0.01)
        agreeButton:SetEnabled(agreeButton.enabledOnce)
    end
end
local function DoInitialUpdate(agreeButton, scroll)
    local automaticEnableTime = GetFrameTimeMilliseconds() + 5000
    local function OnUpdate()
        local _, verticalExtent = scroll:GetScrollExtents()
        if(verticalExtent ~= 0) then
            CheckEnableAgreeButton(agreeButton, scroll)
            scroll:SetHandler("OnUpdate", nil)
        end
        if(GetFrameTimeMilliseconds() > automaticEnableTime) then
            agreeButton:SetEnabled(true)
            scroll:SetHandler("OnUpdate", nil)            
        end
    end
    agreeButton.enabledOnce = false
    agreeButton:SetEnabled(false)
    scroll:SetHandler("OnUpdate", OnUpdate)
end
--[[
Fragment Creation
--]]
do
    local ZO_EULAFragment = ZO_FadeSceneFragment:Subclass()
    function ZO_EULAFragment:New(control)
        local fragment = ZO_FadeSceneFragment.New(self, control, 1500)
        fragment.dialog = control
        return fragment
    end
    function ZO_EULAFragment:Show()
        local dialog = self.dialog
        ZO_Dialogs_ShowDialog("SHOW_EULA")
        dialog:GetNamedChild("ModalUnderlay"):SetColor(0, 0, 0, 1)
        DoInitialUpdate(GetControl(dialog, "Agree"), GetControl(dialog, "ContainerScroll"))
        -- Call base class for animations after everything has been tweaked
        ZO_FadeSceneFragment.Show(self)
    end
    function ZO_EULAFragment:OnHidden()
        ZO_FadeSceneFragment.OnHidden(self)
        ZO_Dialogs_ReleaseDialog("SHOW_EULA")
    end
    CreateEULAScene = function(control)
        local eulaScene = ZO_Scene:New("eula", SCENE_MANAGER)
        eulaScene:AddFragment(ZO_EULAFragment:New(control))
    end
end
local function SetupButtonTextData(agreeText, disagreeText)
    g_dialogInfo.buttons[1].text = (#agreeText > 0) and agreeText or SI_EULA_BUTTON_AGREE
    g_dialogInfo.buttons[2].text = (#disagreeText > 0) and disagreeText or SI_EULA_BUTTON_DISAGREE
end
--[[
Global Functions
--]]
function ZO_EULAInit(self)
    local eulaText, agreeText, disagreeText, hasAgreed = GetEULADetails(EULA_TYPE_PREGAME_EULA)
    if(not hasAgreed) then
        local eulaDialog = self
        EULADialogInitialize(eulaDialog, eulaText)
        SetupButtonTextData(agreeText, disagreeText)
        eulaDialog:GetNamedChild("Title"):SetDimensions(870, 32)
                
        local function OnDocumentScrollChanged(self, horizontalOffset, verticalOffset)
            CheckEnableAgreeButton(eulaDialog:GetNamedChild("Agree"), self, verticalOffset)
        end
        local scroll = eulaDialog:GetNamedChild("ContainerScroll")
        scroll:SetHandler("OnScrollOffsetChanged", OnDocumentScrollChanged)
        CreateEULAScene(eulaDialog)
    else
        AgreeToEULA() -- cleanup
    end
end
function ZO_HasAgreedToEULA()
    return HasAgreedToEULA(EULA_TYPE_PREGAME_EULA)
end