Back to Home

ESO Lua File v101042

libraries/zo_parametricgridlist/zo_abstractgridscrolllist.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
ZO_GRID_SCROLL_LIST_AUTOFILL = true
ZO_GRID_SCROLL_LIST_DONT_AUTOFILL = false
ZO_AbstractGridScrollList = ZO_InitializingCallbackObject:Subclass()
function ZO_AbstractGridScrollList:Initialize(control, autofillRows, resizeToFitColumnMax, resizeToFitRowMax)
    self.control = control
    self.container = control:GetNamedChild("Container")
    self.list = self.container:GetNamedChild("List")
    self.scrollbar = self.list:GetNamedChild("ScrollBar")
    self.currentHeaderName = nil -- Maintaining backwards compatability
    self.currentHeaderData = nil
    self.nextOperationId = 1
    self.indentAmount = 0
    self.headerPrePadding = 0
    self.headerPostPadding = 0
    self.templateOperationIds = {}
    self.autoFillRows = autofillRows or false
    self.resizeToFitColumnMax = resizeToFitColumnMax or 0
    self.resizeToFitRowMax = resizeToFitRowMax or 0
    local minWidth, minHeight, maxWidth, maxHeight = self.control:GetDimensionConstraints()
    self.minWidth = minWidth
    self.minHeight = minHeight
    self.maxWidth = maxWidth
    self.maxHeight = maxHeight
    self.controlsAddedSinceLastFill = 0
    if self.resizeToFitColumnMax > 0 then
        self.numCellsPerRow = self.resizeToFitColumnMax
        self.list:SetWidth(self.maxWidth + self.scrollbar:GetWidth())
    end
    if self.resizeToFitRowMax > 0 then
        self.list:SetHeight(self.maxHeight)
    end
end
function ZO_AbstractGridScrollList:AddResizeOnScreenResize()
    local function OnScreenResized()
        self:CommitGridList()
    end
    self.list:RegisterForEvent(EVENT_SCREEN_RESIZED, OnScreenResized)
end
function ZO_AbstractGridScrollList:SetHeaderPrePadding(prePadding)
    self.headerPrePadding = prePadding
end
function ZO_AbstractGridScrollList:SetHeaderPostPadding(postPadding)
    self.headerPostPadding = postPadding
end
function ZO_AbstractGridScrollList:SetIndentAmount(indentAmount)
    self.indentAmount = indentAmount
    internalassert(self.nextOperationId == 1, "You have to call this function before adding templates or they won't get the indent amount")
end
function ZO_AbstractGridScrollList:SetYDistanceFromEdgeWhereSelectionCausesScroll(yDistanceFromEdgeWhereSelectionCausesScroll)
    ZO_ScrollList_SetYDistanceFromEdgeWhereSelectionCausesScroll(self.list, yDistanceFromEdgeWhereSelectionCausesScroll)
end
function ZO_AbstractGridScrollList:AddHeaderTemplate(templateName, height, setupFunc, onHideFunc, resetControlFunc, considerHeaderWidth)
    if self.templateOperationIds[templateName] == nil then
        local operationId = self.nextOperationId
        local SPACING_XY = 0
        local NOT_SELECTABLE = false
        local WIDTH = nil
        ZO_ScrollList_AddControlOperation(self.list, operationId, templateName, WIDTH, height, resetControlFunc, setupFunc, onHideFunc, SPACING_XY, SPACING_XY, self.indentAmount, NOT_SELECTABLE)
        ZO_ScrollList_SetTypeCategoryHeader(self.list, operationId, true)
        ZO_ScrollList_SetConsiderHeaderWidth(self.list, operationId, considerHeaderWidth)
        self.nextOperationId = self.nextOperationId + 1
        self.templateOperationIds[templateName] = operationId
        return operationId
    end
    return nil
end
function ZO_AbstractGridScrollList:AddEntryTemplate(templateName, width, height, setupFunc, onHideFunc, resetControlFunc, spacingX, spacingY, centerEntries, isSelectable)
    if self.templateOperationIds[templateName] == nil then
        local operationId = self.nextOperationId
        if isSelectable == nil then
            isSelectable = true
        end
        ZO_ScrollList_AddControlOperation(self.list, operationId, templateName, width, height, resetControlFunc, setupFunc, onHideFunc, spacingX, spacingY, self.indentAmount, isSelectable, centerEntries)
        self.nextOperationId = self.nextOperationId + 1
        self.templateOperationIds[templateName] = operationId
        if self.autoFillRows then
            assert(type(width) == "number", "AutoFillRows is not supported with dynamic width entry templates.")
            local listWidth = self.list:GetWidth()
            local numCellsPerRow = zo_floor(listWidth / (width + spacingX))
            if self.numCellsPerRow then
                assert(self.numCellsPerRow == numCellsPerRow, "AutoFillRows is only supported when the number of cells per row is consistent regardless of the entry templates used.")
            else
                self.numCellsPerRow = numCellsPerRow
            end
        end
        return operationId
    end
    return nil
end
function ZO_AbstractGridScrollList:SetEntryTemplateVisibilityFunction(templateName, visiblityFunction)
    local operationId = self.templateOperationIds[templateName]
    if operationId then
        ZO_ScrollList_SetVisibilityFunction(self.list, operationId, visiblityFunction)
    end
end
function ZO_AbstractGridScrollList:SetEntryTemplateEqualityFunction(templateName, equalityFunction)
    local operationId = self.templateOperationIds[templateName]
    if operationId then
    end
end
function ZO_AbstractGridScrollList:SetAutoFillEntryTemplate(templateName)
    self.autoFillRowsOperationId = self.templateOperationIds[templateName]
end
function ZO_AbstractGridScrollList:AddEntry(data, templateName)
    local operationId = self.templateOperationIds[templateName]
    if operationId then
        local gridHeaderData = data.gridHeaderName or data.gridHeaderData
        if self.currentHeaderData ~= gridHeaderData then
            local scrollData = ZO_ScrollList_GetDataList(self.list)
            if self.currentHeaderData or #scrollData > 0 then
                -- we're starting a new section, so first make sure to fill out the last row of the previous section
                self:FillRowWithEmptyCells(self.currentHeaderData)
                ZO_ScrollList_AddOperation(self.list, ZO_SCROLL_LIST_OPERATION_LINE_BREAK, { lineBreakAmount = self.headerPrePadding })
            end
            self.currentHeaderData = gridHeaderData
            self.currentHeaderName = gridHeaderData -- Maintaining backwards compatability
            if self.currentHeaderData and self.currentHeaderData ~= "" then
                local headerOperationId = self.templateOperationIds[data.gridHeaderTemplate]
                -- data is only being kept for theoretical addon compat. There's no reason to have the entry data in the header operation, and no one should use it.
                ZO_ScrollList_AddOperation(self.list, headerOperationId, { header = gridHeaderData, data = data}) 
                if self.headerPostPadding > 0 then
                    ZO_ScrollList_AddOperation(self.list, ZO_SCROLL_LIST_OPERATION_LINE_BREAK, { lineBreakAmount = self.headerPostPadding, indentX = self.indentAmount })
                end
            end
        end
        ZO_ScrollList_AddOperation(self.list, operationId, data)
        self.controlsAddedSinceLastFill = self.controlsAddedSinceLastFill + 1
    end
end
function ZO_AbstractGridScrollList:FillRowWithEmptyCells(gridHeaderData)
    if self.autoFillRows and self.autoFillRowsOperationId then
        local numMissingCells = self.numCellsPerRow - zo_mod(self.controlsAddedSinceLastFill, self.numCellsPerRow)
        if numMissingCells ~= self.numCellsPerRow then -- the row was full, don't need to add any empty cells
            for i = 1, numMissingCells do
                ZO_ScrollList_AddOperation(self.list, self.autoFillRowsOperationId, { gridHeaderData = gridHeaderData, isEmptyCell = true })
            end
        end
    end
    self.controlsAddedSinceLastFill = 0
end
function ZO_AbstractGridScrollList:CommitGridList()
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    if #scrollData > 0 then -- only try to fill in a row if there exists a row to fill in
        self:FillRowWithEmptyCells(self.currentHeaderData)
    end
    if self.resizeToFitColumnMax ~= 0 then
        self.list:SetWidth(self.maxWidth)
    end
    if self.resizeToFitRowMax ~= 0 then
        self.list:SetHeight(self.maxHeight)
    end
    if self.resizeToFitColumnMax ~= 0 then
        self.list:SetWidth(self.list.maxDimensionX + self.scrollbar:GetWidth())
    end
    if self.resizeToFitRowMax ~= 0 then
        self.list:SetHeight(zo_min(self.maxHeight, self.list.maxDimensionY))
    end
end
function ZO_AbstractGridScrollList:RecalculateVisibleEntries()
    -- At present determining which entries are visible is done in the commit
    -- But use a different function signature so we don't do any other behavior that might come with a call to CommitGridList in the future.
    -- CommitGridList is generally understood to be used after you add/remove entries from the list
end
function ZO_AbstractGridScrollList:IsSelectionOfTemplateType(templateName)
    local operationId = self.templateOperationIds[templateName]
    if operationId then
        local selectedData = ZO_ScrollList_GetSelectedData(self.list)
        if selectedData.dataEntry.typeId == operationId then
            return true
        end
    end
    return false
end
function ZO_AbstractGridScrollList:RefreshGridList()
end
function ZO_AbstractGridScrollList:RefreshGridListEntryData(entryData, overrideSetupCallback)
end
function ZO_AbstractGridScrollList:ClearGridList(retainScrollPosition)
    self.currentHeaderName = nil -- Maintaining backwards compatability
    self.currentHeaderData = nil
    if not retainScrollPosition then
        ZO_Scroll_ResetToTop(self.list)
    end
end
function ZO_AbstractGridScrollList:HasEntries()
    local dataList = ZO_ScrollList_GetDataList(self.list)
    return #dataList > 0
end
function ZO_AbstractGridScrollList:AtTopOfGrid()
end
function ZO_AbstractGridScrollList:GetData()
end
function ZO_AbstractGridScrollList:GetControlFromData(data)
end
function ZO_AbstractGridScrollList:ScrollDataToCenter(data, onScrollCompleteCallback, animateInstantly)
    local dataIndex = ZO_ScrollList_GetDataIndex(self.list, data.dataEntry)
    if internalassert(dataIndex ~= nil) then
        ZO_ScrollList_ScrollDataToCenter(self.list, dataIndex, onScrollCompleteCallback, animateInstantly)
    end
end
function ZO_AbstractGridScrollList:SelectData(data)
    local dataIndex = ZO_ScrollList_GetDataIndex(self.list, data.dataEntry)
    if internalassert(dataIndex ~= nil) then
    end
end
function ZO_AbstractGridScrollList:SetAutoSelectToMatchingDataEntry(dataEntry)
end
function ZO_AbstractGridScrollList:GetScrollValue()
end
function ZO_AbstractGridScrollList:ScrollToValue(value, onScrollCompleteCallback, animateInstantly)
end
function ZO_AbstractGridScrollList:ResetToTop()
end
function ZO_AbstractGridScrollList:AddLineBreak(lineBreakAmount)
    ZO_ScrollList_AddOperation(self.list, ZO_SCROLL_LIST_OPERATION_LINE_BREAK, { lineBreakAmount = lineBreakAmount })
end
----------------------
-- Global functions --
----------------------
function ZO_DefaultGridHeaderSetup(control, data, selected)
end
    if not control.icon then
        control.icon = control:GetNamedChild("Icon")
    end
    local icon = control.icon
    if data.iconColor then
        icon:SetColor(data.iconColor:UnpackRGBA())
    end
    if data.iconDesaturation then
        icon:SetDesaturation(data.iconDesaturation)
    end
    if data.textureSampleProcessingWeights then
        for type, weight in pairs(data.textureSampleProcessingWeights) do
            icon:SetTextureSampleProcessingWeight(type, weight)
        end
    end
    local iconFile = data.iconFile or data.icon or (data.GetIcon and data:GetIcon())
    if iconFile then
        icon:SetTexture(iconFile)
        icon:SetHidden(false)
    else
        icon:SetHidden(true)
    end
end
do
    local g_gridEntryScaleAnimationProvider = ZO_ReversibleAnimationProvider:New("ZO_GridEntry_IconSelectedAnimation")
    function ZO_GridEntry_SetIconScaledUp(control, scaledUp, instant)
        if control.icon then
            if scaledUp then
                g_gridEntryScaleAnimationProvider:PlayForward(control.icon, instant)
            else
                g_gridEntryScaleAnimationProvider:PlayBackward(control.icon, instant)
            end
        end
    end
    function ZO_GridEntry_SetIconScaledUpInstantly(control, scaledUp)
        ZO_GridEntry_SetIconScaledUp(control, scaledUp, true)
    end
end
function ZO_AbstractGridScrollList:GetSelectedData()
end