Back to Home

ESO Lua File v101043

ingame/collections/keyboard/tributepatronbook_keyboard.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
-------------------------
-- Tribute Patron Book --
-------------------------
ZO_TributePatronBook_Keyboard = ZO_TributePatronBook_Shared:Subclass()
local function RefreshMainMenu()
    MAIN_MENU_KEYBOARD:RefreshCategoryBar()
    MAIN_MENU_KEYBOARD:UpdateSceneGroupButtons("collectionsSceneGroup")
end
function ZO_TributePatronBook_Keyboard:Initialize(control)
    local TEMPLATE_DATA =
    {
        gridListClass = ZO_GridScrollList_Keyboard,
        headerEntryData =
        {
            entryTemplate = "ZO_TributePatron_Keyboard_Header_Template",
            height = 34,
            gridPaddingY = 10,
        },
        descriptionEntryData =
        {
            entryTemplate = "ZO_TributePatron_Keyboard_Description_Label",
            gridPaddingX = 0,
            gridPaddingY = 10,
        },
        widePatronEntryData =
        {
            entryTemplate = "ZO_TributePatronBookTile_Keyboard_Control_Wide",
            width = ZO_TRIBUTE_PATRON_BOOK_TILE_WIDE_WIDTH_KEYBOARD,
            height = ZO_TRIBUTE_PATRON_BOOK_TILE_HEIGHT_KEYBOARD,
            gridPaddingX = 10,
            gridPaddingY = 10,
        },
        patronEntryData =
        {
            entryTemplate = "ZO_TributePatronBookTile_Keyboard_Control",
            width = ZO_TRIBUTE_PATRON_BOOK_TILE_WIDTH_KEYBOARD,
            height = ZO_TRIBUTE_PATRON_BOOK_TILE_HEIGHT_KEYBOARD,
            gridPaddingX = 10,
            gridPaddingY = 10,
        },
        wideCardEntryData =
        {
            entryTemplate = "ZO_TributePatronBookCardTile_Keyboard_Control_Wide",
            width = ZO_TRIBUTE_PATRON_BOOK_TILE_WIDE_WIDTH_KEYBOARD,
            height = ZO_TRIBUTE_PATRON_BOOK_TILE_HEIGHT_KEYBOARD,
            gridPaddingX = 10,
            gridPaddingY = 10,
        },
        cardEntryData =
        {
            entryTemplate = "ZO_TributePatronBookCardTile_Keyboard_Control",
            width = ZO_TRIBUTE_PATRON_BOOK_TILE_WIDTH_KEYBOARD,
            height = ZO_TRIBUTE_PATRON_BOOK_TILE_HEIGHT_KEYBOARD,
            gridPaddingX = 10,
            gridPaddingY = 10,
        },
    }
    self.searchEditBox = control:GetNamedChild("FiltersSearchBox")
    local infoContainerControl = control:GetNamedChild("InfoContainer")
    ZO_TributePatronBook_Shared.Initialize(self, control, infoContainerControl, TEMPLATE_DATA)
    self.categoryNodeLookupData = {}
    TRIBUTE_PATRON_BOOK_SCENE = self:GetScene()
    TRIBUTE_PATRON_BOOK_FRAGMENT = self:GetFragment()
end
function ZO_TributePatronBook_Keyboard:DeferredInitialize()
    if self.hasDeferredInitialized then
        return
    end
    self.hasDeferredInitialized = true
end
function ZO_TributePatronBook_Keyboard:OnFragmentShowing()
    if self.pendingNavigateToData then
        self:NavigateToCollectibleData(self.pendingNavigateToData)
        self.pendingNavigateToData = nil
    end
    ZO_TributePatronBook_Shared.OnFragmentShowing(self)
end
function ZO_TributePatronBook_Keyboard:AddCategory(tributePatronCategoryData, patronFilters)
    local tree = self.categoryTree
    local entryData = ZO_EntryData:New(tributePatronCategoryData)
    entryData.node = tree:AddNode("ZO_TributePatronBook_StatusIconHeader", entryData)
    for _, patronData in tributePatronCategoryData:PatronIterator(patronFilters) do
        self:AddPatron(patronData, entryData.node)
    end
    self.categoryNodeLookupData[tributePatronCategoryData:GetId()] = entryData.node
end
function ZO_TributePatronBook_Keyboard:AddPatron(tributePatronData, parentNode)
    local tree = self.categoryTree
    local entryData = ZO_EntryData:New(tributePatronData)
    entryData.node = tree:AddNode("ZO_TributePatronBook_PatronEntry", entryData, parentNode)
end
function ZO_TributePatronBook_Keyboard:NavigateToCollectibleData(collectibleData)
    if not TRIBUTE_PATRON_BOOK_SCENE:IsShowing() then
        MAIN_MENU_KEYBOARD:ToggleSceneGroup("collectionsSceneGroup", "tributePatronBook")
    end
    if TRIBUTE_PATRON_BOOK_FRAGMENT:IsShowing() then
        local patronId = collectibleData:GetReferenceId()
        local patronData = TRIBUTE_DATA_MANAGER:GetTributePatronData(patronId)
        local tributePatronCategoryData = patronData:GetCategoryData()
        local categoryNode = self.categoryNodeLookupData[tributePatronCategoryData:GetId()]
        if categoryNode then
            for _, patronNode in ipairs(categoryNode:GetChildren()) do
                local nodePatronData = patronNode:GetData():GetDataSource()
                if nodePatronData == patronData then
                    self.categoryTree:SelectNode(patronNode)
                    break
                end
            end
            self.categoriesRefreshGroup:MarkDirty("List")
        end
    else
        self.pendingNavigateToData = collectibleData
    end
end
-- Begin ZO_TributePatronBook_Shared Overrides --
function ZO_TributePatronBook_Keyboard:GetSceneName()
    return "tributePatronBook"
end
function ZO_TributePatronBook_Keyboard:InitializeControls()
    ZO_TributePatronBook_Shared.InitializeControls(self)
end
do
    local CHILD_INDENT = 76
    local CHILD_SPACING = 0
    function ZO_TributePatronBook_Keyboard:InitializeCategories()
        ZO_TributePatronBook_Shared.InitializeCategories(self)
        self.categories = self.control:GetNamedChild("Categories")
        self.categoryTree = ZO_Tree:New(self.categories:GetNamedChild("ScrollChild"), 60, -10, 300)
        local function BaseTreeHeaderIconSetup(control, categoryData, open)
            local normalIcon, pressedIcon, mouseoverIcon = categoryData:GetKeyboardIcons()
            control.icon:SetTexture(open and pressedIcon or normalIcon)
            control.iconHighlight:SetTexture(mouseoverIcon)
            ZO_IconHeader_Setup(control, open)
        end
        local function BaseTreeHeaderSetup(node, control, categoryData, open)
            control.text:SetModifyTextType(MODIFY_TEXT_TYPE_UPPERCASE)
            control.text:SetText(categoryData:GetFormattedName())
            BaseTreeHeaderIconSetup(control, categoryData, open)
        end
        local function TreeHeaderSetup_Child(node, control, categoryData, open, userRequested)
            BaseTreeHeaderSetup(node, control, categoryData, open)
            if open and userRequested then
                self.categoryTree:SelectFirstChild(node)
            end
        end
        local function TreeEntryOnSelected(control, patronData, selected, reselectingDuringRebuild)
            control:SetSelected(selected)
            if selected then
                self.patronId = patronData.patronId
                self:BuildGridList()
            else
                if patronData:IsNew() then
                    ClearCollectibleNewStatus(patronData:GetPatronCollectibleId())
                    self:UpdateCategoryStatusIcon(patronData.node.parentNode)
                end
            end
        end
        local function TreeEntrySetup(node, control, entryData, open)
            control:SetSelected(false)
            control:SetText(entryData:GetFormattedName())
        end
        self.categoryTree:AddTemplate("ZO_TributePatronBook_StatusIconHeader", TreeHeaderSetup_Child, nil, nil, CHILD_INDENT, CHILD_SPACING)
        self.categoryTree:AddTemplate("ZO_TributePatronBook_PatronEntry", TreeEntrySetup, TreeEntryOnSelected)
        self.categoryTree:SetExclusive(true)
        self.categoryTree:SetOpenAnimation("ZO_TreeOpenAnimation")
    end
end
function ZO_TributePatronBook_Keyboard:InitializeGridList()
    ZO_TributePatronBook_Shared.InitializeGridList(self)
    self.setupLabel = self.gridListControl:GetNamedChild("ContainerListContentsSetupLabel")
end
function ZO_TributePatronBook_Keyboard:GetSelectedCategory()
    self.categoryTree:GetSelectedData()
end
function ZO_TributePatronBook_Keyboard:SetFiltersHidden(hidden)
    self.showLockedCheckBox:SetHidden(hidden)
end
function ZO_TributePatronBook_Keyboard:IsSearchSupported()
    return true
end
-- Do not call this directly, instead call self.categoriesRefreshGroup:MarkDirty("List")
function ZO_TributePatronBook_Keyboard:RefreshCategories()
    local selectedNode = self.categoryTree:GetSelectedNode()
    local selectedPatronId = selectedNode and selectedNode.data:GetId()
    selectedNode = nil
    self.categoryTree:Reset()
    ZO_ClearTable(self.categoryNodeLookupData)
    local categoryList = {}
    local categoryFilters = self.categoryFilters
    local patronFilters = self.patronFilters
    for _, tributePatronCategoryData in TRIBUTE_DATA_MANAGER:TributePatronCategoryIterator(categoryFilters) do
        table.insert(categoryList, tributePatronCategoryData)
    end
    local selectedCategory = self:GetSelectedCategory()
    if #categoryList == 0 and not self:HasSearchFilter() then
        -- Add all categories, regardless of current filters, if no categories are visible and a search is not in progress.
        categoryFilters = nil
        for _, tributePatronCategoryData in TRIBUTE_DATA_MANAGER:TributePatronCategoryIterator() do
            table.insert(categoryList, tributePatronCategoryData)
        end
    end
    for _, tributePatronCategoryData in ipairs(categoryList) do
        self:AddCategory(tributePatronCategoryData, patronFilters)
        if selectedPatronId then
            local categoryNode = self.categoryNodeLookupData[tributePatronCategoryData:GetId()]
            for _, patronNode in pairs(categoryNode.children) do
                if selectedPatronId == patronNode.data:GetId() then
                    selectedNode = patronNode
                end
            end
        end
    end
    self.categoryTree:Commit(selectedNode)
end
function ZO_TributePatronBook_Keyboard:UpdateAllCategoryStatusIcons()
    for _, categoryNode in pairs(self.categoryNodeLookupData) do
        self:UpdateCategoryStatusIcon(categoryNode)
    end
end
function ZO_TributePatronBook_Keyboard:UpdateCategoryStatusIcon(categoryNode)
    local categoryData = categoryNode.data
    local categoryControl = categoryNode.control
    if not categoryControl.statusIcon then
        categoryControl.statusIcon = categoryControl:GetNamedChild("StatusIcon")
    end
    categoryControl.statusIcon:ClearIcons()
    if categoryData:HasAnyNewPatronCollectibles() then
        categoryControl.statusIcon:AddIcon(ZO_KEYBOARD_NEW_ICON)
    end
    for i, patronEntry in pairs(categoryData.node.children) do
        local patronStatusIcon = patronEntry.control:GetNamedChild("StatusIcon")
        patronStatusIcon:ClearIcons()
        if patronEntry.data:IsNew() then
            patronStatusIcon:AddIcon(ZO_KEYBOARD_NEW_ICON)
            patronStatusIcon:Show()
            categoryControl.statusIcon:AddIcon(VISIBLE_ICON)
        end
    end
    categoryControl.statusIcon:Show()
end
-- Do not call this directly, instead call self.categoriesRefreshGroup:MarkDirty("Visible")
function ZO_TributePatronBook_Keyboard:RefreshVisibleCategories()
    local NOT_USER_REQUESTED = false
    self.categoryTree:RefreshVisible(NOT_USER_REQUESTED)
end
-- Do not call this directly, instead call self.categoryContentRefreshGroup:MarkDirty("All")
function ZO_TributePatronBook_Keyboard:RefreshCategoryContent()
    -- TODO Tribute: Implement
end
function ZO_TributePatronBook_Keyboard:BuildGridList()
    if self.gridList then
        self.gridList:ClearGridList()
        -- Pre-process starter cards
        self:SetupStarterCards()
        -- Pre-process dock cards
        self:SetupDockCards()
        -- Build Patron
        self:AddPatronEntry()
        -- Build starter card entries
        self:AddStarterCardEntries()
        -- Build description entry
        self:AddDescriptionEntry()
        -- Build card entries
        self:AddDockCardEntries()
        -- Build card upgrade entries
        self:AddCardUpgradeEntries()
        self.gridList:CommitGridList()
        self.gridList:ResetToTop()
    end
end
-- End ZO_TributePatronBook_Shared Overrides --
--[[Global functions]]--
------------------------
    TRIBUTE_PATRON_BOOK_KEYBOARD = ZO_TributePatronBook_Keyboard:New(control)
end