forked from astralguild/AstralKeys
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Tables.lua
193 lines (175 loc) · 5.34 KB
/
Tables.lua
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
local e, L = unpack(select(2, ...))
local FILTER_METHOD = {}
local SORT_MEDTHOD = {}
local function ListFilter(A, filters)
if not type(A) == 'table' then return end
local keyLevelLowerBound, keyLevelUpperBound = 2, 999 -- Lowest key possible, some high enough number
if filters['key_level'] ~= '' and filters['key_level'] ~= '1' then
local keyFilterText = filters['key_level']
if tonumber(keyFilterText) then -- only input a single key level
keyLevelLowerBound = tonumber(keyFilterText)
keyLevelUpperBound = tonumber(keyFilterText)
elseif string.match(keyFilterText, '%d+%+') then -- Text input is <number>+, looking for any key at least <number>
keyLevelLowerBound = tonumber(string.match(keyFilterText, '%d+'))
elseif string.match(keyFilterText, '%d+%-') then -- Text input is <number>-, looking for a key no higher than <number>
keyLevelUpperBound = tonumber(string.match(keyFilterText, '%d+'))
end
end
for i = 1, #A do
if AstralKeysSettings.frame.show_offline.isEnabled then
A[i].isShown = true
else
A[i].isShown = e.IsUnitOnline(A[i].character_name)
end
if not AstralKeysSettings.friendOptions.show_other_faction.isEnabled then
A[i].isShown = A[i].isShown and tonumber(A[i].faction) == e.FACTION
end
local isShownInFilter = true -- Assume there is no filter taking place
for field, filterText in pairs(filters) do
if filterText ~= '' then
isShownInFilter = false -- There is a filter, now assume this unit is not to be shown
if field == 'dungeon_name' then
local mapName = e.GetMapName(A[i]['dungeon_id'])
if strfind(strlower(mapName), strlower(filterText)) then
isShownInFilter = true
end
elseif field == 'key_level' then
if A[i][field] >= keyLevelLowerBound and A[i][field] <= keyLevelUpperBound then
isShownInFilter = true
end
else
if strfind(strlower(A[i][field]):sub(1, A[i][field]:find('-') - 1), strlower(filterText)) then -- or strfind(strlower(A[i].btag), strlower(filterText)) then
isShownInFilter = true
end
end
end
A[i].isShown = A[i].isShown and isShownInFilter
end
if A[i].isShown then
A.num_shown = A.num_shown + 1
end
end
end
local function CompareUnitNames(a, b)
local s = string.lower(a.btag or a.character_name)
local t = string.lower(b.btag or b.character_name)
if AstralKeysSettings.frame.orientation == 0 then
if s > t then
return true
elseif
s < t then
return false
else
return string.lower(a.character_name) > string.lower(b.character_name)
end
else
if s < t then
return true
elseif
s > t then
return false
else
return string.lower(a.character_name) < string.lower(b.character_name)
end
end
end
local function ListSort(A, v)
if v == 'dungeon_name' then
table.sort(A, function(a, b)
local aOnline = e.IsUnitOnline(a.character_name) and 1 or 0
local bOnline = e.IsUnitOnline(b.character_name) and 1 or 0
if not AstralKeysSettings.frame.mingle_offline.isEnabled then
aOnline = true
bOnline = true
end
if aOnline == bOnline then
if AstralKeysSettings.frame.orientation == 0 then
if e.GetMapName(a.dungeon_id) > e.GetMapName(b.dungeon_id) then
return true
elseif e.GetMapName(b.dungeon_id) > e.GetMapName(a.dungeon_id) then
return false
else
return a.character_name < b.character_name
end
else
if e.GetMapName(a.dungeon_id) > e.GetMapName(b.dungeon_id) then
return false
elseif e.GetMapName(b.dungeon_id) > e.GetMapName(a.dungeon_id) then
return true
else
return CompareUnitNames(a, b)
end
end
else
return aOnline > bOnline
end
end)
else
if v == 'character_name' then
table.sort(A, function(a, b)
local aOnline = e.IsUnitOnline(a.character_name) and 1 or 0
local bOnline = e.IsUnitOnline(b.character_name) and 1 or 0
if not AstralKeysSettings.frame.mingle_offline.isEnabled then
aOnline = true
bOnline = true
end
if aOnline == bOnline then
return CompareUnitNames(a, b)
else
return aOnline > bOnline
end
end)
else
table.sort(A, function(a, b)
local aOnline = e.IsUnitOnline(a.character_name) and 1 or 0
local bOnline = e.IsUnitOnline(b.character_name) and 1 or 0
if not AstralKeysSettings.frame.mingle_offline.isEnabled then
aOnline = true
bOnline = true
end
if aOnline == bOnline then
if AstralKeysSettings.frame.orientation == 0 then
if a[v] > b[v] then
return true
elseif
a[v] < b[v] then
return false
else
return CompareUnitNames(a, b)
end
else
if a[v] < b[v] then
return true
elseif
a[v] > b[v] then
return false
else
return CompareUnitNames(a, b)
end
end
else
return aOnline > bOnline
end
end)
end
end
end
function e.AddListFilter(list, f)
if type(list) ~= 'string' and list == '' then return end
if type(f) ~= 'function' then return end
FILTER_METHOD[list] = f
end
function e.AddListSort(list, f)
if type(list) ~= 'string' and list == '' then return end
if type(f) ~= 'function' then return end
SORT_MEDTHOD[list] = f
end
function e.UpdateTable(tbl, filters)
tbl.num_shown = 0
--FILTER_METHOD[e.FrameListShown()](tbl, filters)
ListFilter(tbl, filters)
end
function e.SortTable(A, v)
ListSort(A, v)
--SORT_MEDTHOD[e.FrameListShown()](A, v)
end