forked from Dicebar/Raven
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Bars.lua
2179 lines (2044 loc) · 119 KB
/
Bars.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
-- Raven is an addon to monitor auras and cooldowns, providing timer bars and icons plus helpful notifications.
-- Bars.lua supports mapping auras to bars and grouping bars into multiple moveable frames.
-- It has special case code for tooltips, test bars, shaman totems, and death knight runes.
-- There are no exported functions at this time other than those called to initialize and update bars.
local MOD = Raven
local SHIM = MOD.SHIM
local L = LibStub("AceLocale-3.0"):GetLocale("Raven")
local LSPELL = MOD.LocalSpellNames
local media = LibStub("LibSharedMedia-3.0")
local wc = { r = 1, g = 1, b = 1, a = 1 }
local rc = { r = 1, g = 0, b = 0, a = 1 }
local vc = { r = 1, g = 0, b = 0, a = 0 }
local zc = { r = 1, g = 1, b = 1, a = 0 }
local gc = { r = 0.5, g = 0.5, b = 0.5, a = 0.5 }
local hidden = false
local detectedBar = {}
local headerBar = {}
local groupIDs = {}
local settingsTemplate = {} -- settings are initialized from default bar group template
local activeSpells = {} -- temporary table used for finding ghost bars
local defaultNotificationIcon = "Interface\\Icons\\Spell_Nature_WispSplode"
local defaultBrokerIcon = "Interface\\Icons\\Inv_Misc_Book_03"
local defaultValueIcon = "Interface\\Icons\\Inv_Jewelry_Ring_03"
local defaultTestIcon = "Interface\\Icons\\Spell_Nature_RavenForm"
local frequentBars = {} -- bars tagged for frequent updates
local prefixRaidTargetIcon = "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_"
local testColors = { "Blue1", "Cyan", "Green1", "Yellow1", "Orange1", "Red1", "Pink", "Purple1", "Brown1", "Gray" }
local tabardIcon
local units = { player = true, target = true, focus = true, pet = true, targettarget = true, focustarget = true, pettarget = true, mouseover = true }
-- Saved variables don't handle being set to nil properly so need to use alternate value to indicate an option has been turned off
local Off = 0 -- value used to designate an option is turned off
local function IsOff(value) return value == nil or value == Off end -- return true if option is turned off
local function IsOn(value) return value ~= nil and value ~= Off end -- return true if option is turned on
local colorTemplate = { timeColor = 0, iconColor = 0, labelColor = 0, backdropColor = 0, backdropFill = 0, borderColor = 0, } -- colors in default fonts and textures
local function DefaultColor(c) return not c or not next(c) or ((c.r == 1) and (c.g == 1) and (c.b == 1) and (c.a == 1)) end
local defaultLabels = { 0, 1, 10, 30, "1m", "2m", "5m" }
function MOD:GetTimelineLabels() return defaultLabels end
MOD.BarGroupTemplate = { -- default bar group settings
enabled = true, locked = true, merged = false, linkSettings = false, linkBars = false, checkCondition = false, noMouse = false, iconMouse = true,
barColors = "Spell", bgColors = "Normal", iconColors = "None", combatTips = true,
casterTips = true, spellTips = false, casterLabels = false, spellLabels = false, anchorTips = "DEFAULT",
useDefaultDimensions = true, useDefaultFontsAndTextures = true, useDefaultColors = true, useDefaultTimeFormat = false, strata = "MEDIUM",
sor = "A", reverseSort = false, timeSort = true, playerSort = false,
configuration = 1, anchor = false, anchorX = 0, anchorY = 0, anchorLastBar = false, anchorRow = false, anchorColumn = true, anchorEmpty = false,
growDirection = true, fillBars = false, segmentBars = false, wrap = 0, wrapDirection = false, snapCenter = false, maxBars = 0,
segmentCount = 10, segmentOverride = false, segmentSpacing = 1, segmentHideEmpty = false,
segmentAdvanced = false, segmentCurve = 0, segmentRotate = 0, segmentTexture = false,
segmentFadePartial = false, segmentShrinkWidth = false, segmentShrinkHeight = false, segmentGradient = false, segmentGradientAll = false,
disableBGSFX = false, customizeSFX = false, shineColor = false, sparkleColor = false, glowColor = false,
expireFGBG = false, flashPeriod = 1.2, flashPercent = 50, combatTextExcludesBG = false,
shineStart = false, sparkleStart, pulseStart = false, glowStart = false, flashStart = false, desatStart = false,
shineExpiring = false, sparkleExpiring = false, pulseExpiring = false, glowExpiring = false, flashExpiring = false, desatExpiring = false,
startEffectTime = 5, endEffectTime = 5, delayTime = 0,
combatStart = false, combatCriticalStart = false, expireMSBT = false, criticalMSBT = false,
combatEnd = false, combatCriticalEnd = false, combatReady = false, combatCriticalReady = false,
shineReady = false, sparkleReady = false, pulseReady = false, glowReady = false, flashReady = false, desaturateReadyIcon = false,
shineEnd = false, sparkleEnd = false, pulseEnd = false, splash = false, ghost = false, hide = false, fade = false,
bgNormalAlpha = 1, bgCombatAlpha = 1, mouseAlpha = 1, fadeAlpha = 1, testTimers = 10, testStatic = 0, testLoop = false,
soundSpellStart = false, soundSpellEnd = false, soundSpellExpire = false, soundSpellReady = false,
soundAltStart = "None", soundAltEnd = "None", soundAltExpire = "None", soundAltReady = "None",
labelOffset = 0, labelInset = 0, labelWrap = false, labelCenter = false, labelAlign = "MIDDLE", labelAdjust = true, labelAuto = true, labelWidth = 100,
timeOffset = 0, timeInset = 0, timeAlign = "normal", timeIcon = false, iconOffset = 0, iconInset = 0, iconHide = false, iconAlign = "CENTER",
flashTime = 5, expirePercentage = 0, expireMinimum = 0, colorExpiring = false, clockReverse = true,
expireColor = false, expireLabelColor = false, expireTimeColor = false, tickColor = false,
combatColorStart = false, combatColorEnd = false, combatColorReady = false, colorMSBT = false,
spellExpireTimes = false, spellExpireColors = false, desaturate = false, desaturateFriend = false, disableAlpha = false,
timelineWidth = 225, timelineHeight = 25, timelineDuration = 300, timelineExp = 3, timelineHide = false, timelineAlternate = true,
timelineSwitch = 2, timelineTexture = "Blizzard", timelineAlpha = 1, timelineColor = false, timelineLabels = false,
timelineBorderTexture = "None", timelineBorderWidth = 4, timelineBorderOffset = 1, timelineBorderColor = false,
timelineSplash = true, timelineSplashX = 0, timelineSplashY = 0, timelinePercent = 50, timelineOffset = 0, timelineDelta = 0,
stripeFullWidth = false, stripeWidth = 500, stripeHeight = 30, stripeInset = 0, stripeOffset = 0, stripeTexture = "Blizzard",
stripeBarInset = 4, stripeBarOffset = 0, stripeColor = false, stripeAltColor = false, stripeCheckCondition = false, stripeCondition = false,
stripeBorderTexture = "None", stripeBorderWidth = 4, stripeBorderOffset = 1, stripeBorderColor = false,
showSolo = true, showParty = true, showRaid = true, showCombat = true, showOOC = true, showStealth = true, showFocusTarget = true,
showInstance = true, showNotInstance = true, showArena = true, showBattleground = true, showPetBattle = false, showOnTaxi = true, showSpecialization = "",
showResting = true, showMounted = true, showVehicle = true, showFriend = true, showEnemy = true, showNeutral = true, showBlizz = true, showNotBlizz = true,
detectBuffs = false, detectDebuffs = false, detectAllBuffs = false, detectAllDebuffs = false,
filterDebuffTypes = false, detectDispellable = false, detectInflictable = false, detectNPCDebuffs = false, detectVehicleDebuffs = false, detectBossDebuffs = false,
detectEffectDebuffs = false, detectAlertDebuffs = false, detectPoison = false, detectCurse = false, detectMagic = false, detectDisease = false, detectOtherDebuffs = false,
excludeDebuffTypes = true, excludeDispellable = false, excludeInflictable = false, excludeNPCDebuffs = false, excludeVehicleDebuffs = false, excludeBossDebuffs = false,
excludeEffectDebuffs = false, excludeAlertDebuffs = true, excludePoison = false, excludeCurse = false, excludeMagic = false, excludeDisease = false, excludeOtherDebuffs = false,
noHeaders = false, noTargets = false, noLabels = false, headerGaps = false, targetFirst = false, targetAlpha = 1, replay = false, replayTime = 5,
detectBuffTypes = false, detectCastable = false, detectStealable = false, detectMagicBuffs = false, detectEffectBuffs = false, detectAlertBuffs = false,
detectWeaponBuffs = false, detectNPCBuffs = false, detectVehicleBuffs = false, detectBossBuffs = false, detectEnrageBuffs = false, detectTracking = false,
detectResources = false, detectMountBuffs = false, detectTabardBuffs = false, detectMinionBuffs = false, detectOtherBuffs = false,
excludeBuffTypes = true, excludeCastable = false, excludeStealable = false, excludeMagicBuffs = false, excludeEffectBuffs = false, excludeAlertBuffs = true,
excludeWeaponBuffs = false, excludeNPCBuffs = false, excludeVehicleBuffs = false, excludeBossBuffs = false, excludeEnrageBuffs = false, excludeTracking = true,
excludeResources = false, excludeMountBuffs = false, excludeTabardBuffs = false, excludeMinionBuffs = true, excludeOtherBuffs = false,
detectCooldowns = false, detectBuffsMonitor = "player", detectBuffsCastBy = "player", detectDebuffsMonitor = "player",
detectDebuffsCastBy = "player", detectCooldownsBy = "player",
detectSpellCooldowns = true, detectTrinketCooldowns = true, detectInternalCooldowns = true, includeTotems = false,
detectSpellEffectCooldowns = true, detectSpellAlertCooldowns = false, detectPotionCooldowns = true, detectOtherCooldowns = true, detectRuneCooldowns = false, detectGlobalCooldown = true,
detectSharedGrimoires = true, detectSharedInfernals = true,
setDuration = false, setOnlyLongDuration = false, uniformDuration = 120, checkDuration = false, minimumDuration = true, filterDuration = 120,
checkTimeLeft = false, minimumTimeLeft = true, filterTimeLeft = 120, showNoDuration = false, showOnlyNoDuration = false,
showNoDurationBackground = false, readyReverse = false, noDurationFirst = false, timeFormat = 6, timeSpaces = false, timeCase = false,
filterBuff = true, filterBuffLink = true, filterBuffSpells = false, filterBuffTable = nil,
filterBuffSpells2 = false, filterBuffTable2 = nil, filterBuffSpells3 = false, filterBuffTable3 = nil,
filterBuffSpells4 = false, filterBuffTable4 = nil, filterBuffSpells5 = false, filterBuffTable5 = nil,
filterDebuff = true, filterDebuffLink = true, filterDebuffSpells = false, filterDebuffTable = nil,
filterDebuffSpells2 = false, filterDebuffTable2 = nil, filterDebuffSpells3 = false, filterDebuffTable3 = nil,
filterDebuffSpells4 = false, filterDebuffTable4 = nil, filterDebuffSpells5 = false, filterDebuffTable5 = nil,
filterCooldown = true, filterCooldownLink = true, filterCooldownSpells = false, filterCooldownTable = nil,
filterCooldownSpells2 = false, filterCooldownTable2 = nil, filterCooldownSpells3 = false, filterCooldownTable3 = nil,
filterCooldownSpells4 = false, filterCooldownTable4 = nil, filterCooldownSpells5 = false, filterCooldownTable5 = nil,
showBuff = false, showDebuff = false, showCooldown = false, filterBuffBars = false, filterDebuffBars = false, filterCooldownBars = false,
selectAll = true, selectPlayer = false, selectPet = false, selectBoss = false, selectDispel = false, selectSteal = false,
selectPoison = false, selectCurse = false, selectMagic = false, selectDisease = false, selectEnrage = false,
}
MOD.BarGroupLayoutTemplate = { -- all the bar group settings involved in layout configuration
barWidth = 0, barHeight = 0, iconSize = 0, scale = 0, spacingX = 0, spacingY = 0, iconOffsetX = 0, iconOffsetY = 0,
useDefaultDimensions = 0, configuration = 0, growDirection = 0, wrap = 0, wrapDirection = 0, snapCenter = 0, segmentBars = 0, fillBars = 0, maxBars = 0,
segmentCount = 0, segmentOverride = 0, segmentSpacing = 0, segmentHideEmpty = 0, segmentFadePartial = 0,
segmentShrinkWidth = 0, segmentShrinkHeight = 0, segmentGradient = 0, segmentGradientAll = 0,
segmentAdvanced = 0, segmentCurve = 0, segmentRotate = 0, segmentTexture = 0,
labelOffset = 0, labelInset = 0, labelWrap = 0, labelCenter = 0, labelAlign = 0, labelAdjust = 0, labelAuto = 0, labelWidth = 0,
timeOffset = 0, timeInset = 0, timeAlign = 0, timeIcon = 0, iconOffset = 0, iconInset = 0, iconHide = 0, iconAlign = 0,
hideIcon = 0, hideClock = 0, hideBar = 0, hideSpark = 0, hideValue = 0, hideLabel = 0, hideCount = 0, showTooltips = 0,
timelineWidth = 0, timelineHeight = 0, timelineDuration = 0, timelineExp = 0, timelineHide = 0, timelineAlternate = 0,
timelineSwitch = 0, timelineTexture = 0, timelineAlpha = 0, timelineColor = 0, timelineLabels = 0,
timelineBorderTexture = 0, timelineBorderWidth = 0, timelineBorderOffset = 0, timelineBorderColor = 0,
timelineSplash = 0, timelineSplashX = 0, timelineSplashY = 0, timelinePercent = 0, timelineOffset = 0, timelineDelta = 0,
stripeFullWidth = 0, stripeWidth = 0, stripeHeight = 0, stripeInset = 0, stripeOffset = 0, stripeTexture = 0,
stripeBarInset = 0, stripeBarOffset = 0, stripeColor = 0, stripeAltColor = 0, stripeCheckCondition = 0, stripeCondition = 0,
stripeBorderTexture = 0, stripeBorderWidth = 0, stripeBorderOffset = 0, stripeBorderColor = 0,
}
-- Check for active tooltip for a bar and update once per second
local function BarTooltipUpdate()
if MOD.tooltipBar and MOD.Bar_OnUpdate then MOD.Bar_OnUpdate(MOD.tooltipBar) end
end
-- Initialize bar groups from those specified in the profile after, for example, a reloadUI or reset profile
function MOD:InitializeBars()
local bgs = MOD.Nest_GetBarGroups()
if bgs then for _, bg in pairs(bgs) do MOD.Nest_DeleteBarGroup(bg) end end -- first remove any bar groups represented in the graphics library
for _, bg in pairs(MOD.db.profile.BarGroups) do -- then set up the ones specified in the profile
if IsOn(bg) then
for n, k in pairs(MOD.db.global.Defaults) do -- add default settings for layout, fonts and textures
if bg[n] == nil then -- only add ones not already set in the bar group's profile
if colorTemplate[n] then bg[n] = MOD.CopyColor(k) else bg[n] = k end -- colors must be handled specially
end
end
for n, k in pairs(MOD.BarGroupTemplate) do if bg[n] == nil then bg[n] = k end end -- add additional default values from the bar group template
MOD:InitializeBarGroup(bg, 0, 0)
if not bg.auto then for _, bar in pairs(bg.bars) do bar.startReady = nil end end -- remove extra settings in custom bars
end
end
MOD:UpdateAllBarGroups() -- this is done last to get all positions updated correctly
MOD.tooltipBar = nil -- set when showing a tooltip for a bar
C_Timer.NewTicker(0.5, BarTooltipUpdate) -- update tooltips for bars when hovering over them
end
-- Finalize bar groups prior to logout, stripping out all values that match current defaults
function MOD:FinalizeBars()
for bn, bg in pairs(MOD.db.profile.BarGroups) do
if IsOn(bg) then
bg.cache = nil -- delete bar group cache contents
for n, k in pairs(MOD.db.global.Defaults) do if bg[n] == k then bg[n] = nil end end -- remove default settings for layout, fonts and textures
for n, k in pairs(MOD.BarGroupTemplate) do if bg[n] == k then bg[n] = nil end end -- remove defaults from the bar group template
for n in pairs(colorTemplate) do if DefaultColor(bg[n]) then bg[n] = nil end end -- detect basic colors set to defaults
else
MOD.db.profile.BarGroups[bn] = nil -- okay to delete these since no default bar groups
end
end
end
-- Raven is disabled so hide all features
function MOD:HideBars()
if not hidden then
for _, bp in pairs(MOD.db.profile.BarGroups) do
if IsOn(bp) then MOD:ReleaseBarGroup(bp) end
end
hidden = true
end
end
-- Initialize bar group settings by adding default values if necessary
function MOD:InitializeSettings()
for n, k in pairs(MOD.BarGroupTemplate) do settingsTemplate[n] = k end -- initialize the settings template from bar group defaults
for n, k in pairs(MOD.db.global.Defaults) do settingsTemplate[n] = k end -- add default settings for layout-fonts-textures
settingsTemplate.enabled = nil; settingsTemplate.locked = nil; settingsTemplate.merged = nil; settingsTemplate.linkSettings = nil; settingsTemplate.linkBars = nil
for _, settings in pairs(MOD.db.global.Settings) do
for n, k in pairs(settingsTemplate) do if settings[n] == nil then settings[n] = k end end -- add missing defaults from settings template
for n in pairs(colorTemplate) do if settings[n] == nil then settings[n] = MOD.CopyColor(wc) end end -- default basic colors
end
end
-- Remove default values from bar group settings
function MOD:FinalizeSettings()
for _, settings in pairs(MOD.db.global.Settings) do
for n, k in pairs(settingsTemplate) do if settings[n] == k then settings[n] = nil end end -- remove values still set to defaults
for n in pairs(colorTemplate) do if DefaultColor(settings[n]) then settings[n] = nil end end -- detect basic colors set to defaults
end
end
-- Show tooltip when entering a bar group anchor
local function Anchor_OnEnter(anchor, bgName)
if GetCVar("UberTooltips") == "1" then
GameTooltip_SetDefaultAnchor(GameTooltip, anchor)
else
GameTooltip:SetOwner(anchor, "ANCHOR_BOTTOMLEFT")
end
local bg, bgType, attachment = MOD.Nest_GetBarGroup(bgName), L["Custom Bar Group"], nil
if bg then
if MOD.Nest_GetBarGroupAttribute(bg, "isAuto") then bgType = L["Auto Bar Group"] end
attachment = MOD.Nest_GetBarGroupAttribute(bg, "attachment")
end
GameTooltip:AddDoubleLine("Raven", bgType)
if attachment then
GameTooltip:AddLine(L["Anchor attached"] .. attachment .. '"')
GameTooltip:AddLine(L["Anchor left click 1"])
else
GameTooltip:AddLine(L["Anchor left click 2"])
end
GameTooltip:AddLine(L["Anchor right click"])
GameTooltip:AddLine(L["Anchor shift left click"])
GameTooltip:AddLine(L["Anchor shift right click"])
GameTooltip:AddLine(L["Anchor alt left click"])
GameTooltip:AddLine(L["Anchor alt right click"])
GameTooltip:Show()
end
-- Hide tooltip when leaving a bar group anchor
local function Anchor_OnLeave(anchor, bgName)
GameTooltip:Hide()
end
-- Callback function for tracking location of the bar group
local function Anchor_Moved(anchor, bgName)
local bp = MOD.db.profile.BarGroups[bgName]
if IsOn(bp) then
local bg = MOD.Nest_GetBarGroup(bgName)
if bg then
bp.pointX, bp.pointXR, bp.pointY, bp.pointYT, bp.pointW, bp.pointH = MOD.Nest_GetAnchorPoint(bg) -- returns fractions from display edge
if bp.anchor then bp.anchor = false end -- no longer anchored to other bar groups
if bp.linkSettings then
local settings = MOD.db.global.Settings[bp.name] -- when updating a bar group with linked settings always overwrite position
if settings then
settings.pointX = bp.pointX; settings.pointXR = bp.pointXR; settings.pointY = bp.pointY; settings.pointYT = bp.pointYT
settings.pointW = bp.pointW; settings.pointH = bp.pointH; settings.anchor = bp.anchor
end
end
Anchor_OnLeave(anchor) -- turn off tooltip while moving the anchor
MOD.updateOptions = true -- if options panel is open then update it in case viewing position info
end
return
end
end
-- Callback function for when a bar group anchor is clicked with a modifier key down
-- Shift left click is test bars, right click is "toggle lock and hide",
local function Anchor_Clicked(anchor, bgName, button)
local shiftLeftClick = (button == "LeftButton") and IsShiftKeyDown()
local shiftRightClick = (button == "RightButton") and IsShiftKeyDown()
local altLeftClick = (button == "LeftButton") and IsAltKeyDown()
local altRightClick = (button == "RightButton") and IsAltKeyDown()
local rightClick = (button == "RightButton")
local bp = MOD.db.profile.BarGroups[bgName]
if IsOn(bp) then
if shiftLeftClick then -- test bars
MOD:TestBarGroup(bp)
elseif shiftRightClick then -- toggle grow up/down
bp.growDirection = not bp.growDirection
elseif altLeftClick then -- toggle options menu
MOD:OptionsPanel()
elseif altRightClick then -- cycle through configurations
if bp.configuration > MOD.Nest_MaxBarConfiguration then -- special case order for cycling icon configurations
local c, i = bp.configuration, MOD.Nest_MaxBarConfiguration + 1
if c == i then c = i + 2 elseif c == (i + 1) then c = i + 3 elseif c == (i + 2) then c = i + 1 elseif c == (i + 3) then c = i
elseif c == (i + 4) then c = i + 5 elseif c == (i + 5) then c = i + 4 end
bp.configuration = c
else
bp.configuration = bp.configuration + 1
if bp.configuration == (MOD.Nest_MaxBarConfiguration + 1) then bp.configuration = 1 end
end
elseif rightClick then -- lock and hide
bp.locked = true
end
MOD:UpdateBarGroup(bp)
MOD.updateOptions = true -- if options panel is open then update it in case viewing configuration info
MOD:ForceUpdate()
return
end
end
-- Update linked settings. If dir is true then update the shared settings, otherwise update the bar group.
-- Also, if dir is true, create a linked settings table if one doesn't yet exist.
local function UpdateLinkedSettings(bp, dir)
local settings = MOD.db.global.Settings[bp.name]
if not settings then
if not dir then return end
settings = {}
MOD.db.global.Settings[bp.name] = settings
end
local p, q = settings, bp
if dir then p = q; q = settings end
for n in pairs(settingsTemplate) do q[n] = p[n] end -- copy every setting in the template
q.pointX = p.pointX; q.pointXR = p.pointXR; q.pointY = p.pointY; q.pointYT = p.pointYT -- always copy the location
q.pointW = p.pointW; q.pointH = p.pointH
if p.fgColor then q.fgColor = MOD.CopyColor(p.fgColor) else q.fgColor = nil end -- foreground and background custom colors must be hand copied
if p.bgColor then q.bgColor = MOD.CopyColor(p.bgColor) else q.bgColor = nil end
if p.iconBorderColor then q.iconBorderColor = MOD.CopyColor(p.iconBorderColor) else q.iconBorderColor = nil end
end
-- Update linked custom bars. If dir is true then update the shared bars, otherwise update the ones in the bar group.
-- Also, if dir is true, create a linked custom bars table if one doesn't yet exist.
local function UpdateLinkedBars(bp, dir)
if bp.auto then return end -- only applies to custom bar groups
local customBars = MOD.db.global.CustomBars[bp.name]
if not customBars then
if not dir then return end
customBars = {}
MOD.db.global.CustomBars[bp.name] = customBars
end
local p, q = customBars, bp.bars
if dir then p = q; q = customBars end
table.wipe(q) -- remove old bars from destination
for k, b in pairs(p) do q[k] = MOD.CopyTable(b) end -- deep copy each bar in the source
end
-- Update a linked filter list. If dir is true then update the shared list, otherwise update the bar group's list.
-- Also, if dir is true, create a linked filter list if one doesn't yet exist.
local function UpdateLinkedFilter(bp, dir, filterType)
local shared = MOD.db.global["Filter" .. filterType]
local bgname = "filter" .. filterType .. "List"
if not shared[bp.name] then
if not dir or not bp[bgname] or not next(bp[bgname], nil) then return end
shared[bp.name] = {}
end
if not bp[bgname] then bp[bgname] = {} end
local p, q = shared[bp.name], bp[bgname]
if dir then p = bp[bgname]; q = shared[bp.name] end
for _, v in pairs(q) do if not p[v] then q[v] = nil end end -- delete any keys in q not in p
for _, v in pairs(p) do if not q[v] then q[v] = v end end -- copy everything from p to q
end
-- Initialize a bar group from a shared filter list, if any.
-- This function is called whenever filterLink is changed.
function MOD:InitializeFilterList(bp, filterType)
if bp and bp["filter" .. filterType] and bp["filter" .. filterType .. "Link"] then
UpdateLinkedFilter(bp, false, filterType) -- use the shared settings, if any, for a linked layout
end
end
-- Get spell associated with a bar
function MOD:GetAssociatedSpellForBar(bar)
local bt = bar.barType
if bt == "Notification" then
local sp = bar.notifySpell
if not sp and not bar.unconditional and bar.action then sp = MOD:GetConditionSpell(bar.action) end
return sp
elseif bt == "Value" then
return bar.spell
end
return bar.action
end
-- Get icon for the spell associated with a bar, returns nil if none found
function MOD:GetIconForBar(bar)
local sp = MOD:GetAssociatedSpellForBar(bar)
if sp then return MOD:GetIcon(sp) end
return nil
end
-- Get color for the spell associated with a bar, returns nil if none found
function MOD:GetSpellColorForBar(bar)
local c = bar.color -- get override if one is set
local spc = nil
local sp = MOD:GetAssociatedSpellForBar(bar)
if sp then spc = MOD:GetColor(sp, bar.spellID) end -- associated spell's color, if any
if bar.barType == "Notification" then -- special case for notifications which can use an associated spell color
if bar.notColor then return c end -- not allowed to get color from associated spell
return spc or c -- prefer the associated spell color instead of the override color
end
return c or spc -- all other bar types only use color from associated spell if no override is set
end
-- Set the bar's current spell color using an override if not linked (note bar.colorLink uses inverted value from expected)
function MOD:SetSpellColorForBar(bar, r, g, b, a)
local c = bar.color -- check if using an override
if c then c.r = r; c.g = g; c.b = b; c.a = a; return end
local bt = bar.barType
local typeCheck = (bt == "Buff") or (bt == "Debuff") or (bt == "Cooldown")
if typeCheck and not bar.colorLink then -- set the shared color for bars with the same associated spell
local sp = MOD:GetAssociatedSpellForBar(bar)
if sp then c = MOD:GetColor(sp, bar.spellID) end
if c then c.r = r; c.g = g; c.b = b; c.a = a; return end
c = { r = r, g = g, b = b, a = a }
if sp then MOD:SetColor(sp, c) else bar.color = c end
else
bar.color = { r = r, g = g, b = b, a = a } -- create an override
end
end
-- Reset the bar's override color
function MOD:ResetSpellColorForBar(bar)
bar.color = nil
local bt = bar.barType
local typeCheck = (bt == "Buff") or (bt == "Debuff") or (bt == "Cooldown")
if typeCheck and not bar.colorLink then -- also reset the shared color for bars with the same associated spell
local sp = MOD:GetAssociatedSpellForBar(bar)
if sp then MOD:ResetColor(sp) end
end
end
-- Either link or decouple the bar's color from the color cache for it's associated spell
function MOD:LinkSpellColorForBar(bar)
local c = MOD:GetSpellColorForBar(bar)
if not bar.colorLink then -- link to the color cache, copying current setting, if any, to the color cache
if c and bar.color then local d = bar.color; c.r = d.r; c.g = d.g; c.b = d.b; c.a = d.a end
bar.color = nil -- delete override to revert back to color cache or default for bar type
else -- decouple from the color cached, copying current setting, if any, to a new override
if c then bar.color = { r = c.r, g = c.g, b = c.b, a = c.a } end
end
end
-- Get the right color for the bar based on bar group settings
local function GetColorForBar(bg, bar, btype)
local bt, c = bar.barType, nil
local scheme = bg.barColors
if scheme == "Spell" then
c = MOD:GetSpellColorForBar(bar)
elseif scheme == "Class" then
c = MOD.ClassColors[MOD.myClass] or wc
elseif scheme == "Custom" then
c = bg.fgColor or wc
end
if not c then -- get the best default color for this bar type
local cc = not bg.useDefaultColors -- indicates the bar group has overrides for standard colors
c = cc and bg.buffColor or MOD.db.global.DefaultBuffColor -- use this as default in case unrecognized bar type
if bt == "Debuff" then
c = cc and bg.debuffColor or MOD.db.global.DefaultDebuffColor
if btype then
if btype == "Poison" then c = cc and bg.poisonColor or MOD.db.global.DefaultPoisonColor end
if btype == "Curse" then c = cc and bg.curseColor or MOD.db.global.DefaultCurseColor end
if btype == "Magic" then c = cc and bg.magicColor or MOD.db.global.DefaultMagicColor end
if btype == "Disease" then c = cc and bg.diseaseColor or MOD.db.global.DefaultDiseaseColor end
end
end
if bt == "Cooldown" then c = cc and bg.cooldownColor or MOD.db.global.DefaultCooldownColor end
if bt == "Notification" then c = cc and bg.notificationColor or MOD.db.global.DefaultNotificationColor end
if bt == "Broker" then c = cc and bg.brokerColor or MOD.db.global.DefaultBrokerColor end
if bt == "Value" then c = cc and bg.valueColor or MOD.db.global.DefaultValueColor end
end
c.a = 1 -- always set alpha to 1 for bar colors
return c
end
-- Get the special debuff color for the bar
function MOD:GetSpecialColorForBar(bg, bar, btype)
local cc = not bg.useDefaultColors -- indicates the bar group has overrides for standard colors
local c = MOD.db.global.DefaultBorderColor -- no color applied if not a special type
local bt = bar.barType
if bt == "Debuff" then
if btype == "Poison" then
c = cc and bg.poisonColor or MOD.db.global.DefaultPoisonColor
elseif btype == "Curse" then
c = cc and bg.curseColor or MOD.db.global.DefaultCurseColor
elseif btype == "Magic" then
c = cc and bg.magicColor or MOD.db.global.DefaultMagicColor
elseif btype == "Disease" then
c = cc and bg.diseaseColor or MOD.db.global.DefaultDiseaseColor
else
c = cc and bg.debuffColor or MOD.db.global.DefaultDebuffColor
end
elseif bt == "Buff" then
if bar.isStealable then
c = cc and bg.stealColor or MOD.db.global.DefaultStealColor
elseif bar.isMagic then
c = cc and bg.magicColor or MOD.db.global.DefaultMagicColor
elseif bar.isEnrage then
c = cc and bg.enrageColor or MOD.db.global.DefaultEnrageColor
else
c = cc and bg.buffColor or MOD.db.global.DefaultBuffColor
end
end
return c
end
-- Initialize bar group in graphics library and set default values from those set in profile
function MOD:InitializeBarGroup(bp, offsetX, offsetY)
local bg = MOD.Nest_GetBarGroup(bp.name)
if not bg then bg = MOD.Nest_CreateBarGroup(bp.name) end
if bp.linkSettings then UpdateLinkedSettings(bp, false) end
if bp.linkBars then UpdateLinkedBars(bp, false) end
if bp.sor == "C" then bp.sor = "A" end -- fix out-dated sort setting
if bp.auto then -- initialize the auto bar group filter lists
if (bp.filterBuff or bp.showBuff) and bp.filterBuffLink then UpdateLinkedFilter(bp, false, "Buff") end -- shared settings for buffs
if (bp.filterDebuff or bp.showDebuff) and bp.filterDebuffLink then UpdateLinkedFilter(bp, false, "Debuff") end -- shared settings for debuffs
if (bp.filterCooldown or bp.showCooldown) and bp.filterCooldownLink then UpdateLinkedFilter(bp, false, "Cooldown") end -- shared settings for cooldowns
end
if not bp.pointX or not bp.pointY then bp.pointX = 0.5 + (offsetX / 600); bp.pointXR = nil; bp.pointY = 0.5 + (offsetY / 600); bp.pointYT = nil end
if not bp.pointW or not bp.pointH then bp.pointW = MOD.db.global.Defaults.barWidth; bp.pointH = MOD.db.global.Defaults.barHeight end
MOD:SetBarGroupPosition(bp)
MOD.Nest_SetBarGroupCallbacks(bg, Anchor_Moved, Anchor_Clicked, Anchor_OnEnter, Anchor_OnLeave)
end
-- Initialize a bar group from linked settings, if any, and always update the bar group location.
-- This function is called whenever linkSettings is changed.
function MOD:InitializeBarGroupSettings(bp)
if bp and bp.enabled then
if bp.linkSettings then UpdateLinkedSettings(bp, false) end
if bp.linkBars then UpdateLinkedBars(bp, false) end
MOD:SetBarGroupPosition(bp)
end
end
-- Load bar group settings from the linked settings.
function MOD:LoadBarGroupSettings(bp) UpdateLinkedSettings(bp, false) end
-- Save bar group settings into the linked settings.
function MOD:SaveBarGroupSettings(bp) UpdateLinkedSettings(bp, true) end
-- Load bar group settings from the linked settings.
function MOD:LoadCustomBars(bp) UpdateLinkedBars(bp, false) end
-- Save bar group settings into the linked settings.
function MOD:SaveCustomBars(bp) UpdateLinkedBars(bp, true) end
-- Validate and update a bar group's display position. If linked, also update the position in the linked settings.
function MOD:SetBarGroupPosition(bp)
local scale = bp.useDefaultDimensions and MOD.db.global.Defaults.scale or bp.scale or 1
local bg = MOD.Nest_GetBarGroup(bp.name)
if bg then MOD.Nest_SetAnchorPoint(bg, bp.pointX, bp.pointXR, bp.pointY, bp.pointYT, scale, bp.pointW, bp.pointH) end
if bp.linkSettings then
local settings = MOD.db.global.Settings[bp.name] -- when updating a bar group with linked settings always overwrite position
if settings then
settings.pointX = bp.pointX; settings.pointXR = bp.pointXR; settings.pointY = bp.pointY; settings.pointYT = bp.pointYT
settings.pointW = bp.pointW; settings.pointH = bp.pointH
end
end
end
-- Set an entry in a bar group cache block
local function SetCache(bg, block, name, value)
if not bg.cache then bg.cache = {} end
if not bg.cache.block then bg.cache.block = {} end
bg.cache.block[name] = value
end
-- Get a value from a bar group cache block
local function GetCache(bg, block, name)
if not bg.cache or not bg.cache.block then return nil end
return bg.cache.block[name]
end
-- Reset a bar group cache block
local function ResetCache(bg, block)
if bg.cache and bg.cache.block then table.wipe(bg.cache.block) end
end
-- Update a bar group with the current values in the profile
function MOD:UpdateBarGroup(bp)
if bp.enabled then
if bp.linkSettings then UpdateLinkedSettings(bp, true) end -- update shared settings in a linked bar group
if bp.linkBars then UpdateLinkedBars(bp, true) end -- update shared settings in a linked bar group
if bp.auto then -- update auto bar group filter lists
if (bp.filterBuff or bp.showBuff) and bp.filterBuffLink then UpdateLinkedFilter(bp, true, "Buff") end -- shared settings for buffs
if (bp.filterDebuff or bp.showDebuff) and bp.filterDebuffLink then UpdateLinkedFilter(bp, true, "Debuff") end -- shared settings for debuffs
if (bp.filterCooldown or bp.showCooldown) and bp.filterCooldownLink then UpdateLinkedFilter(bp, true, "Cooldown") end -- shared settings for buffs
end
ResetCache(bp, "Buff"); ResetCache(bp, "Debuff"); ResetCache(bp, "Cooldown")
if bp.bars then -- create caches for buff, debuff, cooldown actions
for _, b in pairs(bp.bars) do
local ba = b.action
if ba then
local bt = b.barType
if (bt == "Buff") or (bt == "Debuff") then
SetCache(bp, bt, ba, b.monitor)
elseif bt == "Cooldown" then
SetCache(bp, bt, ba, true)
elseif bt == "Broker" then
MOD:ActivateDataBroker(ba)
end
end
end
end
local bg = MOD.Nest_GetBarGroup(bp.name)
if not bg then MOD:InitializeBarGroup(bp); bg = MOD.Nest_GetBarGroup(bp.name) end
if bp.useDefaultTimeFormat then MOD:CopyTimeFormat(MOD.db.global.Defaults, bp) end
if bp.useDefaultDimensions then MOD:CopyDimensions(MOD.db.global.Defaults, bp) end
if bp.useDefaultFontsAndTextures then MOD:CopyFontsAndTextures(MOD.db.global.Defaults, bp) end
local panelTexture = bp.backdropEnable and media:Fetch("background", bp.backdropPanel) or nil
local backdropTexture = (bp.backdropTexture ~= "None") and media:Fetch("border", bp.backdropTexture) or nil
local borderTexture = (bp.borderTexture ~= "None") and media:Fetch("border", bp.borderTexture) or nil
local fgtexture = media:Fetch("statusbar", bp.texture)
local bgtexture = fgtexture
if bp.bgtexture then bgtexture = media:Fetch("statusbar", bp.bgtexture) end
MOD.Nest_SetBarGroupLock(bg, bp.locked)
MOD.Nest_SetBarGroupAttribute(bg, "parentFrame", bp.parentFrame)
MOD.Nest_SetBarGroupLabelFont(bg, media:Fetch("font", bp.labelFont), bp.labelFSize, bp.labelAlpha, bp.labelColor,
bp.labelOutline, bp.labelShadow, bp.labelThick, bp.labelMono, bp.labelSpecial)
MOD.Nest_SetBarGroupTimeFont(bg, media:Fetch("font", bp.timeFont), bp.timeFSize, bp.timeAlpha, bp.timeColor,
bp.timeOutline, bp.timeShadow, bp.timeThick, bp.timeMono, bp.timeSpecial)
MOD.Nest_SetBarGroupIconFont(bg, media:Fetch("font", bp.iconFont), bp.iconFSize, bp.iconAlpha, bp.iconColor,
bp.iconOutline, bp.iconShadow, bp.iconThick, bp.iconMono, bp.iconSpecial)
MOD.Nest_SetBarGroupBarLayout(bg, bp.barWidth, bp.barHeight, bp.iconSize, bp.scale, bp.spacingX, bp.spacingY,
bp.iconOffsetX, bp.iconOffsetY, bp.labelOffset, bp.labelInset, bp.labelWrap, bp.labelAlign, bp.labelCenter, bp.labelAdjust, bp.labelAuto, bp.labelWidth,
bp.timeOffset, bp.timeInset, bp.timeAlign, bp.timeIcon, bp.iconOffset, bp.iconInset, bp.iconHide, bp.iconAlign,
bp.configuration, bp.growDirection, bp.wrap, bp.wrapDirection, bp.snapCenter, bp.fillBars, bp.maxBars, bp.strata)
MOD.Nest_SetBarGroupBackdrop(bg, panelTexture, backdropTexture, bp.backdropWidth, bp.backdropInset, bp.backdropPadding, bp.backdropColor, bp.backdropFill,
bp.backdropOffsetX, bp.backdropOffsetY, bp.backdropPadW, bp.backdropPadH)
MOD.Nest_SetBarGroupBorder(bg, borderTexture, bp.borderWidth, bp.borderOffset, bp.borderColor)
MOD.Nest_SetBarGroupTextures(bg, fgtexture, bp.fgAlpha, bgtexture, bp.bgAlpha, not bp.showNoDurationBackground,
bp.fgSaturation, bp.fgBrightness, bp.bgSaturation, bp.bgBrightness)
MOD.Nest_SetBarGroupVisibles(bg, not bp.hideIcon, not bp.hideClock, not bp.hideBar, not bp.hideSpark, not bp.hideLabel, not bp.hideValue)
if bp.timelineTexture then bgtexture = media:Fetch("statusbar", bp.timelineTexture) else bgtexture = nil end
if bp.timelineBorderTexture then fgtexture = (bp.timelineBorderTexture ~= "None") and media:Fetch("border", bp.timelineBorderTexture) or nil end
MOD.Nest_SetBarGroupTimeline(bg, bp.timelineWidth, bp.timelineHeight, bp.timelineDuration, bp.timelineExp, bp.timelineHide, bp.timelineAlternate,
bp.timelineSwitch, bp.timelinePercent, bp.timelineSplash, bp.timelineSplashX, bp.timelineSplashY, bp.timelineOffset, bp.timelineDelta,
bgtexture, bp.timelineAlpha, bp.timelineColor or gc, bp.timelineLabels or defaultLabels,
fgtexture, bp.timelineBorderWidth, bp.timelineBorderOffset, bp.timelineBorderColor or gc)
MOD.Nest_SetBarGroupAttribute(bg, "targetFirst", bp.targetFirst) -- for multi-target tracking, sort target first
MOD.Nest_SetBarGroupAttribute(bg, "noMouse", bp.noMouse) -- disable interactivity
MOD.Nest_SetBarGroupAttribute(bg, "iconMouse", bp.iconMouse) -- mouse-only interactivity
MOD.Nest_SetBarGroupAttribute(bg, "anchorTips", bp.anchorTips) -- manual tooltip anchor
MOD.Nest_SetBarGroupAttribute(bg, "isAuto", bp.auto) -- save for tooltip
MOD.Nest_SetBarGroupAttribute(bg, "attachment", bp.anchor) -- save for tooltip
MOD.Nest_SetBarGroupAttribute(bg, "clockReverse", bp.clockReverse) -- save for clock animations
MOD.Nest_SetBarGroupTimeFormat(bg, bp.timeFormat, bp.timeSpaces, bp.timeCase)
MOD.Nest_SetBarGroupAttribute(bg, "headerGaps", bp.headerGaps and bp.noHeaders) -- convert headers into spaces for tracker bar groups
local sf = "alpha"
if bp.sor == "T" then sf = "time" elseif bp.sor == "D" then sf = "duration" elseif bp.sor == "S" then sf = "start" end
MOD.Nest_BarGroupSortFunction(bg, sf, bp.reverseSort, bp.timeSort, bp.playerSort)
MOD.Nest_SetBarGroupAttribute(bg, "noDurationFirst", bp.noDurationFirst) -- controls in no duration sorts first or last
if bp.segmentBars then
MOD.Nest_SetBarGroupSegments(bg, bp.segmentCount, bp.segmentOverride, bp.segmentSpacing, bp.segmentHideEmpty, bp.segmentFadePartial, bp.segmentShrinkWidth,
bp.segmentShrinkHeight, bp.segmentGradient, bp.segmentGradientAll, bp.segmentGradientStartColor, bp.segmentGradientEndColor, bp.segmentBorderColor,
bp.segmentAdvanced, bp.segmentCurve, bp.segmentRotate, bp.segmentTexture)
else
MOD.Nest_SetBarGroupSegments(bg, nil) -- segmentCount must be set for segments to be displayed so this disables them
end
else
MOD:ReleaseBarGroup(bp)
end
end
-- Setup graphics library to show a horizontal stripe
local function ShowStripe(bp, bg)
local bgtexture = nil
if bp.stripeTexture then bgtexture = media:Fetch("statusbar", bp.stripeTexture) end
local sc = bp.stripeColor or gc
if bp.stripeCheckCondition and bp.stripeCondition and MOD:CheckCondition(bp.stripeCondition) then sc = bp.stripeAltColor end
local borderTexture = (bp.stripeBorderTexture ~= "None") and media:Fetch("border", bp.stripeBorderTexture) or nil
MOD.Nest_SetBarGroupStripe(bg, bp.stripeFullWidth, bp.stripeWidth, bp.stripeHeight, bp.stripeInset, bp.stripeOffset,
bp.stripeBarInset, bp.stripeBarOffset, bgtexture, sc, borderTexture, bp.stripeBorderWidth, bp.stripeBorderOffset, bp.stripeBorderColor or gc)
end
-- Update the positions of all anchored bar groups plus make sure valid positions in all bar groups
function MOD:UpdatePositions()
for _, bp in pairs(MOD.db.profile.BarGroups) do -- update bar group positions including relative ones if anchored
if IsOn(bp) then
local bg = MOD.Nest_GetBarGroup(bp.name)
if bg and bg.configuration then -- make sure already configured
if not bp.pointX or not bp.pointY then -- if not valid then move to center
bp.pointX = 0.5; bp.pointXR = nil; bp.pointY = 0.5; bp.pointYT = nil
MOD.Nest_SetAnchorPoint(bg, bp.pointX, bp.pointXR, bp.pointY, bp.pointYT, bp.scale or 1, nil, nil)
end
if bp.anchorFrame then
MOD.Nest_SetRelativeAnchorPoint(bg, nil, bp.anchorFrame, bp.anchorPoint, bp.anchorX, bp.anchorY)
elseif bp.anchor then
local abp = MOD.db.profile.BarGroups[bp.anchor]
if IsOn(abp) and abp.enabled then -- make sure the anchor is actually around to attach
MOD.Nest_SetRelativeAnchorPoint(bg, bp.anchor, nil, nil, bp.anchorX, bp.anchorY, bp.anchorLastBar, bp.anchorEmpty, bp.anchorRow, bp.anchorColumn)
end
else
MOD.Nest_SetRelativeAnchorPoint(bg, nil) -- reset the relative anchor point if none set
end
bp.pointX, bp.pointXR, bp.pointY, bp.pointYT, bp.pointW, bp.pointH = MOD.Nest_GetAnchorPoint(bg) -- returns fractions from display edge
end
end
end
end
-- Update all the bar groups, this is necessary when changing stuff that can affect bars in multiple groups (e.g., buff colors and labels)
function MOD:UpdateAllBarGroups()
MOD:UpdateConditions() -- update in case these affect any bar groups and also to update option panel correctly when changing condition settings
for _, bp in pairs(MOD.db.profile.BarGroups) do -- update for changed bar group settings
if IsOn(bp) then MOD:UpdateBarGroup(bp) end
end
MOD:ForceUpdate() -- this forces an immediate update of bar group display
end
-- Lock or unlock all bar groups
function MOD:LockBarGroups(lock)
for _, bp in pairs(MOD.db.profile.BarGroups) do if IsOn(bp) then bp.locked = lock end end
MOD:UpdateAllBarGroups()
end
-- Toggle test mode for all bar groups
function MOD:TestBarGroups(lock)
for _, bp in pairs(MOD.db.profile.BarGroups) do if IsOn(bp) then MOD:TestBarGroup(bp) end end
MOD:UpdateAllBarGroups()
end
-- Toggle locking of bar groups
function MOD:ToggleBarGroupLocks()
-- Look in the profile table to determine current state
local anyLocked = false
for _, bp in pairs(MOD.db.profile.BarGroups) do
if IsOn(bp) and bp.locked then anyLocked = true break end
end
-- Now go back through and set all to same state (if any locked then unlock all)
MOD:LockBarGroups(not anyLocked)
end
-- Release all the bars in the named bar group in the graphics library
function MOD:ReleaseBarGroup(bp)
if bp then
local bg = MOD.Nest_GetBarGroup(bp.name)
if bg then MOD.Nest_DeleteBarGroup(bg) end
end
end
-- Update a tooltip for a bar
local function Bar_OnUpdate(bar)
local bat = bar.attributes
local id = bat.tooltipID
local unit = bat.tooltipUnit
local spell = bat.tooltipSpell
local caster = bat.caster
local tt = bat.tooltipType
if not tt then return end -- tooltipType set to nil suppresses tooltips
GameTooltip:ClearLines() -- clear current tooltip contents
-- MOD.Debug("tt", tt, id, unit, spell, caster)
if tt == "text" then
GameTooltip:SetText(tostring(id))
elseif (tt == "inventory") then
if id then GameTooltip:SetInventoryItem("player", id) end
elseif (tt == "weapon") then
local slotid = id
if slotid == "MainHandSlot" then slotid = 16 end
if slotid == "SecondaryHandSlot" then slotid = 17 end
if slotid == "RangedSlot" then slotid = 18 end
if (slotid == 16) or (slotid == 17) or (slotid == 18) then GameTooltip:SetInventoryItem("player", slotid) end
elseif (tt == "spell id") or (tt == "internal") or (tt == "alert") then
GameTooltip:SetSpellByID(id)
elseif (tt == "item id") then
GameTooltip:SetItemByID(id)
elseif tt == "effect" then
local ect = MOD.db.global.SpellEffects[id]
if ect and ect.id then GameTooltip:SetSpellByID(ect.id) else GameTooltip:SetText(id) end
elseif tt == "buff" then
GameTooltip:SetUnitAura(unit, id, "HELPFUL")
elseif tt == "debuff" then
GameTooltip:SetUnitAura(unit, id, "HARMFUL")
elseif tt == "vehicle buff" then
GameTooltip:SetUnitAura("vehicle", id, "HELPFUL")
elseif tt == "vehicle debuff" then
GameTooltip:SetUnitAura("vehicle", id, "HARMFUL")
elseif tt == "tracking" then
GameTooltip:SetText(tostring(id)) -- id is localized name of tracking type
elseif tt == "spell" then
GameTooltip:SetText(tostring(id))
elseif tt == "totem" then
GameTooltip:SetTotem(id)
elseif tt == "minion" then
GameTooltip:SetText(tostring(bar.label))
elseif tt == "notification" then
GameTooltip:AddDoubleLine(id, "Notification")
local ct = MOD.db.profile.Conditions[MOD.myClass]
if ct then
local c = ct[unit]
if IsOn(c) and c.tooltip then GameTooltip:AddLine(MOD:GetConditionText(c.name), 1, 1, 1, true) end
end
elseif tt == "lines" then
if type(id) == "table" then for k, v in ipairs(id) do GameTooltip:AddLine(v) end end
elseif tt == "header" then
GameTooltip:AddLine(id)
GameTooltip:AddLine(L["Header click"], 1, 1, 1, true)
GameTooltip:AddLine(L["Header shift click"], 1, 1, 1, true)
elseif tt == "test" then
if id == "timer" then
GameTooltip:SetText(L["Timer Bar"] .. " " .. tostring(unit))
else
GameTooltip:SetText(L["Test Bar"] .. " " .. tostring(unit))
end
end
if IsControlKeyDown() then
if spell then GameTooltip:AddLine("<Spell #" .. tonumber(spell) .. ">", 0, 1, 0.2, false) end
if bat.listID then GameTooltip:AddLine("<List #" .. tonumber(bat.listID) .. ">", 0, 1, 0.2, false) end
end
if caster and (caster ~= "") then GameTooltip:AddLine(L["<Applied by "] .. caster .. ">", 0, 0.8, 1, false) end
GameTooltip:Show()
end
MOD.Bar_OnUpdate = Bar_OnUpdate -- saved for tooltip updating
-- Anchor the tooltip appropriately
local function Bar_AnchorTooltip(frame, tooltip, ttanchor)
if not ttanchor then
tooltip:ClearAllPoints()
if type(tooltip.SetOwner) == "function" then tooltip:SetOwner(frame, "ANCHOR_NONE") end
local _, fy = frame:GetCenter()
local _, sy = UIParent:GetCenter()
local frameAnchor, tooltipAnchor
if sy > fy then frameAnchor = "TOP"; tooltipAnchor = "BOTTOM" else frameAnchor = "BOTTOM"; tooltipAnchor = "TOP" end
tooltip:SetPoint(tooltipAnchor, frame, frameAnchor)
elseif (ttanchor == "DEFAULT") and (GetCVar("UberTooltips") == "1") then
GameTooltip_SetDefaultAnchor(tooltip, frame)
else
if not ttanchor or (ttanchor == "DEFAULT") then ttanchor = "ANCHOR_BOTTOMLEFT" else ttanchor = "ANCHOR_" .. ttanchor end
tooltip:SetOwner(frame, ttanchor)
end
end
-- Show tooltip when entering a bar
local function Bar_OnEnter(frame, bgName, barName, ttanchor)
local bg = MOD.Nest_GetBarGroup(bgName)
if not bg then return end
local bar = MOD.Nest_GetBar(bg, barName)
if not bar then return end
local bat = bar.attributes
local db = bat.tooltipID
local tt = bat.tooltipType
if not tt then return end -- tooltipType set to nil suppresses tooltips
if tt == "broker" then
if type(db) == "table" then
if db.tooltip and type(db.tooltip) == "table" and type(db.tooltip.SetText) == "function" and type(dp.tooltip.Show) == "function" then
Bar_AnchorTooltip(frame, db.tooltip)
if db.tooltiptext then db.tooltip:SetText(db.tooltiptext) end
db.tooltip:Show()
elseif type(db.OnTooltipShow) == "function" then
Bar_AnchorTooltip(frame, GameTooltip)
db.OnTooltipShow(GameTooltip)
GameTooltip:Show()
elseif db.tooltiptext then
Bar_AnchorTooltip(frame, GameTooltip)
GameTooltip:SetText(db.tooltiptext)
GameTooltip:Show()
elseif type(db.OnEnter) == "function" then
db.OnEnter(frame)
end
end
else
Bar_AnchorTooltip(frame, GameTooltip, ttanchor)
MOD.tooltipBar = bar
Bar_OnUpdate(bar)
end
end
-- Hide tooltip when leaving a bar
local function Bar_OnLeave(frame, bgName, barName, ttanchor)
local bg = MOD.Nest_GetBarGroup(bgName)
if not bg then return end
local bar = MOD.Nest_GetBar(bg, barName)
if not bar then return end
local bat = bar.attributes
local tt = bat.tooltipType
local db = bat.tooltipID
if tt == "broker" then
if type(db) == "table" then
if type(db.OnTooltipShow) == "function" then
GameTooltip:Hide()
end
if type(db.OnLeave) == "function" then
db.OnLeave(frame)
elseif db.tooltip and type(db.tooltip) == "table" and type(dp.tooltip.Hide) == "function" then
db.tooltip:Hide()
else
GameTooltip:Hide()
end
end
else
MOD.tooltipBar = nil
GameTooltip:Hide()
end
end
-- Handle clicking on a bar for various purposes
local function Bar_OnClick(frame, bgName, barName, button)
local bg = MOD.Nest_GetBarGroup(bgName)
if not bg then return end
local bar = MOD.Nest_GetBar(bg, barName)
if not bar then return end
local bat = bar.attributes
local tt = bat.tooltipType
local db = bat.tooltipID
local unit = bat.tooltipUnit
if (tt == "tracking") and (button == "LeftButton") and (unit == "player") then
if GameTooltip:GetOwner() == frame then
GameTooltip:Hide()
end
ToggleDropDownMenu(1, nil, MiniMapTrackingDropDown, frame, 0, 0)
elseif (tt == "header") and (button == "RightButton") then
if IsShiftKeyDown() then MOD:RemoveMatchingTrackers(unit) else MOD:RemoveTrackers(unit) end
elseif (tt == "broker") then
if type(db) == "table" and type(db.OnClick) == "function" then db.OnClick(frame, button) end
end
end
-- Fire off test bars for this bar group, remove if any already exist
function MOD:TestBarGroup(bp)
local bg = MOD.Nest_GetBarGroup(bp.name)
if bg then
local found = false
local icon = defaultTestIcon
local timers = bp.testTimers or 0; if timers == 0 then timers = 10 end
local static = bp.testStatic or 0
for i = 1, timers do
local bar = MOD.Nest_GetBar(bg, ">>Timer<<" .. string.format("%02d", i))
if bar then found = true; MOD.Nest_DeleteBar(bg, bar) end
end
for i = 1, static do
local bar = MOD.Nest_GetBar(bg, ">>Test<<" .. string.format("%02d", i))
if bar then found = true; MOD.Nest_DeleteBar(bg, bar) end
end
if not found then
for i = 1, timers do
local bar = MOD.Nest_CreateBar(bg, ">>Timer<<" .. string.format("%02d", i))
if bar then
local bat = bar.attributes
local c = MOD.ColorPalette[testColors[(i % 10) + 1]]
MOD.Nest_SetColors(bar, c.r, c.g, c.b, 1, c.r, c.g, c.b, 1, c.r, c.g, c.b, 1)
MOD.Nest_SetLabel(bar, L["Timer Bar"] .. " " .. i); MOD.Nest_SetIcon(bar, icon); MOD.Nest_SetCount(bar, i)
MOD.Nest_StartTimer(bar, i * 5, 60, 60)
MOD.Nest_SetCallbacks(bar, nil, Bar_OnEnter, Bar_OnLeave)
bat.tooltipType = "test"; bat.tooltipID = "timer"; bat.tooltipUnit = i
bat.updated = true
end
end
for i = 1, static do
local bar = MOD.Nest_CreateBar(bg, ">>Test<<" .. string.format("%02d", i))
if bar then
local bat = bar.attributes
local c = MOD.ColorPalette[testColors[(i % 10) + 1]]
MOD.Nest_SetColors(bar, c.r, c.g, c.b, 1, c.r, c.g, c.b, 1, c.r, c.g, c.b, 1)
MOD.Nest_SetLabel(bar, L["Test Bar"] .. " " .. i); MOD.Nest_SetIcon(bar, icon); MOD.Nest_SetCount(bar, i)
MOD.Nest_SetCallbacks(bar, nil, Bar_OnEnter, Bar_OnLeave)
bat.tooltipType = "test"; bat.tooltipID = "test"; bat.tooltipUnit = i
bat.updated = true
end
end
end
end
end
-- Make sure not to delete any unexpired test bars
local function UpdateTestBars(bp, bg)
local timers = bp.testTimers or 0; if timers == 0 then timers = 10 end
local static = bp.testStatic or 0
for i = 1, timers do
local bar = MOD.Nest_GetBar(bg, ">>Timer<<" .. string.format("%02d", i))
if bar then
local timeLeft = MOD.Nest_GetTimes(bar)
if timeLeft and (timeLeft > 0) then
bar.attributes.updated = true
elseif bp.testLoop then
MOD.Nest_StartTimer(bar, i * 5, 60, 60)
bar.attributes.updated = true
end
end
end
for i = 1, static do
local bar = MOD.Nest_GetBar(bg, ">>Test<<" .. string.format("%02d", i))
if bar then bar.attributes.updated = true end
end
end
-- Return true if time and duration pass a bar group's filters
local function CheckTimeAndDuration(bp, timeLeft, duration)
if (timeLeft == 0) and (duration == 0) then -- test for unlimited duration
if not bp.showNoDuration then return false end
else
if bp.showNoDuration and bp.showOnlyNoDuration then return false end
if bp.checkDuration and bp.filterDuration then
if bp.minimumDuration then if duration < bp.filterDuration then return false end
elseif duration >= bp.filterDuration then return false end
end
if bp.checkTimeLeft and bp.filterTimeLeft then
if bp.minimumTimeLeft then if timeLeft < bp.filterTimeLeft then return false end
elseif timeLeft >= bp.filterTimeLeft then return false end
end
end
return true
end
local numberPatterns = { -- patterns for extracting up to 10 numbers from a string
"(%d+%.?%d*)",
"%d+%.?%d*%D+(%d+%.?%d*)",
"%d+%.?%d*%D+%d+%.?%d*%D+(%d+%.?%d*)",
"%d+%.?%d*%D+%d+%.?%d*%D+%d+%.?%d*%D+(%d+%.?%d*)",
"%d+%.?%d*%D+%d+%.?%d*%D+%d+%.?%d*%D+%d+%.?%d*%D+(%d+%.?%d*)",