vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | --===========================================================================-- |
2 | ---------------------------- LootTracker by PNB ---------------------------- |
||
3 | --===========================================================================-- |
||
4 | -- LootTrackerQueryUI.lua |
||
5 | -- |
||
6 | -- Code behind the query UI |
||
7 | --===========================================================================-- |
||
8 | |||
9 | ------------------------------------------------------------------------------ |
||
10 | -- DoQuery |
||
11 | ------------------------------------------------------------------------------ |
||
12 | |||
13 | LT_QueryResultData = {}; |
||
14 | |||
15 | function LT_DoQuery(query) |
||
16 | |||
17 | LT_QueryResultData = {}; |
||
18 | |||
19 | local queryLowercase = strlower(query); |
||
20 | |||
21 | if (queryLowercase == LT_QUERY_TARGETS or queryLowercase == LT_QUERY_LOOT) then |
||
22 | |||
23 | LT_WriteBuffer = ""; |
||
24 | |||
25 | -- forward these on to the standard output handler |
||
26 | LT_OutputSummary(query, LT_BufferOut); |
||
27 | |||
28 | LT_QueryResultText:SetText(LT_WriteBuffer); |
||
29 | LT_QueryResult:AddMessage(LT_WriteBuffer); |
||
30 | LT_WriteBuffer = ""; |
||
31 | |||
32 | else |
||
33 | -- Do a search through all the item/kill/player keys and list all the matches |
||
34 | |||
35 | local items = LT_GetItems(); |
||
36 | local kills = LT_GetKills(); |
||
37 | local players = LT_GetPlayers(); |
||
38 | |||
39 | local itemMatches = {}; |
||
40 | local killMatches = {}; |
||
41 | local playerMatches = {}; |
||
42 | |||
43 | if (queryLowercase == LT_QUERY_ITEMS) then |
||
44 | foreach(items, function(k,v) |
||
45 | tinsert(itemMatches, k); |
||
46 | end); |
||
47 | elseif (queryLowercase == LT_QUERY_KILLS) then |
||
48 | foreach(kills, function(k,v) |
||
49 | tinsert(killMatches, k); |
||
50 | end); |
||
51 | elseif (queryLowercase == LT_QUERY_PLAYERS) then |
||
52 | foreach(players, function(k,v) |
||
53 | tinsert(playerMatches, k); |
||
54 | end); |
||
55 | else |
||
56 | itemMatches = LT_GetMatchingKeys(items, query); |
||
57 | killMatches = LT_GetMatchingKeys(kills, query); |
||
58 | playerMatches = LT_GetMatchingKeys(players, query); |
||
59 | end |
||
60 | |||
61 | foreach(itemMatches, function(k,v) |
||
62 | local data = {}; |
||
63 | data.Type = "Item"; |
||
64 | data.Object = items[v]; |
||
65 | data.Description = LT_GetItemSummary(data.Object); |
||
66 | |||
67 | LT_InsertSorted(LT_QueryResultData, data, LT_DataCmp); |
||
68 | end); |
||
69 | foreach(killMatches, function(k,v) |
||
70 | local data = {}; |
||
71 | data.Type = "Kill"; |
||
72 | data.Object = kills[v]; |
||
73 | data.Description = LT_GetKillSummary(data.Object); |
||
74 | |||
75 | LT_InsertSorted(LT_QueryResultData, data, LT_DataCmp); |
||
76 | end); |
||
77 | foreach(playerMatches, function(k,v) |
||
78 | local data = {}; |
||
79 | data.Type = "Player"; |
||
80 | data.Object = players[v]; |
||
81 | data.Description = LT_GetPlayerSummary(data.Object); |
||
82 | |||
83 | LT_InsertSorted(LT_QueryResultData, data, LT_DataCmp); |
||
84 | end); |
||
85 | |||
86 | LT_QueryResultText:SetText(""); |
||
87 | LT_UpdateQueryScroll(); |
||
88 | end |
||
89 | |||
90 | end |
||
91 | |||
92 | |||
93 | ------------------------------------------------------------------------------ |
||
94 | -- DataCmp |
||
95 | ------------------------------------------------------------------------------ |
||
96 | |||
97 | function LT_DataCmp(a, b) |
||
98 | |||
99 | if ((a == nil) or (b == nil)) then |
||
100 | return 1; |
||
101 | end |
||
102 | |||
103 | if (a.Type ~= b.Type) then |
||
104 | |||
105 | return LT_StrCmp(a.Type, b.Type); |
||
106 | |||
107 | else |
||
108 | |||
109 | if (a.Type == "Item") then |
||
110 | return LT_ItemCmp(a.Object, b.Object); |
||
111 | else |
||
112 | return LT_NameCmp(a.Object, b.Object); |
||
113 | end |
||
114 | |||
115 | end |
||
116 | |||
117 | end |
||
118 | |||
119 | |||
120 | ------------------------------------------------------------------------------ |
||
121 | -- ItemCmp |
||
122 | ------------------------------------------------------------------------------ |
||
123 | |||
124 | function LT_ItemCmp(a, b) |
||
125 | |||
126 | if ((a == nil) or (b == nil)) then |
||
127 | return 1; |
||
128 | end |
||
129 | |||
130 | local qualityDiff = b.Quality - a.Quality; |
||
131 | |||
132 | if (qualityDiff ~= 0) then |
||
133 | return qualityDiff; |
||
134 | end |
||
135 | |||
136 | return LT_NameCmp(a, b); |
||
137 | |||
138 | end |
||
139 | |||
140 | |||
141 | ------------------------------------------------------------------------------ |
||
142 | -- NameCmp |
||
143 | ------------------------------------------------------------------------------ |
||
144 | |||
145 | function LT_NameCmp(a, b) |
||
146 | |||
147 | return LT_StrCmp(a.Name, b.Name); |
||
148 | |||
149 | end |
||
150 | |||
151 | |||
152 | ------------------------------------------------------------------------------ |
||
153 | -- UpdateQueryScroll |
||
154 | ------------------------------------------------------------------------------ |
||
155 | |||
156 | LT_SCROLL_QUERYITEMHEIGHT = 14; |
||
157 | LT_SCROLL_QUERYVISIBLECOUNT = 25; |
||
158 | |||
159 | function LT_UpdateQueryScroll() |
||
160 | |||
161 | local offset = FauxScrollFrame_GetOffset(LT_QueryScrollFrame); |
||
162 | |||
163 | local numItems = getn(LT_QueryResultData); |
||
164 | |||
165 | FauxScrollFrame_Update(LT_QueryScrollFrame, numItems, LT_SCROLL_QUERYVISIBLECOUNT, LT_SCROLL_QUERYITEMHEIGHT, nil, nil, nil, nil, LT_QueryScrollFrame:GetWidth(), LT_QueryScrollFrame:GetHeight()); |
||
166 | |||
167 | -- Fill in the buttons |
||
168 | for i=1, LT_SCROLL_QUERYVISIBLECOUNT, 1 do |
||
169 | |||
170 | local index = i + offset; |
||
171 | local button = getglobal("LT_QueryButton" .. i); |
||
172 | assert(button ~= nil); |
||
173 | |||
174 | local data = LT_QueryResultData[index]; |
||
175 | |||
176 | if ((index <= numItems) and (data ~= nil)) then |
||
177 | local description = data.Description; |
||
178 | |||
179 | local text = getglobal("LT_QueryButton" .. i .. "Text"); |
||
180 | assert(text ~= nil); |
||
181 | text:SetText(description); |
||
182 | |||
183 | button.Data = data; |
||
184 | button:Show(); |
||
185 | else |
||
186 | button:Hide(); |
||
187 | end |
||
188 | |||
189 | end |
||
190 | |||
191 | end |
||
192 | |||
193 | |||
194 | ------------------------------------------------------------------------------ |
||
195 | -- QueryButtonClicked |
||
196 | ------------------------------------------------------------------------------ |
||
197 | |||
198 | function LT_QueryButtonClicked(button) |
||
199 | |||
200 | local data = button.Data; |
||
201 | |||
202 | if (data.Type == "Item") then |
||
203 | |||
204 | LT_SetItem(data.Object); |
||
205 | |||
206 | elseif (data.Type == "Kill") then |
||
207 | |||
208 | LT_SetKill(data.Object); |
||
209 | |||
210 | elseif (data.Type == "Player") then |
||
211 | |||
212 | LT_SetPlayer(data.Object); |
||
213 | |||
214 | end |
||
215 | |||
216 | end |
||
217 |