-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathPlater_BossModsSupport.lua
1114 lines (947 loc) · 35.9 KB
/
Plater_BossModsSupport.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
-- Bigwigs/DBM nameplate aura support
--[[
Options (defaults):
Plater.db.profile.bossmod_support_enabled = true
Plater.db.profile.bossmod_aura_height = 32
Plater.db.profile.bossmod_aura_width = 32
Plater.db.profile.bossmod_cooldown_text_size = 16
Plater.db.profile.bossmod_icons_anchor = {side = 8, x = 0, y = 40}
Plater.db.profile.bossmod_support_bars_enabled = false
Plater.db.profile.bossmod_support_bars_text_max_len = 7
]]--
local DF = _G ["DetailsFramework"]
local Plater = _G.Plater
local C_Timer = _G.C_Timer
local C_NamePlate = _G.C_NamePlate
local GetTime = _G.GetTime
local LCG = LibStub:GetLibrary("LibCustomGlow-1.0")
local UNIT_BOSS_MOD_AURAS_ACTIVE = {} --contains for each [GUID] a list of {texture, duration, desaturate}
local UNIT_BOSS_MOD_AURAS_TO_BE_REMOVED = {} --contains for each [GUID] a list of texture-ids to be removed
local UNIT_BOSS_MOD_BARS = {} --contains for each [GUID] the bar information
local UNIT_BOSS_MOD_NEEDS_UPDATE_IN = {} -- timestamp for next update!
local HOSTILE_ENABLED = false
local IS_REGISTERED = false
local DBM_TIMER_BARS_TEST_MODE = false --can be changed via callback. will disable after 30sec
-- core functions
local function ShowNameplateAura(guid, texture, duration, desaturate, isPriority)
--print("ShowNameplateAura", guid, texture, duration, desaturate, isPriority, HOSTILE_ENABLED)
if not HOSTILE_ENABLED then return end
if not guid or not texture then return end
local values = {
texture = texture,
duration = duration,
desaturate = desaturate,
isPriority = isPriority,
starttime = GetTime(),
}
UNIT_BOSS_MOD_AURAS_ACTIVE [guid] = UNIT_BOSS_MOD_AURAS_ACTIVE [guid] or {}
for index, value in pairs (UNIT_BOSS_MOD_AURAS_ACTIVE [guid]) do
if value.texture == values.texture and value.starttime == values.starttime and value.duration == values.duration then
return
end
end
tinsert(UNIT_BOSS_MOD_AURAS_ACTIVE [guid], values)
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] = -1
end
local function HideNameplateAura(guid, texture)
--print("HideNameplateAura", guid, texture)
if not HOSTILE_ENABLED then return end
if not guid or not texture then return end
-- force direct removal when called for to ensure a new instance can directly be shown after
for activeIndex, activeData in pairs(UNIT_BOSS_MOD_AURAS_ACTIVE [guid] or {}) do
if texture == activeData.texture then
tremove(UNIT_BOSS_MOD_AURAS_ACTIVE [guid], activeIndex)
end
end
-- keep the old way for now
--UNIT_BOSS_MOD_AURAS_TO_BE_REMOVED [guid] = UNIT_BOSS_MOD_AURAS_TO_BE_REMOVED [guid] or {}
--tinsert(UNIT_BOSS_MOD_AURAS_TO_BE_REMOVED [guid], texture)
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] = -1
end
local function DisableHostile()
--print("DisableHostile")
HOSTILE_ENABLED = false
UNIT_BOSS_MOD_AURAS_ACTIVE = {}
UNIT_BOSS_MOD_AURAS_TO_BE_REMOVED = {}
end
local function EnableHostile()
--print("EnableHostile")
if not Plater.db.profile.bossmod_support_enabled then
return
end
HOSTILE_ENABLED = true
end
local function StartGlow(self, glowType)
if not glowType or glowType == 1 then
local options = {
glowType = "pixel",
color = self.bmData.color, -- all plater color types accepted, from lib: {r,g,b,a}, color of lines and opacity, from 0 to 1. Defaul value is {0.95, 0.95, 0.32, 1}
N = 8, -- number of lines. Defaul value is 8;
frequency = 0.25, -- frequency, set to negative to inverse direction of rotation. Default value is 0.25;
length = 3, -- length of lines. Default value depends on region size and number of lines;
th = 3, -- thickness of lines. Default value is 2;
xOffset = 0,
yOffset = 0, -- offset of glow relative to region border;
border = false, -- set to true to create border under lines;
key = "BM_ImportantIconGlow", -- key of glow, allows for multiple glows on one frame;
}
Plater.StartPixelGlow(self, self.bmData.color or "orange", options, "BM_ImportantIconGlow")
elseif glowType == 2 then
local options = {
glowType = "proc",
color = self.bmData.color,
--frameLevel = 8,
startAnim = true,
xOffset = 0,
yOffset = 0,
duration = 1,
key = "BM_ImportantIconGlow",
}
Plater.StartProcGlow(self, self.bmData.color or "orange", options, "BM_ImportantIconGlow")
elseif glowType == 3 then
local options = {
glowType = "ants",
color = self.bmData.color,
N = 4, -- number of particle groups. Default value is 4
frequency = 0.125, -- frequency, set to negative to inverse direction of rotation. Default value is 0.125
scale = 1,-- scale of particles.
xOffset = 0,
yOffset = 0,
duration = 1,
key = "BM_ImportantIconGlow",
}
Plater.StartAntsGlow(self, self.bmData.color or "orange", options, "BM_ImportantIconGlow")
elseif glowType == 4 then
local options = {
glowType = "button",
color = self.bmData.color,
frequency = 0.125,--Default value is 0.125
key = "BM_ImportantIconGlow",
}
Plater.StartButtonGlow(self, self.bmData.color or "orange", options, "BM_ImportantIconGlow")
end
end
local function StopGlow(self, glowType)
--print("StopGlow", glowType)
if not glowType then
Plater.StopGlow(self, "BM_ImportantIconGlow")
elseif glowType == 1 then
Plater.StopPixelGlow(self, "BM_ImportantIconGlow")
elseif glowType == 2 then
Plater.StopProcGlow(self, "BM_ImportantIconGlow")
elseif glowType == 3 then
Plater.StopAntsGlow(self, "BM_ImportantIconGlow")
elseif glowType == 4 then
Plater.StopButtonGlow(self, "BM_ImportantIconGlow")
end
end
function Plater.CreateBossModAuraFrame(unitFrame)
Plater.RegisterBossModAuras()
local options = {
icon_width = Plater.db.profile.bossmod_aura_width or 32,
icon_height = Plater.db.profile.bossmod_aura_height or 32,
texcoord = {.1, .9, .1, .9},
show_text = Plater.db.profile.bossmod_cooldown_text_enabled,
text_size = Plater.db.profile.bossmod_cooldown_text_size or 16,
surpress_tulla_omni_cc = Plater.db.profile.disable_omnicc_on_auras,
desc_text = true,
desc_text_size = 10
}
unitFrame.BossModIconFrame = DF:CreateIconRow (unitFrame.healthBar, "$parentBossModIconRow", options)
unitFrame.BossModIconFrame:ClearIcons()
unitFrame.BossModIconFrame.RefreshID = 0
unitFrame.BossModIconFrame:SetOption ("surpress_tulla_omni_cc", Plater.db.profile.disable_omnicc_on_auras)
unitFrame.BossModIconFrame:SetOption ("surpress_blizzard_cd_timer", true)
unitFrame.BossModIconFrame:SetOption ("anchor", Plater.db.profile.bossmod_icons_anchor or {side = 8, x = 0, y = 30})
unitFrame.BossModIconFrame:SetOption ("grow_direction", unitFrame.ExtraIconFrame:GetIconGrowDirection())
Plater.SetAnchor (unitFrame.BossModIconFrame, Plater.db.profile.bossmod_icons_anchor or {side = 8, x = 0, y = 30})
unitFrame.BossModIconFrame.OnIconTick = function(self, deltaTime) -- override to add glow effects
local now = GetTime()
if (self.lastUpdateCooldown + 0.05) <= now then
self.timeRemaining = ((self.expirationTime or now) - now) / (self.modRate or 1)
if self.timeRemaining > 0 then
if self.parentIconRow.options.decimal_timer then
self.CountdownText:SetText(self.parentIconRow.FormatCooldownTimeDecimal(self.timeRemaining))
else
self.CountdownText:SetText(self.parentIconRow.FormatCooldownTime(self.timeRemaining))
end
else
self.CountdownText:SetText("")
end
local profile = Plater.db.profile
local bmData = self.bmData or {}
local canGlow = false
if bmData.barType ~= "castnp" and (profile.bossmod_aura_glow_cooldown and (not bossmod_aura_glow_important_only or bmData.isPriority)) and self.timeRemaining < 4 and self.timeRemaining > 0 then
canGlow = true
elseif bmData.barType == "castnp" and profile.bossmod_aura_glow_casts and self.timeRemaining < 4 and self.timeRemaining > 0 then
canGlow = true
end
local glowType = bmData.barType == "castnp" and profile.bossmod_aura_glow_casts_glow_type or profile.bossmod_aura_glow_cooldown_glow_type
--print(canGlow, self.isGlowing)
if canGlow and not self.isGlowing then
StartGlow(self, glowType)
self.isGlowing = glowType
elseif not canGlow and self.isGlowing ~= false or self.timeRemaining < 0 then
StopGlow(self, self.isGlowing)
self.isGlowing = false
end
self.lastUpdateCooldown = now
end
end
end
function Plater.UpdateBossModAuraFrameSettings(unitFrame, refreshID)
if (unitFrame.BossModIconFrame.RefreshID < refreshID) then
Plater.SetAnchor (unitFrame.BossModIconFrame, Plater.db.profile.bossmod_icons_anchor)
unitFrame.BossModIconFrame:SetOption ("surpress_tulla_omni_cc", Plater.db.profile.disable_omnicc_on_auras)
unitFrame.BossModIconFrame:SetOption ("text_size", Plater.db.profile.bossmod_cooldown_text_size)
unitFrame.BossModIconFrame:SetOption ("icon_width", Plater.db.profile.bossmod_aura_width)
unitFrame.BossModIconFrame:SetOption ("icon_height", Plater.db.profile.bossmod_aura_height)
unitFrame.BossModIconFrame:SetOption ("anchor", Plater.db.profile.bossmod_icons_anchor or {side = 8, x = 0, y = 30})
unitFrame.BossModIconFrame:SetOption ("grow_direction", unitFrame.ExtraIconFrame:GetIconGrowDirection())
--> update refresh ID
unitFrame.BossModIconFrame.RefreshID = refreshID
end
end
function Plater.EnsureUpdateBossModAuras(guid)
if not guid then return end
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] = -1
end
function Plater.UpdateBossModAuras(unitFrame)
Plater.StartLogPerformanceCore("Plater-Core", "Update", "UpdateBossModAuras")
local guid = unitFrame.PlateFrame.namePlateUnitGUID
local curTime = GetTime()
if not UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] or UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] > curTime then
Plater.EndLogPerformanceCore("Plater-Core", "Update", "UpdateBossModAuras")
return
end
-- maybe find a better way with iconFrame:RemoveIcon(...) ? (not yet implemented, but worth a thought)
if UNIT_BOSS_MOD_AURAS_TO_BE_REMOVED [guid] then
for removeIndex, removeTexture in pairs(UNIT_BOSS_MOD_AURAS_TO_BE_REMOVED [guid]) do
for activeIndex, activeData in pairs(UNIT_BOSS_MOD_AURAS_ACTIVE [guid] or {}) do
if removeTexture == activeData.texture then
tremove(UNIT_BOSS_MOD_AURAS_ACTIVE [guid], activeIndex)
end
end
end
UNIT_BOSS_MOD_AURAS_TO_BE_REMOVED [guid] = nil
end
local nextUpdateTime = nil
local iconFrame = unitFrame.BossModIconFrame
iconFrame:ClearIcons()
if HOSTILE_ENABLED and UNIT_BOSS_MOD_AURAS_ACTIVE [guid] then
for activeIndex, values in pairs(UNIT_BOSS_MOD_AURAS_ACTIVE [guid]) do
if values.duration and values.duration > 0 and curTime > values.starttime + values.duration then
tremove(UNIT_BOSS_MOD_AURAS_ACTIVE [guid], activeIndex)
else
local icon = iconFrame:SetIcon(-1, nil, values.duration and values.duration > 0 and values.starttime, values.duration, values.texture)
-- spellId, borderColor, startTime, duration, forceTexture, descText, count, debuffType, caster, canStealOrPurge, spellName, isBuff
icon.Texture:SetDesaturated(values.desaturate)
icon.bmData = values
icon.lastUpdateCooldown = icon.lastUpdateCooldown or 0
if icon.isGlowing ~= false then
StopGlow(icon, icon.isGlowing)
icon.isGlowing = false
end
iconFrame.OnIconTick(icon)
--icon.Cooldown:SetDesaturated(values.desaturate)
local endTime = values.duration and values.duration > 0 and (values.starttime + values.duration) or nil
if not nextUpdateTime or (endTime and endTime < nextUpdateTime) then
nextUpdateTime = endTime
end
--check if Masque is enabled on Plater and reskin the aura icon
if (Plater.Masque and not icon.Masqued) then
local t = {
FloatingBG = nil, --false,
Icon = icon.Texture,
Cooldown = icon.Cooldown,
Flash = nil, --false,
Pushed = nil, --false,
Normal = false,
Disabled = nil, --false,
Checked = nil, --false,
Border = nil, --icon.Border,
AutoCastable = nil, --false,
Highlight = nil, --false,
HotKey = nil, --false,
Count = false,
Name = nil, --false,
Duration = false,
Shine = nil, --false,
}
icon.Border:Hide() --let Masque handle the border...
Plater.Masque.BossModIconFrame:AddButton (icon, t)
Plater.Masque.BossModIconFrame:ReSkin()
icon.Masqued = true
end
end
end
end
--timer bars
if Plater.db.profile.bossmod_support_bars_enabled and UNIT_BOSS_MOD_BARS [guid] then
local textEnabled = Plater.db.profile.bossmod_support_bars_text_enabled
local sortedAuras = {}
for id, data in pairs(UNIT_BOSS_MOD_BARS [guid]) do
tinsert(sortedAuras, data)
end
table.sort(sortedAuras, function(a,b)
if a.paused and not b.paused then
return false
elseif b.paused and not a.paused then
return true
else
local at, bt = a.timer or 0, b.timer or 0
local as, bs = a.start or 0, b.start or 0
local ar = at - (curTime - (a.paused and (curTime - (a.pauseStartTime - a.start)) or as))
local br = bt - (curTime - (b.paused and (curTime - (b.pauseStartTime - b.start)) or bs))
return br > ar
end
end)
--for id, data in pairs(UNIT_BOSS_MOD_BARS [guid]) do
for _, data in pairs(sortedAuras) do
local id = data.id
local overTime = curTime > data.start + data.timer
if not data.keep and data.timer and overTime then
UNIT_BOSS_MOD_BARS [guid][id] = nil
else
local timer, start = data.timer, data.start
if data.paused then
start = curTime - (data.pauseStartTime - start) --offset for paused.
end
if overTime and data.keep then
timer = nil
end
--print(timer, start, data.name, data.msg, data.colorId)
local icon = iconFrame:SetIcon(-1, data.color, timer and start, timer, data.icon, textEnabled and {text = data.display, text_color = data.color} or nil)
-- spellId, borderColor, startTime, duration, forceTexture, descText, count, debuffType, caster, canStealOrPurge, spellName, isBuff
--DF:TruncateText(icon.Desc, Plater.db.profile.bossmod_aura_width)
icon.bmData = data
icon.lastUpdateCooldown = icon.lastUpdateCooldown or 0
iconFrame.OnIconTick(icon)
if data.paused then
icon:SetScript("OnUpdate", nil)
icon.Cooldown:Pause()
icon.Texture:SetDesaturated(true)
else
--[[
local curOnUpdate = iconFrame.OnIconTick --icon:GetScript("OnUpdate")
icon:SetScript("OnUpdate", function(self)
if self.timeRemaining <= 0 then
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] = -1 -- fallback to remove icons that have run out
end
self.parentIconRow.OnIconTick(self) --curOnUpdate(self)
end)
]]
icon.Texture:SetDesaturated(false)
end
local endTime = timer and (start + timer) or nil
if not nextUpdateTime or (endTime and endTime < nextUpdateTime) then
nextUpdateTime = endTime
end
--check if Masque is enabled on Plater and reskin the aura icon
if (Plater.Masque and not icon.Masqued) then
local t = {
FloatingBG = nil, --false,
Icon = icon.Texture,
Cooldown = icon.Cooldown,
Flash = nil, --false,
Pushed = nil, --false,
Normal = false,
Disabled = nil, --false,
Checked = nil, --false,
Border = nil, --icon.Border,
AutoCastable = nil, --false,
Highlight = nil, --false,
HotKey = nil, --false,
Count = false,
Name = nil, --false,
Duration = false,
Shine = nil, --false,
}
icon.Border:Hide() --let Masque handle the border...
Plater.Masque.BossModIconFrame:AddButton (icon, t)
Plater.Masque.BossModIconFrame:ReSkin()
icon.Masqued = true
end
end
end
end
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] = nextUpdateTime
Plater.EndLogPerformanceCore("Plater-Core", "Update", "UpdateBossModAuras")
end
--callbacks
local function Callback_DBM_ShowAura(_, is_guid, unit, texture, duration, desaturate, isPriority)
local guid = (is_guid == true or is_guid == 'guid') and unit or UnitGUID(unit)
ShowNameplateAura(guid, texture, duration, desaturate, isPriority)
end
local function Callback_DBM_HideNameplateAura(_, is_guid, unit, texture)
local guid = (is_guid == true or is_guid == 'guid') and unit or UnitGUID(unit)
HideNameplateAura(guid, texture)
end
local function Callback_DBM_DisableHostile()
DisableHostile()
end
local function Callback_DBM_EnableHostile()
EnableHostile()
end
local function Callback_BW_ShowAura(guid, texture, duration, desaturate)
ShowNameplateAura(guid, texture, duration, desaturate, isPriority)
end
local function Callback_BW_HideNameplateAura(guid, texture)
HideNameplateAura(guid, texture)
end
local function Callback_BW_DisableHostile()
DisableHostile()
end
local function Callback_BW_EnableHostile()
EnableHostile()
end
function Plater.RegisterBossModAuras()
if IS_REGISTERED then return end
if Plater.db.profile.bossmod_support_enabled then
if DBM and DBM.RegisterCallback then
DBM:RegisterCallback('BossMod_ShowNameplateAura',Callback_DBM_ShowAura)
DBM:RegisterCallback('BossMod_HideNameplateAura',Callback_DBM_HideNameplateAura)
DBM:RegisterCallback('BossMod_EnableHostileNameplates',Callback_DBM_EnableHostile)
DBM:RegisterCallback('BossMod_DisableHostileNameplates',Callback_DBM_DisableHostile)
end
if BigWigsLoader and BigWigsLoader.RegisterMessage then
--[[
BigWigsLoader.RegisterMessage(Plater,'BigWigs_ShowNameplateAura',function(_,_,...)
Callback_ShowAura(select(5,...),...)
end)
BigWigsLoader.RegisterMessage(Plater,'BigWigs_HideNameplateAura',function(_,_,...)
Callback_HideNameplateAura(select(3,...),...)
end)
]]--
BigWigsLoader.RegisterMessage(Plater,'BigWigs_AddNameplateIcon',Callback_BW_ShowAura)
BigWigsLoader.RegisterMessage(Plater,'BigWigs_RemoveNameplateIcon', Callback_BW_HideNameplateAura)
BigWigsLoader.RegisterMessage(Plater,'BigWigs_EnableHostileNameplates', Callback_BW_EnableHostile)
BigWigsLoader.RegisterMessage(Plater,'BigWigs_DisableHostileNameplates', Callback_BW_DisableHostile)
end
end
IS_REGISTERED = true
end
function Plater.GetBossModsEventTimeLeft(spell) -- more or less deprecated, need to know how to get this information from bigwigs
if (_G.DBM) then
for bar, _ in _G.DBM.Bars:GetBarIterator() do
if (not bar.dead and bar.frame:IsShown()) then
if (bar.id:find(spell)) then
return bar.timer, bar.totalTime, bar.id, _G[bar.frame:GetName() .. "BarName"]:GetText()
end
end
end
end
if (BigWigsLoader) then
end
end
---@class plater_altcastbarconfig : table
---@field iconTexture string
---@field iconTexcoord table
---@field iconAlpha number
---@field text string
---@field texture any
---@field color any
---@field isChanneling boolean
---@field canInterrupt boolean
---@field height number
---@field iconSize number
---@field textSize number
---@field spellNameAnchor df_anchor
---@field timerAnchor df_anchor
---@field iconAnchor df_anchor
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> spell prediction
function Plater.GetAltCastBarAltId(plateFrame)
--check if the nameplate is valid
if (not plateFrame or not plateFrame.unitFrame) then
return
end
return plateFrame.unitFrame.castBar2.altCastId
end
function Plater.ClearAltCastBar(plateFrame)
--check if the nameplate is valid
if (not plateFrame or not plateFrame.unitFrame) then
return
end
local castBar2 = plateFrame.unitFrame.castBar2
castBar2.altCastId = nil
castBar2:Hide()
end
function Plater.SetAltCastBar(plateFrame, configTable, timer, startedAt, altCastId)
---@cast configTable plater_altcastbarconfig
--check if the nameplate is valid
if (not plateFrame or not plateFrame.unitFrame) then
return
end
local castBar = plateFrame.unitFrame.castBar2
castBar.CastBarEvents = {}
--> just update the current value since it wasn't running its tick function during the hide state
--> everything else should be in the correct state
castBar.OnShow = function (self)
self.flashTexture:Hide()
if (self.unit) then
if (self.casting) then
self.value = GetTime() - self.spellStartTime
if self.value > self.maxValue then
self:Hide()
return
end
self:RunHooksForWidget ("OnShow", self, self.unit)
elseif (self.channeling) then
self.value = self.spellEndTime - GetTime()
if self.value < 0 then
self:Hide()
return
end
self:RunHooksForWidget ("OnShow", self, self.unit)
end
end
end
--reset the castbar
castBar.Icon:ClearAllPoints()
castBar.Icon:SetPoint("right", castBar, "left", -1, 0)
castBar:ClearAllPoints()
castBar:SetPoint("topleft", plateFrame.unitFrame.castBar, "bottomleft", 0, -2)
castBar:SetPoint("topright", plateFrame.unitFrame.castBar, "bottomright", 0, -2)
castBar.percentText:ClearAllPoints()
castBar.percentText:SetPoint ("right", castBar, "right", -2, 0)
castBar.Text:ClearAllPoints()
castBar.Text:SetPoint ("left", castBar, "left", 2, 0)
--set the unit
castBar:SetUnit(plateFrame.unitFrame.unit)
castBar.altCastId = altCastId
--set spell name
castBar.Text:SetText(configTable.text)
--set texture
castBar.Icon:SetTexture(configTable.iconTexture or "")
if (configTable.iconTexcoord) then
castBar.Icon:SetTexCoord(unpack(configTable.iconTexcoord))
else
castBar.Icon:SetTexCoord(0.1, 0.9, 0.1, 0.9)
end
castBar.Icon:SetAlpha(configTable.iconAlpha or 1)
castBar.Icon:Show()
castBar.percentText:Show()
castBar:SetHeight(configTable.height or 12)
if (configTable.iconSize) then
castBar.Icon:SetSize(configTable.iconSize, configTable.iconSize)
else
castBar.Icon:SetSize(castBar:GetHeight(), castBar:GetHeight())
end
castBar.Spark:Show()
if (configTable.spellNameAnchor) then
Plater.SetAnchor(castBar.Text, configTable.spellNameAnchor)
end
if (configTable.timerAnchor) then
Plater.SetAnchor(castBar.percentText, configTable.timerAnchor)
end
if (configTable.iconAnchor) then
Plater.SetAnchor(castBar.Icon, configTable.iconAnchor)
end
DF:SetFontSize(castBar.Text, configTable.textSize or 10)
DF:SetFontSize(castBar.percentText, configTable.textSize or 10)
local startTime
if (startedAt) then
startTime = startedAt
else
startTime = GetTime()
end
local endTime = startTime + timer
if (configTable.isChanneling) then
castBar.casting = nil
castBar.channeling = true
castBar.spellStartTime = startTime
castBar.spellEndTime = endTime
castBar.SpellStartTime = startTime
castBar.SpellEndTime = endTime
castBar.value = endTime - GetTime()
castBar.maxValue = endTime - startTime
castBar:SetMinMaxValues(0, castBar.maxValue)
castBar:SetValue(castBar.value)
else
castBar.casting = true
castBar.channeling = nil
castBar.spellStartTime = startTime
castBar.spellEndTime = endTime
castBar.SpellStartTime = startTime
castBar.SpellEndTime = endTime
castBar.value = GetTime() - startTime
castBar.maxValue = endTime - startTime
castBar:SetMinMaxValues(0, castBar.maxValue)
castBar:SetValue(castBar.value)
end
castBar.finished = false
castBar.canInterrupt = configTable.canInterrupt
castBar:SetColor(configTable.color or "yellow")
castBar.spellName = configTable.text
castBar.spellID = 1
castBar.spellTexture = configTable.iconTexture or ""
castBar:SetStatusBarTexture(configTable.texture or [[Interface\AddOns\Plater\images\bar_background]])
castBar.flashTexture:Hide()
castBar:Animation_StopAllAnimations()
Plater.CastBarOnEvent_Hook(castBar, "UNIT_SPELLCAST_START", plateFrame.unitFrame.unit, plateFrame.unitFrame.unit)
if (not castBar:IsShown()) then
castBar:Animation_FadeIn()
castBar:Show()
end
end
function Plater.StopAltCastBar(plateFrame)
--check if the nameplate is valid
if (not plateFrame or not plateFrame.unitFrame) then
return
end
local castBar = plateFrame.unitFrame.castBar2
castBar.CastBarEvents = {}
castBar:SetUnit(nil)
castBar.altCastId = nil
castBar.Text:SetText("")
if (castBar:IsShown()) then
castBar:Animation_FadeOut()
castBar:Hide()
end
end
function TESTPlater()
local plateFrame = C_NamePlate.GetNamePlateForUnit ("target")
local config = {
iconTexture = "Interface\\CHARACTERFRAME\\Button_BloodPresence_DeathKnight",
--iconTexcoord = {0, 1, 0, 1},
iconAlpha = 1,
text = "Test Cast Bar",
texture = "Interface\\CHARACTERFRAME\\UI-BarFill-Simple",
color = "pink",
isChanneling = false,
canInterrupt = true,
}
local timer = 5
Plater.SetAltCastBar(plateFrame, config, timer)
end
--SETTINGS
local prediction_time_to_show = 3
local triggerCastBar = function(timerObject)
--get the bar timer id
local timerId = timerObject.timerId
local barInfo = Plater.BossModsTimeBar[timerId]
--check if the bar still exists
if (not barInfo) then
--print("there no bar information for", timerId)
return
end
local bar = DBM.Bars:GetBar(timerId)
if (not bar) then
--print("DBM returned nil for GetBar", timerId)
return
end
--the nameplate to attach the cast bar
local plateFrame
if (timerObject.findUnitBySpellId) then
--find the mob responsible for cast the ability
plateFrame = C_NamePlate.GetNamePlateForUnit("target") --debug
elseif (timerObject.attachToCurrentTarget) then
plateFrame = C_NamePlate.GetNamePlateForUnit("target")
end
if (not plateFrame) then
return
end
--set the castbar config
local config = {
iconTexture = barInfo[5],
iconTexcoord = {0.1, 0.9, 0.1, 0.9},
iconAlpha = 1,
text = barInfo[3],
texture = [[Interface\AddOns\Plater\images\bar_background]],
color = "silver",
isChanneling = false,
canInterrupt = false,
height = Plater.db.profile.spell_prediction.castbar_height,
}
--show the cast bar
Plater.SetAltCastBar(plateFrame, config, prediction_time_to_show)
DF:TruncateText(plateFrame.unitFrame.castBar2.Text, plateFrame.unitFrame.castBar:GetWidth() - 28)
DF:SetFontSize(plateFrame.unitFrame.castBar2.Text, 10)
end
function Plater.GetBossTimer(spellId)
for id, barInfo in pairs (Plater.BossModsTimeBarDBM) do
if ((barInfo.spellId == spellId) or (type(id) == "string" and id:find(spellId))) then
return DF.table.copy({}, barInfo)
end
end
for id, barInfo in pairs (Plater.BossModsTimeBarBW) do
if ((barInfo.spellId == spellId) or (id == spellId)) then
return DF.table.copy({}, barInfo)
end
end
end
local function getDBTColor(colorId)
if DBT and DBT.Options then
local barOptions = DBT.Options
local barStartRed, barStartGreen, barStartBlue
if colorId and colorId >= 1 then
if colorId == 1 then--Add
barStartRed, barStartGreen, barStartBlue = barOptions.StartColorAR, barOptions.StartColorAG, barOptions.StartColorAB
elseif colorId == 2 then--AOE
barStartRed, barStartGreen, barStartBlue = barOptions.StartColorAER, barOptions.StartColorAEG, barOptions.StartColorAEB
elseif colorId == 3 then--Debuff
barStartRed, barStartGreen, barStartBlue = barOptions.StartColorDR, barOptions.StartColorDG, barOptions.StartColorDB
elseif colorId == 4 then--Interrupt
barStartRed, barStartGreen, barStartBlue = barOptions.StartColorIR, barOptions.StartColorIG, barOptions.StartColorIB
elseif colorId == 5 then--Role
barStartRed, barStartGreen, barStartBlue = barOptions.StartColorRR, barOptions.StartColorRG, barOptions.StartColorRB
elseif colorId == 6 then--Phase
barStartRed, barStartGreen, barStartBlue = barOptions.StartColorPR, barOptions.StartColorPG, barOptions.StartColorPB
elseif colorId == 7 then--Important
barStartRed, barStartGreen, barStartBlue = barOptions.StartColorUIR, barOptions.StartColorUIG, barOptions.StartColorUIB
end
else
barStartRed, barStartGreen, barStartBlue = barOptions.StartColorR, barOptions.StartColorG, barOptions.StartColorB
end
return {barStartRed, barStartGreen, barStartBlue, 1}
end
return {1, 1, 1, 1}
end
local function getAllShownGUIDs()
local guids = {}
for _, plateFrame in ipairs (Plater.GetAllShownPlates()) do
if plateFrame.unitFrame.PlaterOnScreen then
tinsert(guids, plateFrame.namePlateUnitGUID)
end
end
return guids
end
function Plater.PauseBarIcon(name)
if not name then return end
local curTime = GetTime()
for id,entry in pairs(Plater.BossModsTimeBarDBM) do
if entry.msg == name then
--print("yes", entry.paused, id)
if not entry.paused then
entry.paused = true
entry.pauseStartTime = curTime
--UNIT_BOSS_MOD_BARS [entry.guid][id].paused = true
--UNIT_BOSS_MOD_BARS [entry.guid][id].pauseStartTime = curTime
else
entry.paused = false
entry.start = entry.start + (curTime - entry.pauseStartTime)
entry.pauseStartTime = entry.start
--UNIT_BOSS_MOD_BARS [entry.guid][id].paused = false
--UNIT_BOSS_MOD_BARS [entry.guid][id].start = entry.start + (curTime - entry.pauseStartTime)
--UNIT_BOSS_MOD_BARS [entry.guid][id].pauseStartTime = entry.start
end
--print(name, entry.msg, entry.msg == name, entry.guid)
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[entry.guid] = -1
end
end
end
function Plater.UpdateBarIcon(name, elapsed, totalTime)
if not name then return end
local curTime = GetTime()
for id,entry in pairs(Plater.BossModsTimeBarDBM) do
if entry.msg == name then
entry.timer = totalTime
entry.start = curTime - elapsed
if entry.paused then
entry.pauseStartTime = curTime
end
--print(name, entry.msg, entry.msg == name, entry.guid)
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[entry.guid] = -1
end
end
end
function Plater.KeepBarIcon(name)
if not name then return end
for id,entry in pairs(Plater.BossModsTimeBarDBM) do
if entry.msg == name then
entry.keep = not entry.keep
--print(name, entry.msg, entry.msg == name, entry.guid)
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[entry.guid] = -1
end
end
end
function Plater.RegisterBossModsBars()
local DBM = _G.DBM
local BigWigsLoader = _G.BigWigsLoader
--check if Deadly Boss Mods is installed
if (DBM) then
--timer start
local timerStartCallback = function(event, id, msg, timer, icon, barType, spellId, colorId, modId, keep, fade, name, guid, timerCount, isPriority)
if event ~= "DBM_NameplateStart" and not (DBM_TIMER_BARS_TEST_MODE and event == "DBM_TimerStart") then return end
if (id and guid) then
local color = getDBTColor(colorId)
local display = DF:CleanTruncateUTF8String(strsub(string.match(name or msg or "", "^%s*(.-)%s*$" ), 1, Plater.db.profile.bossmod_support_bars_text_max_len or 7))
--local display = string.match(name or msg or "", "^%s*(.-)%s*$" )
local curTime = GetTime()
---@type dbmtimerbar
local barData = {
msg = msg,
display = display or name or msg or "",
id = id,
timer = timer,
start = curTime,
icon = icon,
spellId = spellId,
barType = barType or "cdnp",
color = color,
colorId = colorId,
modId = modId,
keep = keep,
fade = fade,
name = name,
guid = guid,
timerCount = timerCount,
isPriority = isPriority,
paused = false,
}
Plater.BossModsTimeBarDBM[id] = barData
UNIT_BOSS_MOD_BARS [guid] = UNIT_BOSS_MOD_BARS [guid] or {}
UNIT_BOSS_MOD_BARS [guid][id] = barData
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] = -1
elseif id and not guid and DBM_TIMER_BARS_TEST_MODE then
for _, guid in pairs(getAllShownGUIDs()) do
id = id .. guid
local color = getDBTColor(colorId)
local display = DF:CleanTruncateUTF8String(strsub(string.match(name or msg or "", "^%s*(.-)%s*$" ), 1, Plater.db.profile.bossmod_support_bars_text_max_len or 7))
--local display = string.match(name or msg or "", "^%s*(.-)%s*$" )
local curTime = GetTime()
---@type dbmtimerbar
local barData = {
msg = msg,
display = display or name or msg or "",
id = id,
timer = timer,
start = curTime,
icon = icon,
spellId = spellId,
barType = barType,
color = color,
colorId = colorId,
modId = modId,
keep = keep,
fade = fade,
name = name,
guid = guid,
timerCount = timerCount,
isPriority = isPriority,
paused = false,
}
Plater.BossModsTimeBarDBM[id] = barData
UNIT_BOSS_MOD_BARS [guid] = UNIT_BOSS_MOD_BARS [guid] or {}
UNIT_BOSS_MOD_BARS [guid][id] = barData
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] = -1
end
end
end
DBM:RegisterCallback("DBM_NameplateStart", timerStartCallback)
local timerUpdateCallback = function(event, id, elapsed, totalTime)
if event ~= "DBM_NameplateUpdate" then return end
if not id or not elapsed or not totalTime then return end
local entry = id and Plater.BossModsTimeBarDBM[id] or nil
local guid = entry and entry.guid
local curTime = GetTime()
if entry and guid then
entry.timer = totalTime
entry.start = curTime - elapsed
if entry.paused then
entry.pauseStartTime = curTime
end
UNIT_BOSS_MOD_NEEDS_UPDATE_IN[guid] = -1
end
end
DBM:RegisterCallback("DBM_NameplateUpdate", timerUpdateCallback)