vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 See the ReadMe.txt file for more information.
4  
5 ]]
6  
7 bcTM_Config = {}
8 bcTM_Config.ShowOnMouse = 1
9 bcTM_Config.ShowOnClick = 0
10 bcTM_Config.ShowOnButton = 0
11 bcTM_Config.HideOnMouse = 1
12 bcTM_Config.HideOnClick = 0
13 bcTM_Config.HideOnButton = 0
14 bcTM_Config.HideOnCast = 0
15 bcTM_Config.Position = 40
16 bcTM_Config.BlinkOnInactive = 1
17 bcTM_Config.HideWhileDead = 1
18 bcTM_Config.BlinkDuration = 1.0
19 bcTM_Config.BlinkDelay = 5
20  
21 -- Number of buttons for the menu defined in the XML file.
22 BCTM_NUM_BUTTONS = 12;
23  
24 -- Constants used in determining menu width/height.
25 BCTM_BORDER_WIDTH = 15;
26 BCTM_BUTTON_HEIGHT = 12;
27  
28 BCTM_BLINK_CHECK_INTERVAL = 2; -- how often, in seconds, to check to see if we need to be blinking, or hiding the icon while dead.
29  
30 bcTM_BlinkLastChecked = 0;
31 bcTM_BlinkEnabled = false;
32 bcTM_BlinkReset = true;
33 bcTM_FadeOut = true;
34 bcTM_CurrentBlinkDelay = 0;
35  
36 -- List of tracking abilities to look for.
37 bcTM_TrackingAbilities = {
38 [BCTM_TEXT_FIND_HERBS] = 0,
39 [BCTM_TEXT_FIND_MINERALS] = 0,
40 [BCTM_TEXT_FIND_TREASURE] = 0,
41 [BCTM_TEXT_TRACK_BEASTS] = 0,
42 [BCTM_TEXT_TRACK_HUMANOIDS] = 0,
43 [BCTM_TEXT_TRACK_HIDDEN] = 0,
44 [BCTM_TEXT_TRACK_ELEMENTALS] = 0,
45 [BCTM_TEXT_TRACK_UNDEAD] = 0,
46 [BCTM_TEXT_TRACK_DEMONS] = 0,
47 [BCTM_TEXT_TRACK_GIANTS] = 0,
48 [BCTM_TEXT_TRACK_DRAGONKIN] = 0,
49 [BCTM_TEXT_SENSE_UNDEAD] = 0,
50 [BCTM_TEXT_SENSE_DEMONS] = 0,
51 }
52  
53 -- ******************************************************************
54 function bcWrite(msg)
55 if (msg and DEFAULT_CHAT_FRAME) then
56 DEFAULT_CHAT_FRAME:AddMessage(msg);
57 end
58 end
59  
60 -- ******************************************************************
61 function bcTM_Report()
62 bcWrite(BCTM_TEXT_TITLE_BUTTON);
63 bcWrite(BCTM_TEXT_TOOLTIP);
64 bcWrite(BCTM_TEXT_FIND_HERBS);
65 bcWrite(BCTM_TEXT_FIND_MINERALS);
66 bcWrite(BCTM_TEXT_FIND_TREASURE);
67 bcWrite(BCTM_TEXT_TRACK_BEASTS);
68 bcWrite(BCTM_TEXT_TRACK_HUMANOIDS);
69 bcWrite(BCTM_TEXT_TRACK_HIDDEN);
70 bcWrite(BCTM_TEXT_TRACK_ELEMENTALS);
71 bcWrite(BCTM_TEXT_TRACK_UNDEAD);
72 bcWrite(BCTM_TEXT_TRACK_DEMONS);
73 bcWrite(BCTM_TEXT_TRACK_GIANTS);
74 bcWrite(BCTM_TEXT_TRACK_DRAGONKIN);
75 bcWrite(BCTM_TEXT_SENSE_UNDEAD);
76 bcWrite(BCTM_TEXT_SENSE_DEMONS);
77 bcWrite(BCTM_TEXT_CONFIG_TITLE);
78 bcWrite(BCTM_TEXT_SHOWONMOUSE);
79 bcWrite(BCTM_TEXT_HIDEONMOUSE);
80 bcWrite(BCTM_TEXT_SHOWONCLICK);
81 bcWrite(BCTM_TEXT_HIDEONCLICK);
82 bcWrite(BCTM_TEXT_SHOWONBUTTON);
83 bcWrite(BCTM_TEXT_HIDEONBUTTON);
84 bcWrite(BCTM_TEXT_HIDEONCAST);
85 bcWrite(BCTM_TEXT_BUTTONUNBOUND);
86 bcWrite(BCTM_TEXT_POSITION);
87 bcWrite(BCTM_TEXT_POSITION_TIP);
88 bcWrite(BINDING_HEADER_BCTM_BINDINGS_HEADER);
89 bcWrite(BINDING_NAME_BCTM_BINDING_TOGGLE_MENU);
90 end
91  
92 -- ******************************************************************
93 function bcTM_OnLoad()
94 -- Register for the neccessary events.
95 this:RegisterEvent("PLAYER_AURAS_CHANGED");
96 this:RegisterEvent("VARIABLES_LOADED");
97 this:RegisterEvent("SPELLS_CHANGED");
98 this:RegisterEvent("LEARNED_SPELL_IN_TAB");
99  
100 -- Create a slash command to list out the values of the localized strings.
101 SlashCmdList["BCTM_REPORT"] = bcTM_Report;
102 SLASH_BCTM_REPORT1 = "/bctm_report";
103  
104 -- Create the slash commands to show/hide the menu.
105 SlashCmdList["BCTM_SHOWMENU"] = bcTM_ShowMenu;
106 SLASH_BCTM_SHOWMENU1 = "/bctm_showmenu";
107 SlashCmdList["BCTM_HIDEMENU"] = bcTM_HideMenu;
108 SLASH_BCTM_HIDEMENU1 = "/bctm_hidemenu";
109  
110 -- Create the slash command to output the cursor position.
111 SlashCmdList["BCTM_GETLOC"] = bcTM_GetLocation;
112 SLASH_BCTM_GETLOC1 = "/bctm_getloc";
113  
114 -- Create the slash commands to show/hide the options window.
115 SlashCmdList["BCTM_SHOWOPTIONS"] = bcTM_ShowOptions;
116 SLASH_BCTM_SHOWOPTIONS1 = "/bctm_showoptions";
117 SlashCmdList["BCTM_HIDEOPTIONS"] = bcTM_HideOptions;
118 SLASH_BCTM_HIDEOPTIONS1 = "/bctm_hideoptions";
119  
120 -- Let the user know the mod loaded.
121 -- if ( DEFAULT_CHAT_FRAME ) then
122 -- bcWrite("BC Tracking Menu loaded");
123 -- end
124 end
125  
126 -- ******************************************************************
127 function bcTM_GetLocation()
128 local x, y = GetCursorPosition();
129 bcWrite("Cursor location: "..x..", "..y);
130 end
131  
132 -- ******************************************************************
133 function bcTM_ShowMenu(x, y, anchor)
134 if (bcTM_Popup:IsVisible()) then
135 bcTM_Hide();
136 return;
137 end
138  
139 if (x == nil or y == nil) then
140 -- Get the cursor position. Point is relative to the bottom left corner of the screen.
141 x, y = GetCursorPosition();
142 end
143  
144 if (anchor == nil) then
145 anchor = "center";
146 end
147  
148 -- Adjust for the UI scale.
149 x = x / UIParent:GetScale();
150 y = y / UIParent:GetScale();
151  
152 -- Adjust for the height/width/anchor of the menu.
153 if (anchor == "topright") then
154 x = x - bcTM_Popup:GetWidth();
155 y = y - bcTM_Popup:GetHeight();
156 elseif (anchor == "topleft") then
157 y = y - bcTM_Popup:GetHeight();
158 elseif (anchor == "bottomright") then
159 x = x - bcTM_Popup:GetWidth();
160 elseif (anchor == "bottomleft") then
161 -- do nothing.
162 else
163 -- anchor is either "center" or not a valid value.
164 x = x - bcTM_Popup:GetWidth() / 2;
165 y = y - bcTM_Popup:GetHeight() / 2;
166 end
167  
168 -- Clear the current anchor point, and set it to be centered under the mouse.
169 bcTM_Popup:ClearAllPoints();
170 bcTM_Popup:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", x, y);
171 bcTM_Show();
172 end
173  
174 -- ******************************************************************
175 function bcTM_HideMenu()
176 bcTM_Hide();
177 end
178  
179 -- ******************************************************************
180 function bcTM_OnEvent()
181 if (event == "PLAYER_AURAS_CHANGED") then
182 -- When the user changes their active tracking ability, do the following.
183  
184 -- Hide the default tracking icon.
185 if (MiniMapTrackingFrame) then
186 MiniMapTrackingFrame:Hide();
187 end
188  
189 -- Get the icon for the currently active tracking ability.
190 local icon = GetTrackingTexture();
191 if ( icon ) then
192 -- Set our icon to match the active ability.
193 bcTM_IconTexture:SetTexture(icon);
194 else
195 -- No ability active... Set our icon to something else.
196 bcTM_IconTexture:SetTexture("Interface\\Icons\\INV_Misc_Map_01");
197 end
198  
199 return;
200 end
201  
202 if (event == "VARIABLES_LOADED") then
203 bcTM_InitializeOptions();
204 bcTM_InitializeMenu();
205 return;
206 end
207  
208 if (event == "SPELLS_CHANGED" or event == "LEARNED_SPELL_IN_TAB") then
209 -- When the player learns a new spell, re-initialize the menu's contents.
210 bcTM_InitializeMenu();
211 return;
212 end
213 end
214  
215 -- ******************************************************************
216 function bcTM_InitializeOptions()
217 bcTM_CheckShowOnMouse:SetChecked(bcTM_Config.ShowOnMouse);
218 bcTM_CheckHideOnMouse:SetChecked(bcTM_Config.HideOnMouse);
219 bcTM_CheckShowOnClick:SetChecked(bcTM_Config.ShowOnClick);
220 bcTM_CheckHideOnClick:SetChecked(bcTM_Config.HideOnClick);
221 bcTM_CheckShowOnButton:SetChecked(bcTM_Config.ShowOnButton);
222 bcTM_CheckHideOnButton:SetChecked(bcTM_Config.HideOnButton);
223 bcTM_CheckHideOnCast:SetChecked(bcTM_Config.HideOnCast);
224 bcTM_CheckBlinkOnInactive:SetChecked(bcTM_Config.BlinkOnInactive);
225 bcTM_CheckHideWhileDead:SetChecked(bcTM_Config.HideWhileDead);
226 bcTM_IconFrame:SetPoint("TOPLEFT", "Minimap", "TOPLEFT", 52 - (80 * cos(bcTM_Config.Position)), (80 * sin(bcTM_Config.Position)) - 52);
227 end
228  
229 -- ******************************************************************
230 function bcTM_InitializeMenu()
231 -- Reset the available abilities.
232 for spell, id in ipairs(bcTM_TrackingAbilities) do
233 if (id > 0) then
234 bcTM_TrackingAbilities[spellName] = 0
235 end
236 end
237  
238 -- Calculate the total number of spells known by scanning the spellbook.
239 local numTotalSpells = 0;
240 for i=1, MAX_SKILLLINE_TABS do
241 local name, texture, offset, numSpells = GetSpellTabInfo(i);
242 if (name) then
243 numTotalSpells = numTotalSpells + numSpells
244 end
245 end
246  
247 bcTM_IconFrame.haveAbilities = false;
248  
249 -- Find the tracking abilities available.
250 for i=1, numTotalSpells do
251 local spellName, subSpellName = GetSpellName(i, SpellBookFrame.bookType);
252 if (spellName) then
253 if (bcTM_TrackingAbilities[spellName]) then
254 bcTM_IconFrame.haveAbilities = true;
255 bcTM_TrackingAbilities[spellName] = i
256 end
257 end
258 end
259  
260 if (bcTM_IconFrame.haveAbilities) then
261 bcTM_IconFrame:Show();
262 end
263  
264 -- Set the text for the buttons while keeping track of how many
265 -- buttons we actually need.
266 local count = 0;
267 for spell, id in bcTM_pairsByKeys(bcTM_TrackingAbilities) do
268 if (id > 0) then
269 count = count + 1;
270 local button = getglobal("bcTM_PopupButton"..count);
271 button:SetText(spell);
272 button.SpellID = id;
273 button:Show();
274 end
275 end
276  
277 -- Set the width for the menu.
278 local width = bcTM_TitleButton:GetWidth();
279 for i = 1, count, 1 do
280 local button = getglobal("bcTM_PopupButton"..i);
281 local w = button:GetTextWidth();
282 if (w > width) then
283 width = w;
284 end
285 end
286 bcTM_Popup:SetWidth(width + 2 * BCTM_BORDER_WIDTH);
287  
288 -- By default, the width of the button is set to the width of the text
289 -- on the button. Set the width of each button to the width of the
290 -- menu so that you can still click on it without being directly
291 -- over the text.
292 for i = 1, count, 1 do
293 local button = getglobal("bcTM_PopupButton"..i);
294 button:SetWidth(width);
295 end
296  
297 -- Hide the buttons we don't need.
298 for i = count + 1, BCTM_NUM_BUTTONS, 1 do
299 local button = getglobal("bcTM_PopupButton"..i);
300 button:Hide();
301 end
302  
303 -- Set the height for the menu.
304 bcTM_Popup:SetHeight(BCTM_BUTTON_HEIGHT + ((count + 1) * BCTM_BUTTON_HEIGHT) + (3 * BCTM_BUTTON_HEIGHT));
305 end
306  
307 -- ******************************************************************
308 function bcTM_ButtonClick()
309 -- Cast the selected spell.
310 CastSpell(this.SpellID, "spell");
311  
312 if (bcTM_Config.HideOnCast == 1) then
313 bcTM_Hide();
314 end
315 end
316  
317 -- ******************************************************************
318 function bcTM_Show()
319 -- Check to see if the aspect menu is shown. If so, hide it before
320 -- showing the tracking menu.
321 if (bcAM_Popup) then
322 if (bcAM_Popup:IsVisible()) then
323 bcAM_Hide();
324 end
325 end
326  
327 bcTM_Popup:Show();
328 end
329  
330 -- ******************************************************************
331 function bcTM_Hide()
332 bcTM_Popup:Hide();
333 end
334  
335 -- ******************************************************************
336 function bcTM_ShowOptions()
337 bcTM_Options:Show();
338 end
339  
340 -- ******************************************************************
341 function bcTM_HideOptions()
342 bcTM_Options:Hide();
343 end
344  
345 -- ******************************************************************
346 function bcTM_OnUpdate(elapsed)
347 -- Check to see if the mouse is still over the menu or the icon.
348 if (bcTM_Config.HideOnMouse == 1 and bcTM_Popup:IsVisible()) then
349 if (not MouseIsOver(bcTM_Popup) and not MouseIsOver(bcTM_IconFrame)) then
350 -- If not, hide the menu.
351 bcTM_Hide();
352 end
353 end
354  
355 bcTM_BlinkLastChecked = bcTM_BlinkLastChecked + elapsed;
356 if (bcTM_BlinkLastChecked > BCTM_BLINK_CHECK_INTERVAL) then
357 if (GetTrackingTexture() == nil and bcTM_Config.BlinkOnInactive == 1) then
358 bcTM_BlinkEnabled = true;
359 else
360 bcTM_BlinkEnabled = false;
361 end
362  
363 if (bcTM_Config.HideWhileDead == 1 and UnitIsDeadOrGhost("player")) then
364 bcTM_IconFrame:Hide();
365 elseif (bcTM_IconFrame.haveAbilities) then
366 bcTM_IconFrame:Show();
367 end
368  
369 bcTM_BlinkLastChecked = 0;
370 end
371  
372 if (bcTM_BlinkEnabled and bcTM_IconFrame:IsVisible()) then
373 bcTM_BlinkReset = false;
374 bcTM_CurrentBlinkDelay = bcTM_CurrentBlinkDelay + elapsed;
375  
376 if (bcTM_CurrentBlinkDelay > bcTM_Config.BlinkDelay) then
377 local alpha = bcTM_IconFrame:GetAlpha();
378  
379 if (alpha == 0 and bcTM_FadeOut) then
380 bcTM_FadeOut = false;
381 elseif (alpha == 1.0 and not bcTM_FadeOut) then
382 bcTM_FadeOut = true;
383 end
384  
385 if (alpha > 0 and bcTM_FadeOut) then
386 -- decrease alpha
387 alpha = alpha - (elapsed / (bcTM_Config.BlinkDuration / 2));
388 else
389 -- increase alpha
390 alpha = alpha + (elapsed / (bcTM_Config.BlinkDuration / 2));
391 end
392  
393 if (alpha < 0) then
394 alpha = 0;
395 elseif (alpha > 1) then
396 alpha = 1.0;
397 end
398  
399 bcTM_IconFrame:SetAlpha(alpha);
400  
401 if (alpha == 1.0 and not bcTM_FadeOut) then
402 bcTM_CurrentBlinkDelay = 0;
403 end
404 end
405  
406 elseif (not bcTM_BlinkReset) then
407 bcTM_IconFrame:SetAlpha(1.0);
408 bcTM_CurrentBlinkDelay = 0;
409 bcTM_BlinkReset = true;
410 end
411  
412 end
413  
414 -- ******************************************************************
415 function bcTM_pairsByKeys(t, f)
416 local a = {}
417 for n in pairs(t) do table.insert(a, n) end
418 table.sort(a, f)
419 local i = 0 -- iterator variable
420 local iter = function () -- iterator function
421 i = i + 1
422 if a[i] == nil then return nil
423 else return a[i], t[a[i]]
424 end
425 end
426 return iter
427 end
428  
429 -- ******************************************************************
430 function bcTM_IconFrameOnEnter()
431 -- Set the anchor point of the menu so it shows up next to the icon.
432 bcTM_Popup:ClearAllPoints();
433 bcTM_Popup:SetPoint("TOPRIGHT", "bcTM_IconFrame", "TOPLEFT");
434  
435 -- Set the anchor and text for the tooltip.
436 GameTooltip:SetOwner(bcTM_IconFrame, "ANCHOR_BOTTOMRIGHT");
437 local icon = GetTrackingTexture();
438 if ( icon ) then
439 GameTooltip:SetTrackingSpell();
440 else
441 GameTooltip:SetText(BCTM_TEXT_TOOLTIP);
442 end
443  
444 -- Show the menu.
445 if (bcTM_Config.ShowOnMouse == 1) then
446 bcTM_Show();
447 end
448 end
449  
450 -- ******************************************************************
451 function bcTM_IconFrameOnClick()
452 if (bcTM_Popup:IsVisible()) then
453 if (bcTM_Config.HideOnClick == 1) then
454 bcTM_Hide();
455 end
456 else
457 if (bcTM_Config.ShowOnClick == 1) then
458 bcTM_Show();
459 end
460 end
461  
462 end
463  
464 -- ******************************************************************
465 -- Not yet fully implemented.
466 function bcTM_ButtonBindingOnLoad()
467 this:RegisterForClicks("LeftButtonUp", "RightButtonUp", "MiddleButtonUp", "Button4Up", "Button5Up");
468  
469 local key1 = GetBindingKey("BCTM_BINDING_TOGGLE_MENU");
470  
471 if (key1) then
472 this:SetText(key1);
473 else
474 this:SetText(BCTM_TEXT_BUTTONUNBOUND);
475 end
476 end
477  
478 -- ******************************************************************
479 -- Not yet fully implemented.
480 function bcTM_ButtonBindingOnClick()
481 local key1, key2 = GetBindingKey("BCTM_BINDING_TOGGLE_MENU");
482  
483 if (this.selected == nil) then
484 this.selected = true;
485 this:SetText("Press a key to bind");
486  
487 else
488 this.selected = nil;
489 local key1, key2 = GetBindingKey("BCTM_BINDING_TOGGLE_MENU");
490 this:SetText(key1);
491 end
492  
493 if (key1) then
494 bcWrite("key 1 = "..key1);
495 end
496 if (key2) then
497 bcWrite("key 2");
498 end
499 end
500  
501 -- ******************************************************************
502 function bcTM_KeyBindingSpellCast(spellName)
503 if (bcTM_TrackingAbilities[spellName] > 0) then
504 CastSpell(bcTM_TrackingAbilities[spellName], "spell");
505 end
506 end