ovolkov@7
|
1 local dump = DevTools_Dump
|
ovolkov@7
|
2
|
ovolkov@3
|
3 LFGListFrame.SearchPanel.SearchBox:SetMaxLetters(2048)
|
ovolkov@0
|
4
|
ovolkov@3
|
5 local filter_expression_functions = setmetatable({}, {
|
ovolkov@3
|
6 __mode = "k",
|
ovolkov@3
|
7 __index = function(t, key)
|
ovolkov@3
|
8 local func, error = loadstring("return " .. key)
|
ovolkov@3
|
9 if error then print("Error in LFG filter expression:\n", error) end
|
ovolkov@3
|
10 t[key] = func
|
ovolkov@3
|
11 return func
|
ovolkov@3
|
12 end
|
ovolkov@3
|
13 })
|
ovolkov@3
|
14
|
ovolkov@3
|
15 function LFGListSearchPanel_DoSearch(self)
|
ovolkov@3
|
16 local searchText = self.SearchBox:GetText();
|
ovolkov@3
|
17 local real_search, filter_expression = searchText:match("^([^=]-)=(.+)$")
|
ovolkov@3
|
18 if filter_expression then
|
ovolkov@3
|
19 filter_expression = filter_expression:lower()
|
ovolkov@3
|
20 self.filter_func = filter_expression_functions[filter_expression]
|
ovolkov@3
|
21 end
|
ovolkov@3
|
22 self.filter_expression = filter_expression
|
ovolkov@3
|
23
|
ovolkov@3
|
24 -- print("lfgsearch", real_search, filter_expression)
|
ovolkov@3
|
25 C_LFGList.Search(self.categoryID, real_search or searchText, self.filters, self.preferredFilters);
|
ovolkov@3
|
26 self.searching = true;
|
ovolkov@3
|
27 self.searchFailed = false;
|
ovolkov@3
|
28 self.selectedResult = nil;
|
ovolkov@3
|
29 LFGListSearchPanel_UpdateResultList(self);
|
ovolkov@3
|
30 LFGListSearchPanel_UpdateResults(self);
|
ovolkov@3
|
31 end
|
ovolkov@3
|
32
|
ovolkov@3
|
33 local result_env = {}
|
ovolkov@3
|
34 -- =highmaul and ((normal and (name:match("imp") or defeated == 6)) or (heroic and defeated == 2))
|
ovolkov@0
|
35 function LFGListUtil_SortSearchResults(results)
|
ovolkov@3
|
36 local self = LFGListFrame.SearchPanel
|
ovolkov@3
|
37 if self.filter_expression then
|
ovolkov@3
|
38 local check = self.filter_func
|
ovolkov@0
|
39 local shift_down = 0
|
ovolkov@0
|
40 local original_size = #results
|
ovolkov@0
|
41 for idx = 1, original_size do
|
ovolkov@3
|
42 local id = results[idx]
|
ovolkov@3
|
43 local _, activityID, name, comment, voiceChat, iLvl, age, numBNetFriends, numCharFriends, numGuildMates, isDelisted, leaderName, numMembers = C_LFGList.GetSearchResultInfo(id)
|
ovolkov@3
|
44 local completedEncounters = C_LFGList.GetSearchResultEncounterInfo(id)
|
ovolkov@3
|
45 local memberCounts = C_LFGList.GetSearchResultMemberCounts(id)
|
ovolkov@3
|
46
|
ovolkov@3
|
47 wipe(result_env)
|
ovolkov@3
|
48 result_env.name = name:lower()
|
ovolkov@3
|
49 result_env.comment = comment:lower()
|
ovolkov@3
|
50 result_env.ilvl = iLvl
|
ovolkov@3
|
51 -- TODO: should be calculated in meta
|
ovolkov@3
|
52 result_env.defeated = completedEncounters and #completedEncounters or 0
|
ovolkov@3
|
53 result_env.members = numMembers
|
ovolkov@6
|
54 result_env.member = numMembers
|
ovolkov@3
|
55 result_env.tanks = memberCounts.TANK
|
ovolkov@6
|
56 result_env.tank = memberCounts.TANK
|
ovolkov@3
|
57 result_env.healers = memberCounts.HEALER
|
ovolkov@6
|
58 result_env.healer = memberCounts.HEALER
|
ovolkov@3
|
59 result_env.damagers = memberCounts.DAMAGER + memberCounts.NOROLE
|
ovolkov@6
|
60 result_env.damager = memberCounts.DAMAGER + memberCounts.NOROLE
|
ovolkov@3
|
61 result_env.my_server = leaderName and not leaderName:find('-')
|
ovolkov@3
|
62
|
ovolkov@7
|
63 for idx = 1, numMembers do
|
ovolkov@7
|
64 local role, class, classLocalized = C_LFGList.GetSearchResultMemberInfo(id, idx)
|
ovolkov@7
|
65 local class_lc = class:lower()
|
ovolkov@7
|
66 local prev_count = result_env[class_lc]
|
ovolkov@7
|
67 result_env[class_lc] = prev_count and (prev_count + 1) or 0
|
ovolkov@7
|
68 end
|
ovolkov@7
|
69 for idx = 1, MAX_CLASSES do
|
ovolkov@7
|
70 local class_lc = CLASS_SORT_ORDER[idx]:lower()
|
ovolkov@7
|
71 local count = result_env[class_lc]
|
ovolkov@7
|
72 if count then
|
ovolkov@7
|
73 result_env[class_lc .. "s"] = count
|
ovolkov@7
|
74 else
|
ovolkov@7
|
75 result_env[class_lc] = 0
|
ovolkov@7
|
76 result_env[class_lc .. "s"] = 0
|
ovolkov@7
|
77 end
|
ovolkov@7
|
78 end
|
ovolkov@7
|
79
|
ovolkov@3
|
80 if activityID == 37 then
|
ovolkov@3
|
81 result_env.highmaul = true
|
ovolkov@3
|
82 result_env.normal = true
|
ovolkov@3
|
83 elseif activityID == 38 then
|
ovolkov@3
|
84 result_env.highmaul = true
|
ovolkov@3
|
85 result_env.heroic = true
|
ovolkov@3
|
86 end
|
ovolkov@3
|
87
|
ovolkov@7
|
88 -- dump(result_env)
|
ovolkov@7
|
89
|
ovolkov@3
|
90 local pass
|
ovolkov@3
|
91 if check then
|
ovolkov@3
|
92 setfenv(check, result_env)
|
ovolkov@3
|
93 pass = check()
|
ovolkov@3
|
94 end
|
ovolkov@3
|
95
|
ovolkov@3
|
96 if pass then
|
ovolkov@0
|
97 if shift_down > 0 then
|
ovolkov@3
|
98 results[idx - shift_down] = id
|
ovolkov@0
|
99 end
|
ovolkov@0
|
100 else
|
ovolkov@0
|
101 shift_down = shift_down + 1
|
ovolkov@0
|
102 end
|
ovolkov@3
|
103
|
ovolkov@0
|
104 end
|
ovolkov@0
|
105 for idx = original_size - shift_down + 1, original_size do
|
ovolkov@0
|
106 results[idx] = nil
|
ovolkov@0
|
107 end
|
ovolkov@0
|
108 end
|
ovolkov@3
|
109 table.sort(results, LFGListUtil_SortSearchResultsCB);
|
ovolkov@0
|
110 end
|
ovolkov@0
|
111
|
ovolkov@0
|
112 function LFGListUtil_SortSearchResultsCB(id1, id2)
|
ovolkov@0
|
113 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(id1);
|
ovolkov@0
|
114 local id2, activityID2, name2, comment2, voiceChat2, iLvl2, age2, numBNetFriends2, numCharFriends2, numGuildMates2, isDelisted2 = C_LFGList.GetSearchResultInfo(id2);
|
ovolkov@0
|
115
|
ovolkov@0
|
116 --If one has more friends, do that one first
|
ovolkov@0
|
117 if ( numBNetFriends1 ~= numBNetFriends2 ) then
|
ovolkov@0
|
118 return numBNetFriends1 > numBNetFriends2;
|
ovolkov@0
|
119 end
|
ovolkov@0
|
120
|
ovolkov@0
|
121 if ( numCharFriends1 ~= numCharFriends2 ) then
|
ovolkov@0
|
122 return numCharFriends1 > numCharFriends2;
|
ovolkov@0
|
123 end
|
ovolkov@0
|
124
|
ovolkov@0
|
125 if ( numGuildMates1 ~= numGuildMates2 ) then
|
ovolkov@0
|
126 return numGuildMates1 > numGuildMates2;
|
ovolkov@0
|
127 end
|
ovolkov@0
|
128
|
ovolkov@0
|
129 if ( activityID1 ~= activityID2 ) then
|
ovolkov@0
|
130 return activityID1 > activityID2;
|
ovolkov@0
|
131 end
|
ovolkov@0
|
132
|
ovolkov@0
|
133 --If we aren't sorting by anything else, just go by ID
|
ovolkov@0
|
134 return id1 < id2;
|
ovolkov@0
|
135 end
|
ovolkov@0
|
136
|
ovolkov@0
|
137 function LFGPrintRawResults()
|
ovolkov@0
|
138 local totalResults, results = C_LFGList.GetSearchResults()
|
ovolkov@0
|
139 for idx = 1, totalResults do
|
ovolkov@0
|
140 local id1, activityID1, name1, comment1, voiceChat1, iLvl1, age1, numBNetFriends1, numCharFriends1, numGuildMates1, isDelisted1 = C_LFGList.GetSearchResultInfo(results[idx])
|
ovolkov@0
|
141 print(id1, activityID1, C_LFGList.GetActivityInfo(activityID1), '*', name1)
|
ovolkov@0
|
142 end
|
ovolkov@3
|
143 end |