-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClassicHealPrediction.lua
2025 lines (1634 loc) · 72 KB
/
ClassicHealPrediction.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
local ADDON_NAME = ...
local ADDON_VERSION = string.match(GetAddOnMetadata(ADDON_NAME, "Version"), "^v(%d+%.%d+%.%d+)$")
local HealComm = LibStub("LibHealComm-4.0")
local HealComm_OVERTIME_HEALS = bit.bor(HealComm.HOT_HEALS, HealComm.CHANNEL_HEALS)
local assert = assert
local bit = bit
local format = format
local min = min
local max = max
local pairs = pairs
local ipairs = ipairs
local select = select
local wipe = wipe
local tinsert = tinsert
local unpack = unpack
local next = next
local GetTime = GetTime
local CreateColor = CreateColor
local UnitGUID = UnitGUID
local UnitCanAssist = UnitCanAssist
local CastingInfo = CastingInfo
local GetSpellPowerCost = GetSpellPowerCost
local GetSpellInfo = GetSpellInfo
local InCombatLockdown = InCombatLockdown
local PlayerFrame = PlayerFrame
local PetFrame = PetFrame
local TargetFrame = TargetFrame
local TargetFrameToT = TargetFrameToT
local FocusFrame = FocusFrame
local PartyMemberFrame = {}
local PartyMemberFramePetFrame = {}
for i = 1, MAX_PARTY_MEMBERS do
PartyMemberFrame[i] = _G["PartyMemberFrame" .. i]
PartyMemberFramePetFrame[i] = _G["PartyMemberFrame" .. i .. "PetFrame"]
end
local function toggleValue(value, bool)
if bool == true then
value = max(value, -(value + 1))
elseif bool == false then
value = min(value, -(value + 1))
elseif bool == nil then
value = -(value + 1)
end
return value
end
local colorCache = {}
local function getColor(r, g, b, a)
a = a or 1
colorCache[r] = colorCache[r] or {}
colorCache[r][g] = colorCache[r][g] or {}
colorCache[r][g][b] = colorCache[r][g][b] or {}
colorCache[r][g][b][a] = colorCache[r][g][b][a] or CreateColor(r, g, b, a)
return colorCache[r][g][b][a]
end
local function rgbToHsl(r, g, b, a)
local max, min = max(r, g, b), min(r, g, b)
local h, s, l
l = (max + min) / 2
if max == min then
h, s = 0, 0
else
local d = max - min
if l > 0.5 then
s = d / (2 - max - min)
else
s = d / (max + min)
end
if max == r then
h = (g - b) / d
if g < b then
h = h + 6
end
elseif max == g then
h = (b - r) / d + 2
elseif max == b then
h = (r - g) / d + 4
end
h = h / 6
end
return h, s, l, a or 1
end
local function hslToRgb(h, s, l, a)
local r, g, b
if s == 0 then
r, g, b = l, l, l
else
local function f(p, q, t)
if t < 0 then
t = t + 1
elseif t > 1 then
t = t - 1
end
if t < 1 / 6 then
return p + (q - p) * 6 * t
end
if t < 1 / 2 then
return q
end
if t < 2 / 3 then
return p + (q - p) * (2 / 3 - t) * 6
end
return p
end
local q
if l < 0.5 then
q = l * (1 + s)
else
q = l + s - l * s
end
local p = 2 * l - q
r = f(p, q, h + 1 / 3)
g = f(p, q, h)
b = f(p, q, h - 1 / 3)
end
return r, g, b, a or 1
end
local function dimColor(x, r, g, b, a)
local h, s, l = rgbToHsl(r, g, b, a)
return hslToRgb(h, s, x * l, a)
end
local function gradient(r, g, b, a)
return r, g, b, a, dimColor(0.667, r, g, b, a)
end
local function complementaryColor(r, g, b, a)
local h, s, l = rgbToHsl(r, g, b, a)
if h < 0.333 then
h = h * 1.5
else
h = (h - 0.333) * 0.5 + 0.5
end
h = (h + 0.5) % 1
if h < 0.5 then
h = h * 0.667
else
h = (h - 0.5) * 1.333 + 0.333
end
return hslToRgb(h % 1, s, l, a)
end
local function tappend(tbl, ...)
for i = 1, select("#", ...) do
local x = select(i, ...)
tinsert(tbl, x)
end
return tbl
end
local ClassicHealPrediction = {}
_G.ClassicHealPrediction = ClassicHealPrediction
local ClassicHealPredictionDefaultSettings = {
myFilter = toggleValue(HealComm.ALL_HEALS, true),
otherFilter = toggleValue(HealComm.ALL_HEALS, true),
myDelta = toggleValue(3, false),
otherDelta = toggleValue(3, false),
overhealThreshold = toggleValue(0.2, false),
overlaying = false,
colors = {
{gradient(0.043, 0.533, 0.412, 1.0)},
{gradient(0.043, 0.533, 0.412, 0.5)},
{gradient(complementaryColor(0.043, 0.533, 0.412, 1.0))},
{gradient(complementaryColor(0.043, 0.533, 0.412, 0.5))},
{gradient(0.082, 0.349, 0.282, 1.0)},
{gradient(0.082, 0.349, 0.282, 0.5)},
{gradient(complementaryColor(0.082, 0.349, 0.282, 1.0))},
{gradient(complementaryColor(0.082, 0.349, 0.282, 0.5))},
{gradient(0.0, 0.827, 0.765, 1.0)},
{gradient(0.0, 0.827, 0.765, 0.5)},
{gradient(complementaryColor(0.0, 0.827, 0.765, 1.0))},
{gradient(complementaryColor(0.0, 0.827, 0.765, 0.5))},
{gradient(0.0, 0.631, 0.557, 1.0)},
{gradient(0.0, 0.631, 0.557, 0.5)},
{gradient(complementaryColor(0.0, 0.631, 0.557, 1.0))},
{gradient(complementaryColor(0.0, 0.631, 0.557, 0.5))},
{gradient(0.0, 0.447, 1.0, 1.0)}
},
showManaCostPrediction = true,
raidFramesMaxOverflow = toggleValue(0.05, true),
unitFramesMaxOverflow = toggleValue(0.0, true)
}
local ClassicHealPredictionSettings = ClassicHealPredictionDefaultSettings
local function getOtherEndTime()
local delta = ClassicHealPredictionSettings.otherDelta
if delta >= 0 then
return GetTime() + delta
end
return nil
end
local function getChild(frame, ...)
for i = 1, select("#", ...) do
frame = select(select(i, ...), frame:GetChildren())
end
return frame
end
local function getTexture(frame, name)
while not frame:GetName() do
frame = frame:GetParent()
end
name = name and string.gsub(name, "%$parent", frame:GetName())
return name and _G[name]
end
local function createTexture(frame, name, layer, subLayer)
return getTexture(frame, name) or frame:CreateTexture(name, layer, nil, subLayer)
end
local function deepcopy(orig)
local orig_type = type(orig)
local copy
if orig_type == "table" then
copy = {}
for orig_key, orig_value in next, orig, nil do
copy[deepcopy(orig_key)] = deepcopy(orig_value)
end
setmetatable(copy, deepcopy(getmetatable(orig)))
else
copy = orig
end
return copy
end
local function deepmerge(tbl1, tbl2)
for k, v in pairs(tbl2) do
if tbl1[k] == nil then
if type(v) == "table" then
tbl1[k] = {}
deepmerge(tbl1[k], v)
else
tbl1[k] = v
end
end
end
end
local weaktable = {__mode = "k"}
local healthBar = setmetatable({}, weaktable)
local myHealPrediction = setmetatable({}, weaktable)
local myHealPrediction2 = setmetatable({}, weaktable)
local otherHealPrediction = setmetatable({}, weaktable)
local otherHealPrediction2 = setmetatable({}, weaktable)
local healAbsorb = setmetatable({}, weaktable)
local overHealAbsorbGlow = setmetatable({}, weaktable)
local overAbsorbGlow = setmetatable({}, weaktable)
local healAbsorbRightShadow = setmetatable({}, weaktable)
local healAbsorbLeftShadow = setmetatable({}, weaktable)
local totalAbsorb = setmetatable({}, weaktable)
local totalAbsorbOverlay = setmetatable({}, weaktable)
local setGradient = setmetatable({}, weaktable)
local proxyFrame = setmetatable({}, weaktable)
local currUnitGUID = setmetatable({}, weaktable)
local tickIntervals
local guidToUnitFrame = {}
local guidToCompactUnitFrame = {}
local guidToNameplateFrame = {}
local lastFrameTime = -1
local deferredUnitFrames = {}
local deferredCompactUnitFrames = {}
local loadedSettings = false
local loadedFrame = false
local checkBoxes
local checkBox2
local checkBox3
local slider
local slider2
local slider3
local slider4
local sliderCheckBox
local sliderCheckBox2
local sliderCheckBox3
local sliderCheckBox4
local colorSwatches = {}
local function getIncomingHeals(unit)
if not unit or not UnitCanAssist("player", unit) then
return 0, 0, 0, 0
end
local dstGUID = UnitGUID(unit)
local dstBitFlag = ClassicHealPredictionSettings.otherFilter
local dstTime = getOtherEndTime()
local srcGUID = UnitGUID("player")
local srcBitFlag = HealComm.ALL_HEALS
local srcTime = nil
local modifier = HealComm:GetHealModifier(dstGUID) or 1.0
local dstAmount1, dstAmount2, srcAmount1, srcAmount2 = HealComm:GetHealAmountEx(dstGUID, dstBitFlag, dstTime, srcGUID, srcBitFlag, srcTime)
return (srcAmount1 or 0) * modifier, (srcAmount2 or 0) * modifier, (dstAmount1 or 0) * modifier, (dstAmount2 or 0) * modifier
end
local function updateHealPrediction(frame, unit, cutoff, gradient, colorPalette, colorPalette2, updateFillBar)
if not myHealPrediction[frame] then
return
end
local _, maxHealth = healthBar[frame]:GetMinMaxValues()
local health = healthBar[frame]:GetValue()
local myIncomingHeal1, myIncomingHeal2, otherIncomingHeal1, otherIncomingHeal2 = getIncomingHeals(unit)
local currentTotalAbsorb = 0
local currentHealAbsorb = 0
local healAbsorb = healAbsorb[frame]
if healAbsorb then
currentHealAbsorb = 0
if health < currentHealAbsorb then
overHealAbsorbGlow[frame]:Show()
currentHealAbsorb = health
else
overHealAbsorbGlow[frame]:Hide()
end
end
local overhealing = maxHealth <= 0 and 0 or max((health - currentHealAbsorb + myIncomingHeal1 + otherIncomingHeal1) / maxHealth - 1, 0)
do
local overhealThreshold = ClassicHealPredictionSettings.overhealThreshold
if overhealThreshold >= 0 and overhealing > overhealThreshold then
colorPalette = colorPalette2
end
end
local colors = ClassicHealPredictionSettings.colors
local myHealPrediction1 = myHealPrediction[frame]
local myHealPrediction2 = myHealPrediction2[frame]
local otherHealPrediction1 = otherHealPrediction[frame]
local otherHealPrediction2 = otherHealPrediction2[frame]
if gradient then
local r, g, b, a, r2, g2, b2
r, g, b, a, r2, g2, b2 = unpack(colors[colorPalette[1]])
if a == 0 then
myIncomingHeal1 = 0
else
myHealPrediction1:SetGradient("VERTICAL", getColor(r2, g2, b2, a), getColor(r, g, b, a))
end
r, g, b, a, r2, g2, b2 = unpack(colors[colorPalette[2]])
if a == 0 then
myIncomingHeal2 = 0
else
myHealPrediction2:SetGradient("VERTICAL", getColor(r2, g2, b2, a), getColor(r, g, b, a))
end
r, g, b, a, r2, g2, b2 = unpack(colors[colorPalette[3]])
if a == 0 then
otherIncomingHeal1 = 0
else
otherHealPrediction1:SetGradient("VERTICAL", getColor(r2, g2, b2, a), getColor(r, g, b, a))
end
r, g, b, a, r2, g2, b2 = unpack(colors[colorPalette[4]])
if a == 0 then
otherIncomingHeal2 = 0
else
otherHealPrediction2:SetGradient("VERTICAL", getColor(r2, g2, b2, a), getColor(r, g, b, a))
end
else
local r, g, b, a
r, g, b, a = unpack(colors[colorPalette[1]])
if a == 0 then
myIncomingHeal1 = 0
else
myHealPrediction1:SetVertexColor(r, g, b, a)
end
r, g, b, a = unpack(colors[colorPalette[2]])
if a == 0 then
myIncomingHeal2 = 0
else
myHealPrediction2:SetVertexColor(r, g, b, a)
end
r, g, b, a = unpack(colors[colorPalette[3]])
if a == 0 then
otherIncomingHeal1 = 0
else
otherHealPrediction1:SetVertexColor(r, g, b, a)
end
r, g, b, a = unpack(colors[colorPalette[4]])
if a == 0 then
otherIncomingHeal2 = 0
else
otherHealPrediction2:SetVertexColor(r, g, b, a)
end
end
local incomingHeal1
local incomingHeal2
if ClassicHealPredictionSettings.overlaying then
incomingHeal1 = max(myIncomingHeal1, otherIncomingHeal1)
incomingHeal2 = max(myIncomingHeal2, otherIncomingHeal2)
else
incomingHeal1 = myIncomingHeal1 + otherIncomingHeal1
incomingHeal2 = myIncomingHeal2 + otherIncomingHeal2
end
local allIncomingHeal = incomingHeal1 + incomingHeal2
if cutoff then
allIncomingHeal = min(allIncomingHeal, maxHealth * cutoff - health + currentHealAbsorb)
end
incomingHeal1 = min(incomingHeal1, allIncomingHeal)
incomingHeal2 = allIncomingHeal - incomingHeal1
myIncomingHeal1 = min(myIncomingHeal1, incomingHeal1)
myIncomingHeal2 = min(myIncomingHeal2, incomingHeal2)
otherIncomingHeal1 = incomingHeal1 - myIncomingHeal1
otherIncomingHeal2 = incomingHeal2 - myIncomingHeal2
local overAbsorb = false
if health - currentHealAbsorb + allIncomingHeal + currentTotalAbsorb >= maxHealth or health + currentTotalAbsorb >= maxHealth then
if currentTotalAbsorb > 0 then
overAbsorb = true
end
if allIncomingHeal > currentHealAbsorb then
currentTotalAbsorb = max(0, maxHealth - (health - currentHealAbsorb + allIncomingHeal))
else
currentTotalAbsorb = max(0, maxHealth - health)
end
end
if overAbsorb then
overAbsorbGlow[frame]:Show()
else
overAbsorbGlow[frame]:Hide()
end
local healthTexture = healthBar[frame]:GetStatusBarTexture()
local currentHealAbsorbPercent = 0
local healAbsorbTexture
if healAbsorb then
currentHealAbsorbPercent = maxHealth <= 0 and 0 or currentHealAbsorb / maxHealth
local healAbsorbLeftShadow = healAbsorbLeftShadow[frame]
local healAbsorbRightShadow = healAbsorbRightShadow[frame]
if currentHealAbsorb > allIncomingHeal then
local shownHealAbsorb = currentHealAbsorb - allIncomingHeal
local shownHealAbsorbPercent = maxHealth <= 0 and 0 or shownHealAbsorb / maxHealth
healAbsorbTexture = updateFillBar(frame, healthTexture, healAbsorb, shownHealAbsorb, -shownHealAbsorbPercent)
if allIncomingHeal > 0 then
healAbsorbLeftShadow:Hide()
else
healAbsorbLeftShadow:SetPoint("TOPLEFT", healAbsorbTexture, "TOPLEFT", 0, 0)
healAbsorbLeftShadow:SetPoint("BOTTOMLEFT", healAbsorbTexture, "BOTTOMLEFT", 0, 0)
healAbsorbLeftShadow:Show()
end
if currentTotalAbsorb > 0 then
healAbsorbRightShadow:SetPoint("TOPLEFT", healAbsorbTexture, "TOPRIGHT", -8, 0)
healAbsorbRightShadow:SetPoint("BOTTOMLEFT", healAbsorbTexture, "BOTTOMRIGHT", -8, 0)
healAbsorbRightShadow:Show()
else
healAbsorbRightShadow:Hide()
end
else
healAbsorb:Hide()
healAbsorbLeftShadow:Hide()
healAbsorbRightShadow:Hide()
end
end
local incomingHealsTexture = updateFillBar(frame, healthTexture, myHealPrediction1, myIncomingHeal1, -currentHealAbsorbPercent)
incomingHealsTexture = updateFillBar(frame, incomingHealsTexture, otherHealPrediction1, otherIncomingHeal1)
incomingHealsTexture = updateFillBar(frame, incomingHealsTexture, myHealPrediction2, myIncomingHeal2)
incomingHealsTexture = updateFillBar(frame, incomingHealsTexture, otherHealPrediction2, otherIncomingHeal2)
local appendTexture = healAbsorbTexture or incomingHealsTexture
updateFillBar(frame, appendTexture, totalAbsorb[frame], currentTotalAbsorb)
end
local CompactUnitFrame_UpdateHealPrediction
local UnitFrameHealPredictionBars_Update
do
local compactUnitFrameColorPalette = {1, 2, 5, 6}
local compactUnitFrameColorPalette2 = {3, 4, 7, 8}
local unitFrameColorPalette = {9, 10, 13, 14}
local unitFrameColorPalette2 = {11, 12, 15, 16}
function CompactUnitFrame_UpdateHealPrediction(frame)
local cutoff
local maxOverflow = ClassicHealPredictionSettings.raidFramesMaxOverflow
if maxOverflow >= 0 then
cutoff = 1.0 + maxOverflow
end
updateHealPrediction(frame, frame.displayedUnit, cutoff, setGradient[frame], compactUnitFrameColorPalette, compactUnitFrameColorPalette2, CompactUnitFrameUtil_UpdateFillBar)
end
function UnitFrameHealPredictionBars_Update(frame)
local cutoff
local maxOverflow = ClassicHealPredictionSettings.unitFramesMaxOverflow
if maxOverflow >= 0 then
cutoff = 1.0 + maxOverflow
end
updateHealPrediction(frame, frame.unit, cutoff, false, unitFrameColorPalette, unitFrameColorPalette2, UnitFrameUtil_UpdateFillBar)
end
end
local function defer_CompactUnitFrame_UpdateHealPrediction(frame)
if GetTime() > lastFrameTime then
deferredCompactUnitFrames[frame] = true
else
CompactUnitFrame_UpdateHealPrediction(frame)
end
end
local function defer_UnitFrameHealPredictionBars_Update(frame)
if GetTime() > lastFrameTime then
deferredUnitFrames[frame] = true
else
UnitFrameHealPredictionBars_Update(frame)
end
end
local function unitFrameManaCostPredictionBars_Update(frame, isStarting, startTime, endTime, spellID)
if frame.unit ~= "player" or not frame.manabar or not frame.myManaCostPredictionBar then
return
end
if not ClassicHealPredictionSettings.showManaCostPrediction then
frame.myManaCostPredictionBar:Hide()
return
end
local cost = 0
if not isStarting or startTime == endTime then
local currentSpellID = select(9, CastingInfo())
if currentSpellID and frame.predictedPowerCost then
cost = frame.predictedPowerCost
else
frame.predictedPowerCost = nil
end
else
local costTable = GetSpellPowerCost(spellID)
for _, costInfo in pairs(costTable) do
if costInfo.type == frame.manabar.powerType then
cost = costInfo.cost
break
end
end
frame.predictedPowerCost = cost
end
local manaBarTexture = frame.manabar:GetStatusBarTexture()
local r, g, b, a = unpack(ClassicHealPredictionSettings.colors[17])
frame.myManaCostPredictionBar:SetVertexColor(r, g, b, a)
UnitFrameManaBar_Update(frame.manabar, "player")
UnitFrameUtil_UpdateManaFillBar(frame, manaBarTexture, frame.myManaCostPredictionBar, cost)
end
local function UnitFrameHealPredictionBars_UpdateSize(self)
if not myHealPrediction[self] or not otherHealPrediction[self] then
return
end
defer_UnitFrameHealPredictionBars_Update(self)
end
hooksecurefunc(
"CompactUnitFrame_UpdateUnitEvents",
function(frame)
if not frame:IsForbidden() then
frame:UnregisterEvent("UNIT_HEALTH")
end
end
)
hooksecurefunc(
"CompactUnitFrame_OnEvent",
function(self, event, ...)
if event == self.updateAllEvent and (not self.updateAllFilter or self.updateAllFilter(self, event, ...)) then
return
end
local unit = ...
if unit == self.unit or unit == self.displayedUnit then
if event == "UNIT_HEALTH_FREQUENT" or event == "UNIT_HEALTH" or event == "UNIT_MAXHEALTH" then
defer_CompactUnitFrame_UpdateHealPrediction(self)
end
end
end
)
local function compactUnitFrame_UpdateAll(frame)
local unit = frame.displayedUnit
do
local unitGUID = currUnitGUID[frame]
local newUnitGUID = unit and UnitGUID(unit)
if newUnitGUID ~= unitGUID then
if unitGUID then
guidToCompactUnitFrame[unitGUID][frame] = nil
if next(guidToCompactUnitFrame[unitGUID]) == nil then
guidToCompactUnitFrame[unitGUID] = nil
end
end
if newUnitGUID then
guidToCompactUnitFrame[newUnitGUID] = guidToCompactUnitFrame[newUnitGUID] or {}
guidToCompactUnitFrame[newUnitGUID][frame] = true
end
currUnitGUID[frame] = newUnitGUID
end
end
defer_CompactUnitFrame_UpdateHealPrediction(frame)
end
hooksecurefunc("CompactUnitFrame_UpdateAll", compactUnitFrame_UpdateAll)
hooksecurefunc("CompactUnitFrame_UpdateHealth", defer_CompactUnitFrame_UpdateHealPrediction)
hooksecurefunc("CompactUnitFrame_UpdateMaxHealth", defer_CompactUnitFrame_UpdateHealPrediction)
local function unitFrame_Update(self)
do
local unit = self.unit
local unitGUID = currUnitGUID[self]
local newUnitGUID = unit and UnitGUID(unit)
if newUnitGUID ~= unitGUID then
if unitGUID then
guidToUnitFrame[unitGUID][self] = nil
if next(guidToUnitFrame[unitGUID]) == nil then
guidToUnitFrame[unitGUID] = nil
end
end
if newUnitGUID then
guidToUnitFrame[newUnitGUID] = guidToUnitFrame[newUnitGUID] or {}
guidToUnitFrame[newUnitGUID][self] = true
end
currUnitGUID[self] = newUnitGUID
end
end
defer_UnitFrameHealPredictionBars_Update(self)
unitFrameManaCostPredictionBars_Update(self)
end
hooksecurefunc("UnitFrame_SetUnit", unitFrame_Update)
hooksecurefunc("UnitFrame_Update", unitFrame_Update)
local function unitFrame_OnEvent(self, event, unit)
if unit == self.unit then
if event == "UNIT_MAXHEALTH" then
defer_UnitFrameHealPredictionBars_Update(self)
elseif event == "UNIT_SPELLCAST_START" or event == "UNIT_SPELLCAST_STOP" or event == "UNIT_SPELLCAST_FAILED" or event == "UNIT_SPELLCAST_SUCCEEDED" then
assert(unit == "player")
local name, text, texture, startTime, endTime, isTradeSkill, castID, notInterruptible, spellID = CastingInfo()
unitFrameManaCostPredictionBars_Update(self, event == "UNIT_SPELLCAST_START", startTime, endTime, spellID)
end
end
end
hooksecurefunc("UnitFrame_OnEvent", unitFrame_OnEvent)
hooksecurefunc(
"UnitFrameHealthBar_OnUpdate",
function(self)
if not self.disconnected and not self.lockValues then
if not self.ignoreNoUnit or UnitGUID(self.unit) then
defer_UnitFrameHealPredictionBars_Update(self:GetParent())
end
end
end
)
hooksecurefunc(
"UnitFrameHealthBar_Update",
function(statusbar, unit)
if not statusbar or statusbar.lockValues then
return
end
defer_UnitFrameHealPredictionBars_Update(statusbar:GetParent())
end
)
local function UpdateHealPrediction(...)
for j = 1, select("#", ...) do
local unitGUID = select(j, ...)
do
local unitFrames = guidToUnitFrame[unitGUID]
if unitFrames then
for unitFrame in pairs(unitFrames) do
defer_UnitFrameHealPredictionBars_Update(unitFrame)
end
end
end
do
local compactUnitFrames = guidToCompactUnitFrame[unitGUID]
if compactUnitFrames then
for compactUnitFrame in pairs(compactUnitFrames) do
defer_CompactUnitFrame_UpdateHealPrediction(compactUnitFrame)
end
end
end
do
local namePlateFrame = guidToNameplateFrame[unitGUID]
if namePlateFrame then
defer_CompactUnitFrame_UpdateHealPrediction(namePlateFrame)
end
end
end
end
local function updateAllFrames()
do
local allUnitFrames = {}
for _, unitFrames in pairs(guidToUnitFrame) do
if unitFrames then
for unitFrame in pairs(unitFrames) do
allUnitFrames[unitFrame] = true
end
end
end
for unitFrame in pairs(allUnitFrames) do
local isParty = unitFrame:GetID() ~= 0
unitFrame_Update(unitFrame, isParty)
end
end
do
local allCompactUnitFrames = {}
for _, compactUnitFrames in pairs(guidToCompactUnitFrame) do
if compactUnitFrames then
for compactUnitFrame in pairs(compactUnitFrames) do
allCompactUnitFrames[compactUnitFrame] = true
end
end
end
for compactUnitFrame in pairs(allCompactUnitFrames) do
compactUnitFrame_UpdateAll(compactUnitFrame)
end
end
do
local allNameplateFrames = {}
for _, namePlateFrame in pairs(guidToNameplateFrame) do
allNameplateFrames[namePlateFrame] = namePlateFrame
end
for namePlateFrame in pairs(allNameplateFrames) do
compactUnitFrame_UpdateAll(namePlateFrame)
end
end
end
local function ClassicHealPrediction_OnEvent(event, arg1)
if event == "GROUP_ROSTER_UPDATE" then
if InCombatLockdown() then
for _, compactUnitFrames in pairs(guidToCompactUnitFrame) do
if compactUnitFrames then
for compactUnitFrame in pairs(compactUnitFrames) do
defer_CompactUnitFrame_UpdateHealPrediction(compactUnitFrame)
end
end
end
end
else
local namePlateUnitToken = arg1
if not UnitCanAssist("player", namePlateUnitToken) then
return
end
local unitGUID = UnitGUID(namePlateUnitToken)
if event == "NAME_PLATE_UNIT_ADDED" then
local namePlate = C_NamePlate.GetNamePlateForUnit(namePlateUnitToken)
local namePlateFrame = namePlate and namePlate.UnitFrame
guidToNameplateFrame[unitGUID] = namePlateFrame
if namePlateFrame then
defer_CompactUnitFrame_UpdateHealPrediction(namePlateFrame)
end
elseif event == "NAME_PLATE_UNIT_REMOVED" then
guidToNameplateFrame[unitGUID] = nil
end
end
end
local function ClassicHealPrediction_OnUpdate()
for unitFrame in pairs(deferredUnitFrames) do
UnitFrameHealPredictionBars_Update(unitFrame)
end
for compactUnitFrame in pairs(deferredCompactUnitFrames) do
CompactUnitFrame_UpdateHealPrediction(compactUnitFrame)
end
wipe(deferredUnitFrames)
wipe(deferredCompactUnitFrames)
lastFrameTime = GetTime()
end
do
local function defaultCompactUnitFrameSetup(frame)
if frame:IsForbidden() or myHealPrediction[frame] then
return
end
setGradient[frame] = true
healthBar[frame] = frame.healthBar
myHealPrediction[frame] = createTexture(frame, "$parentMyHealPrediction", "BORDER", 5)
myHealPrediction[frame]:ClearAllPoints()
myHealPrediction[frame]:SetColorTexture(1, 1, 1)
myHealPrediction2[frame] = createTexture(frame, "$parentMyHealPrediction2", "BORDER", 5)
myHealPrediction2[frame]:ClearAllPoints()
myHealPrediction2[frame]:SetColorTexture(1, 1, 1)
otherHealPrediction[frame] = createTexture(frame, "$parentOtherHealPrediction", "BORDER", 5)
otherHealPrediction[frame]:ClearAllPoints()
otherHealPrediction[frame]:SetColorTexture(1, 1, 1)
otherHealPrediction2[frame] = createTexture(frame, "$parentOtherHealPrediction2", "BORDER", 5)
otherHealPrediction2[frame]:ClearAllPoints()
otherHealPrediction2[frame]:SetColorTexture(1, 1, 1)
totalAbsorb[frame] = createTexture(frame, "$parentTotalAbsorb", "BORDER", 5)
totalAbsorb[frame]:ClearAllPoints()
totalAbsorb[frame]:SetTexture("Interface\\RaidFrame\\Shield-Fill")
totalAbsorbOverlay[frame] = createTexture(frame, "$parentTotalAbsorbOverlay", "BORDER", 6)
totalAbsorb[frame].overlay = totalAbsorbOverlay[frame]
totalAbsorbOverlay[frame]:SetTexture("Interface\\RaidFrame\\Shield-Overlay", true, true)
totalAbsorbOverlay[frame]:SetAllPoints(totalAbsorb[frame])
totalAbsorbOverlay[frame].tileSize = 32
healAbsorb[frame] = createTexture(frame, "$parentMyHealAbsorb", "ARTWORK", 1)
healAbsorb[frame]:ClearAllPoints()
healAbsorb[frame]:SetTexture("Interface\\RaidFrame\\Absorb-Fill", true, true)
healAbsorbLeftShadow[frame] = createTexture(frame, "$parentMyHealAbsorbLeftShadow", "ARTWORK", 1)
healAbsorbLeftShadow[frame]:ClearAllPoints()
healAbsorbLeftShadow[frame]:SetTexture("Interface\\RaidFrame\\Absorb-Edge")
healAbsorbRightShadow[frame] = createTexture(frame, "$parentMyHealAbsorbRightShadow", "ARTWORK", 1)
healAbsorbRightShadow[frame]:ClearAllPoints()
healAbsorbRightShadow[frame]:SetTexture("Interface\\RaidFrame\\Absorb-Edge")
healAbsorbRightShadow[frame]:SetTexCoord(1, 0, 0, 1)
overAbsorbGlow[frame] = createTexture(frame, "$parentOverAbsorbGlow", "ARTWORK", 2)
overAbsorbGlow[frame]:ClearAllPoints()
overAbsorbGlow[frame]:SetTexture("Interface\\RaidFrame\\Shield-Overshield")
overAbsorbGlow[frame]:SetBlendMode("ADD")
overAbsorbGlow[frame]:SetPoint("BOTTOMLEFT", healthBar[frame], "BOTTOMRIGHT", -7, 0)
overAbsorbGlow[frame]:SetPoint("TOPLEFT", healthBar[frame], "TOPRIGHT", -7, 0)
overAbsorbGlow[frame]:SetWidth(16)
overHealAbsorbGlow[frame] = createTexture(frame, "$parentOverHealAbsorbGlow", "ARTWORK", 2)
overHealAbsorbGlow[frame]:ClearAllPoints()
overHealAbsorbGlow[frame]:SetTexture("Interface\\RaidFrame\\Absorb-Overabsorb")
overHealAbsorbGlow[frame]:SetBlendMode("ADD")
overHealAbsorbGlow[frame]:SetPoint("BOTTOMRIGHT", healthBar[frame], "BOTTOMLEFT", 7, 0)
overHealAbsorbGlow[frame]:SetPoint("TOPRIGHT", healthBar[frame], "TOPLEFT", 7, 0)
overHealAbsorbGlow[frame]:SetWidth(16)
end
hooksecurefunc("DefaultCompactUnitFrameSetup", defaultCompactUnitFrameSetup)
local defaultCompactMiniFrameSetup = defaultCompactUnitFrameSetup
hooksecurefunc("DefaultCompactMiniFrameSetup", defaultCompactMiniFrameSetup)
local compactRaidFrameReservation_GetFrame
hooksecurefunc(
"CompactRaidFrameReservation_GetFrame",
function(self, key)
compactRaidFrameReservation_GetFrame = self.reservations[key]
end
)
local frameCreationSpecifiers = {
raid = {mapping = UnitGUID, setUpFunc = defaultCompactUnitFrameSetup},
pet = {setUpFunc = defaultCompactMiniFrameSetup},
flagged = {mapping = UnitGUID, setUpFunc = defaultCompactUnitFrameSetup},
target = {setUpFunc = defaultCompactMiniFrameSetup}
}
hooksecurefunc(
"CompactRaidFrameContainer_GetUnitFrame",
function(self, unit, frameType)
if not compactRaidFrameReservation_GetFrame then
local info = frameCreationSpecifiers[frameType]
local mapping
if info.mapping then
mapping = info.mapping(unit)
else
mapping = unit
end