Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
3942 lines (3722 loc) · 175 KB
/
Copy pathCore.lua
File metadata and controls
3942 lines (3722 loc) · 175 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
-- Tessera - Core.lua
-- ===========================================================================
-- Heart of the addon. Tessera shows small movable "blocks" on screen: data
-- blocks (gold, bags, FPS, time...) and launcher blocks (buttons that open
-- something). This file owns everything those blocks have in common.
--
-- Main responsibilities:
-- * Shared namespace `ns` (module registry, frames, runtime state) and Print.
-- * Media lists (backgrounds, borders, fonts), from the game itself and from
-- LibSharedMedia when another addon (e.g. FlareUI) provides some.
-- * Frame skinning (modern Blizzard nine-slice atlases or classic backdrops).
-- * Saved variables (TesseraDB): profiles, per-block defaults, account-wide
-- settings.
-- * Block creation, styling, visibility, text/icon updates, mouse handlers.
-- * Positioning: snapping to other blocks and to an optional grid.
-- * The default layout created on first install (a compact bar at the top).
-- * Event handling, the periodic update timer, slash commands and the
-- minimap / addon compartment button.
--
-- Related files (loaded after this one, see Tessera.toc):
-- Themes.lua visual themes (ApplyThemeToCfg, theme previews).
-- Merge.lua docking/merging blocks into groups, drag handling and the
-- border seams drawn where merged blocks meet
-- (AnchorDocked, FindDock, GetSubtree, Reroot, RequestLayout).
-- SecureClicks.lua secure click overlays, needed for actions that would be
-- blocked (tainted) when triggered from insecure addon code.
-- Changelog.lua version history shown in the options "Version" tab.
-- Modules.lua data block definitions (registered with ns:RegisterModule).
-- Launchers.lua launcher blocks (ns.launcherModule).
-- Broker.lua DataBroker: other addons' data objects shown as blocks
-- (ns.brokerModule), Tessera's blocks published as data
-- objects, and the DataBroker mode.
-- Options.lua the options window, welcome screen and debug report.
-- Locales/ translated strings, exposed as ns.L.
-- ===========================================================================
local ADDON, ns = ...
local L = ns.L
ns.modules = {}
ns.order = {}
ns.frames = {}
ns.errors = {}
ns.state = { inCombat = false, inInstance = false }
local DEFAULT_PROFILE = "Default"
local LAUNCHER_PREFIX = "launcher:"
ns.DEFAULT_PROFILE = DEFAULT_PROFILE
ns.LAUNCHER_PREFIX = LAUNCHER_PREFIX
-- Width of a block's text. The game measures inline textures (|T file:h:w:x:y|t, e.g. the
-- coin icons after gold amounts) badly: the icons spilled over the next block. Text with
-- textures is measured without them (on a hidden string with the same font), then each
-- texture adds its own width (w, or h when w is 0) and its horizontal offset.
local measure
local iconsWidth -- filled by AddIconWidth, read right after the gsub (no closure per call)
local function AddIconWidth(spec)
local _, h, w, x = spec:match("^([^:]*):?(%-?%d*):?(%-?%d*):?(%-?%d*)")
h, w, x = tonumber(h) or 0, tonumber(w) or 0, tonumber(x) or 0
if w == 0 then w = h end
-- measured in game (29/10): each icon takes about 3 px more than its size and offset
iconsWidth = iconsWidth + math.max(0, w) + math.max(0, x) + 3
return ""
end
function ns.TextWidth(fontString, text)
local plain = (fontString.GetUnboundedStringWidth and fontString:GetUnboundedStringWidth())
or fontString:GetStringWidth() or 0
if type(text) ~= "string" or not text:find("|T", 1, true) then return plain end
iconsWidth = 0
local stripped = text:gsub("|T([^|]*)|t", AddIconWidth)
local icons = iconsWidth
if not measure and CreateFrame and UIParent then
measure = UIParent:CreateFontString(nil, "BACKGROUND")
measure:Hide()
end
local font, size, flags
if fontString.GetFont then font, size, flags = fontString:GetFont() end
if not (measure and font) then return plain + icons end
measure:SetFont(font, size, flags)
measure:SetText(stripped)
local textW = (measure.GetUnboundedStringWidth and measure:GetUnboundedStringWidth()) or measure:GetStringWidth() or 0
return math.max(plain, textW + icons)
end
-- Chat output. In quiet mode nothing is printed, except in reply to a typed
-- command (/tessera ...) or in debug mode.
local function Print(msg)
if ns.sv and ns.sv.quiet and not ns.inCommand and not ns.debug then return end
print("|cff33aaffTessera|r : " .. msg)
end
ns.Print = Print
-- Streamer mode (account-wide): blocks and tooltips hide other players' names, your
-- other characters, your realm, your guild's name and your gold, for streams and videos
ns.HIDDEN = "***"
-- Streamer mode on; with a kind, whether that kind of information is hidden. Each kind has its
-- checkbox in the Streamer block's own settings (all on by default): "players" (other players'
-- names, notes, zones), "alts" (your other characters), "guild" (its name, message of the day and
-- emblem), "gold" (your gold and money amounts)
local STREAMER_FIELDS = { players = "streamerPlayers", alts = "streamerAlts", guild = "streamerGuild", gold = "streamerGold" }
function ns:IsStreamer(kind)
if not (self.sv ~= nil and self.sv.streamerMode == true) then return false end
if kind == nil then return true end
local cfg = self.db and self.db.blocks and self.db.blocks.streamer
return not (cfg and cfg[STREAMER_FIELDS[kind] or ""] == false)
end
function ns:SetStreamerMode(on)
if not self.sv then return end
self.sv.streamerMode = on and true or nil
Print(on and ns.L.STREAMER_ON_MSG or ns.L.STREAMER_OFF_MSG)
if self.built then self:UpdateAll() end
if self.RefreshOptions then self:RefreshOptions() end
end
---------------------------------------------------------------------------
-- Media shipped with the game
---------------------------------------------------------------------------
ns.backgrounds = {
{ key = "none", name = L.MEDIA_NONE },
{ key = "solid", name = L.MEDIA_SOLID, file = "Interface\\Buttons\\WHITE8X8" },
{ key = "tooltip", name = L.MEDIA_TOOLTIP, file = "Interface\\Tooltips\\UI-Tooltip-Background" },
{ key = "dialog", name = L.MEDIA_DIALOG, file = "Interface\\DialogFrame\\UI-DialogBox-Background" },
{ key = "dialogDark", name = L.MEDIA_DIALOG_DARK, file = "Interface\\DialogFrame\\UI-DialogBox-Background-Dark" },
{ key = "marble", name = L.MEDIA_MARBLE, file = "Interface\\FrameGeneral\\UI-Background-Marble", tile = true },
{ key = "rock", name = L.MEDIA_ROCK, file = "Interface\\FrameGeneral\\UI-Background-Rock", tile = true },
}
-- Border fields:
-- insetRatio: share of the border thickness that overlaps the background.
-- reach: length of the seam patch at inner corners of merged blocks (Merge.lua).
-- size: native border thickness in pixels.
ns.borders = {
{ key = "none", name = L.MEDIA_NONE },
{ key = "solid", name = L.MEDIA_SOLID, file = "Interface\\Buttons\\WHITE8X8", insetRatio = 1, reach = 1, size = 1 },
{ key = "tooltip", name = L.MEDIA_TOOLTIP, file = "Interface\\Tooltips\\UI-Tooltip-Border", insetRatio = 0.25, reach = 0.15, size = 16 },
{ key = "dialog", name = L.MEDIA_DIALOG, file = "Interface\\DialogFrame\\UI-DialogBox-Border", insetRatio = 0.35, reach = 0.23, size = 32 },
{ key = "gold", name = L.MEDIA_GOLD, file = "Interface\\DialogFrame\\UI-DialogBox-Gold-Border", insetRatio = 0.35, reach = 0.2, size = 32 },
-- Modern tooltip (Retail and Forever): Blizzard's atlas-based nine-slice frame
-- The game's own art: gold on WoW Forever, silver on Retail
{ key = "modernTooltip", name = L.MEDIA_MODERN_TOOLTIP, nineSlice = "TooltipDefaultLayout", reach = 0.33, size = 16 },
-- The same frame without its color (grey), tinted by the border color: silver on WoW Forever
{ key = "modernTooltipGrey", name = L.MEDIA_MODERN_TOOLTIP_GREY, nineSlice = "TooltipDefaultLayout", desaturate = true,
reach = 0.33, size = 16 },
}
ns.fonts = {
{ key = "friz", name = "Friz Quadrata", file = "Fonts\\FRIZQT__.TTF" },
{ key = "arial", name = "Arial Narrow", file = "Fonts\\ARIALN.TTF" },
-- Morpheus draws small letters: shown 2 points larger to read like the others
{ key = "morpheus", name = "Morpheus", file = "Fonts\\MORPHEUS.TTF", sizeBoost = 2 },
{ key = "skurri", name = "Skurri", file = "Fonts\\SKURRI.TTF" },
-- Accessibility fonts shipped with Tessera (licenses: Licenses folder and the About tab).
-- share = true: also offered to other addons through LibSharedMedia (ns:ShareFonts)
{ key = "atkinson", name = "Atkinson Hyperlegible", share = true, scripts = {"latin"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\AtkinsonHyperlegibleNext-Regular.ttf" },
{ key = "atkinsonbold", name = "Atkinson Hyperlegible Bold", share = true, scripts = {"latin"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\AtkinsonHyperlegibleNext-Bold.ttf" },
{ key = "opendyslexic", name = "OpenDyslexic", share = true, scripts = {"latin", "greek", "cyrillic"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\OpenDyslexic-Regular.otf" },
{ key = "opendyslexicbold", name = "OpenDyslexic Bold", share = true, scripts = {"latin", "greek", "cyrillic"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\OpenDyslexic-Bold.otf" },
{ key = "luciole", name = "Luciole", share = true, scripts = {"latin"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\Luciole-Regular.ttf" },
{ key = "luciolebold", name = "Luciole Bold", share = true, scripts = {"latin"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\Luciole-Bold.ttf" },
{ key = "lexend", name = "Lexend", share = true, scripts = {"latin"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\Lexend-Regular.ttf" },
{ key = "lexendbold", name = "Lexend Bold", share = true, scripts = {"latin"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\Lexend-Bold.ttf" },
{ key = "andika", name = "Andika", share = true, scripts = {"latin", "cyrillic"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\Andika-Regular.ttf" },
{ key = "andikabold", name = "Andika Bold", share = true, scripts = {"latin", "cyrillic"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\Andika-Bold.ttf" },
{ key = "inclusivesans", name = "Inclusive Sans", share = true, scripts = {"latin"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\InclusiveSans-Regular.ttf" },
{ key = "inclusivesansbold", name = "Inclusive Sans Bold", share = true, scripts = {"latin"},
file = "Interface\\AddOns\\Tessera\\Media\\Fonts\\InclusiveSans-Bold.ttf" },
}
---------------------------------------------------------------------------
-- Frames of known interface addons, treated like Blizzard's own frames: Tessera
-- warns when a block covers one (Layers) and blocks snap to the ones marked snap.
-- One entry per addon: the prefix of its global frame names, and for each frame
-- (name without the prefix) the plain-name key used in the overlap question.
-- Only names read in the interface's own code (never guessed); a missing frame is skipped.
ns.KNOWN_UI_FRAMES = {
{ prefix = "FlareUI_", frames = {
XPBar = { label = "EM_XP_BAR", snap = true }, Buffs = { label = "EM_BUFFS" },
Debuffs = { label = "EM_BUFFS" }, ObjectiveTracker = { label = "EM_OBJECTIVES" },
UF_Player = { label = "EM_UNIT_FRAMES" }, UF_Target = { label = "EM_UNIT_FRAMES" },
UF_Focus = { label = "EM_UNIT_FRAMES" }, UF_Pet = { label = "EM_UNIT_FRAMES" },
-- FlareUI 4.0: target of target and of focus, party, raid and boss frames
UF_TargetOfTarget = { label = "EM_UNIT_FRAMES" }, UF_TargetOfFocus = { label = "EM_UNIT_FRAMES" },
Party = { label = "EM_UNIT_FRAMES" }, Raid = { label = "EM_UNIT_FRAMES" }, Boss = { label = "EM_UNIT_FRAMES" },
UF_PlayerCastBar = { label = "EM_CAST_BAR" }, Totems = { label = "EM_TOTEMS" },
Toasts = { label = "EM_TOASTS" }, LootRolls = { label = "EM_LOOT_ROLLS" },
} },
-- EllesmereUI 9.6 (names read in its code; a module turned off has no frame)
{ prefix = "EllesmereUI", frames = {
UnitFrames_Player = { label = "EM_UNIT_FRAMES" }, UnitFrames_Target = { label = "EM_UNIT_FRAMES" },
UnitFrames_Focus = { label = "EM_UNIT_FRAMES" }, UnitFrames_Pet = { label = "EM_UNIT_FRAMES" },
UnitFrames_TargetTarget = { label = "EM_UNIT_FRAMES" }, UnitFrames_FocusTarget = { label = "EM_UNIT_FRAMES" },
PlayerAuraBars_Buffs = { label = "EM_BUFFS" }, PlayerAuraBars_Debuffs = { label = "EM_BUFFS" },
QTBackground = { label = "EM_OBJECTIVES" }, MicroMenu = { label = "EM_MENU" },
} },
{ prefix = "ERB_", frames = { CastBarFrame = { label = "EM_CAST_BAR" } } },
-- DaylightUI 1.6 (names read in its code; its XP bar has no frame of its own, it lives in the info panel)
{ prefix = "DaylightUI", frames = {
Frame_player = { label = "EM_UNIT_FRAMES" }, Frame_target = { label = "EM_UNIT_FRAMES" },
Frame_targettarget = { label = "EM_UNIT_FRAMES" }, Frame_pet = { label = "EM_UNIT_FRAMES" },
Frame_focus = { label = "EM_UNIT_FRAMES" },
Buffs = { label = "EM_BUFFS" }, Debuffs = { label = "EM_BUFFS" },
QuestTracker = { label = "EM_OBJECTIVES" }, Chat = { label = "EM_CHAT" },
InfoPanel = { label = "EM_INFO_PANEL" }, DataBar = { label = "EM_INFO_PANEL" },
} },
-- ElvUI 16 (names read in its code). Some names carry no prefix: only with ElvUI loaded
{ addon = "ElvUI", prefix = "", frames = {
ElvUF_Player = { label = "EM_UNIT_FRAMES" }, ElvUF_Target = { label = "EM_UNIT_FRAMES" },
ElvUF_TargetTarget = { label = "EM_UNIT_FRAMES" }, ElvUF_Focus = { label = "EM_UNIT_FRAMES" },
ElvUF_Pet = { label = "EM_UNIT_FRAMES" },
ElvUIPlayerBuffs = { label = "EM_BUFFS" }, ElvUIPlayerDebuffs = { label = "EM_BUFFS" },
ElvUI_ExperienceBar = { label = "EM_XP_BAR", snap = true }, ElvUI_ReputationBar = { label = "EM_XP_BAR" },
ElvUI_MinimapHolder = { label = "EM_MINIMAP" }, ObjectiveFrameHolder = { label = "EM_OBJECTIVES" },
LeftChatPanel = { label = "EM_CHAT" }, RightChatPanel = { label = "EM_CHAT" },
ElvUI_MicroBar = { label = "EM_MENU" }, ElvUI_StanceBar = { label = "EM_ACTION_BARS" },
ElvUI_BarPet = { label = "EM_ACTION_BARS" },
} },
}
-- ElvUI's action bars: ElvUI_Bar1 to ElvUI_Bar15
for i = 1, 15 do ns.KNOWN_UI_FRAMES[#ns.KNOWN_UI_FRAMES].frames["ElvUI_Bar" .. i] = { label = "EM_ACTION_BARS" } end
-- GW2 UI 12.0 (names read in its code)
table.insert(ns.KNOWN_UI_FRAMES, { addon = "GW2_UI", prefix = "", frames = {
GwPlayerUnitFrame = { label = "EM_UNIT_FRAMES" }, GwTargetUnitFrame = { label = "EM_UNIT_FRAMES" },
GwFocusUnitFrame = { label = "EM_UNIT_FRAMES" }, GwPlayerPetFrame = { label = "EM_UNIT_FRAMES" },
GwPlayerPowerBar = { label = "EM_UNIT_FRAMES" }, GwPlayerClassPower = { label = "EM_UNIT_FRAMES" },
GwQuestTracker = { label = "EM_OBJECTIVES" }, GwExperienceFrame = { label = "EM_XP_BAR", snap = true },
Gw2MicroBarFrame = { label = "EM_MENU" }, GwStanceBar = { label = "EM_ACTION_BARS" },
GwTotemBar = { label = "EM_TOTEMS" },
} })
---------------------------------------------------------------------------
-- First-run windows of other interfaces (setup guide, tour): Tessera's own popups wait for
-- them to close, then follow. Names read in each addon's code (docs/etudes/SOURCES.md).
---------------------------------------------------------------------------
ns.FIRST_RUN_WINDOWS = {
"DaylightUIInstaller", "DaylightUITour", "DaylightUITourAsk", -- DaylightUI
"FlareUI_Tour", "FlareUI_Welcome", -- FlareUI
"ElvUIInstallFrame", "PluginInstallFrame", "ElvUITutorialWindow", -- ElvUI
"EUIFirstInstallPopup", -- EllesmereUI
"GwWelcomePage", -- GW2 UI
}
local WAIT_POLL, WAIT_SETTLE, WAIT_MAX = 2, 2, 1800 -- seconds: check, pause after a close, give up
-- True while one of those windows is open
function ns:OtherUIBusy()
for _, name in ipairs(self.FIRST_RUN_WINDOWS) do
local f = _G[name]
if type(f) == "table" and type(f.IsShown) == "function" then
local ok, shown = pcall(f.IsShown, f)
if ok and shown then return true end
end
end
return false
end
-- Runs fn at once when no such window is open; otherwise when the last one has closed and
-- stayed closed for a moment (a tour often follows a setup guide). Gives up waiting after 30 minutes.
function ns:WhenOtherUIFree(fn)
local waited, sawBusy = 0, false
local function Step()
if ns:OtherUIBusy() and waited < WAIT_MAX then
waited, sawBusy = waited + WAIT_POLL, true
C_Timer.After(WAIT_POLL, Step)
elseif sawBusy then
sawBusy = false
C_Timer.After(WAIT_SETTLE, Step)
else
fn()
end
end
Step()
end
-- Calls fn(frame, info) for every existing frame of ns.KNOWN_UI_FRAMES
function ns:ForEachKnownUIFrame(fn)
local loaded = C_AddOns and C_AddOns.IsAddOnLoaded
for _, ui in ipairs(self.KNOWN_UI_FRAMES) do
local skip = ui.addon and not (loaded and loaded(ui.addon))
for short, info in pairs(skip and {} or ui.frames) do
local f = _G[ui.prefix .. short]
if type(f) == "table" and f.GetRect and not (f.IsForbidden and f:IsForbidden()) then fn(f, info) end
end
end
end
-- Media from other addons (FlareUI, etc.) via LibSharedMedia, if present
---------------------------------------------------------------------------
local BUILTIN = { background = ns.backgrounds, border = ns.borders, font = ns.fonts }
-- Saved media keys starting with this prefix refer to a LibSharedMedia entry
local LSM_PREFIX = "lsm:"
ns.LSM_PREFIX = LSM_PREFIX -- media from LibSharedMedia (checked on import, Profiles.lua)
-- Returns LibSharedMedia if some addon loaded it (silent = true: no error if missing)
function ns:GetLSM()
return LibStub and LibStub("LibSharedMedia-3.0", true)
end
-- Normalizes a texture path so the same file is detected under any spelling
local function NormalizePath(path)
return type(path) == "string" and path:gsub("/", "\\"):lower() or path
end
-- Gap between border and background, depending on the border image
local function LSMInsetRatio(file)
if type(file) == "string" and file:find("FlareUI%-Thin") then
return 3 / 8 -- FlareUI: 8 px Thin border, 3 px gap
end
return 3 / 16 -- FlareUI: 16 px borders, 3 px gap
end
-- Offers Tessera's own fonts to other addons (ElvUI, Details, WeakAuras...) when some addon
-- already loaded LibSharedMedia. A name another addon registered first is left alone.
function ns:ShareFonts()
local LSM = self:GetLSM()
if not (LSM and LSM.Register) then return end
for _, item in ipairs(ns.fonts) do
if item.share then pcall(LSM.Register, LSM, "font", item.name, item.file) end
end
end
-- Font shared by all the blocks (nil when they differ): the Accessibility tab's Font setting
-- is the same as "Font" under "All blocks" in the Blocks tab, so each follows the other
function ns:AllBlocksFont()
local font
for _, key in ipairs(self:GetBlockKeys()) do
local cfg = self.db.blocks[key]
-- spacers keep their own look: "All blocks" does not change them
if cfg and not self.IsSpacerKey(key) then
if font and cfg.font ~= font then return nil end
font = cfg.font
end
end
return font
end
-- Sets the font of all the blocks (what "All blocks" does in the Blocks tab), also for blocks
-- and launchers created later
function ns:SetAllBlocksFont(value)
for _, key in ipairs(self:GetBlockKeys()) do
local cfg = self.db.blocks[key]
if cfg and not self.IsSpacerKey(key) then
cfg.font = value
self:ApplyStyle(key)
end
end
self.db.groupDefaults.font = value
self.db.launcherDefaults.font = value
end
-- Menu text of a media entry: its name, then in grey the alphabets it covers (set for
-- Tessera's own fonts only, measured on the font files: other fonts show no note)
function ns:MediaLabel(opt)
if not opt.scripts then return opt.name end
local texts = { latin = L.SCRIPT_LATIN, greek = L.SCRIPT_GREEK, cyrillic = L.SCRIPT_CYRILLIC }
local names = {}
for _, script in ipairs(opt.scripts) do
table.insert(names, texts[script] or script)
end
return opt.name .. " |cff999999(" .. table.concat(names, ", ") .. ")|r"
end
-- Full list for one media kind: the game's media, then LibSharedMedia's
-- (files already listed are skipped to avoid duplicates)
function ns:GetMediaList(kind)
local list, known = {}, {}
for _, item in ipairs(BUILTIN[kind]) do
table.insert(list, item)
if item.file then known[NormalizePath(item.file)] = true end
end
local LSM = self:GetLSM()
if LSM then
for _, name in ipairs(LSM:List(kind)) do
local file = LSM:Fetch(kind, name, true)
if file and not known[NormalizePath(file)] then
known[NormalizePath(file)] = true
table.insert(list, { key = LSM_PREFIX .. name, name = name })
end
end
end
-- other addons can add media at any time: the options show it as a plain list, never ◄ ►
list.mayGrow = true
return list
end
-- The eight border pieces (corners and edges) of a frame's nine-slice / backdrop
ns.EDGE_PIECES = {
"TopLeftCorner", "TopRightCorner", "BottomLeftCorner", "BottomRightCorner",
"TopEdge", "BottomEdge", "LeftEdge", "RightEdge",
}
-- Frame skin (block or options window): "modern" (Blizzard atlases),
-- "backdrop" (classic textures) or "none". Both systems use the same texture
-- pieces; when switching systems we reset them so nothing of the old one is
-- left over (edge tiling, positions, colors).
local ALL_PIECES = {
"TopLeftCorner", "TopRightCorner", "BottomLeftCorner", "BottomRightCorner",
"TopEdge", "BottomEdge", "LeftEdge", "RightEdge", "Center",
}
-- Clears every skin piece of a frame back to a blank, hidden state
local function ResetPieces(frame)
for _, name in ipairs(ALL_PIECES) do
local piece = frame[name]
if piece then
piece:ClearAllPoints()
piece:SetTexture(nil)
piece:SetTexCoord(0, 1, 0, 1)
if piece.SetHorizTile then piece:SetHorizTile(false) end
if piece.SetVertTile then piece:SetVertTile(false) end
piece:SetVertexColor(1, 1, 1, 1)
piece:Hide()
end
end
end
-- Unpacks a color given as {r=,g=,b=,a=} or {1,2,3,4}; missing values default to 1
local function Rgba(c)
if not c then return 1, 1, 1, 1 end
return c.r or c[1] or 1, c.g or c[2] or 1, c.b or c[3] or 1, c.a or c[4] or 1
end
-- Applies a skin to a frame. spec.kind is "modern" (spec.layout = nine-slice
-- layout name), "backdrop" (spec.info = backdrop table) or "none"; spec.border
-- and spec.bg are colors. Returns the border thickness for "modern" skins
-- (used to compute insets and seams), 0 otherwise.
-- Expansion frame art (The War Within, Midnight): one sliced border atlas over a tiled
-- background atlas, as Blizzard draws its own windows of those expansions
local function AtlasArt(frame, spec)
if not frame.tesseraArtBg then
-- a solid base under the tile: the expansion's background tile is partly see-through,
-- and the game's texts behind the window showed through it
frame.tesseraArtBase = frame:CreateTexture(nil, "BACKGROUND", nil, -8)
frame.tesseraArtBg = frame:CreateTexture(nil, "BACKGROUND", nil, -7)
frame.tesseraArtBorder = frame:CreateTexture(nil, "BORDER", nil, 7)
end
local base, bgTex, border = frame.tesseraArtBase, frame.tesseraArtBg, frame.tesseraArtBorder
if not spec then base:Hide(); bgTex:Hide(); border:Hide(); return end
base:ClearAllPoints()
base:SetPoint("TOPLEFT", spec.bgInset or 8, -(spec.bgInset or 8))
base:SetPoint("BOTTOMRIGHT", -(spec.bgInset or 8), spec.bgInset or 8)
base:SetColorTexture(0.03, 0.025, 0.02, 1)
base:Show()
bgTex:ClearAllPoints()
bgTex:SetPoint("TOPLEFT", spec.bgInset or 8, -(spec.bgInset or 8))
bgTex:SetPoint("BOTTOMRIGHT", -(spec.bgInset or 8), spec.bgInset or 8)
bgTex:SetAtlas(spec.bgAtlas, false)
if bgTex.SetHorizTile then bgTex:SetHorizTile(true); bgTex:SetVertTile(true) end
bgTex:SetVertexColor(Rgba(spec.bg))
bgTex:Show()
border:ClearAllPoints()
border:SetAllPoints(frame)
border:SetAtlas(spec.borderAtlas, false)
border:Show()
end
function ns:ApplySkin(frame, spec)
if spec.kind ~= "atlas" and frame.tesseraArtBg then AtlasArt(frame, nil) end
-- DaylightUI draws its look on a child frame it keeps for good: hide it when the look changes
if spec.kind ~= "daylight" and frame.tesseraDaylightShell then
frame.tesseraDaylightShell:Hide()
end
if frame.skinKind and frame.skinKind ~= spec.kind then
if frame.backdropInfo then frame:SetBackdrop(nil) end
ResetPieces(frame)
end
frame.skinKind = spec.kind
if spec.kind == "modern" then
if frame.backdropInfo then frame:SetBackdrop(nil) end
NineSliceUtil.ApplyLayoutByName(frame, spec.layout)
for _, name in ipairs(ns.EDGE_PIECES) do
local piece = frame[name]
if piece then
if piece.SetDesaturated then piece:SetDesaturated(spec.desaturate == true) end
piece:SetVertexColor(Rgba(spec.border))
piece:Show()
end
end
if frame.Center then
frame.Center:SetVertexColor(Rgba(spec.bg))
frame.Center:SetShown(spec.showCenter ~= false)
end
-- Thickness: read from the corner's atlas info. Right after applying the
-- layout, the corner's size may still be the previous theme's (or 0).
local corner = frame.TopLeftCorner
local atlas = corner and corner.GetAtlas and corner:GetAtlas()
local info = atlas and C_Texture and C_Texture.GetAtlasInfo and C_Texture.GetAtlasInfo(atlas)
if info and info.width and info.width > 0 then return info.width end
return corner and corner:GetWidth() or 0
elseif spec.kind == "atlas" then
if frame.backdropInfo then frame:SetBackdrop(nil) end
ResetPieces(frame)
AtlasArt(frame, spec)
elseif spec.kind == "daylight" then
if frame.backdropInfo then frame:SetBackdrop(nil) end
ResetPieces(frame)
-- the shell (shadow, rounded border, background) comes from DaylightUI's own API;
-- the border thickness is the block's, the colors are the player's DaylightUI settings
local api = self:GetDaylightAPI()
local ok, shell = false, nil
if api then
ok, shell = pcall(api.Skin, frame, { borderPx = spec.borderPx, bgAlpha = spec.bgAlpha })
end
if ok and type(shell) == "table" and shell.Show then
frame.tesseraDaylightShell = shell
shell:Show()
end
elseif spec.kind == "backdrop" then
frame:SetBackdrop(spec.info)
if spec.info.bgFile then
frame:SetBackdropColor(Rgba(spec.bg))
if frame.Center then frame.Center:Show() end
end
if spec.info.edgeFile then
frame:SetBackdropBorderColor(Rgba(spec.border))
for _, name in ipairs(ns.EDGE_PIECES) do
if frame[name] then frame[name]:Show() end
end
end
else
if frame.backdropInfo then frame:SetBackdrop(nil) end
ResetPieces(frame)
end
return 0
end
-- Resolves a saved media key to its description table. "lsm:" keys are
-- looked up in LibSharedMedia; unknown keys fall back to the first entry.
function ns:FindMedia(kind, key)
if type(key) == "string" and key:sub(1, #LSM_PREFIX) == LSM_PREFIX then
local LSM = self:GetLSM()
local file = LSM and LSM:Fetch(kind, key:sub(#LSM_PREFIX + 1), true)
if file then
-- Values tuned in game: FlareUI Thick and Frames 0.10, FlareUI Thin 0.4; otherwise the middle
local reach = 0.5
if type(file) == "string" then
if file:find("FlareUI%-Thick") or file:find("FlareUI%-Frames") then reach = 0.10
elseif file:find("FlareUI") then reach = 0.4 end
end
-- Native thickness: 8 px for FlareUI Thin (as in FlareUI), 16 px otherwise
local size = (type(file) == "string" and file:find("FlareUI%-Thin")) and 8 or 16
return { key = key, file = file, insetRatio = LSMInsetRatio(file), reach = reach, size = size }
end
-- Providing addon missing: fall back to a game media
key = (kind == "font") and "friz" or "solid"
end
-- DaylightUI's own look (not in the lists: only its style sets it); without it, the plain one
if key == "daylight" then
local api = self:GetDaylightAPI()
if kind == "border" and api then
return { key = key, daylight = true, insetRatio = 0, reach = 0.5, size = 2 }
elseif kind == "font" and api and type(api.Font) == "function" then
local ok, file = pcall(api.Font)
if ok and type(file) == "string" and file ~= "" then return { key = key, file = file } end
end
key = (kind == "font") and "arial" or "solid"
end
local list = BUILTIN[kind]
for _, item in ipairs(list) do
if item.key == key then return item end
end
return list[1]
end
-- DaylightUI's public API (version 1), or nil. Read through _G: it is another addon's global.
-- Only the calls its API.md promises are used: Skin, Font, Accent.
function ns:GetDaylightAPI()
local dui = _G["DaylightUI"]
local api = type(dui) == "table" and dui.API
if type(api) == "table" and api.major == 1 and type(api.Skin) == "function" then return api end
end
-- True when FlareUI's media are registered (used to pick the FlareUI-style default layout)
function ns:HasFlareUIMedia()
local LSM = self:GetLSM()
return LSM and LSM:Fetch("border", "FlareUI Thin", true) ~= nil
end
---------------------------------------------------------------------------
-- Utilities
---------------------------------------------------------------------------
local function DeepCopy(src)
if type(src) ~= "table" then return src end
local t = {}
for k, v in pairs(src) do t[k] = DeepCopy(v) end
return t
end
ns.DeepCopy = DeepCopy
-- Fills missing values of dst from src (recursively), never overwriting existing ones
local function CopyDefaults(src, dst)
for k, v in pairs(src) do
if type(v) == "table" then
if type(dst[k]) ~= "table" then dst[k] = {} end
CopyDefaults(v, dst[k])
elseif dst[k] == nil then
dst[k] = v
end
end
return dst
end
-- Launcher blocks are stored under keys like "launcher:<id>"
function ns.IsLauncherKey(key)
return type(key) == "string" and key:sub(1, #LAUNCHER_PREFIX) == LAUNCHER_PREFIX
end
-- DataBroker blocks (another addon's LibDataBroker object) use keys like "broker:<object name>"
local BROKER_PREFIX = "broker:"
ns.BROKER_PREFIX = BROKER_PREFIX
function ns.IsBrokerKey(key)
return type(key) == "string" and key:sub(1, #BROKER_PREFIX) == BROKER_PREFIX
end
-- Launchers and DataBroker blocks pass every click on to the other addon
function ns.IsForwardingKey(key)
return ns.IsLauncherKey(key) or ns.IsBrokerKey(key)
end
-- Sort key of a displayed name: lower case, accents removed ("Épuré" next to "Epic")
local ACCENTS = { ["à"] = "a", ["â"] = "a", ["ä"] = "a", ["é"] = "e", ["è"] = "e", ["ê"] = "e", ["ë"] = "e",
["î"] = "i", ["ï"] = "i", ["ô"] = "o", ["ö"] = "o", ["ù"] = "u", ["û"] = "u", ["ü"] = "u", ["ç"] = "c",
["É"] = "e", ["È"] = "e", ["Ê"] = "e", ["À"] = "a", ["Ç"] = "c", ["Ô"] = "o", ["Î"] = "i" }
function ns.SortKey(name)
local key = tostring(name)
for accented, plain in pairs(ACCENTS) do key = key:gsub(accented, plain) end
return key:lower()
end
-- A group can hang below (second row) or above (bottom bar) another block:
-- cfg.anchor.below / cfg.anchor.above = that block's key. Returns that key.
function ns.HangTarget(anchor)
return anchor and (anchor.below or anchor.above) or nil
end
-- What makes the place of a block: its position (free point, dock, anchor) and, for
-- the first block of a group, the group's own settings (scale, frozen state, screen
-- edges, stretch, group look).
local PLACE_FIELDS = { "point", "dock", "anchor", "scale", "frozen", "edges", "stretch", "look" }
-- Takes a block out of its group, in the saved data only (no frame is touched):
-- * one of the blocks docked to it (its heir) takes its seat: the same dock, or the
-- group's place and settings if it headed the group. The heir is the block that
-- carried on its row, else the first one docked to it. The others follow the heir
-- (at the end of the row if the heir already has a block on that side);
-- * a row hanging on it hangs on the heir, or takes its place when it was alone;
-- * the block itself keeps its look and settings but has no place left.
-- Keys are walked in sorted order: the same data always gives the same result.
-- Damaged data (loops, docks to nothing) raises no error. Returns true when something changed.
-- Known limit: a block with several branches around it (three blocks docked to it on
-- different sides) can make two of them meet; the player moves one with the mouse.
function ns.LeaveGroupData(blocks, key)
local me = type(blocks) == "table" and blocks[key]
if type(me) ~= "table" then return false end
local function Dock(cfg) return type(cfg) == "table" and type(cfg.dock) == "table" and cfg.dock or nil end
local function Anchor(cfg) return type(cfg) == "table" and type(cfg.anchor) == "table" and cfg.anchor or nil end
local keys = {}
for k, cfg in pairs(blocks) do
if k ~= key and type(k) == "string" and type(cfg) == "table" then keys[#keys + 1] = k end
end
table.sort(keys)
-- the last block of the row that already leaves `to` on `side` (or `to` itself)
local function RowEnd(to, side, mover)
for _ = 1, #keys + 1 do
local nextKey
for _, k in ipairs(keys) do
local d = Dock(blocks[k])
if k ~= mover and d and d.to == to and d.side == side then nextKey = k break end
end
if not nextKey then break end
to = nextKey
end
return to
end
local changed = false
local myDock = Dock(me)
local upTo = myDock and myDock.to ~= key and type(blocks[myDock.to]) == "table" and myDock.to or nil
local dependents = {}
for _, k in ipairs(keys) do
local d = Dock(blocks[k])
if d and d.to == key then dependents[#dependents + 1] = k end
end
local heir = dependents[1]
if heir and upTo then
for _, k in ipairs(dependents) do
if blocks[k].dock.side == myDock.side then heir = k break end
end
end
if not heir and not upTo and (me.point ~= nil or Anchor(me)) then
-- alone in its row, but another row may hang on it: that row takes its place
for _, k in ipairs(keys) do
local a = Anchor(blocks[k])
if a and (a.below == key or a.above == key) and not Dock(blocks[k]) then heir = k break end
end
if heir then
for _, field in ipairs(PLACE_FIELDS) do blocks[heir][field] = ns.DeepCopy(me[field]) end
blocks[heir].dock = nil
changed = true
end
elseif heir then
if upTo then
blocks[heir].dock = { to = upTo, side = myDock.side }
else
for _, field in ipairs(PLACE_FIELDS) do blocks[heir][field] = ns.DeepCopy(me[field]) end
blocks[heir].dock = nil
end
changed = true
for _, k in ipairs(dependents) do
if k ~= heir then
blocks[k].dock.to = RowEnd(heir, blocks[k].dock.side, k)
end
end
end
if heir then
-- damaged data (a loop): the place it takes must not hang on itself
local a = Anchor(blocks[heir])
if a and a.below == heir then a.below = nil end
if a and a.above == heir then a.above = nil end
end
-- rows hanging on it now hang on the heir (never on themselves)
for _, k in ipairs(keys) do
local a = Anchor(blocks[k])
if a then
local target = heir or upTo
if target == k then target = nil end
if a.below == key then a.below = target changed = true end
if a.above == key then a.above = target changed = true end
end
end
for _, field in ipairs(PLACE_FIELDS) do
if me[field] ~= nil then me[field] = nil changed = true end
end
return changed
end
-- A block that is turned off has no place: profiles made before 1.3 (and texts exported
-- from them) kept one, which left a gap in the bar. Does nothing the second time.
function ns.TidyRemovedBlocks(blocks)
if type(blocks) ~= "table" then return false end
local keys = {}
for k, cfg in pairs(blocks) do
if type(k) == "string" and type(cfg) == "table" and cfg.enabled == false then keys[#keys + 1] = k end
end
table.sort(keys)
local changed = false
for _, k in ipairs(keys) do
-- it had a place, so the player has had it on screen: its look is the player's
if ns.LeaveGroupData(blocks, k) then
blocks[k].keepLook = true
changed = true
end
end
return changed
end
-- Spacer blocks (empty, separator line or free text) use keys like "spacer:<n>"
local SPACER_PREFIX = "spacer:"
ns.SPACER_PREFIX = SPACER_PREFIX
function ns.IsSpacerKey(key)
return type(key) == "string" and key:sub(1, #SPACER_PREFIX) == SPACER_PREFIX
end
-- Threshold colors: 1 = good, 2 = warning, 3 = critical. Account-wide choice
-- (sv.levelPalette): "bright", "soft" (FlareUI's unit frame tones), "colorblind"
-- (blue / orange / purple) or nil = automatic: soft with a FlareUI style, bright otherwise.
ns.LEVEL_COLORS = { "4dff4d", "ffd933", "ff4d4d" }
local PALETTES = {
bright = { "4dff4d", "ffd933", "ff4d4d" },
-- FlareUI 2.1's "FlareUI" colour palette: health 0.15/0.82/0.15, neutral 0.93/0.78/0.25,
-- hostile 0.87/0.27/0.27
soft = { "26d126", "edc740", "de4545" },
colorblind = { "4da6ff", "ffb000", "c060ff" },
}
function ns:GetLevelPalette()
local sv = self.sv
if not sv then return "bright" end
-- before 1.0.0 the colorblind palette was a checkbox
if sv.colorblind then sv.levelPalette, sv.colorblind = "colorblind", nil end
return sv.levelPalette or "auto"
end
function ns:ApplyLevelPalette()
local key = self:GetLevelPalette()
if key == "auto" then
local theme = self.db and self.GetTheme and self:GetTheme()
key = (ns.IsFlareTheme and ns.IsFlareTheme(theme)) and "soft" or "bright"
end
for i, hex in ipairs(PALETTES[key] or PALETTES.bright) do ns.LEVEL_COLORS[i] = hex end
-- "soft" also tones the class colors down (the colorblind palette leaves them as they are)
ns.softColors = (key == "soft") or nil
end
-- r, g, b of a class ("WARRIOR"...): the game's class colors, as FlareUI uses them.
-- With the soft colors (General tab) they are 15% darker, the way they look on FlareUI's
-- textured bars. nil for an unknown class.
local SOFT_CLASS = 0.85
function ns:ClassColorRGB(class)
local c = class and ((C_ClassColor and C_ClassColor.GetClassColor(class)) or (RAID_CLASS_COLORS and RAID_CLASS_COLORS[class]))
if not c then return nil end
if ns.softColors then return c.r * SOFT_CLASS, c.g * SOFT_CLASS, c.b * SOFT_CLASS end
return c.r, c.g, c.b
end
-- Color of the player's class (for the "class color" options). alpha: the opacity to keep
-- (e.g. the background's own opacity), 1 by default.
function ns:GetClassColor(alpha)
local _, class = UnitClass("player")
local r, g, b = self:ClassColorRGB(class)
if r then return { r = r, g = g, b = b, a = alpha or 1 } end
end
-- Sets a texture from an icon spec: a file path / file ID, or a table
-- { file | atlas, coords, color }. 134400 is the "question mark" icon.
function ns:SetIcon(tex, icon)
tex:SetVertexColor(1, 1, 1)
tex:SetTexCoord(0, 1, 0, 1)
if type(icon) ~= "table" then icon = { file = icon } end
if tex.SetRotation then tex:SetRotation(icon.rotation or 0) end
if icon.atlas then
tex:SetAtlas(icon.atlas)
else
tex:SetTexture(icon.file or 134400)
if icon.coords and #icon.coords >= 4 then
tex:SetTexCoord(unpack(icon.coords))
elseif type(icon.file) == "string" and icon.file:gsub("/", "\\"):lower():find("interface\\icons\\", 1, true) then
tex:SetTexCoord(0.07, 0.93, 0.07, 0.93) -- crops the built-in frame of spell icons
end
end
if icon.color then
tex:SetVertexColor(icon.color[1] or 1, icon.color[2] or 1, icon.color[3] or 1)
end
end
-- Icon frame, shape and color (Frame tab, "Icon" section), applied after SetIcon:
-- square: icon cropped (no built-in edge) inside a thin colored square
-- round: icon cut into a circle inside a thin colored ring
-- black and white: desaturated icon
local CIRCLE_MASK = "Interface\\CharacterFrame\\TempPortraitAlphaMask"
function ns:StyleIcon(f, cfg)
local tex, shape = f.icon, cfg.iconShape or "none"
if tex.SetDesaturated then tex:SetDesaturated((cfg.iconDesaturate or cfg.monochrome) and true or false) end
-- crop the icon's own edge when it gets a frame (only if it is not cropped already)
if shape ~= "none" and tex.GetTexCoord then
local l, t, _, _, _, _, r, b = tex:GetTexCoord()
if l and r and b and l <= 0.01 and r >= 0.99 then
local dx, dy = (r - l) * 0.08, (b - t) * 0.08
tex:SetTexCoord(l + dx, r - dx, t + dy, b - dy)
end
end
-- the frame: a colored texture just larger than the icon, behind it
if not f.iconBorder then
f.iconBorder = f:CreateTexture(nil, "ARTWORK", nil, -1)
f.iconBorder:SetTexture("Interface\\Buttons\\WHITE8X8")
end
local border = f.iconBorder
local edge = self:PixelSize(1, f)
border:ClearAllPoints()
border:SetPoint("TOPLEFT", tex, "TOPLEFT", -edge, edge)
border:SetPoint("BOTTOMRIGHT", tex, "BOTTOMRIGHT", edge, -edge)
local c = cfg.iconBorderColor or {}
if cfg.classColorIcon then c = self:GetClassColor(c.a) or c end
border:SetVertexColor(c.r or 0, c.g or 0, c.b or 0, c.a or 1)
border:SetShown(shape ~= "none" and tex:IsShown())
-- round: a circle mask on both the icon and its frame
if f.CreateMaskTexture and tex.AddMaskTexture then
if not f.iconMask then
f.iconMask = f:CreateMaskTexture()
if not f.iconMask then return end
f.iconMask:SetTexture(CIRCLE_MASK, "CLAMPTOBLACKADDITIVE", "CLAMPTOBLACKADDITIVE")
f.iconMask:SetAllPoints(tex)
f.borderMask = f:CreateMaskTexture()
f.borderMask:SetTexture(CIRCLE_MASK, "CLAMPTOBLACKADDITIVE", "CLAMPTOBLACKADDITIVE")
f.borderMask:SetAllPoints(border)
end
local round = shape == "round"
if round ~= (f.iconMasked or false) then
if round then
tex:AddMaskTexture(f.iconMask)
border:AddMaskTexture(f.borderMask)
else
tex:RemoveMaskTexture(f.iconMask)
border:RemoveMaskTexture(f.borderMask)
end
f.iconMasked = round
end
end
end
-- Places the tooltip below or above the block, toward the screen center
-- Tooltip size chosen in the General tab ("Tooltip size"), for block tooltips only.
-- GameTooltip is shared with the whole game: its own scale is remembered and given
-- back as soon as it hides, so other tooltips are never affected.
local tooltipBaseScale, tooltipHooked = {}, {}
local function ScaleTooltip(owner, tooltip)
local scale = (owner and owner.key and ns.db and ns.db.tooltipScale) or 1
if scale == 1 and not tooltipBaseScale[tooltip] then return end
if not tooltipHooked[tooltip] then
tooltipHooked[tooltip] = true
tooltip:HookScript("OnHide", function(self)
if tooltipBaseScale[self] then
self:SetScale(tooltipBaseScale[self])
tooltipBaseScale[self] = nil
end
end)
end
tooltipBaseScale[tooltip] = tooltipBaseScale[tooltip] or tooltip:GetScale()
tooltip:SetScale(tooltipBaseScale[tooltip] * scale)
end
-- A blank line between two parts of a tooltip (title / info / help), unless the player turned
-- the spacing off. Returns true when it added the line. Used by every block's tooltip.
function ns.TooltipGap(tt)
if ns.db and ns.db.tooltipSpacing == false then return false end
tt:AddLine(" ")
return true
end
function ns.AnchorTooltip(owner, tooltip)
tooltip = tooltip or GameTooltip
tooltip:SetOwner(owner, "ANCHOR_NONE")
ScaleTooltip(owner, tooltip)
ns.MoveTooltip(owner, tooltip)
end
-- Which side of the block a tooltip (or a list) opens on, from the block's "tooltip alignment" and
-- "tooltip position" settings: h is "LEFT", "RIGHT" or "" (centered), below is true under the block
local function TooltipSide(owner)
-- center of the block in UIParent units (the block may have its own scale)
local l, b, r, t = ns:GetRectUI(owner)
if not l then return nil end
local x, y = (l + r) / 2, (b + t) / 2
local cfg = owner.key and ns.db and ns.db.blocks[owner.key]
-- the block's "tooltip alignment" option: left edge, centered or right edge of the block;
-- automatic keeps the edge on the side of the screen's middle where the block is
local align = cfg and cfg.tooltipAlign
local h = x > UIParent:GetWidth() / 2 and "RIGHT" or "LEFT"
if align == "left" then h = "LEFT" elseif align == "right" then h = "RIGHT" elseif align == "center" then h = "" end
-- the block's "tooltip position" option can force above or below
local below = y > UIParent:GetHeight() / 2
if cfg and cfg.tooltipAnchor == "top" then below = false end
if cfg and cfg.tooltipAnchor == "bottom" then below = true end
return h, below
end
-- Repositions an already-owned tooltip (also used when the block moves)
function ns.MoveTooltip(owner, tooltip)
tooltip = tooltip or GameTooltip
local h, below = TooltipSide(owner)
if not h then return end
tooltip:ClearAllPoints()
if below then
tooltip:SetPoint("TOP" .. h, owner, "BOTTOM" .. h, 0, -4)
else
tooltip:SetPoint("BOTTOM" .. h, owner, "TOP" .. h, 0, 4)
end
end
-- Places a list that opens in place of the tooltip: the same side and alignment as the tooltip would
-- have (the block's own settings), a few pixels from the block like the tooltip
function ns.PlaceHoverList(list, owner)
list:ClearAllPoints()
local h, below = TooltipSide(owner)
if not h then h, below = "LEFT", true end
if below then
list:SetPoint("TOP" .. h, owner, "BOTTOM" .. h, 0, -2)
else
list:SetPoint("BOTTOM" .. h, owner, "TOP" .. h, 0, 2)
end
end
---------------------------------------------------------------------------
-- Default settings
---------------------------------------------------------------------------
-- Per-block settings (stored in profile.blocks[key])
local BLOCK_DEFAULTS = {
enabled = true,
keepLook = false, -- true once the block has been on screen: it keeps its own look when it comes back
showLabel = false, -- icon + value, like the stock bar
showIcon = true,
showValue = true, -- false: the icon alone (tooltip and clicks unchanged)
tooltip = true,
colorize = true,
hideInCombat = false,
hideInInstance = false,
hideEmpty = true, -- friends, guild: hidden when there is nothing to show
timeSource = "auto", -- time: auto (the one WoW does not display), local, server
shiftClick = "chat", -- Shift + click: none, chat, options, hide
middleClick = "none", -- middle click: none, open, chat, options, hide (+ module action)
clock24 = true, -- time blocks: 24-hour clock
goldFormat = "full", -- gold: full, gold, short