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