Back to Home

ESO Lua File v101041

libraries/zo_sortfilterlist/zo_sortfilterlist.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
----------------------
--Sort/Filter List
----------------------
local UPDATE_SORT = 1
local UPDATE_FILTER = 2
local UPDATE_DATA = 3
ZO_SortFilterList = ZO_SortFilterListBase:Subclass()
function ZO_SortFilterList:Initialize(control, ...)
    ZO_SortFilterListBase.Initialize(self, ...)
end
function ZO_SortFilterList:BuildMasterList()
    -- intended to be overridden
    -- should build the master list of data that is later filtered by FilterScrollList
end
function ZO_SortFilterList:FilterScrollList()
    -- intended to be overridden
    -- should take the master list data and filter it
end
function ZO_SortFilterList:SortScrollList()
    -- intended to be overriden
    -- should take the filtered data and sort it
end
function ZO_SortFilterList:InitializeSortFilterList(control)
    self.control = control
    control.object = self
    self.list = control:GetNamedChild("List")
    self.headersContainer = control:GetNamedChild("Headers")
    if self.headersContainer then
        self.sortHeaderGroup = ZO_SortHeaderGroup:New(self.headersContainer, true)
        self.sortHeaderGroup:RegisterCallback(ZO_SortHeaderGroup.HEADER_CLICKED, function(key, order) self:OnSortHeaderClicked(key, order) end)
        self.sortHeaderGroup:AddHeadersFromContainer()
    end
    self.automaticallyColorRows = true
end
function ZO_SortFilterList:GetListControl()
    return self.list
end
function ZO_SortFilterList:ClearUpdateInterval()
    self.control:SetHandler("OnUpdate", nil)
    self.updateIntervalSecs = nil
end
function ZO_SortFilterList:SetUpdateInterval(updateIntervalSecs)
    local hadUpdateInterval = self.updateIntervalSecs ~= nil
    self.updateIntervalSecs = updateIntervalSecs
    if not hadUpdateInterval then
        self.updateIntervalLastUpdate = 0
        ZO_PreHookHandler(self.control, "OnUpdate", function(control, seconds)
            if seconds > self.updateIntervalLastUpdate + self.updateIntervalSecs then
                self.updateIntervalLastUpdate = seconds
                self:RefreshVisible()
            end
        end)
    end
end
function ZO_SortFilterList:SetAlternateRowBackgrounds(alternate)
    self.alternateRowBackgrounds = alternate
end
function ZO_SortFilterList:SetEmptyText(emptyText)
    if not self.emptyRow then
        self.emptyRow = CreateControlFromVirtual("$(parent)EmptyRow", self.list, "ZO_SortFilterListEmptyRow_Keyboard")
    end
    self.emptyRow:GetNamedChild("Message"):SetText(emptyText)
end
function ZO_SortFilterList:SetAutomaticallyColorRows(autoColorRows)
    self.automaticallyColorRows = autoColorRows
end
function ZO_SortFilterList:ShowMenu(...)
    if not self.unlockSelectionCallback then
        self.unlockSelectionCallback = function() self:UnlockSelection() end
    end
    if ShowMenu(...) then
        self:LockSelection()
    end
end
function ZO_SortFilterList:UpdatePendingUpdateLevel(pendingUpdate)
    if self.pendingUpdate == nil or pendingUpdate > self.pendingUpdate then
        self.pendingUpdate = pendingUpdate
    end
end
function ZO_SortFilterList:RefreshVisible()
end
function ZO_SortFilterList:RefreshSort()
    if self:IsLockedForUpdates() then
        self:UpdatePendingUpdateLevel(UPDATE_SORT)
        return
    end
    
    self:SortScrollList()
end
function ZO_SortFilterList:RefreshFilters()
    if self:IsLockedForUpdates() then
        self:UpdatePendingUpdateLevel(UPDATE_FILTER)
        return
    end
    self:SortScrollList()
end
function ZO_SortFilterList:RefreshData()
    if self:IsLockedForUpdates() then
        self:UpdatePendingUpdateLevel(UPDATE_DATA)
        return
    end
    self:SortScrollList()
end
function ZO_SortFilterList:CommitScrollList()
    local scrollData = ZO_ScrollList_GetDataList(self.list)
    for i = 1, #scrollData do
        scrollData[i].data.sortIndex = i
    end
    if self.emptyRow then
        self.emptyRow:SetHidden(#scrollData > 0)
    end
    if self.mouseOverRow then
        self:ExitRow(self.mouseOverRow)
    end
end
function ZO_SortFilterList:SetLockedForUpdates(locked)
    if locked ~= self.lockedForUpdates then
        self.lockedForUpdates = locked
        if not locked then
            if self.mouseOverRow then
                self:ExitRow(self.mouseOverRow)
            end
            if self.pendingUpdate then
                local pendingUpdate = self.pendingUpdate
                self.pendingUpdate = nil
                if pendingUpdate == UPDATE_DATA then
                    self:RefreshData()
                elseif pendingUpdate == UPDATE_FILTER then
                    self:RefreshFilters()
                elseif pendingUpdate == UPDATE_SORT then
                    self:RefreshSort()
                end
            end
        end
    end
end
function ZO_SortFilterList:IsLockedForUpdates()
    return self.lockedForUpdates
end
function ZO_SortFilterList:LockSelection()
    self:SetLockedForUpdates(true)
end
function ZO_SortFilterList:UnlockSelection()
    self:SetLockedForUpdates(false)
    local mouseOverRow = ZO_ScrollList_GetMouseOverControl(self.list)
    if mouseOverRow then
        --Check to make sure the mouse over row isn't getting its mouse over blocked by something else first
        local mouseOverControl = WINDOW_MANAGER:GetMouseOverControl()
        if mouseOverControl and (mouseOverRow == mouseOverControl or mouseOverControl:IsChildOf(mouseOverRow)) then
            self:EnterRow(mouseOverRow)
        end
    end
end
function ZO_SortFilterList:OnSortHeaderClicked(key, order)
    self.currentSortKey = key
    self.currentSortOrder = order
    self:RefreshSort()
end
function ZO_SortFilterList:SetHighlightedRow(row)
    if self.mouseOverRow then
        self:ExitRow(self.mouseOverRow)
    end
    if row then
        self:EnterRow(row)
    end
end
function ZO_SortFilterList:EnterRow(row)
    if not self.lockedForUpdates then
        ZO_ScrollList_MouseEnter(self.list, row)
        local data = ZO_ScrollList_GetData(row)
        if data then
            self:ColorRow(row, ZO_ScrollList_GetData(row), true)
        end
        self.mouseOverRow = row
        self:UpdateKeybinds()
    end
end
function ZO_SortFilterList:ExitRow(row)
    if not self.lockedForUpdates then
        ZO_ScrollList_MouseExit(self.list, row)
        local data = ZO_ScrollList_GetData(row)
        if data then
            self:ColorRow(row, ZO_ScrollList_GetData(row), false)
        end
        self.mouseOverRow = nil
        self:UpdateKeybinds()
    end
end
function ZO_SortFilterList:SelectRow(row)
end
function ZO_SortFilterList:OnSelectionChanged(previouslySelected, selected)
    self.selectedData = selected
    self:RefreshVisible()
end
function ZO_SortFilterList:GetRowColors(data, mouseIsOver, control)
    local textColor = ZO_SECOND_CONTRAST_TEXT
    local iconColor = ZO_DEFAULT_ENABLED_COLOR
    if mouseIsOver or data == self.selectedData then
        textColor = control.selectedColor or ZO_SELECTED_TEXT
        iconColor = ZO_SELECTED_TEXT
    else
        if control.normalColor then
            textColor = control.normalColor
        end
    end
    return textColor, iconColor
end
function ZO_SortFilterList:ColorRow(control, data, mouseIsOver)
    if self.automaticallyColorRows then
        for i = 1, control:GetNumChildren() do
            local child = control:GetChild(i)
            if not child.nonRecolorable then
                local childType = child:GetType()
                local textColor, iconColor = self:GetRowColors(data, mouseIsOver, child)
                if childType == CT_LABEL and textColor ~= nil then
                    local r, g, b = textColor:UnpackRGB()
                    child:SetColor(r, g, b, child:GetControlAlpha())
                elseif childType == CT_TEXTURE and iconColor ~= nil then
                    local r, g, b = iconColor:UnpackRGB()
                    child:SetColor(r, g, b, child:GetControlAlpha())
                end
            end
        end
    end
end
function ZO_SortFilterList:SetupRow(control, data)
    local mouseOverControl = WINDOW_MANAGER:GetMouseOverControl()
    local mocBelongsToRow = false
    while mouseOverControl ~= nil do
        if mouseOverControl == control then
            mocBelongsToRow = true
            break
        end
        mouseOverControl = mouseOverControl:GetParent()
    end
    if self.lockedForUpdates then
        self:ColorRow(control, data, self.mouseOverRow == control)
    else
        if mocBelongsToRow then
            self:EnterRow(control)
        else 
            self:ColorRow(control, data, false)
        end
    end
end
function ZO_SortFilterList:SetupRowBG(control, data)
    if self.alternateRowBackgrounds then
        local bg = control:GetNamedChild("BG")
        local hidden = (data.sortIndex % 2) == 0
        bg:SetHidden(hidden)
    end
end
function ZO_SortFilterList:GetSelectedData()
end
function ZO_SortFilterList:HasEntries()
    local dataList = ZO_ScrollList_GetDataList(self.list)
    return #dataList > 0
end
function ZO_SortFilterList:SetKeybindStripDescriptor(keybindStripDescriptor)
    self:RemoveKeybinds()
    self.keybindStripDescriptor = keybindStripDescriptor
end
function ZO_SortFilterList:SetKeybindStripId(keybindStripId)
    self.keybindStripId = keybindStripId
end
function ZO_SortFilterList:AddKeybinds()
    if self.keybindStripDescriptor then
        KEYBIND_STRIP:AddKeybindButtonGroup(self.keybindStripDescriptor, self.keybindStripId)
    end
end
function ZO_SortFilterList:RemoveKeybinds()
    if self.keybindStripDescriptor then
        KEYBIND_STRIP:RemoveKeybindButtonGroup(self.keybindStripDescriptor, self.keybindStripId)
    end
end
function ZO_SortFilterList:UpdateKeybinds()
    if self.keybindStripDescriptor then
        KEYBIND_STRIP:UpdateKeybindButtonGroup(self.keybindStripDescriptor, self.keybindStripId)
    end
end
--XML
function ZO_SortFilterList:Row_OnMouseEnter(control)
end
function ZO_SortFilterList:Row_OnMouseExit(control)
    self:ExitRow(control)
end