Back to Home

ESO Lua File v101041

ingame/collections/gamepad/tributepatronbook_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
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
-------------------------
-- Tribute Patron Book --
-------------------------
ZO_TributePatronBook_Gamepad = ZO_Object.MultiSubclass(ZO_TributePatronBook_Shared, ZO_Gamepad_ParametricList_Screen)
function ZO_TributePatronBook_Gamepad:New(...)
    return ZO_Gamepad_ParametricList_Screen.New(self, ...)
end
function ZO_TributePatronBook_Gamepad:Initialize(control, ...)
    local ACTIVATE_ON_SHOW = true
    ZO_Gamepad_ParametricList_Screen.Initialize(self, control, ZO_GAMEPAD_HEADER_TABBAR_DONT_CREATE, ACTIVATE_ON_SHOW)
    local TEMPLATE_DATA =
    {
        gridListClass = ZO_GridScrollList_Gamepad,
        headerEntryData =
        {
            entryTemplate = "ZO_TributePatron_GP_Header_Template",
            height = 34,
            gridPaddingY = 10,
        },
        descriptionEntryData =
        {
            entryTemplate = "ZO_TributePatron_Gamepad_Description_Label",
            gridPaddingX = 0,
            gridPaddingY = 0,
        },
        patronEntryData =
        {
            entryTemplate = "ZO_TributePatronBookTile_Gamepad_Control",
            width = ZO_TRIBUTE_PATRON_BOOK_TILE_WIDTH_GAMEPAD,
            height = ZO_TRIBUTE_PATRON_BOOK_TILE_HEIGHT_GAMEPAD,
            gridPaddingX = 15,
            gridPaddingY = 10,
        },
        cardEntryData =
        {
            entryTemplate = "ZO_TributePatronBookCardTile_Gamepad_Control",
            width = ZO_TRIBUTE_PATRON_BOOK_TILE_WIDTH_GAMEPAD,
            height = ZO_TRIBUTE_PATRON_BOOK_TILE_HEIGHT_GAMEPAD,
            gridPaddingX = 15,
            gridPaddingY = 10,
        },
    }
    local rightPane = control:GetNamedChild("RightPane")
    local infoContainerControl = rightPane:GetNamedChild("InfoContainer")
    ZO_TributePatronBook_Shared.Initialize(self, control, infoContainerControl, TEMPLATE_DATA)
    ZO_Gamepad_ParametricList_Screen.SetScene(self, self:GetScene())
    self.headerLabel = infoContainerControl:GetNamedChild("Header")
    GAMEPAD_TRIBUTE_PATRON_BOOK_SCENE = self:GetScene()
    GAMEPAD_TRIBUTE_PATRON_BOOK_FRAGMENT = self:GetFragment()
end
function ZO_TributePatronBook_Gamepad:GetSceneName()
    return "gamepadTributePatronBook"
end
function ZO_TributePatronBook_Gamepad:InitializeHeader()
    self.headerData = {}
end
function ZO_TributePatronBook_Gamepad:RefreshHeader()
    if self.currentListDescriptor then
        self.headerData.titleText = self.currentListDescriptor.titleText
    end
end
function ZO_TributePatronBook_Gamepad:ViewCategory(tributePatronCategoryData)
    local patronList = self.patronListDescriptor.list
    patronList:Clear()
    self.patronListDescriptor.titleText = tributePatronCategoryData:GetFormattedName()
    -- Add the patron entries
    for _, patronData in tributePatronCategoryData:PatronIterator() do
        local entryData = ZO_GamepadEntryData:New(patronData:GetFormattedName())
        entryData:SetDataSource(patronData)
        entryData:SetIconTintOnSelection(true)
        patronList:AddEntry("ZO_GamepadNewMenuEntryTemplate", entryData)
    end
    patronList:Commit()
    self.patronListDescriptor.lastParentCategoryData = tributePatronCategoryData
    self:ShowListDescriptor(self.patronListDescriptor)
end
-- Begin ZO_TributePatronBook_Shared Overrides --
function ZO_TributePatronBook_Gamepad:InitializeControls()
    ZO_TributePatronBook_Shared.InitializeControls(self)
end
function ZO_TributePatronBook_Gamepad:InitializeCategories()
    ZO_TributePatronBook_Shared.InitializeCategories(self)
    self.categoryListDescriptor =
    {
        list = self:GetMainList(),
        keybindDescriptor = self.categoryKeybindStripDescriptor,
        titleText = GetString(SI_TRIBUTE_PATRON_BOOK_TITLE),
        isCategoriesDescriptor = true,
    }
    self.patronListDescriptor =
    {
        list = self:AddList("Patrons"),
        keybindDescriptor = self.patronKeybindStripDescriptor,
        -- The title text will be updated to the name of the patron category
    }
    -- Grid Keybind
    self.gridKeybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptors(self.gridKeybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON, function() self:ExitGridList() end)
end
function ZO_TributePatronBook_Gamepad:InitializeGridList()
    ZO_TributePatronBook_Shared.InitializeGridList(self)
    local ALWAYS_ANIMATE = true
    self.gridListFragment = ZO_FadeSceneFragment:New(self.gridListPanelControl, ALWAYS_ANIMATE)
    self.setupLabel = self.gridListControl:GetNamedChild("SetupLabel")
    self.gridList:SetScrollToExtent(true)
    self.gridList:SetOnSelectedDataChangedCallback(function(...) self:OnGridSelectionChanged(...) end)
end
function ZO_TributePatronBook_Gamepad:OnGridSelectionChanged(oldSelectedData, selectedData)
    -- Deselect previous tile
    if oldSelectedData and oldSelectedData.dataEntry then
        if oldSelectedData.dataEntry.control then
            oldSelectedData.dataEntry.control.object:SetSelected(false)
        end
        oldSelectedData.isSelected = false
    end
    -- Select newly selected tile.
    if selectedData and selectedData.dataEntry then
        if selectedData.dataEntry.control then
            selectedData.dataEntry.control.object:SetSelected(true)
        end
        selectedData.isSelected = true
    else
        GAMEPAD_TOOLTIPS:ClearTooltip(GAMEPAD_RIGHT_TOOLTIP)
    end
end
function ZO_TributePatronBook_Gamepad:GetSelectedCategory()
    if self.currentListDescriptor and self.currentListDescriptor.isCategoriesDescriptor then
        return self:GetCurrentListTargetData()
    end
    return nil
end
-- Do not call this directly, instead call self.categoriesRefreshGroup:MarkDirty("List")
function ZO_TributePatronBook_Gamepad:RefreshCategories()
    local categoryList = self.categoryListDescriptor.list
    local selectedData = self.currentListDescriptor.list:GetTargetData()
    categoryList:Clear()
    local entryList = {}
    for _, categoryData in TRIBUTE_DATA_MANAGER:TributePatronCategoryIterator(self.categoryFilters) do
        local categoryName = categoryData:GetFormattedName()
        local gamepadIcon = categoryData:GetGamepadIcon()
        local entryData = ZO_GamepadEntryData:New(categoryName, gamepadIcon)
        entryData:SetDataSource(categoryData)
        entryData:SetIconTintOnSelection(true)
        table.insert(entryList, entryData)
    end
    for _, entryData in ipairs(entryList) do
        categoryList:AddEntry("ZO_GamepadNewMenuEntryTemplate", entryData)
        if selectedData and selectedData:GetId() == entryData:GetId() then
            selectedData = entryData
        end
    end
    categoryList:Commit()
    if self.currentListDescriptor then
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.currentListDescriptor.keybindDescriptor)
        if self.currentListDescriptor == self.patronListDescriptor then
            self:ViewCategory(self.patronListDescriptor.lastParentCategoryData)
        end
    end
end
-- Do not call this directly, instead call self.categoriesRefreshGroup:MarkDirty("Visible")
function ZO_TributePatronBook_Gamepad:RefreshVisibleCategories()
    self.categoryListDescriptor.list:RefreshVisible()
end
-- This function overrides the shared version because in the design the description is placed in a
-- different order then in the base layout.
function ZO_TributePatronBook_Gamepad:BuildGridList()
    if self.gridList then
        self.gridList:ClearGridList()
        -- Pre-process starter cards
        self:SetupStarterCards()
        -- Pre-process dock cards
        self:SetupDockCards()
        -- Build Patron name header
        self:AddPatronHeader()
        -- Build description entry
        self:AddDescriptionEntry()
        -- Build Patron
        self:AddPatronEntry()
        -- Build starter card entries
        self:AddStarterCardEntries()
        -- Build card entries
        self:AddDockCardEntries()
        -- Build card upgrade entries
        self:AddCardUpgradeEntries()
        self.gridList:CommitGridList()
        self.gridList:ResetToTop()
    end
end
-- End ZO_TributePatronBook_Shared Overrides --
function ZO_TributePatronBook_Gamepad:AddPatronHeader()
    local patronData = TRIBUTE_DATA_MANAGER:GetTributePatronData(self.patronId)
    self.headerLabel:SetText(patronData:GetFormattedColorizedName())
end
-- Begin ZO_Gamepad_ParametricList_Screen Overrides --
function ZO_TributePatronBook_Gamepad:InitializeKeybindStripDescriptors()
    self.categoryKeybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                local categoryData = self:GetSelectedCategory()
                self:GetScene():AddFragment(GAMEPAD_NAV_QUADRANT_2_3_BACKGROUND_FRAGMENT)
                self:ViewCategory(categoryData)
            end,
            sound = SOUNDS.GAMEPAD_MENU_FORWARD,
        },
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptorsWithSound(self.categoryKeybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON)
    self.patronKeybindStripDescriptor =
    {
        alignment = KEYBIND_STRIP_ALIGN_LEFT,
        {
            name = GetString(SI_GAMEPAD_SELECT_OPTION),
            keybind = "UI_SHORTCUT_PRIMARY",
            callback = function()
                self:EnterGridList()
            end,
            sound = SOUNDS.GAMEPAD_MENU_FORWARD,
        },
    }
    ZO_Gamepad_AddBackNavigationKeybindDescriptorsWithSound(self.patronKeybindStripDescriptor, GAME_NAVIGATION_TYPE_BUTTON, function()
        self:GetScene():RemoveFragment(GAMEPAD_NAV_QUADRANT_2_3_BACKGROUND_FRAGMENT)
        self:ShowListDescriptor(self.categoryListDescriptor)
    end)
end
function ZO_TributePatronBook_Gamepad:EnterGridList()
    self.gridList:Activate()
    KEYBIND_STRIP:AddKeybindButtonGroup(self.gridKeybindStripDescriptor)
end
function ZO_TributePatronBook_Gamepad:ExitGridList()
    self.gridList:Deactivate()
    KEYBIND_STRIP:RemoveKeybindButtonGroup(self.gridKeybindStripDescriptor)
end
function ZO_TributePatronBook_Gamepad:PerformUpdate()
    -- Must be overridden
    self.dirty = false
end
function ZO_TributePatronBook_Gamepad:OnShowing()
    ZO_Gamepad_ParametricList_Screen.OnShowing(self)
    if self.browseToCollectibleInfo then
        local patronId = self.browseToCollectibleInfo.patronId
        local patronData = TRIBUTE_DATA_MANAGER:GetTributePatronData(patronId)
        local tributePatronCategoryData = patronData:GetCategoryData()
        local patronList = self.patronListDescriptor.list
        self:ViewCategory(tributePatronCategoryData)
        
        local patronIndex = patronList:GetIndexForData("ZO_GamepadNewMenuEntryTemplate", patronData)
        patronList:SetSelectedIndexWithoutAnimation(patronIndex)
        self.browseToCollectibleInfo = nil
        self:GetScene():AddFragment(GAMEPAD_NAV_QUADRANT_2_3_BACKGROUND_FRAGMENT)
        self.categoriesRefreshGroup:MarkDirty("List")
    else
        self:ShowListDescriptor(self.categoryListDescriptor)
    end
end
function ZO_TributePatronBook_Gamepad:OnHide()
    ZO_Gamepad_ParametricList_Screen.OnHide(self)
    if self.gridList:IsActive() then
        self:ExitGridList()
    end
    self:GetScene():RemoveFragment(GAMEPAD_NAV_QUADRANT_2_3_BACKGROUND_FRAGMENT)
end
function ZO_TributePatronBook_Gamepad:SetupList(list)
    local function TributePatronEntrySetup(control, data, selected, reselectingDuringRebuild, enabled, active)
        if data.HasAnyNewPatronCollectibles then
            data:SetNew(data:HasAnyNewPatronCollectibles())
        else
            data:SetNew(data.dataSource:IsNew())
        end
        ZO_SharedGamepadEntry_OnSetup(control, data, selected, reselectingDuringRebuild, enabled, active)
    end
    list:AddDataTemplateWithHeader("ZO_GamepadNewMenuEntryTemplate", TributePatronEntrySetup, ZO_GamepadMenuEntryTemplateParametricListFunction, ZO_TributePatronCategoryData.Equals, "ZO_GamepadMenuEntryHeaderTemplate")
    list:AddDataTemplate("ZO_GamepadNewMenuEntryTemplate", TributePatronEntrySetup, ZO_GamepadMenuEntryTemplateParametricListFunction, ZO_TributePatronCategoryData.Equals)
    list:SetReselectBehavior(ZO_PARAMETRIC_SCROLL_LIST_RESELECT_BEHAVIOR.MATCH_OR_RESET_TO_DEFAULT)
end
-- End ZO_Gamepad_ParametricList_Screen Overrides --
function ZO_TributePatronBook_Gamepad:ShowListDescriptor(listDescriptor)
    if self.currentListDescriptor == listDescriptor then
        return
    end
    self.currentListDescriptor = listDescriptor
    if listDescriptor then
        self:SetCurrentList(listDescriptor.list)
        KEYBIND_STRIP:AddKeybindButtonGroup(listDescriptor.keybindDescriptor)
        self:RefreshHeader()
        self.infoContainerControl:SetHidden(listDescriptor ~= self.patronListDescriptor)
    end
end
function ZO_TributePatronBook_Gamepad:HideCurrentListDescriptor()
    if self.currentListDescriptor then
        if not self.currentListDescriptor.isCategoriesDescriptor then
            local currentData = self.currentListDescriptor.list:GetTargetData()
            if currentData and currentData:IsNew() then
                ClearCollectibleNewStatus(currentData:GetPatronCollectibleId())
                self.categoriesRefreshGroup:MarkDirty("List")
            end
        end
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.currentListDescriptor.keybindDescriptor)
        self:DisableCurrentList()
        self.currentListDescriptor = nil
    end
end
function ZO_TributePatronBook_Gamepad:ActivateCurrentListDescriptor()
    if self.currentListDescriptor then
        self:ActivateCurrentList()
        KEYBIND_STRIP:AddKeybindButtonGroup(self.currentListDescriptor.keybindDescriptor)
    end
end
function ZO_TributePatronBook_Gamepad:DeactivateCurrentListDescriptor()
    if self.currentListDescriptor then
        self:DeactivateCurrentList()
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.currentListDescriptor.keybindDescriptor)
    end
end
function ZO_TributePatronBook_Gamepad:GetCurrentListTargetData()
    local currentList = self:GetCurrentList()
    return currentList and currentList:GetTargetData()
end
function ZO_TributePatronBook_Gamepad:OnSelectionChanged(list, selectedData, oldSelectedData)
    if oldSelectedData and oldSelectedData:IsNew() and oldSelectedData.GetPatronCollectibleId then
        ClearCollectibleNewStatus(oldSelectedData:GetPatronCollectibleId())
        self.categoriesRefreshGroup:MarkDirty("List")
    end
    if selectedData and selectedData.dataSource then
        if list == self.patronListDescriptor.list then
            self.patronId = selectedData.patronId
            self:BuildGridList()
        end
    end
end
function ZO_TributePatronBook_Gamepad:BrowseToPatron(patronId)
    self.browseToCollectibleInfo =
    {
        patronId = patronId,
    }
    SCENE_MANAGER:CreateStackFromScratch("mainMenuGamepad", self:GetSceneName())
end
--[[Global functions]]--
------------------------
    GAMEPAD_TRIBUTE_PATRON_BOOK = ZO_TributePatronBook_Gamepad:New(control)
end