ESO Lua File v100010

ingame/help/gamepad/help_categories_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
local HelpTutorialsCategoriesGamepad = ZO_HelpTutorialsGamepad:Subclass()
function HelpTutorialsCategoriesGamepad:New(...)
    return ZO_HelpTutorialsGamepad.New(self, ...)
end
function HelpTutorialsCategoriesGamepad:Initialize(control)
    ZO_HelpTutorialsGamepad.Initialize(self, control)
    local helpTutorialsFramgent = ZO_FadeSceneFragment:New(control)
    HELP_TUTORIAL_CATEGORIES_SCENE_GAMEPAD = ZO_Scene:New("helpTutorialsCategoriesGamepad", SCENE_MANAGER)
    HELP_TUTORIAL_CATEGORIES_SCENE_GAMEPAD:AddFragment(helpTutorialsFramgent)
    self.searchTextChangedCallback = function()
            ZO_EditDefaultText_OnTextChanged(self.filterBox)
            self.searchString = self.filterBox:GetText()
            StartHelpSearch(self.searchString)
        end
    local function OnStateChanged(...)
        self:OnStateChanged(...)
    end
    HELP_TUTORIAL_CATEGORIES_SCENE_GAMEPAD:RegisterCallback("StateChange", OnStateChanged)
end
function HelpTutorialsCategoriesGamepad:RegisterGroupCallbacks()
    local sceneGroup = HELP_TUTORIAL_CATEGORIES_SCENE_GAMEPAD:GetSceneGroup()
    sceneGroup:RegisterCallback("StateChange", function(oldState, newState)
                                                    if(newState == SCENE_GROUP_SHOWING) then
                                                        self:ClearSearch()
                                                    end
                                                end)
end
function HelpTutorialsCategoriesGamepad:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Back
        KEYBIND_STRIP:GetDefaultGamepadBackButtonDescriptor(),
        -- Show Category or filter
        {
            name = function ()
                local selectedData = self.itemList:GetSelectedData()
                if selectedData and selectedData.isSearch then
                    return GetString(SI_GAMEPAD_SELECT_OPTION)
                else
                    return GetString(SI_GAMEPAD_HELP_DETAILS)
                end
            end,
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                local selectedData = self.itemList:GetSelectedData()
                if selectedData.isSearch then
                    self.filterBox:TakeFocus()
                else
                    HELP_TUTORIALS_ENTRIES_GAMEPAD:Push(selectedData.categoryIndex, self.searchString, self.searchResults)
                end
            end,
        },
    }
    ZO_Gamepad_AddListTriggerKeybindDescriptors(self.keybindStripDescriptor, function() return self.itemList end )
end
local function SortByCategory(result1, result2)
    return result1.helpCategoryIndex < result2.helpCategoryIndex
end
function HelpTutorialsCategoriesGamepad:InitializeSearch(control)
    self.searchString = ""
    self.searchResults = {}
    local SEARCH_DATA_STRIDE = 2
    local function UpdateSearchResults(...)
        self.searchResults = {}
        local entry = 1
        for i = 1, select("#", ...), SEARCH_DATA_STRIDE do
            local helpCategoryIndex, helpIndex = select(i, ...)
            self.searchResults[entry] = {helpCategoryIndex = helpCategoryIndex, helpIndex = helpIndex}
            entry = entry + 1
        end
        table.sort(self.searchResults, SortByCategory)
    end
    local function OnSearchResultsReady()
        self:Update()
    end
    control:RegisterForEvent(EVENT_HELP_SEARCH_RESULTS_READY, OnSearchResultsReady)
end
function HelpTutorialsCategoriesGamepad:SetupList(list)
    ZO_Gamepad_ParametricList_Screen.SetupList(self, list)
    local function SetupSearchListEntry(control, data, selected, reselectingDuringRebuild, enabled, active)
        ZO_SharedGamepadEntry_OnSetup(control, data, selected, reselectingDuringRebuild, enabled, active)
        self.filterContainer = control:GetNamedChild("EditBox")
        self.filterBox = self.filterContainer:GetNamedChild("Edit")
        self.filterBox:SetHandler("OnTextChanged", self.searchTextChangedCallback)
    end
end
function HelpTutorialsCategoriesGamepad:ClearSearch()
    self.searchString = ""
    if self.filterBox then
        self.filterBox:SetText("")
    end
end
function HelpTutorialsCategoriesGamepad:AddSearchEntry()
    local entryData = ZO_GamepadEntryData:New(GetString(SI_GAMEPAD_HELP_SEARCH))
    entryData.isSearch = true
    self.itemList:AddEntry("ZO_Gamepad_Help_Search_Row", entryData)
end
function HelpTutorialsCategoriesGamepad:AddListEntry(categoryIndex)
    local categoryName, description, _, _, _, gamepadIcon = GetHelpCategoryInfo(categoryIndex)
    local entryData = ZO_GamepadEntryData:New(categoryName, gamepadIcon)
    entryData.categoryIndex = categoryIndex
    entryData.name = categoryName
    self.itemList:AddEntry("ZO_GamepadMenuEntryTemplate", entryData)
end
function HelpTutorialsCategoriesGamepad:PerformUpdate()
    self.dirty = false
    self.itemList:Clear()
    self:AddSearchEntry()
    if self.searchString ~= "" then
        local currCategoryIndex = nil
        for i = 1, #self.searchResults do
            local searchResult = self.searchResults[i]
            if searchResult and currCategoryIndex ~= searchResult.helpCategoryIndex then
                currCategoryIndex = searchResult.helpCategoryIndex
                self:AddListEntry(currCategoryIndex)
            end
        end
    else
        -- Get the list of categoires we need to show.
        for categoryIndex = 1, GetNumHelpCategories() do
            self:AddListEntry(categoryIndex)
        end
    end
    self.itemList:Commit()
    -- Update the key bindings.
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    -- Update the header.
    self:SetupSearchHeaderData(self.searchString, self.headerData)
    ZO_GamepadGenericHeader_Refresh(self.header, self.headerData)
end
function HelpTutorialsCategoriesGamepad:OnSelectionChanged(list, selectedData, oldSelectedData)
     if not selectedData.isSearch then
        self.filterBox:LoseFocus()
    end
    
    self.filterContainer:SetHidden(not selectedData.isSearch)
end
    HELP_TUTORIALS_CATEGORIES = HelpTutorialsCategoriesGamepad:New(control)
end