-
Notifications
You must be signed in to change notification settings - Fork 2
/
TargetFrame.lua
1253 lines (1143 loc) · 39.9 KB
/
TargetFrame.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
MAX_COMBO_POINTS = 5;
MAX_TARGET_DEBUFFS = 16;
MAX_TARGET_BUFFS = 32;
MAX_BOSS_FRAMES = 5;
-- aura positioning constants
local AURA_START_X = 5;
local AURA_START_Y = 32;
local AURA_OFFSET_Y = 3;
local LARGE_AURA_SIZE = 21;
local SMALL_AURA_SIZE = 17;
local AURA_ROW_WIDTH = 122;
local TOT_AURA_ROW_WIDTH = 101;
local NUM_TOT_AURA_ROWS = 2; -- TODO: replace with TOT_AURA_ROW_HEIGHT functionality if this becomes a problem
-- focus frame scales
local LARGE_FOCUS_SCALE = 1;
local SMALL_FOCUS_SCALE = 0.75;
local SMALL_FOCUS_UPSCALE = 1.333;
local PLAYER_UNITS = {
player = true,
vehicle = true,
pet = true,
};
function TargetFrame_OnLoad(self, unit, menuFunc)
self.statusCounter = 0;
self.statusSign = -1;
self.unitHPPercent = 1;
local thisName = self:GetName();
self.borderTexture = _G[thisName.."TextureFrameTexture"];
self.highLevelTexture = _G[thisName.."TextureFrameHighLevelTexture"];
self.pvpIcon = _G[thisName.."TextureFramePVPIcon"];
self.leaderIcon = _G[thisName.."TextureFrameLeaderIcon"];
self.raidTargetIcon = _G[thisName.."TextureFrameRaidTargetIcon"];
self.questIcon = _G[thisName.."TextureFrameQuestIcon"];
self.levelText = _G[thisName.."TextureFrameLevelText"];
self.deadText = _G[thisName.."TextureFrameDeadText"];
self.unconsciousText = _G[thisName.."TextureFrameUnconsciousText"];
self.petBattleIcon = _G[thisName.."TextureFramePetBattleIcon"];
self.TOT_AURA_ROW_WIDTH = TOT_AURA_ROW_WIDTH;
-- set simple frame
if ( not self.showLevel ) then
self.highLevelTexture:Hide();
self.levelText:Hide();
end
-- set threat frame
local threatFrame;
if ( self.showThreat ) then
threatFrame = _G[thisName.."Flash"];
end
-- set portrait frame
local portraitFrame;
if ( self.showPortrait ) then
portraitFrame = _G[thisName.."Portrait"];
end
UnitFrame_Initialize(self, unit, _G[thisName.."TextureFrameName"], portraitFrame,
_G[thisName.."HealthBar"], _G[thisName.."TextureFrameHealthBarText"],
_G[thisName.."ManaBar"], _G[thisName.."TextureFrameManaBarText"],
threatFrame, "player", _G[thisName.."NumericalThreat"],
_G[thisName.."MyHealPredictionBar"], _G[thisName.."OtherHealPredictionBar"],
_G[thisName.."TotalAbsorbBar"], _G[thisName.."TotalAbsorbBarOverlay"], _G[thisName.."TextureFrameOverAbsorbGlow"],
_G[thisName.."TextureFrameOverHealAbsorbGlow"], _G[thisName.."HealAbsorbBar"],
_G[thisName.."HealAbsorbBarLeftShadow"], _G[thisName.."HealAbsorbBarRightShadow"]);
TargetFrame_Update(self);
self:RegisterEvent("PLAYER_ENTERING_WORLD");
self:RegisterEvent("UNIT_HEALTH");
self:RegisterEvent("CVAR_UPDATE");
if ( self.showLevel ) then
self:RegisterEvent("UNIT_LEVEL");
end
self:RegisterEvent("UNIT_FACTION");
if ( self.showClassification ) then
self:RegisterEvent("UNIT_CLASSIFICATION_CHANGED");
end
if ( self.showLeader ) then
self:RegisterEvent("PLAYER_FLAGS_CHANGED");
end
self:RegisterEvent("GROUP_ROSTER_UPDATE");
self:RegisterEvent("RAID_TARGET_UPDATE");
self:RegisterUnitEvent("UNIT_AURA", unit);
local frameLevel = _G[thisName.."TextureFrame"]:GetFrameLevel();
local showmenu;
if ( menuFunc ) then
UIDropDownMenu_Initialize(_G[thisName.."DropDown"], menuFunc, "MENU");
showmenu = function()
ToggleDropDownMenu(1, nil, _G[thisName.."DropDown"], thisName, 120, 10);
end
end
SecureUnitButton_OnLoad(self, self.unit, showmenu);
end
function TargetFrame_Update (self)
-- This check is here so the frame will hide when the target goes away
-- even if some of the functions below are hooked by addons.
if ( not UnitExists(self.unit) ) then
self:Hide();
else
self:Show();
-- Moved here to avoid taint from functions below
if ( self.totFrame ) then
TargetofTarget_Update(self.totFrame);
end
UnitFrame_Update(self);
if ( self.showLevel ) then
TargetFrame_CheckLevel(self);
end
TargetFrame_CheckFaction(self);
if ( self.showClassification ) then
TargetFrame_CheckClassification(self);
end
TargetFrame_CheckDead(self);
if ( self.showLeader ) then
if ( UnitLeadsAnyGroup(self.unit) ) then
if ( HasLFGRestrictions() ) then
self.leaderIcon:SetTexture("Interface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES");
self.leaderIcon:SetTexCoord(0, 0.296875, 0.015625, 0.3125);
else
self.leaderIcon:SetTexture("Interface\\GroupFrame\\UI-Group-LeaderIcon");
self.leaderIcon:SetTexCoord(0, 1, 0, 1);
end
self.leaderIcon:Show();
else
self.leaderIcon:Hide();
end
end
TargetFrame_UpdateAuras(self);
if ( self.portrait ) then
self.portrait:SetAlpha(1.0);
end
TargetFrame_CheckBattlePet(self);
if ( self.petBattleIcon ) then
self.petBattleIcon:SetAlpha(1.0);
end
end
end
function TargetFrame_OnEvent (self, event, ...)
UnitFrame_OnEvent(self, event, ...);
local arg1 = ...;
if ( event == "PLAYER_ENTERING_WORLD" ) then
TargetFrame_Update(self);
elseif ( event == "PLAYER_TARGET_CHANGED" ) then
-- Moved here to avoid taint from functions below
TargetFrame_Update(self);
TargetFrame_UpdateRaidTargetIcon(self);
CloseDropDownMenus();
if ( UnitExists(self.unit) ) then
if ( UnitIsEnemy(self.unit, "player") ) then
PlaySound("igCreatureAggroSelect");
elseif ( UnitIsFriend("player", self.unit) ) then
PlaySound("igCharacterNPCSelect");
else
PlaySound("igCreatureNeutralSelect");
end
end
elseif ( event == "INSTANCE_ENCOUNTER_ENGAGE_UNIT" ) then
for i = 1, MAX_BOSS_FRAMES do
TargetFrame_Update(_G["Boss"..i.."TargetFrame"]);
TargetFrame_UpdateRaidTargetIcon(_G["Boss"..i.."TargetFrame"]);
end
CloseDropDownMenus();
UIParent_ManageFramePositions();
elseif ( event == "UNIT_TARGETABLE_CHANGED" and arg1 == self.unit) then
TargetFrame_Update(self);
TargetFrame_UpdateRaidTargetIcon(self);
CloseDropDownMenus();
UIParent_ManageFramePositions();
elseif ( event == "UNIT_HEALTH" ) then
if ( arg1 == self.unit ) then
TargetFrame_CheckDead(self);
end
elseif ( event == "UNIT_LEVEL" ) then
if ( arg1 == self.unit ) then
TargetFrame_CheckLevel(self);
end
elseif ( event == "UNIT_FACTION" ) then
if ( arg1 == self.unit or arg1 == "player" ) then
TargetFrame_CheckFaction(self);
if ( self.showLevel ) then
TargetFrame_CheckLevel(self);
end
end
elseif ( event == "UNIT_CLASSIFICATION_CHANGED" ) then
if ( arg1 == self.unit ) then
TargetFrame_CheckClassification(self);
end
elseif ( event == "UNIT_AURA" ) then
if ( arg1 == self.unit ) then
TargetFrame_UpdateAuras(self);
end
elseif ( event == "PLAYER_FLAGS_CHANGED" ) then
if ( arg1 == self.unit ) then
if ( UnitLeadsAnyGroup(self.unit) ) then
self.leaderIcon:Show();
else
self.leaderIcon:Hide();
end
end
elseif ( event == "GROUP_ROSTER_UPDATE" ) then
if (self.unit == "focus") then
TargetFrame_Update(self);
-- If this is the focus frame, clear focus if the unit no longer exists
if (not UnitExists(self.unit)) then
ClearFocus();
end
else
if ( self.totFrame ) then
TargetofTarget_Update(self.totFrame);
end
TargetFrame_CheckFaction(self);
end
elseif ( event == "RAID_TARGET_UPDATE" ) then
TargetFrame_UpdateRaidTargetIcon(self);
elseif ( event == "PLAYER_FOCUS_CHANGED" ) then
if ( UnitExists(self.unit) ) then
self:Show();
TargetFrame_Update(self);
TargetFrame_UpdateRaidTargetIcon(self);
else
self:Hide();
end
CloseDropDownMenus();
elseif ( event == "CVAR_UPDATE" ) then
if ( arg1 == "SHOW_ALL_ENEMY_DEBUFFS_TEXT" ) then
-- have to set uvar manually or it will be the previous value
SHOW_ALL_ENEMY_DEBUFFS = GetCVar("showAllEnemyDebuffs");
if ( self:IsShown() ) then
TargetFrame_UpdateAuras(self);
end
end
end
end
function TargetFrame_OnVariablesLoaded()
TargetFrame_SetLocked(not TARGET_FRAME_UNLOCKED);
TargetFrame_UpdateBuffsOnTop();
FocusFrame_SetSmallSize(not GetCVarBool("fullSizeFocusFrame"));
FocusFrame_UpdateBuffsOnTop();
end
function TargetFrame_OnHide (self)
PlaySound("INTERFACESOUND_LOSTTARGETUNIT");
CloseDropDownMenus();
end
function TargetFrame_CheckLevel (self)
local targetLevel = UnitLevel(self.unit);
if ( UnitIsCorpse(self.unit) ) then
self.levelText:Hide();
self.highLevelTexture:Show();
elseif ( UnitIsWildBattlePet(self.unit) or UnitIsBattlePetCompanion(self.unit) ) then
local petLevel = UnitBattlePetLevel(self.unit);
self.levelText:SetVertexColor(1.0, 0.82, 0.0);
self.levelText:SetText( petLevel );
self.levelText:Show();
self.highLevelTexture:Hide();
elseif ( targetLevel > 0 ) then
-- Normal level target
self.levelText:SetText(targetLevel);
-- Color level number
if ( UnitCanAttack("player", self.unit) ) then
local color = GetQuestDifficultyColor(targetLevel);
self.levelText:SetVertexColor(color.r, color.g, color.b);
else
self.levelText:SetVertexColor(1.0, 0.82, 0.0);
end
self.levelText:Show();
self.highLevelTexture:Hide();
else
-- Target is too high level to tell
self.levelText:Hide();
self.highLevelTexture:Show();
end
end
function TargetFrame_CheckFaction (self)
if ( not UnitPlayerControlled(self.unit) and UnitIsTapped(self.unit) and not UnitIsTappedByPlayer(self.unit) and not UnitIsTappedByAllThreatList(self.unit) ) then
self.nameBackground:SetVertexColor(0.5, 0.5, 0.5);
if ( self.portrait ) then
self.portrait:SetVertexColor(0.5, 0.5, 0.5);
end
else
self.nameBackground:SetVertexColor(UnitSelectionColor(self.unit));
if ( self.portrait ) then
self.portrait:SetVertexColor(1.0, 1.0, 1.0);
end
end
if ( self.showPVP ) then
local factionGroup = UnitFactionGroup(self.unit);
if ( UnitIsPVPFreeForAll(self.unit) ) then
self.pvpIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-FFA");
self.pvpIcon:Show();
elseif ( factionGroup and factionGroup ~= "Neutral" and UnitIsPVP(self.unit) ) then
self.pvpIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-"..factionGroup);
self.pvpIcon:Show();
else
self.pvpIcon:Hide();
end
end
end
function TargetFrame_CheckBattlePet(self)
if ( UnitIsWildBattlePet(self.unit) or UnitIsBattlePetCompanion(self.unit) ) then
local petType = UnitBattlePetType(self.unit);
self.petBattleIcon:SetTexture("Interface\\TargetingFrame\\PetBadge-"..PET_TYPE_SUFFIX[petType]);
self.petBattleIcon:Show();
else
self.petBattleIcon:Hide();
end
end
function TargetFrame_CheckClassification (self, forceNormalTexture)
local classification = UnitClassification(self.unit);
self.nameBackground:Show();
self.manabar:Show();
self.manabar.TextString:Show();
self.threatIndicator:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Flash");
if ( forceNormalTexture ) then
self.borderTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame");
elseif ( classification == "minus" ) then
self.borderTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Minus");
self.nameBackground:Hide();
self.manabar:Hide();
self.manabar.TextString:Hide();
forceNormalTexture = true;
elseif ( classification == "worldboss" or classification == "elite" ) then
self.borderTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Elite");
elseif ( classification == "rareelite" ) then
self.borderTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Rare-Elite");
elseif ( classification == "rare" ) then
self.borderTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Rare");
else
self.borderTexture:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame");
forceNormalTexture = true;
end
if ( forceNormalTexture ) then
self.haveElite = nil;
if ( classification == "minus" ) then
self.Background:SetSize(119,12);
self.Background:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", 7, 47);
else
self.Background:SetSize(119,25);
self.Background:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", 7, 35);
end
if ( self.threatIndicator ) then
if ( classification == "minus" ) then
self.threatIndicator:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-Minus-Flash");
self.threatIndicator:SetTexCoord(0, 1, 0, 1);
self.threatIndicator:SetWidth(256);
self.threatIndicator:SetHeight(128);
self.threatIndicator:SetPoint("TOPLEFT", self, "TOPLEFT", -24, 0);
else
self.threatIndicator:SetTexCoord(0, 0.9453125, 0, 0.181640625);
self.threatIndicator:SetWidth(242);
self.threatIndicator:SetHeight(93);
self.threatIndicator:SetPoint("TOPLEFT", self, "TOPLEFT", -24, 0);
end
end
else
self.haveElite = true;
TargetFrameBackground:SetSize(119,41);
self.Background:SetSize(119,25);
self.Background:SetPoint("BOTTOMLEFT", self, "BOTTOMLEFT", 7, 35);
if ( self.threatIndicator ) then
self.threatIndicator:SetTexCoord(0, 0.9453125, 0.181640625, 0.400390625);
self.threatIndicator:SetWidth(242);
self.threatIndicator:SetHeight(112);
self.threatIndicator:SetPoint("TOPLEFT", self, "TOPLEFT", -22, 9);
end
end
if (self.questIcon) then
if (UnitIsQuestBoss(self.unit)) then
self.questIcon:Show();
else
self.questIcon:Hide();
end
end
end
function TargetFrame_CheckDead (self)
if ( (UnitHealth(self.unit) <= 0) and UnitIsConnected(self.unit) ) then
if ( UnitIsUnconscious(self.unit) ) then
self.unconsciousText:Show();
self.deadText:Hide();
else
self.unconsciousText:Hide();
self.deadText:Show();
end
else
self.deadText:Hide();
self.unconsciousText:Hide();
end
end
function TargetFrame_OnUpdate (self, elapsed)
if ( self.totFrame and self.totFrame:IsShown() ~= UnitExists(self.totFrame.unit) ) then
TargetofTarget_Update(self.totFrame);
end
self.elapsed = (self.elapsed or 0) + elapsed;
if ( self.elapsed > 0.5 ) then
self.elapsed = 0;
UnitFrame_UpdateThreatIndicator(self.threatIndicator, self.threatNumericIndicator, self.feedbackUnit);
end
end
local largeBuffList = {};
local largeDebuffList = {};
function TargetFrame_UpdateAuras (self)
local frame, frameName;
local frameIcon, frameCount, frameCooldown;
local name, rank, icon, count, debuffType, duration, expirationTime, caster, canStealOrPurge, spellId, _;
local frameStealable;
local numBuffs = 0;
local playerIsTarget = UnitIsUnit(PlayerFrame.unit, self.unit);
local selfName = self:GetName();
local canAssist = UnitCanAssist("player", self.unit);
local filter;
if ( SHOW_CASTABLE_BUFFS == "1" and canAssist ) then
filter = "RAID";
end
for i = 1, MAX_TARGET_BUFFS do
name, rank, icon, count, debuffType, duration, expirationTime, caster, canStealOrPurge, _ , spellId = UnitBuff(self.unit, i, filter);
frameName = selfName.."Buff"..(i);
frame = _G[frameName];
if ( not frame ) then
if ( not icon ) then
break;
else
frame = CreateFrame("Button", frameName, self, "TargetBuffFrameTemplate");
frame.unit = self.unit;
end
end
if ( icon and ( not self.maxBuffs or i <= self.maxBuffs ) ) then
frame:SetID(i);
-- set the icon
frameIcon = _G[frameName.."Icon"];
frameIcon:SetTexture(icon);
-- set the count
frameCount = _G[frameName.."Count"];
if ( count > 1 and self.showAuraCount ) then
frameCount:SetText(count);
frameCount:Show();
else
frameCount:Hide();
end
-- Handle cooldowns
frameCooldown = _G[frameName.."Cooldown"];
if ( duration > 0 ) then
frameCooldown:Show();
CooldownFrame_SetTimer(frameCooldown, expirationTime - duration, duration, 1);
else
frameCooldown:Hide();
end
-- Show stealable frame if the target is not the current player and the buff is stealable.
frameStealable = _G[frameName.."Stealable"];
if ( not playerIsTarget and canStealOrPurge ) then
frameStealable:Show();
else
frameStealable:Hide();
end
-- set the buff to be big if the buff is cast by the player or his pet
largeBuffList[i] = PLAYER_UNITS[caster];
numBuffs = numBuffs + 1;
frame:ClearAllPoints();
frame:Show();
else
frame:Hide();
end
end
local color;
local frameBorder;
local numDebuffs = 0;
local isEnemy = UnitCanAttack("player", self.unit);
if ( SHOW_DISPELLABLE_DEBUFFS == "1" and canAssist ) then
filter = "RAID";
else
filter = nil;
end
local frameNum = 1;
local index = 1;
while ( frameNum <= (self.maxDebuffs or MAX_TARGET_DEBUFFS) ) do
local debuffName = UnitDebuff(self.unit, index, filter);
if ( debuffName ) then
if ( TargetFrame_ShouldShowDebuff(self.unit, index, filter) ) then
name, rank, icon, count, debuffType, duration, expirationTime, caster = UnitDebuff(self.unit, index, filter);
frameName = selfName.."Debuff"..frameNum;
frame = _G[frameName];
if ( icon ) then
if ( not frame ) then
frame = CreateFrame("Button", frameName, self, "TargetDebuffFrameTemplate");
frame.unit = self.unit;
end
frame:SetID(index);
-- set the icon
frameIcon = _G[frameName.."Icon"];
frameIcon:SetTexture(icon);
-- set the count
frameCount = _G[frameName.."Count"];
if ( count > 1 and self.showAuraCount ) then
frameCount:SetText(count);
frameCount:Show();
else
frameCount:Hide();
end
-- Handle cooldowns
frameCooldown = _G[frameName.."Cooldown"];
if ( duration > 0 ) then
frameCooldown:Show();
CooldownFrame_SetTimer(frameCooldown, expirationTime - duration, duration, 1);
else
frameCooldown:Hide();
end
-- set debuff type color
if ( debuffType ) then
color = DebuffTypeColor[debuffType];
else
color = DebuffTypeColor["none"];
end
frameBorder = _G[frameName.."Border"];
frameBorder:SetVertexColor(color.r, color.g, color.b);
-- set the debuff to be big if the buff is cast by the player or his pet
largeDebuffList[index] = (PLAYER_UNITS[caster]);
numDebuffs = numDebuffs + 1;
frame:ClearAllPoints();
frame:Show();
frameNum = frameNum + 1;
end
end
index = index + 1;
else
break;
end
end
for i = frameNum, MAX_TARGET_DEBUFFS do
local frame = _G[selfName.."Debuff"..i];
if ( frame ) then
frame:Hide();
else
break;
end
end
self.auraRows = 0;
local mirrorAurasVertically = false;
if ( self.buffsOnTop ) then
mirrorAurasVertically = true;
end
local haveTargetofTarget;
if ( self.totFrame ) then
haveTargetofTarget = self.totFrame:IsShown();
end
self.spellbarAnchor = nil;
local maxRowWidth;
-- update buff positions
maxRowWidth = ( haveTargetofTarget and self.TOT_AURA_ROW_WIDTH ) or AURA_ROW_WIDTH;
TargetFrame_UpdateAuraPositions(self, selfName.."Buff", numBuffs, numDebuffs, largeBuffList, TargetFrame_UpdateBuffAnchor, maxRowWidth, 3, mirrorAurasVertically);
-- update debuff positions
maxRowWidth = ( haveTargetofTarget and self.auraRows < NUM_TOT_AURA_ROWS and self.TOT_AURA_ROW_WIDTH ) or AURA_ROW_WIDTH;
TargetFrame_UpdateAuraPositions(self, selfName.."Debuff", numDebuffs, numBuffs, largeDebuffList, TargetFrame_UpdateDebuffAnchor, maxRowWidth, 4, mirrorAurasVertically);
-- update the spell bar position
if ( self.spellbar ) then
Target_Spellbar_AdjustPosition(self.spellbar);
end
end
function TargetFrame_ShouldShowDebuff(unit, index, filter)
--This is an enemy
if ( SHOW_ALL_ENEMY_DEBUFFS == "1" or not UnitCanAttack("player", unit) ) then
return true;
else
local name, rank, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, shouldConsolidate, spellId, canApplyAura, isBossDebuff, isCastByPlayer = UnitDebuff(unit, index, filter);
local hasCustom, alwaysShowMine, showForMySpec = SpellGetVisibilityInfo(spellId, "ENEMY_TARGET");
if ( hasCustom ) then
return showForMySpec or (alwaysShowMine and (unitCaster == "player" or unitCaster == "pet" or unitCaster == "vehicle") );
else
return not isCastByPlayer or unitCaster == "player" or unitCaster == "pet" or unitCaster == "vehicle";
end
end
end
function TargetFrame_UpdateAuraPositions(self, auraName, numAuras, numOppositeAuras, largeAuraList, updateFunc, maxRowWidth, offsetX, mirrorAurasVertically)
-- a lot of this complexity is in place to allow the auras to wrap around the target of target frame if it's shown
-- Position auras
local size;
local offsetY = AURA_OFFSET_Y;
-- current width of a row, increases as auras are added and resets when a new aura's width exceeds the max row width
local rowWidth = 0;
local firstBuffOnRow = 1;
for i=1, numAuras do
-- update size and offset info based on large aura status
if ( largeAuraList[i] ) then
size = LARGE_AURA_SIZE;
offsetY = AURA_OFFSET_Y + AURA_OFFSET_Y;
else
size = SMALL_AURA_SIZE;
end
-- anchor the current aura
if ( i == 1 ) then
rowWidth = size;
self.auraRows = self.auraRows + 1;
else
rowWidth = rowWidth + size + offsetX;
end
if ( rowWidth > maxRowWidth ) then
-- this aura would cause the current row to exceed the max row width, so make this aura
-- the start of a new row instead
updateFunc(self, auraName, i, numOppositeAuras, firstBuffOnRow, size, offsetX, offsetY, mirrorAurasVertically);
rowWidth = size;
self.auraRows = self.auraRows + 1;
firstBuffOnRow = i;
offsetY = AURA_OFFSET_Y;
if ( self.auraRows > NUM_TOT_AURA_ROWS ) then
-- if we exceed the number of tot rows, then reset the max row width
-- note: don't have to check if we have tot because AURA_ROW_WIDTH is the default anyway
maxRowWidth = AURA_ROW_WIDTH;
end
else
updateFunc(self, auraName, i, numOppositeAuras, i - 1, size, offsetX, offsetY, mirrorAurasVertically);
end
end
end
function TargetFrame_UpdateBuffAnchor(self, buffName, index, numDebuffs, anchorIndex, size, offsetX, offsetY, mirrorVertically)
--For mirroring vertically
local point, relativePoint;
local startY, auraOffsetY;
if ( mirrorVertically ) then
point = "BOTTOM";
relativePoint = "TOP";
startY = -15;
if ( self.threatNumericIndicator:IsShown() ) then
startY = startY + self.threatNumericIndicator:GetHeight();
end
offsetY = - offsetY;
auraOffsetY = -AURA_OFFSET_Y;
else
point = "TOP";
relativePoint="BOTTOM";
startY = AURA_START_Y;
auraOffsetY = AURA_OFFSET_Y;
end
local buff = _G[buffName..index];
if ( index == 1 ) then
if ( UnitIsFriend("player", self.unit) or numDebuffs == 0 ) then
-- unit is friendly or there are no debuffs...buffs start on top
buff:SetPoint(point.."LEFT", self, relativePoint.."LEFT", AURA_START_X, startY);
else
-- unit is not friendly and we have debuffs...buffs start on bottom
buff:SetPoint(point.."LEFT", self.debuffs, relativePoint.."LEFT", 0, -offsetY);
end
self.buffs:SetPoint(point.."LEFT", buff, point.."LEFT", 0, 0);
self.buffs:SetPoint(relativePoint.."LEFT", buff, relativePoint.."LEFT", 0, -auraOffsetY);
self.spellbarAnchor = buff;
elseif ( anchorIndex ~= (index-1) ) then
-- anchor index is not the previous index...must be a new row
buff:SetPoint(point.."LEFT", _G[buffName..anchorIndex], relativePoint.."LEFT", 0, -offsetY);
self.buffs:SetPoint(relativePoint.."LEFT", buff, relativePoint.."LEFT", 0, -auraOffsetY);
self.spellbarAnchor = buff;
else
-- anchor index is the previous index
buff:SetPoint(point.."LEFT", _G[buffName..anchorIndex], point.."RIGHT", offsetX, 0);
end
-- Resize
buff:SetWidth(size);
buff:SetHeight(size);
end
function TargetFrame_UpdateDebuffAnchor(self, debuffName, index, numBuffs, anchorIndex, size, offsetX, offsetY, mirrorVertically)
local buff = _G[debuffName..index];
local isFriend = UnitIsFriend("player", self.unit);
--For mirroring vertically
local point, relativePoint;
local startY, auraOffsetY;
if ( mirrorVertically ) then
point = "BOTTOM";
relativePoint = "TOP";
startY = -15;
if ( self.threatNumericIndicator:IsShown() ) then
startY = startY + self.threatNumericIndicator:GetHeight();
end
offsetY = - offsetY;
auraOffsetY = -AURA_OFFSET_Y;
else
point = "TOP";
relativePoint="BOTTOM";
startY = AURA_START_Y;
auraOffsetY = AURA_OFFSET_Y;
end
if ( index == 1 ) then
if ( isFriend and numBuffs > 0 ) then
-- unit is friendly and there are buffs...debuffs start on bottom
buff:SetPoint(point.."LEFT", self.buffs, relativePoint.."LEFT", 0, -offsetY);
else
-- unit is not friendly or there are no buffs...debuffs start on top
buff:SetPoint(point.."LEFT", self, relativePoint.."LEFT", AURA_START_X, startY);
end
self.debuffs:SetPoint(point.."LEFT", buff, point.."LEFT", 0, 0);
self.debuffs:SetPoint(relativePoint.."LEFT", buff, relativePoint.."LEFT", 0, -auraOffsetY);
if ( ( isFriend ) or ( not isFriend and numBuffs == 0) ) then
self.spellbarAnchor = buff;
end
elseif ( anchorIndex ~= (index-1) ) then
-- anchor index is not the previous index...must be a new row
buff:SetPoint(point.."LEFT", _G[debuffName..anchorIndex], relativePoint.."LEFT", 0, -offsetY);
self.debuffs:SetPoint(relativePoint.."LEFT", buff, relativePoint.."LEFT", 0, -auraOffsetY);
if ( ( isFriend ) or ( not isFriend and numBuffs == 0) ) then
self.spellbarAnchor = buff;
end
else
-- anchor index is the previous index
buff:SetPoint(point.."LEFT", _G[debuffName..(index-1)], point.."RIGHT", offsetX, 0);
end
-- Resize
buff:SetWidth(size);
buff:SetHeight(size);
local debuffFrame =_G[debuffName..index.."Border"];
debuffFrame:SetWidth(size+2);
debuffFrame:SetHeight(size+2);
end
function TargetFrame_HealthUpdate (self, elapsed, unit)
if ( UnitIsPlayer(unit) ) then
if ( (self.unitHPPercent > 0) and (self.unitHPPercent <= 0.2) ) then
local alpha = 255;
local counter = self.statusCounter + elapsed;
local sign = self.statusSign;
if ( counter > 0.5 ) then
sign = -sign;
self.statusSign = sign;
end
counter = mod(counter, 0.5);
self.statusCounter = counter;
if ( sign == 1 ) then
alpha = (127 + (counter * 256)) / 255;
else
alpha = (255 - (counter * 256)) / 255;
end
if ( self.portrait ) then
self.portrait:SetAlpha(alpha);
end
end
end
end
function TargetHealthCheck (self)
if ( UnitIsPlayer(self.unit) ) then
local unitHPMin, unitHPMax, unitCurrHP;
local parent = self:GetParent();
unitHPMin, unitHPMax = self:GetMinMaxValues();
unitCurrHP = self:GetValue();
parent.unitHPPercent = unitCurrHP / unitHPMax;
if ( self.portrait ) then
if ( UnitIsDead(self.unit) ) then
parent.portrait:SetVertexColor(0.35, 0.35, 0.35, 1.0);
elseif ( UnitIsGhost(self.unit) ) then
parent.portrait:SetVertexColor(0.2, 0.2, 0.75, 1.0);
elseif ( (parent.unitHPPercent > 0) and (parent.unitHPPercent <= 0.2) ) then
parent.portrait:SetVertexColor(1.0, 0.0, 0.0);
else
parent.portrait:SetVertexColor(1.0, 1.0, 1.0, 1.0);
end
end
end
end
function TargetFrameDropDown_Initialize (self)
local menu;
local name;
local id = nil;
if ( UnitIsUnit("target", "player") ) then
menu = "SELF";
elseif ( UnitIsUnit("target", "vehicle") ) then
-- NOTE: vehicle check must come before pet check for accuracy's sake because
-- a vehicle may also be considered your pet
menu = "VEHICLE";
elseif ( UnitIsUnit("target", "pet") ) then
menu = "PET";
elseif ( UnitIsOtherPlayersBattlePet("target") ) then
menu = "OTHERBATTLEPET";
elseif ( UnitIsBattlePet("target") ) then
menu = "BATTLEPET";
elseif ( UnitIsOtherPlayersPet("target") ) then
menu = "OTHERPET";
elseif ( UnitIsPlayer("target") ) then
id = UnitInRaid("target");
if ( id ) then
menu = "RAID_PLAYER";
elseif ( UnitInParty("target") ) then
menu = "PARTY";
else
menu = "PLAYER";
end
else
menu = "TARGET";
name = RAID_TARGET_ICON;
end
if ( menu ) then
UnitPopup_ShowMenu(self, menu, "target", name, id);
end
end
-- Raid target icon function
RAID_TARGET_ICON_DIMENSION = 64;
RAID_TARGET_TEXTURE_DIMENSION = 256;
RAID_TARGET_TEXTURE_COLUMNS = 4;
RAID_TARGET_TEXTURE_ROWS = 4;
function TargetFrame_UpdateRaidTargetIcon (self)
local index = GetRaidTargetIndex(self.unit);
if ( index ) then
SetRaidTargetIconTexture(self.raidTargetIcon, index);
self.raidTargetIcon:Show();
else
self.raidTargetIcon:Hide();
end
end
function SetRaidTargetIconTexture (texture, raidTargetIconIndex)
raidTargetIconIndex = raidTargetIconIndex - 1;
local left, right, top, bottom;
local coordIncrement = RAID_TARGET_ICON_DIMENSION / RAID_TARGET_TEXTURE_DIMENSION;
left = mod(raidTargetIconIndex , RAID_TARGET_TEXTURE_COLUMNS) * coordIncrement;
right = left + coordIncrement;
top = floor(raidTargetIconIndex / RAID_TARGET_TEXTURE_ROWS) * coordIncrement;
bottom = top + coordIncrement;
texture:SetTexCoord(left, right, top, bottom);
end
function SetRaidTargetIcon (unit, index)
if ( GetRaidTargetIndex(unit) and GetRaidTargetIndex(unit) == index ) then
SetRaidTarget(unit, 0);
else
SetRaidTarget(unit, index);
end
end
function TargetFrame_CreateTargetofTarget(self, unit)
local thisName = self:GetName().."ToT";
local frame = CreateFrame("BUTTON", thisName, self, "TargetofTargetFrameTemplate");
self.totFrame = frame;
UnitFrame_Initialize(frame, unit, _G[thisName.."TextureFrameName"], _G[thisName.."Portrait"],
_G[thisName.."HealthBar"], _G[thisName.."TextureFrameHealthBarText"],
_G[thisName.."ManaBar"], _G[thisName.."TextureFrameManaBarText"]);
SetTextStatusBarTextZeroText(frame.healthbar, DEAD);
frame.deadText = _G[thisName.."TextureFrameDeadText"];
frame.unconsciousText = _G[thisName.."TextureFrameUnconsciousText"];
SecureUnitButton_OnLoad(frame, unit);
end
function TargetofTarget_OnHide(self)
TargetFrame_UpdateAuras(self:GetParent());
end
function TargetofTarget_Update(self, elapsed)
local show;
local parent = self:GetParent();
if ( SHOW_TARGET_OF_TARGET == "1" and UnitExists(parent.unit) and UnitExists(self.unit) and ( not UnitIsUnit(PlayerFrame.unit, parent.unit) ) and ( UnitHealth(parent.unit) > 0 ) ) then
if ( ( SHOW_TARGET_OF_TARGET_STATE == "5" ) or
( SHOW_TARGET_OF_TARGET_STATE == "4" and ( IsInGroup() ) ) or
( SHOW_TARGET_OF_TARGET_STATE == "3" and ( not IsInGroup() ) ) or
( SHOW_TARGET_OF_TARGET_STATE == "2" and ( IsInGroup() and not IsInRaid() ) ) or
( SHOW_TARGET_OF_TARGET_STATE == "1" and ( IsInRaid() ) ) ) then
show = true;
end
end
if ( show ) then
if ( not self:IsShown() ) then
self:Show();
if ( parent.spellbar ) then
parent.haveToT = true;
Target_Spellbar_AdjustPosition(parent.spellbar);
end
end
UnitFrame_Update(self);
TargetofTarget_CheckDead(self);
TargetofTargetHealthCheck(self);
RefreshDebuffs(self, self.unit, nil, nil, true);
else
if ( self:IsShown() ) then
self:Hide();
if ( parent.spellbar ) then
parent.haveToT = nil;
Target_Spellbar_AdjustPosition(parent.spellbar);
end
end
end
end
function TargetofTarget_CheckDead(self)
if ( (UnitHealth(self.unit) <= 0) and UnitIsConnected(self.unit) ) then
self.background:SetAlpha(0.9);
if ( UnitIsUnconscious(self.unit) ) then
self.unconsciousText:Show();
self.deadText:Hide();
else
self.unconsciousText:Hide();
self.deadText:Show();
end
else
self.background:SetAlpha(1);
self.deadText:Hide();
self.unconsciousText:Hide();
end
end
function TargetofTargetHealthCheck(self)
if ( UnitIsPlayer(self.unit) ) then
local unitHPMin, unitHPMax, unitCurrHP;
unitHPMin, unitHPMax = self.healthbar:GetMinMaxValues();
unitCurrHP = self.healthbar:GetValue();
self.unitHPPercent = unitCurrHP / unitHPMax;
if ( UnitIsDead(self.unit) ) then
self.portrait:SetVertexColor(0.35, 0.35, 0.35, 1.0);
elseif ( UnitIsGhost(self.unit) ) then
self.portrait:SetVertexColor(0.2, 0.2, 0.75, 1.0);
elseif ( (self.unitHPPercent > 0) and (self.unitHPPercent <= 0.2) ) then
self.portrait:SetVertexColor(1.0, 0.0, 0.0);
else
self.portrait:SetVertexColor(1.0, 1.0, 1.0, 1.0);
end
end
end
function TargetFrame_CreateSpellbar(self, event, boss)
local name = self:GetName().."SpellBar";
local spellbar;
if ( boss ) then
spellbar = CreateFrame("STATUSBAR", name, self, "BossSpellBarTemplate");
else
spellbar = CreateFrame("STATUSBAR", name, self, "TargetSpellBarTemplate");
end
spellbar.boss = boss;
spellbar:SetFrameLevel(_G[self:GetName().."TextureFrame"]:GetFrameLevel() - 1);
self.spellbar = spellbar;
self.auraRows = 0;
spellbar.unit = self.unit;
spellbar:RegisterEvent("CVAR_UPDATE");
spellbar:RegisterEvent("VARIABLES_LOADED");
CastingBarFrame_OnLoad(spellbar, spellbar.unit, false, true);
if ( event ) then
spellbar.updateEvent = event;
spellbar:RegisterEvent(event);
end