ESO Lua File v100012

ingame/scenes/ingamescenemanager.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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
end
TOPLEVEL_LOCKS_UI_MODE = true
ZO_REMOTE_SCENE_CHANGE_ORIGIN = REMOTE_SCENE_STATE_CHANGE_ORIGIN_INGAME
local ZO_IngameSceneManager = ZO_SceneManager:Subclass()
function ZO_IngameSceneManager:New()
    local manager = ZO_SceneManager.New(self)
    manager.topLevelWindows = {}
    manager.numTopLevelShown = 0
    manager.initialized = false
    manager.hudSceneName = "hud"
    manager.hudUISceneName = "hudui"
    manager.hudUISceneHidesAutomatically = true
    manager.exitUIModeOnChatFocusLost = false
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_NEW_MOVEMENT_IN_UI_MODE, function() manager:OnNewMovementInUIMode() end)
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_GAME_CAMERA_ACTIVATED, function() manager:OnGameCameraActivated() end)
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_GAME_FOCUS_CHANGED, function(_, hasFocus) manager:OnGameFocusChanged(hasFocus) end)
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_ENTER_GROUND_TARGET_MODE, function() manager:OnEnterGroundTargetMode() end)
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_PLAYER_ACTIVATED, function() manager:OnLoadingScreenDropped() end)
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_PLAYER_DEACTIVATED, function() manager:OnLoadingScreenShown() end)
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_GLOBAL_MOUSE_UP, function() manager:OnGlobalMouseUp() end)
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_MOUNTED_STATE_CHANGED, function() manager:OnMountStateChanged() end)
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_DISPLAY_TUTORIAL, function(eventCode, ...) manager:OnTutorialStart(...) end)
    EVENT_MANAGER:RegisterForEvent("IngameSceneManager", EVENT_GAMEPAD_PREFERRED_MODE_CHANGED, function() manager:OnGamepadPreferredModeChanged() end)
    return manager
end
function ZO_IngameSceneManager:IsInUIMode()
    if(IsGameCameraActive()) then
        return IsGameCameraUIModeActive()
    end
    return false
end
function ZO_IngameSceneManager:IsLockedInUIMode()
    if(IsGameCameraActive()) then
        for topLevel, _ in pairs(self.topLevelWindows) do
            if(topLevel.locksUIMode and not topLevel:IsControlHidden()) then
                return true
            end
        end
    end
    return false
end
function ZO_IngameSceneManager:SetInUIMode(inUI)
    if(IsGameCameraActive()) then
        if(inUI ~= self:IsInUIMode()) then
            if(inUI) then
                SetGameCameraUIMode(true)
                self:SetBaseScene(self.hudUISceneName)
                ZO_RadialMenu.ForceActiveMenuClosed()
                DIRECTIONAL_INPUT:Activate(self, GuiRoot)
                return true
            else
                if(not self:IsLockedInUIMode() and DoesGameHaveFocus() and IsSafeForSystemToCaptureMouseCursor()) then
                    self.manuallyEnteredHUDUIMode = nil
                    EndLooting()
                    SetGameCameraUIMode(false)
                    self:HideTopLevels()
                    DIRECTIONAL_INPUT:Deactivate(self)
                    self:SetBaseScene(self.hudSceneName)
                    self:ShowBaseScene()
                    MAIN_MENU_SINGLETON:ForceClearBlockingScenes()
                    return true
                end
            end
        end
    end
    return false
end
function ZO_IngameSceneManager:UpdateDirectionalInput()
    --Consume the sticks when we're in UI mode so they don't leak through into the camera and movement processing.
    DIRECTIONAL_INPUT:Consume(ZO_DI_LEFT_STICK, ZO_DI_RIGHT_STICK)
end
--UI Mode Life Cycle
function ZO_IngameSceneManager:ConsiderExitingUIMode(showingHUDUI)
    if(self.hudUISceneHidesAutomatically and self.numTopLevelShown == 0 and showingHUDUI and DoesGameHaveFocus() and not CHAT_SYSTEM:IsTextEntryOpen()) then
        return self:SetInUIMode(false)
    end
end
function ZO_IngameSceneManager:OnGameFocusChanged()
    if(IsGameCameraActive() and IsPlayerActivated()) then
        if(DoesGameHaveFocus() and IsSafeForSystemToCaptureMouseCursor()) then
            if self.actionRequiredTutorialThatActivatedWithoutFocus then
                self:SetInUIMode(false)
                self.actionRequiredTutorialThatActivatedWithoutFocus = false
                return
            end
            
            local mousedOverControl = WINDOW_MANAGER:GetMouseOverControl()
            if(not mousedOverControl or mousedOverControl == GuiRoot) then
                if(self:IsInUIMode()) then
                    self:ConsiderExitingUIMode(self:IsShowingBaseScene())
                end
            end
        else
            if(not self:IsInUIMode()) then
                self:SetInUIMode(true)
                self:ShowBaseScene()
            end
        end
    end
end
local ONLY_CONSIDER_MOUSE_VISIBILITY_WHILE_MOVING = true
function ZO_IngameSceneManager:OnChatInputStart()
    self.exitUIModeOnChatFocusLost = false
    if GetSetting_Bool(SETTING_TYPE_UI, UI_SETTING_RETURN_CURSOR_ON_CHAT_FOCUS) and IsGameCameraActive() then
        if not self:IsInUIMode() and SCENE_MANAGER:IsShowingBaseScene() then
            self:SetInUIMode(true)
            self:ShowBaseScene()
            HideMouse(ONLY_CONSIDER_MOUSE_VISIBILITY_WHILE_MOVING)
            self:CallWhen(self.hudUISceneName, SCENE_HIDDEN, function()
                if self.exitUIModeOnChatFocusLost then
                    -- something other than ending chat input is making us exit UI mode, just return to the old state and normal UI mode behavior
                    ShowMouse(ONLY_CONSIDER_MOUSE_VISIBILITY_WHILE_MOVING)
                    self.exitUIModeOnChatFocusLost = false
                end
            end)
            self.exitUIModeOnChatFocusLost = true
        end
    end
end
function ZO_IngameSceneManager:OnChatInputEnd()
    if self.exitUIModeOnChatFocusLost then
        self.exitUIModeOnChatFocusLost = false
        ShowMouse(ONLY_CONSIDER_MOUSE_VISIBILITY_WHILE_MOVING)
        self:SafelyAttemptToExitUIMode()
    end
end
function ZO_IngameSceneManager:OnTutorialStart(tutorialIndex)
    --Only HUD Brief tutorial types can have the Action Required flag set true.
    if IsTutorialActionRequired(tutorialIndex) then
        TUTORIAL_SYSTEM:ForceRemoveAll() --Make sure no tutorial is showing before turning off UI mode
        if DoesGameHaveFocus() and IsSafeForSystemToCaptureMouseCursor() then
            self:SetInUIMode(false)
        else
            self.actionRequiredTutorialThatActivatedWithoutFocus = true
        end
    end
end
function ZO_IngameSceneManager:OnGamepadPreferredModeChanged()
    --if a scene was already shown when we change input mode, hide it
    if self.currentScene and not self:IsShowingBaseScene() and self.currentScene:GetState() == SCENE_SHOWN then
        self:SetInUIMode(false)
    end
end
function ZO_IngameSceneManager:SafelyAttemptToExitUIMode()
    if(IsGameCameraActive() and IsPlayerActivated()) then
        if(not self.manuallyEnteredHUDUIMode) then
            local mousedOverControl = WINDOW_MANAGER:GetMouseOverControl()
            if(not mousedOverControl or mousedOverControl == GuiRoot) then
                if(self:IsInUIMode() and IsSafeForSystemToCaptureMouseCursor()) then
                    self:ConsiderExitingUIMode(self:IsShowingBaseScene())
                end
            end
        end
    end
end
function ZO_IngameSceneManager:OnGlobalMouseUp()
    if(not IsConsoleUI()) then
        self:SafelyAttemptToExitUIMode()
    end
end
function ZO_IngameSceneManager:OnEnterGroundTargetMode()
    self:SetInUIMode(false)
end
function ZO_IngameSceneManager:OnMountStateChanged()
    -- The market screen causes a dismount and blocks mounting so we need to ignore this on that screen
    if not (self:IsShowing("market") or self:IsShowing("gamepad_market_preview")) then
        self:SetInUIMode(false)
    end
end
function ZO_IngameSceneManager:OnLoadingScreenDropped()
    self.hudSceneName = "hud"
    self.hudUISceneName = "hudui"
    self.hudUISceneHidesAutomatically = true
    if(IsGameCameraActive()) then
        if(self:IsInUIMode()) then
            if(not self:SetInUIMode(false)) then
                self:SetBaseScene("hudui")
                self:ShowBaseScene()
            end
        else
            self:SetBaseScene("hud")
            self:ShowBaseScene()
        end
    else
        self:SetBaseScene("hudui")
        self:ShowBaseScene()
    end
end
function ZO_IngameSceneManager:OnLoadingScreenShown()
    if(IsGameCameraActive()) then
        self:SetInUIMode(true)
    end
end
function ZO_IngameSceneManager:OnGameCameraActivated()
    if(IsPlayerActivated()) then
        if(self:IsShowing(self.hudSceneName) or self:IsShowingNext(self.hudSceneName)) then
            self:SetInUIMode(false)
        elseif(self:IsInUIMode()) then
        end
        if(not DoesGameHaveFocus()) then
            self:OnGameFocusChanged(false)
        end
    end
end
function ZO_IngameSceneManager:OnPreSceneStateChange(scene, currentState, nextState)
    if(IsGameCameraActive()) then
        if(nextState == SCENE_SHOWING and scene ~= self.baseScene) then
            if(not self:IsInUIMode()) then
                self:SetInUIMode(true)
            end
        end
    end
end
function ZO_IngameSceneManager:OnNextSceneRemovedFromQueue(oldNextScene, newNextScene)
    --if the old next scene was booted out, reconsider if we want to exit UI mode based on what the new next scene is
    ZO_SceneManager.OnNextSceneRemovedFromQueue(self, oldNextScene, newNextScene)
    if(IsGameCameraActive()) then
        if(self.currentScene:GetState() == SCENE_HIDING and newNextScene == self.baseScene) then
            if(self:IsInUIMode()) then
                local SHOWING_HUD_UI = true
                self:ConsiderExitingUIMode(SHOWING_HUD_UI)
            end
        end
    end
end
function ZO_IngameSceneManager:OnSceneStateChange(scene, oldState, newState)
    if(IsGameCameraActive()) then
        if(newState == SCENE_HIDING and self.nextScene == self.baseScene) then
            if(self:IsInUIMode()) then
                local SHOWING_HUD_UI = true
                self:ConsiderExitingUIMode(SHOWING_HUD_UI)
            end
        elseif(newState == SCENE_SHOWING) then
            if(IsGameCameraSiegeControlled()) then
                if(scene:GetName() ~= self.hudSceneName and scene:GetName() ~= self.hudUISceneName) then
                    ReleaseGameCameraSiegeControlled()
                end
            end
        end
    end
    ZO_SceneManager.OnSceneStateChange(self, scene, oldState, newState)
end
function ZO_IngameSceneManager:OnNewMovementInUIMode()
    if not self:IsShowingBaseScene() then
        self:ShowBaseScene()
    else
    end
end
--HUD
function ZO_IngameSceneManager:SetHUDScene(hudSceneName)
   local oldHudScene = self.hudSceneName
   self.hudSceneName = hudSceneName
   if(self:IsShowing(oldHudScene)) then
        self:SetBaseScene(hudSceneName)
        self:Show(hudSceneName)
   end
end
function ZO_IngameSceneManager:RestoreHUDScene()
    self:SetHUDScene("hud")
end
function ZO_IngameSceneManager:SetHUDUIScene(hudUISceneName, hidesAutomatically)
    local oldHUDUIScene = self.hudUISceneName
    self.hudUISceneName = hudUISceneName
    self.hudUISceneHidesAutomatically = hidesAutomatically
    if(self:IsShowing(oldHUDUIScene)) then
        self:SetBaseScene(hudUISceneName)
        self:Show(hudUISceneName)
    end
end
function ZO_IngameSceneManager:RestoreHUDUIScene()
    self:SetHUDUIScene("hudui", true)
end
--Top Levels
function ZO_IngameSceneManager:RegisterTopLevel(topLevel, locksUIMode)
    topLevel.locksUIMode = locksUIMode
    self.topLevelWindows[topLevel] = true
end
function ZO_IngameSceneManager:HideTopLevel(topLevel)
    if(not topLevel:IsControlHidden() and self.topLevelWindows[topLevel] == true) then
        topLevel:SetHidden(true)
        self.numTopLevelShown = self.numTopLevelShown - 1
        if(IsGameCameraActive()) then
        end
    end
end
function ZO_IngameSceneManager:ShowTopLevel(topLevel)
    if(topLevel:IsControlHidden() and self.topLevelWindows[topLevel] == true) then
        topLevel:SetHidden(false)
        self.numTopLevelShown = self.numTopLevelShown + 1
        if(IsGameCameraActive()) then
            if(not self:IsInUIMode()) then
                self:SetInUIMode(true)
                self:ShowBaseScene()
            end
        end
    end    
end
function ZO_IngameSceneManager:ToggleTopLevel(topLevel)
    if(topLevel:IsControlHidden()) then
        self:ShowTopLevel(topLevel)
    else
        self:HideTopLevel(topLevel)
    end
end
local function GetMenuObject()
    return IsInGamepadPreferredMode() and PLAYER_MENU or MAIN_MENU
end
--Alt Key Functions
function ZO_IngameSceneManager:OnToggleUIModeBinding()
    if(IsGameCameraActive()) then
        if(self:IsInUIMode()) then
            self:SetInUIMode(false)
        else
            self:SetInUIMode(true)
            GetMenuObject():ShowLastCategory()
        end
    else
        self:ShowBaseScene()
    end
end
--Escape Key Functions
local function HideSpecialWindow(window)
    if(not window:IsControlHidden()) then
        window:SetHidden(true)
        return true
    end
    
    return false
end
function ZO_IngameSceneManager:HideTopLevels()
    local topLevelHidden = false
    for topLevel, _ in pairs(self.topLevelWindows) do
        if(not topLevel:IsControlHidden()) then
            self:HideTopLevel(topLevel)
            topLevelHidden = true
        end
    end
    return topLevelHidden
end
function ZO_IngameSceneManager:OnToggleGameMenuBinding()
    if SYSTEMS:IsShowing("dyeing") then
        SYSTEMS:GetObject("dyeing"):AttemptExit()
        return
    end
    if not IsInGamepadPreferredMode() and GUILD_RANKS:AttemptSaveIfBlocking() then
        -- The guild ranks scene was the current blocking scene, so we can return early here.
        return
    end
    local SHOW_BASE_SCENE = true
    if GUILD_HERALDRY:AttemptSaveIfBlocking() or GUILD_HERALDRY_GAMEPAD:AttemptSaveIfBlocking(SHOW_BASE_SCENE) then
        return
    end
    if(IsPlayerGroundTargeting()) then
        CancelCast()
        return
    end
    
    if(IsGameCameraSiegeControlled()) then
        return
    end
    if(ZO_Dialogs_IsShowingDialog()) then
        ZO_Dialogs_ReleaseAllDialogs()
        return
    end
        return
    end
    if PopupTooltip and not PopupTooltip:IsControlHidden() then
        ZO_PopupTooltip_Hide()
        return
    end
    if(self:IsShowingBaseScene() and not self:IsInUIMode()) then
        if(GetInteractionType() ~= INTERACTION_NONE) then
            EndInteraction(GetInteractionType())
            return
        end
        if(IsInteractionPending()) then
            EndPendingInteraction()
            return
        end
    end    
    if(self:IsLockedInUIMode()) then
        return
    end
    if(self:IsShowing(self.hudUISceneName) and self.hudUISceneName ~= "hudui") then
        self:RestoreHUDUIScene()
        return
    end
    --Top Levels and Scenes
    local topLevelHidden = self:HideTopLevels()
    local baseSceneShown = false
    if(not self:IsShowingBaseScene()) then
        self:ShowBaseScene()
        baseSceneShown = true
    end
    --System Menu Toggle
    if(not (topLevelHidden or baseSceneShown)) then
        SCENE_MANAGER:Toggle("gameMenuInGame")
    end
end
--Period Key Functionality
function ZO_IngameSceneManager:OnToggleHUDUIBinding()
    if(IsGameCameraActive()) then
        if(self:IsInUIMode()) then
            self:SetInUIMode(false)
        else
            self.manuallyEnteredHUDUIMode = true
            self:Show(self.hudUISceneName)
        end
    end 
end
--Global API
    SCENE_MANAGER:OnToggleUIModeBinding()
end
    SCENE_MANAGER:OnToggleGameMenuBinding()
end
    SCENE_MANAGER:OnToggleHUDUIBinding()
end
SCENE_MANAGER = ZO_IngameSceneManager:New()