ESO Lua File v100010

pregame/console/emergencyscreen/pregameinitialscreen_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
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
local PregameInitialScreen_Console = ZO_Object:Subclass()
local ESO_FADE_IN = "eso_fade_in"
local ESO_FADE_OUT = "eso_fade_out"
local ESO_SHOW_TIME = 1500 --ms
local ESO_DELAY_TIME = 1000 --ms
local OUROBOROS_FADE_IN = "ouroboros_fade_in"
local OUROBOROS_WAIT_FOR_BUTTON = "ouroboros_wait_for_button"
local OUROBOROS_FADING_OUT = "ouroboros_fading_out"
local STARTUP_BUTTONS = 
{
    "UI_SHORTCUT_PRIMARY",
    "UI_SHORTCUT_SECONDARY",
    "UI_SHORTCUT_TERTIARY",
    "UI_SHORTCUT_NEGATIVE",
    "UI_SHORTCUT_RIGHT_SHOULDER",
    "UI_SHORTCUT_LEFT_SHOULDER",
    "UI_SHORTCUT_RIGHT_TRIGGER",
    "UI_SHORTCUT_LEFT_TRIGGER",
    "UI_SHORTCUT_RIGHT_STICK",
    "UI_SHORTCUT_LEFT_STICK",
    "UI_SHORTCUT_START",
    "UI_SHORTCUT_BACK",
}
local function AddStartupButtons()
    for i, button in ipairs(STARTUP_BUTTONS) do
        AddStartupButtonFromAction(button)
    end
end
 
function PregameInitialScreen_Console:New(control)
    local object = ZO_Object.New(self)
    object:Initialize(control)
    return object
end
function PregameInitialScreen_Console:Initialize(control)
    self.control = control
    self.playAnimations = true
    local pregameInitialScreen_Console_Fragment = ZO_FadeSceneFragment:New(control)
    PREGAME_INITIAL_SCREEN_CONSOLE_SCENE = ZO_Scene:New("PregameInitialScreen_Gamepad", SCENE_MANAGER)
    PREGAME_INITIAL_SCREEN_CONSOLE_SCENE:AddFragment(pregameInitialScreen_Console_Fragment)
    PREGAME_INITIAL_SCREEN_CONSOLE_SCENE:RegisterCallback("StateChange", function(oldState, newState)
                        if newState == SCENE_SHOWING then
                            self:PerformDeferredInitialization()
                            KEYBIND_STRIP:RemoveDefaultExit()
                            KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor)
                        elseif newState == SCENE_SHOWN then
                            UnlockGamepads()
                            DisableShareFeatures()
                            if self.playAnimations then
                                self.fadeMode = ESO_FADE_IN
                                zo_callLater(function() self.esoLogoAnimation:PlayFromStart() end, ESO_DELAY_TIME)
                                self.playAnimations = false
                            else
                                self.fadeMode = OUROBOROS_FADE_IN
                                self.ouroborosAnimation:PlayInstantlyToEnd()
                            end
                        elseif newState == SCENE_HIDDEN then
                            self:ClearError()
                            KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor)
                            KEYBIND_STRIP:RestoreDefaultExit()
                        end
                    end)
    --Register the four face buttons as buttons to be considered as the first button pressed
    --to lock in the controller as the playable controller
     local function HandleKeybindingsLoaded(eventCode, ...)
        AddStartupButtons()
        EVENT_MANAGER:UnregisterForEvent(EVENT_KEYBINDINGS_LOADED)
        end
        EVENT_MANAGER:RegisterForEvent("PregameInitialScreen", EVENT_KEYBINDINGS_LOADED, HandleKeybindingsLoaded)
end
function PregameInitialScreen_Console:PerformDeferredInitialization()
    if self.initialized then return end
    self.initialized = true
    self.errorBox = self.control:GetNamedChild("ErrorBox")
    local errorBoxCenterer = self.errorBox:GetNamedChild("Centerer")
    self.errorIcon = errorBoxCenterer:GetNamedChild("Icon")
    self.errorTitle = errorBoxCenterer:GetNamedChild("ErrorTitle")
    self.errorMessage = errorBoxCenterer:GetNamedChild("ErrorMessage")
    local ouroboros = self.control:GetNamedChild("Ouroboros")
    local pressText = self.control:GetNamedChild("PressText")
    local esoLogo = self.control:GetNamedChild("Logo")
    self.ouroborosAnimation = GetAnimationManager():CreateTimelineFromVirtual("ZO_PregameInitialScreen_FadeAnimation", ouroboros)
    self.pressTextAnimation = GetAnimationManager():CreateTimelineFromVirtual("ZO_PregameInitialScreen_FadeAnimation", pressText)
    self.esoLogoAnimation = GetAnimationManager():CreateTimelineFromVirtual("ZO_PregameInitialScreen_FadeAnimation", esoLogo)
    self.esoLogoAnimation:SetHandler("OnStop", function()
                                    if self.fadeMode == ESO_FADE_OUT then
                                        self.fadeMode = OUROBOROS_FADE_IN
                                        self.ouroborosAnimation:PlayFromStart()
                                    elseif self.fadeMode == ESO_FADE_IN then
                                        self.fadeMode = ESO_FADE_OUT
                                        zo_callLater(function() self.esoLogoAnimation:PlayFromEnd() end, ESO_SHOW_TIME)
                                    end
                                end)
    self.ouroborosAnimation:SetHandler("OnStop", function()
                                    if self.fadeMode == OUROBOROS_FADE_IN then
                                        self.fadeMode = OUROBOROS_WAIT_FOR_BUTTON
                                        self.pressTextAnimation:PlayFromStart()
                                        self.pressAnyPromptFadingIn = true
                                    elseif self.fadeMode == OUROBOROS_FADING_OUT then
                                        PregameStateManager_AdvanceState()
                                    end
                                end)
    self.pressTextAnimation:SetHandler("OnStop", function()
                                                    if(self.pressAnyPromptFadingIn) then
                                                        self.continueAllowed = true
                                                        self.pressAnyPromptFadingIn = false
                                                    end
                                                end)
    self.keybindStripDescriptor = {}
    self:SetupStartupButtons(self.keybindStripDescriptor)
    local function ProfileLoginResult(eventCode, isSuccess, profileError)
        if isSuccess == true then
            self:OnProfileLoginSuccess()
        else
            self:RefreshScreen()
        end
    end
    
    if(IsConsoleUI()) then
        EVENT_MANAGER:RegisterForEvent("PregameInitialScreen", EVENT_PROFILE_LOGIN_RESULT, ProfileLoginResult)
    end
end
function PregameInitialScreen_Console:SetupStartupButtons(keybindStripDescriptor)
    for i, button in ipairs(STARTUP_BUTTONS) do
        descriptor = 
        {
            keybind = button,
            callback = function() self:ContinueFunction() end,
            ethereal = true,
        }
        table.insert(keybindStripDescriptor, descriptor)
    end
end
function PregameInitialScreen_Console:OnProfileLoginSuccess()
    -- Show the login options dialog if that was requested
    if(GetCVar("ShowLoginSettings") == "1") then
        ZO_Dialogs_ShowDialog("LOGIN_SETTINGS")
    else
        --Set the platform to the last logged in platform.
        local lastPlat = GetCVar("LastPlatform")
        if lastPlat ~= nil then
            for platformIndex = 1, GetNumPlatforms() do
                local platformName = GetPlatformInfo(platformIndex)
            
                if platformName == lastPlat then
                    SetSelectedPlatform(platformIndex)
                end
            end
        end
        self:FinishUp()
    end
    SetCVar("ShowLoginSettings", "0")
end
function PregameInitialScreen_Console:ContinueFunction()
    if(self.continueAllowed) then
        --remove keybindings and message to prevent spamming
        self.pressTextAnimation:PlayFromEnd()
        if(IsConsoleUI() and GetUIPlatform() ~= UI_PLATFORM_PC) then
            PregameSelectProfile()
        else
            self:OnProfileLoginSuccess()
        end
        self.continueAllowed = false
    end
end
function PregameInitialScreen_Console:FinishUp()
    if self.fadeMode == OUROBOROS_WAIT_FOR_BUTTON then
        self.fadeMode = OUROBOROS_FADING_OUT
        PlaySound(SOUNDS.CONSOLE_GAME_ENTER)
        self:Hide()
    end
end
function PregameInitialScreen_Console:RefreshScreen()
    self.pressTextAnimation:PlayFromStart()
    self.pressAnyPromptFadingIn = true
     UnlockGamepads()
end
function PregameInitialScreen_Console:Hide()
    self.esoLogoAnimation:PlayInstantlyToStart()
    self.ouroborosAnimation:PlayFromEnd()
end
function PregameInitialScreen_Console:ClearError()
    self.errorBox:SetHidden(true)
end
function PregameInitialScreen_Console:ShowError(icon, errorTitle, errorMessage)
    self:RefreshScreen()
    self.errorIcon:SetTexture(icon)
    self.errorTitle:SetText(errorTitle)
    self.errorMessage:SetText(errorMessage)
    self.errorBox:SetHidden(false)
    PregameStateManager_SetState("AccountLogin")
end
    PREGAME_INITIAL_SCREEN_CONSOLE = PregameInitialScreen_Console:New(self)
end