Back to Home

ESO Lua File v101041

pregame/accountlogin/keyboard/zo_createlinkaccount.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
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
local SETUP_MODE_NONE = 0
local SETUP_MODE_NEW = 1
local SETUP_MODE_LINK = 2
local SETUP_MODE_ACTIVATE = 3
local CreateLinkAccount_Keyboard = ZO_LoginBase_Keyboard:Subclass()
function CreateLinkAccount_Keyboard:New(...)
    return ZO_LoginBase_Keyboard.New(self, ...)
end
function CreateLinkAccount_Keyboard:Initialize(control)
    ZO_LoginBase_Keyboard.Initialize(self, control)
    self.accountSetupContainer = control:GetNamedChild("AccountSetup")
    self.createRadio = self.accountSetupContainer:GetNamedChild("CreateRadio")
    self.activateRadio = self.accountSetupContainer:GetNamedChild("ActivateRadio")
    self.radioGroup = ZO_RadioButtonGroup:New()
    self.radioGroup:Add(self.createRadio)
    self.radioGroup:Add(self.activateRadio)
    -- Create Account controls
    self.newAccountContainer = control:GetNamedChild("NewAccount")
    local newAccountScrollChild = self.newAccountContainer:GetNamedChild("ScrollChild")
    self.accountNameEntry = newAccountScrollChild:GetNamedChild("AccountNameEntry")
    self.accountNameEntryEdit = self.accountNameEntry:GetNamedChild("Edit")
    self.accountNameInstructionsControl = self.newAccountContainer:GetNamedChild("Instructions")
    self.countryLabel = newAccountScrollChild:GetNamedChild("CountryLabel")
    self.countryDropdown = newAccountScrollChild:GetNamedChild("CountryDropdown")
    self.countryDropdownDefaultText = self.countryDropdown:GetNamedChild("DefaultText")
    self.emailLabel = newAccountScrollChild:GetNamedChild("EmailLabel")
    self.emailEntry = newAccountScrollChild:GetNamedChild("EmailEntry")
    self.emailEntryEdit = self.emailEntry:GetNamedChild("Edit")
    self.subscribeCheckbox = newAccountScrollChild:GetNamedChild("Subscribe")
    self.createAccountButton = newAccountScrollChild:GetNamedChild("CreateAccount")
    self.countryComboBox = ZO_ComboBox_ObjectFromContainer(self.countryDropdown)
    self.countryComboBox:SetSortsItems(false)
    self.accountNameEntryEdit:SetMaxInputChars(ACCOUNT_NAME_MAX_LENGTH)
    self.emailEntryEdit:SetMaxInputChars(MAX_EMAIL_LENGTH)
    -- Link Account controls
    self.linkAccountContainer = control:GetNamedChild("LinkAccount")
    self.accountName = self.linkAccountContainer:GetNamedChild("AccountName")
    self.accountNameEdit = self.accountName:GetNamedChild("Edit")
    self.password = self.linkAccountContainer:GetNamedChild("Password")
    self.passwordEdit = self.password:GetNamedChild("Edit")
    self.capsLockWarning = self.linkAccountContainer:GetNamedChild("CapsLockWarning")
    self.linkAccountButton = self.linkAccountContainer:GetNamedChild("LinkAccount")
    -- Activate Account controls
    self.activateAccountContainer = control:GetNamedChild("ActivateAccount")
    self.activateAccountInstructionsLabel = self.activateAccountContainer:GetNamedChild("Instructions")
    self.activateAccountCodeLabel = self.activateAccountContainer:GetNamedChild("Code")
    local activationURLText = GetURLTextByType(APPROVED_URL_ESO_ACCOUNT_LINKING)
    local activationLink = ZO_URL_LINK_COLOR:Colorize(ZO_LinkHandler_CreateURLLink(activationURLText, activationURLText))
    self.activateAccountInstructionsLabel:SetText(zo_strformat(SI_LINKACCOUNT_ACTIVATION_MESSAGE, activationLink))
    self.mode = SETUP_MODE_NONE
    EVENT_MANAGER:RegisterForEvent("CreateLinkAccount", EVENT_SCREEN_RESIZED, function() self:ResizeControls() end)
    local function UpdateForCaps(capsLockIsOn)
        self.capsLockWarning:SetHidden(not capsLockIsOn)
    end
    self.capsLockWarning:RegisterForEvent(EVENT_CAPS_LOCK_STATE_CHANGED, function(eventCode, capsLockIsOn) UpdateForCaps(capsLockIsOn) end)
    
    self.capsLockWarning:SetHidden(not IsCapsLockOn())
    CREATE_LINK_ACCOUNT_FRAGMENT = ZO_FadeSceneFragment:New(control)
    CREATE_LINK_ACCOUNT_FRAGMENT:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_FRAGMENT_SHOWING then
            if IsUsingLinkedLogin() then
                self:PopulateCountryDropdown()
            end
            if self.mode == SETUP_MODE_ACTIVATE then
                LOGIN_MANAGER_KEYBOARD:RequestAccountActivationCode()
            end
        end
    end)
     local function OnActivationCodeReceived(eventId, activationCode)
        self.activationCode = activationCode
        local DELIMITER = " "
        local SEGMENT_LENGTH = 4
        local formattedCode = ZO_GenerateDelimiterSegmentedString(activationCode, SEGMENT_LENGTH, DELIMITER)
        self.activateAccountCodeLabel:SetText(formattedCode)
        if CREATE_LINK_ACCOUNT_FRAGMENT:IsShowing() then
            RegisterForLinkAccountActivationProgress()
        end
    end
    self.control:RegisterForEvent(EVENT_ACCOUNT_LINK_ACTIVATION_CODE_RECEIVED, OnActivationCodeReceived)
end
function CreateLinkAccount_Keyboard:GetControl()
    return self.control
end
function CreateLinkAccount_Keyboard:PopulateCountryDropdown()
    if not self.hasPopulatedCountryDropdown then
        local numCountries = GetNumCountries()
        for i = 1, numCountries do
            local countryName, countryCode, _, isAllowedInAccountCreation, autoEmailSubscribe = GetCountryDataForIndex(i)
            if isAllowedInAccountCreation then
                local entry = self.countryComboBox:CreateItemEntry(countryName, function(...) self:OnCountrySelected(...) end)
                entry.countryName = countryName
                entry.countryCode = countryCode
                entry.autoEmailSubscribe = autoEmailSubscribe
                self.countryComboBox:AddItem(entry, ZO_COMBOBOX_SUPPRESS_UPDATE)
            end
        end
        if numCountries == 1 then
            -- If there's only one choice, select that country immediately and disable the dropdown
            self.countryComboBox:SelectItemByIndex(1)
            self:HideCountryDropdown()
        end
        self.countryComboBox:UpdateItems()
        self.hasPopulatedCountryDropdown = true
    end
end
function CreateLinkAccount_Keyboard:OnCountrySelected(comboBox, entryText, entry)
    self.selectedCountry = entry
    self.countryDropdownDefaultText:SetHidden(true)
end
function CreateLinkAccount_Keyboard:SetRadioFromMode(mode)
    if mode ~= self.mode then
        if mode == SETUP_MODE_NEW then
            self.radioGroup:SetClickedButton(self.createRadio)
        elseif mode == SETUP_MODE_ACTIVATE then
            self.radioGroup:SetClickedButton(self.activateRadio)
        end
    end
end
function CreateLinkAccount_Keyboard:ChangeMode(newMode)
    self.mode = newMode
    if self.mode == SETUP_MODE_ACTIVATE then
        LOGIN_MANAGER_KEYBOARD:RequestAccountActivationCode()
    end
    self.newAccountContainer:SetHidden(newMode ~= SETUP_MODE_NEW)
    self.activateAccountContainer:SetHidden(newMode ~= SETUP_MODE_ACTIVATE)
end
function CreateLinkAccount_Keyboard:IsRequestedAccountNameValid()
    return self.accountNameValid
end
function CreateLinkAccount_Keyboard:CanCreateAccount()
    return self.emailEntryEdit:GetText() ~= "" and self.selectedCountry ~= nil and self:IsRequestedAccountNameValid()
end
function CreateLinkAccount_Keyboard:CanLinkAccount()
    return self.accountNameEdit:GetText() ~= "" and self.passwordEdit:GetText() ~= ""
end
function CreateLinkAccount_Keyboard:AttemptCreateAccount()
    if self:CanCreateAccount() then
        local email = self.emailEntryEdit:GetText()
        -- Auto subscribe never sees an option
        local emailSignup = self.selectedCountry.autoEmailSubscribe or ZO_CheckButton_IsChecked(self.subscribeCheckbox)
        local country = self.selectedCountry.countryCode
        local requestedAccountName = self.accountNameEntryEdit:GetText()
        LOGIN_MANAGER_KEYBOARD:AttemptCreateAccount(email, emailSignup, country, requestedAccountName)
    end
end
function CreateLinkAccount_Keyboard:AttemptLinkAccount()
    if self:CanLinkAccount() then
        local dialogData = { 
                                partnerAccount = GetExternalName(),
                                esoAccount = self.accountNameEdit:GetText(),
                                password = self.passwordEdit:GetText(),
                           }
        ZO_Dialogs_ShowDialog("LINK_ACCOUNT_KEYBOARD", dialogData)
    end
end
function CreateLinkAccount_Keyboard:UpdateCreateAccountButton()
    self.createAccountButton:SetEnabled(self:CanCreateAccount())
end
function CreateLinkAccount_Keyboard:UpdateLinkAccountButton()
    self.linkAccountButton:SetEnabled(self:CanLinkAccount())
end
function CreateLinkAccount_Keyboard:GetAccountNameEdit()
    return self.accountNameEdit
end
function CreateLinkAccount_Keyboard:GetPasswordEdit()
    return self.passwordEdit
end
function CreateLinkAccount_Keyboard:GetAccountNameEntryEdit()
    return self.accountNameEntryEdit
end
function CreateLinkAccount_Keyboard:GetEmailEntryEdit()
    return self.emailEntryEdit
end
function CreateLinkAccount_Keyboard:RefreshCheckboxHiddenStates()
    local platformDisablesSubscription = not DoesPlatformAllowForEmailSubscription()
    local noRegionOrAutoSubscription = not self.selectedCountry or self.selectedCountry.autoEmailSubscribe
    local subscriptionShouldBeHidden = platformDisablesSubscription or noRegionOrAutoSubscription
    if subscriptionShouldBeHidden ~= self.subscribeCheckbox:IsControlHidden() then
        if subscriptionShouldBeHidden then
            -- Email subscription isn't allowed, so remove the checkbox
            ZO_CheckButton_SetUnchecked(self.subscribeCheckbox)
            self:HideEmailSubscriptionCheckbox()
        else
            self:ShowEmailSubscriptionCheckbox()
        end
    end
end
function CreateLinkAccount_Keyboard:ShowEmailSubscriptionCheckbox()
    -- Show the email subscription checkbox, and reanchor the Create Account button
    self.subscribeCheckbox:SetHidden(false)
    -- use the Create Account button's current anchors, but use the subscribe checkbox as the relative point
    local _, point, _, relPoint, offsetX, offsetY = self.createAccountButton:GetAnchor(0)
    self.createAccountButton:ClearAnchors()
    self.createAccountButton:SetAnchor(point, self.subscribeCheckbox, relPoint, offsetX, offsetY)
end
function CreateLinkAccount_Keyboard:HideEmailSubscriptionCheckbox()
    -- Hide the email subscription checkbox, and reanchor the Create Account button
    self.subscribeCheckbox:SetHidden(true)
    -- use the Create Account button's current anchors, but use the subscribe checkbox's relative point
    local _, _, relTo = self.subscribeCheckbox:GetAnchor(0)
    local _, point, _, relPoint, offsetX, offsetY = self.createAccountButton:GetAnchor(0)
    self.createAccountButton:ClearAnchors()
    self.createAccountButton:SetAnchor(point, relTo, relPoint, offsetX, offsetY)
end
function CreateLinkAccount_Keyboard:HideCountryDropdown()
    -- Hide the country dropdown and transfer its anchors to the email entry field
    self.countryLabel:SetHidden(true)
    self.countryDropdown:SetHidden(true)
    local isValid, point, relTo, relPoint, offsetX, offsetY = self.countryLabel:GetAnchor(0)
    self.emailLabel:ClearAnchors()
    self.emailLabel:SetAnchor(point, relTo, relPoint, offsetX, offsetY)
end
function CreateLinkAccount_Keyboard:SetupAccountNameInstructions()
    if not self.accountNameInstructions then
        local ACCOUNT_NAME_INSTRUCTIONS_OFFSET_X = 15
        local ACCOUNT_NAME_INSTRUCTIONS_OFFSET_Y = 0
        self.accountNameInstructions = ZO_ValidAccountNameInstructions:New(self.accountNameInstructionsControl)
        self.accountNameInstructions:SetPreferredAnchor(LEFT, self.accountNameEntryEdit, RIGHT, ACCOUNT_NAME_INSTRUCTIONS_OFFSET_X, ACCOUNT_NAME_INSTRUCTIONS_OFFSET_Y)
    end
end
function CreateLinkAccount_Keyboard:ValidateAccountName()
    local requestedAccountName = self.accountNameEntryEdit:GetText()
    local accountNameViolations = { IsValidAccountName(requestedAccountName) }
    
    self.accountNameValid = #accountNameViolations == 0
    if self.accountNameValid then
    else
        self.accountNameInstructions:Show(self.accountNameEntryEdit, accountNameViolations)
    end
end
function CreateLinkAccount_Keyboard:HideAccountNameInstructions()
    self.accountNameInstructions:Hide()
end
function CreateLinkAccount_Keyboard:CopyActivationCodeToClipboard()
    if self.activationCode then
        CopyToClipboard(self.activationCode)
    end
end
-- XML Handlers --
    CREATE_LINK_ACCOUNT_KEYBOARD = CreateLinkAccount_Keyboard:New(control)
end
    CREATE_LINK_ACCOUNT_KEYBOARD:ChangeMode(SETUP_MODE_NEW)
end
    CREATE_LINK_ACCOUNT_KEYBOARD:SetRadioFromMode(SETUP_MODE_NEW)
end
    CREATE_LINK_ACCOUNT_KEYBOARD:ChangeMode(SETUP_MODE_ACTIVATE)
end
    CREATE_LINK_ACCOUNT_KEYBOARD:SetRadioFromMode(SETUP_MODE_ACTIVATE)
end
    CREATE_LINK_ACCOUNT_KEYBOARD:AttemptCreateAccount()
end
    CREATE_LINK_ACCOUNT_KEYBOARD:AttemptLinkAccount()
end
    CREATE_LINK_ACCOUNT_KEYBOARD:GetPasswordEdit():TakeFocus()
end
    CREATE_LINK_ACCOUNT_KEYBOARD:GetAccountNameEdit():TakeFocus()
end
    CREATE_LINK_ACCOUNT_KEYBOARD:GetAccountNameEntryEdit():TakeFocus()
end
    CREATE_LINK_ACCOUNT_KEYBOARD:GetEmailEntryEdit():TakeFocus()
end
    CREATE_LINK_ACCOUNT_KEYBOARD:UpdateCreateAccountButton()
end
    CREATE_LINK_ACCOUNT_KEYBOARD:UpdateLinkAccountButton()
end
    -- Assumes that the check button is the parent of the label
    local checkButton = labelControl:GetParent()
    ZO_CheckButton_SetCheckState(checkButton, not ZO_CheckButton_IsChecked(checkButton))
    CREATE_LINK_ACCOUNT_KEYBOARD:UpdateCreateAccountButton()
end
    CREATE_LINK_ACCOUNT_KEYBOARD:ValidateAccountName()
end
    CREATE_LINK_ACCOUNT_KEYBOARD:HideAccountNameInstructions()
end
    InitializeTooltip(InformationTooltip, control, LEFT, 0, 0, RIGHT)
    SetTooltipText(InformationTooltip, GetString(SI_KEYBOARD_LINKACCOUNT_ACTIVATION_COPY_ACTIVATION_CODE_TOOLTIP))
end
    ClearTooltip(InformationTooltip)
end
    CREATE_LINK_ACCOUNT_KEYBOARD:CopyActivationCodeToClipboard()
end