Back to Home

ESO Lua File v101042

ingame/help/help_manager.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
local ZO_Help_Manager = ZO_InitializingCallbackObject:Subclass()
function ZO_Help_Manager:Initialize(...)
    self.overlayScenes = {}
    self.searchString = ""
    self.searchResults = {}
    EVENT_MANAGER:RegisterForEvent("Help_Manager", EVENT_HELP_SEARCH_RESULTS_READY, function() self:OnSearchResultsReady() end)
    EVENT_MANAGER:RegisterForEvent("Help_Manager", EVENT_GAMEPAD_PREFERRED_MODE_CHANGED, function() self:OnGamepadPreferredModeChanged() end)
    EVENT_MANAGER:RegisterForEvent("Help_Manager", EVENT_TOGGLE_HELP, function() self:ToggleHelp() end)
    local function OnShowSpecificPage(_, helpCategoryIndex, helpIndex)
        -- If we ever want to use this mechanism to show the overlay version we can, but right now there's no use case
        -- so that can be a future change if we decide we need it
        if IsInGamepadPreferredMode() then
            -- ideally we would do a push here, but that is currently not playing
            -- well with opening help from the Crown Store
            -- specifically: attempting to gift from the furniture browser with gifting locked
            HELP_TUTORIALS_ENTRIES_GAMEPAD:Show(helpCategoryIndex, helpIndex)
        else
            HELP:ShowSpecificHelp(helpCategoryIndex, helpIndex)
        end
    end
    EVENT_MANAGER:RegisterForEvent("Help_Manager", EVENT_SHOW_SPECIFIC_HELP_PAGE, OnShowSpecificPage)
    local function OnInterceptCloseAction()
        SCENE_MANAGER:RemoveFragmentGroup(HELP_TUTORIALS_OVERLAY_KEYBOARD_FRAGMENT_GROUP)
        local HANDLED = true
        return HANDLED
    end
    self.overlaySyncObject = GetOrCreateSynchronizingObject("helpOverlay")
    self.overlaySyncObject:SetHandler("OnShown", function()
        local NO_ARG = nil
        -- We want HelpOverlay to get dibs on intercepting the close button before other systems (e.g.: Tribute conceding)
        local PRIORITY = 1
        CLOSE_ACTIONS_INTERCEPT_LAYER_FRAGMENT:RegisterCallback("InterceptCloseAction", OnInterceptCloseAction, NO_ARG, PRIORITY)
    end, "Help_Manager")
    
    self.overlaySyncObject:SetHandler("OnHidden", function()
        CLOSE_ACTIONS_INTERCEPT_LAYER_FRAGMENT:UnregisterCallback("InterceptCloseAction", OnInterceptCloseAction)
    end, "Help_Manager")
    EVENT_MANAGER:RegisterForEvent("Help_Manager", EVENT_GUI_UNLOADING, function()
        while self.overlaySyncObject:IsShown() do
            self.overlaySyncObject:Hide()
        end
    end)
end
function ZO_Help_Manager:OnSearchResultsReady()
    ZO_ClearNumericallyIndexedTable(self.searchResults)
    local searchData = { GetHelpSearchResults() }
    local SEARCH_DATA_STRIDE = 2
    for i = 1, #searchData, SEARCH_DATA_STRIDE do
        local helpCategoryIndex, helpIndex = searchData[i], searchData[i + 1]
        table.insert(self.searchResults, { helpCategoryIndex = helpCategoryIndex, helpIndex = helpIndex })
    end
    self:FireCallbacks("UpdateSearchResults")
end
function ZO_Help_Manager:GetSearchResults()
    if zo_strlen(self.searchString) > 1 then
        return self.searchResults
    end
    return nil
end
function ZO_Help_Manager:SetSearchString(searchString)
    self.searchString = searchString or ""
    StartHelpSearch(self.searchString)
end
function ZO_Help_Manager:OnGamepadPreferredModeChanged()
    if self:IsShowingOverlayScene() then
        SCENE_MANAGER:RemoveFragmentGroup(HELP_TUTORIALS_OVERLAY_KEYBOARD_FRAGMENT_GROUP)
        ZO_Dialogs_ReleaseDialog("HELP_TUTORIALS_OVERLAY_DIALOG")
    end
end
-- Optionally pass in a data object that can specify arguments and filters
-- sceneInfo =
-- {
-- systemFilters = { UI_SYSTEM_ANTIQUITY_DIGGING, UI_SYSTEM_BATTELGROUND_FINDER },
-- showOverlayConditionalFunction = function() MySceneShouldShowOverlayExample() end,
-- }
function ZO_Help_Manager:AddOverlayScene(sceneName, sceneInfo)
    sceneInfo = sceneInfo or {}
    sceneInfo.systemFilters = sceneInfo.systemFilters or {}
    self.overlayScenes[sceneName] = sceneInfo
end
function ZO_Help_Manager:GetShowingOverlaySceneInfo()
    for sceneName, sceneInfo in pairs(self.overlayScenes) do
        if SCENE_MANAGER:IsShowing(sceneName) and (not sceneInfo.showOverlayConditionalFunction or sceneInfo.showOverlayConditionalFunction())then
            return sceneInfo
        end
    end
    return nil
end
function ZO_Help_Manager:GetShowingOverlaySceneSystemFilters()
    local sceneInfo = self:GetShowingOverlaySceneInfo()
    return sceneInfo and sceneInfo.systemFilters or nil
end
function ZO_Help_Manager:IsShowingOverlayScene()
    return self:GetShowingOverlaySceneInfo() ~= nil
end
function ZO_Help_Manager:ToggleHelp()
    if TUTORIAL_SYSTEM:ShowHelp() then
        return
    end
    if self:IsShowingOverlayScene() then
        self:ToggleHelpOverlay()
        return
    end
    SYSTEMS:GetObject("mainMenu"):ToggleCategory(MENU_CATEGORY_HELP)
end
function ZO_Help_Manager:ToggleHelpOverlay()
    if IsInGamepadPreferredMode() then
        if ZO_Dialogs_IsShowing("HELP_TUTORIALS_OVERLAY_DIALOG") then
            ZO_Dialogs_ReleaseDialog("HELP_TUTORIALS_OVERLAY_DIALOG")
        else
            ZO_Dialogs_ShowGamepadDialog("HELP_TUTORIALS_OVERLAY_DIALOG")
        end
    else
        if HELP_TUTORIALS_FRAGMENT:IsShowing() then
            SCENE_MANAGER:RemoveFragmentGroup(HELP_TUTORIALS_OVERLAY_KEYBOARD_FRAGMENT_GROUP)
        else
            SCENE_MANAGER:AddFragmentGroup(HELP_TUTORIALS_OVERLAY_KEYBOARD_FRAGMENT_GROUP)
        end
    end
end
function ZO_Help_Manager:GetOverlaySyncObject()
    return self.overlaySyncObject
end
HELP_MANAGER = ZO_Help_Manager:New()