forked from i2ichardt/HealersMate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHMUnitFrame.lua
1541 lines (1316 loc) · 52.6 KB
/
HMUnitFrame.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
HMUnitFrame = {}
HMUnitFrame.owningGroup = nil
HMUnitFrame.unit = nil
HMUnitFrame.isCustomUnit = false
HMUnitFrame.guidUnit = nil -- Used for custom units
HMUnitFrame.rootContainer = nil -- Contains the main container and the overlay
HMUnitFrame.overlayContainer = nil -- Contains elements that should not be affected by opacity
HMUnitFrame.container = nil -- Most elements are contained in this
HMUnitFrame.nameText = nil
HMUnitFrame.healthBar = nil
HMUnitFrame.incomingHealthBar = nil
HMUnitFrame.incomingDirectHealthBar = nil
HMUnitFrame.healthText = nil
HMUnitFrame.missingHealthText = nil
HMUnitFrame.incomingHealText = nil
HMUnitFrame.powerBar = nil
HMUnitFrame.powerText = nil
HMUnitFrame.roleIcon = nil
HMUnitFrame.button = nil
HMUnitFrame.auraPanel = nil
HMUnitFrame.scrollingDamageFrame = nil -- Unimplemented
HMUnitFrame.scrollingHealFrame = nil -- Unimplemented
HMUnitFrame.auraIconPool = {} -- map: {"frame", "icon", "stackText"}
HMUnitFrame.auraIcons = {} -- map: {"frame", "icon", "stackText"}
HMUnitFrame.targetOutline = nil
HMUnitFrame.targeted = false
HMUnitFrame.flashTexture = nil -- {"frame", "texture"}
HMUnitFrame.flashTime = 0
HMUnitFrame.lastHealthPercent = 0
HMUnitFrame.incomingHealing = 0
HMUnitFrame.incomingDirectHealing = 0
HMUnitFrame.hovered = false
HMUnitFrame.pressed = false
HMUnitFrame.distanceText = nil
HMUnitFrame.lineOfSightIcon = nil -- map: {"frame", "icon"}
HMUnitFrame.inRange = true
HMUnitFrame.distance = 0
HMUnitFrame.inSight = true
HMUnitFrame.fakeStats = {} -- Used for displaying a fake party/raid
local _G = getfenv(0)
if HMUtil.IsSuperWowPresent() then
setmetatable(HMUnitProxy, {__index = getfenv(1)})
setfenv(1, HMUnitProxy)
end
-- Singleton references, assigned in constructor
local HM
local util = HMUtil
local compost = AceLibrary("Compost-2.0")
function HMUnitFrame:New(unit, isCustomUnit)
HM = HealersMate -- Need to do this in the constructor or else it doesn't exist yet
local obj = {unit = unit, isCustomUnit = isCustomUnit, auraIconPool = {},
auraIcons = {}, fakeStats = HMUnitFrame.GenerateFakeStats()}
setmetatable(obj, self)
self.__index = self
return obj
end
local fakeNames = {"Leeroyjenkins", "Realsigred", "Appledog", "Exdraclespy", "Dieghostt", "Olascoli", "Yaijin",
"Geroya", "Artemyz", "Nomeon", "Orinnberry", "Hoppetosse", "Deathell", "Jackbob", "Luscita", "Healpiggies",
"Pamara", "Merauder", "Onetwofree", "Biggly", "Drexx", "Grassguzzler", "Thebackup", "Steaktank", "Fshoo",
"Bovinebill", "Rawtee", "Aylin", "Sneeziesnorf", "Dreak", "Jordin", "Evilkillers", "Xathas", "Linkado",
"Smiteknight", "Rollnmbqs", "Viniss", "Rinnegon", "Elfdefense", "Foxtau", "Tombdeath", "Myhawk", "Numnumcat",
"Laudead", "Esatto", "Boffin", "Tikomo", "Huddletree", "Butterboy", "Bolgrand", "Ginius", "Exulthiuss",
"Xplol", "Wheeliebear", "Pimenton", "Meditating", "Qyroth", "Lazhar", "Rookon", "Eiris", "Padren",
"Erazergus", "Scarlatina", "Holdrim", "Soulbane", "Debilitated", "Doorooid", "Palefire", "Tellarna",
"Breathofwing", "Chillaf", "Hulena", "Hyperiann", "Bluebeam", "Daevana", "Adriena", "Aeywynn", "Bluaa",
"Chadd", "Leutry", "Mouzer", "Qiner"}
function HMUnitFrame.GenerateFakeStats()
local name = fakeNames[math.random(table.getn(fakeNames))]
local class = util.GetRandomClass()
local currentHealth
local maxHealth = math.random(100, 5000)
if math.random(10) > 3 then
currentHealth = math.random(1, maxHealth)
elseif math.random(8) == 1 then
currentHealth = 0
else
currentHealth = maxHealth
end
local maxPower = math.random(100, 5000)
if util.ClassPowerTypes[class] ~= "mana" then
maxPower = 100
end
local currentPower = math.random(1, maxPower)
local debuffType
local trackedDebuffCount = table.getn(HealersMateSettings.TrackedDebuffTypes)
if trackedDebuffCount > 0 then
if math.random(1, 10) == 1 then
debuffType = HealersMateSettings.TrackedDebuffTypes[math.random(trackedDebuffCount)]
end
end
local raidMark
if math.random(10) == 1 then
raidMark = math.random(8)
end
local online = not (math.random(12) == 1)
local fakeStats = {
name = name,
class = class,
currentHealth = currentHealth,
maxHealth = maxHealth,
currentPower = currentPower,
maxPower = maxPower,
debuffType = debuffType,
raidMark = raidMark,
online = online}
return fakeStats
end
function HMUnitFrame:GetUnit()
return self.unit
end
function HMUnitFrame:GetResolvedUnit()
return not self.isCustomUnit and self.unit or self.guidUnit
end
function HMUnitFrame:GetRootContainer()
return self.rootContainer
end
function HMUnitFrame:GetContainer()
return self.container
end
function HMUnitFrame:Show()
self.container:Show()
self.rootContainer:Show()
self:UpdateAll()
end
function HMUnitFrame:Hide()
if not self:IsFake() then
self.container:Hide()
self.rootContainer:Hide()
end
end
function HMUnitFrame:IsShown()
return self.rootContainer:IsShown()
end
function HMUnitFrame:SetOwningGroup(group)
self.owningGroup = group
self:Initialize()
self:GetRootContainer():SetParent(group:GetContainer())
end
function HMUnitFrame:RegisterClicks()
local buttons = HMOptions.CastWhen == "Mouse Up" and util.GetUpButtons() or util.GetDownButtons()
self.button:RegisterForClicks(unpack(buttons))
for _, aura in ipairs(self.auraIcons) do
aura.frame:RegisterForClicks(unpack(buttons))
end
for _, aura in ipairs(self.auraIconPool) do
aura.frame:RegisterForClicks(unpack(buttons))
end
end
function HMUnitFrame:UpdateAll()
self:UpdateAuras()
self:UpdateHealth()
self:UpdatePower()
self:UpdateRange()
self:UpdateSight()
self:EvaluateTarget()
self:UpdateOutline()
self:UpdateRaidMark()
end
function HMUnitFrame:UpdateRange()
local wasInRange = self.inRange
self.distance = self:GetCache():GetDistance()
self.inRange = self.distance <= 40
if wasInRange ~= self.inRange then
self:UpdateOpacity()
end
self:UpdateRangeText()
end
function HMUnitFrame:UpdateSight()
self.inSight = self:GetCache():IsInSight()
local frame = self.lineOfSightIcon.frame
if frame:IsShown() ~= self.inSight then
local dist = math.ceil(self.distance)
if not self.inSight and (dist < 80 or UnitIsUnit(self.unit, "target")) then
frame:Show()
else
frame:Hide()
end
end
end
local preciseDistance = util.CanClientGetPreciseDistance()
function HMUnitFrame:UpdateRangeText()
local dist = math.ceil(self.distance)
local distanceText = self.distanceText
local text = ""
if dist >= (preciseDistance and 30 or 28) and dist < 9999 then
local r, g, b
if dist > 80 then
r, g, b = 0.75, 0.75, 0.75
elseif dist > 40 then
r, g, b = 1, 0.3, 0.3
else
r, g, b = 1, 0.6, 0
end
if preciseDistance then
text = text..util.Colorize(dist.." yd", r, g, b)
else
if dist < 28 then
text = text..util.Colorize("<"..dist.." yd", r, g, b)
else
text = text..util.Colorize("28+ yd", r, g, b)
end
end
end
distanceText:SetText(text)
end
function HMUnitFrame:UpdateOpacity()
local profile = self:GetProfile()
local alpha = 1
if not self.inRange then
alpha = alpha * (profile.OutOfRangeOpacity / 100)
end
if profile.AlertPercent < math.ceil((self:GetCurrentHealth() / self:GetMaxHealth()) * 100) and
table.getn(self:GetAfflictedDebuffTypes()) == 0 then
alpha = alpha * (profile.NotAlertedOpacity / 100)
end
self.container:SetAlpha(alpha)
end
-- Evaluate if the unit of this frame is the target and update the target outline if the state has changed
function HMUnitFrame:EvaluateTarget()
if self.unit == "target" then -- "target" frames should not show a border since it's obvious they're the target
return
end
local wasTargeted = self.targeted
self.targeted = UnitIsUnit(self.unit, "target")
if self.targeted ~= wasTargeted then
self:UpdateOutline()
end
end
function HMUnitFrame:UpdateOutline()
local aggro = self:HasAggro()
local targeted = self.targeted
local r, g, b
if aggro and targeted then
r, g, b = 1, 0.6, 0.5
elseif aggro then
r, g, b = 1, 0, 0
elseif targeted then
r, g, b = 1, 1, 0.85
end
self:SetOutlineColor(r, g, b)
end
function HMUnitFrame:SetOutlineColor(r, g, b)
if r then
self.targetOutline:Show()
self.targetOutline:SetBackdropBorderColor(r, g, b, 0.75)
else
self.targetOutline:Hide()
end
end
function HMUnitFrame:UpdateRaidMark()
local unit = self:GetResolvedUnit()
local fake = self:IsFake()
if not unit and not fake then
self.raidMarkIcon.frame:Hide()
return
end
if unit == "target" and not UnitExists("target") then
self.raidMarkIcon.frame:Hide()
return
end
local markIndex
if fake then
markIndex = self.fakeStats.raidMark
else
markIndex = GetRaidTargetIndex(unit)
end
if not markIndex then
self.raidMarkIcon.frame:Hide()
return
end
SetRaidTargetIconTexture(self.raidMarkIcon.icon, markIndex)
self.raidMarkIcon.frame:Show()
end
function HMUnitFrame:Flash()
local FLASH_TIME = 0.15
local START_OPACITY = self:GetProfile().FlashOpacity / 100
self.flashTime = FLASH_TIME
local frame = self.flashTexture.frame
frame:Show()
frame:SetAlpha(START_OPACITY)
frame.flashTime = FLASH_TIME
frame.startOpacity = START_OPACITY
if not frame:GetScript("OnUpdate") then
frame:SetScript("OnUpdate", HMUnitFrame.Flash_OnUpdate)
end
end
do
function HMUnitFrame.Flash_OnUpdate()
local frame = this
local self = frame.unitFrame
local FLASH_TIME = frame.flashTime
local START_OPACITY = frame.startOpacity
self.flashTime = self.flashTime - arg1
frame:SetAlpha(START_OPACITY - (((FLASH_TIME - self.flashTime) / FLASH_TIME) * START_OPACITY))
if self.flashTime <= 0 then
frame:Hide()
frame:SetScript("OnUpdate", nil)
end
end
end
-- If direct healing is nil, it will be assumed that all the incoming healing is direct healing
function HMUnitFrame:SetIncomingHealing(incomingHealing, incomingDirectHealing)
self.incomingHealing = incomingHealing
self.incomingDirectHealing = incomingDirectHealing or incomingHealing
self:UpdateHealth()
end
function HMUnitFrame:UpdateIncomingHealing()
if HMHealPredict then
local _, guid = UnitExists(self:GetUnit())
self:SetIncomingHealing(HMHealPredict.GetIncomingHealing(guid))
else
local name = UnitName(self:GetUnit())
self:SetIncomingHealing(HealersMate.HealComm:getHeal(name))
end
end
function HMUnitFrame:GetCurrentHealth()
if self:IsFake() then
if not self.fakeStats.online then
return 0
end
return self.fakeStats.currentHealth
end
return UnitHealth(self.unit)
end
function HMUnitFrame:GetMaxHealth()
if self:IsFake() then
return self.fakeStats.maxHealth
end
return UnitHealthMax(self.unit)
end
function HMUnitFrame:GetCurrentPower()
if self:IsFake() then
return self.fakeStats.currentPower
end
return UnitMana(self.unit)
end
function HMUnitFrame:GetMaxPower()
if self:IsFake() then
return self.fakeStats.maxPower
end
return UnitManaMax(self.unit)
end
function HMUnitFrame:ShouldShowMissingHealth()
local profile = self:GetProfile()
local currentHealth = self:GetCurrentHealth()
if currentHealth == 0 then
return false
end
local missingHealth = self:GetMaxHealth() - currentHealth
return (missingHealth > 0 or profile.AlwaysShowMissingHealth) and profile.MissingHealthDisplay ~= "Hidden"
and (profile.ShowEnemyMissingHealth or not self:IsEnemy())
and not UnitIsGhost(self.unit) and (UnitIsConnected(self.unit) or self:IsFake())
end
-- Used for custom colors in profiles.
-- Valid Colors:
-- "Class" - Uses the unit's class color
-- "Default" - Does not color the text
-- Array RGB - Colors the text as the RGB values
function HMUnitFrame:ColorizeText(inputText, color)
if color == "Class" then
local r, g, b = util.GetClassColor(self:GetClass())
return util.Colorize(inputText, r, g, b)
elseif type(color) == "table" then
return util.Colorize(inputText, color)
end
return inputText
end
function HMUnitFrame:UpdateHealth()
local fake = self:IsFake()
if not UnitExists(self.unit) and not fake then
if self.isCustomUnit or self.unit == "target" then
self.healthText:SetText(util.Colorize(self.unit ~= "target" and "Too Far" or "", 0.7, 0.7, 0.7))
self.missingHealthText:SetText("")
self:SetHealthBarValue(0)
self.powerBar:SetValue(0)
self:UpdateOpacity()
self:AdjustHealthPosition()
end
if self.unit == "target" then
self.nameText:SetText("")
end
return
end
local profile = self:GetProfile()
local unit = self.unit
local fakeOnline = self.fakeStats.online
local currentHealth = self:GetCurrentHealth()
local maxHealth = self:GetMaxHealth()
local unitName = self:GetName()
self:UpdateOpacity() -- May be changed further down
if not UnitIsConnected(unit) and (not fake or not fakeOnline) then
self.nameText:SetText(self:ColorizeText(unitName, profile.NameText.Color))
self.healthText:SetText(util.Colorize("Offline", 0.7, 0.7, 0.7))
self.missingHealthText:SetText("")
self:SetHealthBarValue(0)
self.powerBar:SetValue(0)
self:UpdateOpacity()
self:AdjustHealthPosition()
return
end
local enemy = self:IsEnemy()
-- Set Name and its colors
local nameText
if self:IsPlayer() or fake then
local r, g, b
if profile.ShowDebuffColorsOn == "Name" and not enemy then
r, g, b = self:GetDebuffColor()
end
if r then
nameText = util.Colorize(unitName, r, g, b)
else
nameText = self:ColorizeText(unitName, profile.NameText.Color)
end
else -- Unit is not a player
if enemy then
nameText = util.Colorize(unitName, 1, 0.3, 0.3)
else -- Unit is not an enemy
local r, g, b
if profile.ShowDebuffColorsOn == "Name" then
r, g, b = self:GetDebuffColor()
end
if r then
nameText = util.Colorize(unitName, r, g, b)
else
nameText = unitName
end
end
end
self.nameText:SetText(nameText)
local healthText = self.healthText
local missingHealthText = self.missingHealthText
-- Set Health Status
if currentHealth <= 0 then -- Unit Dead
local cache = self:GetCache()
local text
if cache:IsBeingResurrected() then
if cache:GetResurrectionCasts() > 1 then
text = util.Colorize("DEAD", 0.8, 1, 0.8)
else
text = util.Colorize("DEAD", 0.3, 1, 0.3)
end
else
text = util.Colorize("DEAD", 1, 0.3, 0.3)
end
-- Check for Feign Death so the healer doesn't get alarmed
local feign = self:GetCache():HasBuffIDOrName(5384, "Feign Death")
if feign then
text = "Feign"
end
healthText:SetText(text)
missingHealthText:SetText("")
self:SetHealthBarValue(0)
self.powerBar:SetValue(0)
if self.lastHealthPercent > 0 and not self:IsEnemy() then
if not feign then
self:Flash()
end
self.lastHealthPercent = 0
end
elseif UnitIsGhost(unit) then
healthText:SetText(util.Colorize("Ghost", 1, 0.3, 0.3))
missingHealthText:SetText("")
self:SetHealthBarValue(0)
self.powerBar:SetValue(0)
else -- Unit Not Dead
local text = ""
local missingText = ""
if profile.HealthDisplay == "Health/Max Health" then
text = currentHealth.."/"..maxHealth
elseif profile.HealthDisplay == "Health" then
text = currentHealth
elseif profile.HealthDisplay == "% Health" then
text = math.floor((currentHealth / maxHealth) * 100).."%"
end
if profile.ShowDebuffColorsOn == "Health" then
local r, g, b = self:GetDebuffColor()
if r then
text = util.Colorize(text, r, g, b)
end
end
if self.hovered then
text = util.Colorize(text, 1, 1, 1)
end
local missingHealth = math.floor(maxHealth - currentHealth)
if self:ShouldShowMissingHealth() then
local missingHealthStr
if profile.MissingHealthDisplay == "-Health" then
missingHealthStr = "-"..missingHealth
elseif profile.MissingHealthDisplay == "-% Health" then
missingHealthStr = "-"..math.ceil((missingHealth / maxHealth) * 100).."%"
end
if profile.MissingHealthInline then
if text ~= "" then
text = text..self:ColorizeText(" ("..missingHealthStr..")", profile.HealthTexts.Missing.Color)
end
else
missingText = self:ColorizeText(missingHealthStr, profile.HealthTexts.Missing.Color)
end
end
healthText:SetText(text)
missingHealthText:SetText(missingText)
self:SetHealthBarValue(currentHealth / maxHealth)
local healthPercent = (currentHealth / maxHealth) * 100
if healthPercent < self.lastHealthPercent - profile.FlashThreshold and not self:IsEnemy() then
self:Flash()
end
self.lastHealthPercent = healthPercent
if self:GetCache():HasBuffIDOrName(27827, "Spirit of Redemption") then
healthText:SetText(util.Colorize("Spirit", 1, 0.3, 0.3))
end
end
self:UpdateOpacity()
self:AdjustHealthPosition()
end
local greenToRedColors = {{1, 0, 0}, {1, 0.3, 0}, {1, 1, 0}, {0.6, 0.92, 0}, {0, 0.8, 0}}
function HMUnitFrame:SetHealthBarValue(value)
local unit = self.unit
local healthBar = self.healthBar
local incomingHealthBar = self.incomingHealthBar
local incomingDirectHealthBar = self.incomingDirectHealthBar
local incomingHealText = self.incomingHealText
local incomingHealing = self.incomingHealing
local incomingDirectHealing = self.incomingDirectHealing
local profile = self:GetProfile()
local enemy = self:IsEnemy()
healthBar:SetValue(value)
local healthIncMaxRatio = 0
local healthIncDirectMaxRatio = 0
if incomingHealing > 0 then
healthIncMaxRatio = value + (incomingHealing / self:GetMaxHealth())
healthIncDirectMaxRatio = value + (incomingDirectHealing / self:GetMaxHealth())
incomingHealthBar:SetValue(healthIncMaxRatio)
incomingDirectHealthBar:SetValue(healthIncDirectMaxRatio)
if profile.IncomingHealDisplay == "Overheal" then
if healthIncMaxRatio > 1 then
incomingHealText:SetText("+"..math.ceil(self:GetCurrentHealth() + incomingHealing - self:GetMaxHealth()))
local rgb = incomingDirectHealing > 0 and profile.IncomingHealText.Color or
profile.IncomingHealText.IndirectColor
if incomingDirectHealing > 0 then
incomingHealText:SetTextColor(rgb[1], rgb[2], rgb[3])
else
incomingHealText:SetTextColor(rgb[1], rgb[2], rgb[3])
end
else
incomingHealText:SetText("")
end
elseif profile.IncomingHealDisplay == "Heal" then
incomingHealText:SetText("+"..self.incomingHealing)
local rgb = incomingDirectHealing > 0 and profile.IncomingHealText.Color or
profile.IncomingHealText.IndirectColor
if incomingDirectHealing > 0 then
incomingHealText:SetTextColor(rgb[1], rgb[2], rgb[3])
else
incomingHealText:SetTextColor(rgb[1], rgb[2], rgb[3])
end
else
incomingHealText:SetText("")
end
else -- No incoming healing
incomingHealthBar:SetValue(0)
incomingDirectHealthBar:SetValue(0)
incomingHealText:SetText("")
end
incomingHealthBar:SetAlpha(0.35)
incomingDirectHealthBar:SetAlpha(0.4)
local r, g, b
if profile.ShowDebuffColorsOn == "Health Bar" then
r, g, b = self:GetDebuffColor()
end
if r == nil then -- If there's no debuff color, proceed to normal colors
local hbc = enemy and profile.EnemyHealthBarColor or profile.HealthBarColor
if hbc == "Class" then
local class = util.GetClass(unit)
if class == nil then
class = self.fakeStats.class
end
r, g, b = util.GetClassColor(class)
elseif hbc == "Green" then
r, g, b = 0, 0.8, 0
elseif hbc == "Green To Red" then
r, g, b = util.InterpolateColorsNoTable(greenToRedColors, value)
end
if healthIncMaxRatio > 1 then
local brightenFactor = math.min(((healthIncMaxRatio - 1) / 4) + 1, 1.25)
r = math.min(r * brightenFactor, 1)
g = math.min(g * brightenFactor, 1)
b = math.min(b * brightenFactor, 1)
end
end
healthBar:SetStatusBarColor(r, g, b)
incomingHealthBar:SetStatusBarColor(0, 0.8, 0)
incomingDirectHealthBar:SetStatusBarColor(0, 0.8, 0)
local feign = self:GetCache():HasBuffIDOrName(5384, "Feign Death")
local bg = healthBar.background
if value == 0 and not feign then
bg:SetTexture(0.5, 0.5, 0.5, 0.5)
elseif value < 0.3 and not enemy and not feign then
bg:SetTexture(1, 0.4, 0.4, 0.25)
else
bg:SetTexture(0.5, 0.5, 0.5, 0.25)
end
end
-- Returns the r, g, b of the current dispellable debuff color, or nil if none
function HMUnitFrame:GetDebuffColor()
local enemy = self:IsEnemy()
if not enemy then -- Do not display debuff colors for enemies
for _, trackedDebuffType in ipairs(HealersMateSettings.TrackedDebuffTypes) do
if self:GetAfflictedDebuffTypes()[trackedDebuffType] then
local debuffTypeColor = HealersMateSettings.DebuffTypeColors[trackedDebuffType]
return debuffTypeColor[1], debuffTypeColor[2], debuffTypeColor[3]
end
end
end
local fake = self:IsFake()
if fake and self.fakeStats.debuffType then
local debuffTypeColor = HealersMateSettings.DebuffTypeColors[self.fakeStats.debuffType]
return debuffTypeColor[1], debuffTypeColor[2], debuffTypeColor[3]
end
end
function HMUnitFrame:UpdatePower()
local profile = self:GetProfile()
local unit = self.unit
local powerBar = self.powerBar
local fake = self:IsFake()
local class = fake and self.fakeStats.class or util.GetClass(unit)
local currentPower = self:GetCurrentPower()
local maxPower = self:GetMaxPower()
if not UnitExists(self.unit) and not fake then
powerBar:SetValue(0)
self.powerText:SetText("")
return
end
local powerColor = fake and util.PowerColors[util.ClassPowerTypes[class or "WARRIOR"]] or util.GetPowerColor(unit)
powerBar:SetValue(currentPower / maxPower)
powerBar:SetStatusBarColor(powerColor[1], powerColor[2], powerColor[3])
local text = ""
if profile.PowerDisplay == "Power" then
text = currentPower
elseif profile.PowerDisplay == "Power/Max Power" then
text = currentPower.."/"..maxPower
elseif profile.PowerDisplay == "% Power" then
if maxPower == 0 then
maxPower = 1
end
text = math.floor((currentPower / maxPower) * 100).."%"
end
self.powerText:SetText(text)
end
local AURA_DURATION_TEXT_FLASH_THRESHOLD = 5
local AURA_DURATION_TEXT_LOW_THRESHOLD = 30
-- A map of all seconds below the flash threshold to an array of colors to interpolate
local durationTextFlashColorsRange
if util.IsSuperWowPresent() then
local flashColorsReset = {{1, 1, 0.75}, {1, 0.7, 0.55}, {1, 0.6, 0.6}}
local flashColors = {{1, 1, 0.25}, {1, 0.6, 0.35}, {1, 0.4, 0.4}}
local textFlashColors = {}
for i = 0, AURA_DURATION_TEXT_FLASH_THRESHOLD + 1 do
textFlashColors[i] = {}
textFlashColors[i][1] = util.InterpolateColors(flashColors,
(AURA_DURATION_TEXT_FLASH_THRESHOLD - i) / AURA_DURATION_TEXT_FLASH_THRESHOLD)
textFlashColors[i][2] = util.InterpolateColors(flashColorsReset,
(AURA_DURATION_TEXT_FLASH_THRESHOLD - i) / AURA_DURATION_TEXT_FLASH_THRESHOLD)
end
durationTextFlashColorsRange = {}
for seconds, colors in pairs(textFlashColors) do
durationTextFlashColorsRange[seconds] = {colors[2], colors[1]}
end
end
function HMUnitFrame:AllocateAura()
local frame = CreateFrame("Button", nil, self.auraPanel, "UIPanelButtonTemplate")
frame.unitFrame = self
frame:SetNormalTexture(nil)
frame:SetHighlightTexture(nil)
frame:SetPushedTexture(nil)
local buttons = HMOptions.CastWhen == "Mouse Up" and util.GetUpButtons() or util.GetDownButtons()
frame:RegisterForClicks(unpack(buttons))
frame:EnableMouse(true)
frame:SetScript("OnEnter", HMUnitFrame.Aura_OnEnter)
frame:SetScript("OnLeave", HMUnitFrame.Aura_OnLeave)
frame:SetScript("OnClick", HMUnitFrame.Aura_OnClick)
frame:SetScript("OnMouseUp", HMUnitFrame.Aura_OnMouseUp)
frame:SetScript("OnMouseDown", HMUnitFrame.Aura_OnMouseDown)
local icon = frame:CreateTexture(nil, "OVERLAY")
local stackText = frame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
stackText:SetTextColor(1, 1, 1)
-- Duration display, only used when SuperWoW is present
if util.IsSuperWowPresent() then
local duration = CreateFrame("Model", nil, frame, "CooldownFrameTemplate")
duration.noCooldownCount = true
duration:SetAlpha(0.8)
local durationOverlayFrame = CreateFrame("Frame", nil, frame)
durationOverlayFrame:SetFrameLevel(durationOverlayFrame:GetFrameLevel() + 1)
local durationText = durationOverlayFrame:CreateFontString(nil, "ARTWORK", "GameFontNormal")
durationText:SetPoint("BOTTOMLEFT", durationOverlayFrame, "BOTTOMLEFT", 0, 0)
durationText.SetSeconds = function(self, seconds)
self.seconds = seconds
if seconds == nil then
self:SetText("")
return
end
self:SetText(seconds <= 60 and seconds or math.ceil(seconds / 60).."m")
self:SetFont("Fonts\\FRIZQT__.TTF", math.ceil(frame:GetHeight() *
(seconds < 540 and (seconds < 10 and 0.6 or 0.45) or 0.35)), "OUTLINE")
end
duration.UpdateText = function()
local seconds = duration.seconds
local secondsPrecise = duration.secondsPrecise
durationText:SetSeconds(seconds)
if seconds <= AURA_DURATION_TEXT_FLASH_THRESHOLD then
durationText:SetTextColor(
util.InterpolateColorsNoTable(durationTextFlashColorsRange[seconds],
secondsPrecise - seconds))
elseif seconds <= AURA_DURATION_TEXT_LOW_THRESHOLD then
durationText:SetTextColor(1, 1, 0.25)
else
durationText:SetTextColor(1, 1, 1)
end
duration:SetScript("OnUpdate", nil)
end
duration:SetScript("OnUpdateModel", function()
if this.stopping == 0 then
this:SetAlpha(0.8)
local time = GetTime()
local progress = (time - this.start) / this.duration
if progress < 1.0 then
this:SetSequenceTime(0, 1000 - (progress * 1000))
local secondsPrecise = this.start - time + this.duration
local seconds = math.floor(secondsPrecise)
if seconds <= (this.displayAt and this.displayAt or AURA_DURATION_TEXT_FLASH_THRESHOLD) then
if durationText.seconds ~= seconds or seconds <= AURA_DURATION_TEXT_FLASH_THRESHOLD then
-- You don't want to know why it's gotta be done like this..
-- (If you're insane and you do, it's because otherwise the text will disappear for one frame otherwise)
duration.seconds = seconds
duration.secondsPrecise = secondsPrecise
duration:SetScript("OnUpdate", duration.UpdateText)
end
elseif durationText.seconds ~= nil then
durationText:SetSeconds(nil)
end
return
end
durationText:SetSeconds(nil)
this:SetSequenceTime(0, 0)
end
end)
return {["frame"] = frame, ["icon"] = icon, ["stackText"] = stackText, ["overlay"] = durationOverlayFrame,
["durationText"] = durationText, ["duration"] = duration, ["durationEnabled"] = true}
end
return {["frame"] = frame, ["icon"] = icon, ["stackText"] = stackText}
end
-- Get an icon from the available pool. Automatically inserts into the used pool.
function HMUnitFrame:GetUnusedAura()
local aura
if table.getn(self.auraIconPool) > 0 then
aura = table.remove(self.auraIconPool, table.getn(self.auraIconPool))
else
aura = self:AllocateAura()
end
aura.frame:SetAlpha(aura.frame:GetParent():GetAlpha())
table.insert(self.auraIcons, aura)
return aura
end
function HMUnitFrame:ReleaseAuras()
if table.getn(self.auraIcons) == 0 then
return
end
-- Release all icons back to the icon pool
for _, aura in ipairs(self.auraIcons) do
local frame = aura.frame
frame:Hide()
frame:ClearAllPoints()
local icon = aura.icon
icon:ClearAllPoints()
local stackText = aura.stackText
stackText:ClearAllPoints()
stackText:SetText("")
if aura.durationEnabled then
aura.durationText:SetSeconds(nil)
CooldownFrame_SetTimer(aura.duration, 0, 0, 0)
end
table.insert(self.auraIconPool, aura)
end
self.auraIcons = compost:Erase(self.auraIcons)
end
do
local trackedBuffs = HealersMateSettings.TrackedBuffs
function HMUnitFrame.BuffSorter(a, b)
return trackedBuffs[a.name] < trackedBuffs[b.name]
end
end
do
local trackedDebuffs = HealersMateSettings.TrackedDebuffs
function HMUnitFrame.DebuffSorter(a, b)
return trackedDebuffs[a.name] < trackedDebuffs[b.name]
end
end
function HMUnitFrame:UpdateAuras()
local profile = self:GetProfile()
local unit = self.unit
local enemy = self:IsEnemy()
self:ReleaseAuras()
local cache = self:GetCache()
local trackedBuffs = HealersMateSettings.TrackedBuffs
local buffs = compost:GetTable() -- Buffs that are tracked because of matching name
for name, array in pairs(cache.BuffsMap) do
if trackedBuffs[name] or enemy then
util.AppendArrayElements(buffs, array)
end
end
if not enemy then
table.sort(buffs, self.BuffSorter)
end
local trackedDebuffs = HealersMateSettings.TrackedDebuffs
local trackedDebuffTypes = HealersMateSettings.TrackedDebuffTypesSet
local debuffs = compost:GetTable() -- Debuffs that are tracked because of matching name, later combined with typed debuffs
local typedDebuffs = compost:GetTable() -- Debuffs that are tracked because it's a tracked type (like "Magic" or "Disease")
for name, array in pairs(cache.DebuffsMap) do
if trackedDebuffs[name] or enemy then
util.AppendArrayElements(debuffs, array)
else
-- Check if debuff is a tracked type
for _, debuff in ipairs(array) do
if trackedDebuffTypes[debuff.type] then
table.insert(typedDebuffs, debuff)
end
end
end
end
if not enemy then
table.sort(debuffs, self.DebuffSorter)
util.AppendArrayElements(debuffs, typedDebuffs)
end
local auraTrackerProps = profile.AuraTracker
local width = auraTrackerProps.Width == "Anchor" and auraTrackerProps:GetAnchorComponent(self):GetWidth() or auraTrackerProps.Width
local auraSize = auraTrackerProps.Height
local origSize = auraSize
local spacing = profile.TrackedAurasSpacing
local origSpacing = spacing
local auraCount = table.getn(buffs) + table.getn(debuffs)
-- If there's not enough space, shrink until all auras fit
while ((auraSize * auraCount) + (spacing * (auraCount - 1)) > width) and auraSize >= 1 do
auraSize = auraSize - 1
spacing = (auraSize / origSize) * origSpacing
end
local xOffset = 0
local yOffset = profile.TrackedAurasAlignment == "TOP" and 0 or origSize - auraSize
for _, buff in ipairs(buffs) do
local aura = self:GetUnusedAura()
self:CreateAura(aura, buff.name, buff.index, buff.texture, buff.stacks, xOffset, -yOffset, "Buff", auraSize)
xOffset = xOffset + auraSize + spacing
end
xOffset = 0
for _, debuff in ipairs(debuffs) do
local aura = self:GetUnusedAura()
self:CreateAura(aura, debuff.name, debuff.index, debuff.texture, debuff.stacks, xOffset, -yOffset, "Debuff", auraSize)
xOffset = xOffset - auraSize - spacing
end
compost:Reclaim(buffs)
compost:Reclaim(debuffs)
compost:Reclaim(typedDebuffs)
-- Prevent lingering tooltips when the icon is removed or is changed to a different aura
if not HM.GameTooltip.OwningFrame or not HM.GameTooltip.OwningFrame:IsShown() or
HM.GameTooltip.IconTexture ~= HM.GameTooltip.OwningIcon:GetTexture() then
HM.GameTooltip:Hide()
end
end
function HMUnitFrame.Aura_OnEnter()
local self = this.unitFrame
local aura = this.aura
local index = this.auraIndex
local type = this.auraType