ESO Lua File v100010

libraries/zo_sortableparametriclist/zo_sortableparametriclist.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
--[[
This class allows a parametric list to have sort headers to allow the user to change how the list is sorted
To setup, your main control needs to have a "Headers" child that has all the sort headers and
a "List" child that defines the scroll list
The children of "Headers" should have their OnInitialized call ZO_SortableParametricList_InitSortHeader
(or other init sort header function) passing in the sortKey that header will use
ex: ZO_SortableParametricList_InitSortHeader(self, SI_LABEL_GOES_HERE, TEXT_ALIGN_LEFT, MY_SORT_KEY_NAME)
To associate the data in the list with the sortKeys in the header, the function SetSortOptions needs to be called,
passing in a table where the sortKeys used to initialize the headers are the table key and the value is a table
the defines the list's sort options for that key
in this ex. both name and price are members of the list data
local NAME_SORT_KEYS =
{
name = {tiebreaker = "price"},
price = {}
}
local PRICE_SORT_KEYS =
{
price = {tiebreaker = "name"},
name = {}
}
local tradingHouseSortOptions = {
[MY_SORT_KEY_NAME] = NAME_SORT_KEYS,
[MY_SORT_KEY_PRICE] = PRICE_SORT_KEYS,
}
self:SetSortOptions(tradingHouseSortOptions)
Once the sorting is setup, you just need to create a BuildList() function in your derived class to populate the list
]]
ZO_SortableParametricList = ZO_SortFilterListBase:Subclass()
function ZO_SortableParametricList:New(control)
    local manager = ZO_SortFilterListBase.New(self, control)
    manager:Initialize(control)
    return manager
end
function ZO_SortableParametricList:Initialize(control)
    self.control = control
    local headerContainer = GetControl(control, "Headers")
    self.sortHeaderGroup = ZO_SortHeaderGroup:New(headerContainer, true)
    self.sortHeaderGroup:RegisterCallback(ZO_SortHeaderGroup.HEADER_CLICKED, function(key, order) self:OnSortHeaderClicked(key, order) end)
    self.sortHeaderGroup:EnableHighlight("ZO_ThinListHighlight")
    self.sortHeaderGroup:AddHeadersFromContainer()
    self.listControl = GetControl(control, "List")
    self.itemList = ZO_GamepadVerticalItemParametricScrollList:New(self.listControl)
    self:InitializeList()
end
function ZO_SortableParametricList:SetSortOptions(sortOptions)
    self.sortOptions = sortOptions
end
function ZO_SortableParametricList:Activate()
    self.sortHeaderGroup:SetDirectionalInputEnabled(true)
    self.sortHeaderGroup:EnableSelection(true)
    self.itemList:Activate()
end
function ZO_SortableParametricList:Deactivate()
   self.sortHeaderGroup:SetDirectionalInputEnabled(false)
   self.sortHeaderGroup:EnableSelection(false)
   self.itemList:Deactivate()
end
function ZO_SortableParametricList:OnSortHeaderClicked(key, order)
    self:RefreshSort()
end
function ZO_SortableParametricList:SortFunc(data1, data2)
    return ZO_TableOrderingFunction(data1, data2, self.sortKey, self.currentSortOption, self.sortOrder)
end
function ZO_SortableParametricList:UpdateListSortFunction()
    if self.currentSortOption then
        if not self.itemList.sortFunction then
            self.itemList:SetSortFunction(function(data1, data2) return self:SortFunc(data1, data2) end)
        end
    else
        self.itemList:SetSortFunction(nil)
    end
end
function ZO_SortableParametricList:UpdateSortOption()
    self.currentSortOption = nil
    if self.sortOptions then
        self.sortKey = self.sortHeaderGroup:GetCurrentSortKey()
        if self.sortKey then
            self.sortOrder = self.sortHeaderGroup:GetSortDirection()
            self.currentSortOption = self.sortOptions[self.sortKey]
        end
    end
end
function ZO_SortableParametricList:GetList()
    return self.itemList
end
-- Funtions that wrap functions in ZO_SortHeaderGroup
function ZO_SortableParametricList:SortBySelected()
    self.sortHeaderGroup:SortBySelected()
end
function ZO_SortableParametricList:SelectHeaderByKey(key)
    self.sortHeaderGroup:SelectHeaderByKey(key)
end
function ZO_SortableParametricList:SelectAndResetSortForKey(key)
    self.sortHeaderGroup:SelectAndResetSortForKey(key)
end
function ZO_SortableParametricList:SetHeaderNameForKey(key, name)
    return self.sortHeaderGroup:SetHeaderNameForKey(key, name)
end
function ZO_SortableParametricList:ReplaceKey(curKey, newKey, newText, selectNewKey)
    self.sortHeaderGroup:ReplaceKey(curKey, newKey, newText, selectNewKey)
end
-- Functions that wrap functions in ZO_ParametricScrollList
function ZO_SortableParametricList:CommitList(dontReselect)
    if dontReselect == nil then
        dontReselect = true
    end
    self.itemList:Commit(dontReselect)
end
function ZO_SortableParametricList:ClearList()
    self.itemList:Clear()
end
-- ZO_SortFilterListBase overridden functions
function ZO_SortableParametricList:RefreshVisible()
     self.itemList:RefreshVisible()
end
function ZO_SortableParametricList:RefreshSort()
    if self.currentSortOption then
        self:CommitList()
    end
end
function ZO_SortableParametricList:RefreshFilters()
    --- No Filters
end
function ZO_SortableParametricList:RefreshData(dontReselect)
    self:ClearList()
    self:BuildList()
    self:CommitList(dontReselect)
end
-- Functions to be overridden
function ZO_SortableParametricList:InitializeList()
    --- should be overridden to call AddDataTemplate & handle needed callbacks
end
function ZO_SortableParametricList:BuildList()
    -- intended to be overridden
    -- should populate the itemList by calling AddEntry
end
-- Globals
function ZO_SortableParametricList_InitSortHeader(header, stringId, textAlignment, sortKey)
    ZO_SortHeader_Initialize(header, GetString(stringId), sortKey, ZO_SORT_ORDER_UP, textAlignment or TEXT_ALIGN_LEFT, "ZoFontHeader")
end