ESO Lua File v100010

ingame/help/gamepad/help_search_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
local HelpTutorialsSearchGamepad = ZO_HelpTutorialsGamepad:Subclass()
function HelpTutorialsSearchGamepad:New(...)
    local screen = ZO_Object.New(self)
    screen:Initialize(...)
    return screen
end
function HelpTutorialsSearchGamepad:Initialize(control)
    ZO_HelpTutorialsGamepad.Initialize(self, control)
    local helpEntriesFragment = ZO_FadeSceneFragment:New(control)
    HELP_TUTORIALS_SEARCH_GAMEPAD = ZO_Scene:New("helpTutorialsSearchGamepad", SCENE_MANAGER)
    HELP_TUTORIALS_SEARCH_GAMEPAD:AddFragment(helpEntriesFragment)
    local function OnStateChanged(...)
        self:OnStateChanged(...)
    end
    HELP_TUTORIALS_SEARCH_GAMEPAD:RegisterCallback("StateChange", OnStateChanged)
    self.tutorialBox = control:GetNamedChild("TutorialText")
    self.tutorialHeader = self.tutorialBox:GetNamedChild("Header")
    self.tutorialTitle = self.tutorialBox:GetNamedChild("Title")
    self.tutorialText = self.tutorialBox:GetNamedChild("Text")
end
function HelpTutorialsSearchGamepad:InitializeEvents()
    ZO_HelpTutorialsGamepad.InitializeEvents(self)
    self.control:RegisterForEvent(EVENT_HELP_SEARCH_RESULTS_READY, function() self:UpdateSearchResults(GetHelpSearchResults()) end)
end
function HelpTutorialsSearchGamepad:BeginSearch()
    -- TODO: Show virtual keyboard, and begin search on completion, rather than a hard-coded string.
    self.searchString = "gem"
    StartHelpSearch(self.searchString)
end
function HelpTutorialsSearchGamepad:Push()
    SCENE_MANAGER:Push("helpTutorialsSearchGamepad")
    self:BeginSearch()
end
function HelpTutorialsSearchGamepad:InitializeKeybindStripDescriptors()
    self.keybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        -- Back
        KEYBIND_STRIP:GetDefaultGamepadBackButtonDescriptor(),
        -- Search
        {
            name = GetString(SI_GAMEPAD_HELP_SEARCH),
            keybind = "UI_SHORTCUT_TERTIARY",
            callback = function()
                self:BeginSearch()
            end,
        },
    }
end
function HelpTutorialsSearchGamepad:PerformUpdate()
    self.dirty = false
    self.itemList:Clear()
    if not self.searchResults then
        return
    end
    -- Add the entries.
    local lastCategory = nil
    for i = 1, #self.searchResults do
        local entry = self.searchResults[i]
        local nextEntry = self.searchResults[i + 1]
        local categoryIndex = entry.helpCategoryIndex
        local helpIndex = entry.helpIndex
        local isHeader = lastCategory ~= categoryIndex
        local isNextHeader
        if nextEntry then
            isNextHeader = (categoryIndex ~= nextEntry.helpCategoryIndex)
        else
            isNextHeader = false
        end
        local prePadding = isNextHeader and GAMEPAD_HEADER_DEFAULT_PADDING
        local helpName, description, description2, image = GetHelpInfo(categoryIndex, helpIndex)
        local entryData = ZO_GamepadEntryData:New(helpName, image)
        entryData.description = description
        entryData.description2 = description2
        local categoryName = nil
        local templateName
        local postPadding
        local preSelectedOffsetAdditionalPadding
        if isHeader then
            lastCategory = categoryIndex
            categoryName = select(1, GetHelpCategoryInfo(categoryIndex))
            entryData:SetHeader(categoryName)
            templateName = "ZO_GamepadMenuEntryTemplateWithHeader"
            postPadding = GAMEPAD_HEADER_SELECTED_PADDING
        else
            templateName = "ZO_GamepadMenuEntryTemplate"
            preSelectedOffsetAdditionalPadding = isNextHeader and GAMEPAD_HEADER_SELECTED_PADDING
        end
        self.itemList:AddEntry(templateName, entryData, nil, prePadding, postPadding, preSelectedOffsetAdditionalPadding)
    end
    self.itemList:Commit()
    -- Update the key bindings.
    KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor)
    -- Update the header.
    self.headerData.titleText = zo_strformat(SI_GAMEPAD_HELP_SEARCH_TITLE, self.searchString)
    ZO_GamepadGenericHeader_Refresh(self.header, self.headerData)
end
function HelpTutorialsSearchGamepad:UpdateSearchResults(...)
    self.searchResults = {}
    local SEARCH_DATA_STRIDE = 2
    for i = 1, select("#", ...), SEARCH_DATA_STRIDE do
        local helpCategoryIndex, helpIndex = select(i, ...)
        self.searchResults[#self.searchResults + 1] = {helpCategoryIndex = helpCategoryIndex, helpIndex = helpIndex}
    end
    self:Update()
end
function HelpTutorialsSearchGamepad:OnSelectionChanged(list, selectedData, oldSelectedData)
    if not selectedData then
        return
    end
    local helpName = selectedData.name
    local description = selectedData.description
    local description2 = selectedData.description2
    self.tutorialBox:SetHidden(false)
    self.tutorialTitle:SetText(helpName)
    self.tutorialText:SetText(description .. '\n\n' .. description2)
end
function HelpTutorialsSearchGamepad:OnHide()
    ZO_HelpTutorialsGamepad.OnHide(self)
    self.tutorialBox:SetHidden(true)
end
    HELP_TUTORIALS_SEARCH_GAMEPAD = HelpTutorialsSearchGamepad:New(control)
end