forked from LiuJonathan/HealBarsClassic
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHealCommClassic.lua
986 lines (914 loc) · 36.3 KB
/
HealCommClassic.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
--[[
Table of contents, in order:
- *General settings
- RaidPulloutButton_OnLoadHook
- UnitFrameHealthBar_OnValueChangedHook
- UnitFrameHealthBar_OnUpdateHook
- CompactUnitFrame_UpdateHealthHook
- CompactUnitFrame_UpdateMaxHealthHook
- CompactUnitFrame_SetUnitHook
- CompactUnitFrame_UpdateStatusTextHook
- OnInitialize
- CreateBars
- UpdateColors
- UpdateHealthValuesLoop
- UNIT_PET
- PLAYER_TARGET_CHANGED
- PLAYER_ROLES_ASSIGNED
- HealComm_HealUpdated
- HealComm_HealStopped
- HealComm_ModifierChanged
- HealComm_GUIDDisappeared
- UpdateIncoming
- UpdateFrame
- CreateConfigs
- *Event registration
--]]
local libCHC = LibStub("LibHealComm-4.0", true)
HealCommClassic = LibStub("AceAddon-3.0"):NewAddon("HealCommClassic")
--Remember to update version number!!
--Curseforge release starting from 1.1.7
HealCommClassic.version = "1.3.3"
local hpBars = {} --incoming castedHeals
local playerHpBars={} --incoming player casted heals
local nextHpBars={} --next incoming heal
local hotBars={} --incoming HoTs
local healColor,playerHealColor,hotColor
local frames = {
["player"] = { bar = getglobal("PlayerFrameHealthBar"), frame = _G["PlayerFrame"] },
["pet"] = { bar = getglobal("PetFrameHealthBar"), frame = _G["PetFrame"] },
["target"] = { bar = getglobal("TargetFrameHealthBar"), frame = _G["TargetFrame"] },
["party1"] = { bar = getglobal("PartyMemberFrame1HealthBar"), frame = _G["PartyMemberFrame1"] },
["partypet1"] = { bar = getglobal("PartyMemberFrame1PetFrameHealthBar"), frame = _G["PartyMemberFrame1PetFrame"] },
["party2"] = { bar = getglobal("PartyMemberFrame2HealthBar"), frame = _G["PartyMemberFrame2"] },
["partypet2"] = { bar = getglobal("PartyMemberFrame2PetFrameHealthBar"), frame = _G["PartyMemberFrame2PetFrame"] },
["party3"] = { bar = getglobal("PartyMemberFrame3HealthBar"), frame = _G["PartyMemberFrame3"] },
["partypet3"] = { bar = getglobal("PartyMemberFrame3PetFrameHealthBar"), frame = _G["PartyMemberFrame3PetFrame"] },
["party4"] = { bar = getglobal("PartyMemberFrame4HealthBar"), frame = _G["PartyMemberFrame4"] },
["partypet4"] = { bar = getglobal("PartyMemberFrame4PetFrameHealthBar"), frame = _G["PartyMemberFrame4PetFrame"] },
}
local playerGUID = UnitGUID("player")
local partyGUIDs = {
[UnitGUID("player")] = "player",
}
local currentHeals = {}
local currentPlayerHeals = {}
local currentNextHeals = {}
local currentHots ={}
local HCCdefault = {
global = {
overhealPercent = 20,
timeframe = 6,
showHots = true,
seperateHots = true,
seperatePlayer=true,
healColor = {0, 1, 50/255, 1},
hotColor = {120/255, 210/255, 65/255, 0.7},
playerHealColor = {50/255, 50/255, 255/255, 1},
feignIndicator = true,
predictiveHealthLost = false,
fastUpdate = false,
fastUpdateDuration = 0.1, --10 updates per second
}
}
local HCCdb = {}
--[[
Function: RaidPulloutButton_OnLoadHook
Purpose: Creates heal bars for raid members upon joining a raid
Inputs: self
Where self is a unit frame to update
]]--
local function RaidPulloutButton_OnLoadHook(self)
if not hpBars[self] then
hpBars[getglobal(self:GetParent():GetName().."HealthBar")] = CreateFrame("StatusBar", self:GetName().."HealthBarIncHeal" , self)
hpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetFrameStrata("LOW")
hpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetFrameLevel(hpBars[getglobal(self:GetParent():GetName().."HealthBar")]:GetFrameLevel()-1)
hpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
hpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetMinMaxValues(0, 1)
hpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetValue(1)
hpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetStatusBarColor(unpack(HCCdb.global.healColor))
end
if not playerHpBars[self] then
playerHpBars[getglobal(self:GetParent():GetName().."HealthBar")] = CreateFrame("StatusBar", self:GetName().."HealthBarIncPlayerHeal" , self)
playerHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetFrameStrata("LOW")
playerHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetFrameLevel(hpBars[getglobal(self:GetParent():GetName().."HealthBar")]:GetFrameLevel()-1)
playerHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
playerHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetMinMaxValues(0, 1)
playerHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetValue(1)
playerHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetStatusBarColor(unpack(HCCdb.global.playerHealColor))
end
if not nextHpBars[self] then
nextHpBars[getglobal(self:GetParent():GetName().."HealthBar")] = CreateFrame("StatusBar", self:GetName().."HealthBarIncNextHeal" , self)
nextHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetFrameStrata("LOW")
nextHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetFrameLevel(hpBars[getglobal(self:GetParent():GetName().."HealthBar")]:GetFrameLevel()-1)
nextHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
nextHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetMinMaxValues(0, 1)
nextHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetValue(1)
nextHpBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetStatusBarColor(unpack(HCCdb.global.healColor))
end
if not hotBars[self] then
hotBars[getglobal(self:GetParent():GetName().."HealthBar")] = CreateFrame("StatusBar", self:GetName().."HotBarIncHeal" , self)
hotBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetFrameStrata("LOW")
hotBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetFrameLevel(hotBars[getglobal(self:GetParent():GetName().."HealthBar")]:GetFrameLevel()-1)
hotBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
hotBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetMinMaxValues(0, 1)
hotBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetValue(1)
hotBars[getglobal(self:GetParent():GetName().."HealthBar")]:SetStatusBarColor(unpack(HCCdb.global.hotColor))
end
end
--[[
Function: UnitFrameHealthBar_OnValueChangedHook
Purpose: Updates unit frames when a unit's max health changes
Inputs: self
Where self is a unit frame to update
]]--
local function UnitFrameHealthBar_OnValueChangedHook(self)
HealCommClassic:UpdateFrame(self, self.unit, currentHeals[UnitGUID(self.unit)] or 0, currentPlayerHeals[UnitGUID(self.unit)] or 0, currentNextHeals[UnitGUID(self.unit)] or 0, currentHots[UnitGUID(self.unit)] or 0)
end
--[[
Function: UnitFrameHealthBar_OnUpdateHook
Purpose: Updates unit frames when a unit's health changes
Inputs: self
Where self is a unit frame to update
Notes:
Function hook happens immediately after function definition
]]--
local function UnitFrameHealthBar_OnUpdateHook(self)
if self.unit ~= "player" then return end
HealCommClassic:UpdateFrame(self, self.unit, currentHeals[UnitGUID(self.unit)] or 0, currentPlayerHeals[UnitGUID(self.unit)] or 0, currentNextHeals[UnitGUID(self.unit)] or 0, currentHots[UnitGUID(self.unit)] or 0)
end
hooksecurefunc("UnitFrameHealthBar_OnUpdate", UnitFrameHealthBar_OnUpdateHook) -- This needs early hooking
--[[
Function: CompactUnitFrame_UpdateHealthHook
Purpose: Update heal bars when a unit's health changes
Inputs: self
Where self is a unit frame to update
]]--
local function CompactUnitFrame_UpdateHealthHook(self)
if not hpBars[self.healthBar] and not playerHpBars[self.healthBar] and not hotBars[self.healthBar] then return end
HealCommClassic:UpdateFrame(self.healthBar, self.displayedUnit, currentHeals[UnitGUID(self.displayedUnit)] or 0, currentPlayerHeals[UnitGUID(self.displayedUnit)] or 0, currentNextHeals[UnitGUID(self.displayedUnit)] or 0, currentHots[UnitGUID(self.displayedUnit)] or 0)
end
--[[
Function: CompactUnitFrame_UpdateMaxHealthHook
Purpose: Update heal calculations after a max health change
Inputs: self
Where self is a unit frame to update
]]--
local function CompactUnitFrame_UpdateMaxHealthHook(self)
if not hpBars[self.healthBar] and not playerHpBars[self.healthBar] and not hotBars[self.healthBar] then return end
HealCommClassic:UpdateFrame(self.healthBar, self.displayedUnit, currentHeals[UnitGUID(self.displayedUnit)] or 0, currentPlayerHeals[UnitGUID(self.displayedUnit)] or 0, currentNextHeals[UnitGUID(self.displayedUnit)] or 0, currentHots[UnitGUID(self.displayedUnit)] or 0)
end
--[[
Function: CompactUnitFrame_SetUnitHook
Purpose: Create a new heal bar whenever any frame is assigned a new unit
Inputs: self, Unit
Where self is a parent frame to attach to
Where Unit is the UnitID of the unit being added
Notes:
Function hook happens immediately after function definition
]]--
local function CompactUnitFrame_SetUnitHook(self, unit)
if (self:IsForbidden()) then return end --Catch for forbidden nameplates in dungeons/raids
if not hpBars[self.healthBar] then
hpBars[self.healthBar] = CreateFrame("StatusBar", nil, self)
hpBars[self.healthBar]:SetFrameStrata("LOW")
hpBars[self.healthBar]:SetFrameLevel(hpBars[self.healthBar]:GetFrameLevel()-1)
hpBars[self.healthBar]:SetStatusBarTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill")
hpBars[self.healthBar]:SetMinMaxValues(0, 1)
hpBars[self.healthBar]:SetValue(1)
hpBars[self.healthBar]:SetStatusBarColor(unpack(HCCdb.global.healColor))
end
if not playerHpBars[self.healthBar] then
playerHpBars[self.healthBar] = CreateFrame("StatusBar", nil, self)
playerHpBars[self.healthBar]:SetFrameStrata("LOW")
playerHpBars[self.healthBar]:SetFrameLevel(playerHpBars[self.healthBar]:GetFrameLevel()-1)
playerHpBars[self.healthBar]:SetStatusBarTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill")
playerHpBars[self.healthBar]:SetMinMaxValues(0, 1)
playerHpBars[self.healthBar]:SetValue(1)
playerHpBars[self.healthBar]:SetStatusBarColor(unpack(HCCdb.global.playerHealColor))
end
if not nextHpBars[self.healthBar] then
nextHpBars[self.healthBar] = CreateFrame("StatusBar", nil, self)
nextHpBars[self.healthBar]:SetFrameStrata("LOW")
nextHpBars[self.healthBar]:SetFrameLevel(nextHpBars[self.healthBar]:GetFrameLevel()-1)
nextHpBars[self.healthBar]:SetStatusBarTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill")
nextHpBars[self.healthBar]:SetMinMaxValues(0, 1)
nextHpBars[self.healthBar]:SetValue(1)
nextHpBars[self.healthBar]:SetStatusBarColor(unpack(HCCdb.global.healColor))
end
if not hotBars[self.healthBar] then
hotBars[self.healthBar] = CreateFrame("StatusBar", nil, self)
hotBars[self.healthBar]:SetFrameStrata("LOW")
hotBars[self.healthBar]:SetFrameLevel(hotBars[self.healthBar]:GetFrameLevel()-1)
hotBars[self.healthBar]:SetStatusBarTexture("Interface\\RaidFrame\\Raid-Bar-Hp-Fill")
hotBars[self.healthBar]:SetMinMaxValues(0, 1)
hotBars[self.healthBar]:SetValue(1)
hotBars[self.healthBar]:SetStatusBarColor(unpack(HCCdb.global.hotColor))
end
end
hooksecurefunc("CompactUnitFrame_SetUnit", CompactUnitFrame_SetUnitHook) -- This needs early hooking
--[[
Function: CompactUnitFrame_UpdateStatusTextHook
Purpose: Handle status text features
--]]
function CompactUnitFrame_UpdateStatusTextHook(frame)
if (not frame.statusText or not frame.optionTable.displayStatusText or not UnitIsConnected(frame.unit) or UnitIsDeadOrGhost(frame.displayedUnit)) then return end
if (UnitIsFeignDeath(frame.displayedUnit) and HCCdb.global.feignIndicator) then
frame.statusText:SetText('FEIGN')
end
if ( frame.optionTable.healthText == "losthealth" and HCCdb.global.predictiveHealthLost ) then
local currentHeals = currentHeals[UnitGUID(frame.displayedUnit)] or 0
local currentHots = currentHots[UnitGUID(frame.displayedUnit)] or 0
local healthLost = UnitHealthMax(frame.displayedUnit) - UnitHealth(frame.displayedUnit)
local healthDelta = (currentHeals + currentHots) - healthLost
if healthDelta >= 0 then
frame.statusText:Hide()
else
frame.statusText:SetFormattedText("%d", healthDelta)
end
end
end
--[[
Function: OnInitialize
Purpose: Initalize necessary functions, variables and set hooks, callbacks
]]--
function HealCommClassic:OnInitialize()
--convert options from earlier than 1.3.0
if HealCommSettings and HealCommSettings.timeframe then
settings = HCCdefault.global
settings.overhealPercent = HealCommSettings.overhealpercent or settings.overhealPercent
settings.timeframe = HealCommSettings.timeframe or settings.timeframe
if HealCommSettings.showHots then
settings.showHots = HealCommSettings.showHots
end
if HealCommSettings.seperateHots then
settings.seperateHots = HealCommSettings.seperateHots
end
settings.feignIndicator = settings.feignIndicator
settings.predictiveHealthLost = settings.predictiveHealthLost
if HealCommSettings.healColor then
settings.healColor = {HealCommSettings.healColor.red, HealCommSettings.healColor.green, HealCommSettings.healColor.blue, HealCommSettings.healColor.alpha or settings.healColor[4]}
end
if HealCommSettings.hotColor then
settings.hotColor = {HealCommSettings.hotColor.red, HealCommSettings.hotColor.green, HealCommSettings.hotColor.blue, HealCommSettings.hotColor.alpha or settings.hotColor[4]}
end
settings.statusText = HealCommSettings.statusText or settings.predictiveHealthLost
HealCommSettings=nil
end
HCCdb = LibStub("AceDB-3.0"):New("HealCommSettings", HCCdefault)
healColor=HCCdb.global.healColor
playerHealColor=HCCdb.global.playerHealColor
hotColor=HCCdb.global.hotColor
self:CreateBars()
self:CreateConfigs()
hooksecurefunc("RaidPulloutButton_OnLoad", RaidPulloutButton_OnLoadHook)
hooksecurefunc("UnitFrameHealthBar_OnValueChanged", UnitFrameHealthBar_OnValueChangedHook)
hooksecurefunc("CompactUnitFrame_UpdateHealth", CompactUnitFrame_UpdateHealthHook)
hooksecurefunc("CompactUnitFrame_UpdateMaxHealth", CompactUnitFrame_UpdateMaxHealthHook)
hooksecurefunc("CompactUnitFrame_UpdateStatusText", CompactUnitFrame_UpdateStatusTextHook)
libCHC.RegisterCallback(HealCommClassic, "HealComm_HealStarted", "HealComm_HealUpdated")
libCHC.RegisterCallback(HealCommClassic, "HealComm_HealStopped")
libCHC.RegisterCallback(HealCommClassic, "HealComm_HealDelayed", "HealComm_HealUpdated")
libCHC.RegisterCallback(HealCommClassic, "HealComm_HealUpdated")
libCHC.RegisterCallback(HealCommClassic, "HealComm_ModifierChanged")
libCHC.RegisterCallback(HealCommClassic, "HealComm_GUIDDisappeared")
end
--[[
Function: CreateBars
Purpose: Create and initalize heal bars for all frames
]]--
function HealCommClassic:CreateBars()
for unit,v in pairs(frames) do
if not hpBars[v] then
hpBars[v.bar] = CreateFrame("StatusBar", "IncHealBar"..unit, v.frame)
hpBars[v.bar]:SetFrameStrata("LOW")
hpBars[v.bar]:SetFrameLevel(hpBars[v.bar]:GetFrameLevel()-1)
hpBars[v.bar]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
hpBars[v.bar]:SetMinMaxValues(0, 1)
hpBars[v.bar]:SetValue(1)
hpBars[v.bar]:SetStatusBarColor(unpack(HCCdb.global.healColor))
end
if not playerHpBars[v] then
playerHpBars[v.bar] = CreateFrame("StatusBar", "IncPlayerHealBar"..unit, v.frame)
playerHpBars[v.bar]:SetFrameStrata("LOW")
playerHpBars[v.bar]:SetFrameLevel(playerHpBars[v.bar]:GetFrameLevel()-1)
playerHpBars[v.bar]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
playerHpBars[v.bar]:SetMinMaxValues(0, 1)
playerHpBars[v.bar]:SetValue(1)
playerHpBars[v.bar]:SetStatusBarColor(unpack(HCCdb.global.playerHealColor))
end
if not nextHpBars[v] then
nextHpBars[v.bar] = CreateFrame("StatusBar", "IncNextHealBar"..unit, v.frame)
nextHpBars[v.bar]:SetFrameStrata("LOW")
nextHpBars[v.bar]:SetFrameLevel(nextHpBars[v.bar]:GetFrameLevel()-1)
nextHpBars[v.bar]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
nextHpBars[v.bar]:SetMinMaxValues(0, 1)
nextHpBars[v.bar]:SetValue(1)
nextHpBars[v.bar]:SetStatusBarColor(unpack(HCCdb.global.healColor))
end
if not hotBars[v] then
hotBars[v.bar] = CreateFrame("StatusBar", "IncHotBar"..unit, v.frame)
hotBars[v.bar]:SetFrameStrata("LOW")
hotBars[v.bar]:SetFrameLevel(hotBars[v.bar]:GetFrameLevel()-1)
hotBars[v.bar]:SetStatusBarTexture("Interface\\TargetingFrame\\UI-StatusBar")
hotBars[v.bar]:SetMinMaxValues(0, 1)
hotBars[v.bar]:SetValue(1)
hotBars[v.bar]:SetStatusBarColor(unpack(HCCdb.global.hotColor))
end
end
end
--[[
Function: UpdateColors
Purpose: Update the color of all heal bars
]]--
function HealCommClassic:UpdateColors()
for unit,v in pairs(hpBars) do
if hpBars[unit] then
hpBars[unit]:SetStatusBarColor(unpack(HCCdb.global.healColor))
end
if playerHpBars[unit] then
playerHpBars[unit]:SetStatusBarColor(unpack(HCCdb.global.playerHealColor))
end
if nextHpBars[unit] then
nextHpBars[unit]:SetStatusBarColor(unpack(HCCdb.global.healColor))
end
if hotBars[unit] then
hotBars[unit]:SetStatusBarColor(unpack(HCCdb.global.hotColor))
end
end
end
--[[
Function: UpdateHealthValuesLoop
Purpose: Force health and max health value update
--]]
function HealCommClassic:UpdateHealthValuesLoop()
if UnitInRaid("player") and HCCdb.global.fastUpdate then
unitframe = _G["CompactRaidFrame1"]
num = 1
while unitframe do
if unitframe.displayedUnit and UnitExists(unitframe.displayedUnit) then
CompactUnitFrame_UpdateMaxHealth(unitframe.healthBar:GetParent())
CompactUnitFrame_UpdateHealth(unitframe.healthBar:GetParent())
end
num = num + 1
unitframe = _G["CompactRaidFrame"..num]
end
for k=1, NUM_RAID_PULLOUT_FRAMES do
frame = getglobal("RaidPullout"..k)
for z=1, frame.numPulloutButtons do
unitframe = getglobal(frame:GetName().."Button"..z)
if unitframe.unit and UnitExists(unitframe.unit) then
CompactUnitFrame_UpdateMaxHealth(unitframe.healthBar:GetParent())
CompactUnitFrame_UpdateHealth(unitframe.healthBar:GetParent())
end
end
end
for i=1, 8 do
local grpHeader = "CompactRaidGroup"..i
if _G[grpHeader] then
for k=1, 5 do
unitframe = _G[grpHeader.."Member"..k]
if unitframe and unitframe.displayedUnit and UnitExists(unitframe.displayedUnit) then
CompactUnitFrame_UpdateMaxHealth(unitframe.healthBar:GetParent())
CompactUnitFrame_UpdateHealth(unitframe.healthBar:GetParent())
end
end
end
end
C_Timer.After(HCCdb.global.fastUpdateDuration,HealCommClassic.UpdateHealthValuesLoop)
end
end
--[[`
Function: UNIT_PET
Purpose: Update pet heal bars
Inputs: Unit
Where Unit is the UnitID of the pet being updated
]]--
function HealCommClassic:UNIT_PET(unit)
if unit ~= "player" and strsub(unit,1,5) ~= "party" then return end
petunit = unit == "player" and "pet" or "partypet"..strsub(unit,6)
for guid,unit in pairs(partyGUIDs) do
if unit == petunit then
partyGUIDs[guid] = nil
break
end
end
if UnitExists(petunit) then
partyGUIDs[UnitGUID(petunit)] = petunit
end
if hpBars[frames[petunit].bar] or playerHpBars[frames[petunit].bar] or hotBars[frames[petunit].bar] then
self:UpdateFrame(frames[petunit].bar, petunit, currentHeals[UnitGUID("pet")] or 0, currentPlayerHeals[UnitGUID("pet")] or 0, currentNextHeals[UnitGUID("pet")] or 0, currentHots[UnitGUID("pet")] or 0)
end
end
--[[
Function: PLAYER_TARGET_CHANGED
Purpose: Update player target heal bars
]]--
function HealCommClassic:PLAYER_TARGET_CHANGED()
self:UpdateFrame(frames["target"].bar, "target", currentHeals[UnitGUID("target")] or 0, currentPlayerHeals[UnitGUID("target")] or 0, currentNextHeals[UnitGUID("target")] or 0, currentHots[UnitGUID("target")] or 0)
end
--[[
Function: PLAYER_ROLES_ASSIGNED
Purpose: Update party and raid heal bars after a raid role assignment
]]--
function HealCommClassic:PLAYER_ROLES_ASSIGNED()
local frame, unitframe, num
for guid,unit in pairs(partyGUIDs) do
if strsub(unit,1,5) == "party" then
partyGUIDs[guid] = nil
end
end
if UnitInParty("player") then
for i=1, MAX_PARTY_MEMBERS do
local p = "party"..i
if UnitExists(p) then
partyGUIDs[UnitGUID(p)] = p
else
break
end
end
unitframe = _G["CompactPartyFrameMember1"]
num = 1
while unitframe do
if unitframe.displayedUnit and UnitExists(unitframe.displayedUnit) then
self:UpdateFrame(unitframe.healthBar, unitframe.displayedUnit, amount, playerAmount, nextAmount, hotAmount) --no amount declaration? call just hides bars
end
num = num + 1
unitframe = _G["CompactPartyFrameMember"..num]
end
unitframe = _G["CompactRaidFrame1"]
num = 1
while unitframe do
if unitframe.displayedUnit and UnitExists(unitframe.displayedUnit) then
self:UpdateFrame(unitframe.healthBar, unitframe.displayedUnit, amount, playerAmount, nextAmount, hotAmount)
end
num = num + 1
unitframe = _G["CompactRaidFrame"..num]
end
end
if UnitInRaid("player") then
for k=1, NUM_RAID_PULLOUT_FRAMES do
frame = getglobal("RaidPullout"..k)
for z=1, frame.numPulloutButtons do
unitframe = getglobal(frame:GetName().."Button"..z)
if unitframe.unit and UnitExists(unitframe.unit) then
self:UpdateFrame(getglobal(unitframe:GetName().."HealthBar"), unitframe.unit, currentHeals[UnitGUID(unitframe.unit)] or 0, currentPlayerHeals[UnitGUID(unitframe.unit)] or 0, currentNextHeals[UnitGUID(unitframe.unit)] or 0, currentHots[UnitGUID(unitframe.unit)] or 0)
end
end
end
for i=1, 8 do
local grpHeader = "CompactRaidGroup"..i
if _G[grpHeader] then
for k=1, 5 do
unitframe = _G[grpHeader.."Member"..k]
if unitframe and unitframe.displayedUnit and UnitExists(unitframe.displayedUnit) then
self:UpdateFrame(unitframe.healthBar, unitframe.displayedUnit, currentHeals[UnitGUID(unitframe.displayedUnit)] or 0, currentPlayerHeals[UnitGUID(unitframe.displayedUnit)] or 0, currentNextHeals[UnitGUID(unitframe.displayedUnit)] or 0, currentHots[UnitGUID(unitframe.displayedUnit)] or 0)
end
end
end
end
end
end
--[[
Function: HealCommClassic_HealUpdated
Purpose: HealCommLib callback handler
Redirect callback
Inputs: event, casterGUID, spellID, healType, interrupted, args
Where event, casterGUID, spellID, etc. are non-functional
Where args is a table of GUIDs to update
--]]
function HealCommClassic:HealComm_HealUpdated(event, casterGUID, spellID, healType, endTime, ...)
self:UpdateIncoming(...)
end
--[[
Function: HealComm_HealStopped
Purpose: HealCommLib callback handler
Redirect callback
Inputs: event, casterGUID, spellID, healType, interrupted, args
Where event, casterGUID, spellID, etc. are non-functional
Where args is a table of GUIDs to update
--]]
function HealCommClassic:HealComm_HealStopped(event, casterGUID, spellID, healType, interrupted, ...)
self:UpdateIncoming(...)
end
--[[
Function: HealComm_ModifierChanged
Purpose: HealCommLib callback handler
Redirect callback
Inputs: Event, GUID
Where Event is non-functional
Where GUID is the GUID to update
--]]
function HealCommClassic:HealComm_ModifierChanged(event, guid)
self:UpdateIncoming(guid)
end
--[[
Function: HealComm_GUIDDisappeared
Purpose: Update heal bars after a GUID disappears from view
Inputs: Event, GUID
Where Event is non-functional
Where GUID is the GUID that disappeared
--]]
function HealCommClassic:HealComm_GUIDDisappeared(event, guid)
self:UpdateIncoming(guid)
end
--[[
Function: UpdateIncoming
Purpose: Stores incoming healing information from healcomm library
Inputs: args
A table of GUIDs to update
--]]
function HealCommClassic:UpdateIncoming(...)
local targetGUID, num, frame, unitframe, healType
local hotType=libCHC.HOT_HEALS
local castedType=libCHC.CASTED_HEALS
if HCCdb.global.showHots and not HCCdb.global.seperateHots then
healType = libCHC.ALL_HEALS
else
healType = libCHC.CASTED_HEALS
end
for i=1, select("#", ...) do
local amount, playerAmount, nextAmount, nextPlayerHealTime, hotAmount
targetGUID = select(i, ...)
amount = (libCHC:GetHealAmount(targetGUID, healType, nil) or 0) * (libCHC:GetHealModifier(targetGUID) or 1)
if HCCdb.global.seperatePlayer then
nextPlayerHealTime, _, playerAmount = libCHC:GetNextHealAmount(targetGUID, castedType, GetTime()+ HCCdb.global.timeframe, nil, playerGUID)
playerAmount = min(amount, (playerAmount or 0) * (libCHC:GetHealModifier(targetGUID) or 1))
amount = amount - playerAmount
if playerAmount > 0 then
nextAmount = libCHC:GetOthersHealAmount(targetGUID, castedType, nextPlayerHealTime)
end
nextAmount = min(amount, (nextAmount or 0) * (libCHC:GetHealModifier(targetGUID) or 1))
amount = amount - nextAmount
else
playerAmount = 0
nextAmount = 0
end
if HCCdb.global.seperateHots and HCCdb.global.showHots then
hotAmount= (libCHC:GetHealAmount(targetGUID, hotType, GetTime()+HCCdb.global.timeframe) or 0) * (libCHC:GetHealModifier(targetGUID) or 1)
end
currentHots[targetGUID] = hotAmount
currentPlayerHeals[targetGUID] = playerAmount
currentNextHeals[targetGUID] = nextAmount
currentHeals[targetGUID] = amount
if UnitGUID("target") == targetGUID then
self:UpdateFrame(frames["target"].bar, "target", amount, playerAmount, nextAmount, hotAmount)
end
if partyGUIDs[targetGUID] then
self:UpdateFrame(frames[partyGUIDs[targetGUID]].bar, partyGUIDs[targetGUID], amount, playerAmount, nextAmount, hotAmount)
end
if UnitInParty("player") then
unitframe = _G["CompactPartyFrameMember1"]
num = 1
while unitframe do
if unitframe.displayedUnit and UnitExists(unitframe.displayedUnit) and UnitGUID(unitframe.displayedUnit) == targetGUID then
self:UpdateFrame(unitframe.healthBar, unitframe.displayedUnit, amount, playerAmount, nextAmount, hotAmount)
end
num = num + 1
unitframe = _G["CompactPartyFrameMember"..num]
end
unitframe = _G["CompactRaidFrame1"]
num = 1
while unitframe do
if unitframe.displayedUnit and UnitExists(unitframe.displayedUnit) and UnitGUID(unitframe.displayedUnit) == targetGUID then
self:UpdateFrame(unitframe.healthBar, unitframe.displayedUnit, amount, playerAmount, nextAmount, hotAmount)
CompactUnitFrame_UpdateStatusText(unitframe.healthBar:GetParent())
end
num = num + 1
unitframe = _G["CompactRaidFrame"..num]
end
end
if UnitInRaid("player") then
for k=1, NUM_RAID_PULLOUT_FRAMES do
frame = getglobal("RaidPullout"..k)
for z=1, frame.numPulloutButtons do
unitframe = getglobal(frame:GetName().."Button"..z)
if unitframe.unit and UnitExists(unitframe.unit) and UnitGUID(unitframe.unit) == targetGUID then
self:UpdateFrame(getglobal(unitframe:GetName().."HealthBar"), unitframe.unit, amount, playerAmount, nextAmount, hotAmount)
CompactUnitFrame_UpdateStatusText(unitframe.healthBar:GetParent())
end
end
end
for j=1, 8 do
local grpHeader = "CompactRaidGroup"..j
if _G[grpHeader] then
for k=1, 5 do
unitframe = _G[grpHeader.."Member"..k]
if unitframe and unitframe.displayedUnit and UnitExists(unitframe.displayedUnit) and UnitGUID(unitframe.displayedUnit) == targetGUID then
self:UpdateFrame(unitframe.healthBar, unitframe.displayedUnit, currentHeals[UnitGUID(unitframe.displayedUnit)] or 0, currentPlayerHeals[UnitGUID(unitframe.displayedUnit)] or 0, currentNextHeals[UnitGUID(unitframe.displayedUnit)] or 0, currentHots[UnitGUID(unitframe.displayedUnit)] or 0)
CompactUnitFrame_UpdateStatusText(unitframe.healthBar:GetParent())
end
end
end
end
end
end
end
--[[
Function: UpdateFrame
Purpose: Updates heal bar sizes based on incoming healing
Inputs: Frame, Unit, Amount, hotAmount
Where Frame is the heal bar frame to update
Where Unit is the UnitID that the heal bar references
Where Amount is the amount of incoming healing
Where hotAmount is the amount of incoming HoTs
--]]
function HealCommClassic:UpdateFrame(frame, unit, amount, playerAmount, nextAmount, hotAmount)
local health, maxHealth= UnitHealth(unit), UnitHealthMax(unit)
local healthWidth=frame:GetWidth() * (health / maxHealth)
local incNextWidth = frame:GetWidth() * (nextAmount or 0) / maxHealth
local incWidth = frame:GetWidth() * (amount or 0) / maxHealth
local incPlayerWidth = frame:GetWidth() * (playerAmount or 0) / maxHealth
local hotWidth = frame:GetWidth() * (hotAmount or 0) / maxHealth
local remainingWidth = frame:GetWidth() * (1+(HCCdb.global.overhealPercent/100)) - healthWidth
incNextWidth = min(remainingWidth, incNextWidth)
remainingWidth = remainingWidth - incNextWidth
incPlayerWidth = min(remainingWidth, incPlayerWidth)
remainingWidth = remainingWidth - incPlayerWidth
incWidth = min(remainingWidth, incWidth)
remainingWidth = remainingWidth - incWidth
hotWidth = min(remainingWidth, hotWidth)
remainingWidth = remainingWidth - hotWidth
if incNextWidth > 0 and frame:IsVisible() then
nextHpBars[frame]:Show()
nextHpBars[frame]:SetWidth(incNextWidth)
nextHpBars[frame]:SetHeight(frame:GetHeight())
nextHpBars[frame]:ClearAllPoints()
nextHpBars[frame]:SetPoint("TOPLEFT", frame, "TOPLEFT", healthWidth, 0)
else
nextHpBars[frame]:Hide()
end
if incPlayerWidth > 0 and frame:IsVisible() then
playerHpBars[frame]:Show()
playerHpBars[frame]:SetWidth(incPlayerWidth)
playerHpBars[frame]:SetHeight(frame:GetHeight())
playerHpBars[frame]:ClearAllPoints()
playerHpBars[frame]:SetPoint("TOPLEFT", frame, "TOPLEFT", healthWidth + incNextWidth, 0)
else
playerHpBars[frame]:Hide()
end
if incWidth > 0 and frame:IsVisible() then
hpBars[frame]:Show()
hpBars[frame]:SetWidth(incWidth)
hpBars[frame]:SetHeight(frame:GetHeight())
hpBars[frame]:ClearAllPoints()
hpBars[frame]:SetPoint("TOPLEFT", frame, "TOPLEFT", healthWidth + incNextWidth + incPlayerWidth, 0)
else
hpBars[frame]:Hide()
end
if hotWidth > 0 and frame:IsVisible() then
hotBars[frame]:Show()
hotBars[frame]:SetWidth(hotWidth)
hotBars[frame]:SetHeight(frame:GetHeight())
hotBars[frame]:ClearAllPoints()
hotBars[frame]:SetPoint("TOPLEFT", frame, "TOPLEFT", healthWidth + incNextWidth + incPlayerWidth + incWidth, 0)
else
hotBars[frame]:Hide()
end
end
--[[
Function: CreateConfigs
Purpose: Create and attach options page
Notes:
For convenience, order is incremented in steps of two so new options can be squeezed between them.
]]--
function HealCommClassic:CreateConfigs()
local options = {
name = 'HealCommClassic Options',
type = 'group',
args = {
desc1 = {
order = 0,
type = 'description',
width = 2.5,
name = 'Version '..HealCommClassic.version,
},
button0 = {
order = 1,
type = 'execute',
name = 'Reset to defaults',
confirm = true,
func = function() HCCdb:ResetDB() end
},
desc2 = {
order = 2,
type = 'description',
width = 'full',
name = 'HealCommClassic is an implementation of HealComm (LibHealComm) for Blizzard\'s raid frames'
},
},
}
options.args['healthBars'] = {
name = 'Health Bars',
type = 'group',
order = 0,
args = {
header0 = {
order = 2,
type = 'header',
name = 'General Settings',
},
overheal = {
order = 4,
type = 'range',
name = 'Extend Overheals',
desc = 'How far heals can extend on overhealing, in percentage of the health bar size',
min = 0,
max = 0.5,
step = 0.01,
isPercent = true,
get = function() return HCCdb.global.overhealPercent / 100 end,
set = function(_,value) HCCdb.global.overhealPercent = value * 100 end,
},
spacer1 = {
order = 6,
type = 'description',
name = '\n',
},
header1 = {
order = 8,
type = 'header',
name = 'Heal Over Times'
},
hotToggle = {
order = 10,
type = 'toggle',
name = 'Show HoTs',
desc = 'Include HoTs in healing prediction',
width = 'full',
get = function() return HCCdb.global.showHots end,
set = function(_, value) HCCdb.global.showHots = value end,
},
timeframe = {
order = 12,
type = 'range',
name = 'Timeframe',
desc = 'How many seconds into the future to predict HoTs',
min = 3,
max = 23,
step = 1,
get = function() return HCCdb.global.timeframe end,
set = function(info,value) HCCdb.global.timeframe = value end,
},
spacer2 = {
order = 14,
type = 'description',
name = '\n',
},
header2 = {
order = 16,
type = 'header',
name = 'Color Options',
},
desc1 = {
order = 17,
type = 'description',
name = 'Note: The plus and minus slider sets transparency.'
},
healColor = {
order = 18,
type = 'color',
name = 'Heal Color',
hasAlpha = true,
width = 'full',
get = function() return unpack(HCCdb.global.healColor) end,
set = function (_, r, g, b, a) HCCdb.global.healColor = {r,g,b,a}; self:UpdateColors() end,
},
spacer3 = {
order = 20,
type = 'description',
name = '\n',
},
seperateHot = {
order = 22,
type = 'toggle',
name = 'Seperate HoT Color',
desc = 'Color HoTs as a seperate color.\n\'Show HoTs\' must be enabled.',
width = 'full',
get = function() return HCCdb.global.seperateHots end,
set = function(_, value) HCCdb.global.seperateHots = value end,
},
hotColor = {
order = 24,
type = 'color',
name = 'HoT Color',
hasAlpha = true,
width = 'full',
get = function() return unpack(HCCdb.global.hotColor) end,
set = function (_,r, g, b, a) HCCdb.global.hotColor = {r,g,b,a}; self:UpdateColors() end,
},
spacer4 = {
order = 26,
type = 'description',
name = '\n',
},
seperatePlayer = {
order = 28,
type = 'toggle',
name = 'Seperate Player Color',
desc = 'Color players next direct heal as a seperate color.',
width = 'full',
get = function() return HCCdb.global.seperatePlayer end,
set = function(_, value) HCCdb.global.seperatePlayer = value end,
},
playerHealColor = {
order = 30,
type = 'color',
name = 'Player Color',
hasAlpha = true,
width = 'full',
get = function() return unpack(HCCdb.global.playerHealColor) end,
set = function (_,r, g, b, a) HCCdb.global.playerHealColor = {r,g,b,a}; self:UpdateColors() end,
},
},
}
options.args['statusText'] = {
name = 'Status Text',
type = 'group',
order = 2,
args = {
header0 = {
order = 0,
type = 'header',
name = 'General Settings',
},
feignToggle = {
order = 2,
type = 'toggle',
name = 'Feign death indicator',
descStyle = 'inline',
desc = 'Shows the text \'FEIGN\' instead of \'DEAD\' when a hunter feigns death.',
width = 'full',
get = function() return HCCdb.global.feignIndicator end,
set = function(_, value) HCCdb.global.feignIndicator = value end,
},
spacer = {
order = 3,
type = 'description',
name = '\n',
},
desc1 = {
order = 4,
type = 'header',
name = 'Health Text Replacers',
},
desc2 = {
order = 6,
type = 'description',
name = 'These options replace the functionality of \'Display Health Text\' in Blizzard\'s Raid Profiles.\n\n',
},
predictiveHealthLostToggle = {
order = 8,
type = 'toggle',
name = 'Predictive \'Health Lost\'',
desc = 'Shows the amount of health missing after all shown heals go off. \nThis replaces the \'Health Lost\' option.',
descStyle = 'inline',
width = 'full',
get = function() return HCCdb.global.predictiveHealthLost end,
set = function(_, value) HCCdb.global.predictiveHealthLost = value end,
},
continued = {
order = 20,
type = 'description',
name = '\n\nMore options will be added in the future.',
}
},
}
options.args['misc']={
name = 'Miscellaneous',
type = 'group',
order = 4,
args = {
header0 = {
order = 0,
type = 'header',
name = 'General Settings',
},
fastUpdate = {
order = 2,
type = 'toggle',
name = 'Fast Raid Health Update',
desc = 'Adds extra health updates every second.\nMay impact framerate on low end machines.',
descStyle = 'inline',
width = 'full',
get = function() return HCCdb.global.fastUpdate end,
set = function(_, value) HCCdb.global.fastUpdate = value; C_Timer.After(HCCdb.global.fastUpdateDuration, HealCommClassic.UpdateHealthValuesLoop) end,
},
}
}
LibStub("AceConfig-3.0"):RegisterOptionsTable("HCCOptions", options)
LibStub("AceConfigDialog-3.0"):AddToBlizOptions("HCCOptions","HealCommClassic")
end
--[[
Code section: Event Registration
Purpose: Set event to initalize HealCommClassic on first login and
update targets after target/pet/raid role change
--]]
local frame = CreateFrame("Frame")
frame:RegisterEvent("PLAYER_TARGET_CHANGED")
frame:RegisterEvent("PLAYER_ROLES_ASSIGNED")
frame:RegisterEvent("UNIT_PET")
frame:SetScript("OnEvent", function(self, event, ...)
HealCommClassic[event](HealCommClassic, ...)
end)
--[[ End of "Event Registration" code section ]]--