Repository navigation
Expand file tree
/
Copy pathOptions.lua
More file actions
2720 lines (2482 loc) · 120 KB
/
Copy pathOptions.lua
File metadata and controls
2720 lines (2482 loc) · 120 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
local L = _G.QuestTogether.Translate
--[[
QuestTogether Options Panel (Esc > Options > AddOns)
]]
local QuestTogether = _G.QuestTogether
QuestTogether.announcementControls = QuestTogether.announcementControls or {}
QuestTogether.whereToAnnounceControls = QuestTogether.whereToAnnounceControls or {}
QuestTogether.questPlateControls = QuestTogether.questPlateControls or {}
QuestTogether.groupsControls = QuestTogether.groupsControls or {}
QuestTogether.homeControls = QuestTogether.homeControls or {}
QuestTogether.profileControls = QuestTogether.profileControls or {}
QuestTogether.profileUIState = QuestTogether.profileUIState or {}
local function SafeText(value, fallback)
return QuestTogether:SafeToString(value, fallback or "")
end
local function IsFrameMutable(frame)
if QuestTogether and QuestTogether.CanAccessForeignFrame then
return QuestTogether:CanAccessForeignFrame(frame)
end
if not frame then
return false
end
if frame.IsForbidden and frame:IsForbidden() then
return false
end
return true
end
local QUEST_PLATE_PREVIEW_SCALE = 1.35
local QUEST_PLATE_PREVIEW_FRAME_HEIGHT = 195
local QUEST_PLATE_PREVIEW_RANDOM_NAMES = {
"Koda Bug",
"Rue Angel",
"Pi Floof",
"Sammy Bear",
"Cinder Kitten",
"Lilly Pig",
"Booker Bean",
"Piper Hippo",
"Wifebeast",
"Husblebee",
}
local NAMEPLATE_STYLE_MODERN = Enum and Enum.NamePlateStyle and Enum.NamePlateStyle.Modern or 0
local NAMEPLATE_STYLE_BLOCK = Enum and Enum.NamePlateStyle and Enum.NamePlateStyle.Block or 2
local NAMEPLATE_STYLE_HEALTH_FOCUS = Enum and Enum.NamePlateStyle and Enum.NamePlateStyle.HealthFocus or 3
local NAMEPLATE_STYLE_LEGACY = Enum and Enum.NamePlateStyle and Enum.NamePlateStyle.Legacy or 5
local NAMEPLATE_STYLE_CLASSIC = Enum and Enum.NamePlateStyle and Enum.NamePlateStyle.Classic or 6
local NAMEPLATE_SIZE_MEDIUM = Enum and Enum.NamePlateSize and Enum.NamePlateSize.Medium or 2
local NAMEPLATE_INFO_PERCENT = Enum and Enum.NamePlateInfoDisplay and Enum.NamePlateInfoDisplay.CurrentHealthPercent or 1
local NAMEPLATE_INFO_VALUE = Enum and Enum.NamePlateInfoDisplay and Enum.NamePlateInfoDisplay.CurrentHealthValue or 2
local NAMEPLATE_PREVIEW_SCALES = {
[1] = { horizontal = 0.75, vertical = 0.8 },
[2] = { horizontal = 1.0, vertical = 1.0 },
[3] = { horizontal = 1.25, vertical = 1.25 },
[4] = { horizontal = 1.4, vertical = 1.4 },
[5] = { horizontal = 1.6, vertical = 1.6 },
}
local function HasBit(mask, bitValue)
if type(mask) ~= "number" or type(bitValue) ~= "number" or bitValue <= 0 then
return false
end
if bit and bit.band then
return bit.band(mask, bitValue) ~= 0
end
if bit32 and bit32.band then
return bit32.band(mask, bitValue) ~= 0
end
local remainder = mask % (bitValue * 2)
return remainder >= bitValue
end
local function GetNumericCVarValue(cvarName, fallbackValue)
if not (QuestTogether and QuestTogether.API and type(QuestTogether.API.GetCVar) == "function") then
return fallbackValue
end
local rawValue = QuestTogether.API.GetCVar(cvarName)
local numericValue = QuestTogether:SafeToNumber(rawValue)
if numericValue == nil then
return fallbackValue
end
return numericValue
end
local function AnchorPreviewFillTexture(texture, healthBar)
if not (texture and healthBar and texture.ClearAllPoints and texture.SetPoint) then
return
end
local fillTexture = healthBar.GetStatusBarTexture and healthBar:GetStatusBarTexture() or nil
if not fillTexture then
return
end
texture:ClearAllPoints()
texture:SetPoint("TOPLEFT", fillTexture, "TOPLEFT", 0, 0)
texture:SetPoint("BOTTOMLEFT", fillTexture, "BOTTOMLEFT", 0, 0)
texture:SetPoint("TOPRIGHT", fillTexture, "TOPRIGHT", 0, 0)
texture:SetPoint("BOTTOMRIGHT", fillTexture, "BOTTOMRIGHT", 0, 0)
end
local function GetRandomQuestPlatePreviewName()
local totalNames = #QUEST_PLATE_PREVIEW_RANDOM_NAMES
if totalNames <= 0 then
return L("Quest Mob")
end
if not (math and type(math.random) == "function") then
return QUEST_PLATE_PREVIEW_RANDOM_NAMES[1]
end
local randomIndex = math.random(totalNames)
if type(randomIndex) ~= "number" or randomIndex < 1 or randomIndex > totalNames then
randomIndex = 1
end
return QUEST_PLATE_PREVIEW_RANDOM_NAMES[randomIndex]
end
local function ApplyAnnouncementGroupIcon(texture, iconType)
if not texture then
return
end
if iconType == "world" and texture.SetAtlas then
texture:SetAtlas("worldquest-icon", true)
texture:SetTexCoord(0, 1, 0, 1)
return
end
if iconType == "bonus" and texture.SetAtlas then
texture:SetAtlas("Bonus-Objective-Star", true)
texture:SetTexCoord(0, 1, 0, 1)
return
end
if iconType == "quest" then
texture:SetTexture("Interface\\GossipFrame\\AvailableQuestIcon")
texture:SetTexCoord(0, 1, 0, 1)
return
end
if QuestTogether.NAMEPLATE_QUEST_ICON_ATLAS and texture.SetAtlas then
texture:SetAtlas(QuestTogether.NAMEPLATE_QUEST_ICON_ATLAS, true)
texture:SetTexCoord(0, 1, 0, 1)
return
end
texture:SetTexture(QuestTogether.NAMEPLATE_QUEST_ICON_TEXTURE)
if QuestTogether.NAMEPLATE_QUEST_ICON_TEX_COORDS then
local coords = QuestTogether.NAMEPLATE_QUEST_ICON_TEX_COORDS
texture:SetTexCoord(coords.left, coords.right, coords.top, coords.bottom)
else
texture:SetTexCoord(0, 1, 0, 1)
end
end
local function CreateAnnouncementGroupHeader(parent, text, iconType, x, y, width)
local icon = parent:CreateTexture(nil, "ARTWORK")
icon:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
icon:SetSize(16, 16)
ApplyAnnouncementGroupIcon(icon, iconType)
local label = parent:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
label:SetPoint("LEFT", icon, "RIGHT", 8, 0)
label:SetText(text)
local divider = parent:CreateTexture(nil, "BORDER")
divider:SetPoint("TOPLEFT", icon, "BOTTOMLEFT", 0, -8)
divider:SetSize(width or 620, 1)
divider:SetColorTexture(1, 1, 1, 0.12)
return label
end
function QuestTogether:GetSettingsTooltipParent()
return UIParent
end
function QuestTogether:CreateSettingsTooltipFrame(parent)
return CreateFrame("Frame", nil, parent, "BackdropTemplate")
end
function QuestTogether:GetSettingsTooltipCursorPosition(parent, owner)
if self:IsNativeGamepadMode()
and (not self.API.IsMouseOverPartyQuestWindow or not self.API.IsMouseOverPartyQuestWindow(owner)) then return end
return self:GetChatLogTooltipCursorPosition(parent)
end
function QuestTogether:HideSettingsTooltip(owner)
if owner and rawget(self, "settingsTooltipOwner") ~= owner then return end
self.settingsTooltipOwner, self.settingsTooltipSession = nil, nil
local tooltip = rawget(self, "settingsTooltip")
self:QueueOwnedUICleanup(tooltip, function(frame)
frame:SetScript("OnUpdate", nil)
frame:Hide()
end)
end
function QuestTogether:ShowSettingsTooltip(owner, title, text)
if self:IsRuntimeRestricted() or not self.LibChev.CanMutateOwnedRegion(owner) or not owner:IsVisible() then
self:HideSettingsTooltip()
return false
end
local parent = self:GetSettingsTooltipParent()
if not self:CanAccessForeignFrame(parent) then return false end
local tooltip = rawget(self, "settingsTooltip")
if not tooltip then
tooltip = self:CreateSettingsTooltipFrame(parent)
if not self.LibChev.CanMutateOwnedRegion(tooltip) then return false end
self.settingsTooltip = tooltip
tooltip:Hide()
tooltip:SetFrameStrata("TOOLTIP")
tooltip:SetFrameLevel(100)
tooltip:SetClampedToScreen(true)
tooltip:SetBackdrop({ bgFile = "Interface\\Buttons\\WHITE8X8", edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border", edgeSize = 12 })
tooltip:SetBackdropColor(0.04, 0.05, 0.07, 0.97)
tooltip.title = tooltip:CreateFontString(nil, "OVERLAY", "GameFontNormal")
tooltip.title:SetPoint("TOPLEFT", 12, -12)
tooltip.title:SetWidth(296)
tooltip.title:SetJustifyH("LEFT")
tooltip.title:SetWordWrap(true)
tooltip.text = tooltip:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
tooltip.text:SetPoint("TOPLEFT", tooltip.title, "BOTTOMLEFT", 0, -8)
tooltip.text:SetWidth(296)
tooltip.text:SetJustifyH("LEFT")
tooltip.text:SetWordWrap(true)
end
if not self.LibChev.CanMutateOwnedRegion(tooltip)
or not self.LibChev.CanMutateOwnedRegion(tooltip.title)
or not self.LibChev.CanMutateOwnedRegion(tooltip.text) then return false end
tooltip.title:SetText(title)
tooltip.text:SetText(text)
tooltip:SetSize(320, tooltip.title:GetStringHeight() + tooltip.text:GetStringHeight() + 32)
local session = {}
self.settingsTooltipOwner, self.settingsTooltipSession = owner, session
self:CancelOwnedUICleanup(tooltip)
local relative, point, offsetX, offsetY
local function Position()
local x, y = self:GetSettingsTooltipCursorPosition(parent, owner)
x, y = self:SafeToNumber(x), self:SafeToNumber(y)
local anchor, anchorPoint, relativePoint = owner, "TOPLEFT", "BOTTOMLEFT"
if x and y then
anchor, anchorPoint, relativePoint = parent, "BOTTOMLEFT", "BOTTOMLEFT"
x, y = x + 12, y + 12
else
x, y = 8, -8
end
if relative == anchor and point == anchorPoint and offsetX == x and offsetY == y then return end
tooltip:ClearAllPoints()
tooltip:SetPoint(anchorPoint, anchor, relativePoint, x, y)
relative, point, offsetX, offsetY = anchor, anchorPoint, x, y
end
Position()
tooltip:SetScript("OnUpdate", function()
if rawget(self, "settingsTooltipSession") ~= session then return end
local current = rawget(self, "settingsTooltipOwner")
if self:IsRuntimeRestricted()
or not self.LibChev.CanMutateOwnedRegion(tooltip) or not self:CanAccessForeignFrame(parent)
or not self.LibChev.CanMutateOwnedRegion(current) or not current:IsVisible() then
self:HideSettingsTooltip()
return
end
Position()
end)
tooltip:Show()
return true
end
-- Only attach to controls created by this addon. No shared GameTooltip state.
function QuestTogether:AttachSettingsTooltip(control, title, text)
assert(type(text) == "string" and text ~= "" and text ~= title, "settings controls require explanatory tooltip text")
control:EnableMouse(true)
if control.SetMotionScriptsWhileDisabled then control:SetMotionScriptsWhileDisabled(true) end
control:HookScript("OnEnter", function() self:ShowSettingsTooltip(control, title, text) end)
control:HookScript("OnLeave", function() self:HideSettingsTooltip(control) end)
control:HookScript("OnHide", function() self:HideSettingsTooltip(control) end)
end
local function CreateCheckbox(parent, optionKey, labelText, tooltipText, x, y)
local checkbox = CreateFrame("CheckButton", nil, parent, "MinimalCheckboxTemplate")
checkbox:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
local label = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("LEFT", checkbox, "RIGHT", 6, 0)
label:SetWidth(math.max(360, 600 - x))
label:SetJustifyH("LEFT")
label:SetWordWrap(true)
label:SetMaxLines(2)
label:SetText(labelText)
checkbox.Label = label
checkbox.qtOptionKey = optionKey
checkbox:SetChecked(QuestTogether:GetOption(optionKey) == true)
checkbox:HookScript("OnShow", function(self)
self:SetChecked(QuestTogether:GetOption(optionKey) == true)
end)
checkbox:SetHitRectInsets(0, -(math.max(360, 600 - x) + 6), 0, 0)
QuestTogether:AttachSettingsTooltip(checkbox, labelText, tooltipText)
checkbox:SetScript("OnClick", function(self)
QuestTogether:SetOption(optionKey, self:GetChecked() == true)
QuestTogether:RefreshOptionsWindow()
end)
return checkbox
end
local function ClampColorComponent(value, fallback)
local numberValue = QuestTogether:SafeToNumber(value)
if not numberValue then
return fallback
end
if numberValue < 0 then
return 0
end
if numberValue > 1 then
return 1
end
return numberValue
end
local function ColorsNearlyEqual(left, right)
return math.abs((left or 0) - (right or 0)) < 0.001
end
local function GetColorOption(optionKey, fallbackColor)
local configuredColor = QuestTogether:GetOption(optionKey)
if type(configuredColor) ~= "table" then
return {
r = fallbackColor.r,
g = fallbackColor.g,
b = fallbackColor.b,
}
end
return {
r = ClampColorComponent(configuredColor.r, fallbackColor.r),
g = ClampColorComponent(configuredColor.g, fallbackColor.g),
b = ClampColorComponent(configuredColor.b, fallbackColor.b),
}
end
local function IsColorOptionAtDefault(optionKey, fallbackColor)
local current = GetColorOption(optionKey, fallbackColor)
return ColorsNearlyEqual(current.r, fallbackColor.r)
and ColorsNearlyEqual(current.g, fallbackColor.g)
and ColorsNearlyEqual(current.b, fallbackColor.b)
end
function QuestTogether:CreateProfileOptionEditCallback(optionKey)
local profile = self.db and self.db.profile
local editToken = {}
self.profileOptionEditToken = editToken
return function(value)
-- A picker can outlive a profile switch, copy/reset, or another picker.
-- Table identity also catches replacement of a profile with the same name.
if type(profile) ~= "table" or not self.db or self.db.profile ~= profile
or self.profileOptionEditToken ~= editToken then
return false
end
return self:SetOption(optionKey, value)
end
end
local function CreateColorSwatch(parent, optionKey, labelText, tooltipText, fallbackColor, x, y)
local swatchButton = CreateFrame("Button", nil, parent, "ColorSwatchTemplate")
swatchButton:SetSize(22, 22)
swatchButton:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
local label = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
label:SetPoint("LEFT", swatchButton, "RIGHT", 8, 0)
label:SetText(labelText)
swatchButton:SetHitRectInsets(0, -120, 0, 0)
QuestTogether:AttachSettingsTooltip(swatchButton, labelText, tooltipText)
swatchButton:SetScript("OnClick", function()
if not (ColorPickerFrame and ColorPickerFrame.SetupColorPickerAndShow) then
QuestTogether:Print(L("Color picker is unavailable right now."))
return
end
local applyOption = QuestTogether:CreateProfileOptionEditCallback(optionKey)
local function SetColorOption(r, g, b)
if applyOption({
r = ClampColorComponent(r, fallbackColor.r),
g = ClampColorComponent(g, fallbackColor.g),
b = ClampColorComponent(b, fallbackColor.b),
}) then
QuestTogether:RefreshOptionsWindow()
end
end
local currentColor = GetColorOption(optionKey, fallbackColor)
local previousColor = {
r = currentColor.r,
g = currentColor.g,
b = currentColor.b,
}
local info = {}
info.r = currentColor.r
info.g = currentColor.g
info.b = currentColor.b
info.hasOpacity = false
info.swatchFunc = function()
local r, g, b = ColorPickerFrame:GetColorRGB()
SetColorOption(r, g, b)
end
info.cancelFunc = function()
SetColorOption(previousColor.r, previousColor.g, previousColor.b)
end
ColorPickerFrame:SetupColorPickerAndShow(info)
end)
local startingColor = GetColorOption(optionKey, fallbackColor)
swatchButton:SetColorRGB(startingColor.r, startingColor.g, startingColor.b)
return swatchButton
end
local function BuildDropdownEntries(dropdown)
dropdown.entries = {}
dropdown.initializeMenu(dropdown)
return dropdown.entries
end
local function CreateDropdown(parent, titleText, tooltipText, x, y, width, initializeMenu)
local title = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
title:SetText(titleText)
local control = CreateFrame("Frame", nil, parent, "SettingsDropdownWithButtonsTemplate")
control:SetSize((width or 180) + 62, 25)
control:SetPoint("TOPLEFT", title, "BOTTOMLEFT", 0, -8)
control.initializeMenu = initializeMenu
control.title = title
control.Label:Hide()
local dropdown = control.Dropdown
dropdown:SetWidth(width or 180)
dropdown:SetMenuAnchor(AnchorUtil.CreateAnchor("TOPRIGHT", dropdown, "BOTTOMRIGHT", 0, -2))
for _, region in ipairs({ dropdown, control.DecrementButton, control.IncrementButton }) do
QuestTogether:AttachSettingsTooltip(region, titleText, tooltipText)
end
local function Populate(_, root)
root:SetMinimumWidth(dropdown:GetWidth())
for _, entry in ipairs(BuildDropdownEntries(control)) do
root:CreateHighlightRadio(entry.text, entry.checked, entry.func)
end
end
control.gamepadGenerator = Populate
local choice = QuestTogether:ConfigureGamepadDropdown(dropdown, Populate, nil, "settings")
if choice then QuestTogether:AttachSettingsTooltip(choice, titleText, tooltipText) end
QuestTogether:ConfigureGamepadDropdownSteppers(control, function() return BuildDropdownEntries(control) end)
return control
end
local function CreateSettingsSlider(parent, titleText, tooltipText, x, y, minimum, maximum, step, plainNumber, formatter)
local control = CreateFrame("Frame", nil, parent, "MinimalSliderWithSteppersTemplate")
control:SetSize(360, 20)
control:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y)
local title = control:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("BOTTOMLEFT", control, "TOPLEFT", 0, 8)
title:SetText(titleText)
control.title = title
control:Init(minimum, minimum, maximum, (maximum - minimum) / step, {
[MinimalSliderWithSteppersMixin.Label.Right] = formatter or function(value)
return string.format(plainNumber and "%d" or "%d%%", math.floor(value + 0.5))
end,
})
if control.Slider.SetNarrationLabelRegion then control.Slider:SetNarrationLabelRegion(title) end
for _, region in ipairs({ control.Slider, control.Back, control.Forward }) do
QuestTogether:AttachSettingsTooltip(region, titleText, tooltipText)
end
return control
end
-- The native control owns formatting, arrows and interaction scripts. Profile
-- refreshes use its value API without persisting the resulting callback.
local function ConfigureSettingsSlider(control, getValue, onValueChanged)
control.RefreshValue = function(self)
self.qtRefreshing = true
self:SetValue(getValue())
self.qtRefreshing = nil
end
control:RegisterCallback("OnValueChanged", function(self, value)
if not self.qtRefreshing then onValueChanged(value) end
end, control)
control:RefreshValue()
end
function QuestTogether:CreateQuestFocusSlider(parent, title, x, y, minimum, maximum, step, getValue, setValue, percent, tooltip)
local slider = CreateSettingsSlider(parent, title, tooltip, x, y, minimum, maximum, step, not percent)
ConfigureSettingsSlider(slider, getValue, setValue)
return slider
end
local scrollPanelSequence = 0
local function CreateScrollablePanelContent(parent, minimumHeight)
local scrollFrame = CreateFrame("ScrollFrame", nil, parent)
scrollFrame:SetPoint("TOPLEFT", parent, "TOPLEFT", 0, 0)
scrollFrame:SetPoint("BOTTOMRIGHT", parent, "BOTTOMRIGHT", -28, 0)
local content = CreateFrame("Frame", nil, scrollFrame)
content:SetSize(672, minimumHeight or 600)
scrollFrame:SetScrollChild(content)
scrollPanelSequence = scrollPanelSequence + 1
local workKey = "settings_scrollbar_" .. scrollPanelSequence
local scrollbar, refreshing
local function RefreshScroll(value)
if refreshing then return end
if not QuestTogether:CanMutateOwnedUI(scrollFrame) or not QuestTogether:CanMutateOwnedUI(content) then
QuestTogether:ScheduleRuntimeWork("foreign_frame_mutation", workKey, function() RefreshScroll() end,
{ lifetime = "ui", reason = "settings scrollbar refresh" })
return
end
refreshing = true
content:SetWidth(math.max(672, scrollFrame:GetWidth() - 8))
if not scrollbar then
scrollbar = QuestTogether:CreateOwnedScrollBar(QuestTogether.CreateOwnedWindowFrame, parent, false,
function(offset) RefreshScroll(offset) end)
scrollbar:SetPoint("TOPLEFT", scrollFrame, "TOPRIGHT", 10, -4)
scrollbar:SetPoint("BOTTOMLEFT", scrollFrame, "BOTTOMRIGHT", 10, 4)
scrollFrame.ScrollBar = scrollbar
end
local maximum = math.max(0, scrollFrame:GetVerticalScrollRange())
local offset = math.max(0, math.min(maximum, value or scrollFrame:GetVerticalScroll()))
scrollFrame:SetVerticalScroll(offset)
QuestTogether:UpdateOwnedScrollBar(scrollbar, offset, maximum, scrollFrame:GetHeight(), 30)
refreshing = nil
end
scrollFrame:SetScript("OnSizeChanged", function() RefreshScroll() end)
scrollFrame:SetScript("OnScrollRangeChanged", function() RefreshScroll() end)
scrollFrame:SetScript("OnVerticalScroll", function() RefreshScroll() end)
scrollFrame:SetScript("OnShow", function() RefreshScroll() end)
scrollFrame:EnableMouseWheel(true)
scrollFrame:SetScript("OnMouseWheel", function(_, delta)
if QuestTogether:CanMutateOwnedUI(scrollFrame) then RefreshScroll(scrollFrame:GetVerticalScroll() - delta * 30) end
end)
RefreshScroll()
return scrollFrame, content
end
function QuestTogether:ApplyOptionsDropdownSelection(optionKey, value)
-- This choice opens/closes native chat windows. A stale Settings dropdown
-- must recheck restrictions just like the minimap and chat context menus.
if optionKey == "chatLogDestination" and self:IsRuntimeRestricted() then return false end
if not self:SetOption(optionKey, value) then return false end
self:RefreshOptionsWindow()
return true
end
local function CreateOptionDropdown(parent, titleText, tooltipText, x, y, width, values, getLabel, optionKey, currentValueGetter)
return CreateDropdown(
parent,
titleText,
tooltipText,
x,
y,
width,
function(dropdown)
for _, value in ipairs(values) do
local info = {}
info.text = getLabel(value)
info.func = function()
QuestTogether:ApplyOptionsDropdownSelection(optionKey, value)
end
info.checked = function() return currentValueGetter() == value end
dropdown.entries[#dropdown.entries + 1] = info
end
end
)
end
local function CreateShowProgressForDropdown(parent, x, y)
return CreateOptionDropdown(
parent,
L("Show Announcements For"),
L("Party Only shows announcements from your group. Party and Nearby also includes players within your Nearby Range or visible nearby. Looking-for-partners announcements reach the whole zone."),
x,
y,
200,
QuestTogether.showProgressForOrder,
function(value)
return QuestTogether:GetShowProgressForLabel(value)
end,
"showProgressFor",
function()
return QuestTogether:GetOption("showProgressFor")
end
)
end
local function OwnChatBubbleModeLabel(mode)
if mode == "solo" then return L("Show only when solo") end
if mode == "party" then return L("Show only when in a party") end
if mode == "hidden" then return L("Hide always") end
return L("Show always")
end
local function CreateQTChatScopeDropdown(parent, x, y)
return CreateOptionDropdown(parent, L("QT Chat Scope"),
L("Global shows all received QT chat. Zone Only shows players whose recent shared location is in your zone; unknown or stale locations are hidden."),
x, y, 140, { "zone_only", "global" },
function(value) return value == "zone_only" and L("Zone Only") or L("Global") end,
"qtChatScope", function() return QuestTogether:GetOption("qtChatScope") end)
end
local function CreateChatLogDestinationDropdown(parent, x, y)
return CreateOptionDropdown(
parent,
L("Chat Log Destination"),
L("Choose whether QuestTogether chat logs print to your main chat frame or a dedicated QuestTogether chat frame."),
x,
y,
190,
QuestTogether.chatLogDestinationOrder,
function(value)
return QuestTogether:GetChatLogDestinationLabel(value)
end,
"chatLogDestination",
function()
return QuestTogether:GetOption("chatLogDestination")
end
)
end
local function CreateNameplateIconStyleDropdown(parent, x, y, playerPlates)
return CreateOptionDropdown(
parent,
playerPlates and L("Player Icon Style") or L("Quest Icon Style"),
L("Left, Right and Top position the icon around the health bar. Prefix puts it beside the name. On names-only player plates, all positions use the name instead; Left and Prefix match."),
x,
y,
140,
QuestTogether.nameplateQuestIconStyleOrder,
function(styleKey)
return QuestTogether:GetNameplateQuestIconStyleLabel(styleKey)
end,
playerPlates and "nameplatePlayerIconStyle" or "nameplateQuestIconStyle",
function()
return playerPlates and QuestTogether:GetNameplatePlayerIconStyle()
or QuestTogether:GetNameplateQuestIconStyle()
end
)
end
-- Every boolean control uses the same schema as SetOption. Adding a setting
-- must not require a second, manually maintained list just to display its value.
local function RefreshCheckboxOptions(controls, addon)
if type(controls) ~= "table" then return end
addon = addon or QuestTogether
for key, control in pairs(controls) do
if type(addon.DEFAULTS.profile[key]) == "boolean" and type(control) == "table"
and type(control.SetChecked) == "function" then
control:SetChecked(addon:GetOption(key) == true)
end
end
end
local function RefreshDropdownControl(dropdown, labelText)
if dropdown.gamepadGenerator then QuestTogether:ConfigureGamepadDropdown(dropdown.Dropdown, dropdown.gamepadGenerator) end
dropdown.Dropdown:SetDefaultText(labelText)
if not QuestTogether:IsNativeGamepadMode() then dropdown.Dropdown:GenerateMenu()
else dropdown:UpdateSteppers() end
end
local function SetLabeledControlShown(control, shown)
if not control then
return
end
if not shown and not QuestTogether:PrepareGamepadControlHide(control) then return end
if control.SetShown then
control:SetShown(shown)
end
if control.Label and control.Label.SetShown then
control.Label:SetShown(shown)
end
if control.title and control.title.SetShown then
control.title:SetShown(shown)
end
end
local function RefreshPlayerPlateNamesOnlyNotice(controls, namesOnly)
local notice = controls.namesOnlyNotice
if not notice then return end
if not QuestTogether:CanMutateOwnedUI(notice)
or (not namesOnly and notice:IsShown()
and not QuestTogether:PrepareGamepadControlHide(notice, controls.nameplatePlayerIconEnabled)) then
QuestTogether:ScheduleRuntimeWork("foreign_frame_mutation", "player_names_only_notice", function()
QuestTogether:RefreshQuestPlatesWindow(true)
end, { lifetime = "ui", reason = "player nameplate notice refresh" })
return
end
local extraHeight = 0
if namesOnly then
-- Measure wrapped localized text instead of reserving an English-only row.
notice:SetHeight(12 + notice.heading:GetStringHeight() + 6 + notice.body:GetStringHeight() + 12 + 24 + 12)
notice.settingsButton:SetWidth(math.min(596, math.max(220, notice.settingsButton:GetFontString():GetStringWidth() + 32)))
extraHeight = notice:GetHeight() + 16
end
notice:SetShown(namesOnly)
controls.playerTooltipHeader:ClearAllPoints()
controls.playerTooltipHeader:SetPoint("TOPLEFT", controls.content, "TOPLEFT", 16, -428 - extraHeight)
controls.playerTooltipIdentifierDropdown.title:ClearAllPoints()
controls.playerTooltipIdentifierDropdown.title:SetPoint("TOPLEFT", controls.content, "TOPLEFT", 16, -456 - extraHeight)
controls.content:SetHeight(560 + extraHeight)
end
local function RefreshQuestPlatesPreview(controls)
if type(controls) ~= "table" then
return
end
local previewFrame = controls.previewFrame
local previewUnitFrame = controls.previewUnitFrame
if not IsFrameMutable(previewUnitFrame) or not previewUnitFrame.healthBar then
return
end
if previewUnitFrame.SetScale then
previewUnitFrame:SetScale(QUEST_PLATE_PREVIEW_SCALE)
end
local nameplateStyle = GetNumericCVarValue("nameplateStyle", NAMEPLATE_STYLE_MODERN)
local nameplateSize = GetNumericCVarValue("nameplateSize", NAMEPLATE_SIZE_MEDIUM)
local infoDisplayMask = GetNumericCVarValue("nameplateInfoDisplay", 0)
local forever = QuestTogether:UsesRegionalPlayerNames()
local namesOnly = controls.playerPlates == true
and GetNumericCVarValue("nameplateShowOnlyNameForFriendlyPlayerUnits", 0) == 1
RefreshPlayerPlateNamesOnlyNotice(controls, namesOnly)
-- This frame and all its members are QT-owned. Reuse the live icon geometry
-- without registering a native preview unit or editing Blizzard setup tables.
previewUnitFrame.showOnlyName = namesOnly
local scaleData = NAMEPLATE_PREVIEW_SCALES[nameplateSize] or NAMEPLATE_PREVIEW_SCALES[NAMEPLATE_SIZE_MEDIUM]
local horizontalScale = scaleData.horizontal or 1
local verticalScale = scaleData.vertical or 1
local classic = nameplateStyle == NAMEPLATE_STYLE_CLASSIC
if classic and nameplateSize == 1 then horizontalScale = verticalScale end
local largeHealthBar = nameplateStyle == NAMEPLATE_STYLE_MODERN
or nameplateStyle == NAMEPLATE_STYLE_BLOCK
or nameplateStyle == NAMEPLATE_STYLE_HEALTH_FOCUS
local nameInsideHealthBar = nameplateStyle == NAMEPLATE_STYLE_MODERN or nameplateStyle == NAMEPLATE_STYLE_BLOCK
-- Retail's outer plate includes two 12-pixel scaled content insets.
-- Enlarge the entire sample uniformly, not just the health bar.
local barWidth = ((classic and 152 or 230) - 24) * horizontalScale
local barHeight = (largeHealthBar and 20 or 10) * verticalScale
local nameFontSize = (classic and 10 or 12) * verticalScale
if forever then
-- Camelot constants: 190-wide plate (152 in Classic), 12-pixel side
-- insets, 13/20-pixel health, 14-point names. Scale the whole preview
-- uniformly, rather than enlarging only the bar relative to its text.
barWidth = ((classic and 152 or 190) - 24) * horizontalScale
barHeight = (classic and 10 or largeHealthBar and 20 or 13) * verticalScale
-- The enlarged friendly-player sample uses a smaller label; real native
-- nameplate fonts are never modified by this preview.
nameFontSize = (classic and 10 or controls.playerPlates and 12 or 14) * verticalScale
end
local healthContainer = previewUnitFrame.HealthBarsContainer
if healthContainer and healthContainer.SetSize then
healthContainer:SetSize(barWidth, barHeight)
healthContainer:ClearAllPoints()
healthContainer:SetPoint("CENTER", previewUnitFrame, "CENTER", 0, nameInsideHealthBar and 0 or -6)
end
if previewUnitFrame.SetSize then
local frameWidth = barWidth + 140
local frameHeight = math.max(72, barHeight + (nameInsideHealthBar and 34 or 50))
previewUnitFrame:SetSize(frameWidth, frameHeight)
end
if previewFrame and previewUnitFrame.ClearAllPoints and previewUnitFrame.SetPoint then
previewUnitFrame:ClearAllPoints()
previewUnitFrame:SetPoint("CENTER", previewFrame, "CENTER", 0, 0)
end
local nameLabel = previewUnitFrame.name
local healthText = previewUnitFrame.questPreviewHealthText
local healthInsideBar = nameInsideHealthBar or forever or classic
local nameFont = (forever or nameInsideHealthBar) and "SystemFont_NamePlate_Outlined" or "SystemFont_NamePlate"
local classR, classG, classB
if not forever and controls.playerPlates then
classR, classG, classB = QuestTogether.API.GetPlayerNameplatePreviewClassColor()
end
if nameLabel then
if nameLabel.SetFontObject then
nameLabel:SetFontObject(nameFont)
end
local fontPath, _, fontFlags = nameLabel:GetFont()
if fontPath and nameLabel.SetFont then
nameLabel:SetFont(fontPath, nameFontSize, fontFlags)
end
nameLabel:ClearAllPoints()
if nameLabel.SetDrawLayer then
nameLabel:SetDrawLayer("OVERLAY", 7)
end
local centered = namesOnly or classic or (forever and not nameInsideHealthBar)
if nameLabel.SetJustifyH then nameLabel:SetJustifyH(centered and "CENTER" or "LEFT") end
if nameLabel.SetWidth then nameLabel:SetWidth(math.max(1, barWidth - 8)) end
if centered and healthContainer then
-- Center on the health bar, not on the combined bar and level badge.
if nameInsideHealthBar then
nameLabel:SetPoint("CENTER", healthContainer, "CENTER", 0, 0)
else
nameLabel:SetPoint("BOTTOM", healthContainer, "TOP", 0, namesOnly and 2 or (classic and 4 or 2) * verticalScale)
end
elseif nameInsideHealthBar and healthContainer then
nameLabel:SetPoint("LEFT", healthContainer, "LEFT", 4, 0)
elseif healthContainer then
nameLabel:SetPoint("BOTTOMLEFT", healthContainer, "TOPLEFT", 4, 2 * verticalScale)
else
nameLabel:SetPoint("TOP", previewUnitFrame, "TOP", 0, 0)
end
if classR and GetNumericCVarValue("nameplateUseClassColorForFriendlyPlayerUnitNames", 0) == 1 then
nameLabel:SetTextColor(classR, classG, classB, 1)
elseif nameplateStyle == NAMEPLATE_STYLE_LEGACY and nameLabel.SetTextColor then
if controls.playerPlates then
nameLabel:SetTextColor(0.22, 0.80, 0.22, 1)
else
nameLabel:SetTextColor(1, 0, 0, 1)
end
elseif nameLabel.SetTextColor then
nameLabel:SetTextColor(1, 1, 1, 1)
end
end
local healthBar = previewUnitFrame.healthBar
healthBar:SetShown(not namesOnly)
local baseFill = previewUnitFrame.questPreviewBaseFillTexture
local tintOverlay = previewUnitFrame.questPreviewTintTexture
local tintHighlight = previewUnitFrame.questPreviewTintHighlight
local background = previewUnitFrame.questPreviewHealthBackground
healthBar:ClearAllPoints()
if classic then
healthBar:SetPoint("TOPLEFT", healthContainer, "TOPLEFT", 3.5 * horizontalScale, 0.5 * verticalScale)
healthBar:SetPoint("BOTTOMRIGHT", healthContainer, "BOTTOMRIGHT", -20.75 * horizontalScale, 0.5 * verticalScale)
else
healthBar:SetAllPoints(healthContainer)
end
if background then
background:ClearAllPoints()
if classic then
background:SetTexture("Interface\\Tooltips\\Nameplate-Border")
background:SetTexCoord(0, 1, 0.5, 1)
if background.SetTextureSliceMargins then background:SetTextureSliceMargins(0, 0, 0, 0) end
background:SetDrawLayer("ARTWORK", 1)
background:SetPoint("CENTER", healthContainer, "CENTER", 0, 0)
background:SetSize(128 * horizontalScale, 16 * verticalScale)
else
background:SetAtlas("UI-HUD-CoolDownManager-Bar-BG", true)
background:SetTexCoord(0, 1, 0, 1)
background:SetDrawLayer("BACKGROUND")
background:SetPoint("TOPLEFT", healthBar, "TOPLEFT", -2, 3)
background:SetPoint("BOTTOMRIGHT", healthBar, "BOTTOMRIGHT", 6, -6)
end
end
if previewUnitFrame.questPreviewDeselectedOverlay then
previewUnitFrame.questPreviewDeselectedOverlay:SetShown(not classic)
end
if healthBar and healthBar.SetMinMaxValues and healthBar.SetValue then
healthBar:SetMinMaxValues(0, 100)
healthBar:SetValue(100)
end
if baseFill then
if classic then baseFill:SetTexture("Interface\\TargetingFrame\\UI-TargetingFrame-BarFill")
else baseFill:SetAtlas(QuestTogether.NAMEPLATE_HEALTH_FILL_ATLAS or "UI-HUD-CoolDownManager-Bar", true) end
AnchorPreviewFillTexture(baseFill, healthBar)
baseFill:Show()
end
if tintOverlay then
AnchorPreviewFillTexture(tintOverlay, healthBar)
end
if tintHighlight then
AnchorPreviewFillTexture(tintHighlight, healthBar)
end
local level = previewUnitFrame.PlayerLevelDiffFrame
local sampleLevel
if forever or classic then
sampleLevel = QuestTogether:SafeToNumber(QuestTogether.API.UnitLevel("player"))
if not sampleLevel or sampleLevel < 1 or sampleLevel > 1000 then sampleLevel = 20 end
sampleLevel = tostring(math.floor(sampleLevel))
end
if level then
level:SetShown(forever and not namesOnly)
if forever then
level.playerLevelDiffIcon:SetAtlas("ui-hud-nameplates-levelindicator", true)
level:ClearAllPoints()
level:SetWidth(28 * horizontalScale)
level:SetPoint("TOPLEFT", healthBar, "TOPRIGHT", 5, 3)
level:SetPoint("BOTTOMLEFT", healthBar, "BOTTOMRIGHT", 5, -2)
level.playerLevelDiffText:SetText(sampleLevel)
level.playerLevelDiffText:SetFontObject("SystemFont_NamePlateLevel")
local path, _, flags = level.playerLevelDiffText:GetFont()
if path then level.playerLevelDiffText:SetFont(path, 10 * verticalScale, flags) end
-- A same-level quest mob is fair difficulty; friendly levels are white.
level.playerLevelDiffText:SetTextColor(1, controls.playerPlates and 1 or 0.82, controls.playerPlates and 1 or 0, 1)
end
end
local classicLevel = previewUnitFrame.questPreviewClassicLevel
if classicLevel then
classicLevel:SetShown(classic and not namesOnly)
if classic then
classicLevel:ClearAllPoints()
classicLevel:SetPoint("CENTER", background, "RIGHT", -11 * horizontalScale, 0)
classicLevel:SetText(sampleLevel)
classicLevel:SetFontObject("SystemFont_NamePlateLevel")
local path, _, flags = classicLevel:GetFont()
if path then classicLevel:SetFont(path, 10 * verticalScale, flags) end
classicLevel:SetTextColor(1, controls.playerPlates and 1 or 0.82, controls.playerPlates and 1 or 0, 1)
end
end
local tintEnabled = not controls.playerPlates
and QuestTogether:GetOption("nameplateQuestHealthColorEnabled") == true
local enemyBarColor = { r = 0.82, g = 0.14, b = 0.14 }
local previewBarColor = controls.playerPlates and { r = 0.22, g = 0.80, b = 0.22 } or enemyBarColor
if classR and GetNumericCVarValue("nameplateShowFriendlyClassColor", 0) == 1 then
previewBarColor = { r = classR, g = classG, b = classB }
end
if tintEnabled then
previewBarColor = GetColorOption("nameplateQuestHealthColor", QuestTogether.NAMEPLATE_QUEST_HEALTH_COLOR)
end
if baseFill and baseFill.SetVertexColor then
baseFill:SetVertexColor(previewBarColor.r, previewBarColor.g, previewBarColor.b, 1)
end
-- For preview accuracy keep the fill opaque and avoid additive tints.
if tintOverlay and tintOverlay.Hide then
tintOverlay:Hide()
end
if tintHighlight and tintHighlight.Hide then
tintHighlight:Hide()
end
if healthText then
healthText:SetFontObject(healthInsideBar and "SystemFont_NamePlate_Outlined" or "SystemFont_NamePlate")
local path, _, flags = healthText:GetFont()
if path then healthText:SetFont(path, nameFontSize, flags) end
if healthText.SetDrawLayer then
healthText:SetDrawLayer("OVERLAY", 7)
end
if healthText.SetJustifyH then
healthText:SetJustifyH("RIGHT")
end
healthText:ClearAllPoints()
if healthInsideBar and healthContainer then
healthText:SetPoint("RIGHT", healthBar, "RIGHT", -4, not forever and classic and -0.5 or 0)
elseif healthContainer then
healthText:SetPoint("BOTTOMRIGHT", healthBar, "TOPRIGHT", -4, 2)
end
local showPercent = HasBit(infoDisplayMask, NAMEPLATE_INFO_PERCENT)
local showValue = HasBit(infoDisplayMask, NAMEPLATE_INFO_VALUE)
if not namesOnly and (showPercent or showValue) then
if showPercent and showValue then
healthText:SetText("241 K 100%")
elseif showValue then
healthText:SetText("241 K")
else
healthText:SetText("100%")
end
healthText:Show()
else
healthText:Hide()
end
if (nameInsideHealthBar or not healthInsideBar) and not namesOnly and nameLabel then
local reserved = healthText:IsShown() and ((QuestTogether:SafeToNumber(healthText:GetStringWidth()) or 0) + 2) or 0
nameLabel:SetWidth(math.max(1, barWidth - 8 - reserved))
end
end
local previewIconFrame = controls.previewIconFrame
local previewIcon = controls.previewIconTexture
if not previewIconFrame or controls.previewIconOwner ~= previewUnitFrame then
local iconParent = previewUnitFrame
previewIconFrame = CreateFrame("Frame", nil, iconParent)
previewIconFrame:SetFrameStrata("HIGH")
local parentFrameLevel = 0
if healthContainer and healthContainer.GetFrameLevel and QuestTogether.SafeToNumber then
parentFrameLevel = QuestTogether:SafeToNumber(healthContainer:GetFrameLevel()) or 0
elseif iconParent and iconParent.GetFrameLevel and QuestTogether.SafeToNumber then
parentFrameLevel = QuestTogether:SafeToNumber(iconParent:GetFrameLevel()) or 0
end
previewIconFrame:SetFrameLevel(parentFrameLevel + 30)
previewIcon = previewIconFrame:CreateTexture(nil, "OVERLAY")