vanilla-wow-addons – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | function GB_ActionButton_Initialize(bar, button) |
2 | if (button > GB_UNITS_ARRAY[bar].buttons) then |
||
3 | return; |
||
4 | end |
||
5 | local settings = GB_Get(bar, button); |
||
6 | local count; |
||
7 | if (settings.idType == "item") then |
||
8 | if (GB_ITEMS[settings.name]) then |
||
9 | if (GB_Get_ItemCount(settings.name) == 0) then |
||
10 | GB_Settings[GB_INDEX][bar].Button[button] = GB_Get_DefaultButtonSettings(); |
||
11 | settings = GB_Get(bar, button); |
||
12 | end |
||
13 | else |
||
14 | GB_Settings[GB_INDEX][bar].Button[button] = GB_Get_DefaultButtonSettings(); |
||
15 | settings = GB_Get(bar, button); |
||
16 | end |
||
17 | elseif (settings.idType == "inv") then |
||
18 | if (GB_INVENTORY[settings.name]) then |
||
19 | if (GB_INVENTORY[settings.name].count == 0) then |
||
20 | GB_Settings[GB_INDEX][bar].Button[button] = GB_Get_DefaultButtonSettings(); |
||
21 | settings = GB_Get(bar, button); |
||
22 | end |
||
23 | else |
||
24 | GB_Settings[GB_INDEX][bar].Button[button] = GB_Get_DefaultButtonSettings(); |
||
25 | settings = GB_Get(bar, button); |
||
26 | end |
||
27 | end |
||
28 | local texture = GB_Get_Texture(bar, button); |
||
29 | for _, unitBar in GB_UNITS_ARRAY[bar].frames do |
||
30 | local actionButton = unitBar.."_Button_"..button; |
||
31 | getglobal(actionButton.."_Icon"):SetTexture(texture); |
||
32 | getglobal(actionButton.."TextFrame_Name"):SetText(""); |
||
33 | if (settings.name) then |
||
34 | GB_ActionButton_SetCount(bar, button); |
||
35 | if (settings.idType == "macro") then |
||
36 | getglobal(actionButton.."TextFrame_Name"):SetText(settings.name); |
||
37 | end |
||
38 | end |
||
39 | actionButton = getglobal(actionButton); |
||
40 | actionButton.InContext = {}; |
||
41 | if (not settings.name) then |
||
42 | if (not GB_Get("showEmpty")) then |
||
43 | actionButton.InContext.empty = -1; |
||
44 | actionButton:Hide(); |
||
45 | else |
||
46 | actionButton.InContext.empty = nil; |
||
47 | actionButton:Show(); |
||
48 | end |
||
49 | else |
||
50 | actionButton.InContext.empty = nil; |
||
51 | if (settings.hide) then |
||
52 | actionButton.InContext.userhidden = -1; |
||
53 | actionButton:Hide(); |
||
54 | else |
||
55 | actionButton.InContext.userhidden = nil; |
||
56 | actionButton:Show(); |
||
57 | end |
||
58 | end |
||
59 | if (GB_Options:IsVisible()) then |
||
60 | actionButton:Show(); |
||
61 | end |
||
62 | |||
63 | actionButton:UnregisterEvent("PARTY_MEMBERS_CHANGED"); |
||
64 | actionButton:UnregisterEvent("PLAYER_ENTER_COMBAT"); |
||
65 | actionButton:UnregisterEvent("PLAYER_LEAVE_COMBAT"); |
||
66 | actionButton:UnregisterEvent("PLAYER_REGEN_DISABLED"); |
||
67 | actionButton:UnregisterEvent("PLAYER_REGEN_ENABLED"); |
||
68 | actionButton:UnregisterEvent("PLAYER_TARGET_CHANGED"); |
||
69 | actionButton:UnregisterEvent("RAID_ROSTER_UPDATE"); |
||
70 | actionButton:UnregisterEvent("UNIT_AURA"); |
||
71 | actionButton:UnregisterEvent("UNIT_HEALTH"); |
||
72 | actionButton:UnregisterEvent("UNIT_MANA"); |
||
73 | actionButton:UnregisterEvent("UPDATE_BONUS_ACTIONBAR"); |
||
74 | |||
75 | actionButton:RegisterEvent("ACTIONBAR_UPDATE_COOLDOWN"); |
||
76 | |||
77 | if (bar == "party" or bar == "lowesthealth") then |
||
78 | actionButton:RegisterEvent("PARTY_MEMBERS_CHANGED"); |
||
79 | elseif (string.find(bar, "target")) then |
||
80 | actionButton:RegisterEvent("PLAYER_TARGET_CHANGED"); |
||
81 | elseif (bar == "raid") then |
||
82 | actionButton:RegisterEvent("RAID_ROSTER_UPDATE"); |
||
83 | end |
||
84 | actionButton.contextType = ""; |
||
85 | if (settings.name and settings.context ~= "Always") then |
||
86 | if (settings.context == "Mana") then |
||
87 | actionButton.contextType = "mana"; |
||
88 | actionButton:RegisterEvent("UNIT_MANA"); |
||
89 | actionButton:RegisterEvent("UNIT_MAXMANA"); |
||
90 | elseif (settings.context == "Health1" or settings.context == "Health2" or settings.context == "Health3" or settings.context == "Health4" or settings.context == "Area" or settings.context == "Dead" or settings.context == "DmgGTHeal") then |
||
91 | actionButton.contextType = "health"; |
||
92 | actionButton:RegisterEvent("UNIT_HEALTH"); |
||
93 | actionButton:RegisterEvent("UNIT_MAXHEALTH"); |
||
94 | elseif (settings.context == "Diseased" or settings.context == "Poisoned" or settings.context == "Cursed" or settings.context == "MagicDebuffed" or settings.context == "NotBuffed" or settings.context == "NotDebuffed") then |
||
95 | actionButton.contextType = "buffs"; |
||
96 | if (bar == "player") then |
||
97 | actionButton:RegisterEvent("PLAYER_AURAS_CHANGED"); |
||
98 | end |
||
99 | actionButton:RegisterEvent("UNIT_AURA"); |
||
100 | end |
||
101 | end |
||
102 | if (settings.name and bar == "lowesthealth") then |
||
103 | if (actionButton.contextType == "") then |
||
104 | if (settings.idType=="spell") then |
||
105 | if (GB_SPELLS[settings.name][settings.rank].type == "cure" or GB_SPELLS[settings.name][settings.rank].type == "buff") then |
||
106 | actionButton:RegisterEvent("UNIT_AURA"); |
||
107 | end |
||
108 | else |
||
109 | actionButton:RegisterEvent("UNIT_HEALTH"); |
||
110 | actionButton:RegisterEvent("UNIT_MAXHEALTH"); |
||
111 | end |
||
112 | end |
||
113 | end |
||
114 | if (settings.name == GB_MINLVL_SPELLS.PWShield and settings.validTarget) then |
||
115 | actionButton:RegisterEvent("UNIT_AURA"); |
||
116 | end |
||
117 | if (settings.inCombat or settings.notInCombat) then |
||
118 | actionButton:RegisterEvent("PLAYER_LEAVE_COMBAT"); |
||
119 | actionButton:RegisterEvent("PLAYER_ENTER_COMBAT"); |
||
120 | actionButton:RegisterEvent("PLAYER_REGEN_DISABLED"); |
||
121 | actionButton:RegisterEvent("PLAYER_REGEN_ENABLED"); |
||
122 | end |
||
123 | if (settings.form) then |
||
124 | actionButton:RegisterEvent("UPDATE_BONUS_ACTIONBAR"); |
||
125 | end |
||
126 | -- if (settings.outdoors) then |
||
127 | -- actionButton:RegisterEvent("ZONE_CHANGED"); |
||
128 | -- actionButton:RegisterEvent("ZONE_CHANGED_INDOORS"); |
||
129 | -- end |
||
130 | GB_ActionButton_CheckAllContexts(actionButton); |
||
131 | end |
||
132 | end |
||
133 | |||
134 | function GB_ActionButton_CheckAllContexts(actionbutton) |
||
135 | if (not GB_INITIALIZED) then return; end |
||
136 | |||
137 | if (GB_Options:IsVisible()) then |
||
138 | actionbutton:Show(); |
||
139 | return; |
||
140 | end |
||
141 | |||
142 | if (not actionbutton:GetParent():IsVisible()) then return; end |
||
143 | |||
144 | local bar = actionbutton:GetParent().index; |
||
145 | local button = actionbutton:GetID(); |
||
146 | local target = actionbutton:GetParent().unit; |
||
147 | |||
148 | if (actionbutton:GetParent().index == "lowesthealth") then |
||
149 | local spellname = GB_Settings[GB_INDEX][bar].Button[button].name; |
||
150 | local spellrank = GB_Settings[GB_INDEX][bar].Button[button].rank; |
||
151 | if (GB_SPELLS[spellname] and GB_SPELLS[spellname][spellrank].type == "cure") then |
||
152 | target = GB_Get_CureTarget(spellname); |
||
153 | elseif (GB_SPELLS[spellname] and GB_SPELLS[spellname][spellrank].type == "buff") then |
||
154 | target = GB_Get_BuffTarget(spellname); |
||
155 | else |
||
156 | target = actionbutton:GetParent().unit(); |
||
157 | end |
||
158 | if (target) then |
||
159 | getglobal(actionbutton:GetName().."TextFrame_Name"):SetText(UnitName(target)); |
||
160 | else |
||
161 | getglobal(actionbutton:GetName().."TextFrame_Name"):SetText(""); |
||
162 | target = "player"; |
||
163 | end |
||
164 | end |
||
165 | local origContext = GB_Get_InContext(actionbutton); |
||
166 | |||
167 | actionbutton.InContext.class = GB_ActionButton_CheckClassContext( |
||
168 | target, |
||
169 | GB_Settings[GB_INDEX][bar].Button[button].classes); |
||
170 | if (GB_Settings[GB_INDEX][bar].Button[button].playerOnly) then |
||
171 | if (not UnitIsPlayer(target)) then |
||
172 | actionbutton.InContext.playerOnly = -1; |
||
173 | else |
||
174 | actionbutton.InContext.playerOnly = nil; |
||
175 | end |
||
176 | else |
||
177 | actionbutton.InContext.playerOnly = nil; |
||
178 | end |
||
179 | actionbutton.InContext.combat = GB_ActionButton_CheckCombatContext( |
||
180 | GB_Settings[GB_INDEX][bar].Button[button].inCombat, |
||
181 | GB_Settings[GB_INDEX][bar].Button[button].notInCombat); |
||
182 | if (actionbutton.contextType == "buffs") then |
||
183 | actionbutton.InContext.main = GB_ActionButton_CheckBuffContexts( |
||
184 | GB_Settings[GB_INDEX][bar].Button[button].context, |
||
185 | target, |
||
186 | GB_Settings[GB_INDEX][bar].Button[button].name); |
||
187 | elseif (actionbutton.contextType == "health") then |
||
188 | actionbutton.InContext.main = GB_ActionButton_CheckHealthContexts( |
||
189 | GB_Settings[GB_INDEX][bar].Button[button].context, |
||
190 | target, |
||
191 | GB_Settings[GB_INDEX][bar].Button[button].name, |
||
192 | GB_Settings[GB_INDEX][bar].Button[button].rank); |
||
193 | elseif (actionbutton.contextType == "mana") then |
||
194 | actionbutton.InContext.main = GB_ActionButton_CheckManaContexts( |
||
195 | GB_Settings[GB_INDEX][bar].Button[button].context, target); |
||
196 | end |
||
197 | actionbutton.InContext.form = GB_ActionButton_CheckFormContext(GB_Settings[GB_INDEX][bar].Button[button].form); |
||
198 | actionbutton.InContext.validTarget = GB_ActionButton_CheckValidTargetContext( |
||
199 | GB_Settings[GB_INDEX][bar].Button[button].validTarget, |
||
200 | target, |
||
201 | GB_Settings[GB_INDEX][bar].Button[button].name); |
||
202 | |||
203 | GB_ActionButton_ShowInContext(actionbutton, origContext, GB_Settings[GB_INDEX][bar].Button[button].OOCoption, GB_Settings[GB_INDEX][bar].Button[button].flashInContext); |
||
204 | end |
||
205 | |||
206 | function GB_ActionButton_CheckBuffContexts(context, target, name) |
||
207 | if (not UnitIsPlayer(target)) then |
||
208 | if (UnitHealth(target) <= 0) then return 0; end |
||
209 | end |
||
210 | if (context == "NotBuffed") then |
||
211 | if (GB_Get_BuffMatch(name, target)) then |
||
212 | return -1; |
||
213 | elseif (name == GB_MINLVL_SPELLS.PWShield) then |
||
214 | if (GB_Get_DebuffMatch(GB_TEXT.WeakenedSoul, target)) then return -1; end |
||
215 | elseif (GB_AREA_BUFFS[name]) then |
||
216 | if (GB_Get_BuffMatch(GB_AREA_BUFFS[name], target)) then return -1; end |
||
217 | elseif (GB_Get("hideAllBlessings") and string.find(name, GB_TEXT.Blessing)) then |
||
218 | if (GB_Get_BuffMatch(GB_TEXT.Blessing, target)) then return -1; end |
||
219 | end |
||
220 | elseif (context == "NotDebuffed") then |
||
221 | if (GB_Get_DebuffMatch(name, target)) then return -1; end |
||
222 | elseif (context == "MagicDebuffed") then |
||
223 | if (not GB_Get_DebuffMatch(GB_FILTERS.Magic, target, 1)) then return -1; end |
||
224 | elseif (context == "Cursed") then |
||
225 | if (not GB_Get_DebuffMatch(GB_FILTERS.Curse, target, 1)) then return -1; end |
||
226 | elseif (context == "Diseased") then |
||
227 | if (name ~= GB_TEXT.Purify) then |
||
228 | if (not GB_Get_DebuffMatch(GB_FILTERS.Disease, target, 1)) then return -1; end |
||
229 | else |
||
230 | if ((not GB_Get_DebuffMatch(GB_FILTERS.Disease, target, 1)) and (not GB_Get_DebuffMatch(GB_FILTERS.Poison, target, 1))) then |
||
231 | return -1; |
||
232 | end |
||
233 | end |
||
234 | elseif (context == "Poisoned") then |
||
235 | if (name ~= GB_TEXT.Purify) then |
||
236 | if (not GB_Get_DebuffMatch(GB_FILTERS.Poison, target, 1)) then return -1; end |
||
237 | else |
||
238 | if ((not GB_Get_DebuffMatch(GB_FILTERS.Disease, target, 1)) and (not GB_Get_DebuffMatch(GB_FILTERS.Poison, target, 1))) then |
||
239 | return -1; |
||
240 | end |
||
241 | end |
||
242 | end |
||
243 | return 0; |
||
244 | end |
||
245 | |||
246 | function GB_ActionButton_CheckClassContext(target, classes) |
||
247 | if (UnitIsPlayer(target)) then |
||
248 | if (not classes[UnitClass(target)]) then return -1; end |
||
249 | end |
||
250 | return 0; |
||
251 | end |
||
252 | |||
253 | function GB_ActionButton_CheckCombatContext(inCombat, notInCombat) |
||
254 | if (inCombat and (not GB_INCOMBAT)) then |
||
255 | return -1; |
||
256 | end |
||
257 | if (notInCombat and GB_INCOMBAT) then |
||
258 | return -1; |
||
259 | end |
||
260 | return 0; |
||
261 | end |
||
262 | |||
263 | function GB_ActionButton_CheckFormContext(context) |
||
264 | if (context and GB_Get_CurrentForm() ~= context) then |
||
265 | return -1; |
||
266 | else |
||
267 | return 0; |
||
268 | end |
||
269 | end |
||
270 | |||
271 | function GB_ActionButton_CheckHealthContexts(context, target, name, rank) |
||
272 | if (not UnitIsPlayer(target)) then |
||
273 | if (UnitHealth(target) <= 0) then return; end |
||
274 | end |
||
275 | local threshold; |
||
276 | if (context == "Health1") then |
||
277 | threshold = 1; |
||
278 | elseif (context == "Health2") then |
||
279 | threshold = 2; |
||
280 | elseif (context == "Health3") then |
||
281 | threshold = 3; |
||
282 | elseif (context == "Health4") then |
||
283 | threshold = 4; |
||
284 | end |
||
285 | if (threshold) then |
||
286 | if (not GB_Get_PastThreshold("healthThresholds", target, threshold)) then return -1; end |
||
287 | elseif (context == "Dead") then |
||
288 | if (UnitHealth(target) > 0 and (not UnitIsDeadOrGhost(target))) then |
||
289 | return -1; |
||
290 | end |
||
291 | if (not UnitIsVisible(target)) then |
||
292 | return -1; |
||
293 | end |
||
294 | elseif (context == "DmgGTHeal") then |
||
295 | if (rank and UnitHealthMax(target) and UnitHealthMax(target) ~= 100) then |
||
296 | if (GB_SPELLS[name][rank].avg > (UnitHealthMax(target) - UnitHealth(target))) then |
||
297 | return -1; |
||
298 | end |
||
299 | end |
||
300 | elseif (context == "Area") then |
||
301 | local numPast = 0; |
||
302 | if (GB_Get_PastThreshold("aeThreshold", "player")) then |
||
303 | numPast = numPast + 1; |
||
304 | end |
||
305 | for i = 1,GetNumPartyMembers() do |
||
306 | if (UnitHealth("party"..i) and UnitHealth("party"..i) > 0 and UnitIsVisible("party"..i) and (not GB_Get("limitaerange") or CheckInteractDistance("party"..i, 4))) then |
||
307 | if (GB_Get_PastThreshold("aeThreshold", "party"..i)) then |
||
308 | numPast = numPast + 1; |
||
309 | end |
||
310 | end |
||
311 | end |
||
312 | if (numPast < GB_Settings[GB_INDEX].numPastAEThreshold) then |
||
313 | return -1; |
||
314 | end |
||
315 | end |
||
316 | return 0; |
||
317 | end |
||
318 | |||
319 | function GB_ActionButton_CheckOutdoorsContext(context) |
||
320 | if (not context) then return 0; end |
||
321 | local outdoors = GetMapInfo(); |
||
322 | if (not outdoors) then |
||
323 | return -1; |
||
324 | else |
||
325 | return 0; |
||
326 | end |
||
327 | end |
||
328 | |||
329 | function GB_ActionButton_CheckManaContexts(context, target) |
||
330 | if (not UnitIsPlayer(target)) then |
||
331 | if (UnitHealth(target) <= 0) then return; end |
||
332 | end |
||
333 | local threshold = GB_Get("manaThreshold"); |
||
334 | local damage; |
||
335 | if (string.find(threshold, "%%")) then |
||
336 | _,_,threshold = string.find(threshold, "(%d*)%%"); |
||
337 | damage = 100 - UnitMana(target) / UnitManaMax(target) * 100; |
||
338 | else |
||
339 | if (UnitManaMax(target) == 100) then return 0; end |
||
340 | damage = UnitManaMax(target) - UnitMana(target); |
||
341 | end |
||
342 | threshold = tonumber(threshold); |
||
343 | if (not threshold) then return 0; end |
||
344 | if (damage < threshold) then |
||
345 | return -1; |
||
346 | end |
||
347 | return 0; |
||
348 | end |
||
349 | |||
350 | function GB_ActionButton_CheckValidTargetContext(validTarget, target, name) |
||
351 | if (not validTarget) then return 0; end |
||
352 | if (not UnitIsPlayer(target)) then |
||
353 | if (UnitHealth(target) <= 0) then return; end |
||
354 | end |
||
355 | local creatureType = UnitCreatureType(target); |
||
356 | if (not creatureType) then creatureType = GB_TEXT.Humanoid; end |
||
357 | if (name == GB_TEXT.ManaBurn or name == GB_TEXT.ViperSting or name == GB_TEXT.Silence or name == GB_TEXT.Counterspell) then |
||
358 | if (UnitPowerType(target) ~= 0 or UnitManaMax(target) == 0) then |
||
359 | return -1; |
||
360 | end |
||
361 | elseif (name == GB_TEXT.CurseOfDoom) then |
||
362 | if (UnitIsPlayer(target)) then |
||
363 | return -1; |
||
364 | end |
||
365 | elseif (name == GB_MINLVL_SPELLS.PWShield) then |
||
366 | if (not UnitInParty(target)) then |
||
367 | if (not GB_UnitInRaid(target)) then |
||
368 | return -1; |
||
369 | end |
||
370 | end |
||
371 | if (GB_Get_DebuffMatch(GB_TEXT.WeakenedSoul, target)) then return -1; end |
||
372 | elseif (not GB_TARGET_SPELLS[name]) then |
||
373 | return 0; |
||
374 | elseif (not GB_TARGET_SPELLS[name][creatureType]) then |
||
375 | return -1; |
||
376 | end |
||
377 | return 0; |
||
378 | end |
||
379 | |||
380 | function GB_ActionButton_OnClick(unitBar, button, clickcasttoggle, unitoverride) |
||
381 | if (unitBar == "target") then |
||
382 | unitBar = GB_Get_UnitBar(unitBar); |
||
383 | end |
||
384 | if (not unitBar) then return; end |
||
385 | unitBar = getglobal(unitBar); |
||
386 | |||
387 | local retarget = false; |
||
388 | local hadTarget, targetName; |
||
389 | |||
390 | local idType = GB_Settings[GB_INDEX][unitBar.index].Button[button].idType; |
||
391 | local name = GB_Settings[GB_INDEX][unitBar.index].Button[button].name; |
||
392 | local rank = GB_Settings[GB_INDEX][unitBar.index].Button[button].rank; |
||
393 | local target = unitBar.unit; |
||
394 | if (unitBar:GetName() == "GB_LowestHealthBar") then |
||
395 | if (GB_SPELLS[name][rank].type == "cure") then |
||
396 | target = GB_Get_CureTarget(name); |
||
397 | elseif (GB_SPELLS[name][rank].type == "buff" and name ~= GB_MINLVL_SPELLS.PWShield) then |
||
398 | target = GB_Get_BuffTarget(name); |
||
399 | else |
||
400 | target = unitBar.unit(); |
||
401 | end |
||
402 | if (not target) then |
||
403 | local text = string.gsub(GB_TEXT.TargetNotFound, '$n', name); |
||
404 | GB_Feedback(text); |
||
405 | return; |
||
406 | end |
||
407 | end |
||
408 | if (unitoverride) then |
||
409 | target = unitoverride; |
||
410 | end |
||
411 | GB_LAST_UNIT = target; |
||
412 | |||
413 | local overridePO; |
||
414 | if (UnitName("target")) then |
||
415 | hadTarget = true; |
||
416 | if (not UnitCanAttack("player", "target")) then |
||
417 | if (UnitIsPlayer("target")) then |
||
418 | targetName = UnitName("target"); |
||
419 | else |
||
420 | targetName = "NPC"; |
||
421 | end |
||
422 | TargetUnit(target); |
||
423 | retarget = true; |
||
424 | elseif (UnitFactionGroup("target") == UnitFactionGroup("player") and UnitIsPlayer("target")) then |
||
425 | targetName = UnitName("target"); |
||
426 | TargetUnit(target); |
||
427 | retarget = true; |
||
428 | end |
||
429 | end |
||
430 | |||
431 | if (not clickcasttoggle) then |
||
432 | if (IsShiftKeyDown() and (not GB_Get("dontTargetPet")) and target ~= "target") then |
||
433 | local unitnum; |
||
434 | if (target == "player") then |
||
435 | target = "pet"; |
||
436 | elseif (string.find(target, "party")) then |
||
437 | _,_,unitnum = string.find(target, "party(%d*)"); |
||
438 | target = "partypet"..unitnum; |
||
439 | elseif (string.find(target, "raid")) then |
||
440 | _,_,unitnum = string.find(target, "raid(%d*)"); |
||
441 | target = "raidpet"..unitnum; |
||
442 | end |
||
443 | TargetUnit(target); |
||
444 | target = "target"; |
||
445 | retarget = true; |
||
446 | end |
||
447 | if (IsControlKeyDown()) then |
||
448 | if (not GB_Settings[GB_INDEX].applyPOonCtrl) then |
||
449 | overridePO = true; |
||
450 | end |
||
451 | elseif (GB_Settings[GB_INDEX].applyPOonCtrl) then |
||
452 | overridePO = true; |
||
453 | end |
||
454 | end |
||
455 | if (idtype == "macro") then |
||
456 | TargetUnit(target); |
||
457 | retarget = true; |
||
458 | end |
||
459 | if (name == GB_TEXT.DispelMagic and UnitCanAttack("player", "target")) then |
||
460 | TargetUnit(target); |
||
461 | retarget = true; |
||
462 | end |
||
463 | if (GB_Settings[GB_INDEX].changeTarget) then |
||
464 | TargetUnit(target); |
||
465 | retarget = false; |
||
466 | end |
||
467 | if (target == "target") then |
||
468 | retarget = false; |
||
469 | end |
||
470 | if (GB_Settings[GB_INDEX][unitBar.index].Button[button].assist) then |
||
471 | retarget = false; |
||
472 | AssistUnit(target); |
||
473 | target = "target"; |
||
474 | end |
||
475 | |||
476 | if (name ~= GB_TEXT.Attack) then |
||
477 | GB_AttackTarget(); |
||
478 | end |
||
479 | |||
480 | GB_LAST_SPELL = nil; |
||
481 | GB_LAST_SPELLNUM = GB_LAST_SPELLNUM + 1; |
||
482 | GB_ANNOUNCEFAILURE = nil; |
||
483 | GB_ANNOUNCEINTERRUPTED = nil; |
||
484 | GB_ISCASTING = nil; |
||
485 | GB_INSTANTCASTING = nil; |
||
486 | if (idType == "spell") then |
||
487 | local spellName, spellRank = GB_Get_CorrectSpell(unitBar.index, button, target, overridePO); |
||
488 | if (spellName) then |
||
489 | if (GB_Get_ActionUsuable(spellName, spellRank, getglobal(unitBar:GetName().."_Button_"..button))) then |
||
490 | local castit = true; |
||
491 | if (GB_Settings[GB_INDEX][unitBar.index].Button[button].cancelHeal) then |
||
492 | if (not GB_Get_PastThreshold("cancelHealThreshold", target, threshold)) then |
||
493 | castit = false; |
||
494 | end |
||
495 | end |
||
496 | if (castit) then |
||
497 | if (GB_Settings[GB_INDEX].autoleaveform and GB_SPELLS[spellName][spellRank].type == "heal") then |
||
498 | if (GB_PLAYER_CLASS == "PRIEST" and GB_SHADOWFORM_INDEX) then |
||
499 | CancelPlayerBuff(GB_SHADOWFORM_INDEX); |
||
500 | elseif (GB_PLAYER_CLASS == "DRUID") then |
||
501 | local f = GB_Get_CurrentForm() |
||
502 | if (f > 0) then |
||
503 | CastShapeshiftForm(f) |
||
504 | end |
||
505 | end |
||
506 | end |
||
507 | CastSpell( GB_SPELLS[spellName][spellRank].id, "BOOKTYPE_SPELL" ); |
||
508 | if (GB_Settings[GB_INDEX][unitBar.index].Button[button].announce) then |
||
509 | GB_ANNOUNCEFAILURE = nil; |
||
510 | GB_ANNOUNCEINTERRUPTED = nil; |
||
511 | GB_ISCASTING = true; |
||
512 | GB_INSTANTCASTING = nil; |
||
513 | GB_ANNOUNCETEXT = GB_Get_AnnounceText(spellName, spellRank, target, GB_Settings[GB_INDEX][unitBar.index].Button[button].announceText); |
||
514 | GB_WHISPERTARGET = UnitName(target); |
||
515 | if (GB_SPELLS[spellName][spellRank].castingTime == 0) then |
||
516 | GB_INSTANTCASTING = true; |
||
517 | end |
||
518 | end |
||
519 | elseif (not GB_Settings[GB_INDEX][unitBar.index].Button[button].preventOverhealing) then |
||
520 | GB_Feedback(GB_TEXT.NotPastCancelHeal); |
||
521 | end |
||
522 | if (GB_Settings[GB_INDEX][unitBar.index].Button[button].cancelHeal and castit) then |
||
523 | GB_CURRENT_HEAL = {spellName, spellRank, target}; |
||
524 | end |
||
525 | end |
||
526 | end |
||
527 | elseif (idType == "item") then |
||
528 | UseContainerItem(GB_ITEMS[name].bag, GB_ITEMS[name].slot); |
||
529 | elseif (idType == "inv") then |
||
530 | UseInventoryItem(GB_INVENTORY[name].id); |
||
531 | elseif (idType == "macro") then |
||
532 | GB_RunMacro(name); |
||
533 | end |
||
534 | |||
535 | if (SpellIsTargeting()) then |
||
536 | if ( unitBar.index == "hostiletarget") then |
||
537 | SpellTargetUnit("player"); |
||
538 | else |
||
539 | SpellTargetUnit(target); |
||
540 | end |
||
541 | end |
||
542 | |||
543 | if (retarget) then |
||
544 | if (not hadTarget) then |
||
545 | ClearTarget(); |
||
546 | elseif (targetName) then |
||
547 | if (targetName == "NPC") then |
||
548 | TargetLastTarget(); |
||
549 | else |
||
550 | TargetByName(targetName); |
||
551 | end |
||
552 | else |
||
553 | TargetLastEnemy(); |
||
554 | end |
||
555 | end |
||
556 | GB_LAST_UNIT = nil; |
||
557 | end |
||
558 | |||
559 | function GB_ActionButton_OnEvent(event) |
||
560 | if (not GB_INITIALIZED) then return; end |
||
561 | |||
562 | if (event == "UNIT_AURA" and arg1 == "target" and (not GroupButtonsFrame.targetauras)) then return; end |
||
563 | |||
564 | if (event == "ACTIONBAR_UPDATE_COOLDOWN") then |
||
565 | GB_ActionButton_UpdateCooldown(); |
||
566 | return; |
||
567 | end |
||
568 | if (GB_Options:IsVisible()) then |
||
569 | this:Show(); |
||
570 | return; |
||
571 | end |
||
572 | if (event == "PARTY_MEMBERS_CHANGED" or event == "RAID_ROSTER_UPDATE") then |
||
573 | GB_ActionButton_CheckAllContexts(this); |
||
574 | return; |
||
575 | elseif (event == "PLAYER_TARGET_CHANGED") then |
||
576 | if (UnitCanAttack("player", "target") and this:GetParent():GetName() == "GB_HostileTargetBar") then |
||
577 | GB_ActionButton_CheckAllContexts(this); |
||
578 | return; |
||
579 | end |
||
580 | if ((not UnitCanAttack("player", "target")) and this:GetParent():GetName() == "GB_FriendlyTargetBar") then |
||
581 | GB_ActionButton_CheckAllContexts(this); |
||
582 | return; |
||
583 | end |
||
584 | end |
||
585 | |||
586 | local origContext = GB_Get_InContext(this); |
||
587 | local target = this:GetParent().unit; |
||
588 | local lhbar; |
||
589 | if (this:GetParent().index == "lowesthealth") then |
||
590 | lhbar = true; |
||
591 | if (GB_SPELLS[GB_Settings[GB_INDEX]["lowesthealth"].Button[this:GetID()].name] and GB_SPELLS[GB_Settings[GB_INDEX]["lowesthealth"].Button[this:GetID()].name][GB_Settings[GB_INDEX]["lowesthealth"].Button[this:GetID()].rank].type == "cure") then |
||
592 | target = GB_Get_CureTarget(GB_Settings[GB_INDEX]["lowesthealth"].Button[this:GetID()].name); |
||
593 | elseif (GB_SPELLS[GB_Settings[GB_INDEX]["lowesthealth"].Button[this:GetID()].name] and GB_SPELLS[GB_Settings[GB_INDEX]["lowesthealth"].Button[this:GetID()].name][GB_Settings[GB_INDEX]["lowesthealth"].Button[this:GetID()].rank].type == "buff" and GB_Settings[GB_INDEX]["lowesthealth"].Button[this:GetID()].name ~= GB_MINLVL_SPELLS.PWShield) then |
||
594 | target = GB_Get_BuffTarget(GB_Settings[GB_INDEX]["lowesthealth"].Button[this:GetID()].name); |
||
595 | else |
||
596 | target = this:GetParent().unit(); |
||
597 | end |
||
598 | if (target) then |
||
599 | getglobal(this:GetName().."TextFrame_Name"):SetText(UnitName(target)); |
||
600 | else |
||
601 | getglobal(this:GetName().."TextFrame_Name"):SetText(""); |
||
602 | target = "player"; |
||
603 | end |
||
604 | end |
||
605 | if (GB_Settings[GB_INDEX][this:GetParent().index].Button[this:GetID()].assist) then |
||
606 | target = target.."target"; |
||
607 | end |
||
608 | if (not UnitExists(target)) then return; end |
||
609 | local bar = this:GetParent().index; |
||
610 | local buttNum = this:GetID(); |
||
611 | |||
612 | if (event == "UPDATE_BONUS_ACTIONBAR") then |
||
613 | this.InContext.form = GB_ActionButton_CheckFormContext(GB_Settings[GB_INDEX][bar].Button[buttNum].form); |
||
614 | elseif (event == "PLAYER_ENTER_COMBAT" or event == "PLAYER_LEAVE_COMBAT" or event == "PLAYER_REGEN_DISABLED" or event == "PLAYER_REGEN_ENABLED") then |
||
615 | this.InContext.combat = GB_ActionButton_CheckCombatContext( |
||
616 | GB_Settings[GB_INDEX][bar].Button[buttNum].inCombat, |
||
617 | GB_Settings[GB_INDEX][bar].Button[buttNum].notInCombat); |
||
618 | elseif (event == "UNIT_AURA") then |
||
619 | if (arg1 == target or lhbar) then |
||
620 | this.InContext.main = GB_ActionButton_CheckBuffContexts(GB_Settings[GB_INDEX][bar].Button[buttNum].context, target, GB_Settings[GB_INDEX][bar].Button[buttNum].name); |
||
621 | if (GB_Settings[GB_INDEX][bar].Button[buttNum].name == GB_MINLVL_SPELLS.PWShield and GB_Settings[GB_INDEX][bar].Button[buttNum].validTarget) then |
||
622 | this.InContext.validTarget = GB_ActionButton_CheckValidTargetContext( |
||
623 | GB_Settings[GB_INDEX][bar].Button[buttNum].validTarget, |
||
624 | target, |
||
625 | GB_Settings[GB_INDEX][bar].Button[buttNum].name); |
||
626 | end |
||
627 | end |
||
628 | elseif (event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH" ) then |
||
629 | if (arg1 == target or lhbar or GB_Settings[GB_INDEX][bar].Button[buttNum].context == "Area") then |
||
630 | this.InContext.main = GB_ActionButton_CheckHealthContexts( GB_Settings[GB_INDEX][bar].Button[buttNum].context, target, GB_Settings[GB_INDEX][bar].Button[buttNum].name, GB_Settings[GB_INDEX][bar].Button[buttNum].rank); |
||
631 | end |
||
632 | elseif (event == "UNIT_MANA" or event == "UNIT_MAXMANA") then |
||
633 | if (arg1 == target) then |
||
634 | this.InContext.main = GB_ActionButton_CheckManaContexts(GB_Settings[GB_INDEX][bar].Button[buttNum].context, target); |
||
635 | end |
||
636 | -- elseif (event == "ZONE_CHANGED" or event == "ZONE_CHANGED_INDOORS") then |
||
637 | -- this.InContext.outdoors = GB_ActionButton_CheckOutdoorsContext(settings.outdoors); |
||
638 | end |
||
639 | |||
640 | GB_ActionButton_ShowInContext(this, origContext, GB_Settings[GB_INDEX][bar].Button[buttNum].OOCoption, GB_Settings[GB_INDEX][bar].Button[buttNum].flashInContext); |
||
641 | end |
||
642 | |||
643 | function GB_ActionButton_OnUpdate(elapsed) |
||
644 | if (not GB_INITIALIZED) then return; end |
||
645 | |||
646 | if (this.timer) then |
||
647 | this.timer = this.timer - elapsed; |
||
648 | if (this.timer > 0) then |
||
649 | return; |
||
650 | else |
||
651 | this.timer = TOOLTIP_UPDATE_TIME; |
||
652 | end |
||
653 | end |
||
654 | |||
655 | if (this.flashing) then |
||
656 | this.flashtimer = this.flashtimer - arg1; |
||
657 | if (this.flashtimer < 0) then |
||
658 | this.flashtimer = .5; |
||
659 | if (this.Direction) then |
||
660 | this.Direction = nil; |
||
661 | else |
||
662 | this.Direction = 1; |
||
663 | end |
||
664 | else |
||
665 | if (this.Direction) then |
||
666 | local a = this.flashtimer * 2; |
||
667 | this:SetAlpha(a); |
||
668 | else |
||
669 | local a = 1 - this.flashtimer * 2; |
||
670 | this:SetAlpha(a); |
||
671 | end |
||
672 | end |
||
673 | end |
||
674 | |||
675 | if (this.cooldowncount) then |
||
676 | this.cooldowncount = this.cooldowncount - elapsed; |
||
677 | if (this.cooldowncount <= 0) then |
||
678 | this.cooldowncount = nil; |
||
679 | getglobal(this:GetName().."TextFrame_CooldownCount"):SetText(""); |
||
680 | else |
||
681 | local count = math.ceil(this.cooldowncount); |
||
682 | if (count < 60) then |
||
683 | getglobal(this:GetName().."TextFrame_CooldownCount"):SetText(count.."s"); |
||
684 | else |
||
685 | count = math.ceil(count / 60); |
||
686 | getglobal(this:GetName().."TextFrame_CooldownCount"):SetText(count.."m"); |
||
687 | end |
||
688 | end |
||
689 | end |
||
690 | |||
691 | local idType = GB_Settings[GB_INDEX][this:GetParent().index].Button[this:GetID()].idType; |
||
692 | local name = GB_Settings[GB_INDEX][this:GetParent().index].Button[this:GetID()].name; |
||
693 | local rank = GB_Settings[GB_INDEX][this:GetParent().index].Button[this:GetID()].rank; |
||
694 | |||
695 | local textscale = getglobal(this:GetName().."TextFrame").textscale; |
||
696 | if (textscale) then |
||
697 | if (getglobal(this:GetName().."TextFrame"):GetScale() ~= textscale) then |
||
698 | getglobal(this:GetName().."TextFrame"):SetScale(textscale); |
||
699 | end |
||
700 | end |
||
701 | |||
702 | if (idType == "spell") then |
||
703 | local inRange, enoughMana = true, true; |
||
704 | local texture = getglobal(this:GetName().."_Icon"); |
||
705 | local range = GB_SPELLS[name][rank].range; |
||
706 | local unit = this:GetParent().unit; |
||
707 | if (this:GetParent().index == "lowesthealth") then |
||
708 | unit = this:GetParent().unit(); |
||
709 | end |
||
710 | if (unit ~= "target") then |
||
711 | range = tonumber(GB_SPELLS[name][rank].rangeinyds); |
||
712 | end |
||
713 | local mana = GB_SPELLS[name][rank].mana; |
||
714 | if (range) then |
||
715 | if (unit == "target") then |
||
716 | if (IsActionInRange(range) == 0) then |
||
717 | inRange = false; |
||
718 | elseif ((not UnitIsVisible("target")) and UnitExists("target")) then |
||
719 | inRange = false; |
||
720 | end |
||
721 | -- elseif (unit == "player") then |
||
722 | -- elseif (MapLibrary_Updater and (not GB_Settings[GB_INDEX].disablePartyRange)) then |
||
723 | -- local inInstance = MapLibrary.InInstance(); |
||
724 | -- if (MapLibrary.Ready and (not inInstance)) then |
||
725 | -- local dist = MapLibrary.UnitDistance(unit, "player", 1); |
||
726 | -- if (dist and dist > range) then inRange = false; end |
||
727 | -- end |
||
728 | end |
||
729 | end |
||
730 | if (mana) then |
||
731 | if (UnitMana("player") < mana and (not GB_Get_BuffMatch(GB_TEXT.InnerFocus, "player"))) then |
||
732 | enoughMana = false; |
||
733 | end |
||
734 | end |
||
735 | if (not inRange) then |
||
736 | texture:SetVertexColor(GB_Settings[GB_INDEX].OORcolor.r, GB_Settings[GB_INDEX].OORcolor.g, GB_Settings[GB_INDEX].OORcolor.b); |
||
737 | elseif (not enoughMana) then |
||
738 | texture:SetVertexColor(GB_Settings[GB_INDEX].OOMcolor.r, GB_Settings[GB_INDEX].OOMcolor.g, GB_Settings[GB_INDEX].OOMcolor.b); |
||
739 | elseif (this.grey) then |
||
740 | texture:SetVertexColor(GB_Settings[GB_INDEX].greycolor.r, GB_Settings[GB_INDEX].greycolor.g, GB_Settings[GB_INDEX].greycolor.b); |
||
741 | else |
||
742 | texture:SetVertexColor(1, 1, 1); |
||
743 | end |
||
744 | end |
||
745 | end |
||
746 | |||
747 | function GB_ActionButton_SetCount(bar, button) |
||
748 | if (not GB_INITIALIZED) then return; end |
||
749 | if (bar == "raid" or bar == "partypet") then return; end |
||
750 | local name = GB_Settings[GB_INDEX][bar].Button[button].name; |
||
751 | local idType = GB_Settings[GB_INDEX][bar].Button[button].idType; |
||
752 | local count; |
||
753 | if (not name) then |
||
754 | GB_ActionButton_Initialize(bar, button); |
||
755 | GB_Set_Appearance(bar); |
||
756 | return; |
||
757 | end |
||
758 | if (idType == "item") then |
||
759 | count = GB_Get_ItemCount(name); |
||
760 | elseif (idType == "inv") then |
||
761 | count = GB_INVENTORY[name].count; |
||
762 | else |
||
763 | for _, unitBar in GB_UNITS_ARRAY[bar].frames do |
||
764 | getglobal(unitBar.."_Button_"..button.."TextFrame_Count"):SetText(""); |
||
765 | end |
||
766 | return; |
||
767 | end |
||
768 | for _, unitBar in GB_UNITS_ARRAY[bar].frames do |
||
769 | if (count > 1) then |
||
770 | getglobal(unitBar.."_Button_"..button.."TextFrame_Count"):SetText(count); |
||
771 | else |
||
772 | getglobal(unitBar.."_Button_"..button.."TextFrame_Count"):SetText(""); |
||
773 | end |
||
774 | end |
||
775 | if (count == 0) then |
||
776 | GB_ActionButton_Initialize(bar, button); |
||
777 | GB_Set_Appearance(bar); |
||
778 | end |
||
779 | end |
||
780 | |||
781 | function GB_ActionButton_ShowInContext(button, origContext, OOCoption, FlashInContext) |
||
782 | local currentContext = GB_Get_InContext(button); |
||
783 | if (currentContext) then |
||
784 | button:Show(); |
||
785 | if (FlashInContext) then |
||
786 | button.flashtimer = .5; |
||
787 | button.flashing = true; |
||
788 | else |
||
789 | button.flashing = nil; |
||
790 | button.flashtimer = nil; |
||
791 | end |
||
792 | button.grey = nil; |
||
793 | getglobal(button:GetName().."_Icon"):SetVertexColor(1, 1, 1); |
||
794 | button:SetAlpha(GB_Settings[GB_INDEX][button:GetParent().index].alpha); |
||
795 | else |
||
796 | if (OOCoption == "hide") then |
||
797 | button:Hide(); |
||
798 | elseif (OOCoption == "grey") then |
||
799 | button.grey = true; |
||
800 | getglobal(button:GetName().."_Icon"):SetVertexColor(.4, .4, .4); |
||
801 | button.flashing = nil; |
||
802 | button.flashtimer = nil; |
||
803 | button:SetAlpha(GB_Settings[GB_INDEX][button:GetParent().index].alpha); |
||
804 | elseif (OOCoption == "flash") then |
||
805 | button.flashtimer = .5; |
||
806 | button.flashing = true; |
||
807 | end |
||
808 | end |
||
809 | if (currentContext ~= origContext) then |
||
810 | local unitBar; |
||
811 | if (button:GetParent().index == "party" or button:GetParent().index == "pet" or button:GetParent().index == "partypet" or button:GetParent().index == "raid") then |
||
812 | unitBar = GB_Get_UnitBar(button:GetParent().unit); |
||
813 | else |
||
814 | unitBar = GB_Get_UnitBar(button:GetParent().index); |
||
815 | end |
||
816 | GB_Set_Layout(button:GetParent().index, unitBar); |
||
817 | end |
||
818 | end |
||
819 | |||
820 | function GB_ActionButton_UpdateCooldown() |
||
821 | if (not GB_INITIALIZED) then return; end |
||
822 | local start, duration, enable; |
||
823 | local idType = GB_Settings[GB_INDEX][this:GetParent().index].Button[this:GetID()].idType; |
||
824 | local name = GB_Settings[GB_INDEX][this:GetParent().index].Button[this:GetID()].name; |
||
825 | local rank = GB_Settings[GB_INDEX][this:GetParent().index].Button[this:GetID()].rank; |
||
826 | |||
827 | if (idType == "spell") then |
||
828 | start, duration, enable = GetSpellCooldown(GB_SPELLS[name][rank].id, BOOKTYPE_SPELL); |
||
829 | elseif (idType == "item") then |
||
830 | start, duration, enable = GetContainerItemCooldown(GB_ITEMS[name].bag, GB_ITEMS[name].slot); |
||
831 | elseif (idType == "inv") then |
||
832 | start, duration, enable = GetInventoryItemCooldown("player", GB_INVENTORY[name].id); |
||
833 | end |
||
834 | if (start and start > 0) then |
||
835 | if (GB_Settings[GB_INDEX].showCooldown) then |
||
836 | if (this.cooldowncount) then |
||
837 | this.cooldowncount = duration - (GetTime() - start); |
||
838 | else |
||
839 | this.cooldowncount = duration; |
||
840 | end |
||
841 | end |
||
842 | CooldownFrame_SetTimer(getglobal(this:GetName().."_Cooldown"), start, duration, enable); |
||
843 | else |
||
844 | if (GB_Settings[GB_INDEX].showCooldown) then |
||
845 | this.cooldowncount = 0; |
||
846 | end |
||
847 | end |
||
848 | end |