Back to Home

ESO Lua File v101044

ingame/tradinghouse/gamepad/tradinghousecategories_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
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
ZO_TradingHouseSearchCategoryFeature_Gamepad = ZO_TradingHouseSearchCategoryFeature_Shared:Subclass()
function ZO_TradingHouseSearchCategoryFeature_Gamepad:New(...)
    return ZO_TradingHouseSearchCategoryFeature_Shared.New(self, ...)
end
-- Override
function ZO_TradingHouseSearchCategoryFeature_Gamepad:Initialize()
    self.headers = {}
    self.headerToCategoriesMap = {}
    self.featureKeyToFeatureObjectMap = {}
    self.selectedHeader = nil
    self.selectedCategoryParams = nil
    self.selectedSubcategoryKey = nil
    local lastHeader = nil
    for _, categoryParams in ipairs(ZO_TRADING_HOUSE_CATEGORY_PARAMS_LIST) do
        local header = categoryParams:GetHeader()
        if lastHeader ~= header then
            table.insert(self.headers, header)
            self.headerToCategoriesMap[header] = {}
            lastHeader = header
        end
        table.insert(self.headerToCategoriesMap[header], categoryParams)
        for _, featureKey in categoryParams:FeatureKeyIterator() do
            local feature = self.featureKeyToFeatureObjectMap[featureKey]
            if not feature then
                feature = ZO_TradingHouse_CreateGamepadFeature(featureKey)
                self.featureKeyToFeatureObjectMap[featureKey] = feature
            end
        end
    end
end
do
    local function GetCategoryNarrationText(entryData, entryControl)
        if entryData.dropDown then
            return entryData.dropDown:GetNarrationText()
        end
    end
    function ZO_TradingHouseSearchCategoryFeature_Gamepad:GetOrCreateHeaderEntryData()
        if self.headerEntryData then
            return self.headerEntryData
        end
        local function OnHeaderChanged(dropDown, entryName, entry, selectionChanged)
            if self.selectedHeader ~= entry.header then
                local headerFirstCategoryParams = self.headerToCategoriesMap[entry.header][1]
                local categoryFirstSubcategoryKey = headerFirstCategoryParams:GetSubcategoryKey(1)
                self:SelectCategoryParams(headerFirstCategoryParams, categoryFirstSubcategoryKey)
            end
        end
        local function MatchesSelectedHeader(entry)
            return entry.header == self.selectedHeader
        end
        local function SetupHeaderDropdown(dropdown)
            dropdown:ClearItems()
            for _, header in ipairs(self.headers) do
                local headerName = GetString("SI_TRADINGHOUSECATEGORYHEADER", header)
                local entry = dropdown:CreateItemEntry(headerName, OnHeaderChanged)
                entry.header = header
                dropdown:AddItem(entry)
            end
            if self.selectedHeader then
                dropdown:SetSelectedItemByEval(MatchesSelectedHeader)
            else
                dropdown:SelectFirstItem()
            end
        end
        local entryData = ZO_GamepadEntryData:New("GuildStoreHeader")
        entryData.setupCallback = SetupHeaderDropdown
        entryData:SetHeader(GetString(SI_GAMEPAD_TRADING_HOUSE_BROWSE_CATEGORY))
        entryData.narrationText = GetCategoryNarrationText
        self.headerEntryData = entryData
        return entryData
    end
    function ZO_TradingHouseSearchCategoryFeature_Gamepad:AddHeaderEntry(itemList)
        itemList:AddEntryWithHeader("ZO_GamepadGuildStoreBrowseDropdownTemplate", self:GetOrCreateHeaderEntryData())
    end
    function ZO_TradingHouseSearchCategoryFeature_Gamepad:GetOrCreateCategoryEntryData()
        if self.categoryEntryData then
            return self.categoryEntryData
        end
        local function OnCategorySelected(_, entryName, entry, _)
            if self.selectedCategoryParams ~= entry.categoryParams then
                local categoryFirstSubcategoryKey = entry.categoryParams:GetSubcategoryKey(1)
                self:SelectCategoryParams(entry.categoryParams, categoryFirstSubcategoryKey)
            end
        end
        local function MatchesSelectedCategory(entry)
            return entry.categoryParams == self.selectedCategoryParams
        end
        local function SetupCategoryComboBox(comboBox)
            comboBox:ClearItems()
            local selectOld = false
            local categories = self.headerToCategoriesMap[self.selectedHeader]
            for _, categoryParams in ipairs(categories) do
                local categoryName = categoryParams:GetFormattedName()
                local entry = comboBox:CreateItemEntry(categoryName, OnCategorySelected)
                entry.categoryParams = categoryParams
                if categoryParams == self.selectedCategoryParams then
                    selectOld = true
                end
                comboBox:AddItem(entry)
            end
            if selectOld then
                comboBox:SetSelectedItemByEval(MatchesSelectedCategory)
            else
                comboBox:SelectFirstItem()
            end
        end
        local entryData = ZO_GamepadEntryData:New("GuildStoreCategory")
        entryData.setupCallback = SetupCategoryComboBox
        entryData.narrationText = GetCategoryNarrationText
        self.categoryEntryData = entryData
        return entryData
    end
    function ZO_TradingHouseSearchCategoryFeature_Gamepad:AddCategoryEntry(itemList)
        local categories = self.headerToCategoriesMap[self.selectedHeader]
        if #categories > 1 then
            itemList:AddEntry("ZO_GamepadGuildStoreBrowseDropdownTemplate", self:GetOrCreateCategoryEntryData())
        else
            -- Since aren't creating the dropdown, we need to manually update the key to the correct value
            -- instead of relying on the OnCategorySelected callback
            self.selectedCategoryParams = categories[1]
        end
    end
    function ZO_TradingHouseSearchCategoryFeature_Gamepad:GetOrCreateSubcategoryEntryData(itemList)
        if self.subcategoryEntryData then
            return self.subcategoryEntryData
        end
        local function OnSubcategorySelected(_, entryName, entry, _)
            if self.selectedSubcategoryKey ~= entry.subcategoryKey then
                self:SelectCategoryParams(self.selectedCategoryParams, entry.subcategoryKey)
            end
        end
        local function MatchesSelectedSubcategory(entry)
            return entry.subcategoryKey == self.selectedSubcategoryKey
        end
        local function SetupSubcategory(dropdown)
            local categoryParams = self:GetCategoryParams()
            dropdown:ClearItems()
            local selectOld = false
            for subcategoryIndex = 1, categoryParams:GetNumSubcategories() do
                local key = categoryParams:GetSubcategoryKey(subcategoryIndex)
                local name = categoryParams:GetSubcategoryName(subcategoryIndex)
                local entry = dropdown:CreateItemEntry(name, OnSubcategorySelected)
                entry.subcategoryKey = key
                if key == self.selectedSubcategoryKey then
                    selectOld = true
                end
                dropdown:AddItem(entry)
            end
            if selectOld then
            else
                dropdown:SelectFirstItem()
            end
        end
        local entryData = ZO_GamepadEntryData:New("GuildStoreSubcategory")
        entryData.setupCallback = SetupSubcategory
        entryData.narrationText = GetCategoryNarrationText
        self.subcategoryEntryData = entryData
        return entryData
    end
end
function ZO_TradingHouseSearchCategoryFeature_Gamepad:AddSubcategoryEntry(itemList)
    if self.selectedCategoryParams and self.selectedCategoryParams:GetNumSubcategories() > 1 then
        itemList:AddEntry("ZO_GamepadGuildStoreBrowseDropdownTemplate", self:GetOrCreateSubcategoryEntryData())
    else
        -- Since aren't creating the dropdown, we need to manually update the key to the correct value
        -- instead of relying on the OnSubCategorySelected callback
        self.selectedSubcategoryKey = "AllSubcategories"
    end
end
function ZO_TradingHouseSearchCategoryFeature_Gamepad:AddEntries(itemList)
    self:AddHeaderEntry(itemList)
    self:AddCategoryEntry(itemList)
    local categoryParams = self.selectedCategoryParams
    if categoryParams then
        self:AddSubcategoryEntry(itemList)
        for _, featureKey in categoryParams:FeatureKeyIterator() do
            local feature = self.featureKeyToFeatureObjectMap[featureKey]
            feature:AddEntries(itemList)
        end
    end
end
-- Override
function ZO_TradingHouseSearchCategoryFeature_Gamepad:GetCategoryParams()
    return self.selectedCategoryParams
end
-- Override
function ZO_TradingHouseSearchCategoryFeature_Gamepad:GetSubcategoryKey()
    return self.selectedSubcategoryKey
end
-- Override
function ZO_TradingHouseSearchCategoryFeature_Gamepad:GetFeatureForKey(featureKey)
    return self.featureKeyToFeatureObjectMap[featureKey]
end
-- Override
function ZO_TradingHouseSearchCategoryFeature_Gamepad:SelectCategoryParams(categoryParams, subcategoryKey)
    if categoryParams then
        self.selectedHeader = categoryParams:GetHeader()
        self.selectedCategoryParams = categoryParams
        if subcategoryKey then
            self.selectedSubcategoryKey = subcategoryKey
        end
        TRADING_HOUSE_SEARCH:HandleSearchCriteriaChanged(self)
    end
end