forked from ennvina/spellactivationoverlay
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSpellActivationOverlay.lua
More file actions
730 lines (636 loc) · 26.2 KB
/
SpellActivationOverlay.lua
File metadata and controls
730 lines (636 loc) · 26.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
local AddonName, SAO = ...
local Module = "main"
-- Optimize frequent calls
local GetSpellInfo = GetSpellInfo
local GetTime = GetTime
local InCombatLockdown = InCombatLockdown
local sizeScale = 0.8;
local longSide = 256 * sizeScale;
local shortSide = 128 * sizeScale;
local combatOverlayFactor = 2;
local useTimer = true;
local useSound = false;
function SpellActivationOverlay_OnLoad(self)
SAO.Frame = self;
SAO.ShowAllOverlays = SpellActivationOverlay_ShowAllOverlays;
SAO.HideOverlays = SpellActivationOverlay_HideOverlays;
SAO.HideAllOverlays = SpellActivationOverlay_HideAllOverlays;
SAO.SetOverlayTimer = SpellActivationOverlay_SetAllOverlayTimers;
self.overlaysInUse = {};
self.unusedOverlays = {};
self.combatOnlyOverlays = {};
self.offset = 0;
self.scale = 1;
SpellActivationOverlay_OnChangeGeometry(self);
self.useTimer = true;
SpellActivationOverlay_OnChangeTimerVisibility(self);
self.useSound = false;
SpellActivationOverlay_OnChangeSoundToggle(self);
local className, classFile, classId = UnitClass("player");
local class = SAO.Class[classFile];
if class then
class.Intrinsics = { className, classFile, classId };
SAO.CurrentClass = class;
-- Keys of the class other than "Intrinsics", "Register" and "LoadOptions" are expected to be event names
for key, _ in pairs(class) do
if (key ~= "Intrinsics" and key ~= "Register" and key ~= "LoadOptions") then
self:RegisterEvent(key);
end
end
else
local currentClass = tostring(select(1, UnitClass("player")));
SAO:Error(Module, "Class unknown or not converted yet:", currentClass);
end
if ( SAO.IsCata() ) then
-- These events do not exist in Classic Era, Burning Crusade Classic, nor Wrath Classic
-- They have yet to be confirmed for Cataclysm, but they could (should?) exist
self:RegisterEvent("SPELL_ACTIVATION_OVERLAY_SHOW");
self:RegisterEvent("SPELL_ACTIVATION_OVERLAY_HIDE");
end
-- self:RegisterUnitEvent("UNIT_AURA", "player");
self:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED");
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("SPELL_UPDATE_USABLE");
self:RegisterEvent("PLAYER_REGEN_ENABLED");
self:RegisterEvent("PLAYER_REGEN_DISABLED");
self:RegisterEvent("SPELLS_CHANGED");
self:RegisterEvent("LEARNED_SPELL_IN_TAB");
self:RegisterEvent("LOADING_SCREEN_DISABLED");
end
function SpellActivationOverlay_OnChangeGeometry(self)
SAO:Trace(Module, "SpellActivationOverlay_OnChangeGeometry");
-- Ignores self.scale because it should be used to scale alerts, not core
local newSize = 256 * sizeScale + self.offset;
-- Resize the parent instead of self because the parent is the one bearing the Size element
self:GetParent():SetSize(newSize, newSize);
-- Resize existing overlays and prepare variables for future overlays
longSide = 256 * sizeScale * self.scale;
shortSide = 128 * sizeScale * self.scale;
for _, overlayList in pairs(self.overlaysInUse) do
for i=1, #overlayList do
local overlay = overlayList[i];
overlay:SetGeometry(longSide, shortSide);
end
end
-- Resize offsets for overlays that offset a mask when out of combat
for _, overlay in ipairs(self.combatOnlyOverlays) do
if overlay.combat.animOut:IsPlaying() then
-- Calling the 'Play' custom function for animOut will setup its offset
SpellActivationOverlayFrame_PlayCombatAnimOut(overlay.combat.animOut);
end
end
end
function SpellActivationOverlay_OnChangeTimerVisibility(self)
SAO:Trace(Module, "SpellActivationOverlay_OnChangeTimerVisibility");
if useTimer == self.useTimer then
return;
end
useTimer = self.useTimer;
for _, overlayList in pairs(self.overlaysInUse) do
for i=1, #overlayList do
local overlay = overlayList[i];
overlay.mask:SetShown(useTimer);
end
end
end
function SpellActivationOverlay_OnChangeSoundToggle(self)
SAO:Trace(Module, "SpellActivationOverlay_OnChangeSoundToggle");
if useSound == self.useSound then
return;
end
useSound = self.useSound;
if useSound then
for _, overlayList in pairs(self.overlaysInUse) do
if #overlayList > 0 then
-- Play generic sound if at least one effect is displayed
-- No need to spam players with several effects, because currently there is only one type of sound effect
overlayList[1].soundHandle = SAO:PlaySpellAlertSound();
-- Please note, we might play a sound for a non-pulsing alert (which should not play sounds),
-- but that's a minor issue, and we might even argue that it's for the better,
-- because it gives feedback that the player actually changed the sound option
break;
end
end
else
for _, overlayList in pairs(self.overlaysInUse) do
for i=1, #overlayList do
local overlay = overlayList[i];
SAO:StopSpellAlertSound(overlay.soundHandle);
overlay.soundHandle = nil;
end
end
end
end
function SpellActivationOverlay_OnEvent(self, event, ...)
SAO:TraceThrottled(event, Module, "SpellActivationOverlay_OnEvent "..tostring(event));
--[[
Dead code because these events do not exist in Classic Era, BC Classic, nor Wrath Classic
Also, the "displaySpellActivationOverlays" console variable does not exist
-- Update with upcoming Cataclysm --
Must look into it for Cataclysm Classic, because these events should occur once again
But we have added a few parameters since then - must add missing parameters if needed
For now, we simply write debug information to try to confirm these events are emitted
]]
if ( event == "SPELL_ACTIVATION_OVERLAY_SHOW" ) then
local spellID, texture, positions, scale, r, g, b = ...;
SAO:Debug(Module, "Received native SPELL_ACTIVATION_OVERLAY_SHOW with spell ID "..tostring(spellID)..", texture "..tostring(texture)..", positions '"..tostring(positions).."', scale "..tostring(scale)..", (r g b) = ("..tostring(r).." "..tostring(g).." "..tostring(b)..")");
-- if ( GetCVarBool("displaySpellActivationOverlays") ) then
-- SpellActivationOverlay_ShowAllOverlays(self, spellID, texture, positions, scale, r, g, b, true)
-- end
elseif ( event == "SPELL_ACTIVATION_OVERLAY_HIDE" ) then
local spellID = ...;
SAO:Debug(Module, "Received native SPELL_ACTIVATION_OVERLAY_HIDE with spell ID "..tostring(spellID));
-- if spellID then
-- SpellActivationOverlay_HideOverlays(self, spellID);
-- else
-- SpellActivationOverlay_HideAllOverlays(self);
-- end
end
if ( not self.disableDimOutOfCombat ) then
if ( event == "PLAYER_REGEN_DISABLED" ) then
self.combatAnimOut:Stop(); --In case we're in the process of animating this out.
self.combatAnimIn:Play();
for _, overlay in ipairs(self.combatOnlyOverlays) do
overlay.combat.animOut:Stop();
SpellActivationOverlayFrame_PlayCombatAnimIn(overlay.combat.animIn);
end
elseif ( event == "PLAYER_REGEN_ENABLED" ) then
self.combatAnimIn:Stop(); --In case we're in the process of animating this out.
self.combatAnimOut:Play();
for _, overlay in ipairs(self.combatOnlyOverlays) do
overlay.combat.animIn:Stop();
SpellActivationOverlayFrame_PlayCombatAnimOut(overlay.combat.animOut);
end
end
end
if ( event ) then
SAO:OnEvent(event, ...);
end
end
local complexLocationTable = {
["RIGHT (FLIPPED)"] = {
RIGHT = { hFlip = true },
},
["BOTTOM (FLIPPED)"] = {
BOTTOM = { vFlip = true },
},
["LEFT + RIGHT (FLIPPED)"] = {
LEFT = {},
RIGHT = { hFlip = true },
},
["TOP + BOTTOM (FLIPPED)"] = {
TOP = {},
BOTTOM = { vFlip = true },
},
["LEFT (CW)"] = {
LEFT = { cw = 1 },
},
["LEFT (CCW)"] = {
LEFT = { cw = -1 },
},
["RIGHT (CW)"] = {
RIGHT = { cw = 1 },
},
["RIGHT (CCW)"] = {
RIGHT = { cw = -1 },
},
["TOP (CW)"] = {
TOP = { cw = 1 },
},
["TOP (CCW)"] = {
TOP = { cw = -1 },
},
["BOTTOM (CW)"] = {
BOTTOM = { cw = 1 },
},
["BOTTOM (CCW)"] = {
BOTTOM = { cw = -1 },
},
}
function SpellActivationOverlay_ShowAllOverlays(self, spellID, texturePath, positions, scale, r, g, b, autoPulse, forcePulsePlay, endTime, combatOnly)
SAO:Trace(Module, "SpellActivationOverlay_ShowAllOverlays "..tostring(spellID));
positions = strupper(positions);
if ( complexLocationTable[positions] ) then
for location, info in pairs(complexLocationTable[positions]) do
SpellActivationOverlay_ShowOverlay(self, spellID, texturePath, location, scale, r, g, b, info.vFlip, info.hFlip, info.cw, autoPulse, forcePulsePlay, endTime, combatOnly);
end
else
SpellActivationOverlay_ShowOverlay(self, spellID, texturePath, positions, scale, r, g, b, false, false, 0, autoPulse, forcePulsePlay, endTime, combatOnly);
end
end
function SpellActivationOverlay_ShowOverlay(self, spellID, texturePath, position, scale, r, g, b, vFlip, hFlip, cw, autoPulse, forcePulsePlay, endTime, combatOnly)
SAO:Trace(Module, "SpellActivationOverlay_ShowOverlay "..tostring(spellID).." "..position);
SAO:Debug(Module, "Starting Overlay at location "..position.." for spell ID "..spellID.." "..(GetSpellInfo(spellID) or "")..(endTime and (" for "..math.floor((type(endTime) == 'number' and endTime or endTime.endTime)-GetTime()+0.5).." secs") or ""));
if (SpellActivationOverlayDB and SpellActivationOverlayDB.alert and not SpellActivationOverlayDB.alert.enabled) then
-- Last chance to quit displaying the overlay, if the main overlay flag is disabled
return;
end
local overlay = SpellActivationOverlay_GetOverlay(self, spellID, position);
SAO_LastShownOverlay = overlay; -- Global variable for debugging purposes
overlay.spellID = spellID;
overlay.position = position;
local texLeft, texRight, texTop, texBottom = 0, 1, 0, 1;
if ( vFlip ) then
texTop, texBottom = 1, 0;
end
if ( hFlip ) then
texLeft, texRight = 1, 0;
end
if ( not cw or cw == 0 ) then
overlay.texture:SetTexCoord(texLeft, texRight, texTop, texBottom);
-- overlay.texture:SetTexCoord(texLeft,texTop, texLeft,texBottom, texRight,texTop, texRight,texBottom); -- Written for reference
elseif ( cw > 0 ) then
overlay.texture:SetTexCoord(texLeft,texBottom, texRight,texBottom, texLeft,texTop, texRight,texTop);
else
overlay.texture:SetTexCoord(texRight,texTop, texLeft,texTop, texRight,texBottom, texLeft,texBottom);
end
overlay.SetGeometry = function(self, longSide, shortSide)
local parent = self:GetParent();
self:ClearAllPoints();
local width, height;
if ( position == "CENTER" ) then
width, height = longSide, longSide;
self:SetPoint("CENTER", parent, "CENTER", 0, 0);
elseif ( position == "LEFT" ) then
width, height = shortSide, longSide;
self:SetPoint("RIGHT", parent, "LEFT", 0, 0);
elseif ( position == "RIGHT" ) then
width, height = shortSide, longSide;
self:SetPoint("LEFT", parent, "RIGHT", 0, 0);
elseif ( position == "TOP" ) then
width, height = longSide, shortSide;
self:SetPoint("BOTTOM", parent, "TOP");
elseif ( position == "BOTTOM" ) then
width, height = longSide, shortSide;
self:SetPoint("TOP", parent, "BOTTOM");
elseif ( position == "TOPRIGHT" ) then
width, height = shortSide, shortSide;
self:SetPoint("BOTTOMLEFT", parent, "TOPRIGHT", 0, 0);
elseif ( position == "TOPLEFT" ) then
width, height = shortSide, shortSide;
self:SetPoint("BOTTOMRIGHT", parent, "TOPLEFT", 0, 0);
elseif ( position == "BOTTOMRIGHT" ) then
width, height = shortSide, shortSide;
self:SetPoint("TOPLEFT", parent, "BOTTOMRIGHT", 0, 0);
elseif ( position == "BOTTOMLEFT" ) then
width, height = shortSide, shortSide;
self:SetPoint("TOPRIGHT", parent, "BOTTOMLEFT", 0, 0);
else
--GMError("Unknown SpellActivationOverlay position: "..tostring(position));
return;
end
self:SetSize(width * scale, height * scale);
self.mask:SetSize(longSide * scale, longSide * scale);
self.combat:SetSize(longSide * scale * combatOverlayFactor, longSide * scale * combatOverlayFactor);
-- Combat mask texture is bigger, to get an 'eye of the storm' effect at start
end
overlay:SetGeometry(longSide, shortSide);
overlay.texture:SetTexture(texturePath);
overlay.texture:SetVertexColor(r / 255, g / 255, b / 255);
overlay.animOut:Stop(); --In case we're in the process of animating this out.
if useSound and (autoPulse or forcePulsePlay) then
overlay.soundHandle = SAO:PlaySpellAlertSound();
end
overlay:Show();
if ( forcePulsePlay ) then
overlay.pulse:Play();
end
overlay.pulse.autoPlay = autoPulse;
overlay.mask:SetShown(useTimer);
SpellActivationOverlay_SetOverlayTimer(self, overlay, endTime);
overlay.combatOnly = combatOnly;
if ( combatOnly ) then
tDeleteItem(self.combatOnlyOverlays, overlay); -- In case it was already in the list
tinsert(self.combatOnlyOverlays, overlay);
if ( InCombatLockdown() ) then
overlay.combat.animOut:Stop();
-- SpellActivationOverlayFrame_PlayCombatAnimIn(overlay.combat.animIn); -- Do not play combat.animIn if already in combat
elseif ( self.disableDimOutOfCombat ) then -- Do not start animOut, because animIn will be started about 10 lines below
overlay.combat.animIn:Stop();
SpellActivationOverlayFrame_PlayCombatAnimOut(overlay.combat.animOut);
end
else
tDeleteItem(self.combatOnlyOverlays, overlay);
end
if ( not self.disableDimOutOfCombat and not InCombatLockdown() ) then
-- Simulate a short, fake in-combat mode, to make the spell alert more visible
self.combatAnimOut:Stop();
self.combatAnimIn:Play();
if ( combatOnly ) then
-- Playing combat.animIn to add a smoother fade-in animation when not in combat
-- Because the player is not in combat, the 'very quick' popup is overkill
overlay.combat.animOut:Stop();
SpellActivationOverlayFrame_PlayCombatAnimIn(overlay.combat.animIn);
end
end
end
function SpellActivationOverlay_GetOverlay(self, spellID, position)
local overlayList = self.overlaysInUse[spellID];
local overlay;
if ( overlayList ) then
for i=1, #overlayList do
if ( overlayList[i].position == position ) then
overlay = overlayList[i];
end
end
end
if ( not overlay ) then
overlay = SpellActivationOverlay_GetUnusedOverlay(self);
if ( overlayList ) then
tinsert(overlayList, overlay);
else
self.overlaysInUse[spellID] = { overlay };
end
end
return overlay;
end
function SpellActivationOverlay_HideOverlays(self, spellID)
SAO:Trace(Module, "SpellActivationOverlay_HideOverlays "..tostring(spellID));
local overlayList = self.overlaysInUse[spellID];
if ( overlayList ) then
for i=1, #overlayList do
local overlay = overlayList[i];
SAO:Debug(Module, "Hiding Overlay at location "..overlay.position.." for spell ID "..overlay.spellID.." "..(GetSpellInfo(overlay.spellID) or ""));
overlay.pulse:Pause();
overlay.animOut:Play();
end
end
end
function SpellActivationOverlay_HideAllOverlays(self)
SAO:Trace(Module, "SpellActivationOverlay_HideAllOverlays");
for spellID, overlayList in pairs(self.overlaysInUse) do
SpellActivationOverlay_HideOverlays(self, spellID);
end
end
function SpellActivationOverlay_SetAllOverlayTimers(self, spellID, endTime)
SAO:Trace(Module, "SpellActivationOverlay_SetAllOverlayTimers "..tostring(spellID).." "..tostring(endTime));
if ( not endTime ) then
return
end
local overlayList = self.overlaysInUse[spellID];
if ( overlayList ) then
for i=1, #overlayList do
local overlay = overlayList[i];
SpellActivationOverlay_SetOverlayTimer(self, overlay, endTime);
end
end
end
function SpellActivationOverlay_SetOverlayTimer(self, overlay, endTime)
SAO:Trace(Module, "SpellActivationOverlay_SetOverlayTimer "..tostring(overlay).." "..tostring(endTime));
local startTime = type(endTime) == 'table' and endTime.startTime or nil;
endTime = type(endTime) == 'table' and endTime.endTime or endTime;
if ( not endTime or endTime <= GetTime() ) then
return; -- endTime not set or "too soon"
end
local maxLag = 0.25; -- Estimated maximum lag, used to compare existing endTime with new endTime
if ( type(overlay.endTime) == 'number' and SAO:IsTimeAlmostEqual(endTime, overlay.endTime, maxLag) ) then
return; -- Overlay already has similar endTime: assume this is the same timer
end
overlay.endTime = endTime;
SAO:Debug(Module, "Setting Overlay Timer at location "..overlay.position.." for spell ID "..overlay.spellID.." "..(GetSpellInfo(overlay.spellID) or "")..(endTime and (" for "..math.floor(endTime-GetTime()+0.5).." secs") or " without time"));
local offset = startTime and (GetTime() - startTime) or 0;
local duration = endTime - GetTime() + offset - 0.1; -- Subtract 0.1 to account for final shrink
local position = overlay.position;
local isHorizontal = position:sub(1, 3) == "TOP" or position:sub(1, 6) == "BOTTOM";
local isVertical = position:sub(#position-3) == "LEFT" or position:sub(#position-4) == "RIGHT";
if ( isHorizontal and isVertical ) then
-- Corner
overlay.mask.timeoutXY.scaleXY:SetDuration(duration);
overlay.mask.timeoutXY:Stop();
overlay.mask.timeoutXY:Play(false, offset);
elseif ( isHorizontal ) then
-- Top/Bottom
overlay.mask.timeoutX.scaleX:SetDuration(duration);
overlay.mask.timeoutX:Stop();
overlay.mask.timeoutX:Play(false, offset);
elseif ( isVertical ) then
-- Left/Right
overlay.mask.timeoutY.scaleY:SetDuration(duration);
overlay.mask.timeoutY:Stop();
overlay.mask.timeoutY:Play(false, offset);
end
end
function SpellActivationOverlay_GetUnusedOverlay(self)
local overlay = tremove(self.unusedOverlays, #self.unusedOverlays);
if ( not overlay ) then
overlay = SpellActivationOverlay_CreateOverlay(self);
end
return overlay;
end
function SpellActivationOverlay_CreateOverlay(self)
SAO:Trace(Module, "SpellActivationOverlay_CreateOverlay");
return CreateFrame("Frame", nil, self, "SpellActivationOverlayTemplate");
end
function SpellActivationOverlayTexture_OnShow(self)
SAO:Trace(Module, "SpellActivationOverlayTexture_OnShow");
self.animIn:Play();
end
function SpellActivationOverlayTexture_TerminateOverlay(overlay)
SAO:Trace(Module, "SpellActivationOverlayTexture_TerminateOverlay "..tostring(overlay));
SAO:Debug(Module, "Terminating Overlay at location "..overlay.position.." for spell ID "..overlay.spellID.." "..(GetSpellInfo(overlay.spellID) or ""));
local overlayParent = overlay:GetParent();
-- No longer need to pulse
overlay.pulse:Stop();
-- Stop animations that may re-trigger terminate when they finish
overlay.animOut:Stop();
overlay.mask.timeoutXY:Stop();
overlay.mask.timeoutX:Stop();
overlay.mask.timeoutY:Stop();
overlay.combat.animIn:Stop();
overlay.combat.animOut:Stop();
-- Stop playing sound
SAO:StopSpellAlertSound(overlay.soundHandle, 1000);
overlay.soundHandle = nil;
-- Hide the overlay and make it available again in the pool for future use
overlay.mask:SetScale(1); -- Reset scale, in case a previous animation shrank it to 0.01
overlay.endTime = nil; -- Reset endTime, to avoid excessive optimizations when re-using this overlay
overlay:Hide();
tDeleteItem(overlayParent.overlaysInUse[overlay.spellID], overlay);
tinsert(overlayParent.unusedOverlays, overlay);
end
function SpellActivationOverlayFrame_OnTimeoutFinished(anim)
SAO:Trace(Module, "SpellActivationOverlayFrame_OnTimeoutFinished "..tostring(anim));
local mask = anim:GetParent();
local overlay = mask:GetParent();
mask:SetScale(0.01); -- Shrink mask scale to 0.01 to avoid glitches with final animation below
-- Start the fade-out animation, which will eventually terminate the overlay
overlay.animOut:Play();
end
function SpellActivationOverlayFrame_GetCombatAnimOffsetFarAway(anim)
local combat = anim:GetParent();
local overlay = combat:GetParent();
local frame = overlay:GetParent();
local position = overlay.position;
local baseLongSide = 256;
local baseShortSide = 128;
local farAway = ((baseLongSide-baseShortSide) / 2 + baseShortSide) * sizeScale * frame.scale * combatOverlayFactor;
if ( position == "CENTER" ) then
return 0, 0;
elseif ( position == "LEFT" ) then
return farAway, 0;
elseif ( position == "RIGHT" ) then
return -farAway, 0;
elseif ( position == "TOP" ) then
return 0, -farAway;
elseif ( position == "BOTTOM" ) then
return 0, farAway;
elseif ( position == "TOPRIGHT" ) then
return -farAway, -farAway;
elseif ( position == "TOPLEFT" ) then
return farAway, -farAway;
elseif ( position == "BOTTOMRIGHT" ) then
return -farAway, farAway;
elseif ( position == "BOTTOMLEFT" ) then
return farAway, farAway;
else
--GMError("Unknown SpellActivationOverlay position: "..tostring(position));
return;
end
end
function SpellActivationOverlayFrame_PlayCombatAnimIn(animIn)
SAO:Trace(Module, "SpellActivationOverlayFrame_PlayCombatAnimIn "..tostring(animIn));
local offsetX, offsetY = SpellActivationOverlayFrame_GetCombatAnimOffsetFarAway(animIn);
offsetX, offsetY = 0.7 * offsetX, 0.7 * offsetY -- Attenuate distance to make it visible sooner
animIn.point1:SetOffset(offsetX, offsetY);
animIn.point2:SetOffset(-offsetX, -offsetY);
animIn:Play();
end
function SpellActivationOverlayFrame_PlayCombatAnimOut(animOut)
SAO:Trace(Module, "SpellActivationOverlayFrame_PlayCombatAnimOut "..tostring(animOut));
local offsetX, offsetY = SpellActivationOverlayFrame_GetCombatAnimOffsetFarAway(animOut);
animOut.point1:SetOffset(offsetX, offsetY);
animOut:Play();
end
function SpellActivationOverlayTexture_ShowCombatMask(anim)
SAO:Trace(Module, "SpellActivationOverlayTexture_ShowCombatMask "..tostring(anim));
local combat = anim:GetParent():GetParent();
combat:SetTexture("Interface/Addons/SpellActivationOverlay/textures/maskzero");
local overlay = combat:GetParent();
SAO:Debug(Module, "Showing combat mask for Overlay at location "..overlay.position.." for spell ID "..overlay.spellID.." "..(GetSpellInfo(overlay.spellID) or ""));
end
function SpellActivationOverlayTexture_HideCombatMask(anim)
SAO:Trace(Module, "SpellActivationOverlayTexture_HideCombatMask "..tostring(anim));
local combat = anim:GetParent():GetParent();
combat:SetTexture("");
local overlay = combat:GetParent();
SAO:Debug(Module, "Hiding combat mask for Overlay at location "..overlay.position.." for spell ID "..overlay.spellID.." "..(GetSpellInfo(overlay.spellID) or ""));
end
function SpellActivationOverlayTexture_OnCombatAnimInPlay(animIn)
SAO:Trace(Module, "SpellActivationOverlayTexture_OnCombatAnimInPlay "..tostring(animIn));
SpellActivationOverlayTexture_HideCombatMask(animIn);
end
function SpellActivationOverlayTexture_OnCombatAnimInFinished(animIn)
SAO:Trace(Module, "SpellActivationOverlayTexture_OnCombatAnimInFinished "..tostring(animIn));
SpellActivationOverlayTexture_ShowCombatMask(animIn);
end
function SpellActivationOverlayTexture_OnCombatAnimInStop(animIn)
SAO:Trace(Module, "SpellActivationOverlayTexture_OnCombatAnimInStop "..tostring(animIn));
SpellActivationOverlayTexture_ShowCombatMask(animIn);
end
function SpellActivationOverlayTexture_OnCombatAnimOutPlay(animOut)
SAO:Trace(Module, "SpellActivationOverlayTexture_OnCombatAnimOutPlay "..tostring(animOut));
SpellActivationOverlayTexture_ShowCombatMask(animOut);
end
function SpellActivationOverlayTexture_OnFadeInPlay(animGroup)
SAO:Trace(Module, "SpellActivationOverlayTexture_OnFadeInPlay "..tostring(animGroup));
local overlay = animGroup:GetParent();
overlay:SetAlpha(0);
end
function SpellActivationOverlayTexture_OnFadeInFinished(animGroup)
SAO:Trace(Module, "SpellActivationOverlayTexture_OnFadeInFinished "..tostring(animGroup));
local overlay = animGroup:GetParent();
overlay:SetAlpha(1);
if ( overlay.pulse.autoPlay ) then
overlay.pulse:Play();
end
end
function SpellActivationOverlayTexture_PreStartPulse(anim)
local overlay = anim:GetParent():GetParent();
if ( overlay.pulse.autoPlay ) then
overlay.pulse:Play();
end
end
function SpellActivationOverlayTexture_OnFadeOutFinished(anim)
SAO:Trace(Module, "SpellActivationOverlayTexture_OnFadeOutFinished "..tostring(anim));
local overlay = anim:GetRegionParent();
SpellActivationOverlayTexture_TerminateOverlay(overlay);
end
function SpellActivationOverlayFrame_OnFadeInFinished(anim)
SAO:Trace(Module, "SpellActivationOverlayFrame_OnFadeInFinished "..tostring(anim));
if ( not InCombatLockdown() ) then
-- Fade-out immediately if not in combat
-- Although it may look counter-intuitive to be out-of-combat during an in-combat animation,
-- This may actually happen if the in-combat mode was forced to showcase out-of-combat procs e.g., healing-based procs
local frame = anim:GetParent();
if ( not frame.disableDimOutOfCombat ) then
frame.combatAnimOut:Play();
for _, overlay in ipairs(frame.combatOnlyOverlays) do
SpellActivationOverlayFrame_PlayCombatAnimOut(overlay.combat.animOut);
end
end
end
end
function SpellActivationOverlayFrame_SetForceAlpha1(enabled)
SAO:Trace(Module, "SpellActivationOverlayFrame_SetForceAlpha1 "..tostring(enabled));
local self = SpellActivationOverlayFrame;
if (enabled) then
if (not self.disableDimOutOfCombat) then
self.disableDimOutOfCombat = 1;
self.combatAnimOut:Stop(); --In case we're in the process of animating this out.
self:SetAlpha(1);
for _, overlay in ipairs(self.combatOnlyOverlays) do
overlay.combat.animOut:Stop();
overlay.texture:SetAlpha(1);
end
else
-- Set last digit
self.disableDimOutOfCombat = self.disableDimOutOfCombat-self.disableDimOutOfCombat%10+1;
end
else
if (self.disableDimOutOfCombat) then
-- Reset last digit
self.disableDimOutOfCombat = self.disableDimOutOfCombat-self.disableDimOutOfCombat%10;
if (self.disableDimOutOfCombat == 0) then
self.disableDimOutOfCombat = nil;
if (not InCombatLockdown()) then
self.combatAnimOut:Play();
for _, overlay in ipairs(self.combatOnlyOverlays) do
SpellActivationOverlayFrame_PlayCombatAnimOut(overlay.combat.animOut);
end
end
end
end
end
end
function SpellActivationOverlayFrame_SetForceAlpha2(enabled)
SAO:Trace(Module, "SpellActivationOverlayFrame_SetForceAlpha2 "..tostring(enabled));
local self = SpellActivationOverlayFrame;
if (enabled) then
if (not self.disableDimOutOfCombat) then
self.disableDimOutOfCombat = 10;
self.combatAnimOut:Stop(); --In case we're in the process of animating this out.
self:SetAlpha(1);
for _, overlay in ipairs(self.combatOnlyOverlays) do
overlay.combat.animOut:Stop();
overlay.texture:SetAlpha(1);
end
else
-- Set second-to-last digit
self.disableDimOutOfCombat = self.disableDimOutOfCombat%10+10;
end
else
if (self.disableDimOutOfCombat) then
-- Reset second-to-last digit
self.disableDimOutOfCombat = self.disableDimOutOfCombat%10;
if (self.disableDimOutOfCombat == 0) then
self.disableDimOutOfCombat = nil;
if (not InCombatLockdown()) then
self.combatAnimOut:Play();
for _, overlay in ipairs(self.combatOnlyOverlays) do
SpellActivationOverlayFrame_PlayCombatAnimOut(overlay.combat.animOut);
end
end
end
end
end
end