Repository navigation
Expand file tree
/
Copy pathBarDisplay.lua
More file actions
1496 lines (1329 loc) · 40 KB
/
Copy pathBarDisplay.lua
File metadata and controls
1496 lines (1329 loc) · 40 KB
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
--[[
The traditional bar display used in some form by most damage meters.
--]]
local _, Skada = ...
local L = LibStub("AceLocale-3.0"):GetLocale("Skada", true)
local mod = Skada:NewModule("BarDisplay", "SpecializedLibBars-1.0")
local libwindow = LibStub("LibWindow-1.1")
local media = LibStub("LibSharedMedia-3.0")
-- Aliases
local table_sort = table.sort
local next, pairs, ipairs, type = next, pairs, ipairs, type
--
-- Display implementation.
--
-- Add to Skada's enormous list of display providers.
mod.name = L["Bar display"]
mod.description = L["Bar display is the normal bar window used by most damage meters. It can be extensively styled."]
Skada:AddDisplaySystem("bar", mod)
-- Called when a Skada window starts using this display provider.
function mod:Create(window)
-- Re-use bargroup if it exists.
window.bargroup = mod:GetBarGroup(window.db.name)
-- Save a reference to window in bar group. Needed for some nasty callbacks.
if window.bargroup then
-- Clear callbacks.
window.bargroup.callbacks = LibStub:GetLibrary("CallbackHandler-1.0"):New(window.bargroup)
else
window.bargroup = mod:NewBarGroup(window.db.name, nil, window.db.background.height, window.db.barwidth, window.db.barheight, "SkadaBarWindow"..window.db.name)
local bargroup = window.bargroup -- ticket 323
-- Add window buttons.
window.bargroup:AddButton(L["Configure"], L["Configure description"], "Interface\\Buttons\\UI-OptionsButton", "Interface\\Buttons\\UI-OptionsButton", function() Skada:OpenMenu(bargroup.win) end)
window.bargroup:AddButton(L["Reset"], L["Reset description"], "Interface\\Buttons\\UI-StopButton", "Interface\\Buttons\\UI-StopButton", function() Skada:ShowPopup() end)
window.bargroup:AddButton(L["Segment"], L["Segment description"], "Interface\\Buttons\\UI-GuildButton-PublicNote-Up", "Interface\\Buttons\\UI-GuildButton-PublicNote-Up", function() Skada:SegmentMenu(bargroup.win) end)
window.bargroup:AddButton(L["Mode"], L["Mode description"], "Interface\\GROUPFRAME\\UI-GROUP-MAINASSISTICON", "Interface\\GROUPFRAME\\UI-GROUP-MAINASSISTICON", function() Skada:ModeMenu(bargroup.win) end)
window.bargroup:AddButton(L["Report"], L["Report description"], "Interface\\Buttons\\UI-GuildButton-MOTD-Up", "Interface\\Buttons\\UI-GuildButton-MOTD-Up", function() Skada:OpenReportWindow(bargroup.win) end)
end
window.bargroup.win = window
window.bargroup.RegisterCallback(mod, "AnchorMoved")
window.bargroup.RegisterCallback(mod, "WindowResized")
window.bargroup:EnableMouse(true)
window.bargroup:SetScript("OnMouseDown", function(win, button) if IsShiftKeyDown() then Skada:OpenMenu(window) elseif button == "RightButton" then window:RightClick() end end)
window.bargroup.button:SetScript("OnClick", function(win, button) if IsShiftKeyDown() then Skada:OpenMenu(window) elseif button == "RightButton" then window:RightClick() end end)
window.bargroup.button:SetScript("OnEnter", function(win, button)
window.bargroup:SetButtonsOpacity(1.0)
end)
window.bargroup.button:SetScript("OnLeave", function(win, button)
if not window.bargroup.button:IsMouseOver() then
window.bargroup:SetButtonsOpacity(0.25)
end
end)
window.bargroup:HideIcon()
window.bargroup.button:GetFontString():SetWordWrap(false);
window.bargroup.button:GetFontString():SetPoint("LEFT", window.bargroup.button, "LEFT", 5, 1)
window.bargroup.button:GetFontString():SetJustifyH("LEFT")
window.bargroup.button:SetHeight(window.db.title.height or 15)
-- Register with LibWindow-1.0.
libwindow.RegisterConfig(window.bargroup, window.db)
-- Restore window position.
libwindow.RestorePosition(window.bargroup)
if not mod.class_icon_tcoords then -- amortized class icon coordinate adjustment
mod.class_icon_tcoords = {}
for class, coords in pairs(CLASS_ICON_TCOORDS) do
local l,r,t,b = unpack(coords)
local adj = 0.02
mod.class_icon_tcoords[class] = {(l+adj),(r-adj),(t+adj),(b-adj)}
end
end
if not mod.role_icon_tcoords then
mod.role_icon_tcoords = {
DAMAGER = {0.3125, 0.63, 0.3125, 0.63},
HEALER = {0.3125, 0.63, 0.015625, 0.3125},
TANK = {0, 0.296875, 0.3125, 0.63},
LEADER = {0, 0.296875, 0.015625, 0.3125},
NONE = ""
}
end
end
-- Called by Skada windows when the window is to be destroyed/cleared.
function mod:Destroy(win)
win.bargroup:Hide()
win.bargroup = nil
end
-- Called by Skada windows when the window is to be completely cleared and prepared for new data.
function mod:Wipe(win)
-- Reset sort function.
win.bargroup:SetSortFunction(nil)
-- Reset scroll offset.
win.bargroup:SetBarOffset(0)
-- Remove the bars.
local bars = win.bargroup:GetBars()
if bars then
for i, bar in pairs(bars) do
bar:Hide()
win.bargroup:RemoveBar(bar)
end
end
-- Clean up.
win.bargroup:SortBars()
end
local function showmode(win, id, label, mode)
-- Add current mode to window traversal history.
if win.selectedmode then
tinsert(win.history, win.selectedmode)
end
-- Call the Enter function on the mode.
if mode.Enter then
mode:Enter(win, id, label)
end
-- Display mode.
win:DisplayMode(mode)
end
local function BarClickIgnore(bar, button)
local win = bar.win
if button == "RightButton" then
win:RightClick()
end
end
local function BarClick(bar, button)
local win, id, label = bar.win, bar.id, bar.text
local click1 = win.metadata.click1
local click2 = win.metadata.click2
local click3 = win.metadata.click3
if button == "RightButton" and IsShiftKeyDown() then
Skada:OpenMenu(win)
elseif win.metadata.click then
win.metadata.click(win, id, label, button)
elseif button == "RightButton" then
win:RightClick()
elseif click2 and IsShiftKeyDown() then
showmode(win, id, label, click2)
elseif click3 and IsControlKeyDown() then
showmode(win, id, label, click3)
elseif click1 then
showmode(win, id, label, click1)
end
end
local ttactive = false
local function BarEnter(bar)
local win, id, label = bar.win, bar.id, bar.text
ttactive = true
Skada:SetTooltipPosition(GameTooltip, win.bargroup)
Skada:ShowTooltip(win, id, label)
end
local function BarLeave(bar)
local win, id, label = bar.win, bar.id, bar.text
if ttactive then
GameTooltip:Hide()
ttactive = false
end
end
local function BarResize(bar)
if bar.bgwidth then
bar.bgtexture:SetWidth(bar.bgwidth * bar:GetWidth())
else
bar:SetScript("OnSizeChanged",bar.OnSizeChanged)
end
bar:OnSizeChanged() -- call library version
end
local function BarIconEnter(icon)
local bar = icon.bar
local win = bar.win
if bar.spellid and win and win.bargroup then
Skada:SetTooltipPosition(GameTooltip, win.bargroup);
GameTooltip:SetHyperlink("spell:"..bar.spellid);
GameTooltip:Show();
end
if bar.link and win and win.bargroup then
Skada:SetTooltipPosition(GameTooltip, win.bargroup);
GameTooltip:SetHyperlink(bar.link);
GameTooltip:Show();
end
end
local function BarIconMouseDown(icon) -- shift-click to link spell into chat
local bar = icon.bar
if not IsShiftKeyDown() or not bar.link then return end
local activeEditBox = ChatEdit_GetActiveWindow()
if activeEditBox then
ChatEdit_InsertLink(bar.link)
else
ChatFrame_OpenChat(bar.link, DEFAULT_CHAT_FRAME)
end
end
-- Uses Skada.value_sort (defined in Skada.lua) to avoid duplication
local function value_sort(a, b)
return Skada.value_sort(a, b)
end
local function bar_order_sort(a,b)
return a and b and a.order and b.order and a.order < b.order
end
local function HideGameTooltip()
GameTooltip:Hide()
end
-- Called by Skada windows when title of window should change.
function mod:SetTitle(win, title)
-- Set title.
-- WoW 12.0+ restriction: Button:SetText() does not allow secret values during combat.
-- However, FontString:SetText() does allow them. We use the internal FontString to bypass this.
local fs = win.bargroup.button:GetFontString()
if fs then
fs:SetText(title)
else
win.bargroup.button:SetText(title)
end
end
-- Called by Skada windows when the display should be updated to match the dataset.
function mod:Update(win)
-- Some modes may alter title continously.
local fs = win.bargroup.button:GetFontString()
if fs then
fs:SetText(win.metadata.title)
else
win.bargroup.button:SetText(win.metadata.title)
end
-- Sort if we are showing spots with "showspots".
if win.metadata.showspots then
table_sort(win.dataset, value_sort)
end
-- Find out if we have icons in this update, and if so, adjust accordingly.
local hasicon = false
for i, data in ipairs(win.dataset) do
if (data.icon and not data.ignore) or (data.class and win.db.classicons) or (data.role and win.db.roleicons) then
hasicon = true
end
end
if hasicon and not win.bargroup.showIcon then
win.bargroup:ShowIcon()
end
if not hasicon and win.bargroup.showIcon then
win.bargroup:HideIcon()
end
-- If we are using "wipestale", we may have removed data
-- and we need to remove unused bars.
-- The Threat module uses this.
-- For each bar, mark bar as unchecked.
if win.metadata.wipestale then
local bars = win.bargroup:GetBars()
if bars then
for name, bar in pairs(bars) do
bar.checked = false
end
end
end
local nr = 1
local activeBarIds = {}
for i, data in ipairs(win.dataset) do
if data.id then
local barid = data.id
local barlabel = data.label
activeBarIds[barid] = true
local bar = win.bargroup:GetBar(barid)
if bar and bar.missingclass and data.class and not data.ignore then
-- fixup bar that was generated before class info was available
bar:Hide()
win.bargroup:RemoveBar(bar)
bar.missingclass = nil
bar = nil
end
if bar then
bar:SetValue(data.value or 0)
bar:SetMaxValue(win.metadata.maxvalue or 1) -- MUST come after SetValue
else
-- Initialization of bars.
bar = mod:CreateBar(win, barid, barlabel, data.value, win.metadata.maxvalue or 1, data.icon, false)
bar.id = barid
bar.text = barlabel
bar.fixed = false
if not data.ignore then
if data.icon ~= nil then
bar:ShowIcon()
bar.iconFrame.bar = bar
bar.iconFrame:EnableMouse(true)
bar.iconFrame:SetScript("OnEnter", BarIconEnter)
bar.iconFrame:SetScript("OnLeave", HideGameTooltip)
bar.iconFrame:SetScript("OnMouseDown", BarIconMouseDown)
else
bar:HideIcon()
end
bar:EnableMouse(true)
bar:SetScript("OnEnter", BarEnter)
bar:SetScript("OnLeave", BarLeave)
bar:SetScript("OnMouseDown", BarClick)
else
bar:SetScript("OnEnter", nil)
bar:SetScript("OnLeave", nil)
bar:SetScript("OnMouseDown", BarClickIgnore)
end
bar:SetValue(data.value or 0)
bar.link = nil
bar.spellid = nil
if data.spellid then
bar.spellid = data.spellid
elseif data.hyperlink then
bar.link = data.hyperlink
end
if not data.class and (win.db.classicons or win.db.classcolorbars or win.db.classcolortext) then
bar.missingclass = true
else
bar.missingclass = nil
end
if data.role and data.role ~= "NONE" and win.db.roleicons then
bar:ShowIcon()
-- bar:SetIconWithCoord("Interface\\LFGFrame\\UI-LFG-ICON-ROLES", GetTexCoordsForRole(data.role))
bar:SetIconWithCoord("Interface\\LFGFrame\\UI-LFG-ICON-PORTRAITROLES", mod.role_icon_tcoords[data.role])
elseif data.class and win.db.classicons and mod.class_icon_tcoords[data.class] then
bar:ShowIcon()
bar:SetIconWithCoord("Interface\\Glues\\CharacterCreate\\UI-CharacterCreate-Classes", mod.class_icon_tcoords[data.class])
end
if data.color then
-- Explicit color from dataset.
bar:SetColorAt(0, data.color.r, data.color.g, data.color.b, data.color.a or 1)
elseif data.spellschool and win.db.spellschoolcolors then
local school_colors = {
[1] = {r = 1, g = 0.82, b = 0.17},
[2] = {r = 0.96, g = 0.91, b = 0.11},
[4] = {r = 0.89, g = 0.33, b = 0.10},
[8] = {r = 0.31, g = 0.81, b = 0.19},
[16] = {r = 0.40, g = 0.86, b = 0.96},
[32] = {r = 0.61, g = 0.39, b = 0.76},
[64] = {r = 0.92, g = 0.47, b = 0.88},
}
local color = school_colors[data.spellschool]
if color then
bar:SetColorAt(0, color.r, color.g, color.b, color.a or 1)
end
elseif data.class and win.db.classcolorbars then
-- Class color.
local color = Skada.classcolors[data.class]
if color then
bar:SetColorAt(0, color.r, color.g, color.b, color.a or 1)
end
else
-- Default color.
local color = win.db.barcolor
bar:SetColorAt(0, color.r, color.g, color.b, color.a or 1)
end
if data.class and win.db.classcolortext then
-- Class color text.
local color = Skada.classcolors[data.class]
if color then
bar.label:SetTextColor(color.r, color.g, color.b, color.a or 1)
-- Apply color to all columns
for i = 1, 3 do
if bar.columns[i] then
bar.columns[i]:SetTextColor(color.r, color.g, color.b, color.a or 1)
end
end
end
else
-- Default color text.
bar.label:SetTextColor(1,1,1,1)
-- Apply value text color or default
local vtc = win.db.valuetextcolor
for i = 1, 3 do
if bar.columns[i] then
if vtc then
bar.columns[i]:SetTextColor(vtc.r, vtc.g, vtc.b, vtc.a or 1)
else
bar.columns[i]:SetTextColor(1,1,1,1)
end
end
end
end
if Skada.db.profile.showself and data.id and data.id == UnitGUID("player") then
-- Always show self
bar.fixed = true
bar.isSelfBar = true
else
bar.isSelfBar = false
end
end
if win.metadata.ordersort then
bar.order = i
end
if win.metadata.showspots and Skada.db.profile.showranks and not data.ignore then
if win.db.barorientation == 1 then
bar:SetLabel(("%2u. %s"):format(nr, data.label))
else
bar:SetLabel(("%s %2u"):format(data.label, nr))
end
else
bar:SetLabel(data.label)
end
if data.valuetext then
-- No columns
bar:SetColumnText(3, data.valuetext)
else
-- Up to 3 columns - always call SetColumnText, it handles nil
-- Note: Boolean tests on secret values are not allowed in WoW 12.0
bar:SetColumnText(3, data.valueText1)
bar:SetColumnText(2, data.valueText2)
bar:SetColumnText(1, data.valueText3)
end
if win.metadata.wipestale then
bar.checked = true
end
-- Emphathized items - cache a flag saying it is done so it is not done again.
-- This is a little lame.
if data.emphathize and bar.emphathize_set ~= true then
bar:SetFont(nil,nil,"OUTLINE")
bar.emphathize_set = true
elseif not data.emphathize and bar.emphathize_set ~= false then
bar:SetFont(nil,nil, win.db.barfontflags)
bar.emphathize_set = false
end
-- Background texture color.
if data.backgroundcolor then
bar.bgtexture:SetVertexColor(data.backgroundcolor.r, data.backgroundcolor.g, data.backgroundcolor.b, data.backgroundcolor.a or 1)
end
-- Background texture size (in percent, as the mode has no idea on actual widths).
if data.backgroundwidth then
bar.bgtexture:ClearAllPoints()
bar.bgtexture:SetPoint("BOTTOMLEFT")
bar.bgtexture:SetPoint("TOPLEFT")
bar.bgwidth = data.backgroundwidth
bar:SetScript("OnSizeChanged",BarResize) -- ticket 365: required to resize bgtexture
BarResize(bar)
else
bar.bgwidth = nil
end
if not data.ignore then
nr = nr + 1
end
end
end
-- Remove bars that are no longer in the current dataset.
-- This prevents stale bars from ID scheme transitions (e.g. combat_N <-> GUID)
-- from lingering with outdated labels/values.
local allBars = win.bargroup:GetBars()
if allBars then
for name, bar in pairs(allBars) do
if not activeBarIds[name] then
win.bargroup:RemoveBar(bar)
end
end
end
-- If we are using "wipestale", remove all unchecked bars.
if win.metadata.wipestale then
local bars = win.bargroup:GetBars()
for name, bar in pairs(bars) do
if not bar.checked then
win.bargroup:RemoveBar(bar)
end
end
end
-- Always sort after applying the dataset. The previous "lazy" guard
-- compared win.bargroup.barCount before and after the loop, but barCount
-- is only assigned inside SortBars() itself, so it never differed and the
-- guard suppressed legitimate re-sorts (rank changes, new/removed bars,
-- ordersort updates). Sorting a few dozen bars per tick is cheap.
if win.metadata.ordersort then
win.bargroup:SetSortFunction(bar_order_sort)
else
win.bargroup:SetSortFunction(nil)
end
win.bargroup:SortBars()
end
function mod:AnchorMoved(cbk, group, x, y)
libwindow.SavePosition(group)
end
function mod:WindowResized(cbk, group)
-- Capture position and size BEFORE clearing anchors
local top = group:GetTop()
local left = group:GetLeft()
local width = group:GetWidth()
-- Calculate snapped height based on number of bars
local height = group:GetHeight()
local barHeight = group.win.db.barheight
local barSpacing = group.win.db.barspacing
local totalBarHeight = barHeight + barSpacing
local numBars = math.floor((height + barSpacing + (totalBarHeight/2)) / totalBarHeight)
local snappedHeight = (numBars * totalBarHeight) - barSpacing
-- Re-anchor with snapped height, restoring width explicitly
group:ClearAllPoints()
group:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", left, top)
group:SetWidth(width)
group:SetHeight(snappedHeight)
-- Save position and size
libwindow.SavePosition(group)
group.win.db.background.height = snappedHeight
group.win.db.barwidth = width
group:SetLength(width)
-- Re-layout all bars at the new width
group:SortBars()
end
function mod:Show(win)
win.bargroup:Show()
win.bargroup:SortBars()
end
function mod:Hide(win)
win.bargroup:Hide()
end
function mod:IsShown(win)
return win.bargroup:IsShown()
end
local function getNumberOfBars(win)
-- Use barCount maintained by SortBars for O(1) lookup
return win.bargroup.barCount or 0
end
local function OnMouseWheel(frame, direction)
local win = frame.win
local maxbars = win.db.background.height / (win.db.barheight + win.db.barspacing)
if direction == 1 and win.bargroup:GetBarOffset() > 0 then
win.bargroup:SetBarOffset(win.bargroup:GetBarOffset() - 1)
elseif direction == -1 and ((getNumberOfBars(win) - maxbars - win.bargroup:GetBarOffset()) > 0) then
win.bargroup:SetBarOffset(win.bargroup:GetBarOffset() + 1)
end
end
function mod:OnMouseWheel(win, frame, direction) -- external scrolling interface (SkadaScroll)
if not frame then
mod.framedummy = mod.framedummy or {}
mod.framedummy.win = win
frame = mod.framedummy
end
OnMouseWheel(frame, direction)
end
function mod:CreateBar(win, name, label, value, maxvalue, icon, o)
local bar = win.bargroup:NewCounterBar(name, label, value, maxvalue, icon)
bar.win = win
bar:EnableMouseWheel(true)
bar:SetScript("OnMouseWheel", OnMouseWheel)
bar.iconFrame:SetScript("OnEnter", nil)
bar.iconFrame:SetScript("OnLeave", nil)
bar.iconFrame:SetScript("OnMouseDown", nil)
bar.iconFrame:EnableMouse(false)
return bar
end
local titlebackdrop = {}
local windowbackdrop = {}
-- Called by Skada windows when window settings have changed.
function mod:ApplySettings(win)
local g = win.bargroup
g:SetFrameLevel(1)
local p = win.db
g:ReverseGrowth(p.reversegrowth)
g:SetOrientation(p.barorientation)
g:SetBarHeight(p.barheight)
g:SetHeight(p.background.height)
g:SetWidth(p.barwidth)
g:SetLength(p.barwidth)
g:SetTexture(p.bartexturepath or media:Fetch('statusbar', p.bartexture))
g:SetBarBackgroundColor(p.barbgcolor.r, p.barbgcolor.g, p.barbgcolor.b, p.barbgcolor.a or 0.6)
g:SetFont(p.barfontpath or media:Fetch('font', p.barfont), p.barfontsize, p.barfontflags)
g:SetSpacing(p.barspacing)
g:UnsetAllColors()
g:SetColorAt(0,p.barcolor.r,p.barcolor.g,p.barcolor.b, p.barcolor.a)
if p.barslocked then
g:Lock()
else
g:Unlock()
end
if p.strata then g:SetFrameStrata(p.strata) end
-- Header
local fo = CreateFont("TitleFont"..win.db.name)
fo:SetFont(p.title.fontpath or media:Fetch('font', p.title.font), p.title.fontsize, p.title.fontflags)
if p.title.textcolor then
fo:SetTextColor(p.title.textcolor.r, p.title.textcolor.g, p.title.textcolor.b, p.title.textcolor.a)
end
g.button:SetNormalFontObject(fo)
-- Title text alignment
local fs = g.button:GetFontString()
if fs then
fs:SetJustifyH(p.title.textalign or "LEFT")
end
local titleBgFile = media:Fetch("statusbar", p.title.texture)
if not titleBgFile or p.title.texture == "None" then
titleBgFile = "Interface\\Buttons\\WHITE8X8"
end
titlebackdrop.bgFile = titleBgFile
titlebackdrop.tile = false
titlebackdrop.tileSize = 0
titlebackdrop.edgeSize = p.title.borderthickness
g.button:SetBackdrop(titlebackdrop)
local color = p.title.color
g.button:SetBackdropColor(color.r, color.g, color.b, color.a or 1)
-- Title gradient
local tex = g.button:GetNormalTexture()
if tex and p.title.color and p.title.color2 then
tex:SetGradient("HORIZONTAL", CreateColor(p.title.color.r, p.title.color.g, p.title.color.b, p.title.color.a), CreateColor(p.title.color2.r, p.title.color2.g, p.title.color2.b, p.title.color2.a or 1))
elseif tex then
tex:SetGradient("HORIZONTAL", CreateColor(1,1,1,1), CreateColor(1,1,1,1)) -- Reset if no gradient
end
g.button:SetHeight(p.title.height or 15)
Skada:ApplyBorder(g.button, p.title.bordertexture, p.title.bordercolor, p.title.borderthickness)
if p.enabletitle then
g:ShowAnchor()
else
g:HideAnchor()
end
-- Adjust button positions
g:AdjustButtons()
-- Button visibility.
g:ShowButton(L["Configure"], p.buttons.menu)
g:ShowButton(L["Reset"], p.buttons.reset)
g:ShowButton(L["Mode"], p.buttons.mode)
g:ShowButton(L["Segment"], p.buttons.segment)
g:ShowButton(L["Report"], p.buttons.report)
-- g:ShowButton(L["Stop"], p.buttons.stop)
-- Window
local padtop = (p.enabletitle and not p.reversegrowth and p.title.height)
local padbottom = (p.enabletitle and p.reversegrowth and p.title.height)
Skada:ApplyBorder(g, p.background.bordertexture, p.background.bordercolor, p.background.borderthickness, padtop, padbottom)
local bgFile = p.background.texturepath or media:Fetch("background", p.background.texture)
if not bgFile or p.background.texture == "None" then
bgFile = "Interface\\Buttons\\WHITE8X8"
end
windowbackdrop.bgFile = bgFile
windowbackdrop.tile = false
windowbackdrop.tileSize = 0
g:SetBackdrop(windowbackdrop)
local bgcolor = p.background.color
g:SetBackdropColor(bgcolor.r, bgcolor.g, bgcolor.b, bgcolor.a or 1)
-- Clickthrough
g:SetEnableMouse(not p.clickthrough)
-- Scale
g:SetScale(p.scale)
-- Smoothing
g:SetSmoothing(p.smoothing)
-- Bar fill
g:SetFill(p.barfill)
-- Alternating row colors
g:SetAlternateRows(p.alternaterows)
-- Self-highlight
if p.highlightself then
local sc = p.selfhighlightcolor
g:SetSelfHighlight(true, sc and {sc.r, sc.g, sc.b, sc.a})
else
g:SetSelfHighlight(false)
end
-- Spark on leading bar
g:SetSpark(p.spark)
-- Icon scale
g:SetIconScale(p.iconscale or 100)
-- Bar inset
g:SetBarInset(p.barinset or 0)
libwindow.SavePosition(g)
g:SortBars()
end
--
-- Options.
--
function mod:AddDisplayOptions(win, options)
local db = win.db
options.baroptions = {
type = "group",
name = L["Bars"],
order = 1,
args = {
barfont = {
type = 'select',
dialogControl = 'LSM30_Font',
name = L["Bar font"],
desc = L["The font used by all bars."],
values = AceGUIWidgetLSMlists.font,
get = function() return db.barfont end,
set = function(win,key)
db.barfont = key
Skada:ApplySettings()
end,
order = 1,
},
barfontsize = {
type="range",
name=L["Bar font size"],
desc=L["The font size of all bars."],
min=7,
max=40,
step=1,
get=function() return db.barfontsize end,
set=function(win, size)
db.barfontsize = size
Skada:ApplySettings()
end,
order=2,
},
barfontflags = {
type = 'select',
name = L["Font flags"],
desc = L["Sets the font flags."],
values = {[""] = L["None"], ["OUTLINE"] = L["Outline"], ["THICKOUTLINE"] = L["Thick outline"], ["MONOCHROME"] = L["Monochrome"], ["OUTLINEMONOCHROME"] = L["Outlined monochrome"]},
get = function() return db.barfontflags end,
set = function(win,key)
db.barfontflags = key
Skada:ApplySettings()
end,
order = 3,
},
bartexture = {
type = 'select',
dialogControl = 'LSM30_Statusbar',
name = L["Bar texture"],
desc = L["The texture used by all bars."],
values = AceGUIWidgetLSMlists.statusbar,
get = function() return db.bartexture end,
set = function(win,key)
db.bartexture = key
Skada:ApplySettings()
end,
order = 12,
},
barspacing = {
type="range",
name=L["Bar spacing"],
desc=L["Distance between bars."],
min=0,
max=10,
step=1,
get=function() return db.barspacing end,
set=function(win, spacing)
db.barspacing = spacing
Skada:ApplySettings()
end,
order=13,
},
barheight = {
type="range",
name=L["Bar height"],
desc=L["The height of the bars."],
min=10,
max=40,
step=1,
get=function() return db.barheight end,
set=function(win, height)
db.barheight = height
Skada:ApplySettings()
end,
order=14,
},
barorientation = {
type="select",
name=L["Bar orientation"],
desc=L["The direction the bars are drawn in."],
values= function() return {[1] = L["Left to right"], [3] = L["Right to left"]} end,
get=function() return db.barorientation end,
set=function(win, orientation)
db.barorientation = orientation
Skada:ApplySettings()
end,
order=17,
},
reversegrowth = {
type="toggle",
name=L["Reverse bar growth"],
desc=L["Bars will grow up instead of down."],
order=19,
get=function() return db.reversegrowth end,
set=function()
db.reversegrowth = not db.reversegrowth
Skada:ApplySettings()
end,
},
color = {
type="color",
name=L["Bar color"],
desc=L["Choose the default color of the bars."],
hasAlpha=true,
get=function(i)
local c = db.barcolor
return c.r, c.g, c.b, c.a
end,
set=function(i, r,g,b,a)
db.barcolor = {["r"] = r, ["g"] = g, ["b"] = b, ["a"] = a}
Skada:ApplySettings()
end,
order=21,
},
bgcolor = {
type="color",
name=L["Background color"],
desc=L["Choose the background color of the bars."],
hasAlpha=true,
get=function(i) return db.barbgcolor.r, db.barbgcolor.g, db.barbgcolor.b, db.barbgcolor.a end,
set=function(i, r,g,b,a) db.barbgcolor = {["r"] = r, ["g"] = g, ["b"] = b, ["a"] = a}; Skada:ApplySettings() end,
order=22,
},
classcolorbars = {
type="toggle",
name=L["Class color bars"],
desc=L["When possible, bars will be colored according to player class."],
order=30,
get=function() return db.classcolorbars end,
set=function()
db.classcolorbars = not db.classcolorbars
Skada:ApplySettings()
end,
},
classcolortext = {
type="toggle",
name=L["Class color text"],
desc=L["When possible, bar text will be colored according to player class."],
order=31,
get=function() return db.classcolortext end,
set=function()
db.classcolortext = not db.classcolortext
Skada:ApplySettings()
end,
},
classicons = {
type="toggle",
name=L["Class icons"],
desc=L["Use class icons where applicable."],
order=32,
get=function() return db.classicons end,
set=function()
db.classicons = not db.classicons
Skada:ApplySettings()
end,
},
roleicons = {
type="toggle",
name=L["Role icons"],
desc=L["Use role icons where applicable."],
order=33,
get=function() return db.roleicons end,
set=function()
db.roleicons = not db.roleicons
Skada:ApplySettings()
end,
},
spellschoolcolors = {
type="toggle",
name=L["Spell school colors"],
desc=L["Use spell school colors where applicable."],
order=33,
get=function() return db.spellschoolcolors end,
set=function()
db.spellschoolcolors = not db.spellschoolcolors
Skada:ApplySettings()
end,
},
clickthrough = {
type="toggle",
name=L["Clickthrough"],
desc=L["Disables mouse clicks on bars."],
order=20,
get=function() return db.clickthrough end,
set=function()
db.clickthrough = not db.clickthrough
Skada:ApplySettings()
end,
},
smoothing = {
type="toggle",
name=L["Smooth bars"],
desc=L["Animate bar changes smoothly rather than immediately."],
order=34,
get=function() return db.smoothing end,
set=function()
db.smoothing = not db.smoothing
Skada:ApplySettings()
end,
},
alternaterows = {
type="toggle",
name=L["Alternate row colors"],
desc=L["Slightly darkens every other bar for easier readability."],
order=35,
get=function() return db.alternaterows end,
set=function()
db.alternaterows = not db.alternaterows
Skada:ApplySettings()
end,
},
highlightself = {
type="toggle",
name=L["Highlight self"],
desc=L["Adds a subtle highlight overlay on your own bar to make it easier to spot."],
order=36,
get=function() return db.highlightself end,
set=function()