-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Expand file tree
/
Copy pathMinionSearchListControl.lua
More file actions
67 lines (60 loc) · 2.17 KB
/
MinionSearchListControl.lua
File metadata and controls
67 lines (60 loc) · 2.17 KB
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
-- Path of Building
--
-- Class: Minion Search List
-- Minion list control with search field. Cannot be mutable.
--
local ipairs = ipairs
local t_insert = table.insert
local t_remove = table.remove
local s_format = string.format
local MinionSearchListClass = newClass("MinionSearchListControl", "MinionListControl", function(self, anchor, rect, data, list, dest)
self.MinionListControl(anchor, rect, data, list, dest)
self.unfilteredList = copyTable(list)
self.isMutable = false
self.controls.searchText = new("EditControl", {"BOTTOMLEFT",self,"TOPLEFT"}, {0, -2, 203, 18}, "", "Search", "%c", 100, function(buf)
self:ListFilterChanged(buf, self.controls.searchModeDropDown.selIndex)
end, nil, nil, true)
self.controls.searchModeDropDown = new("DropDownControl", {"LEFT",self.controls.searchText,"RIGHT"}, {2, 0, 60, 18}, { "Names", "Skills", "Both"}, function(index, value)
self:ListFilterChanged(self.controls.searchText.buf, index)
end)
self.labelPositionOffset = {0, -20}
if dest then
self.controls.add.y = self.controls.add.y - 20
else
self.controls.delete.y = self.controls.add.y - 20
end
end)
function MinionSearchListClass:DoesEntryMatchFilters(searchStr, minionId, filterMode)
if filterMode == 1 or filterMode == 3 then
local err, match = PCall(string.matchOrPattern, self.data.minions[minionId].name:lower(), searchStr)
if not err and match then
return true
end
end
if filterMode == 2 or filterMode == 3 then
for _, skillId in ipairs(self.data.minions[minionId].skillList) do
if self.data.skills[skillId] then
local err, match = PCall(string.matchOrPattern, self.data.skills[skillId].name:lower(), searchStr)
if not err and match then
return true
end
end
end
end
return false
end
function MinionSearchListClass:ListFilterChanged(buf, filterMode)
local searchStr = buf:lower():gsub("[%-%.%+%[%]%$%^%%%?%*]", "%%%0")
if searchStr:match("%S") then
local filteredList = { }
for _, minionId in pairs(self.unfilteredList) do
if self:DoesEntryMatchFilters(searchStr, minionId, filterMode) then
t_insert(filteredList, minionId)
end
end
self.list = filteredList
self:SelectIndex(1)
else
self.list = self.unfilteredList
end
end