-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathLoseControl.lua
1022 lines (935 loc) · 36.6 KB
/
LoseControl.lua
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
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[ Code Credits - to the people whose code I borrowed and learned from:
Vendethiel, Lawz, Wowwiki, Kollektiv, Tuller, ckknight, The authors of Nao!!
Thanks! :)
]]
local L = "LoseControl"
local UIParent = UIParent -- it's faster to keep local references to frequently used global vars
local function log(msg) DEFAULT_CHAT_FRAME:AddMessage(msg) end -- alias for convenience
-------------------------------------------------------------------------------
local CC = LOSECONTROL["CC"]
local Silence = LOSECONTROL["Silence"]
local Disarm = LOSECONTROL["Disarm"]
local Root = LOSECONTROL["Root"]
local Snare = LOSECONTROL["Snare"]
local Immune = LOSECONTROL["Immune"]
local PvE = LOSECONTROL["PvE"]
local TypeMap = {
[CC] = "CC",
[Silence] = "Silence",
[Disarm] = "Disarm",
[Root] = "Root",
[Snare] = "Snare",
[Immune] = "Immune",
[PvE] = "PvE",
}
local spellIds = {
-- Death Knight
[47481] = CC, -- Gnaw (Ghoul)
[51209] = CC, -- Hungering Cold
[47476] = Silence, -- Strangulate
[45524] = Snare, -- Chains of Ice
[55666] = Snare, -- Desecration (no duration, lasts as long as you stand in it)
[58617] = Snare, -- Glyph of Heart Strike
[50436] = Snare, -- Icy Clutch (Chilblains)
-- Druid
[5211] = CC, -- Bash (also Shaman Spirit Wolf ability)
[33786] = CC, -- Cyclone
[2637] = CC, -- Hibernate (works against Druids in most forms and Shamans using Ghost Wolf)
[22570] = CC, -- Maim
[9005] = CC, -- Pounce
[339] = Root, -- Entangling Roots
[19675] = Root, -- Feral Charge Effect (immobilize with interrupt [spell lockout, not silence])
[58179] = Snare, -- Infected Wounds
[61391] = Snare, -- Typhoon
-- Hunter
[60210] = CC, -- Freezing Arrow Effect
[3355] = CC, -- Freezing Trap Effect
[24394] = CC, -- Intimidation
[1513] = CC, -- Scare Beast (works against Druids in most forms and Shamans using Ghost Wolf)
[19503] = CC, -- Scatter Shot
[19386] = CC, -- Wyvern Sting
[34490] = Silence, -- Silencing Shot
[53359] = Disarm, -- Chimera Shot - Scorpid
[19306] = Root, -- Counterattack
[19185] = Root, -- Entrapment
[35101] = Snare, -- Concussive Barrage
[5116] = Snare, -- Concussive Shot
[13810] = Snare, -- Frost Trap Aura (no duration, lasts as long as you stand in it)
[61394] = Snare, -- Glyph of Freezing Trap
[2974] = Snare, -- Wing Clip
-- Hunter Pets
[50519] = CC, -- Sonic Blast (Bat)
[50541] = Disarm, -- Snatch (Bird of Prey)
[54644] = Snare, -- Froststorm Breath (Chimera)
[50245] = Root, -- Pin (Crab)
[50271] = Snare, -- Tendon Rip (Hyena)
[50518] = CC, -- Ravage (Ravager)
[54706] = Root, -- Venom Web Spray (Silithid)
[4167] = Root, -- Web (Spider)
-- Mage
[44572] = CC, -- Deep Freeze
[31661] = CC, -- Dragon's Breath
[12355] = CC, -- Impact
[118] = CC, -- Polymorph
[18469] = Silence, -- Silenced - Improved Counterspell
[64346] = Disarm, -- Fiery Payback
[33395] = Root, -- Freeze (Water Elemental)
[122] = Root, -- Frost Nova
[11071] = Root, -- Frostbite
[55080] = Root, -- Shattered Barrier
[11113] = Snare, -- Blast Wave
[6136] = Snare, -- Chilled (generic effect, used by lots of spells [looks weird on Improved Blizzard, might want to comment out])
[120] = Snare, -- Cone of Cold
[116] = Snare, -- Frostbolt
[47610] = Snare, -- Frostfire Bolt
[31589] = Snare, -- Slow
-- Paladin
[853] = CC, -- Hammer of Justice
[2812] = CC, -- Holy Wrath (works against Warlocks using Metamorphasis and Death Knights using Lichborne)
[20066] = CC, -- Repentance
[20170] = CC, -- Stun (Seal of Justice proc)
[10326] = CC, -- Turn Evil (works against Warlocks using Metamorphasis and Death Knights using Lichborne)
[63529] = Silence, -- Shield of the Templar
[20184] = Snare, -- Judgement of Justice (100% movement snare, druids and shamans might want this though)
-- Priest
[605] = CC, -- Mind Control
[64044] = CC, -- Psychic Horror
[8122] = CC, -- Psychic Scream
[9484] = CC, -- Shackle Undead (works against Death Knights using Lichborne)
[15487] = Silence, -- Silence
--[64058] = Disarm, -- Psychic Horror (duplicate debuff names not allowed atm, need to figure out how to support this later)
[15407] = Snare, -- Mind Flay
-- Rogue
[2094] = CC, -- Blind
[1833] = CC, -- Cheap Shot
[1776] = CC, -- Gouge
[408] = CC, -- Kidney Shot
[6770] = CC, -- Sap
[1330] = Silence, -- Garrote - Silence
[18425] = Silence, -- Silenced - Improved Kick
[51722] = Disarm, -- Dismantle
[31125] = Snare, -- Blade Twisting
[3409] = Snare, -- Crippling Poison
[26679] = Snare, -- Deadly Throw
-- Shaman
[39796] = CC, -- Stoneclaw Stun
[51514] = CC, -- Hex (although effectively a silence+disarm effect, it is conventionally thought of as a CC, plus you can trinket out of it)
[64695] = Root, -- Earthgrab (Storm, Earth and Fire)
[63685] = Root, -- Freeze (Frozen Power)
[3600] = Snare, -- Earthbind (5 second duration per pulse, but will keep re-applying the debuff as long as you stand within the pulse radius)
[8056] = Snare, -- Frost Shock
[8034] = Snare, -- Frostbrand Attack
-- Warlock
[710] = CC, -- Banish (works against Warlocks using Metamorphasis and Druids using Tree Form)
[6789] = CC, -- Death Coil
[5782] = CC, -- Fear
[5484] = CC, -- Howl of Terror
[6358] = CC, -- Seduction (Succubus)
[30283] = CC, -- Shadowfury
[24259] = Silence,-- Spell Lock (Felhunter)
[43523] = Silence,-- UA silence
[18118] = Snare, -- Aftermath
[18223] = Snare, -- Curse of Exhaustion
[32752] = CC, -- Summoning Disorientations (stun for active pet while summoning new one)
-- Warrior
[7922] = CC, -- Charge Stun
[12809] = CC, -- Concussion Blow
[20253] = CC, -- Intercept (also Warlock Felguard ability)
[5246] = CC, -- Intimidating Shout
[12798] = CC, -- Revenge Stun
[46968] = CC, -- Shockwave
[18498] = Silence, -- Silenced - Gag Order
[676] = Disarm, -- Disarm
[58373] = Root, -- Glyph of Hamstring
[23694] = Root, -- Improved Hamstring
[1715] = Snare, -- Hamstring
[12323] = Snare, -- Piercing Howl
-- Other
[30217] = CC, -- Adamantite Grenade
[67769] = CC, -- Cobalt Frag Bomb
[30216] = CC, -- Fel Iron Bomb
[20549] = CC, -- War Stomp
[25046] = Silence, -- Arcane Torrent
[39965] = Root, -- Frost Grenade
[55536] = Root, -- Frostweave Net
[13099] = Root, -- Net-o-Matic
[29703] = Snare, -- Dazed
-- Immunities
[46924] = Immune, -- Bladestorm (Warrior)
[642] = Immune, -- Divine Shield (Paladin)
[45438] = Immune, -- Ice Block (Mage)
[34692] = Immune, -- The Beast Within (Hunter)
[19263] = Immune, -- Deterrence (Hunter)
-- PvE
[28169] = PvE, -- Mutating Injection (Grobbulus)
[28059] = PvE, -- Positive Charge (Thaddius)
[28084] = PvE, -- Negative Charge (Thaddius)
[27819] = PvE, -- Detonate Mana (Kel'Thuzad)
[63024] = PvE, -- Gravity Bomb (XT-002 Deconstructor)
[63018] = PvE, -- Light Bomb (XT-002 Deconstructor)
[62589] = PvE, -- Nature's Fury (Freya, via Ancient Conservator)
[63276] = PvE, -- Mark of the Faceless (General Vezax)
}
local INTERRUPTS = {
[6552] = 4, -- [Warrior] Pummel
[72] = 6, -- [Warrior] Shield Bash
[1766] = 5, -- [Rogue] Kick
[47528] = 4, -- [DK] Mind Freeze
[57994] = 2, -- [Shaman] Wind Shear
[19647] = 6, -- [Warlock] Spell Lock
[132409]= 6, -- [Warlock] Spell Lock
[2139] = 8, -- [Mage] Counterspell
[16979] = 4, -- [Feral] Feral Charge (Bear)
}
local abilities = {} -- localized names are saved here
for k, v in pairs(spellIds) do
local name = GetSpellInfo(k)
if name then
abilities[name] = v
else -- Thanks to inph for this idea. Keeps things from breaking when Blizzard changes things.
log(L .. " unknown spellId: " .. k)
end
end
-------------------------------------------------------------------------------
-- Global references for attaching icons to various unit frames
local anchors = {
None = {}, -- empty but necessary
Blizzard = {
player = "PlayerPortrait",
pet = "PetPortrait",
target = "TargetFramePortrait",
focus = "FocusFramePortrait",
party1 = "PartyMemberFrame1Portrait",
party2 = "PartyMemberFrame2Portrait",
party3 = "PartyMemberFrame3Portrait",
party4 = "PartyMemberFrame4Portrait",
arena1 = "ArenaEnemyFrame1ClassPortrait",
arena2 = "ArenaEnemyFrame2ClassPortrait",
arena3 = "ArenaEnemyFrame3ClassPortrait",
arena4 = "ArenaEnemyFrame4ClassPortrait",
arena5 = "ArenaEnemyFrame5ClassPortrait",
},
Perl = {
player = "Perl_Player_Portrait",
pet = "Perl_Player_Pet_Portrait",
target = "Perl_Target_Portrait",
focus = "Perl_Focus_Portrait",
party1 = "Perl_Party_MemberFrame1_Portrait",
party2 = "Perl_Party_MemberFrame2_Portrait",
party3 = "Perl_Party_MemberFrame3_Portrait",
party4 = "Perl_Party_MemberFrame4_Portrait",
},
XPerl = {
player = "XPerl_PlayerportraitFrameportrait",
pet = "XPerl_Player_PetportraitFrameportrait",
target = "XPerl_TargetportraitFrameportrait",
focus = "XPerl_FocusportraitFrameportrait",
party1 = "XPerl_party1portraitFrameportrait",
party2 = "XPerl_party2portraitFrameportrait",
party3 = "XPerl_party3portraitFrameportrait",
party4 = "XPerl_party4portraitFrameportrait",
},
-- more to come here?
}
local ALL_CATS = {
"Immune",
"CC",
"PvE",
"Silence",
"Disarm",
"Root",
"Snare",
}
-------------------------------------------------------------------------------
-- Default settings
local DBdefaults = {
version = 3.33,
noCooldownCount = false,
priorities = ALL_CATS,
tracking = {
Immune = true,
CC = true,
PvE = true,
Silence = true,
Disarm = true,
Root = true,
Snare = false,
},
frames = {
player = {
enabled = true,
size = 36,
alpha = 1,
anchor = "None",
point = "CENTER",
relativePoint = "CENTER",
x = 0,
y = 110,
},
pet = {
enabled = true,
size = 36,
alpha = 1,
anchor = "Blizzard",
},
target = {
enabled = true,
size = 56,
alpha = 1,
anchor = "Blizzard",
},
focus = {
enabled = true,
size = 56,
alpha = 1,
anchor = "Blizzard",
},
party1 = {
enabled = true,
size = 36,
alpha = 1,
anchor = "Blizzard",
},
party2 = {
enabled = true,
size = 36,
alpha = 1,
anchor = "Blizzard",
},
party3 = {
enabled = true,
size = 36,
alpha = 1,
anchor = "Blizzard",
},
party4 = {
enabled = true,
size = 36,
alpha = 1,
anchor = "Blizzard",
},
arena1 = {
enabled = true,
size = 28,
alpha = 1,
anchor = "Blizzard",
},
arena2 = {
enabled = true,
size = 28,
alpha = 1,
anchor = "Blizzard",
},
arena3 = {
enabled = true,
size = 28,
alpha = 1,
anchor = "Blizzard",
},
arena4 = {
enabled = true,
size = 28,
alpha = 1,
anchor = "Blizzard",
},
arena5 = {
enabled = true,
size = 28,
alpha = 1,
anchor = "Blizzard",
},
},
}
local LoseControlDB -- local reference to the addon settings. this gets initialized when the ADDON_LOADED event fires
-------------------------------------------------------------------------------
-- Create the main class
local LoseControl = CreateFrame("Cooldown", nil, UIParent) -- Exposes the SetCooldown method
function LoseControl:OnEvent(event, ...) -- functions created in "object:method"-style have an implicit first parameter of "self", which points to object
self[event](self, ...) -- route event parameters to LoseControl:event methods
end
LoseControl:SetScript("OnEvent", LoseControl.OnEvent)
-- Handle default settings
function LoseControl:ADDON_LOADED(arg1)
if arg1 == L then
if _G.LoseControlDB and _G.LoseControlDB.version then
if _G.LoseControlDB.version < DBdefaults.version then
_G.LoseControlDB = CopyTable(DBdefaults)
log(LOSECONTROL["LoseControl reset."])
end
else -- never installed before
_G.LoseControlDB = CopyTable(DBdefaults)
log(LOSECONTROL["LoseControl reset."])
end
LoseControlDB = _G.LoseControlDB
LoseControl.noCooldownCount = LoseControlDB.noCooldownCount
end
end
LoseControl:RegisterEvent("ADDON_LOADED")
-- Initialize a frame's position
function LoseControl:PLAYER_ENTERING_WORLD() -- this correctly anchors enemy arena frames that aren't created until you zone into an arena
self.frame = LoseControlDB.frames[self.unitId] -- store a local reference to the frame's settings
local frame = self.frame
self.anchor = _G[anchors[frame.anchor][self.unitId]] or UIParent
self:SetParent(self.anchor:GetParent()) -- or LoseControl) -- If Hide() is called on the parent frame, its children are hidden too. This also sets the frame strata to be the same as the parent's.
--self:SetFrameStrata(frame.strata or "LOW")
self:ClearAllPoints() -- if we don't do this then the frame won't always move
self:SetWidth(frame.size)
self:SetHeight(frame.size)
self:SetPoint(
frame.point or "CENTER",
self.anchor,
frame.relativePoint or "CENTER",
frame.x or 0,
frame.y or 0
)
--self:SetAlpha(frame.alpha) -- doesn't seem to work; must manually set alpha after the cooldown is displayed, otherwise it doesn't apply.
end
local function IndexOf(tabl, value)
for k, v in pairs(tabl) do
if v == value then
return k
end
end
return 0
end
local UnitDebuff = UnitDebuff
local UnitBuff = UnitBuff
-- This is the main event
function LoseControl:UNIT_AURA(unitId) -- fired when a (de)buff is gained/lost
local frame = LoseControlDB.frames[unitId]
if not (unitId == self.unitId and frame.enabled and self.anchor:IsVisible()) then return end
-- the unit is currently kicked, don't show anything else
if self:GetKick() then return end
local maxExpirationTime = 0
local maxPriority = 99
local _, name, icon, Icon, duration, Duration, expirationTime, spellID
for i = 1, 40 do
name, _, icon, _, _, duration, expirationTime,_,_,_,spellID = UnitDebuff(unitId, i)
if not name then break end -- no more debuffs, terminate the loop
--log(i .. ") " .. name .. " | " .. rank .. " | " .. icon .. " | " .. count .. " | " .. debuffType .. " | " .. duration .. " | " .. expirationTime )
-- exceptions, when different auras have the same name (use icons or spell ids instead, still needs better fix...)
if name == "Wyvern Sting" and spellID ~= 49012 and spellID ~= 19386 then
name = nil -- hack to skip the next if condition since LUA doesn't have a "continue" statement
elseif name == "Psychic Horror" and icon == "Interface\\Icons\\Ability_Warrior_Disarm" then
name = nil
elseif name == "Unstable Affliction" and icon ~= "Interface\\Icons\\Spell_Holy_Silence" then
name = nil
end
if LoseControlDB.tracking[abilities[name]] then
-- only do indexof here to save on iterations
local prio = IndexOf(LoseControlDB.priorities, TypeMap[abilities[name]])
-- low prio = beginning of table = better
if prio < maxPriority or (prio == maxPriority and expirationTime > maxExpirationTime) then
maxPriority = prio
maxExpirationTime = expirationTime
Duration = duration
Icon = icon
end
end
end
-- Track Immunities
local immuPrio = IndexOf(LoseControlDB.priorities, "Immune") -- use a string
if not Icon and LoseControlDB.tracking[Immune] and immuPrio < maxPriority then -- only bother checking for immunities if there were no debuffs found
for i = 1, 40 do
name, _, icon, _, _, duration, expirationTime = UnitBuff(unitId, i)
if not name then break
elseif abilities[name] == "Immune" and expirationTime > maxExpirationTime then
maxExpirationTime = expirationTime
Duration = duration
Icon = icon
end
end
end
if maxExpirationTime == 0 then -- no (de)buffs found
self:ClearIcon()
elseif maxExpirationTime ~= self.maxExpirationTime then -- this is a different (de)buff, so initialize the cooldown
self.maxExpirationTime = maxExpirationTime
self:DisplayIcon(frame, Icon, maxExpirationTime - Duration, Duration)
end
end
function LoseControl:GetKick()
if not self.interrupt then return end
if GetTime() > self.interrupt then
self.interrupt = nil
return false
end
return true
end
function LoseControl:COMBAT_LOG_EVENT_UNFILTERED(...)
local subEvent = select(2, ...)
--local destName = select(7, ...)
local destGUID = select(6, ...)
local spellId = select(9, ...)
if UnitGUID(self.unitId) ~= destGUID then return end
if subEvent ~= "SPELL_CAST_SUCCESS" and subEvent ~= "SPELL_INTERRUPT" then
return
end
-- it is necessary to check ~= false, as if the unit isn't casting a channeled spell, it will be nil
if subEvent == "SPELL_CAST_SUCCESS" and select(8, UnitChannelInfo(self.unitId)) ~= false then
-- not interruptible
return
end
local frame = LoseControlDB.frames[self.unitId]
local interruptDuration = INTERRUPTS[spellId]
if not interruptDuration then return end
self.interrupt = GetTime() + interruptDuration
local icon = select(3, GetSpellInfo(spellId))
self:DisplayIcon(frame, icon, GetTime(), interruptDuration)
end
function LoseControl:DisplayIcon(frame, Icon, start, duration)
if self.anchor ~= UIParent then
self:SetFrameLevel(self.anchor:GetParent():GetFrameLevel()) -- must be dynamic, frame level changes all the time
if not self.drawlayer then
self.drawlayer = self.anchor:GetDrawLayer() -- back up the current draw layer
end
self.anchor:SetDrawLayer("BACKGROUND") -- Temporarily put the portrait texture below the debuff texture. This is the only reliable method I've found for keeping the debuff texture visible with the cooldown spiral on top of it.
end
if frame.anchor == "Blizzard" then
SetPortraitToTexture(self.texture, Icon) -- Sets the texture to be displayed from a file applying a circular opacity mask making it look round like portraits. TO DO: mask the cooldown frame somehow so the corners don't stick out of the portrait frame. Maybe apply a circular alpha mask in the OVERLAY draw layer.
else
self.texture:SetTexture(Icon)
end
self:Show()
self:SetCooldown(start, duration)
self:SetAlpha(frame.alpha) -- hack to apply transparency to the cooldown timer
end
function LoseControl:OnUpdate()
-- we *WERE* interrupted, but it just finished
if self.interrupt and not self:GetKick() then
-- trigger UNIT_AURA "manually". It will clear the frame if there is no aura to show.
self:UNIT_AURA(self.unitId)
end
end
function LoseControl:ClearIcon()
self.maxExpirationTime = 0
if self.anchor ~= UIParent and self.drawlayer then
self.anchor:SetDrawLayer(self.drawlayer) -- restore the original draw layer
end
self:Hide()
end
-- V: this is the worst way to go about it
-- basically when we tab-target, since the unitId doesn't change per say ("target"),
-- we do not detect that the kick icon shouldn't be displayed.
-- The right way to go about it would be to store kicks in a table UnitGUID=>Kick,
-- but :effort:. For now, this will do.
function LoseControl:ResetKick(unitId)
local frame = LoseControlDB.frames[unitId]
if not (unitId == self.unitId and frame and frame.enabled and self.anchor:IsVisible()) then return end
self.interrupt = nil
end
function LoseControl:PLAYER_FOCUS_CHANGED()
self:ResetKick("focus")
self:UNIT_AURA("focus")
end
function LoseControl:PLAYER_TARGET_CHANGED()
self:ResetKick("target")
self:UNIT_AURA("target")
end
local UnitDropDown -- declared here, initialized below in the options panel code
local AnchorDropDown
-- Handle mouse dragging
function LoseControl:StopMoving()
local frame = LoseControlDB.frames[self.unitId]
frame.point, frame.anchor, frame.relativePoint, frame.x, frame.y = self:GetPoint()
if not frame.anchor then
frame.anchor = "None"
if UIDropDownMenu_GetSelectedValue(UnitDropDown) == self.unitId then
UIDropDownMenu_SetSelectedValue(AnchorDropDown, "None") -- update the drop down to show that the frame has been detached from the anchor
end
end
self.anchor = _G[anchors[frame.anchor][self.unitId]] or UIParent
self:StopMovingOrSizing()
end
-- Constructor method
function LoseControl:new(unitId)
local o = CreateFrame("Cooldown", L .. unitId) --, UIParent)
setmetatable(o, self)
self.__index = self
-- Init class members
o.unitId = unitId -- ties the object to a unit
o.texture = o:CreateTexture(nil, "BORDER") -- displays the debuff; draw layer should equal "BORDER" because cooldown spirals are drawn in the "ARTWORK" layer.
o.texture:SetAllPoints(o) -- anchor the texture to the frame
o:SetReverse(true) -- makes the cooldown shade from light to dark instead of dark to light
--[[ Rufio's code to make the frame border pretty. Maybe use this somehow to mask cooldown corners in Blizzard frames.
o.overlay = o:CreateTexture(nil, "OVERLAY");
o.overlay:SetTexture("Interface\\AddOns\\LoseControl\\gloss");
o.overlay:SetPoint("TOPLEFT", -1, 1);
o.overlay:SetPoint("BOTTOMRIGHT", 1, -1);
o.overlay:SetVertexColor(0.25, 0.25, 0.25);]]
o:Hide()
-- Handle events
o:SetScript("OnEvent", self.OnEvent)
o:SetScript("OnDragStart", self.StartMoving) -- this function is already built into the Frame class
o:SetScript("OnDragStop", self.StopMoving) -- this is a custom function
o:SetScript("OnUpdate", self.OnUpdate)
o:RegisterEvent("PLAYER_ENTERING_WORLD")
o:RegisterEvent("UNIT_AURA")
if unitId == "focus" then
o:RegisterEvent("PLAYER_FOCUS_CHANGED")
elseif unitId == "target" then
o:RegisterEvent("PLAYER_TARGET_CHANGED")
end
o:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
return o
end
-- Create new object instance for each frame
local LC = {}
for k in pairs(DBdefaults.frames) do
LC[k] = LoseControl:new(k)
end
-------------------------------------------------------------------------------
-- Add main Interface Option Panel
local O = L .. "OptionsPanel"
local OptionsPanel = CreateFrame("Frame", O)
OptionsPanel.name = L
local title = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormalLarge")
title:SetText(L)
local subText = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
local notes = GetAddOnMetadata(L, "Notes-" .. GetLocale())
if not notes then
notes = GetAddOnMetadata(L, "Notes")
end
subText:SetText(notes)
-- "Unlock" checkbox - allow the frames to be moved
local Unlock = CreateFrame("CheckButton", O.."Unlock", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."UnlockText"]:SetText(LOSECONTROL["Unlock"])
function Unlock:OnClick()
if self:GetChecked() then
_G[O.."UnlockText"]:SetText(LOSECONTROL["Unlock"] .. LOSECONTROL[" (drag an icon to move)"])
local keys = {} -- for random icon sillyness
for k in pairs(spellIds) do
tinsert(keys, k)
end
for k, v in pairs(LC) do
local frame = LoseControlDB.frames[k]
if _G[anchors[frame.anchor][k]] or frame.anchor == "None" then -- only unlock frames whose anchor exists
v:UnregisterEvent("UNIT_AURA")
v:UnregisterEvent("PLAYER_FOCUS_CHANGED")
v:UnregisterEvent("PLAYER_TARGET_CHANGED")
v:SetMovable(true)
v:RegisterForDrag("LeftButton")
v:EnableMouse(true)
v.texture:SetTexture(select(3, GetSpellInfo(keys[random(#keys)])))
v:SetParent(nil) -- detach the frame from its parent or else it won't show if the parent is hidden
--v:SetFrameStrata(frame.strata or "MEDIUM")
if v.anchor:GetParent() then
v:SetFrameLevel(v.anchor:GetParent():GetFrameLevel())
end
v:Show()
v:SetCooldown( GetTime(), 30 )
v:SetAlpha(frame.alpha) -- hack to apply the alpha to the cooldown timer
end
end
else
_G[O.."UnlockText"]:SetText(LOSECONTROL["Unlock"])
for k, v in pairs(LC) do
local frame = LoseControlDB.frames[k]
v:RegisterEvent("UNIT_AURA")
if k == "focus" then
v:RegisterEvent("PLAYER_FOCUS_CHANGED")
elseif k == "target" then
v:RegisterEvent("PLAYER_TARGET_CHANGED")
end
v:SetMovable(false)
v:RegisterForDrag()
v:EnableMouse(false)
v:SetParent(v.anchor:GetParent()) -- or UIParent)
--v:SetFrameStrata(frame.strata or "LOW")
v:Hide()
end
end
end
Unlock:SetScript("OnClick", Unlock.OnClick)
local DisableCooldownCount = CreateFrame("CheckButton", O.."DisableCooldownCount", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."DisableCooldownCountText"]:SetText(LOSECONTROL["Disable OmniCC/CooldownCount Support"])
DisableCooldownCount:SetScript("OnClick", function(self)
LoseControlDB.noCooldownCount = self:GetChecked()
LoseControl.noCooldownCount = LoseControlDB.noCooldownCount
end)
local Tracking = OptionsPanel:CreateFontString(nil, "ARTWORK", "GameFontNormal")
Tracking:SetText(LOSECONTROL["Tracking"])
local TrackCCs = CreateFrame("CheckButton", O.."TrackCCs", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."TrackCCsText"]:SetText(CC)
TrackCCs:SetScript("OnClick", function(self)
LoseControlDB.tracking[CC] = self:GetChecked()
end)
local TrackSilences = CreateFrame("CheckButton", O.."TrackSilences", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."TrackSilencesText"]:SetText(Silence)
TrackSilences:SetScript("OnClick", function(self)
LoseControlDB.tracking[Silence] = self:GetChecked()
end)
local TrackDisarms = CreateFrame("CheckButton", O.."TrackDisarms", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."TrackDisarmsText"]:SetText(Disarm)
TrackDisarms:SetScript("OnClick", function(self)
LoseControlDB.tracking[Disarm] = self:GetChecked()
end)
local TrackRoots = CreateFrame("CheckButton", O.."TrackRoots", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."TrackRootsText"]:SetText(Root)
TrackRoots:SetScript("OnClick", function(self)
LoseControlDB.tracking[Root] = self:GetChecked()
end)
local TrackSnares = CreateFrame("CheckButton", O.."TrackSnares", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."TrackSnaresText"]:SetText(Snare)
TrackSnares:SetScript("OnClick", function(self)
LoseControlDB.tracking[Snare] = self:GetChecked()
end)
local TrackImmune = CreateFrame("CheckButton", O.."TrackImmune", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."TrackImmuneText"]:SetText(Immune)
TrackImmune:SetScript("OnClick", function(self)
LoseControlDB.tracking[Immune] = self:GetChecked()
end)
local TrackPvE = CreateFrame("CheckButton", O.."TrackPvE", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."TrackPvEText"]:SetText(PvE)
TrackPvE:SetScript("OnClick", function(self)
LoseControlDB.tracking[PvE] = self:GetChecked()
end)
-------------------------------------------------------------------------------
-- DropDownMenu helper function
local info = UIDropDownMenu_CreateInfo()
local function AddItem(owner, text, value)
info.owner = owner
info.func = owner.OnClick
info.text = text
info.value = value
info.checked = nil -- initially set the menu item to being unchecked
UIDropDownMenu_AddButton(info)
return info
end
local UnitDropDownLabel = OptionsPanel:CreateFontString(O.."UnitDropDownLabel", "ARTWORK", "GameFontNormal")
UnitDropDownLabel:SetText(LOSECONTROL["Unit Configuration"])
UnitDropDown = CreateFrame("Frame", O.."UnitDropDown", OptionsPanel, "UIDropDownMenuTemplate")
function UnitDropDown:OnClick()
UIDropDownMenu_SetSelectedValue(UnitDropDown, self.value)
OptionsPanel.refresh() -- easy way to update all the other controls
end
UIDropDownMenu_Initialize(UnitDropDown, function() -- sets the initialize function and calls it
for _, v in ipairs({ "player", "pet", "target", "focus", "party1", "party2", "party3", "party4", "arena1", "arena2", "arena3", "arena4", "arena5" }) do -- indexed manually so they appear in order
AddItem(UnitDropDown, LOSECONTROL[v], v)
end
end)
UIDropDownMenu_SetSelectedValue(UnitDropDown, "player") -- set the initial drop down choice
local AnchorDropDownLabel = OptionsPanel:CreateFontString(O.."AnchorDropDownLabel", "ARTWORK", "GameFontNormal")
AnchorDropDownLabel:SetText(LOSECONTROL["Anchor"])
AnchorDropDown = CreateFrame("Frame", O.."AnchorDropDown", OptionsPanel, "UIDropDownMenuTemplate")
function AnchorDropDown:OnClick()
local unit = UIDropDownMenu_GetSelectedValue(UnitDropDown)
local frame = LoseControlDB.frames[unit]
local icon = LC[unit]
UIDropDownMenu_SetSelectedValue(AnchorDropDown, self.value)
frame.anchor = self.value
if self.value ~= "None" then -- reset the frame position so it centers on the anchor frame
frame.point = nil
frame.relativePoint = nil
frame.x = nil
frame.y = nil
end
icon.anchor = _G[anchors[frame.anchor][unit]] or UIParent
if not Unlock:GetChecked() then -- prevents the icon from disappearing if the frame is currently hidden
icon:SetParent(icon.anchor:GetParent())
end
icon:ClearAllPoints() -- if we don't do this then the frame won't always move
icon:SetPoint(
frame.point or "CENTER",
icon.anchor,
frame.relativePoint or "CENTER",
frame.x or 0,
frame.y or 0
)
end
function AnchorDropDown:initialize() -- called from OptionsPanel.refresh() and every time the drop down menu is opened
local unit = UIDropDownMenu_GetSelectedValue(UnitDropDown)
AddItem(self, LOSECONTROL["None"], "None")
AddItem(self, "Blizzard", "Blizzard")
if _G[anchors["Perl"][unit]] then AddItem(self, "Perl", "Perl") end
if _G[anchors["XPerl"][unit]] then AddItem(self, "XPerl", "XPerl") end
end
local StrataDropDownLabel = OptionsPanel:CreateFontString(O.."StrataDropDownLabel", "ARTWORK", "GameFontNormal")
StrataDropDownLabel:SetText(LOSECONTROL["Strata"])
local StrataDropDown = CreateFrame("Frame", O.."StrataDropDown", OptionsPanel, "UIDropDownMenuTemplate")
function StrataDropDown:OnClick()
local unit = UIDropDownMenu_GetSelectedValue(UnitDropDown)
UIDropDownMenu_SetSelectedValue(StrataDropDown, self.value)
LoseControlDB.frames[unit].strata = self.value
LC[unit]:SetFrameStrata(self.value)
end
function StrataDropDown:initialize() -- called from OptionsPanel.refresh() and every time the drop down menu is opened
for _, v in ipairs({ "HIGH", "MEDIUM", "LOW", "BACKGROUND" }) do -- indexed manually so they appear in order
AddItem(self, v, v)
end
end
-------------------------------------------------------------------------------
-- Slider helper function, thanks to Kollektiv
local function CreateSlider(text, parent, low, high, step)
local name = parent:GetName() .. text
local slider = CreateFrame("Slider", name, parent, "OptionsSliderTemplate")
slider:SetWidth(160)
slider:SetMinMaxValues(low, high)
slider:SetValueStep(step)
--_G[name .. "Text"]:SetText(text)
_G[name .. "Low"]:SetText(low)
_G[name .. "High"]:SetText(high)
return slider
end
local SizeSlider = CreateSlider(LOSECONTROL["Icon Size"], OptionsPanel, 16, 512, 4)
SizeSlider:SetScript("OnValueChanged", function(self, value)
local unit = UIDropDownMenu_GetSelectedValue(UnitDropDown)
_G[self:GetName() .. "Text"]:SetText(LOSECONTROL["Icon Size"] .. " (" .. value .. "px)")
LoseControlDB.frames[unit].size = value
LC[unit]:SetWidth(value)
LC[unit]:SetHeight(value)
end)
local AlphaSlider = CreateSlider(LOSECONTROL["Opacity"], OptionsPanel, 0, 100, 5) -- I was going to use a range of 0 to 1 but Blizzard's slider chokes on decimal values
AlphaSlider:SetScript("OnValueChanged", function(self, value)
local unit = UIDropDownMenu_GetSelectedValue(UnitDropDown)
_G[self:GetName() .. "Text"]:SetText(LOSECONTROL["Opacity"] .. " (" .. value .. "%)")
LoseControlDB.frames[unit].alpha = value / 100 -- the real alpha value
LC[unit]:SetAlpha(value / 100)
end)
-------------------------------------------------------------------------------
-- Defined last because it references earlier declared variables
local Enabled = CreateFrame("CheckButton", O.."Enabled", OptionsPanel, "OptionsCheckButtonTemplate")
_G[O.."EnabledText"]:SetText(LOSECONTROL["Enabled"])
function Enabled:OnClick()
local enabled = self:GetChecked()
LoseControlDB.frames[UIDropDownMenu_GetSelectedValue(UnitDropDown)].enabled = enabled
if enabled then
UIDropDownMenu_EnableDropDown(AnchorDropDown)
UIDropDownMenu_EnableDropDown(StrataDropDown)
BlizzardOptionsPanel_Slider_Enable(SizeSlider)
BlizzardOptionsPanel_Slider_Enable(AlphaSlider)
else
UIDropDownMenu_DisableDropDown(AnchorDropDown)
UIDropDownMenu_DisableDropDown(StrataDropDown)
BlizzardOptionsPanel_Slider_Disable(SizeSlider)
BlizzardOptionsPanel_Slider_Disable(AlphaSlider)
end
end
Enabled:SetScript("OnClick", Enabled.OnClick)
-------------------------------------------------------------------------------
-- Arrange all the options neatly
title:SetPoint("TOPLEFT", 16, -16)
subText:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
Unlock:SetPoint("TOPLEFT", subText, "BOTTOMLEFT", 0, -16)
DisableCooldownCount:SetPoint("TOPLEFT", Unlock, "BOTTOMLEFT", 0, -2)
Tracking:SetPoint("TOPLEFT", DisableCooldownCount, "BOTTOMLEFT", 0, -12)
TrackCCs:SetPoint("TOPLEFT", Tracking, "BOTTOMLEFT", 0, -4)
TrackSilences:SetPoint("TOPLEFT", TrackCCs, "TOPRIGHT", 100, 0)
TrackDisarms:SetPoint("TOPLEFT", TrackSilences, "TOPRIGHT", 100, 0)
TrackRoots:SetPoint("TOPLEFT", TrackCCs, "BOTTOMLEFT", 0, -2)
TrackSnares:SetPoint("TOPLEFT", TrackSilences, "BOTTOMLEFT", 0, -2)
TrackImmune:SetPoint("TOPLEFT", TrackDisarms, "BOTTOMLEFT", 0, -2)
TrackPvE:SetPoint("TOPLEFT", TrackRoots, "BOTTOMLEFT", 0, -2)
UnitDropDownLabel:SetPoint("TOPLEFT", TrackPvE, "BOTTOMLEFT", 0, -12)
UnitDropDown:SetPoint("TOPLEFT", UnitDropDownLabel, "BOTTOMLEFT", 0, -8)
Enabled:SetPoint("TOPLEFT", UnitDropDown, "BOTTOMLEFT") --, 200, -8)
AnchorDropDownLabel:SetPoint("TOPLEFT", Enabled, "BOTTOMLEFT", 0, 0) --StrataDropDownLabel:SetPoint("TOPLEFT", UnitDropDown, "BOTTOMLEFT", 200, -12)
AnchorDropDown:SetPoint("TOPLEFT", AnchorDropDownLabel, "BOTTOMLEFT", 0, -8) --StrataDropDown:SetPoint("TOPLEFT", StrataDropDownLabel, "BOTTOMLEFT", 0, -8)
SizeSlider:SetPoint("TOPLEFT", AnchorDropDown, "BOTTOMLEFT", 0, -24) AlphaSlider:SetPoint("TOPLEFT", AnchorDropDown, "BOTTOMLEFT", 200, -24)
local PriorityLabel = OptionsPanel:CreateFontString(O.."PriorityLabel", "ARTWORK", "GameFontNormal")
PriorityLabel:SetText("Priorities")
PriorityLabel:SetPoint("TOPLEFT", UnitDropDownLabel, "TOPRIGHT", 110, 30)
local sortLabels = {}
local upButtons = {}
local function RedrawPriorities()
for i = 1, #LoseControlDB.priorities do
sortLabels[i]:SetText(LoseControlDB.priorities[i])
end
end
for i = 1, #ALL_CATS do
local upButton = CreateFrame("Button", O.."PriorityLabelFor"..i.."Button", OptionsPanel, "OptionsButtonTemplate")
upButton:SetText("^")
upButton:SetWidth(20)
tinsert(upButtons, upButton)
upButton:SetScript("OnClick", function (self)
local prios = LoseControlDB.priorities
if i < 1 then return end
if i > #prios then return end
local prev = prios[i - 1]
prios[i - 1] = prios[i]
prios[i] = prev
RedrawPriorities()
end)
upButton.i = i
local catLabel = OptionsPanel:CreateFontString(O.."PriorityLabelFor"..i, "ARTWORK", "GameFontNormal")
catLabel:SetText(ALL_CATS[i])
tinsert(sortLabels, catLabel)
if i == 1 then
upButton:SetPoint("TOPLEFT", PriorityLabel, "BOTTOMLEFT", -25, -5)
upButton:Disable()
else
upButton:SetPoint("TOPLEFT", upButtons[i - 1], "BOTTOMLEFT", 0, 0)
end
catLabel:SetPoint("TOPLEFT", upButton, "TOPRIGHT", 5, -5)
end
-------------------------------------------------------------------------------
OptionsPanel.default = function() -- This method will run when the player clicks "defaults".
_G.LoseControlDB = nil
LoseControl:ADDON_LOADED(L)
for _, v in pairs(LC) do
v:PLAYER_ENTERING_WORLD()
end
end
OptionsPanel.refresh = function() -- This method will run when the Interface Options frame calls its OnShow function and after defaults have been applied via the panel.default method described above, and after the Unit Configuration dropdown is changed.
local tracking = LoseControlDB.tracking
local unit = UIDropDownMenu_GetSelectedValue(UnitDropDown)
local frame = LoseControlDB.frames[unit]
DisableCooldownCount:SetChecked(LoseControlDB.noCooldownCount)
TrackCCs:SetChecked(tracking[CC])
TrackSilences:SetChecked(tracking[Silence])
TrackDisarms:SetChecked(tracking[Disarm])
TrackRoots:SetChecked(tracking[Root])
TrackSnares:SetChecked(tracking[Snare])
TrackImmune:SetChecked(tracking[Immune])
TrackPvE:SetChecked(tracking[PvE])
Enabled:SetChecked(frame.enabled)
Enabled:OnClick()
AnchorDropDown:initialize()
UIDropDownMenu_SetSelectedValue(AnchorDropDown, frame.anchor)
StrataDropDown:initialize()
UIDropDownMenu_SetSelectedValue(StrataDropDown, frame.strata or "LOW")
SizeSlider:SetValue(frame.size)
AlphaSlider:SetValue(frame.alpha * 100)
RedrawPriorities() -- now that we have the actual priorities
end
InterfaceOptions_AddCategory(OptionsPanel)
-------------------------------------------------------------------------------
SLASH_LoseControl1 = "/lc"
SLASH_LoseControl2 = "/losecontrol"
SlashCmdList[L] = function(cmd)
cmd = cmd:lower()
if cmd == "reset" then
OptionsPanel.default()
OptionsPanel.refresh()
elseif cmd == "lock" then
Unlock:SetChecked(false)
Unlock:OnClick()
-- log(L .. " locked.")
elseif cmd == "unlock" then
Unlock:SetChecked(true)
Unlock:OnClick()
-- log(L .. " unlocked.")
elseif cmd:sub(1, 6) == "enable" then
local unit = cmd:sub(8, 14)
if LoseControlDB.frames[unit] then