Back to Home

ESO Lua File v101043

ingame/collections/tributepatronbook_shared.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
ZO_TributePatronBook_Shared = ZO_TextSearchObject:Subclass()
local PATRON_SEARCH_CONTEXT = "tributePatronTextSearch"
function ZO_TributePatronBook_Shared:Initialize(control, infoContainerControl, templateData)
    ZO_TextSearchObject.Initialize(self, PATRON_SEARCH_CONTEXT, self.searchEditBox)
    self.control = control
    self.templateData = templateData
    self.infoContainerControl = infoContainerControl
    self.starterCardIdCounts = {}
    self.starterUniqueCardIds = {}
    self.dockCardIdCounts = {}
    self.currentDockCards = {}
    self.categoryFilters = {}
    self.patronFilters = {}
    self.scene = ZO_Scene:New(self:GetSceneName(), SCENE_MANAGER)
    self.fragment = ZO_FadeSceneFragment:New(control)
    self.fragment:RegisterCallback("StateChange", function(oldState, newState)
        if newState == SCENE_FRAGMENT_SHOWING then
            self.categoriesRefreshGroup:TryClean()
            self:OnFragmentShowing()
            if self:IsSearchSupported() then
                self:ActivateTextSearch()
            end
        elseif newState == SCENE_FRAGMENT_HIDDEN then
            if self:IsSearchSupported() then
                self:DeactivateTextSearch()
            end
        end
    end)
end
function ZO_TributePatronBook_Shared:SetupContextTextSearch()
    if self:IsSearchSupported() then
        -- Shared search for tribute patrons
        local filterTargetDescriptor =
        {
            [BACKGROUND_LIST_FILTER_TARGET_TRIBUTE_PATRON_ID] =
            {
                searchFilterList =
                {
                    BACKGROUND_LIST_FILTER_TYPE_NAME,
                    BACKGROUND_LIST_FILTER_TYPE_DESCRIPTION,
                    BACKGROUND_LIST_FILTER_TYPE_SEARCH_KEYWORDS,
                },
                primaryKeys = function()
                    local patronIdList = {}
                    for _, patronData in TRIBUTE_DATA_MANAGER:TributePatronIterator() do
                        table.insert(patronIdList, patronData:GetId())
                    end
                    return patronIdList
                end,
            },
        }
        TEXT_SEARCH_MANAGER:SetupContextTextSearch(self.searchContext, filterTargetDescriptor)
    end
end
ZO_TributePatronBook_Shared.GetSceneName = ZO_TributePatronBook_Shared:MUST_IMPLEMENT()
function ZO_TributePatronBook_Shared:GetScene()
    return self.scene
end
function ZO_TributePatronBook_Shared:GetFragment()
    return self.fragment
end
function ZO_TributePatronBook_Shared:InitializeControls()
    -- Can be overridden
end
function ZO_TributePatronBook_Shared:InitializeCategories()
    -- Categories refresh group
    local categoriesRefreshGroup = ZO_OrderedRefreshGroup:New(ZO_ORDERED_REFRESH_GROUP_AUTO_CLEAN_PER_FRAME)
    categoriesRefreshGroup:AddDirtyState("List", function()
        self:RefreshCategories()
    end)
    categoriesRefreshGroup:AddDirtyState("Visible", function()
        self:RefreshVisibleCategories()
    end)
    categoriesRefreshGroup:SetActive(function()
        return self:IsCategoriesRefreshGroupActive()
    end)
    categoriesRefreshGroup:MarkDirty("List")
    self.categoriesRefreshGroup = categoriesRefreshGroup
end
function ZO_TributePatronBook_Shared:InitializeGridList()
    -- Initialize grid list object
    local templateData = self.templateData
    local gridListControl = self.infoContainerControl:GetNamedChild("GridList")
    self.gridListControl = gridListControl
    self.gridList = self.templateData.gridListClass:New(gridListControl)
    local function GetDescriptionHeight(instanceData)
        return instanceData.height
    end
    local function DescriptionEntrySetup(control, instanceData, list)
        control:SetText(instanceData.text)
    end
    local HIDE_CALLBACK = nil
    local NO_FUNCTION = nil
    local DONT_CENTER = false
    local NOT_SELECTABLE = false
    local headerEntryData = templateData.headerEntryData
    local descriptionEntryData = templateData.descriptionEntryData
    local patronEntryData = templateData.patronEntryData
    local widePatronEntryData = templateData.widePatronEntryData
    local cardEntryData = templateData.cardEntryData
    local wideCardEntryData = templateData.wideCardEntryData
    self.gridList:AddHeaderTemplate(headerEntryData.entryTemplate, headerEntryData.height, ZO_DefaultGridTileHeaderSetup)
    self.gridList:SetHeaderPrePadding(headerEntryData.gridPaddingY)
    self.gridList:AddEntryTemplate(descriptionEntryData.entryTemplate, descriptionEntryData.width, GetDescriptionHeight, DescriptionEntrySetup, HIDE_CALLBACK, NO_FUNCTION, descriptionEntryData.gridPaddingX, descriptionEntryData.gridPaddingY, DONT_CENTER, NOT_SELECTABLE)
    self.gridList:AddEntryTemplate(patronEntryData.entryTemplate, patronEntryData.width, patronEntryData.height, ZO_DefaultGridTileEntrySetup, HIDE_CALLBACK, ZO_DefaultGridTileEntryReset, patronEntryData.gridPaddingX, patronEntryData.gridPaddingY)
    self.gridList:AddEntryTemplate(cardEntryData.entryTemplate, cardEntryData.width, cardEntryData.height, ZO_DefaultGridTileEntrySetup, HIDE_CALLBACK, ZO_DefaultGridTileEntryReset, cardEntryData.gridPaddingX, cardEntryData.gridPaddingY)
    if widePatronEntryData and wideCardEntryData then
        self.gridList:AddEntryTemplate(widePatronEntryData.entryTemplate, widePatronEntryData.width, widePatronEntryData.height, ZO_DefaultGridTileEntrySetup, HIDE_CALLBACK, ZO_DefaultGridTileEntryReset, widePatronEntryData.gridPaddingX, widePatronEntryData.gridPaddingY)
        self.gridList:AddEntryTemplate(wideCardEntryData.entryTemplate, wideCardEntryData.width, wideCardEntryData.height, ZO_DefaultGridTileEntrySetup, HIDE_CALLBACK, ZO_DefaultGridTileEntryReset, wideCardEntryData.gridPaddingX, wideCardEntryData.gridPaddingY)
    end
end
function ZO_TributePatronBook_Shared:RegisterForEvents()
    local function OnProgressionUpgradeStatusChanged(patronId)
        if patronId == self.patronId then
            self:BuildGridList()
        end
    end
    local function OnPatronsUpdated()
        if self:IsCategoriesRefreshGroupActive() and self.patronId ~= nil then
            self:BuildGridList()
        end
    end
    local function OnPatronsDataDirty()
        self.categoriesRefreshGroup:MarkDirty("List")
    end
    local function OnCollectibleUpdated(collectibleId)
        local categoryType = GetCollectibleCategoryType(collectibleId)
        if categoryType == COLLECTIBLE_CATEGORY_TYPE_TRIBUTE_PATRON then
            OnPatronsDataDirty()
        end
    end
    local function OnCollectionUpdated(collectibleUpdateType, collectiblesByNewUnlockState)
        for _, unlockState in pairs(collectiblesByNewUnlockState) do
            for _, collectible in pairs(unlockState) do
                local categoryType = GetCollectibleCategoryType(collectible.collectibleId)
                if categoryType == COLLECTIBLE_CATEGORY_TYPE_TRIBUTE_PATRON then
                    OnPatronsDataDirty()
                    return
                end
            end
        end
    end
    TRIBUTE_DATA_MANAGER:RegisterCallback("PatronsUpdated", OnPatronsUpdated)
    TRIBUTE_DATA_MANAGER:RegisterCallback("PatronsDataDirty", OnPatronsDataDirty)
    TRIBUTE_DATA_MANAGER:RegisterCallback("ProgressionUpgradeStatusChanged", OnProgressionUpgradeStatusChanged)
    ZO_COLLECTIBLE_DATA_MANAGER:RegisterCallback("OnCollectibleUpdated", OnCollectibleUpdated)
    ZO_COLLECTIBLE_DATA_MANAGER:RegisterCallback("OnCollectionUpdated", OnCollectionUpdated)
    ZO_COLLECTIBLE_DATA_MANAGER:RegisterCallback("OnCollectibleNewStatusCleared", OnCollectibleUpdated)
end
ZO_TributePatronBook_Shared.BuildGridList = ZO_TributePatronBook_Shared:MUST_IMPLEMENT()
function ZO_TributePatronBook_Shared.CompareTributeStarterCards(leftCardId, rightCardId)
    local leftCardName = GetTributeCardName(leftCardId)
    local rightCardName = GetTributeCardName(rightCardId)
    return leftCardName < rightCardName
end
function ZO_TributePatronBook_Shared.CompareTributeCards(leftCardTable, rightCardTable)
    local leftBaseCardId = leftCardTable.baseCardId
    local rightBaseCardId = rightCardTable.baseCardId
    -- TODO Tribute: Update compare function to take upgrade status of cards for this player into account
    if leftBaseCardId == rightBaseCardId then
        local leftUpgradeCardId = leftCardTable.upgradeCardId
        local rightUpgradeCardId = rightCardTable.upgradeCardId
        local leftCardName = GetTributeCardName(leftUpgradeCardId)
        local rightCardName = GetTributeCardName(rightUpgradeCardId)
        return leftCardName < rightCardName
    else
        local leftCardName = GetTributeCardName(leftBaseCardId)
        local rightCardName = GetTributeCardName(rightBaseCardId)
        return leftCardName < rightCardName
    end
end
function ZO_TributePatronBook_Shared:SetupStarterCards()
    local patronData = TRIBUTE_DATA_MANAGER:GetTributePatronData(self.patronId)
    local numStarterCards = patronData:GetNumStarterCards()
    self.starterCardIdCounts = {}
    self.starterUniqueCardIds = {}
    for index = 1, numStarterCards do
        local cardId = patronData:GetStarterCardIdByIndex(index)
        if not self.starterCardIdCounts[cardId] then
            self.starterCardIdCounts[cardId] = 1
            table.insert(self.starterUniqueCardIds, cardId)
        else
            self.starterCardIdCounts[cardId] = self.starterCardIdCounts[cardId] + 1
        end
    end
    table.sort(self.starterUniqueCardIds, ZO_TributePatronBook_Shared.CompareTributeStarterCards)
end
function ZO_TributePatronBook_Shared:SetupDockCards()
    local patronData = TRIBUTE_DATA_MANAGER:GetTributePatronData(self.patronId)
    self.currentDockCards, self.availableUpgradeCards = patronData:GetDockCards()
end
function ZO_TributePatronBook_Shared:AddDescriptionEntry()
    local patronData = TRIBUTE_DATA_MANAGER:GetTributePatronData(self.patronId)
    local loreDescription = patronData:GetLoreDescription()
    local playStyleDescription = patronData:GetTributePatronPlayStyleDescription()
    local acquireHint = patronData:GetTributePatronAcquireHint()
    local displayText = loreDescription
    if  playStyleDescription ~= "" then
        if displayText ~= "" then
            displayText = string.format("%s\n\n%s", displayText, playStyleDescription)
        else
            displayText = playStyleDescription
        end
    end
    if patronData:IsPatronLocked() and acquireHint ~= "" then
        if displayText ~= "" then
            displayText = string.format("%s\n\n%s", displayText, acquireHint)
        else
            displayText = acquireHint
        end
    end
    self.setupLabel:SetText(displayText)
    local data =
    {
        height = self.setupLabel:GetHeight(),
        text = displayText,
    }
    self.gridList:AddEntry(data, self.templateData.descriptionEntryData.entryTemplate)
end
function ZO_TributePatronBook_Shared:AddPatronEntry()
    local patronData = TRIBUTE_DATA_MANAGER:GetTributePatronData(self.patronId)
    local entryData = ZO_EntryData:New(patronData)
    entryData.gridHeaderName = GetString(SI_TRIBUTE_PATRON_TITLE)
    entryData.gridHeaderTemplate = self.templateData.headerEntryData.entryTemplate
    local patronEntryTemplate = self.templateData.patronEntryData.entryTemplate
    if self.templateData.widePatronEntryData and #self.starterUniqueCardIds <= 1 then
        patronEntryTemplate = self.templateData.widePatronEntryData.entryTemplate
    end
    self.gridList:AddEntry(entryData, patronEntryTemplate)
end
function ZO_TributePatronBook_Shared:AddStarterCardEntries()
    local cardTemplateData = self.templateData.cardEntryData
    if self.templateData.wideCardEntryData and #self.starterUniqueCardIds <= 1 then
        cardTemplateData = self.templateData.wideCardEntryData
    end
    for index, cardId in ipairs(self.starterUniqueCardIds) do
        local cardData =
        {
            cardId = cardId,
            count = self.starterCardIdCounts[cardId],
            isStarter = true
        }
        self:AddCardEntryById(cardData, cardTemplateData, GetString(SI_TRIBUTE_PATRON_TITLE), self.templateData.wideCardEntryData and #self.starterUniqueCardIds <= 1)
    end
end
function ZO_TributePatronBook_Shared:AddDockCardEntries()
    local NOT_WIDE = false
    local cardTemplateData = self.templateData.cardEntryData
    for index, cardData in ipairs(self.currentDockCards) do
        self:AddCardEntryById(cardData, cardTemplateData, GetString(SI_TRIBUTE_PATRON_CARD_TITLE), NOT_WIDE)
    end
end
function ZO_TributePatronBook_Shared:AddCardUpgradeEntries()
    local NOT_WIDE = false
    local cardTemplateData = self.templateData.cardEntryData
    for index, cardData in ipairs(self.availableUpgradeCards) do
        self:AddCardEntryById(cardData, cardTemplateData, GetString(SI_TRIBUTE_PATRON_UPGRADE_TITLE), NOT_WIDE)
    end
end
function ZO_TributePatronBook_Shared:AddCardEntryById(cardData, cardTemplateData, header, isWide)
    local entryData = ZO_EntryData:New(cardData)
    entryData.gridHeaderName = header
    entryData.gridHeaderTemplate = self.templateData.headerEntryData.entryTemplate
    entryData.patronId = self.patronId
    entryData.cardTemplateData = cardTemplateData
    entryData.isWide = isWide
    self.gridList:AddEntry(entryData, cardTemplateData.entryTemplate)
end
function ZO_TributePatronBook_Shared:OnFragmentShowing()
    -- Can be overridden
end
-- Overrides ZO_TextSearchObject
function ZO_TributePatronBook_Shared:OnUpdateSearchResults()
    self:RefreshFilters()
end
function ZO_TributePatronBook_Shared:RefreshFilters()
    ZO_ClearNumericallyIndexedTable(self.categoryFilters)
    ZO_ClearNumericallyIndexedTable(self.patronFilters)
    if self:IsSearchSupported() and self:HasSearchFilter() then
        table.insert(self.categoryFilters, ZO_TributePatronCategoryData.IsSearchResult)
        table.insert(self.patronFilters, ZO_TributePatronData.IsSearchResult)
    end
    self.categoriesRefreshGroup:MarkDirty("List")
end
function ZO_TributePatronBook_Shared:IsCategoriesRefreshGroupActive()
    return self.fragment:IsShowing()
end
function ZO_TributePatronBook_Shared:GetSelectedCategory()
    assert(false) -- Must be overridden
end
function ZO_TributePatronBook_Shared:IsSearchSupported()
    -- Can be overridden
    return false
end
function ZO_TributePatronBook_Shared:IsViewingCategory(tributePatronCategoryData)
    local categoryData = self:GetSelectedCategory()
    return categoryData and categoryData:GetId() == tributePatronCategoryData:GetId()
end
-- Do not call this directly, instead call self.categoriesRefreshGroup:MarkDirty("List")
function ZO_TributePatronBook_Shared:RefreshCategories()
    assert(false) -- Must be overridden
end
-- Do not call this directly, instead call self.categoriesRefreshGroup:MarkDirty("Visible")
function ZO_TributePatronBook_Shared:RefreshVisibleCategories()
    assert(false) -- Must be overridden
end