Back to Home

ESO Lua File v101038

pregame/accountlogin/gamepad/linkaccountscreen_gamepad.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
local LinkAccount_Gamepad = ZO_InitializingObject:Subclass()
function LinkAccount_Gamepad:Initialize(control)
    self.control = control
    local fragment = ZO_FadeSceneFragment:New(self.control)
    LINK_ACCOUNT_ACTIVATION_SCENE = ZO_Scene:New("LinkAccount_Activation_Gamepad", SCENE_MANAGER)
    LINK_ACCOUNT_ACTIVATION_SCENE:AddFragment(fragment)
    LINK_ACCOUNT_ACTIVATION_SCENE:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_SHOWING then
            self:PerformDeferredInitialize()
            RequestLinkAccountActivationCode()
            KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
            KEYBIND_STRIP:RemoveDefaultExit()
        elseif newState == SCENE_HIDDEN then
            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
            KEYBIND_STRIP:RestoreDefaultExit()
        end
    end)
end
function LinkAccount_Gamepad:PerformDeferredInitialize()
    if self.initialized then
        return
    end
    self.initialized = true
    local function OnActivationCodeReceived(eventId, activationCode)
        self.activationCode = activationCode
        local DELIMITER = " "
        local SEGMENT_LENGTH = 4
        local formattedCode = ZO_GenerateDelimiterSegmentedString(activationCode, SEGMENT_LENGTH, DELIMITER)
        self.codeLabel:SetText(formattedCode)
        if LINK_ACCOUNT_ACTIVATION_SCENE:IsShowing() then
            RegisterForLinkAccountActivationProgress()
        end
    end
    self.control:RegisterForEvent(EVENT_ACCOUNT_LINK_ACTIVATION_CODE_RECEIVED, OnActivationCodeReceived)
    local function OnAccountLinkSuccessful()
        if LINK_ACCOUNT_ACTIVATION_SCENE:IsShowing() then
            PregameStateManager_AdvanceState()
        end
    end
    self.control:RegisterForEvent(EVENT_ACCOUNT_LINK_SUCCESSFUL, OnAccountLinkSuccessful)
    local function OnCreateLinkLoadingError(eventId, loginError, linkingError, debugInfo)
        if not LINK_ACCOUNT_ACTIVATION_SCENE:IsShowing() or linkingError == ACCOUNT_CREATE_LINK_ERROR_NO_ERROR then
            return
        end
        -- TODO Account Linking are there more errors we need to handle?
        local formattedErrorString
        if linkingError == ACCOUNT_CREATE_LINK_ERROR_EXTERNAL_REFERENCE_ALREADY_USED or linkingError == ACCOUNT_CREATE_LINK_ERROR_USER_ALREADY_LINKED then
            local serviceType = GetPlatformServiceType()
            local accountTypeName = GetString("SI_PLATFORMSERVICETYPE", serviceType)
            formattedErrorString = zo_strformat(SI_LINKACCOUNT_ALREADY_LINKED_ERROR_FORMAT, accountTypeName)
        else
            local linkErrorString = GetString("SI_ACCOUNTCREATELINKERROR", linkingError)
            formattedErrorString = zo_strformat(linkErrorString, GetURLTextByType(APPROVED_URL_ESO_HELP))
        end
        -- debugInfo will be empty in public, non-debug builds
        local message = formattedErrorString .. debugInfo
        self:ShowError(message)
    end
    self.control:RegisterForEvent(EVENT_CREATE_LINK_LOADING_ERROR, OnCreateLinkLoadingError)
end
function LinkAccount_Gamepad:InitializeControls()
    local contentsContainer = self.control:GetNamedChild("ContainerContent")
    self.textControl = contentsContainer:GetNamedChild("Text")
    self.codeLabel = contentsContainer:GetNamedChild("Code")
    local activationURL = ZO_SELECTED_TEXT:Colorize(GetURLTextByType(APPROVED_URL_ESO_ACCOUNT_LINKING))
    self.textControl:SetText(zo_strformat(SI_LINKACCOUNT_ACTIVATION_MESSAGE, activationURL))
end
function LinkAccount_Gamepad:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Copy Code
        {
            name = GetString(SI_LINKACCOUNT_ACTIVATION_COPY_CODE_KEYBIND),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                if self.activationCode then
                    CopyToClipboard(self.activationCode)
                end
            end,
            visible = function()
                return not IsConsoleUI()
            end,
        },
        -- Back
        KEYBIND_STRIP:GenerateGamepadBackButtonDescriptor(function()
            PregameStateManager_SetState("CreateLinkAccount")
            PlaySound(SOUNDS.NEGATIVE_CLICK)
        end)
    }
end
function LinkAccount_Gamepad:InitializeErrorDialog()
    ZO_Dialogs_RegisterCustomDialog("GAMEPAD_LINK_ACCOUNT_ERROR_DIALOG_2", -- TODO Account Linking remove the _2
    {
        gamepadInfo =
        {
            dialogType = GAMEPAD_DIALOGS.BASIC,
        },
        title =
        {
            text = SI_LINKACCOUNT_ERROR_HEADER,
        },
        mainText = 
        {
            text = function(dialog)
                return dialog.data.errorString
            end,
        },
        buttons =
        {
            {
                keybind = "DIALOG_NEGATIVE",
                text = SI_DIALOG_EXIT,
            },
        }
    })
end
function LinkAccount_Gamepad:ShowError(message)
    local dialogData = { errorString = message}
    ZO_Dialogs_ShowGamepadDialog("GAMEPAD_LINK_ACCOUNT_ERROR_DIALOG_2", dialogData)
end
-- XML Handlers --
    LINK_ACCOUNT_GAMEPAD_2 = LinkAccount_Gamepad:New(self) -- TODO Account Linking remove the _2
end