vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | function GB_Main_RegisterEvents() |
2 | this:RegisterEvent("ACTIONBAR_HIDEGRID"); |
||
3 | this:RegisterEvent("BAG_UPDATE"); |
||
4 | this:RegisterEvent("PLAYER_AURAS_CHANGED"); |
||
5 | this:RegisterEvent("PLAYER_ENTER_COMBAT"); |
||
6 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
7 | --this:RegisterEvent("PLAYER_LEAVING_WORLD"); |
||
8 | this:RegisterEvent("PLAYER_LEAVE_COMBAT"); |
||
9 | this:RegisterEvent("PLAYER_REGEN_DISABLED"); |
||
10 | this:RegisterEvent("PLAYER_REGEN_ENABLED"); |
||
11 | this:RegisterEvent("PLAYER_TARGET_CHANGED"); |
||
12 | this:RegisterEvent("RAID_ROSTER_UPDATE"); |
||
13 | this:RegisterEvent("SPELLCAST_FAILED"); |
||
14 | this:RegisterEvent("SPELLCAST_INTERRUPTED"); |
||
15 | this:RegisterEvent("SPELLCAST_START"); |
||
16 | this:RegisterEvent("SPELLCAST_STOP"); |
||
17 | this:RegisterEvent("SPELLS_CHANGED"); |
||
18 | this:RegisterEvent("TRAINER_CLOSED"); |
||
19 | this:RegisterEvent("UNIT_AURA"); |
||
20 | this:RegisterEvent("UNIT_HEALTH"); |
||
21 | this:RegisterEvent("UNIT_INVENTORY_CHANGED"); |
||
22 | this:RegisterEvent("UNIT_LEVEL"); |
||
23 | this:RegisterEvent("UPDATE_BINDINGS"); |
||
24 | this:RegisterEvent("VARIABLES_LOADED"); |
||
25 | end |
||
26 | |||
27 | function GB_Main_OnLoad() |
||
28 | GB_Main_RegisterEvents(); |
||
29 | |||
30 | SlashCmdList["GB"] = GB_Slash_Handler; |
||
31 | SLASH_GB1 = "/gb"; |
||
32 | SLASH_GB2 = "/groupbuttons"; |
||
33 | end |
||
34 | |||
35 | function GB_Main_OnEvent() |
||
36 | if (event == "VARIABLES_LOADED") then |
||
37 | GB_VARIABLES_LOADED = true; |
||
38 | if ( GB_ENTERING_WORLD and GB_BAGS_LOADED) then |
||
39 | GB_Initialize(); |
||
40 | end |
||
41 | elseif (event == "PLAYER_ENTERING_WORLD") then |
||
42 | --GB_Main_RegisterEvents(); |
||
43 | GB_ENTERING_WORLD = true; |
||
44 | if ( GB_VARIABLES_LOADED and GB_BAGS_LOADED) then |
||
45 | GB_Initialize(); |
||
46 | end |
||
47 | GB_REGEN = true; |
||
48 | GB_INCOMBAT = false; |
||
49 | elseif (event == "ACTIONBAR_HIDEGRID") then |
||
50 | GB_Clear_MouseAction(); |
||
51 | elseif (event == "BAG_UPDATE") then |
||
52 | if (GB_INITIALIZED) then |
||
53 | GroupButtonsFrame.itemstimer = .5; |
||
54 | else |
||
55 | GB_BAGS_LOADED = nil; |
||
56 | GroupButtonsFrame.bagsloadedtimer = 1; |
||
57 | end |
||
58 | elseif (event == "PLAYER_ENTER_COMBAT") then |
||
59 | GB_ATTACKING = true; |
||
60 | GB_INCOMBAT = true; |
||
61 | elseif (event == "PLAYER_LEAVE_COMBAT") then |
||
62 | GB_ATTACKING = false; |
||
63 | if (GB_REGEN) then |
||
64 | GB_INCOMBAT = false; |
||
65 | end |
||
66 | elseif (event == "PLAYER_LEAVING_WORLD") then |
||
67 | this:UnregisterAllEvents(); |
||
68 | this:RegisterEvent("PLAYER_ENTERING_WORLD"); |
||
69 | elseif (event == "PLAYER_REGEN_DISABLED") then |
||
70 | GB_REGEN = false; |
||
71 | GB_INCOMBAT = true; |
||
72 | elseif (event == "PLAYER_REGEN_ENABLED") then |
||
73 | GB_REGEN = true; |
||
74 | if (not GB_ATTACKING) then |
||
75 | GB_INCOMBAT = false; |
||
76 | end |
||
77 | elseif (event == "PLAYER_TARGET_CHANGED") then |
||
78 | if (UnitName("target")) then |
||
79 | this.targetauras = true; |
||
80 | GB_Update_Auras("target"); |
||
81 | else |
||
82 | this.targetauras = false; |
||
83 | end |
||
84 | elseif (event == "RAID_ROSTER_UPDATE") then |
||
85 | if (not GB_INITIALIZED) then return; end |
||
86 | for i=1,40 do |
||
87 | local unit = "raid"..i; |
||
88 | if (UnitExists(unit) and UnitName(unit) and (not GB_SKIP_NAMES[UnitName(unit)])) then |
||
89 | GB_RAID_MEMBERS[UnitName(unit)] = 1; |
||
90 | end |
||
91 | end |
||
92 | GB_Update_RaidMemberSelect(); |
||
93 | if (not GB_Settings[GB_INDEX].raid.hide) then |
||
94 | GB_Initialize_Labels(); |
||
95 | end |
||
96 | if (GetNumRaidMembers() > 0 and GB_SHUFFLE_RAID and (not GB_Settings[GB_INDEX].raid.hide)) then |
||
97 | GB_Set_Appearance("raid"); |
||
98 | end |
||
99 | if (GB_Settings[GB_INDEX].hideInRaid and GetNumRaidMembers() > 0) then |
||
100 | local partyBar, petBar; |
||
101 | for i=1,4 do |
||
102 | partyBar = getglobal(GB_Get_UnitBar("party"..i)); |
||
103 | petBar = getglobal(GB_Get_UnitBar("partypet"..i)); |
||
104 | partyBar.noshow = true; |
||
105 | petBar.noshow = true; |
||
106 | partyBar:Hide(); |
||
107 | petBar:Hide(); |
||
108 | end |
||
109 | end |
||
110 | elseif (event == "SPELLCAST_FAILED") then |
||
111 | if (GB_ANNOUNCEFAILURE) then |
||
112 | GB_Announce_Failed(GB_Get("failedText")); |
||
113 | end |
||
114 | GB_ANNOUNCEFAILURE = nil; |
||
115 | GB_ANNOUNCEINTERRUPTED = nil; |
||
116 | GB_ISCASTING = nil; |
||
117 | GB_INSTANTCASTING = nil; |
||
118 | GB_CURRENT_HEAL = {nil}; |
||
119 | GB_ANNOUNCED = {nil}; |
||
120 | GB_SPELLISCASTING = nil; |
||
121 | elseif (event == "SPELLCAST_INTERRUPTED") then |
||
122 | if (GB_ANNOUNCEINTERRUPTED) then |
||
123 | GB_Announce_Failed(GB_Get("interruptedText")); |
||
124 | end |
||
125 | GB_ANNOUNCEFAILURE = nil; |
||
126 | GB_ANNOUNCEINTERRUPTED = nil; |
||
127 | GB_ISCASTING = nil; |
||
128 | GB_INSTANTCASTING = nil; |
||
129 | GB_CURRENT_HEAL = {nil}; |
||
130 | GB_ANNOUNCED = {nil}; |
||
131 | GB_SPELLISCASTING = nil; |
||
132 | elseif (event == "SPELLCAST_START") then |
||
133 | GB_ANNOUNCEFAILURE = nil; |
||
134 | GB_ANNOUNCEINTERRUPTED = nil; |
||
135 | GB_INSTANTCASTING = nil; |
||
136 | if (GB_ANNOUNCETEXT) then |
||
137 | GB_Announce_Spellcast(GB_ANNOUNCETEXT, GB_WHISPERTARGET); |
||
138 | end |
||
139 | GB_ISCASTING = nil; |
||
140 | GB_INSTANTCASTING = nil; |
||
141 | GB_ANNOUNCETEXT = nil; |
||
142 | GB_SPELLISCASTING = true; |
||
143 | elseif (event == "SPELLCAST_STOP") then |
||
144 | if (GB_INSTANTCASTING) then |
||
145 | GB_Announce_Spellcast(GB_ANNOUNCETEXT, GB_WHISPERTARGET); |
||
146 | GB_ANNOUNCEFAILURE = nil; |
||
147 | GB_ANNOUNCEINTERRUPTED = nil; |
||
148 | GB_ISCASTING = nil; |
||
149 | end |
||
150 | GB_INSTANTCASTING = nil; |
||
151 | GB_CURRENT_HEAL = {nil}; |
||
152 | GB_SPELLISCASTING = nil; |
||
153 | elseif (event == "SPELLS_CHANGED") then |
||
154 | if (GB_CheckForNewSpells() and GB_INITIALIZED) then |
||
155 | if (ClassTrainerFrame and ClassTrainerFrame:IsVisible()) then return; end |
||
156 | GroupButtonsFrame.spellstimer = .1; |
||
157 | GB_Spellbook_Initialize(); |
||
158 | end |
||
159 | elseif (event == "TRAINER_CLOSED") then |
||
160 | GB_Spellbook_Initialize(); |
||
161 | if (GB_SPELLS_UPDATED) then |
||
162 | GB_SPELLS_UPDATED = nil; |
||
163 | else |
||
164 | GB_Update_SpellRanks(); |
||
165 | end |
||
166 | elseif (event == "UNIT_AURA") then |
||
167 | if (arg1 == "target") then |
||
168 | if (this.targetauras) then |
||
169 | GB_Update_Auras(arg1); |
||
170 | end |
||
171 | else |
||
172 | GB_Update_Auras(arg1); |
||
173 | end |
||
174 | elseif (event == "PLAYER_AURAS_CHANGED") then |
||
175 | GB_Update_Auras("player"); |
||
176 | elseif (event == "UNIT_HEALTH") then |
||
177 | if (GB_CURRENT_HEAL[1] and arg1 == GB_CURRENT_HEAL[3]) then |
||
178 | if (GB_Settings[GB_INDEX].cancelHealThreshold) then |
||
179 | if (not GB_Get_PastThreshold("cancelHealThreshold", GB_CURRENT_HEAL[3])) then |
||
180 | local text = GB_TEXT.HealCancelledMessage; |
||
181 | text = string.gsub(text, '$s', GB_CURRENT_HEAL[1]); |
||
182 | text = string.gsub(text, '$r', GB_CURRENT_HEAL[2]); |
||
183 | GB_Feedback(text); |
||
184 | GB_CURRENT_HEAL = {}; |
||
185 | SpellStopCasting(); |
||
186 | end |
||
187 | end |
||
188 | end |
||
189 | elseif (event == "UNIT_INVENTORY_CHANGED") then |
||
190 | if (GB_INITIALIZED) then |
||
191 | GroupButtonsFrame.itemstimer = .5; |
||
192 | end |
||
193 | elseif (event == "UNIT_LEVEL") then |
||
194 | if (GetNumRaidMembers() > 0 and string.find(arg1, "raid")) then |
||
195 | GB_Update_RaidMemberSelect(); |
||
196 | end |
||
197 | elseif (event == "UNIT_NAME") then |
||
198 | if (GetNumRaidMembers() > 0 and string.find(arg1, "raid")) then |
||
199 | GB_Update_RaidMemberSelect(); |
||
200 | end |
||
201 | elseif (event == "UPDATE_BINDINGS") then |
||
202 | GB_Update_Bindings(); |
||
203 | end |
||
204 | end |
||
205 | |||
206 | function GB_Slash_Handler(msg) |
||
207 | local command, param; |
||
208 | local index = string.find(msg, " "); |
||
209 | |||
210 | if( index) then |
||
211 | command = string.sub(msg, 1, (index - 1)); |
||
212 | param = string.sub(msg, (index + 1) ); |
||
213 | else |
||
214 | command = msg; |
||
215 | end |
||
216 | |||
217 | if ( command == "" ) then |
||
218 | GB_Show_OptionsFrame("main"); |
||
219 | elseif (command == "updateranges") then |
||
220 | GB_Update_SpellRanges(1) |
||
221 | elseif (command == "updatespells") then |
||
222 | GB_Update_Spells(1); |
||
223 | elseif (command == "toggle") then |
||
224 | if (param == "labels") then |
||
225 | GB_Toggle_Labels(); |
||
226 | elseif (param == "empty") then |
||
227 | GB_Toggle_EmptyButtons(); |
||
228 | elseif (param == "spellbook") then |
||
229 | GB_Toggle_MiniSpellbook(); |
||
230 | elseif (param == "barlock") then |
||
231 | GB_Toggle_BarLock(); |
||
232 | elseif (param == "buttonlock") then |
||
233 | GB_Toggle_ButtonsLock(); |
||
234 | end |
||
235 | elseif (command == "hidebar") then |
||
236 | local unitBar = GB_Get_UnitBar(param); |
||
237 | if (unitBar) then |
||
238 | GB_Settings[GB_INDEX][getglobal(unitBar).index].hide = true; |
||
239 | GB_Set_Appearance(getglobal(unitBar).index); |
||
240 | end |
||
241 | elseif (command == "showbar") then |
||
242 | local unitBar = GB_Get_UnitBar(param); |
||
243 | if (unitBar) then |
||
244 | GB_Settings[GB_INDEX][getglobal(unitBar).index].hide = nil; |
||
245 | GB_Set_Appearance(getglobal(unitBar).index); |
||
246 | end |
||
247 | elseif (command == "setkeybar") then |
||
248 | local unitBar = GB_Get_UnitBar(param); |
||
249 | if (param == "target") then unitBar = "target"; end |
||
250 | if (unitBar) then |
||
251 | GB_Set_CurrentKeybindingBar(unitBar); |
||
252 | end |
||
253 | elseif (command == "useaction") then |
||
254 | local _, _, bar, button = string.find(param, "(.*) (.*)"); |
||
255 | bar = GB_Get_UnitBar(bar); |
||
256 | if (bar) then |
||
257 | button = tonumber(button); |
||
258 | if (button) then |
||
259 | GB_ActionButton_OnClick(bar, button); |
||
260 | end |
||
261 | end |
||
262 | elseif (command == "contexts") then |
||
263 | local unitBar = GB_Get_UnitBar("target"); |
||
264 | local button; |
||
265 | for i=1,20 do |
||
266 | button = getglobal(unitBar.."_Button_"..i); |
||
267 | for index,v in button.InContext do |
||
268 | if (v == -1) then |
||
269 | GB_Debug("button "..i.." "..index.." = "..v); |
||
270 | end |
||
271 | end |
||
272 | end |
||
273 | elseif (command == "spelldata") then |
||
274 | for name, ranks in GB_SPELLS do |
||
275 | for rank,data in ranks do |
||
276 | for i, v in data do |
||
277 | if (string.find(name, param)) then |
||
278 | GB_Feedback(name.." "..rank..": "..i.." = "..v); |
||
279 | end |
||
280 | end |
||
281 | end |
||
282 | end |
||
283 | elseif (command == "clearall") then |
||
284 | GB_Settings[GB_INDEX] = nil; |
||
285 | GB_Initialize_DefaultSettings(); |
||
286 | GB_Initialize_NewSettings(); |
||
287 | GB_UnitFrames_Initialize(); |
||
288 | GB_Initialize_BarOptions("player"); |
||
289 | GB_Initialize_Labels(); |
||
290 | GB_Initialize_Toggles(); |
||
291 | GB_Initialize_AllBars(); |
||
292 | GB_Initialize_AnnounceOptions(); |
||
293 | GB_Initialize_ThresholdsOptions(); |
||
294 | GB_Initialize_MiscOptions(); |
||
295 | elseif (command == "hidebar") then |
||
296 | if (GB_Settings[GB_INDEX][param]) then |
||
297 | GB_Settings[GB_INDEX][param].hide = true; |
||
298 | GB_Set_Appearance(param); |
||
299 | end |
||
300 | elseif (command == "showbar") then |
||
301 | if (GB_Settings[GB_INDEX][param]) then |
||
302 | GB_Settings[GB_INDEX][param].hide = nil; |
||
303 | GB_Set_Appearance(param); |
||
304 | end |
||
305 | else |
||
306 | for _, t in GB_HELP_TEXT do |
||
307 | GB_Feedback(t); |
||
308 | end |
||
309 | end |
||
310 | end |
||
311 | |||
312 | function GB_Debug(msg) |
||
313 | DEFAULT_CHAT_FRAME:AddMessage( msg, 1.0, 0.0, 0.0 ); |
||
314 | end |
||
315 | |||
316 | function GB_Feedback(msg) |
||
317 | if (GB_Get("disableGBSpam")) then return; end |
||
318 | DEFAULT_CHAT_FRAME:AddMessage( msg, 1.0, 1.0, 0.0 ); |
||
319 | end |
||
320 | |||
321 | function GB_StopMoving(frame) |
||
322 | if (frame) then |
||
323 | this = frame; |
||
324 | end |
||
325 | if (this.isMoving) then |
||
326 | this:StopMovingOrSizing(); |
||
327 | this:SetUserPlaced(true); |
||
328 | GB_Settings[GB_INDEX].frameLocs[this:GetName()] = {x = this:GetLeft(), y = this:GetTop()}; |
||
329 | this.isMoving = false; |
||
330 | end |
||
331 | end |
||
332 | |||
333 | function GB_StartMoving(frame) |
||
334 | if (frame) then |
||
335 | this = frame; |
||
336 | end |
||
337 | if (this:GetName() ~= "GB_Options" and this:GetName() ~= "GB_MiniSpellbook" ) then |
||
338 | if (not GB_Get("barsLocked")) then |
||
339 | GB_Feedback(GB_TEXT.BarsUnlockedWarning); |
||
340 | end |
||
341 | end |
||
342 | if (arg1 == "LeftButton") then |
||
343 | this:SetUserPlaced(true); |
||
344 | this:StartMoving(); |
||
345 | this.isMoving = true; |
||
346 | end |
||
347 | end |
||
348 | |||
349 | function GB_Copy_Table(src, dest) |
||
350 | for index, value in src do |
||
351 | if (type(value) == "table") then |
||
352 | dest[index] = {}; |
||
353 | GB_Copy_Table(value, dest[index]); |
||
354 | else |
||
355 | dest[index] = value; |
||
356 | end |
||
357 | end |
||
358 | end |
||
359 | |||
360 | function GB_MenuTimeout() |
||
361 | if (this.timer) then |
||
362 | this.timer = this.timer - arg1; |
||
363 | if (this.timer < 0) then |
||
364 | this:Hide(); |
||
365 | this.timer = nil; |
||
366 | end |
||
367 | end |
||
368 | end |
||
369 | |||
370 | function GB_SpellChanged(text, name, rank) |
||
371 | text = string.gsub(text, "$name", name); |
||
372 | if (rank and rank ~= "") then |
||
373 | text = string.gsub(text, "$rank", "("..rank..")"); |
||
374 | end |
||
375 | GB_Feedback(text); |
||
376 | end |
||
377 | |||
378 | function GB_Show_Tooltip(bar, button) |
||
379 | if (GB_Settings[GB_INDEX].Disable) then return; end |
||
380 | if (GB_Get("disableTooltip")) then return; end |
||
381 | local idType = GB_Settings[GB_INDEX][bar].Button[button].idType; |
||
382 | local name = GB_Settings[GB_INDEX][bar].Button[button].name; |
||
383 | if (not name) then |
||
384 | return; |
||
385 | end |
||
386 | GameTooltip_SetDefaultAnchor(GameTooltip, this); |
||
387 | if (idType == "spell") then |
||
388 | GameTooltip:SetSpell(GB_SPELLS[name][GB_Settings[GB_INDEX][bar].Button[button].rank].id, SpellBookFrame.bookType); |
||
389 | elseif (idType == "item") then |
||
390 | local hasCooldown = GameTooltip:SetBagItem(GB_ITEMS[name].bag,GB_ITEMS[name].slot); |
||
391 | if ( hasCooldown ) then |
||
392 | this.updateTooltip = TOOLTIP_UPDATE_TIME; |
||
393 | else |
||
394 | this.updateTooltip = nil; |
||
395 | end |
||
396 | elseif (idType == "inv") then |
||
397 | local _,hasCooldown = GameTooltip:SetInventoryItem("player", GB_INVENTORY[name].id); |
||
398 | if ( hasCooldown ) then |
||
399 | this.updateTooltip = TOOLTIP_UPDATE_TIME; |
||
400 | else |
||
401 | this.updateTooltip = nil; |
||
402 | end |
||
403 | elseif (idType == "macro") then |
||
404 | GameTooltip:SetText(name, 1, 1, 1); |
||
405 | end |
||
406 | end |
||
407 | |||
408 | function GB_AttackTarget() |
||
409 | if (UnitCanAttack("player","target") and UnitHealth("target") > 0) then |
||
410 | if (not GB_ATTACKING) then |
||
411 | if (not GB_Get("dontAttack")) then |
||
412 | AttackTarget(); |
||
413 | end |
||
414 | end |
||
415 | end |
||
416 | end |
||
417 | |||
418 | function GB_Announce_Spellcast(text, target) |
||
419 | if (not GB_ISCASTING) then return; end |
||
420 | if (not text) then return; end |
||
421 | if (GB_Get("announceDisabled")) then return; end |
||
422 | |||
423 | if (GB_Get("doNotAnnounceSolo")) then |
||
424 | local numParty = GetNumPartyMembers() + GetNumRaidMembers(); |
||
425 | if (numParty < 1) then return; end |
||
426 | end |
||
427 | |||
428 | local channel = "SAY"; |
||
429 | local lang = ChatFrameEditBox.language; |
||
430 | |||
431 | if (GB_Get("doNotUseSay")) then channel="WHISPER"; end |
||
432 | if (not GB_Get("doNotUseParty")) then |
||
433 | if (GetNumPartyMembers() > 0) then channel = "PARTY"; end |
||
434 | end |
||
435 | if (not GB_Get("doNotUseRaid")) then |
||
436 | if (GetNumRaidMembers() > 0) then channel = "RAID"; end |
||
437 | end |
||
438 | |||
439 | if (GB_Settings[GB_INDEX].sendToChannel and GB_Settings[GB_INDEX].announceChannel and GB_Settings[GB_INDEX].announceChannel ~= "") then |
||
440 | channel = "CHANNEL"; |
||
441 | target = GetChannelName(GB_Settings[GB_INDEX].announceChannel); |
||
442 | end |
||
443 | |||
444 | SendChatMessage(text, channel, lang, target); |
||
445 | |||
446 | if (GB_Get("announceFailed")) then |
||
447 | GB_ANNOUNCEFAILURE = true; |
||
448 | else |
||
449 | GB_ANNOUNCEFAILURE = nil; |
||
450 | end |
||
451 | if (GB_Get("announceInterrupted")) then |
||
452 | GB_ANNOUNCEINTERRUPTED = true; |
||
453 | else |
||
454 | GB_ANNOUNCEINTERRUPTED = nil; |
||
455 | end |
||
456 | end |
||
457 | |||
458 | function GB_KeyBindingFrame_GetLocalizedName(name, prefix) |
||
459 | if ( not name ) then |
||
460 | return ""; |
||
461 | end |
||
462 | local tempName = name; |
||
463 | local i = strfind(name, "-"); |
||
464 | local dashIndex = nil; |
||
465 | while ( i ) do |
||
466 | if ( not dashIndex ) then |
||
467 | dashIndex = i; |
||
468 | else |
||
469 | dashIndex = dashIndex + i; |
||
470 | end |
||
471 | tempName = strsub(tempName, i + 1); |
||
472 | i = strfind(tempName, "-"); |
||
473 | end |
||
474 | |||
475 | local modKeys = ''; |
||
476 | if ( not dashIndex ) then |
||
477 | dashIndex = 0; |
||
478 | else |
||
479 | modKeys = strsub(name, 1, dashIndex); |
||
480 | if ( GetLocale() == "deDE") then |
||
481 | modKeys = gsub(modKeys, "CTRL", "STRG"); |
||
482 | end |
||
483 | end |
||
484 | |||
485 | local variablePrefix = prefix; |
||
486 | if ( not variablePrefix ) then |
||
487 | variablePrefix = ""; |
||
488 | end |
||
489 | local localizedName = nil; |
||
490 | if ( IsMacClient() ) then |
||
491 | -- see if there is a mac specific name for the key |
||
492 | localizedName = getglobal(variablePrefix..tempName.."_MAC"); |
||
493 | end |
||
494 | if ( not localizedName ) then |
||
495 | localizedName = getglobal(variablePrefix..tempName); |
||
496 | end |
||
497 | if ( not localizedName ) then |
||
498 | localizedName = tempName; |
||
499 | end |
||
500 | return modKeys..localizedName; |
||
501 | end |
||
502 | |||
503 | function GB_Update_Bindings() |
||
504 | for bar in GB_UNITS_ARRAY do |
||
505 | for _, unitBar in GB_UNITS_ARRAY[bar].frames do |
||
506 | for button = 1, GB_UNITS_ARRAY[bar].buttons do |
||
507 | local keytext = getglobal(unitBar.."_Button_"..button.."TextFrame_HotKey"); |
||
508 | local keytext2 = getglobal(unitBar.."_Button_"..button.."TextFrame_DynamicHotKey"); |
||
509 | local unit = getglobal(unitBar).unit; |
||
510 | if (bar == "lowesthealth") then |
||
511 | unit = bar; |
||
512 | end |
||
513 | if (unit == "hostiletarget") then unit = "target"; |
||
514 | elseif (unit == "friendlytarget") then unit = "target"; |
||
515 | end |
||
516 | local action = "GB_"..string.upper(unit)..button; |
||
517 | if (string.find(unit,"party")) then |
||
518 | action = "GB_"..string.upper(unit).."_"..button; |
||
519 | end |
||
520 | local action2 = "GB_DYNAMICKB"..button; |
||
521 | local kbtext = GB_KeyBindingFrame_GetLocalizedName(GetBindingKey(action), "KEY_"); |
||
522 | local kbtext2 = GB_KeyBindingFrame_GetLocalizedName(GetBindingKey(action2), "KEY_"); |
||
523 | kbtext = string.upper(kbtext); |
||
524 | kbtext2 = string.upper(kbtext2); |
||
525 | kbtext = string.gsub(kbtext, "SHIFT", "S"); |
||
526 | kbtext = string.gsub(kbtext, "CTRL", "C"); |
||
527 | kbtext = string.gsub(kbtext, "ALT", "A"); |
||
528 | kbtext = string.gsub(kbtext, "MOUSE BUTTON", "MB"); |
||
529 | kbtext = string.gsub(kbtext, "MIDDLE MOUSE", "MM"); |
||
530 | kbtext = string.gsub(kbtext, "NUM PAD", "NP"); |
||
531 | kbtext2 = string.gsub(kbtext2, "SHIFT", "S"); |
||
532 | kbtext2 = string.gsub(kbtext2, "CTRL", "C"); |
||
533 | kbtext2 = string.gsub(kbtext2, "ALT", "A"); |
||
534 | kbtext2 = string.gsub(kbtext2, "MIDDLE MOUSE", "MM"); |
||
535 | kbtext2 = string.gsub(kbtext2, "MOUSE BUTTON", "MB"); |
||
536 | kbtext2 = string.gsub(kbtext2, "NUM PAD", "NP"); |
||
537 | if (GB_Get("hideBaseBindings")) then kbtext = ""; end |
||
538 | if (GB_Get("hideDynamicBindings")) then kbtext2 = ""; end |
||
539 | keytext:SetText(kbtext); |
||
540 | if (GB_CURRENT_KB_BAR == unitBar or GB_CURRENT_KB_BAR == unit) then |
||
541 | keytext2:SetText(kbtext2); |
||
542 | else |
||
543 | keytext2:SetText(""); |
||
544 | end |
||
545 | end |
||
546 | end |
||
547 | end |
||
548 | end |
||
549 | |||
550 | function GB_Set_CurrentKeybindingBar(unitBar) |
||
551 | GB_CURRENT_KB_BAR = unitBar; |
||
552 | GB_Update_Bindings(); |
||
553 | end |
||
554 | |||
555 | function GB_Announce_Failed(text) |
||
556 | if ((not text) or text == "") then return; end |
||
557 | if (not GB_ANNOUNCED.spellName) then return; end |
||
558 | if (GB_ANNOUNCED.target) then |
||
559 | text = string.gsub(text, '$t', GB_ANNOUNCED.target); |
||
560 | end |
||
561 | if (GB_ANNOUNCED.spellRank) then |
||
562 | text = string.gsub(text, '$r', GB_ANNOUNCED.spellRank); |
||
563 | end |
||
564 | text = string.gsub(text, '$s', GB_ANNOUNCED.spellName); |
||
565 | local channel = "SAY"; |
||
566 | local lang = ChatFrameEditBox.language; |
||
567 | if (GB_Get("doNotUseSay")) then channel="WHISPER"; end |
||
568 | if (not GB_Get("doNotUseParty")) then |
||
569 | if (GetNumPartyMembers() > 0) then channel = "PARTY"; end |
||
570 | end |
||
571 | if (not GB_Get("doNotUseRaid")) then |
||
572 | if (GetNumRaidMembers() > 0) then channel = "RAID"; end |
||
573 | end |
||
574 | if (GB_Settings[GB_INDEX].sendToChannel and GB_Settings[GB_INDEX].announceChannel and GB_Settings[GB_INDEX].announceChannel ~= "") then |
||
575 | channel = "CHANNEL"; |
||
576 | GB_ANNOUNCED.target = GetChannelName(GB_Settings[GB_INDEX].announceChannel); |
||
577 | end |
||
578 | SendChatMessage(text, channel, lang, GB_ANNOUNCED.target); |
||
579 | end |
||
580 | |||
581 | function GB_Update_SpellRanks() |
||
582 | if (GB_Settings[GB_INDEX].Disable) then return; end |
||
583 | GB_SPELLS_UPDATED = true; |
||
584 | GB_CheckForNewSpells(); |
||
585 | GB_Update_Spells(); |
||
586 | local idType, spellrank, rank, autoUpdate, name |
||
587 | for bar in GB_UNITS_ARRAY do |
||
588 | for button = 1, 20 do |
||
589 | name = GB_Settings[GB_INDEX][bar].Button[button].name |
||
590 | idType = GB_Settings[GB_INDEX][bar].Button[button].idType; |
||
591 | spellrank = GB_Settings[GB_INDEX][bar].Button[button].rank; |
||
592 | autoUpdate = GB_Settings[GB_INDEX][bar].Button[button].autoUpdate; |
||
593 | if (idType == "spell" and autoUpdate) then |
||
594 | _,_,rank = string.find(spellrank, " (%d*)"); |
||
595 | rank = tonumber(rank); |
||
596 | if (rank) then |
||
597 | rank = rank + 1; |
||
598 | if (GB_SPELLS[name][GB_TEXT.Rank..rank]) then |
||
599 | GB_Settings[GB_INDEX][bar].Button[button].rank = GB_TEXT.Rank..rank; |
||
600 | GB_ActionButton_Initialize(bar, button); |
||
601 | if (bar == GB_BAR) then |
||
602 | GB_Options_InitAction(bar, button); |
||
603 | end |
||
604 | end |
||
605 | end |
||
606 | end |
||
607 | end |
||
608 | end |
||
609 | end |
||
610 | |||
611 | function GB_CheckForNewSpells() |
||
612 | count = 0; |
||
613 | while true do |
||
614 | count = count + 1; |
||
615 | local spellName, spellRank = GetSpellName(count, BOOKTYPE_SPELL); |
||
616 | if not spellName then |
||
617 | do break end |
||
618 | end |
||
619 | end |
||
620 | if (GB_SPELLS_COUNT ~= (count - 1)) then |
||
621 | return true; |
||
622 | end |
||
623 | end |
||
624 | |||
625 | function GB_CheckTimeout(timeout, elapsed) |
||
626 | if (GroupButtonsFrame[timeout].time) then |
||
627 | GroupButtonsFrame[timeout].time = GroupButtonsFrame[timeout].time - elapsed; |
||
628 | if (GroupButtonsFrame[timeout].time < 0) then |
||
629 | GroupButtonsFrame[timeout].time = nil; |
||
630 | GroupButtonsFrame[timeout].func(); |
||
631 | end |
||
632 | end |
||
633 | end |
||
634 | |||
635 | function GB_CheckBagsTimer(elapsed) |
||
636 | if (this.bagsloadedtimer) then |
||
637 | this.bagsloadedtimer = this.bagsloadedtimer - elapsed; |
||
638 | if (this.bagsloadedtimer < 0) then |
||
639 | this.bagsloadedtimer = nil; |
||
640 | GB_BAGS_LOADED = true; |
||
641 | if (GB_ENTERING_WORLD and GB_VARIABLES_LOADED) then |
||
642 | GB_Initialize(); |
||
643 | end |
||
644 | end |
||
645 | end |
||
646 | end |
||
647 | |||
648 | function GB_CheckItemUpdateTimer(elapsed) |
||
649 | if (this.itemstimer) then |
||
650 | this.itemstimer = this.itemstimer - elapsed; |
||
651 | if (this.itemstimer < 0) then |
||
652 | this.itemstimer = nil; |
||
653 | GB_Update_InventoryItems(); |
||
654 | GB_Update_ContainerItems(); |
||
655 | end |
||
656 | end |
||
657 | end |
||
658 | |||
659 | function GB_CheckSpellsUpdateTimer(elapsed) |
||
660 | if (this.spellstimer) then |
||
661 | this.spellstimer = this.spellstimer - elapsed; |
||
662 | if (this.spellstimer < 0) then |
||
663 | this.spellstimer = nil; |
||
664 | GB_Update_Spells(); |
||
665 | GB_Spellbook_Initialize(); |
||
666 | end |
||
667 | end |
||
668 | end |
||
669 | |||
670 | function GB_UnitInRaid(unit) |
||
671 | local name = UnitName(unit); |
||
672 | for i=1, GetNumRaidMembers() do |
||
673 | if (UnitName("raid"..i) == name) then return true; end |
||
674 | end |
||
675 | end |
||
676 | |||
677 | function GB_CureAny(unit) |
||
678 | if (not unit) then |
||
679 | if (GB_LAST_UNIT) then |
||
680 | unit = GB_LAST_UNIT; |
||
681 | else |
||
682 | unit = "target"; |
||
683 | end |
||
684 | end |
||
685 | if (not UnitName(unit)) then return; end |
||
686 | local disease, poison, curse, magic; |
||
687 | local debuff; |
||
688 | local spell, rank; |
||
689 | for i = 1, 8 do |
||
690 | debuff = UnitDebuff(unit, i); |
||
691 | if (not debuff) then break; end |
||
692 | GBTooltip:SetUnitDebuff(unit, i); |
||
693 | if (GBTooltipTextRight1:IsVisible()) then |
||
694 | debuff = GBTooltipTextRight1:GetText(); |
||
695 | else |
||
696 | debuff = nil; |
||
697 | end |
||
698 | if (debuff) then |
||
699 | if (string.find(debuff, GB_FILTERS.Disease)) then |
||
700 | if (disease) then |
||
701 | disease = disease + 1; |
||
702 | else |
||
703 | disease = 1; |
||
704 | end |
||
705 | end |
||
706 | if (string.find(debuff, GB_FILTERS.Poison)) then |
||
707 | if (poison) then |
||
708 | poison = poison + 1; |
||
709 | else |
||
710 | poison = 1; |
||
711 | end |
||
712 | end |
||
713 | if (string.find(debuff, GB_FILTERS.Magic)) then |
||
714 | if (magic) then |
||
715 | magic = magic + 1; |
||
716 | else |
||
717 | magic = 1; |
||
718 | end |
||
719 | end |
||
720 | if (string.find(debuff, GB_FILTERS.Curse)) then |
||
721 | if (curse) then |
||
722 | curse = curse + 1; |
||
723 | else |
||
724 | curse = 1; |
||
725 | end |
||
726 | end |
||
727 | end |
||
728 | end |
||
729 | if (magic and (not spell)) then |
||
730 | if (GB_SPELLS[GB_CURES.DispelMagic.text]) then |
||
731 | spell = GB_CURES.DispelMagic.text; |
||
732 | rank = 1; |
||
733 | if (magic > 1) then |
||
734 | rank = 2; |
||
735 | end |
||
736 | elseif (GB_SPELLS[GB_CURES.Cleanse.text]) then |
||
737 | spell = GB_CURES.Cleanse.text; |
||
738 | end |
||
739 | end |
||
740 | if (disease and (not spell)) then |
||
741 | if (GB_SPELLS[GB_CURES.CureDisease.text]) then |
||
742 | spell = GB_CURES.CureDisease.text; |
||
743 | elseif (GB_SPELLS[GB_CURES.Purify.text]) then |
||
744 | spell = GB_CURES.Purify.text; |
||
745 | end |
||
746 | if (disease > 1 and GB_SPELLS[GB_CURES.AbolishDisease.text]) then |
||
747 | if (not GB_Get_BuffMatch(GB_CURES.AbolishDisease.text, target)) then |
||
748 | spell = GB_CURES.AbolishDisease.text; |
||
749 | else |
||
750 | spell = nil; |
||
751 | end |
||
752 | end |
||
753 | end |
||
754 | if (poison and (not spell)) then |
||
755 | if (GB_SPELLS[GB_CURES.CurePoison.text]) then |
||
756 | spell = GB_CURES.CurePoison.text; |
||
757 | elseif (GB_SPELLS[GB_CURES.Purify.text]) then |
||
758 | spell = GB_CURES.Purify.text; |
||
759 | end |
||
760 | if (poison > 1 and GB_SPELLS[GB_CURES.AbolishPoison.text]) then |
||
761 | if (not GB_Get_BuffMatch(GB_CURES.AbolishPoison.text, target)) then |
||
762 | spell = GB_CURES.AbolishPoison.text; |
||
763 | else |
||
764 | spell = nil; |
||
765 | end |
||
766 | end |
||
767 | end |
||
768 | if (curse and (not spell)) then |
||
769 | if (GB_SPELLS[GB_CURES.RemoveCurse.text]) then |
||
770 | spell = GB_CURES.RemoveCurse.text; |
||
771 | end |
||
772 | end |
||
773 | if (spell) then |
||
774 | if (rank) then |
||
775 | rank = GB_TEXT.Rank..rank; |
||
776 | else |
||
777 | rank = ""; |
||
778 | end |
||
779 | CastSpell( GB_SPELLS[spell][rank].id, "BOOKTYPE_SPELL" ); |
||
780 | else |
||
781 | GB_Feedback(GB_TEXT.NoEffectsFound); |
||
782 | end |
||
783 | end |
||
784 | |||
785 | --[[function GB_RunMacro(macroname) |
||
786 | local macroID = GetMacroIndexByName(macroname); |
||
787 | local _, _, body = GetMacroInfo(macroID); |
||
788 | if (string.find(body, "\n")) then |
||
789 | local line = ""; |
||
790 | for i=1,string.len(body) do |
||
791 | local character = string.sub(body, i, i); |
||
792 | if (character == "\n") then |
||
793 | GB_MacroBox:SetText(line); |
||
794 | ChatEdit_SendText(GB_MacroBox); |
||
795 | line = ""; |
||
796 | else |
||
797 | line = line..character; |
||
798 | end |
||
799 | end |
||
800 | else |
||
801 | GB_MacroBox:SetText(body); |
||
802 | ChatEdit_SendText(GB_MacroBox); |
||
803 | end |
||
804 | end --]] |
||
805 | |||
806 | function GB_RunMacro(macroname) |
||
807 | local name, texture, body, isLocal = GetMacroInfo(GetMacroIndexByName(macroname)); |
||
808 | |||
809 | if ( not body ) then return; end |
||
810 | |||
811 | local length = string.len(body); |
||
812 | local text=""; |
||
813 | for i = 1, length do |
||
814 | text=text..string.sub(body,i,i); |
||
815 | if ( string.sub(body,i,i) == "\n" or i == length ) then |
||
816 | if ( string.find(text,"/cast") ) then |
||
817 | local i, booktype = GB_GetSpell(gsub(text,"%s*/cast%s*(.*)%s;*.*","%1")); |
||
818 | if ( i ) then |
||
819 | RunScript("CastSpell("..i..",'"..booktype.."')"); |
||
820 | end |
||
821 | else |
||
822 | while ( string.find(text, "CastSpellByName")) do |
||
823 | local spell = gsub(text,'.-CastSpellByName.-%(.-"(.-)".*','%1',1); |
||
824 | local i, booktype = GB_GetSpell(spell); |
||
825 | if ( i ) then |
||
826 | text = gsub(text,'CastSpellByName.-%(.-".-"','CastSpell('..i..','..'"'..booktype..'"',1); |
||
827 | else |
||
828 | text = gsub(text,'CastSpellByName.-%(.-".-"%)','',1); |
||
829 | end |
||
830 | end |
||
831 | if ( string.find(text,"/script")) then |
||
832 | RunScript(gsub(text,"%s*/script%s*(.*)","%1")); |
||
833 | else |
||
834 | GB_MacroBox:SetText(text); |
||
835 | ChatEdit_SendText(GB_MacroBox); |
||
836 | end |
||
837 | end |
||
838 | text=""; |
||
839 | end |
||
840 | end |
||
841 | end |
||
842 | |||
843 | function GB_GetSpell(spell) |
||
844 | local s = gsub(spell, "%s-(.-)%s*%(.*","%1"); |
||
845 | local r; |
||
846 | if ( string.find(spell, "%(%s*[Rr]acial")) then |
||
847 | r = "racial" |
||
848 | elseif ( string.find(spell, "%(%s*[Ss]ummon")) then |
||
849 | r = "summon" |
||
850 | elseif ( string.find(spell, "%(%s*[Aa]pprentice")) then |
||
851 | r = "apprentice" |
||
852 | elseif ( string.find(spell, "%(%s*[Jj]ourneyman")) then |
||
853 | r = "journeyman" |
||
854 | elseif ( string.find(spell, "%(%s*[Ee]xpert")) then |
||
855 | r = "expert" |
||
856 | elseif ( string.find(spell, "%(%s*[Aa]rtisan")) then |
||
857 | r = "artisan" |
||
858 | elseif ( string.find(spell, "%(%s*[Mm]aster")) then |
||
859 | r = "master" |
||
860 | elseif ( not string.find(spell, "%(")) then |
||
861 | r = "" |
||
862 | else |
||
863 | r = gsub(spell, ".*%(.*[Rr]ank%s*(%d+).*", "Rank %1"); |
||
864 | end |
||
865 | return GB_FindSpell(s,r); |
||
866 | end |
||
867 | |||
868 | function GB_FindSpell(spell, rank) |
||
869 | local i = 1; |
||
870 | local booktype = "spell"; |
||
871 | local s,r; |
||
872 | local ys, yr; |
||
873 | while true do |
||
874 | s, r = GetSpellName(i,"spell"); |
||
875 | if ( not s ) then break; end |
||
876 | if ( string.lower(s) == string.lower(spell)) then ys=true; end |
||
877 | if ( (r == rank) or (r and rank and string.lower(r) == string.lower(rank))) then yr=true; end |
||
878 | if ( ys and yr ) then |
||
879 | return i,booktype; |
||
880 | end |
||
881 | i=i+1; |
||
882 | ys = nil; |
||
883 | yr = nil; |
||
884 | end |
||
885 | i = 1; |
||
886 | while true do |
||
887 | s, r = GetSpellName(i,"pet"); |
||
888 | if ( not s) then break; end |
||
889 | if ( string.lower(s) == string.lower(spell)) then ys=true; end |
||
890 | if ( (r == rank) or (r and rank and string.lower(r) == string.lower(rank))) then yr=true; end |
||
891 | if ( ys and yr ) then |
||
892 | booktype = "pet"; |
||
893 | return i,booktype; |
||
894 | end |
||
895 | i=i+1; |
||
896 | ys = nil; |
||
897 | yr = nil; |
||
898 | end |
||
899 | return nil, booktype; |
||
900 | end |
||
901 | |||
902 | function GB_Update_Auras(unit) |
||
903 | if (unit == "mouseover") then return; end |
||
904 | if (not UnitName(unit)) then return; end |
||
905 | GB_BUFFS[unit] = {nil}; |
||
906 | GB_DEBUFFS[unit] = {nil}; |
||
907 | GBAuraTooltip:SetOwner(WorldFrame, "ANCHOR_NONE"); |
||
908 | |||
909 | if (unit == "player") then |
||
910 | GB_SHADOWFORM_INDEX = nil |
||
911 | end |
||
912 | for i = 1, 16 do |
||
913 | if (UnitBuff(unit, i)) then |
||
914 | GBAuraTooltip:SetUnitBuff(unit, i); |
||
915 | if (GBAuraTooltipTextLeft1:IsShown()) then |
||
916 | GB_BUFFS[unit][GBAuraTooltipTextLeft1:GetText()] = i; |
||
917 | if (unit == "player" and GBAuraTooltipTextLeft1:GetText() == GB_TEXT.Shadowform) then |
||
918 | for j = 0, 15 do |
||
919 | local bi = GetPlayerBuff(j, "HELPFUL") |
||
920 | if (GetPlayerBuffTexture(bi)) then |
||
921 | GBAuraTooltip:SetPlayerBuff(bi); |
||
922 | if (GBAuraTooltipTextLeft1:IsShown() and GBAuraTooltipTextLeft1:GetText() == GB_TEXT.Shadowform) then |
||
923 | GB_SHADOWFORM_INDEX = j |
||
924 | break |
||
925 | end |
||
926 | end |
||
927 | end |
||
928 | end |
||
929 | if (string.find(GBAuraTooltipTextLeft1:GetText(), "-", 1, true)) then |
||
930 | GB_BUFFS[unit][UnitBuff(unit, i)] = i; |
||
931 | end |
||
932 | end |
||
933 | end |
||
934 | end |
||
935 | for i = 1, 16 do |
||
936 | if (UnitDebuff(unit, i)) then |
||
937 | GBAuraTooltip:SetUnitDebuff(unit, i); |
||
938 | if (GBAuraTooltipTextLeft1:IsShown()) then |
||
939 | GB_DEBUFFS[unit][GBAuraTooltipTextLeft1:GetText()] = true; |
||
940 | end |
||
941 | if (GBAuraTooltipTextRight1:IsShown()) then |
||
942 | GB_DEBUFFS[unit][GBAuraTooltipTextRight1:GetText()] = true; |
||
943 | end |
||
944 | end |
||
945 | end |
||
946 | end |