-
Notifications
You must be signed in to change notification settings - Fork 10
/
Core.lua
1181 lines (1044 loc) · 39 KB
/
Core.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
----------------------------------------------
-- Create the addon object
----------------------------------------------
ArcHUD = LibStub("AceAddon-3.0"):NewAddon("ArcHUD",
"AceConsole-3.0",
"AceEvent-3.0",
"AceHook-3.0",
"AceTimer-3.0")
-- Version
ArcHUD.version = "@project-version@ (@project-abbreviated-hash@)"
ArcHUD.codename = "Pandemic"
ArcHUD.authors = "nyyr, Nenie"
-- Classic specifics
ArcHUD.isClassicWoW = (WOW_PROJECT_ID == WOW_PROJECT_CLASSIC)
ArcHUD.isClassicTbc = (WOW_PROJECT_ID == WOW_PROJECT_BURNING_CRUSADE_CLASSIC)
ArcHUD.isClassicWrath = (WOW_PROJECT_ID == WOW_PROJECT_WRATH_CLASSIC)
ArcHUD.isClassicCata = (WOW_PROJECT_ID == WOW_PROJECT_CATACLYSM_CLASSIC)
-- generic classic only up to Wrath
ArcHUD.classic = ArcHUD.isClassicWoW or ArcHUD.isClassicTbc or ArcHUD.isClassicWrath
-- generic feature switches based on expansion
ArcHUD.hasHealPrediction = not ArcHUD.classic
ArcHUD.hasAbsorbs = not ArcHUD.classic and not ArcHUD.isClassicCata
ArcHUD.UnitCastingInfo = UnitCastingInfo
ArcHUD.UnitChannelInfo = UnitChannelInfo
if ArcHUD.isClassicWoW then
ArcHUD.LibClassicCasterino = LibStub("LibClassicCasterino", true)
ArcHUD.UnitCastingInfo = function(unit)
return ArcHUD.LibClassicCasterino:UnitCastingInfo(unit)
end
ArcHUD.UnitChannelInfo = function(unit)
return ArcHUD.LibClassicCasterino:UnitChannelInfo(unit)
end
end
-- Locale object
local L = LibStub("AceLocale-3.0"):GetLocale("ArcHUD_Core")
-- Debugging levels
-- 1 Warning
-- 2 Info
-- 3 Notice
-- 4 Off
local debugLevels = {"warn", "info", "notice", "off"}
local d_warn = 1
local d_info = 2
local d_notice = 3
-- Set up tables
ArcHUD.movableFrames = {}
ArcHUD.Nameplates = {}
ArcHUD.timers = {}
-- Set up default configuration
ArcHUD.defaults = {
profile = {
Debug = nil,
TargetFrame = true,
PlayerFrame = false,
PlayerModel = true,
MobModel = true,
ShowGuild = true,
ShowClass = false,
Width = 30,
YLoc = 0,
XLoc = 0,
FadeFull = 0.1,
FadeOOC = 0.5,
FadeIC = 0.75,
RingVisibility = 3,
PartyLock = true,
TargetTarget = true,
TargetTargetTarget = true,
Nameplate_player = true,
Nameplate_pet = true,
Nameplate_target = false,
Nameplate_targettarget = false,
Nameplate_targettargettarget = false,
HoverMsg = false,
HoverDelay = 1.5,
Scale = 1.0,
ScaleTargetFrame = 1.0,
AttachTop = false,
ShowBuffs = true,
ShowOnlyBuffsCastByPlayer = false,
ShowBuffTooltips = true,
HideBuffTooltipsIC = false,
BuffIconSize = 20,
ShowHealthPowerTextMax = true,
BlizzPlayer = true,
BlizzTarget = true,
BlizzFocus = true,
BlizzSpellActCenter = true,
BlizzSpellActScale = 0.8,
BlizzSpellActOpacity = 1.0,
ShowPVP = true,
-- deprecated: ShowComboPoints = true,
Positions = {},
ShowResting = true,
-- deprecated: ShowHolyPowerPoints = false,
-- deprecated: ShowSoulShardPoints = false,
-- deprecated: ShowChiPoints = false,
-- deprecated: ShowRunePoints = false,
-- deprecated: ShowSoulFragmentPoints = false,
-- deprecated: ColorComboPoints = {r = 1, g = 1, b = 0},
-- deprecated: ColorOldComboPoints = {r = 0.5, g = 0.5, b = 0.5},
-- deprecated: OldComboPointsDecay = 10.0,
CustomModules = {},
}
}
-- Setup class colors
ArcHUD.ClassColor = {
["MAGE"] = "69CCF0",
["WARLOCK"] = "9482C9",
["PRIEST"] = "FFFFFF",
["DRUID"] = "FF7D0A",
["SHAMAN"] = "0070DE",
["PALADIN"] = "F58CBA",
["ROGUE"] = "FFF569",
["HUNTER"] = "ABD473",
["WARRIOR"] = "C79C6E",
["DEATHKNIGHT"] = "C41F3B",
["MONK"] = "00FF96"
}
-- Reputation colors
ArcHUD.RepColor = { "FF4444", "DD4444", "DD7744", "BB9944", "44DD44", "55EE44", "66FF44"}
-- for backward compatibility (WoW 4.x-5.x)
if not UnitIsGroupLeader then
UnitIsGroupLeader = UnitIsPartyLeader
end
----------------------------------------------
-- Print debug message
----------------------------------------------
function ArcHUD:LevelDebug(level, msg, ...)
if (self.db.global.debugLevel) then
if (level <= self.db.global.debugLevel) then
self:Printf(msg, ...)
end
end
end
----------------------------------------------
-- Return current debug level
----------------------------------------------
function ArcHUD:GetDebugLevel()
return self.db.global.debugLevel
end
----------------------------------------------
-- Set debug level
----------------------------------------------
function ArcHUD:SetDebugLevel(level)
if (level == nil) or (level > 0 and level <= 4) then
local levelName = "off"
if (level ~= nil) then
levelName = debugLevels[level]
self:Printf(L["CMD_OPTS_DEBUG_SET"], levelName)
end
self.db.global.debugLevel = level
else
self:Print("Invalid debug level: "..level)
end
end
----------------------------------------------
-- OnInitialize()
----------------------------------------------
function ArcHUD:OnInitialize()
-- Set up database
self.db = LibStub("AceDB-3.0"):New("ArcHUD3DB", ArcHUD.defaults, "profile")
-- Set debug level
--self:SetDebugging(true)
self:SetDebugLevel(self.db.profile.Debug)
self:LevelDebug(d_info, "Registering timers")
self:RegisterTimer("UpdatePetNamePlate", self.UpdatePetNamePlate, 2, self, true)
self:RegisterTimer("UpdateTargetTarget", self.UpdateTargetTarget, 1, self, true)
self:RegisterTimer("CheckNamePlateMouseOver", self.CheckNamePlateMouseOver, 0.1, self, true)
self:RegisterTimer("UpdateTargetPower", self.UpdateTargetPower, 0.1, self, true)
self:LevelDebug(d_info, "Creating HUD frame elements")
self.TargetHUD = self:CreateHUDFrames()
self:InitConfig()
self:SendMessage("ARCHUD_LOADED")
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self:LevelDebug(d_notice, "ArcHUD has been initialized.")
end
----------------------------------------------
-- OnEnable()
----------------------------------------------
function ArcHUD:OnEnable()
self:LevelDebug(d_notice, "Registering events")
-- basic events
self:RegisterEvent("PLAYER_ENTERING_WORLD", "EventHandler")
self:RegisterEvent("PLAYER_ENTER_COMBAT", "CombatStatus")
self:RegisterEvent("PLAYER_LEAVE_COMBAT", "CombatStatus")
self:RegisterEvent("PLAYER_REGEN_ENABLED", "CombatStatus")
self:RegisterEvent("PLAYER_REGEN_DISABLED", "CombatStatus")
self:RegisterEvent("PET_ATTACK_START", "CombatStatus")
self:RegisterEvent("PET_ATTACK_STOP", "CombatStatus")
self:RegisterEvent("UNIT_FACTION", "UpdateFaction")
self:RegisterEvent("GROUP_ROSTER_UPDATE", "UpdateFaction")
self:RegisterEvent("RAID_TARGET_UPDATE", "UpdateRaidTargetIcon")
self:RegisterEvent("PLAYER_FLAGS_CHANGED")
self:RegisterEvent("PLAYER_UPDATE_RESTING")
if ArcHUD.classic then
self:RegisterEvent("UNIT_HAPPINESS", "UpdatePetNamePlate")
end
self:RegisterMessage("ARCHUD_FRAME_MOVED", "CheckFrames")
-- Set initial combat flags
self.PlayerIsInCombat = false
self.PlayerIsRegenOn = true
self.PetIsInCombat = false
self:LevelDebug(d_warn, "OnProfileChanged() A")
self:OnProfileChanged()
self:LevelDebug(d_warn, "OnProfileChanged() B")
self.Enabled = true
ArcHUDFrame:Show()
self:LevelDebug(d_notice, "Triggering ring enable event")
self:SendMessage("ARCHUD_MODULE_ENABLE")
self:LevelDebug(d_info, L["TEXT_ENABLED"])
if (AH_RuneFrame) then
AH_RuneFrame:Show()
end
-- load custom buff modules (OnInitialize() is too early)
self:LoadCustomBuffModules()
end
----------------------------------------------
-- OnDisable()
----------------------------------------------
function ArcHUD:OnDisable()
self:LevelDebug(d_notice, "Triggering ring disable event")
self:SendMessage("ARCHUD_MODULE_DISABLE")
self:HideBlizzardPlayer(true)
self:HideBlizzardTarget(true)
self:HideBlizzardFocus(true)
-- basic events
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
self:UnregisterEvent("PLAYER_ENTER_COMBAT")
self:UnregisterEvent("PLAYER_LEAVE_COMBAT")
self:UnregisterEvent("PLAYER_REGEN_ENABLED")
self:UnregisterEvent("PLAYER_REGEN_DISABLED")
self:UnregisterEvent("PET_ATTACK_START")
self:UnregisterEvent("PET_ATTACK_STOP")
self:UnregisterEvent("UNIT_FACTION")
self:UnregisterEvent("PARTY_MEMBERS_CHANGED")
self:UnregisterEvent("RAID_TARGET_UPDATE")
self:UnregisterEvent("PLAYER_FLAGS_CHANGED")
self:UnregisterEvent("PLAYER_UPDATE_RESTING")
if ArcHUD.classic then
self:UnregisterEvent("UNIT_HAPPINESS")
end
self:UnregisterMessage("ARCHUD_FRAME_MOVED")
-- Hide frame
ArcHUDFrame:Hide()
self.Enabled = false
self:LevelDebug(d_info, L["TEXT_DISABLED"])
end
----------------------------------------------
-- OnProfileChanged()
----------------------------------------------
function ArcHUD:OnProfileChanged(db, profile)
self.updating = true
self:UnregisterAll()
self:LevelDebug(d_notice, "OnProfileChanged()")
if(self.db.profile.BlizzPlayer and self.BlizzPlayerHidden or not self.db.profile.BlizzPlayer and not self.BlizzPlayerHidden) then
self:HideBlizzardPlayer(self.db.profile.BlizzPlayer)
end
if(self.db.profile.BlizzTarget and self.BlizzTargetHidden or not self.db.profile.BlizzTarget and not self.BlizzTargetHidden) then
self:HideBlizzardTarget(self.db.profile.BlizzTarget)
end
if(self.db.profile.BlizzFocus and self.BlizzFocusHidden or not self.db.profile.BlizzFocus and not self.BlizzFocusHidden) then
self:HideBlizzardFocus(self.db.profile.BlizzFocus)
end
if (SpellActivationOverlayFrame) then
SpellActivationOverlayFrame:SetScale(self.db.profile.BlizzSpellActScale)
if self.db.profile.BlizzSpellActCenter then
SpellActivationOverlayFrame:ClearAllPoints()
SpellActivationOverlayFrame:SetPoint("CENTER", ArcHUDFrame, "CENTER", 0, -87)
else
SpellActivationOverlayFrame:ClearAllPoints()
SpellActivationOverlayFrame:SetPoint("CENTER", UIParent, "CENTER", 0, 0)
end
self:HookBlizzardSpellActivation((self.db.profile.BlizzSpellActOpacity < 1.0))
end
if (self.db.profile.PlayerFrame) then
self.Nameplates.player:Show()
self.Nameplates.pet:Show()
else
self.Nameplates.player:Hide()
self.Nameplates.pet:Hide()
end
if(self.db.profile.TargetFrame) then
self:LevelDebug(d_notice, "Targetframe enabled. Registering unit events")
self:RegisterEvent("UNIT_HEALTH", "EventHandler")
self:RegisterEvent("UNIT_MAXHEALTH", "EventHandler")
self:RegisterEvent("UNIT_POWER_UPDATE", "EventHandler")
self:RegisterEvent("UNIT_MAXPOWER", "EventHandler")
self:RegisterEvent("UNIT_DISPLAYPOWER", "EventHandler")
if(self.db.profile.ShowBuffs) then
self:RegisterEvent("UNIT_AURA", "TargetAuras")
else
for i=1,40 do
self.TargetHUD["Buff"..i]:Hide()
self.TargetHUD["Debuff"..i]:Hide()
end
end
self:RegisterEvent("PLAYER_TARGET_CHANGED", "TargetUpdate")
if (not ArcHUD.classic) then
self:RegisterEvent("PLAYER_FOCUS_CHANGED", "TargetUpdate")
end
-- Show target frame if we have a target
if(UnitExists("target")) then
self:TargetUpdate()
end
self:LevelDebug(d_notice, "Enabling TargetTarget updates")
-- Enable Target's Target('s Target) updates
self:StartTimer("UpdateTargetTarget")
if(self.db.profile.AttachTop) then
self:LevelDebug(d_notice, "Attaching targetframe to top")
self.TargetHUD:ClearAllPoints()
self.TargetHUD:SetPoint("BOTTOM", self.TargetHUD:GetParent(), "TOP", 0, -100)
else
self:LevelDebug(d_notice, "Attaching targetframe to bottom")
self.TargetHUD:ClearAllPoints()
self.TargetHUD:SetPoint("TOP", self.TargetHUD:GetParent(), "BOTTOM", 0, -60)
end
-- Check for custom frame placements
for id, pos in pairs(self.db.profile.Positions) do
if(type(pos) == "table") then
self.movableFrames[id]:ClearAllPoints()
self.movableFrames[id]:SetPoint("BOTTOMLEFT", WorldFrame, "BOTTOMLEFT", pos.x, pos.y)
end
end
else
self:StopTimer("UpdateTargetTarget")
self:StopTimer("UpdateTargetPower")
self.TargetHUD:SetAlpha(0)
self.TargetHUD:Lock()
self:UnregisterEvent("UNIT_HEALTH", "EventHandler")
self:UnregisterEvent("UNIT_MAXHEALTH", "EventHandler")
self:UnregisterEvent("UNIT_POWER_UPDATE", "EventHandler")
self:UnregisterEvent("UNIT_MAXPOWER", "EventHandler")
self:UnregisterEvent("UNIT_DISPLAYPOWER", "EventHandler")
self:UnregisterEvent("UNIT_AURA", "TargetAuras")
self:UnregisterEvent("PLAYER_TARGET_CHANGED", "TargetUpdate")
if (not ArcHUD.classic) then
self:UnregisterEvent("PLAYER_FOCUS_CHANGED", "TargetUpdate")
end
end
self:LevelDebug(d_notice, "Positioning ring anchors. Width: "..self.db.profile.Width)
-- Position the HUD according to user settings
anchorModule = self:GetModule("Anchors", true)
if not (anchorModule == nil) then
self:GetModule("Anchors").Left:ClearAllPoints()
self:GetModule("Anchors").Left:SetPoint("TOPLEFT", ArcHUDFrame, "TOPLEFT", 0-self.db.profile.Width, 0)
self:GetModule("Anchors").Right:ClearAllPoints()
self:GetModule("Anchors").Right:SetPoint("TOPLEFT", ArcHUDFrame, "TOPRIGHT", self.db.profile.Width, 0)
end
--self:LevelDebug(d_notice, "Position frame. YLoc: "..self.db.profile.YLoc.." XLoc: "..self.db.profile.XLoc)
ArcHUDFrame:ClearAllPoints()
ArcHUDFrame:SetPoint("CENTER", WorldFrame, "CENTER", self.db.profile.XLoc, self.db.profile.YLoc)
--self:LevelDebug(d_notice, "Setting scale. Scale: "..self.db.profile.Scale)
-- Scale the HUD according to user settings.
ArcHUDFrame:SetScale(self.db.profile.Scale)
-- Scale TargetHUD according to user settings (relative to ArcHUDFrame).
self.TargetHUD:SetScale(self.db.profile.ScaleTargetFrame)
-- Set playername
self:UpdateFaction()
self:PLAYER_UPDATE_RESTING()
-- Enable nameplate updates
self:RestartNamePlateTimers()
-- Update target HUD
self:UpdateTargetHUD()
-- Modules
self:SendMessage("ARCHUD_MODULE_UPDATE")
self.updating = false
self:LevelDebug(d_notice, "OnProfileChanged() done")
end
----------------------------------------------
-- UnregisterAll()
----------------------------------------------
function ArcHUD:UnregisterAll()
self:LevelDebug(d_notice, "Unregistering events")
self:UnregisterEvent("UNIT_HEALTH")
self:UnregisterEvent("UNIT_MAXHEALTH")
self:UnregisterEvent("UNIT_POWER_UPDATE")
self:UnregisterEvent("UNIT_MAXPOWER")
self:UnregisterEvent("UNIT_DISPLAYPOWER")
self:UnregisterEvent("UNIT_AURA")
self:UnregisterEvent("UNIT_FACTION")
self:UnregisterEvent("PLAYER_TARGET_CHANGED")
if (not ArcHUD.classic) then
self:UnregisterEvent("PLAYER_FOCUS_CHANGED")
end
self:LevelDebug(d_notice, "Disabling timers")
self:StopTimer("UpdateTargetTarget")
self:StopTimer("UpdatePetNamePlate")
self:StopTimer("CheckNamePlateMouseOver")
self:StopTimer("UpdateTargetPower")
self:LevelDebug(d_notice, "Hiding frames")
for i=1,40 do
self.TargetHUD["Buff"..i]:Hide()
self.TargetHUD["Debuff"..i]:Hide()
end
self.TargetHUD:SetAlpha(0)
end
----------------------------------------------
-- ResetOptionsConfirm()
----------------------------------------------
function ArcHUD:ResetOptionsConfirm()
self.db:ResetDB()
self:OnProfileChanged()
self:Print(L["TEXT_RESET_CONFIRM"])
end
----------------------------------------------
-- Completely refresh HUD
----------------------------------------------
function ArcHUD:UpdateTargetHUD()
self:TargetUpdate()
end
----------------------------------------------
-- TargetUpdate()
----------------------------------------------
function ArcHUD:TargetUpdate(event, arg1)
-- Make sure we are targeting someone and that ArcHUD is enabled
if (UnitExists("target") and self.db.profile.TargetFrame) then
--self:LevelDebug(d_info, "TargetUpdate: Updating target frame...")
-- 3D target model
if((self.db.profile.PlayerModel and UnitIsPlayer("target")) or (self.db.profile.MobModel and not UnitIsPlayer("target"))) then
self.TargetHUD.Model:Show()
self.TargetHUD.Model:SetUnit("target")
--self:LevelDebug(d_notice, "TargetUpdate: Enabling 3D model. Player - "..((self.db.profile.PlayerModel and UnitIsPlayer("target")) and "yes" or "no")..", Mob - "..((self.db.profile.MobModel and not UnitIsPlayer("target")) and "yes" or "no"))
else
self.TargetHUD.Model:Hide()
--self:LevelDebug(d_notice, "TargetUpdate: Disabling 3D model")
end
self.TargetHUD:SetAlpha(1)
if(UnitIsDead("target") or UnitIsGhost("target")) then
self.TargetHUD.HPText:SetText("Dead")
else
if self.db.profile.ShowHealthPowerTextMax then
self.TargetHUD.HPText:SetText(self:fint(UnitHealth("target")).."/"..self:fint(UnitHealthMax("target")))
else
self.TargetHUD.HPText:SetText(self:fint(UnitHealth("target")))
end
end
-- Does the unit have power? If so we want to show it
if (UnitPowerMax("target") > 0) then
if self.db.profile.ShowHealthPowerTextMax then
self.TargetHUD.MPText:SetText(self:fint(UnitPower("target")).."/"..self:fint(UnitPowerMax("target")))
else
self.TargetHUD.MPText:SetText(self:fint(UnitPower("target")))
end
self:StartTimer("UpdateTargetPower")
else
self.TargetHUD.MPText:SetText(" ")
self:StopTimer("UpdateTargetPower")
end
local addtolevel = ""
if(self.db.profile.ShowClass) then
addtolevel = " " .. (UnitIsPlayer("target") and UnitClass("target") or UnitCreatureFamily("target") or UnitCreatureType("target") or "Unknown")
self.TargetHUD.Level:SetJustifyH("CENTER")
else
self.TargetHUD.Level:SetJustifyH("CENTER")
end
-- What kind of target is it? If UnitLevel returns negative we have a target whose
-- level are too high to show or a boss
if (UnitLevel("target") < 0) then
if ( UnitClassification("target") == "worldboss" ) then
self.TargetHUD.Level:SetText("Boss" .. addtolevel)
else
self.TargetHUD.Level:SetText("L??" .. addtolevel)
end
else
if (UnitClassification("target") == "normal") then
self.TargetHUD.Level:SetText("L" .. UnitLevel("target") .. addtolevel)
-- Make sure we mark elites with a + after the level
elseif (UnitClassification("target") == "elite") then
self.TargetHUD.Level:SetText("L" .. UnitLevel("target") .. "+" .. addtolevel)
-- Make sure we mark rares with Rare before level
elseif (UnitClassification("target") == "rare") then
self.TargetHUD.Level:SetText("Rare L" .. UnitLevel("target") .. addtolevel)
-- Make sure we mark rareelites with Rare before level and a + after level
elseif (UnitClassification("target") == "rareelite") then
self.TargetHUD.Level:SetText("Rare L" .. UnitLevel("target") .. "+" .. addtolevel)
end
end
-- Check if the target is friendly to the player
targetfriend = UnitIsFriend("player","target")
-- Color the level display based on the targets level in relation
-- to player level
if (targetfriend) then
self.TargetHUD.Level:SetTextColor(1, 0.9, 0)
elseif (UnitIsTrivial("target")) then
self.TargetHUD.Level:SetTextColor(0.7, 0.7, 0.7)
elseif (UnitLevel("target") == -1) then
self.TargetHUD.Level:SetTextColor(1, 0, 0)
elseif (UnitLevel("target") <= (UnitLevel("player")-3)) then
self.TargetHUD.Level:SetTextColor(0, 0.9, 0)
elseif (UnitLevel("target") >= (UnitLevel("player")+5)) then
self.TargetHUD.Level:SetTextColor(1, 0, 0)
elseif (UnitLevel("target") >= (UnitLevel("player")+3)) then
self.TargetHUD.Level:SetTextColor(1, 0.5, 0)
else
self.TargetHUD.Level:SetTextColor(1, 0.9, 0)
end
-- Color the targets hp and mana text correctly
local info = { r = 0.00, g = 1.00, b = 1.00 } -- alternate Mana color
local powerType, powerToken, altR, altG, altB = UnitPowerType("target")
if (powerType ~= nil and powerType > 0) then -- anything else then Mana
info = PowerBarColor[powerType]
if info == nil then
if not (altR == nil or altG == nil or altB == nil) then
info = { r = altR, g = altG, b = altB }
end
end
elseif not (altR == nil or altG == nil or altB == nil) then
info = { r = altR, g = altG, b = altB }
end
self.TargetHUD.MPText:SetTextColor(info.r, info.g, info.b)
if(targetfriend) then
self.TargetHUD.HPText:SetTextColor(0, 1, 0)
else
self.TargetHUD.HPText:SetTextColor(1, 0, 0)
end
-- The name of the target should be colored differently if it's a player or if
-- it's a mob
local _, class = UnitClass("target")
local color = self.ClassColor[class]
local decoration_l, decoration_r = "", ""
if(UnitIsUnit("target", "focus")) then
decoration_l = "|cffffffff>>|r "
decoration_r = " |cffffffff<<|r"
end
if (color and UnitIsPlayer("target")) then
-- Is target in a guild?
local guild, _, _ = GetGuildInfo("target")
-- Color the target name based on class since we have a player targeted
if(guild and ArcHUD.db.profile.ShowGuild) then
self.TargetHUD.Name:SetText(decoration_l.."|cff"..color..UnitName("target").." <"..guild..">".."|r"..decoration_r)
else
self.TargetHUD.Name:SetText(decoration_l.."|cff"..color..UnitName("target").."|r"..decoration_r)
end
else
-- Color the target name based on reaction (red to green) since we have a
-- mob targeted
local reaction = self.RepColor[UnitReaction("target","player")]
if(reaction) then
self.TargetHUD.Name:SetText(decoration_l.."|cff"..reaction..UnitName("target").."|r"..decoration_r)
else
self.TargetHUD.Name:SetText(decoration_l..UnitName("target")..decoration_r)
end
end
-- Show clickable nameplate only if the target is a friendly player and not self
--[[if(UnitIsPlayer("target") and targetfriend and not UnitIsUnit("player", "target")) then
self.NamePlates.Target:Show()
else
self.NamePlates.Target:Hide()
end]]
if(self.db.profile.ShowBuffs) then
-- Update buffs and debuffs for the target
self:TargetAuras(nil, "target")
end
self:UpdateFaction("target")
self:UpdateRaidTargetIcon()
self:PLAYER_FLAGS_CHANGED("target")
if(self.BlizzTargetHidden and not self.updating) then
if(UnitIsEnemy("target", "player")) then
PlaySound(SOUNDKIT.IG_CREATURE_AGGRO_SELECT) -- igCreatureAggroSelect
elseif(UnitIsFriend("player", "target")) then
PlaySound(SOUNDKIT.IG_CHARACTER_NPC_SELECT) -- igCharacterNPCSelect
else
PlaySound(SOUNDKIT.IG_CREATURE_NEUTRAL_SELECT) -- igCreatureNeutralSelect
end
end
self.Nameplates.target:Enable()
else
-- We didn't have anything targeted or ArcHUD is disabled so lets hide the
-- target frame again
if(self.BlizzTargetHidden and not self.updating) then
PlaySound(SOUNDKIT.INTERFACE_SOUND_LOST_TARGET_UNIT) -- INTERFACESOUND_LOSTTARGETUNIT
end
if (self.TargetHUD.locked) then
self.TargetHUD:SetAlpha(0)
else
self.TargetHUD:SetAlpha(1)
end
self.TargetHUD.Model:Hide()
self:StopTimer("UpdateTargetPower")
self.Nameplates.target:Disable()
end
end
----------------------------------------------
-- TargetAuras()
----------------------------------------------
function ArcHUD:TargetAuras(event, arg1)
if(not arg1 == "target") then return end
local unit = "target"
local i, icon, buff, count, buffType, color, duration, expirationTime
local filter = ""
if (self.db.profile.ShowOnlyBuffsCastByPlayer) then
filter = "PLAYER"
end
-- buffs
for i = 1, 40 do
local _, buff, count, buffType, duration, expirationTime = C_UnitAuras.GetBuffDataByIndex(unit, i, filter)
button = self.TargetHUD["Buff"..i]
if (buff) then
button.Icon:SetTexture(buff)
button:Show()
button.unit = unit
if (count > 1) then
button.Count:SetText(count)
button.Count:Show()
button.Count:SetPoint("CENTER", button, "CENTER", 2, 0)
else
button.Count:Hide()
end
if(duration) then
if(duration > 0) then
button.Cooldown:Show()
startCooldownTime = expirationTime - duration
button.Cooldown:SetCooldown(startCooldownTime, duration)
else
button.Cooldown:Hide()
end
else
button.Cooldown:Hide()
end
else
button:Hide()
end
end
-- debuffs
for i = 1, 40 do
local _, buff, count, buffType, duration, expirationTime = C_UnitAuras.GetDebuffDataByIndex(unit, i, filter)
button = self.TargetHUD["Debuff"..i]
if (buff) then
button.Icon:SetTexture(buff)
button:Show()
button.Border:Show()
button.isdebuff = 1
button.unit = unit
if ( buffType ) then
color = DebuffTypeColor[buffType]
else
color = DebuffTypeColor["none"]
end
button.Border:SetVertexColor(color.r, color.g, color.b)
if (count > 1) then
button.Count:SetText(count)
button.Count:Show()
button.Count:SetPoint("CENTER", button, "CENTER", 2, 0)
else
button.Count:Hide()
end
if(duration) then
if(duration > 0) then
button.Cooldown:Show()
startCooldownTime = expirationTime - duration
button.Cooldown:SetCooldown(startCooldownTime, duration)
else
button.Cooldown:Hide()
end
else
button.Cooldown:Hide()
end
else
button:Hide()
end
end
end
----------------------------------------------
-- SetAuraTooltip()
----------------------------------------------
function ArcHUD:SetAuraTooltip(this)
if (not this:IsVisible() or (self.db.profile.ShowBuffTooltips == false)) then return end
if (self.db.profile.HideBuffTooltipsIC and self.PlayerIsInCombat) then return end
GameTooltip:SetOwner(this, "ANCHOR_BOTTOMRIGHT")
local unit = this.unit
if (this.isdebuff == 1) then
GameTooltip:SetUnitDebuff(unit, this:GetID())
else
GameTooltip:SetUnitBuff(unit, this:GetID())
end
end
----------------------------------------------
-- UpdateTargetPower()
----------------------------------------------
function ArcHUD:UpdateTargetPower()
if self.db.profile.ShowHealthPowerTextMax then
self.TargetHUD.MPText:SetText(self:fint(UnitPower("target")).."/"..self:fint(UnitPowerMax("target")))
else
self.TargetHUD.MPText:SetText(self:fint(UnitPower("target")))
end
end
----------------------------------------------
-- UpdateFaction()
----------------------------------------------
function ArcHUD:UpdateFaction(unit)
--self:LevelDebug(d_info, "UpdateFaction: arg1 = %s, unit = %s", arg1 or "nil", unit or "nil")
if(not unit and arg1 and arg1 ~= "player") then return end
if(arg1 and not unit) then unit = arg1 end
if(unit and unit == "target") then
local factionGroup = UnitFactionGroup("target")
if(UnitIsPVPFreeForAll("target")) then
self.TargetHUD.PVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-FFA")
self.TargetHUD.PVPIcon:Show()
elseif(factionGroup and UnitIsPVP("target") and factionGroup ~= "Neutral") then
self.TargetHUD.PVPIcon:SetTexture("Interface\\TargetingFrame\\UI-PVP-"..factionGroup)
self.TargetHUD.PVPIcon:Show()
else
self.TargetHUD.PVPIcon:Hide()
end
else
local factionGroup, factionName = UnitFactionGroup("player");
local _, class = UnitClass("player")
local color = self.ClassColor[class]
if(self.db.profile.ShowPVP and UnitIsPVPFreeForAll("player")) then
if(not self.PVPEnabled) then
PlaySound(SOUNDKIT.IG_PVP_UPDATE)
end
self.Nameplates.player.Text:SetText("|cffffff00[FFA] |cff"..(color or "ffffff")..(UnitName("player") or "Unknown Entity").."|r")
self.PVPEnabled = true
elseif(self.db.profile.ShowPVP and factionGroup and UnitIsPVP("player")) then
if(not self.PVPEnabled) then
PlaySound(SOUNDKIT.IG_PVP_UPDATE)
end
self.Nameplates.player.Text:SetText("|cffff0000[PVP] |cff"..(color or "ffffff")..(UnitName("player") or "Unknown Entity").."|r")
self.PVPEnabled = true
else
self.Nameplates.player.Text:SetText("|cff"..(color or "ffffff")..(UnitName("player") or "Unknown Entity").."|r")
self.PVPEnabled = nil
end
end
end
----------------------------------------------
-- UpdateRaidTargetIcon()
----------------------------------------------
function ArcHUD:UpdateRaidTargetIcon()
if(not UnitExists("target")) then self.TargetHUD.RaidTargetIcon:Hide() return end
local index = GetRaidTargetIndex("target")
if(index) then
SetRaidTargetIconTexture(self.TargetHUD.RaidTargetIcon, index)
self.TargetHUD.RaidTargetIcon:Show()
else
self.TargetHUD.RaidTargetIcon:Hide()
end
end
----------------------------------------------
-- PLAYER_FLAGS_CHANGED()
----------------------------------------------
function ArcHUD:PLAYER_FLAGS_CHANGED(unit)
if(arg1 and not unit) then unit = arg1 end
if(not UnitExists("target")) then self.TargetHUD.LeaderIcon:Hide() return end
if(unit == "target") then
if(UnitIsGroupLeader("target")) then
self.TargetHUD.LeaderIcon:Show()
else
self.TargetHUD.LeaderIcon:Hide()
end
end
end
----------------------------------------------
-- UpdatePetNamePlate()
----------------------------------------------
function ArcHUD:UpdatePetNamePlate()
if(UnitExists("pet")) then
local color = "00ff00"
local alpha = self.db.profile.FadeFull
local happiness = ""
if ArcHUD.classic then
happiness, _, _ = GetPetHappiness()
if(happiness) then
if(happiness == 1) then
color = "ff0000"
happiness = " :("
alpha = self.db.profile.FadeIC
elseif(happiness == 2) then
color = "ffff00"
happiness = " :||"
alpha = self.db.profile.FadeOOC
elseif(happiness == 3) then
color = "00ff00"
happiness = " :)"
alpha = self.db.profile.FadeFull
end
else
happiness = ""
end
end
self.Nameplates.pet.alpha = alpha
if ((not self.Nameplates.pet.state)) then
ArcHUDRingTemplate.SetRingAlpha(self.Nameplates.pet, alpha)
end
self.Nameplates.pet.Text:SetText("|cff"..color..UnitName("pet")..happiness.."|r")
self.Nameplates.pet.disabled = false
else
self.Nameplates.pet:Disable()
self.Nameplates.pet.disabled = true
self.Nameplates.pet:SetAlpha(0)
end
end
----------------------------------------------
-- UpdateTargetTarget()
----------------------------------------------
function ArcHUD:UpdateTargetTarget()
-- Handle Target's Target
if(UnitExists("targettarget") and self.db.profile.TargetTarget) then
local _, class = UnitClass("targettarget")
local color = self.ClassColor[class]
local decoration = ""
if(UnitIsUnit("targettarget", "focus")) then
decoration = "|cffffffff>|r "
end
if (color and UnitIsPlayer("targettarget")) then
self.TargetHUD.Target.Name:SetText(decoration.."|cff"..color..UnitName("targettarget").."|r")
else
local reaction = self.RepColor[UnitReaction("targettarget","player")]
if(reaction) then
self.TargetHUD.Target.Name:SetText(decoration.."|cff"..reaction..UnitName("targettarget").."|r")
else
self.TargetHUD.Target.Name:SetText(decoration..UnitName("targettarget"))
end
end
local info = {}
if (UnitPowerType("targettarget") == 0) then
info = { r = 0.00, g = 1.00, b = 1.00 }
else
info = PowerBarColor[UnitPowerType("targettarget")]
end
self.TargetHUD.Target.MPText:SetTextColor(info.r, info.g, info.b)
if(UnitIsFriend("player","targettarget")) then
self.TargetHUD.Target.HPText:SetTextColor(0, 1, 0)
else
self.TargetHUD.Target.HPText:SetTextColor(1, 0, 0)
end
if(UnitIsDead("targettarget") or UnitIsGhost("targettarget")) then
self.TargetHUD.Target.HPText:SetText("Dead")
else
self.TargetHUD.Target.HPText:SetText(math.floor(UnitHealth("targettarget")/UnitHealthMax("targettarget")*100).."%")
end
if (UnitPowerMax("targettarget") > 0) then
self.TargetHUD.Target.MPText:SetText(math.floor(UnitPower("targettarget")/UnitPowerMax("targettarget")*100).."%")
else
self.TargetHUD.Target.MPText:SetText(" ")
end
self.TargetHUD.Target:SetAlpha(1)
self.Nameplates.targettarget:Enable()
else
if(self.TargetHUD.Target.locked) then
self.TargetHUD.Target:SetAlpha(0)
end
self.Nameplates.targettarget:Disable()
end
-- Handle Target's Target's Target
if(UnitExists("targettargettarget") and self.db.profile.TargetTargetTarget) then
local _, class = UnitClass("targettargettarget")
local color = self.ClassColor[class]
local decoration = ""
if(UnitIsUnit("targettargettarget", "focus")) then
decoration = "|cffffffff>|r "
end
if (color and UnitIsPlayer("targettargettarget")) then
self.TargetHUD.TargetTarget.Name:SetText(decoration.."|cff"..color..UnitName("targettargettarget").."|r")
else
local reaction = self.RepColor[UnitReaction("targettargettarget","player")]
if(reaction) then
self.TargetHUD.TargetTarget.Name:SetText(decoration.."|cff"..reaction..UnitName("targettargettarget").."|r")
else
self.TargetHUD.TargetTarget.Name:SetText(decoration..UnitName("targettargettarget"))
end
end
local info = {}
if (UnitPowerType("targettargettarget") == 0) then
info = { r = 0.00, g = 1.00, b = 1.00 }
else
info = PowerBarColor[UnitPowerType("targettargettarget")]
end
self.TargetHUD.TargetTarget.MPText:SetTextColor(info.r, info.g, info.b)
if(UnitIsFriend("player","targettargettarget")) then
self.TargetHUD.TargetTarget.HPText:SetTextColor(0, 1, 0)
else
self.TargetHUD.TargetTarget.HPText:SetTextColor(1, 0, 0)
end
if(UnitIsDead("targettargettarget") or UnitIsGhost("targettargettarget")) then