vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | -------------------------------------------------------------------------------- |
2 | -- TrackerAssist |
||
3 | -------------------------------------------------------------------------------- |
||
4 | |||
5 | -------------------------------------------------------------------------------- |
||
6 | -- global variables which get saved across sessions |
||
7 | -------------------------------------------------------------------------------- |
||
8 | |||
9 | -- whether or not the AddOn is enabled. |
||
10 | TrackerAssist_ENABLED = true; |
||
11 | |||
12 | -- whether or not label delay is enabled. if enabled, labels will only display |
||
13 | -- for a period of time and will then be cleared. |
||
14 | TrackerAssist_ENABLE_LABEL_DECAY = true; |
||
15 | |||
16 | -- if enabled track info printed in your chat window will also be sent to the |
||
17 | -- specified chat channel ("party", "guild", or "raid") |
||
18 | TrackerAssist_ENABLE_CHAT_ANNOUNCE = true; |
||
19 | TrackerAssist_CHAT_ANNOUNCE_CHANNEL = "party"; |
||
20 | |||
21 | -- if enabled, then the label under the minimap updates by mousing over blips |
||
22 | TrackerAssist_ENABLE_MOUSEOVER = false; |
||
23 | |||
24 | -- if enabled, NPCs are colored based on their reaction to the player |
||
25 | TrackerAssist_ENABLE_NPCCOLOR = true; |
||
26 | |||
27 | -------------------------------------------------------------------------------- |
||
28 | -- global variables |
||
29 | -------------------------------------------------------------------------------- |
||
30 | |||
31 | -- current version |
||
32 | local curVersion = "v1.7"; |
||
33 | |||
34 | -- the text label (FontString) currently being displayed, or nil if none |
||
35 | local curLabel = nil; |
||
36 | |||
37 | -- the time (returned from GetTime()) at which the currently displayed |
||
38 | -- label was first displayed. used to decay the label after a period of time. |
||
39 | local curLabelStartTime = 0; |
||
40 | |||
41 | -- if label decay is enabled, this controls how long (in seconds) before the |
||
42 | -- label decays. this is initially set to a longer time period so that the |
||
43 | -- announcement/version message gets displayed, but is shortened when text |
||
44 | -- is set via the SetTextXXX() functions. |
||
45 | local LABEL_DECAY_TIME = 30.0; |
||
46 | |||
47 | -- when multiple items are under the mouse, these variables are used to cycle |
||
48 | -- through them. |
||
49 | local prevLineText = ""; |
||
50 | local prevLineItemNum = 0; |
||
51 | local prevLineNumItems = 0; |
||
52 | |||
53 | -- if there was already a target and the tooltip didn't contain a valid target |
||
54 | -- this is used to preserve the original target |
||
55 | local origTarget = nil; |
||
56 | |||
57 | -- indicates the new target selected as a result of processing the click |
||
58 | local newTarget = nil; |
||
59 | |||
60 | -- the last mouse-over tooltip text that was processed |
||
61 | local lastMOText = ""; |
||
62 | |||
63 | -- indicates current event is a mouse-over not a click |
||
64 | local eventIsMouseOver = false; |
||
65 | |||
66 | -- stores original functions while processing text |
||
67 | local orig_TargetFrame_OnShow; |
||
68 | local orig_TargetFrame_OnHide; |
||
69 | |||
70 | -------------------------------------------------------------------------------- |
||
71 | -- function which does nothing |
||
72 | -------------------------------------------------------------------------------- |
||
73 | function TrackerAssist_nil() |
||
74 | end |
||
75 | |||
76 | -------------------------------------------------------------------------------- |
||
77 | -- clears currently displayed label |
||
78 | -------------------------------------------------------------------------------- |
||
79 | function TrackerAssist_ClearText() |
||
80 | if (curLabel ~= nil) then |
||
81 | curLabel:SetText(""); |
||
82 | curLabel = nil; |
||
83 | curLabelStartTime = 0; |
||
84 | end |
||
85 | end |
||
86 | |||
87 | -------------------------------------------------------------------------------- |
||
88 | -- sets and shows regular message text |
||
89 | -------------------------------------------------------------------------------- |
||
90 | function TrackerAssist_SetText(text) |
||
91 | TrackerAssist_ClearText(); |
||
92 | TrackerAssistText:SetText(text); |
||
93 | TrackerAssistText:SetTextColor(1.0,1.0,0.0); |
||
94 | TrackerAssistText:Show(); |
||
95 | curLabel = TrackerAssistText; |
||
96 | curLabelStartTime = GetTime(); |
||
97 | LABEL_DECAY_TIME = 5.0; |
||
98 | end |
||
99 | |||
100 | -------------------------------------------------------------------------------- |
||
101 | -- sets and shows friendly message text |
||
102 | -------------------------------------------------------------------------------- |
||
103 | function TrackerAssist_SetFriendText(text) |
||
104 | TrackerAssist_ClearText(); |
||
105 | TrackerAssistText:SetText(text); |
||
106 | TrackerAssistText:SetTextColor(0.3,1.0,0.3); |
||
107 | TrackerAssistText:Show(); |
||
108 | curLabel = TrackerAssistText; |
||
109 | curLabelStartTime = GetTime(); |
||
110 | LABEL_DECAY_TIME = 5.0; |
||
111 | end |
||
112 | |||
113 | -------------------------------------------------------------------------------- |
||
114 | -- sets and shows hostile message text |
||
115 | -------------------------------------------------------------------------------- |
||
116 | function TrackerAssist_SetFoeText(text) |
||
117 | TrackerAssist_ClearText(); |
||
118 | TrackerAssistText:SetText(text); |
||
119 | TrackerAssistText:SetTextColor(1.0,0.3,0.3); |
||
120 | TrackerAssistText:Show(); |
||
121 | curLabel = TrackerAssistText; |
||
122 | curLabelStartTime = GetTime(); |
||
123 | LABEL_DECAY_TIME = 5.0; |
||
124 | end |
||
125 | |||
126 | -------------------------------------------------------------------------------- |
||
127 | -- prints message text of the specified color to the chat window |
||
128 | -------------------------------------------------------------------------------- |
||
129 | function TrackerAssist_PrintColoredMsg(msg,r,g,b) |
||
130 | if(ChatFrame1) then |
||
131 | ChatFrame1:AddMessage(msg, r, g, b); |
||
132 | end |
||
133 | end |
||
134 | |||
135 | -------------------------------------------------------------------------------- |
||
136 | -- prints regular message text to the chat window |
||
137 | -------------------------------------------------------------------------------- |
||
138 | function TrackerAssist_Print(msg) |
||
139 | TrackerAssist_PrintColoredMsg(msg,1.0,1.0,0.0); |
||
140 | end |
||
141 | |||
142 | -------------------------------------------------------------------------------- |
||
143 | -- prints NPC message text to the chat window |
||
144 | -------------------------------------------------------------------------------- |
||
145 | function TrackerAssist_PrintNPC(msg) |
||
146 | TrackerAssist_PrintColoredMsg(msg,1.0,1.0,0.0); |
||
147 | end |
||
148 | |||
149 | -------------------------------------------------------------------------------- |
||
150 | -- prints friendly message text to the chat window |
||
151 | -------------------------------------------------------------------------------- |
||
152 | function TrackerAssist_PrintFriend(msg) |
||
153 | TrackerAssist_PrintColoredMsg(msg,0.3,1.0,0.3); |
||
154 | end |
||
155 | |||
156 | -------------------------------------------------------------------------------- |
||
157 | -- prints hostile message text to the chat window |
||
158 | -------------------------------------------------------------------------------- |
||
159 | function TrackerAssist_PrintFoe(msg) |
||
160 | TrackerAssist_PrintColoredMsg(msg,1.0,0.3,0.3); |
||
161 | end |
||
162 | |||
163 | -------------------------------------------------------------------------------- |
||
164 | -- called when the AddOn is loaded. Performs initialization tasks. |
||
165 | -------------------------------------------------------------------------------- |
||
166 | function TrackerAssist_OnLoad() |
||
167 | -- register for minimap ping (mouse click on minimap) events |
||
168 | this:RegisterEvent("MINIMAP_PING"); |
||
169 | |||
170 | -- create slash "/" command |
||
171 | SlashCmdList["TRACKERASSIST"] = TrackerAssist_Command; |
||
172 | SLASH_TRACKERASSIST1 = "/trackerassist"; |
||
173 | SLASH_TRACKERASSIST2 = "/ta"; |
||
174 | |||
175 | -- set text label to right/top-justified |
||
176 | TrackerAssistText:SetJustifyH("right"); |
||
177 | TrackerAssistText:SetJustifyV("top"); |
||
178 | |||
179 | -- show initial welcome text |
||
180 | TrackerAssist_SetText("TrackerAssist " .. curVersion); |
||
181 | -- TrackerAssist_Print("TrackerAssist " .. curVersion .. " loaded"); |
||
182 | end |
||
183 | |||
184 | -------------------------------------------------------------------------------- |
||
185 | -- called on each visual update |
||
186 | -------------------------------------------------------------------------------- |
||
187 | function TrackerAssist_OnUpdate() |
||
188 | -- if a label is currently being displayed and if label decay is enabled |
||
189 | if ((curLabel ~= nil) and |
||
190 | (TrackerAssist_ENABLE_LABEL_DECAY)) then |
||
191 | -- if the label has been displayed for longer than the decay time |
||
192 | if ((GetTime() - curLabelStartTime) > LABEL_DECAY_TIME) then |
||
193 | -- clear the label |
||
194 | TrackerAssist_ClearText(); |
||
195 | lastMOText = ""; |
||
196 | end |
||
197 | end |
||
198 | |||
199 | -- only process event if enabled |
||
200 | if (TrackerAssist_ENABLED) then |
||
201 | -- only process if mouseover processing is enabled |
||
202 | if (TrackerAssist_ENABLE_MOUSEOVER) then |
||
203 | if (TrackerAssist_MouseCheck()) then |
||
204 | -- only proceed if tooltip is showing |
||
205 | if (GameTooltip:IsVisible()) then |
||
206 | TrackerAssist_Process_Tooltip_MouseOver(); |
||
207 | end |
||
208 | end |
||
209 | end |
||
210 | end |
||
211 | end |
||
212 | |||
213 | -------------------------------------------------------------------------------- |
||
214 | -- checks if the mouse should be processed |
||
215 | -------------------------------------------------------------------------------- |
||
216 | function TrackerAssist_MouseCheck() |
||
217 | local result = false; |
||
218 | |||
219 | -- if the mouse is over the visible minimap or zoomed minimap and its not |
||
220 | -- over any of the edge buttons (clock, mail, etc) then process |
||
221 | if ((MinimapCluster and MouseIsOver(MinimapCluster) and MinimapCluster:IsVisible() and |
||
222 | MiniMapTrackingFrame and (not MouseIsOver(MiniMapTrackingFrame)) and |
||
223 | MiniMapMailFrame and (not MouseIsOver(MiniMapMailFrame)) and |
||
224 | MinimapZoomIn and (not MouseIsOver(MinimapZoomIn)) and |
||
225 | MinimapZoneTextButton and (not MouseIsOver(MinimapZoneTextButton)) and |
||
226 | MinimapZoomOut and (not MouseIsOver(MinimapZoomOut)) and |
||
227 | GameTimeFrame and (not MouseIsOver(GameTimeFrame))) or |
||
228 | (ZoomMapCluster and MouseIsOver(ZoomMapCluster) and ZoomMapCluster:IsVisible())) then |
||
229 | result = true; |
||
230 | end |
||
231 | |||
232 | return result; |
||
233 | end |
||
234 | |||
235 | -------------------------------------------------------------------------------- |
||
236 | -- responds to the slash "/" command |
||
237 | -------------------------------------------------------------------------------- |
||
238 | function TrackerAssist_Command(cmd) |
||
239 | |||
240 | if (string.len(cmd) == 0) then |
||
241 | TrackerAssist_Print("\nTrackerAssist " .. curVersion .. "\n\n"); |
||
242 | |||
243 | if (TrackerAssist_ENABLED) then |
||
244 | TrackerAssist_Print("TrackerAssist is ENABLED\n"); |
||
245 | else |
||
246 | TrackerAssist_Print("TrackerAssist is DISABLED\n"); |
||
247 | end |
||
248 | |||
249 | if (TrackerAssist_ENABLE_LABEL_DECAY) then |
||
250 | TrackerAssist_Print("Label Decay is ENABLED\n"); |
||
251 | else |
||
252 | TrackerAssist_Print("Label Decay is DISABLED\n"); |
||
253 | end |
||
254 | |||
255 | if (TrackerAssist_ENABLE_CHAT_ANNOUNCE) then |
||
256 | TrackerAssist_Print("Chat Announce is ENABLED\n"); |
||
257 | else |
||
258 | TrackerAssist_Print("Chat Announce is DISABLED\n"); |
||
259 | end |
||
260 | |||
261 | TrackerAssist_Print("Chat Announce Channel is " .. |
||
262 | TrackerAssist_CHAT_ANNOUNCE_CHANNEL .. "\n"); |
||
263 | |||
264 | if (TrackerAssist_ENABLE_MOUSEOVER) then |
||
265 | TrackerAssist_Print("Mouse Over is ENABLED\n"); |
||
266 | else |
||
267 | TrackerAssist_Print("Mouse Over is DISABLED\n"); |
||
268 | end |
||
269 | |||
270 | if (TrackerAssist_ENABLE_NPCCOLOR) then |
||
271 | TrackerAssist_Print("NPC color is ENABLED\n"); |
||
272 | else |
||
273 | TrackerAssist_Print("NPC color is DISABLED\n"); |
||
274 | end |
||
275 | |||
276 | TrackerAssist_Print("\n/trackerassist enabled - toggles whether or not " .. |
||
277 | "the TrackerAssist AddOn is enabled\n"); |
||
278 | TrackerAssist_Print("/trackerassist decay - toggles decay of the " .. |
||
279 | "label under the minimap\n"); |
||
280 | TrackerAssist_Print("/trackerassist announce - toggles " .. |
||
281 | "announcement of track info on the specified chat channel\n"); |
||
282 | TrackerAssist_Print("/trackerassist channel <chan> - sets the chat channel used " .. |
||
283 | "to announce track info (must be party, guild, or raid)\n"); |
||
284 | TrackerAssist_Print("/trackerassist mouseover - toggles whether " .. |
||
285 | "or not mouseover is enabled.\n"); |
||
286 | TrackerAssist_Print("/trackerassist npccolor - toggles whether " .. |
||
287 | "or not NPC text is color-coded based on the unit " .. |
||
288 | "reaction to the player.\n\n"); |
||
289 | |||
290 | else |
||
291 | if (cmd == "enabled") then |
||
292 | TrackerAssist_ENABLED = not TrackerAssist_ENABLED; |
||
293 | |||
294 | if (TrackerAssist_ENABLED) then |
||
295 | TrackerAssist_Print("TrackerAssist is ENABLED\n"); |
||
296 | else |
||
297 | TrackerAssist_Print("TrackerAssist is DISABLED\n"); |
||
298 | TrackerAssist_ClearText(); |
||
299 | end |
||
300 | elseif (cmd == "decay") then |
||
301 | TrackerAssist_ENABLE_LABEL_DECAY = |
||
302 | not TrackerAssist_ENABLE_LABEL_DECAY; |
||
303 | |||
304 | if (TrackerAssist_ENABLE_LABEL_DECAY) then |
||
305 | TrackerAssist_Print("Label Decay is ENABLED\n"); |
||
306 | else |
||
307 | TrackerAssist_Print("Label Decay is DISABLED\n"); |
||
308 | end |
||
309 | elseif (cmd == "announce") then |
||
310 | TrackerAssist_ENABLE_CHAT_ANNOUNCE = |
||
311 | not TrackerAssist_ENABLE_CHAT_ANNOUNCE; |
||
312 | |||
313 | if (TrackerAssist_ENABLE_CHAT_ANNOUNCE) then |
||
314 | TrackerAssist_Print("Chat Announce is ENABLED\n"); |
||
315 | else |
||
316 | TrackerAssist_Print("Chat Announce is DISABLED\n"); |
||
317 | end |
||
318 | elseif (cmd == "channel party") then |
||
319 | TrackerAssist_CHAT_ANNOUNCE_CHANNEL = "party"; |
||
320 | TrackerAssist_Print("Chat Announce Channel is " .. |
||
321 | TrackerAssist_CHAT_ANNOUNCE_CHANNEL .. "\n"); |
||
322 | elseif (cmd == "channel guild") then |
||
323 | TrackerAssist_CHAT_ANNOUNCE_CHANNEL = "guild"; |
||
324 | TrackerAssist_Print("Chat Announce Channel is " .. |
||
325 | TrackerAssist_CHAT_ANNOUNCE_CHANNEL .. "\n"); |
||
326 | elseif (cmd == "channel raid") then |
||
327 | TrackerAssist_CHAT_ANNOUNCE_CHANNEL = "raid"; |
||
328 | TrackerAssist_Print("Chat Announce Channel is " .. |
||
329 | TrackerAssist_CHAT_ANNOUNCE_CHANNEL .. "\n"); |
||
330 | elseif (cmd == "mouseover") then |
||
331 | TrackerAssist_ENABLE_MOUSEOVER = |
||
332 | not TrackerAssist_ENABLE_MOUSEOVER; |
||
333 | |||
334 | if (TrackerAssist_ENABLE_MOUSEOVER) then |
||
335 | TrackerAssist_Print("Mouse Over is ENABLED\n"); |
||
336 | else |
||
337 | TrackerAssist_Print("Mouse Over is DISABLED\n"); |
||
338 | end |
||
339 | elseif (cmd == "npccolor") then |
||
340 | TrackerAssist_ENABLE_NPCCOLOR = |
||
341 | not TrackerAssist_ENABLE_NPCCOLOR; |
||
342 | |||
343 | if (TrackerAssist_ENABLE_NPCCOLOR) then |
||
344 | TrackerAssist_Print("NPC color is ENABLED\n"); |
||
345 | else |
||
346 | TrackerAssist_Print("NPC color is DISABLED\n"); |
||
347 | end |
||
348 | end |
||
349 | end |
||
350 | end |
||
351 | |||
352 | -------------------------------------------------------------------------------- |
||
353 | -- called when events occur |
||
354 | -------------------------------------------------------------------------------- |
||
355 | function TrackerAssist_OnEvent() |
||
356 | -- only process event if enabled |
||
357 | if (TrackerAssist_ENABLED) then |
||
358 | -- look for minimap ping events |
||
359 | if (event == "MINIMAP_PING") then |
||
360 | if (TrackerAssist_MouseCheck()) then |
||
361 | -- only proceed if tooltip is showing |
||
362 | if (GameTooltip:IsVisible()) then |
||
363 | TrackerAssist_Process_Tooltip(); |
||
364 | end |
||
365 | end |
||
366 | end |
||
367 | end |
||
368 | end |
||
369 | |||
370 | -------------------------------------------------------------------------------- |
||
371 | -- process the tooltip resulting from a mouse click |
||
372 | -------------------------------------------------------------------------------- |
||
373 | function TrackerAssist_Process_Tooltip() |
||
374 | -- for purposes of targeting blips on the map, we only need |
||
375 | -- the first tooltip line. when there are multiple blips |
||
376 | -- being represented, they're all actually in the first tooltip |
||
377 | -- line as a string which itself has multiple lines |
||
378 | numLines = GameTooltip:NumLines(); |
||
379 | if (numLines > 0) then |
||
380 | local tttext = GameTooltipTextLeft1:GetText(); |
||
381 | if (tttext ~= nil) then |
||
382 | TrackerAssist_Process_TooltipLine(tttext); |
||
383 | end |
||
384 | end |
||
385 | end |
||
386 | |||
387 | -------------------------------------------------------------------------------- |
||
388 | -- process the tooltip resulting from a mouse over |
||
389 | -------------------------------------------------------------------------------- |
||
390 | function TrackerAssist_Process_Tooltip_MouseOver() |
||
391 | numLines = GameTooltip:NumLines(); |
||
392 | if (numLines > 0) then |
||
393 | local motext = GameTooltipTextLeft1:GetText(); |
||
394 | if (motext ~= nil) then |
||
395 | local moline = TrackerAssist_GetLine(motext,1); |
||
396 | if (string.len(moline) > 0) then |
||
397 | -- if the first line of the tooltip text has changed since we last |
||
398 | -- did this, then process it |
||
399 | if (moline ~= lastMOText) then |
||
400 | |||
401 | -- hook these to avoid the targeting sound |
||
402 | orig_TargetFrame_OnShow = TargetFrame_OnShow; |
||
403 | orig_TargetFrame_OnHide = TargetFrame_OnHide; |
||
404 | TargetFrame_OnShow = TrackerAssist_nil; |
||
405 | TargetFrame_OnHide = TrackerAssist_nil; |
||
406 | |||
407 | eventIsMouseOver = true; |
||
408 | |||
409 | lastMOText = moline; |
||
410 | TrackerAssist_Process_TooltipLine(moline); |
||
411 | |||
412 | -- restore or clear target, since mouse-over shouldn't affect |
||
413 | -- targeting |
||
414 | if (origTarget ~= nil) then |
||
415 | TargetByName(origTarget); |
||
416 | else |
||
417 | ClearTarget(); |
||
418 | end |
||
419 | |||
420 | eventIsMouseOver = false; |
||
421 | |||
422 | -- unhook |
||
423 | TargetFrame_OnShow = orig_TargetFrame_OnShow; |
||
424 | TargetFrame_OnHide = orig_TargetFrame_OnHide; |
||
425 | end |
||
426 | end |
||
427 | end |
||
428 | end |
||
429 | end |
||
430 | |||
431 | -------------------------------------------------------------------------------- |
||
432 | -- processes the specified tooltip line (which may contain multiple units) |
||
433 | -------------------------------------------------------------------------------- |
||
434 | function TrackerAssist_Process_TooltipLine(line) |
||
435 | |||
436 | -- store current target, if any and initialize new target variable |
||
437 | origTarget = UnitName("target"); |
||
438 | newTarget = nil; |
||
439 | |||
440 | -- temporarily clear some error messages which could be shown |
||
441 | local orig_ERR_UNIT_NOT_FOUND = ERR_UNIT_NOT_FOUND; |
||
442 | ERR_UNIT_NOT_FOUND = ""; |
||
443 | local orig_ERR_GENERIC_NO_TARGET = ERR_GENERIC_NO_TARGET; |
||
444 | ERR_GENERIC_NO_TARGET = ""; |
||
445 | |||
446 | -- gets rid of any items which can not be a target. |
||
447 | -- when the mouse is over multiple items, clicking multiple |
||
448 | -- times cycles through them. if there are non-targetable items |
||
449 | -- included in this cycling, then extra clicks would be needed |
||
450 | -- to cycle through the valid targets. this avoids that. |
||
451 | line = TrackerAssist_StripNontargets(line); |
||
452 | |||
453 | local idx = string.find(line,"\n"); |
||
454 | if (idx == nil) then |
||
455 | -- if there's only a single item, then process it and |
||
456 | -- clear out the variables used for cycling through multiple items |
||
457 | prevLineText = ""; |
||
458 | prevLineItemNum = 0; |
||
459 | prevLineNumItems = 0; |
||
460 | TrackerAssist_Process_Unit(line); |
||
461 | else |
||
462 | -- if there are multiple items and this is the |
||
463 | -- first time this particular set of items was clicked |
||
464 | -- initialize the variables used for cycling through the items |
||
465 | if (line ~= prevLineText) then |
||
466 | prevLineText = line; |
||
467 | prevLineItemNum = 0; |
||
468 | prevLineNumItems = TrackerAssist_NumLines(line); |
||
469 | end |
||
470 | -- advance to next item in the set of items |
||
471 | prevLineItemNum = prevLineItemNum + 1; |
||
472 | if (prevLineItemNum > prevLineNumItems) then |
||
473 | prevLineItemNum = 1; |
||
474 | end |
||
475 | -- process the next item in the set of items |
||
476 | TrackerAssist_Process_Unit(TrackerAssist_GetLine(line,prevLineItemNum)); |
||
477 | end |
||
478 | |||
479 | -- if we didn't select a new target and if there was previously |
||
480 | -- a target, then restore that target |
||
481 | if ((origTarget ~= nil) and |
||
482 | (newTarget == nil)) then |
||
483 | TargetByName(origTarget); |
||
484 | end |
||
485 | |||
486 | -- restore error messages |
||
487 | ERR_UNIT_NOT_FOUND = orig_ERR_UNIT_NOT_FOUND; |
||
488 | ERR_GENERIC_NO_TARGET = orig_ERR_GENERIC_NO_TARGET; |
||
489 | end |
||
490 | |||
491 | -------------------------------------------------------------------------------- |
||
492 | -- counts the # of lines in the specified string |
||
493 | -------------------------------------------------------------------------------- |
||
494 | function TrackerAssist_NumLines(s) |
||
495 | local idx = string.find(s,"\n"); |
||
496 | if (idx == nil) then |
||
497 | return 1; |
||
498 | else |
||
499 | return 1 + TrackerAssist_NumLines(string.sub(s,idx+1,string.len(s))); |
||
500 | end |
||
501 | end |
||
502 | |||
503 | -------------------------------------------------------------------------------- |
||
504 | -- retrieves the specified line from the string |
||
505 | -------------------------------------------------------------------------------- |
||
506 | function TrackerAssist_GetLine(s,line) |
||
507 | local tmp = s; |
||
508 | local curLineNum = 0; |
||
509 | local result = ""; |
||
510 | while (curLineNum < line) do |
||
511 | curLineNum = curLineNum + 1; |
||
512 | local idx = string.find(tmp,"\n"); |
||
513 | if (idx == null) then |
||
514 | result = tmp; |
||
515 | break; |
||
516 | else |
||
517 | result = string.sub(tmp,1,idx-1); |
||
518 | tmp = string.sub(tmp,idx+1,string.len(tmp)); |
||
519 | end |
||
520 | end |
||
521 | if (curLineNum ~= line) then |
||
522 | result = ""; |
||
523 | end |
||
524 | return result; |
||
525 | end |
||
526 | |||
527 | -------------------------------------------------------------------------------- |
||
528 | -- removes all lines from the string which do not represent valid targets |
||
529 | -------------------------------------------------------------------------------- |
||
530 | function TrackerAssist_StripNontargets(line) |
||
531 | local newline = ""; |
||
532 | local curLineNum = 0; |
||
533 | local numLines = TrackerAssist_NumLines(line); |
||
534 | while (curLineNum < numLines) do |
||
535 | curLineNum = curLineNum + 1; |
||
536 | local s = TrackerAssist_GetLine(line,curLineNum); |
||
537 | ClearTarget(); |
||
538 | TargetByName(s); |
||
539 | local name = UnitName("target"); |
||
540 | if (name ~= nil) then |
||
541 | newline = newline .. s; |
||
542 | if (curLineNum < numLines) then |
||
543 | newline = newline .. "\n"; |
||
544 | end |
||
545 | end |
||
546 | end |
||
547 | ClearTarget(); |
||
548 | return newline; |
||
549 | end |
||
550 | |||
551 | -------------------------------------------------------------------------------- |
||
552 | -- called once a targetable unit has been identified in the tooltip text |
||
553 | -------------------------------------------------------------------------------- |
||
554 | function TrackerAssist_Process_Unit(line) |
||
555 | ClearTarget(); |
||
556 | TargetByName(line); |
||
557 | |||
558 | local s, x, name, level, race, class, guildname, guildstatust, guildstatusn, |
||
559 | reaction; |
||
560 | |||
561 | name = UnitName("target"); |
||
562 | if (name ~= nil) then |
||
563 | newTarget = name; |
||
564 | s = "TRACK INFO: "; |
||
565 | |||
566 | if (UnitIsPlayer("target")) then |
||
567 | s = s .. "PLAYER: "; |
||
568 | else |
||
569 | s = s .. "NPC: "; |
||
570 | end |
||
571 | |||
572 | s = s .. name; |
||
573 | |||
574 | level = UnitLevel("target"); |
||
575 | if (level ~= nil) then |
||
576 | s = s .. ", " .. level; |
||
577 | end |
||
578 | |||
579 | if (UnitIsPlayer("target")) then |
||
580 | race = UnitRace("target"); |
||
581 | if (race ~= nil) then |
||
582 | s = s .. " " .. race; |
||
583 | end |
||
584 | |||
585 | class = UnitClass("target"); |
||
586 | if (class ~= nil) then |
||
587 | s = s .. " " .. class; |
||
588 | end |
||
589 | end |
||
590 | |||
591 | if (UnitIsPlayer("target")) then |
||
592 | x = name .. " " .. level .. " " .. race .. " " .. class; |
||
593 | |||
594 | guildname,guildstatust,guildstatusn = GetGuildInfo("target"); |
||
595 | if (guildname ~= nil) then |
||
596 | x = x .. "\n<" .. guildname .. ">"; |
||
597 | s = s .. " <" .. guildname .. ">"; |
||
598 | end |
||
599 | |||
600 | local factionT, groupT = UnitFactionGroup("target"); |
||
601 | local factionP, groupP = UnitFactionGroup("player"); |
||
602 | |||
603 | if (factionT == factionP) then |
||
604 | TrackerAssist_SetFriendText(x); |
||
605 | if (not eventIsMouseOver) then |
||
606 | TrackerAssist_PrintFriend(s); |
||
607 | end |
||
608 | else |
||
609 | TrackerAssist_SetFoeText(x); |
||
610 | if (not eventIsMouseOver) then |
||
611 | TrackerAssist_PrintFoe(s); |
||
612 | end |
||
613 | end |
||
614 | else |
||
615 | x = name .. " " .. level .. " NPC"; |
||
616 | |||
617 | if (TrackerAssist_ENABLE_NPCCOLOR) then |
||
618 | reaction = UnitReaction("target","player"); |
||
619 | |||
620 | if (reaction < 4) then |
||
621 | TrackerAssist_SetFoeText(x); |
||
622 | if (not eventIsMouseOver) then |
||
623 | TrackerAssist_PrintFoe(s); |
||
624 | end |
||
625 | elseif (reaction > 4) then |
||
626 | TrackerAssist_SetFriendText(x); |
||
627 | if (not eventIsMouseOver) then |
||
628 | TrackerAssist_PrintFriend(s); |
||
629 | end |
||
630 | else |
||
631 | TrackerAssist_SetText(x); |
||
632 | if (not eventIsMouseOver) then |
||
633 | TrackerAssist_PrintNPC(s); |
||
634 | end |
||
635 | end |
||
636 | else |
||
637 | TrackerAssist_SetText(x); |
||
638 | if (not eventIsMouseOver) then |
||
639 | TrackerAssist_PrintNPC(s); |
||
640 | end |
||
641 | end |
||
642 | end |
||
643 | |||
644 | if (TrackerAssist_ENABLE_CHAT_ANNOUNCE and (not eventIsMouseOver)) then |
||
645 | if (TrackerAssist_CHAT_ANNOUNCE_CHANNEL == "party") then |
||
646 | if (GetNumPartyMembers() > 0) then |
||
647 | SendChatMessage(s,"party"); |
||
648 | end |
||
649 | elseif (TrackerAssist_CHAT_ANNOUNCE_CHANNEL == "guild") then |
||
650 | guildname,guildstatust,guildstatusn = GetGuildInfo("player"); |
||
651 | if (guildname ~= nil) then |
||
652 | SendChatMessage(s,"guild"); |
||
653 | end |
||
654 | elseif (TrackerAssist_CHAT_ANNOUNCE_CHANNEL == "raid") then |
||
655 | if (GetNumRaidMembers() > 0) then |
||
656 | SendChatMessage(s,"raid"); |
||
657 | end |
||
658 | end |
||
659 | end |
||
660 | end |
||
661 | end |