ESO Lua File v100015

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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
local PREGAME_EULAS = {
    EULA_TYPE_PREGAME_EULA,
    EULA_TYPE_TERMS_OF_SERVICE,
    EULA_TYPE_PRIVACY_POLICY,
    EULA_TYPE_CODE_OF_CONDUCT,
}
--[[
Fragment Creation
--]]
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()
    ZO_Dialogs_ShowDialog("SHOW_EULA")
    EULA_SCREEN:ShowNextEULA()
    -- 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
local ZO_EULA = ZO_Object:Subclass()
function ZO_EULA:New(control)
    local object = ZO_Object.New(self)
    object:Initialize(control)
    return object    
end
function ZO_EULA:Initialize(control)
    self.control = control
    self.isShowingLinkConfirmation = false
    self.agreeButton = self.control:GetNamedChild("Agree")
    self.scroll = self.control:GetNamedChild("ContainerScroll")
    LINK_HANDLER:RegisterCallback(LINK_HANDLER.LINK_CLICKED_EVENT, function(...) self:OnLinkClicked(...) end)
    CALLBACK_MANAGER:RegisterCallback("AllDialogsHidden", function()
        if self.isShowingLinkConfirmation then
            ZO_Dialogs_ShowDialog("SHOW_EULA")
            self:ShowNextEULA()
            self.isShowingLinkConfirmation = false
        end
    end)
end
function ZO_EULA:OnLinkClicked(link, button, text, color, linkType, ...)
    if ZO_Dialogs_IsShowing("SHOW_EULA") then
        -- Need to release the EULA dialog so that the CONFIRM_OPEN_URL dialog will be shown
        ZO_Dialogs_ReleaseDialog("SHOW_EULA")
        self.isShowingLinkConfirmation = true
        return true
    end
end
function ZO_EULA:GetNextEulaType()
    for k, eulaType in ipairs(PREGAME_EULAS) do
        if not HasAgreedToEULA(eulaType) then
            return eulaType
        end
    end
end
function ZO_EULA:ShowNextEULA()
    self.eulaType = self:GetNextEulaType()
    if self.eulaType then
        local eulaText, agreeText, disagreeText, hasAgreed, eulaTitle = GetEULADetails(self.eulaType)
        if eulaTitle == "" then
            eulaTitle = SI_WINDOW_TITLE_EULA
        end
        ZO_Dialogs_UpdateDialogTitleText(self.control, { text = eulaTitle })
        ZO_Dialogs_UpdateDialogMainText(self.control, { text = eulaText })
        self:SetupButtonTextData(agreeText, disagreeText)
        self:ResetDialog()
    else
        SCENE_MANAGER:Hide("eula")
    end
end
function ZO_EULA:AcceptCurrentEULA()
    AgreeToEULA(self.eulaType)
end
function ZO_EULA:InitializeDialog(dialogControl)
    self.dialogInfo =
    {
        customControl = dialogControl,
        canQueue = true,
        mustChoose = true,
        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)
                                self:AcceptCurrentEULA()
                                self:ShowNextEULA()
                            end,
            },
            [2] =
            {
                control =   GetControl(dialogControl, "Disagree"),
                text =      SI_EULA_BUTTON_DISAGREE,
                callback =  function(dialog)
                                PregameQuit()
                            end,
            }
        }
    }
    ZO_Dialogs_RegisterCustomDialog("SHOW_EULA", self.dialogInfo)
    
    self.control:GetNamedChild("Title"):SetDimensions(870, 32)
    local function OnDocumentScrollChanged(scrollControl, horizontalOffset, verticalOffset)
        self:CheckEnableAgreeButton(verticalOffset)
    end
    self.scroll:SetHandler("OnScrollOffsetChanged", OnDocumentScrollChanged)
end
function ZO_EULA:CheckEnableAgreeButton(verticalOffset)
    if(not self.agreeButton.enabledOnce) then
        if(verticalOffset == nil) then
            local _
            _, verticalOffset = self.scroll:GetScrollOffsets()
        end
        local _, verticalExtent = self.scroll:GetScrollExtents()
        self.agreeButton.enabledOnce = (verticalExtent == 0) or zo_floatsAreEqual(verticalOffset, verticalExtent, 0.01)
        self.agreeButton:SetEnabled(self.agreeButton.enabledOnce)
    end
end
function ZO_EULA:ResetDialog()
    if not self.isShowingLinkConfirmation then
        ZO_Scroll_ResetToTop(self.scroll:GetParent())
    end
    local automaticEnableTime = GetFrameTimeMilliseconds() + 5000
    local function OnUpdate()
        local _, verticalExtent = self.scroll:GetScrollExtents()
        if(verticalExtent ~= 0) then
            self:CheckEnableAgreeButton()
            self.scroll:SetHandler("OnUpdate", nil)
        end
        if(GetFrameTimeMilliseconds() > automaticEnableTime) then
            self.agreeButton:SetEnabled(true)
            self.scroll:SetHandler("OnUpdate", nil)            
        end
    end
    self.agreeButton.enabledOnce = false
    self.agreeButton:SetEnabled(false)
    self.scroll:SetHandler("OnUpdate", OnUpdate)
end
function ZO_EULA:SetupButtonTextData(agreeText, disagreeText)
    self.dialogInfo.buttons[1].text = (#agreeText > 0) and agreeText or SI_EULA_BUTTON_AGREE
    self.dialogInfo.buttons[2].text = (#disagreeText > 0) and disagreeText or SI_EULA_BUTTON_DISAGREE
end
function ZO_EULA:CreateEULAScene(control)
    local eulaScene = ZO_Scene:New("eula", SCENE_MANAGER)
    eulaScene:AddFragment(ZO_EULAFragment:New(control))
end
--[[
Global Functions
--]]
function ZO_EULAInit(control)
    EULA_SCREEN = ZO_EULA:New(control)
end
function ZO_HasAgreedToEULA()
    if GetUIPlatform() ~= UI_PLATFORM_PC then
        return HasAgreedToEULA(EULA_TYPE_PREGAME_EULA)
    else
        -- The PC loads its additional legal documents differently from console
        for k, eulaType in ipairs(PREGAME_EULAS) do
            if not HasAgreedToEULA(eulaType) then
                return false
            end
        end
        return true
    end
end