vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2  
3 See the ReadMe.html file for more information.
4  
5 ]]
6  
7 -- Number of buttons for the menu defined in the XML file.
8 BCAM_NUM_BUTTONS = 12;
9  
10 -- Constants used in determining menu width/height.
11 BCAM_BORDER_WIDTH = 15;
12 BCAM_BUTTON_HEIGHT = 12;
13  
14 BCAM_BLINK_CHECK_INTERVAL = 2; -- how often, in seconds, to check to see if we need to be blinking, or hiding the icon while dead.
15  
16 bcAM_BlinkLastChecked = 0;
17 bcAM_BlinkEnabled = false;
18 bcAM_BlinkReset = true;
19 bcAM_FadeOut = true;
20 bcAM_CurrentBlinkDelay = 0;
21  
22 -- List of tracking abilities to look for.
23 bcAM_Abilities = {
24 [BCAM_TEXT_HAWK] = 0,
25 [BCAM_TEXT_CHEETA] = 0,
26 [BCAM_TEXT_MONKEY] = 0,
27 [BCAM_TEXT_PACK] = 0,
28 [BCAM_TEXT_BEAST] = 0,
29 [BCAM_TEXT_WILD] = 0,
30 }
31  
32 -- ******************************************************************
33 function bcWrite(msg)
34 if (msg and DEFAULT_CHAT_FRAME) then
35 DEFAULT_CHAT_FRAME:AddMessage(msg);
36 end
37 end
38  
39 -- ******************************************************************
40 function bcAM_Report()
41 bcWrite(BCAM_TEXT_TITLE_BUTTON);
42 bcWrite(BCAM_TEXT_TOOLTIP);
43 bcWrite(BCAM_TEXT_FIND_HERBS);
44 bcWrite(BCAM_TEXT_FIND_MINERALS);
45 bcWrite(BCAM_TEXT_FIND_TREASURE);
46 bcWrite(BCAM_TEXT_TRACK_BEASTS);
47 bcWrite(BCAM_TEXT_TRACK_HUMANOIDS);
48 bcWrite(BCAM_TEXT_TRACK_HIDDEN);
49 bcWrite(BCAM_TEXT_TRACK_ELEMENTALS);
50 bcWrite(BCAM_TEXT_TRACK_UNDEAD);
51 bcWrite(BCAM_TEXT_TRACK_DEMONS);
52 bcWrite(BCAM_TEXT_TRACK_GIANTS);
53 bcWrite(BCAM_TEXT_TRACK_DRAGONKIN);
54 bcWrite(BCAM_TEXT_SENSE_UNDEAD);
55 bcWrite(BCAM_TEXT_SENSE_DEMONS);
56 bcWrite(BCAM_TEXT_CONFIG_TITLE);
57 bcWrite(BCAM_TEXT_SHOWONMOUSE);
58 bcWrite(BCAM_TEXT_HIDEONMOUSE);
59 bcWrite(BCAM_TEXT_SHOWONCLICK);
60 bcWrite(BCAM_TEXT_HIDEONCLICK);
61 bcWrite(BCAM_TEXT_SHOWONBUTTON);
62 bcWrite(BCAM_TEXT_HIDEONBUTTON);
63 bcWrite(BCAM_TEXT_HIDEONCAST);
64 bcWrite(BCAM_TEXT_BUTTONUNBOUND);
65 bcWrite(BCAM_TEXT_POSITION);
66 bcWrite(BCAM_TEXT_POSITION_TIP);
67 bcWrite(BINDING_HEADER_BCAM_BINDINGS_HEADER);
68 bcWrite(BINDING_NAME_BCAM_BINDING_TOGGLE_MENU);
69 end
70  
71 -- ******************************************************************
72 function bcAM_OnLoad()
73 -- Register for the neccessary events.
74 this:RegisterEvent("PLAYER_AURAS_CHANGED");
75 this:RegisterEvent("VARIABLES_LOADED");
76 this:RegisterEvent("SPELLS_CHANGED");
77 this:RegisterEvent("LEARNED_SPELL_IN_TAB");
78  
79 -- Create a slash command to list out the values of the localized strings.
80 SlashCmdList["BCAM_REPORT"] = bcAM_Report;
81 SLASH_BCAM_REPORT1 = "/bcam_report";
82  
83 -- Create the slash commands to show/hide the menu.
84 SlashCmdList["BCAM_SHOWMENU"] = bcAM_ShowMenu;
85 SLASH_BCAM_SHOWMENU1 = "/bcam_showmenu";
86 SlashCmdList["BCAM_HIDEMENU"] = bcAM_HideMenu;
87 SLASH_BCAM_HIDEMENU1 = "/bcam_hidemenu";
88  
89 -- Create the slash command to output the cursor position.
90 SlashCmdList["BCAM_GETLOC"] = bcAM_GetLocation;
91 SLASH_BCAM_GETLOC1 = "/bcam_getloc";
92  
93 -- Create the slash commands to show/hide the options window.
94 SlashCmdList["BCAM_SHOWOPTIONS"] = bcAM_ShowOptions;
95 SLASH_BCAM_SHOWOPTIONS1 = "/bcam_showoptions";
96 SlashCmdList["BCAM_HIDEOPTIONS"] = bcAM_HideOptions;
97 SLASH_BCAM_HIDEOPTIONS1 = "/bcam_hideoptions";
98  
99 -- Let the user know the mod loaded.
100 -- if ( DEFAULT_CHAT_FRAME ) then
101 -- bcWrite("BC Aspect Menu loaded");
102 -- end
103 end
104  
105 -- ******************************************************************
106 function bcAM_GetLocation()
107 local x, y = GetCursorPosition();
108 bcWrite("Cursor location: "..x..", "..y);
109 end
110  
111 -- ******************************************************************
112 function bcAM_ShowMenu(x, y, anchor)
113 if (bcAM_Popup:IsVisible()) then
114 bcAM_Hide();
115 return;
116 end
117  
118 if (x == nil or y == nil) then
119 -- Get the cursor position. Point is relative to the bottom left corner of the screen.
120 x, y = GetCursorPosition();
121 end
122  
123 if (anchor == nil) then
124 anchor = "center";
125 end
126  
127 -- Adjust for the UI scale.
128 x = x / UIParent:GetScale();
129 y = y / UIParent:GetScale();
130  
131 -- Adjust for the height/width/anchor of the menu.
132 if (anchor == "topright") then
133 x = x - bcAM_Popup:GetWidth();
134 y = y - bcAM_Popup:GetHeight();
135 elseif (anchor == "topleft") then
136 y = y - bcAM_Popup:GetHeight();
137 elseif (anchor == "bottomright") then
138 x = x - bcAM_Popup:GetWidth();
139 elseif (anchor == "bottomleft") then
140 -- do nothing.
141 else
142 -- anchor is either "center" or not a valid value.
143 x = x - bcAM_Popup:GetWidth() / 2;
144 y = y - bcAM_Popup:GetHeight() / 2;
145 end
146  
147 -- Clear the current anchor point, and set it to be centered under the mouse.
148 bcAM_Popup:ClearAllPoints();
149 bcAM_Popup:SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", x, y);
150 bcAM_Show();
151 end
152  
153 -- ******************************************************************
154 function bcAM_HideMenu()
155 bcAM_Hide();
156 end
157  
158 -- ******************************************************************
159 function bcAM_OnEvent()
160 if (event == "PLAYER_AURAS_CHANGED") then
161 -- When the user changes their active ability, do the following.
162 return;
163 end
164  
165 if (event == "VARIABLES_LOADED") then
166 bcAM_InitializeOptions();
167 bcAM_InitializeMenu();
168 return;
169 end
170  
171 if (event == "SPELLS_CHANGED" or event == "LEARNED_SPELL_IN_TAB") then
172 -- When the player learns a new spell, re-initialize the menu's contents.
173 bcAM_InitializeMenu();
174 return;
175 end
176 end
177  
178 -- ******************************************************************
179 function bcAM_InitializeOptions()
180 -- flag to determine if we show the menu when the mouse is over the icon.
181 if (bcAM_ShowOnMouse == nil) then
182 bcAM_ShowOnMouse = 1;
183 end
184  
185 -- flag to determine if we show the menu when the icon is clicked.
186 if (bcAM_ShowOnClick == nil) then
187 bcAM_ShowOnClick = 0;
188 end
189  
190 -- flag to determine if we show the menu when the bound key is pressed.
191 if (bcAM_ShowOnButton == nil) then
192 bcAM_ShowOnButton = 0;
193 end
194  
195 -- flag to determine if we hide the menu when the mouse is not over the icon.
196 if (bcAM_HideOnMouse == nil) then
197 bcAM_HideOnMouse = 1;
198 end
199  
200 -- flag to determine if we hide the menu when the icon is clicked.
201 if (bcAM_HideOnClick == nil) then
202 bcAM_HideOnClick = 0;
203 end
204  
205 -- flag to determine if we hide the menu when the bound key is pressed.
206 if (bcAM_HideOnButton == nil) then
207 bcAM_HideOnButton = 0;
208 end
209  
210 -- flag to determine if we hide the menu when a spell is cast.
211 if (bcAM_HideOnCast == nil) then
212 bcAM_HideOnCast = 0;
213 end
214  
215 -- position of the icon around the border of the minimap.
216 if (bcAM_Position == nil) then
217 bcAM_Position = 15;
218 end
219  
220 -- flag to determine if we need to blink while no ability is active.
221 if (bcAM_BlinkOnInactive == nil) then
222 bcAM_BlinkOnInactive = 0;
223 end
224  
225 -- flag to determine if we hide the icon while dead.
226 if (bcAM_HideWhileDead == nil) then
227 bcAM_HideWhileDead = 1;
228 end
229  
230 -- how long, in seconds, to take to fade in/out.
231 if (bcAM_BlinkDuration == nil) then
232 bcAM_BlinkDuration = 1.0;
233 end
234  
235 -- how long, in seconds, between blinks.
236 if (bcAM_BlinkDelay == nil) then
237 bcAM_BlinkDelay = 5;
238 end
239  
240 bcAM_CheckShowOnMouse:SetChecked(bcAM_ShowOnMouse);
241 bcAM_CheckHideOnMouse:SetChecked(bcAM_HideOnMouse);
242 bcAM_CheckShowOnClick:SetChecked(bcAM_ShowOnClick);
243 bcAM_CheckHideOnClick:SetChecked(bcAM_HideOnClick);
244 bcAM_CheckShowOnButton:SetChecked(bcAM_ShowOnButton);
245 bcAM_CheckHideOnButton:SetChecked(bcAM_HideOnButton);
246 bcAM_CheckHideOnCast:SetChecked(bcAM_HideOnCast);
247 bcAM_CheckBlinkOnInactive:SetChecked(bcAM_BlinkOnInactive);
248 bcAM_CheckHideWhileDead:SetChecked(bcAM_HideWhileDead);
249 bcAM_IconFrame:SetPoint("TOPLEFT", "Minimap", "TOPLEFT", 52 - (80 * cos(bcAM_Position)), (80 * sin(bcAM_Position)) - 52);
250 end
251  
252 -- ******************************************************************
253 function bcAM_InitializeMenu()
254 -- Reset the available abilities.
255 for spell, id in ipairs(bcAM_Abilities) do
256 if (id > 0) then
257 bcAM_Abilities[spellName] = 0
258 end
259 end
260  
261 -- Calculate the total number of spells known by scanning the spellbook.
262 local numTotalSpells = 0;
263 for i=1, MAX_SKILLLINE_TABS do
264 local name, texture, offset, numSpells = GetSpellTabInfo(i);
265 if (name) then
266 numTotalSpells = numTotalSpells + numSpells
267 end
268 end
269  
270 bcAM_IconFrame.haveAbilities = false;
271  
272 -- Find the abilities available.
273 for i=1, numTotalSpells do
274 local spellName, subSpellName = GetSpellName(i, SpellBookFrame.bookType);
275 if (spellName) then
276 if (bcAM_Abilities[spellName]) then
277 bcAM_IconFrame.haveAbilities = true;
278 bcAM_Abilities[spellName] = i
279 end
280 end
281 end
282  
283 if (bcAM_IconFrame.haveAbilities) then
284 bcAM_IconFrame:Show();
285 end
286  
287 -- Set the text for the buttons while keeping track of how many
288 -- buttons we actually need.
289 local count = 0;
290 for spell, id in bcAM_pairsByKeys(bcAM_Abilities) do
291 if (id > 0) then
292 count = count + 1;
293 local button = getglobal("bcAM_PopupButton"..count);
294 button:SetText(spell);
295 button.SpellID = id;
296 button:Show();
297 end
298 end
299  
300 -- Set the width for the menu.
301 local width = bcAM_TitleButton:GetWidth();
302 for i = 1, count, 1 do
303 local button = getglobal("bcAM_PopupButton"..i);
304 local w = button:GetTextWidth();
305 if (w > width) then
306 width = w;
307 end
308 end
309 bcAM_Popup:SetWidth(width + 2 * BCAM_BORDER_WIDTH);
310  
311 -- By default, the width of the button is set to the width of the text
312 -- on the button. Set the width of each button to the width of the
313 -- menu so that you can still click on it without being directly
314 -- over the text.
315 for i = 1, count, 1 do
316 local button = getglobal("bcAM_PopupButton"..i);
317 button:SetWidth(width);
318 end
319  
320 -- Hide the buttons we don't need.
321 for i = count + 1, BCAM_NUM_BUTTONS, 1 do
322 local button = getglobal("bcAM_PopupButton"..i);
323 button:Hide();
324 end
325  
326 -- Set the height for the menu.
327 bcAM_Popup:SetHeight(BCAM_BUTTON_HEIGHT + ((count + 1) * BCAM_BUTTON_HEIGHT) + (3 * BCAM_BUTTON_HEIGHT));
328 end
329  
330 -- ******************************************************************
331 function bcAM_ButtonClick()
332 -- Cast the selected spell.
333 CastSpell(this.SpellID, "spell");
334  
335 if (bcAM_HideOnCast == 1) then
336 bcAM_Hide();
337 end
338 end
339  
340 -- ******************************************************************
341 function bcAM_Show()
342 -- Check to see if the tracking menu is shown. If so, hide it before
343 -- showing the aspect menu.
344 if (bcTM_Popup) then
345 if (bcTM_Popup:IsVisible()) then
346 bcTM_Hide();
347 end
348 end
349  
350 bcAM_Popup:Show();
351 end
352  
353 -- ******************************************************************
354 function bcAM_Hide()
355 bcAM_Popup:Hide();
356 end
357  
358 -- ******************************************************************
359 function bcAM_ShowOptions()
360 bcAM_Options:Show();
361 end
362  
363 -- ******************************************************************
364 function bcAM_HideOptions()
365 bcAM_Options:Hide();
366 end
367  
368 -- ******************************************************************
369 function bcAM_OnUpdate(elapsed)
370 -- Check to see if the mouse is still over the menu or the icon.
371 if (bcAM_HideOnMouse == 1 and bcAM_Popup:IsVisible()) then
372 if (not MouseIsOver(bcAM_Popup) and not MouseIsOver(bcAM_IconFrame)) then
373 -- If not, hide the menu.
374 bcAM_Hide();
375 end
376 end
377  
378 bcAM_BlinkLastChecked = bcAM_BlinkLastChecked + elapsed;
379 if (bcAM_BlinkLastChecked > BCAM_BLINK_CHECK_INTERVAL) then
380 if (GetTrackingTexture() == nil and bcAM_BlinkOnInactive == 1) then
381 bcAM_BlinkEnabled = true;
382 else
383 bcAM_BlinkEnabled = false;
384 end
385  
386 if (bcAM_HideWhileDead == 1 and UnitIsDeadOrGhost("player")) then
387 bcAM_IconFrame:Hide();
388 elseif (bcAM_IconFrame.haveAbilities) then
389 bcAM_IconFrame:Show();
390 end
391  
392 bcAM_BlinkLastChecked = 0;
393 end
394  
395 if (false and bcAM_BlinkEnabled and bcAM_IconFrame:IsVisible()) then
396 bcAM_BlinkReset = false;
397 bcAM_CurrentBlinkDelay = bcAM_CurrentBlinkDelay + elapsed;
398  
399 if (bcAM_CurrentBlinkDelay > bcAM_BlinkDelay) then
400 local alpha = bcAM_IconFrame:GetAlpha();
401  
402 if (alpha == 0 and bcAM_FadeOut) then
403 bcAM_FadeOut = false;
404 elseif (alpha == 1.0 and not bcAM_FadeOut) then
405 bcAM_FadeOut = true;
406 end
407  
408 if (alpha > 0 and bcAM_FadeOut) then
409 -- decrease alpha
410 alpha = alpha - (elapsed / (bcAM_BlinkDuration / 2));
411 else
412 -- increase alpha
413 alpha = alpha + (elapsed / (bcAM_BlinkDuration / 2));
414 end
415  
416 if (alpha < 0) then
417 alpha = 0;
418 elseif (alpha > 1) then
419 alpha = 1.0;
420 end
421  
422 bcAM_IconFrame:SetAlpha(alpha);
423  
424 if (alpha == 1.0 and not bcAM_FadeOut) then
425 bcAM_CurrentBlinkDelay = 0;
426 end
427 end
428  
429 elseif (not bcAM_BlinkReset) then
430 bcAM_IconFrame:SetAlpha(1.0);
431 bcAM_CurrentBlinkDelay = 0;
432 bcAM_BlinkReset = true;
433 end
434  
435 end
436  
437 -- ******************************************************************
438 function bcAM_pairsByKeys(t, f)
439 local a = {}
440 for n in pairs(t) do table.insert(a, n) end
441 table.sort(a, f)
442 local i = 0 -- iterator variable
443 local iter = function () -- iterator function
444 i = i + 1
445 if a[i] == nil then return nil
446 else return a[i], t[a[i]]
447 end
448 end
449 return iter
450 end
451  
452 -- ******************************************************************
453 function bcAM_IconFrameOnEnter()
454 -- Set the anchor point of the menu so it shows up next to the icon.
455 bcAM_Popup:ClearAllPoints();
456 bcAM_Popup:SetPoint("TOPRIGHT", "bcAM_IconFrame", "TOPLEFT");
457  
458 -- Set the anchor and text for the tooltip.
459 GameTooltip:SetOwner(bcAM_IconFrame, "ANCHOR_BOTTOMRIGHT");
460 GameTooltip:SetText(BCAM_TEXT_TOOLTIP);
461  
462 -- Show the menu.
463 if (bcAM_ShowOnMouse == 1) then
464 bcAM_Show();
465 end
466 end
467  
468 -- ******************************************************************
469 function bcAM_IconFrameOnClick()
470 if (bcAM_Popup:IsVisible()) then
471 if (bcAM_HideOnClick == 1) then
472 bcAM_Hide();
473 end
474 else
475 if (bcAM_ShowOnClick == 1) then
476 bcAM_Show();
477 end
478 end
479  
480 end
481  
482 -- ******************************************************************
483 -- Not yet fully implemented.
484 function bcAM_ButtonBindingOnLoad()
485 this:RegisterForClicks("LeftButtonUp", "RightButtonUp", "MiddleButtonUp", "Button4Up", "Button5Up");
486  
487 local key1 = GetBindingKey("BCAM_BINDING_TOGGLE_MENU");
488  
489 if (key1) then
490 this:SetText(key1);
491 else
492 this:SetText(BCAM_TEXT_BUTTONUNBOUND);
493 end
494 end
495  
496 -- ******************************************************************
497 -- Not yet fully implemented.
498 function bcAM_ButtonBindingOnClick()
499 local key1, key2 = GetBindingKey("BCAM_BINDING_TOGGLE_MENU");
500  
501 if (this.selected == nil) then
502 this.selected = true;
503 this:SetText("Press a key to bind");
504  
505 else
506 this.selected = nil;
507 local key1, key2 = GetBindingKey("BCAM_BINDING_TOGGLE_MENU");
508 this:SetText(key1);
509 end
510  
511 if (key1) then
512 bcWrite("key 1 = "..key1);
513 end
514 if (key2) then
515 bcWrite("key 2");
516 end
517 end