-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRefactorUI.lua
More file actions
2130 lines (1921 loc) · 81.7 KB
/
Copy pathRefactorUI.lua
File metadata and controls
2130 lines (1921 loc) · 81.7 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
-- RefactorUI
-- The addon's control panel: one window that manages every Refactor
-- feature — loot toasts, the crowd-control alert and the interface
-- tweaks — plus the minimap button that opens it. (Gear comparison is
-- its own addon now, Refactor Gear, with its own window.)
--
-- All reads/writes go through the small tables the other files export
-- (RefactorQoL, RefactorToastShared, RefactorCCShared); no feature logic
-- lives here. Every change applies immediately (tweaks re-check their
-- flag at use time), so there is no Apply/OK step.
--
-- Look: the DiamondMetal atlas frame border over a flat dark
-- background, a header ribbon, red panel buttons, native checkbox and
-- input-box art, quest-log gold highlights — so the window reads as
-- part of the game, not a web panel dropped into it. Three columns:
-- sidebar (search + nav), the option list, and a detail pane that
-- explains whatever the mouse is over (option descriptions live there,
-- not under the rows). Native behavior kept: Escape closes, the header
-- drags.
local SOLID = "Interface\\ChatFrame\\ChatFrameBackground" -- tintable solid
-- Palette (r, g, b) — Blizzard's own warm colors. ACCENT is the stock
-- gold of NORMAL_FONT_COLOR; the addon's chat green stays in chat.
local ACCENT = { 1.00, 0.82, 0.00 }
local C_BORDER = { 0.45, 0.40, 0.28 } -- warm border for the quality chips
local C_DIM = { 0.62, 0.56, 0.44 } -- warm gray for descriptions
local C_PARCH = { 0.85, 0.80, 0.68 } -- parchment-white for idle nav labels
-- Three-column layout (like the retail-style options panels): sidebar
-- with search + nav, the option list in the middle, and a detail pane on
-- the right that explains whatever the mouse is over.
local W_WIDTH, W_HEIGHT = 920, 600
local SIDEBAR_W = 170
local DETAIL_W = 210
local HEADER_H = 42
local PAD = 16
local INSET = 11 -- thickness the DiamondMetal border art eats
local BORDER_SIZE = 32 -- display size of the -8x DiamondMetal border pieces
-- Center column right edge: detail pane + its divider gutter.
local CENTER_RIGHT = INSET + DETAIL_W + 18
local CONTENT_W = W_WIDTH - (INSET + SIDEBAR_W + PAD) - CENTER_RIGHT -- 484
-- modules/core.lua creates and owns the saved variable; before it exists
-- (very early login) every caller here treats nil as "still loading".
local function DB()
return type(RefactorCompareDB) == "table" and RefactorCompareDB or nil
end
local function TDB()
return RefactorToastShared and RefactorToastShared.GetDB() or nil
end
local function Print(msg)
DEFAULT_CHAT_FRAME:AddMessage("|cff33ff99Refactor|r: " .. msg)
end
--------------------------------------------------------------------------
-- Widget helpers
--------------------------------------------------------------------------
local function SetFlat(frame, bg, border, bgAlpha)
frame:SetBackdrop({ bgFile = SOLID, edgeFile = SOLID, edgeSize = 1 })
frame:SetBackdropColor(bg[1], bg[2], bg[3], bgAlpha or 1)
if border then
frame:SetBackdropBorderColor(border[1], border[2], border[3], 1)
else
frame:SetBackdropBorderColor(0, 0, 0, 0)
end
end
-- Explanations render in the right-hand detail pane, not GameTooltip:
-- hovering a control puts its title + body there and leaves them until
-- the next hover or a page switch (sticky, so text doesn't flicker away
-- while the mouse travels). SetDetail is bound in BuildWindow.
local SetDetail
-- Modal confirm/prompt popup (built near BuildWindow, below); forward
-- declared so the earlier page builders can call it from button handlers.
local ShowPopup
-- HookScript (not SetScript) so widgets keep their own hover styling.
local function Explain(widget, title, body)
widget:HookScript("OnEnter", function()
if SetDetail then SetDetail(title, body) end
end)
end
-- Everything a MakeCheck row shows also lands here, feeding the sidebar
-- search: label + body matched case-insensitively, page key to jump to.
local searchRegistry = {}
local function RegisterOption(label, body, pageKey)
tinsert(searchRegistry, {
label = label, body = body, page = pageKey,
needle = (label .. " " .. (body or "")):lower(),
})
end
-- Section header: stock-gold label (GameFontNormal's own color) over a
-- gold hairline that fades out to the right, with a small gold stud at
-- its left end (the diamond-finial divider look; true 45° rotation isn't
-- possible on 3.3.5 textures, a 4px stud reads the same at this size).
-- Returns the y where content below should start.
local function Section(parent, text, x, y, width)
local h = parent:CreateFontString(nil, "OVERLAY", "GameFontNormal")
h:SetPoint("TOPLEFT", x, y)
h:SetText(text)
local line = parent:CreateTexture(nil, "ARTWORK")
line:SetTexture(SOLID)
line:SetGradientAlpha("HORIZONTAL",
ACCENT[1], ACCENT[2], ACCENT[3], 0.35,
ACCENT[1], ACCENT[2], ACCENT[3], 0)
line:SetHeight(1)
line:SetPoint("TOPLEFT", x, y - 16)
line:SetPoint("TOPRIGHT", parent, "TOPLEFT", x + width, y - 16)
local stud = parent:CreateTexture(nil, "ARTWORK")
stud:SetTexture(ACCENT[1], ACCENT[2], ACCENT[3], 0.8)
stud:SetWidth(4)
stud:SetHeight(4)
stud:SetPoint("CENTER", line, "LEFT", 2, 0)
return y - 26
end
local function SmallText(parent, text, x, y, width)
local fs = parent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
fs:SetPoint("TOPLEFT", x, y)
if width then fs:SetWidth(width) end
fs:SetJustifyH("LEFT")
fs:SetTextColor(C_DIM[1], C_DIM[2], C_DIM[3])
fs:SetText(text)
return fs
end
-- Checkbox row: stock checkbox art (UICheckButtonTemplate's anatomy,
-- drawn by hand so the whole row stays the click target) plus a
-- single-line label — the description shows in the detail pane on hover
-- instead of under the label, keeping rows one line tall like the stock
-- options list. Rows highlight full-width on hover and feed the search.
-- isEnabled (optional): predicate for a sub-option gated by another flag.
-- While false the row dims and ignores clicks, but its saved value is left
-- untouched so it comes back as-was when the parent is re-enabled.
local function MakeCheck(parent, x, y, width, label, desc, get, set, tip, isEnabled)
local row = CreateFrame("Button", nil, parent)
row:SetPoint("TOPLEFT", x, y)
row:SetWidth(width)
row:SetHeight(20)
local hl = row:CreateTexture(nil, "HIGHLIGHT")
hl:SetTexture("Interface\\QuestFrame\\UI-QuestTitleHighlight")
hl:SetBlendMode("ADD")
hl:SetAlpha(0.35)
hl:SetAllPoints()
-- The 24px art carries ~4px of transparent padding, hence the bleed.
local box = row:CreateTexture(nil, "ARTWORK")
box:SetTexture("Interface\\Buttons\\UI-CheckBox-Up")
box:SetWidth(24)
box:SetHeight(24)
box:SetPoint("LEFT", -3, 0)
local mark = row:CreateTexture(nil, "OVERLAY")
mark:SetTexture("Interface\\Buttons\\UI-CheckBox-Check")
mark:SetAllPoints(box)
local text = row:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
text:SetPoint("LEFT", box, "RIGHT", 2, 0)
text:SetJustifyH("LEFT")
text:SetText(label)
local info = desc
if desc and tip then
info = desc .. "\n\n" .. tip
elseif tip then
info = tip
end
Explain(row, label, info)
RegisterOption(label, info, parent.pageKey)
row.enabled = true
row.Refresh = function(self)
if get() then mark:Show() else mark:Hide() end
self.enabled = not isEnabled or (isEnabled() and true or false)
self:SetAlpha(self.enabled and 1 or 0.4)
end
row:SetScript("OnClick", function(self)
if not self.enabled then return end
set(not get())
self:Refresh()
end)
return row
end
-- Resolves an atlas name onto a texture. SetAtlas is preferred;
-- GetAtlasInfo + manual texcoords is the fallback if it is missing.
local function ApplyAtlas(tex, atlas)
if tex.SetAtlas then
tex:SetAtlas(atlas)
return
end
local info = GetAtlasInfo and GetAtlasInfo(atlas)
if not info then return end
tex:SetTexture(info.file)
tex:SetTexCoord(info.leftTexCoord, info.rightTexCoord,
info.topTexCoord, info.bottomTexCoord)
end
-- Keeps only the rightmost `keep` fraction of a texture's current
-- texcoord span (squares off the over-wide redbutton right cap).
local function CropRightTexCoord(tex, keep)
local ulx, uly, _, lly, urx, ury, _, lry = tex:GetTexCoord()
local nl = urx - (urx - ulx) * keep
tex:SetTexCoord(nl, uly, nl, lly, urx, ury, urx, lry)
end
-- Crops a texture's current texcoord rect (already set by ApplyAtlas) down
-- to the pixel range [x1,x2]x[y1,y2] of a srcW x srcH source region — the
-- manual nine-slice this client's plain textures can't apply on their own
-- (the CommonDropdown2x atlas ships slice= data for it, but that's a
-- retail 9-slice hint this client's SetAtlas doesn't act on).
local function CropTexCoordRect(tex, srcW, srcH, x1, y1, x2, y2)
local ulx, uly, _, lly, urx, ury, _, lry = tex:GetTexCoord()
local spanX, spanY = urx - ulx, lly - uly
local nx1, nx2 = ulx + spanX * (x1 / srcW), ulx + spanX * (x2 / srcW)
local ny1, ny2 = uly + spanY * (y1 / srcH), uly + spanY * (y2 / srcH)
tex:SetTexCoord(nx1, ny1, nx1, ny2, nx2, ny1, nx2, ny2)
end
-- Horizontal three-slice strip (fixed end caps, stretched middle) cut from
-- one atlas image via CropTexCoordRect, stretched to fill `region`. Used
-- for both the dropdown pill (whole button) and the list-row hover strip
-- (common-dropdown-textholder). Returns a Show/Hide pair driving all three
-- pieces as one unit.
local function BuildStripH(region, atlas, srcW, srcH, capL, capR, layer)
local left = region:CreateTexture(nil, layer or "ARTWORK")
ApplyAtlas(left, atlas)
CropTexCoordRect(left, srcW, srcH, 0, 0, capL, srcH)
left:SetWidth(capL)
left:SetPoint("TOPLEFT", 0, 0)
left:SetPoint("BOTTOMLEFT", 0, 0)
local center = region:CreateTexture(nil, layer or "ARTWORK")
ApplyAtlas(center, atlas)
CropTexCoordRect(center, srcW, srcH, capL, 0, srcW - capR, srcH)
center:SetPoint("TOPLEFT", capL, 0)
center:SetPoint("BOTTOMRIGHT", -capR, 0)
local right = region:CreateTexture(nil, layer or "ARTWORK")
ApplyAtlas(right, atlas)
CropTexCoordRect(right, srcW, srcH, srcW - capR, 0, srcW, srcH)
right:SetWidth(capR)
right:SetPoint("TOPRIGHT", 0, 0)
right:SetPoint("BOTTOMRIGHT", 0, 0)
local pieces = { left, center, right }
return {
Show = function() for _, t in ipairs(pieces) do t:Show() end end,
Hide = function() for _, t in ipairs(pieces) do t:Hide() end end,
}
end
-- Nine-slice panel (fixed corners, stretched edges, stretched center fill)
-- cut from one atlas image — the CommonDropdown2x list background.
local function BuildNineSlicePanel(region, atlas, srcW, srcH, capL, capT, capR, capB)
local function piece(x1, y1, x2, y2)
local t = region:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(t, atlas)
CropTexCoordRect(t, srcW, srcH, x1, y1, x2, y2)
return t
end
local tl = piece(0, 0, capL, capT)
tl:SetSize(capL, capT)
tl:SetPoint("TOPLEFT", 0, 0)
local tr = piece(srcW - capR, 0, srcW, capT)
tr:SetSize(capR, capT)
tr:SetPoint("TOPRIGHT", 0, 0)
local bl = piece(0, srcH - capB, capL, srcH)
bl:SetSize(capL, capB)
bl:SetPoint("BOTTOMLEFT", 0, 0)
local br = piece(srcW - capR, srcH - capB, srcW, srcH)
br:SetSize(capR, capB)
br:SetPoint("BOTTOMRIGHT", 0, 0)
local top = piece(capL, 0, srcW - capR, capT)
top:SetHeight(capT)
top:SetPoint("TOPLEFT", capL, 0)
top:SetPoint("TOPRIGHT", -capR, 0)
local bottom = piece(capL, srcH - capB, srcW - capR, srcH)
bottom:SetHeight(capB)
bottom:SetPoint("BOTTOMLEFT", capL, 0)
bottom:SetPoint("BOTTOMRIGHT", -capR, 0)
local left = piece(0, capT, capL, srcH - capB)
left:SetWidth(capL)
left:SetPoint("TOPLEFT", 0, -capT)
left:SetPoint("BOTTOMLEFT", 0, capB)
local right = piece(srcW - capR, capT, srcW, srcH - capB)
right:SetWidth(capR)
right:SetPoint("TOPRIGHT", 0, -capT)
right:SetPoint("BOTTOMRIGHT", 0, capB)
local center = piece(capL, capT, srcW - capR, srcH - capB)
center:SetPoint("TOPLEFT", capL, -capT)
center:SetPoint("BOTTOMRIGHT", -capR, capB)
end
-- Red panel button from the 128-redbutton atlas set: left/right caps
-- around the tiling center, drawn as three ARTWORK textures per state
-- (a Button's NormalTexture is a single texture, so three-slice states
-- are swapped by hand). The right slice ships 292px wide and is cropped
-- to the left cap's 114px.
-- The right slices are the mixed-case "128-RedButton-Right*" names: this
-- client registers those separately from the all-lowercase spellings the
-- other slices use, and the lowercase right variants resolve to older art.
local RB_CAP = 114 / 128 -- cap width as a fraction of button height
local RB_RIGHT_KEEP = 114 / 292
local function MakeButton(parent, w, h, label, onClick)
local b = CreateFrame("Button", nil, parent)
b:SetWidth(w)
b:SetHeight(h)
local capW = math.min(math.floor(h * RB_CAP + 0.5), math.floor(w / 2))
local stateAtlases = {
normal = { "128-redbutton-left", "_128-redbutton-center", "128-RedButton-Right" },
pressed = { "128-redbutton-left-pressed", "_128-redbutton-center-pressed", "128-RedButton-Right-Pressed" },
disabled = { "128-redbutton-left-disabled", "_128-redbutton-center-disabled", "128-RedButton-Right-Disabled" },
}
local groups = {}
for state, atlases in pairs(stateAtlases) do
local left = b:CreateTexture(nil, "ARTWORK")
ApplyAtlas(left, atlases[1])
left:SetWidth(capW)
left:SetPoint("TOPLEFT", 0, 0)
left:SetPoint("BOTTOMLEFT", 0, 0)
local center = b:CreateTexture(nil, "ARTWORK")
ApplyAtlas(center, atlases[2])
center:SetPoint("TOPLEFT", capW, 0)
center:SetPoint("BOTTOMRIGHT", -capW, 0)
local right = b:CreateTexture(nil, "ARTWORK")
ApplyAtlas(right, atlases[3])
CropRightTexCoord(right, RB_RIGHT_KEEP)
right:SetWidth(capW)
right:SetPoint("TOPRIGHT", 0, 0)
right:SetPoint("BOTTOMRIGHT", 0, 0)
groups[state] = { left, center, right }
end
local function ShowState(state)
for name, g in pairs(groups) do
for i = 1, 3 do
if name == state then g[i]:Show() else g[i]:Hide() end
end
end
end
-- One full-width highlight art, stretched over the assembled button.
local hl = b:CreateTexture(nil, "HIGHLIGHT")
ApplyAtlas(hl, "128-redbutton-highlight")
hl:SetAllPoints(b)
hl:SetBlendMode("ADD")
b:SetScript("OnMouseDown", function(self)
if self:IsEnabled() then ShowState("pressed") end
end)
b:SetScript("OnMouseUp", function(self)
ShowState(self:IsEnabled() and "normal" or "disabled")
end)
b:SetScript("OnEnable", function() ShowState("normal") end)
b:SetScript("OnDisable", function() ShowState("disabled") end)
ShowState("normal")
local t = b:CreateFontString(nil, "OVERLAY", "GameFontNormal")
t:SetPoint("CENTER", 0, 0)
b:SetFontString(t)
b:SetNormalFontObject(GameFontNormal)
b:SetDisabledFontObject(GameFontDisable)
b:SetText(label)
b.text = t
if onClick then b:SetScript("OnClick", onClick) end
return b
end
-- common-dropdown-b-button (CommonDropdown2x atlas): a 97x26 pill with the
-- dropdown chevron baked into its right cap, slice={8,0,18,0} — left cap
-- 8px, right cap 18px, middle stretches. None of Refactor's dropdowns are
-- ever disabled, so only the states the click handler actually drives are
-- built (the kit also has disabled/open/pressedhover for a future caller).
local DD_PILL_W, DD_PILL_H = 97, 26
local DD_PILL_CAP_L, DD_PILL_CAP_R = 8, 18
local DD_PILL_ATLAS_STATES = {
normal = "common-dropdown-b-button-2x",
hover = "common-dropdown-b-button-hover-2x",
pressed = "common-dropdown-b-button-pressed-2x",
}
-- Builds one BuildStripH per state and returns a ShowState(name) setter
-- that shows exactly one at a time.
local function BuildDropdownPill(parent)
local groups = {}
for state, atlas in pairs(DD_PILL_ATLAS_STATES) do
local strip = BuildStripH(parent, atlas, DD_PILL_W, DD_PILL_H,
DD_PILL_CAP_L, DD_PILL_CAP_R)
strip.Hide() -- BuildStripH's textures start shown; stack all three
-- and only the active one is revealed below
groups[state] = strip
end
local current
local function ShowState(state)
if current then current.Hide() end
current = groups[state]
current.Show()
end
ShowState("normal")
return ShowState
end
--------------------------------------------------------------------------
-- Dropdown popup list (common-dropdown-bg panel + common-dropdown-
-- textholder row highlight + the yellow checkmark icon) — a full custom
-- replacement for Blizzard's UIDropDownMenu list frame, not a reskin of
-- it, since that frame's own art can't be swapped out from under it.
-- One shared list frame (nothing here stacks); items are plain
-- {text, checked, func} tables the dropdown's itemsFn returns.
--------------------------------------------------------------------------
local DD_BG_ATLAS = "common-dropdown-bg-2x"
local DD_BG_W, DD_BG_H = 68, 68
local DD_BG_L, DD_BG_T, DD_BG_R, DD_BG_B = 16, 13, 16, 19 -- asymmetric: baked drop shadow at the bottom
local DD_ROWSTRIP_ATLAS = "common-dropdown-textholder-2x"
local DD_ROWSTRIP_W, DD_ROWSTRIP_H = 54, 41
local DD_ROWSTRIP_CAP_L, DD_ROWSTRIP_CAP_R = 16, 19
local DD_ROW_H = 24
-- Row label insets: the left one clears the checkmark column.
local DD_LABEL_L, DD_LABEL_R = 30, 10
-- The list is free to be wider than its pill (it opens over the page, and
-- profile names like "Knight of Xoroth - Defiance" don't fit a 200px pill).
-- Capped so a stray long name can't run off the window.
local DD_MAX_W = 420
local ddList, ddBlocker
local function HideDropdownList()
if ddList then
ddList:Hide()
ddList.owner = nil
end
end
local function BuildDropdownList()
-- Full-screen catcher behind the list: closes it on an outside click.
local blocker = CreateFrame("Button", nil, UIParent)
blocker:SetAllPoints(UIParent)
blocker:SetFrameStrata("FULLSCREEN_DIALOG")
blocker:SetFrameLevel(1)
blocker:Hide()
blocker:SetScript("OnClick", HideDropdownList)
ddBlocker = blocker
local list = CreateFrame("Frame", "RefactorUIDropdownList", UIParent)
list:SetFrameStrata("FULLSCREEN_DIALOG")
list:SetFrameLevel(10)
list:SetToplevel(true)
list:SetClampedToScreen(true)
list:Hide()
BuildNineSlicePanel(list, DD_BG_ATLAS, DD_BG_W, DD_BG_H,
DD_BG_L, DD_BG_T, DD_BG_R, DD_BG_B)
list.rows = {}
-- Hidden, width-unconstrained twin of a row label: the real labels are
-- anchored LEFT+RIGHT, so their GetStringWidth reports the constrained
-- (truncated) width and can't size the list. This one measures the
-- text's natural width instead.
list.measure = list:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
list.measure:SetPoint("TOPLEFT")
list.measure:Hide()
-- The blocker only exists to back an open list, so bind it to the
-- list's visibility here: every close path (row click, outside click,
-- Escape via UISpecialFrames, window close) runs through OnHide, so
-- the full-screen catcher can never outlive the list it belongs to.
list:SetScript("OnHide", function()
if ddBlocker then ddBlocker:Hide() end
end)
tinsert(UISpecialFrames, "RefactorUIDropdownList") -- Escape closes
ddList = list
return list
end
local function GetDropdownRow(list, index)
local row = list.rows[index]
if row then return row end
row = CreateFrame("Button", nil, list)
row:SetHeight(DD_ROW_H)
local hl = BuildStripH(row, DD_ROWSTRIP_ATLAS, DD_ROWSTRIP_W, DD_ROWSTRIP_H,
DD_ROWSTRIP_CAP_L, DD_ROWSTRIP_CAP_R, "ARTWORK")
hl.Hide()
local check = row:CreateTexture(nil, "OVERLAY")
ApplyAtlas(check, "common-dropdown-icon-checkmark-yellow-2x")
check:SetSize(15, 14)
check:SetPoint("LEFT", 10, 0)
local label = row:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
label:SetPoint("LEFT", DD_LABEL_L, 0)
label:SetPoint("RIGHT", -DD_LABEL_R, 0)
label:SetJustifyH("LEFT")
row:SetScript("OnEnter", function() hl.Show() end)
row:SetScript("OnLeave", function() hl.Hide() end)
row:SetScript("OnClick", function(self)
HideDropdownList()
if self.onClick then self.onClick() end
end)
row.hl, row.check, row.label = hl, check, label
list.rows[index] = row
return row
end
local function OpenDropdownList(dd)
local list = ddList or BuildDropdownList()
local items = dd.itemsFn and dd.itemsFn() or {}
-- Width first: measure every entry's natural text width so long profile
-- names read in full. The pill's width is the floor, DD_MAX_W the cap.
local chrome = DD_LABEL_L + DD_LABEL_R + DD_BG_L + DD_BG_R
local w = dd:GetWidth()
for _, item in ipairs(items) do
list.measure:SetText(item.text)
local need = list.measure:GetStringWidth() + chrome
if need > w then w = need end
end
w = math.min(math.ceil(w), DD_MAX_W)
for i, item in ipairs(items) do
local row = GetDropdownRow(list, i)
row:ClearAllPoints()
row:SetPoint("TOPLEFT", DD_BG_L, -(DD_BG_T + (i - 1) * DD_ROW_H))
row:SetWidth(w - DD_BG_L - DD_BG_R)
row.label:SetText(item.text)
row.onClick = item.func
if item.checked then row.check:Show() else row.check:Hide() end
row:Show()
end
for i = #items + 1, #list.rows do
list.rows[i]:Hide()
end
list:SetWidth(w)
list:SetHeight(DD_BG_T + math.max(#items, 1) * DD_ROW_H + DD_BG_B)
list:ClearAllPoints()
list:SetPoint("TOPLEFT", dd, "BOTTOMLEFT", 0, -2)
list.owner = dd
list:Show()
ddBlocker:Show()
end
-- Retail-style dropdown: the CommonDropdown2x pill as the closed-state
-- button, opening a fully custom list (above) instead of Blizzard's
-- UIDropDownMenu — that frame's own art can't be swapped from under it,
-- so this doesn't reskin it, it replaces it outright. `width` sets the
-- pill's (and the popup list's) width; the caller assigns `dd.itemsFn`
-- (a function returning an array of {text, checked, func}) and positions
-- `dd` like any other widget — no template, no global name required.
local function MakeDropdown(parent, width)
local dd = CreateFrame("Frame", nil, parent)
dd:SetSize(width, 26)
local ShowState = BuildDropdownPill(dd)
local text = dd:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
text:SetPoint("LEFT", 14, 1)
text:SetPoint("RIGHT", -20, 1)
text:SetJustifyH("LEFT")
dd.text = text
dd.SetText = function(self, t) self.text:SetText(t or "") end
local click = CreateFrame("Button", nil, dd)
click:SetAllPoints(dd)
click.enabled = true
click:SetScript("OnEnter", function(self)
if self.enabled then ShowState("hover") end
end)
click:SetScript("OnLeave", function(self)
if self.enabled then ShowState("normal") end
end)
click:SetScript("OnMouseDown", function(self)
if self.enabled then ShowState("pressed") end
end)
click:SetScript("OnMouseUp", function(self)
if not self.enabled then return end
ShowState(self:IsMouseOver() and "hover" or "normal")
end)
click:SetScript("OnClick", function()
if not click.enabled then return end
if ddList and ddList:IsShown() and ddList.owner == dd then
HideDropdownList()
else
OpenDropdownList(dd)
end
end)
dd.click = click
return dd
end
-- Retail-style minimal scrollbar (minimal-scrollbar-small atlas kit) for
-- UIPanelScrollFrameTemplate scrollbars, which are fully named. Stock
-- art is hidden; the arrows get atlas normal/over/down overlays swapped
-- by scripts; the engine-driven thumb keeps its behavior but wears the
-- atlas middle with cap textures over its ends (thumb over/down states
-- exist in the kit but the thumb is a texture, not a button — no mouse
-- scripts, so it stays in the normal state); a three-piece track sits
-- behind it.
local function SkinMinimalScrollbar(scroll)
local sb = _G[scroll:GetName() .. "ScrollBar"]
if not sb then return end
local sbName = sb:GetName()
local thumb = sb.GetThumbTexture and sb:GetThumbTexture()
or _G[sbName .. "ThumbTexture"]
-- Hide the stock track art ($parentTop/Middle/Bottom regions).
for i = 1, sb:GetNumRegions() do
local r = select(i, sb:GetRegions())
if r and r:IsObjectType("Texture") and r ~= thumb then r:Hide() end
end
local function Arrow(btnName, base)
local btn = _G[sbName .. btnName]
if not btn then return end
for _, getter in ipairs({ "GetNormalTexture", "GetPushedTexture",
"GetHighlightTexture", "GetDisabledTexture" }) do
local t = btn[getter](btn)
if t then t:SetAlpha(0) end
end
local function overlay(atlas)
local t = btn:CreateTexture(nil, "OVERLAY")
ApplyAtlas(t, atlas)
t:SetSize(17, 11)
t:SetPoint("CENTER", 0, 0)
t:Hide()
return t
end
local up, over, down = overlay(base), overlay(base .. "-over"), overlay(base .. "-down")
local pressed = false
local function Refresh()
up:Hide() over:Hide() down:Hide()
if pressed then down:Show()
elseif btn:IsMouseOver() then over:Show()
else up:Show() end
end
btn:HookScript("OnEnter", Refresh)
btn:HookScript("OnLeave", function() pressed = false Refresh() end)
btn:HookScript("OnMouseDown", function() pressed = true Refresh() end)
btn:HookScript("OnMouseUp", function() pressed = false Refresh() end)
Refresh()
end
Arrow("ScrollUpButton", "minimal-scrollbar-small-arrow-top")
Arrow("ScrollDownButton", "minimal-scrollbar-small-arrow-bottom")
-- Track behind the thumb, spanning between the two arrows.
local trackTop = sb:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(trackTop, "minimal-scrollbar-small-track-top")
trackTop:SetSize(8, 8)
trackTop:SetPoint("TOP", 0, -12)
local trackBot = sb:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(trackBot, "minimal-scrollbar-small-track-bottom")
trackBot:SetSize(8, 8)
trackBot:SetPoint("BOTTOM", 0, 12)
local trackMid = sb:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(trackMid, "!minimal-scrollbar-small-track-middle")
trackMid:SetWidth(8)
trackMid:SetPoint("TOP", trackTop, "BOTTOM", 0, 0)
trackMid:SetPoint("BOTTOM", trackBot, "TOP", 0, 0)
if thumb then
ApplyAtlas(thumb, "minimal-scrollbar-small-thumb-middle")
thumb:SetWidth(8)
local capTop = sb:CreateTexture(nil, "OVERLAY")
ApplyAtlas(capTop, "minimal-scrollbar-small-thumb-top")
capTop:SetSize(8, 8)
capTop:SetPoint("CENTER", thumb, "TOP", 0, 0)
local capBot = sb:CreateTexture(nil, "OVERLAY")
ApplyAtlas(capBot, "minimal-scrollbar-small-thumb-bottom")
capBot:SetSize(8, 8)
capBot:SetPoint("CENTER", thumb, "BOTTOM", 0, 0)
-- The engine hides the thumb when the content fits; the caps
-- anchored to it must follow (textures have no OnHide script).
-- Polled rather than event-driven because the engine hides the
-- ThumbTexture directly and textures carry no OnHide script. 10 Hz
-- is plenty for a cosmetic cap follow — at 60 Hz this was two C
-- calls per frame per scrollbar for as long as the window was open.
local capAccum = 0
sb:HookScript("OnUpdate", function(_, elapsed)
capAccum = capAccum + (elapsed or 0)
if capAccum < 0.1 then return end
capAccum = 0
local show = thumb:IsShown() and true or false
if (capTop:IsShown() and true or false) ~= show then
if show then capTop:Show() capBot:Show()
else capTop:Hide() capBot:Hide() end
end
end)
end
end
-- Three-slice input-field border from the common-search atlas (16x40 caps
-- around a tiling middle), drawn as BACKGROUND textures filling `frame`.
-- capW scales the 16px cap to the field's height. Returns the {left, right,
-- mid} list so callers can tint it (gold on focus). Shared by MakeEdit
-- (numeric fields) and MakeSearchBox.
local function ApplySearchBorder(frame, height, capW)
local left = frame:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(left, "common-search-border-left")
left:SetSize(capW, height)
left:SetPoint("TOPLEFT", 0, 0)
left:SetPoint("BOTTOMLEFT", 0, 0)
local right = frame:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(right, "common-search-border-right")
right:SetSize(capW, height)
right:SetPoint("TOPRIGHT", 0, 0)
right:SetPoint("BOTTOMRIGHT", 0, 0)
local mid = frame:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(mid, "common-search-border-middle")
mid:SetPoint("TOPLEFT", left, "TOPRIGHT", 0, 0)
mid:SetPoint("BOTTOMRIGHT", right, "BOTTOMLEFT", 0, 0)
return { left, right, mid }
end
-- Edit box wearing the common-search border art (same kit as the sidebar
-- search, minus the glyph/clear button). Border tints gold on focus.
-- With get/set (numeric): commits on Enter / focus lost, reverts on
-- Escape. Without: plain text field, read via GetText().
local EDIT_H = 22
local EDIT_CAP = 9 -- 16px cap scaled from the atlas's 40px native height
local function MakeEdit(parent, w, get, set)
local eb = CreateFrame("EditBox", nil, parent)
eb:SetWidth(w)
eb:SetHeight(EDIT_H)
eb:SetAutoFocus(false)
eb:SetFontObject(ChatFontNormal)
eb:SetTextInsets(8, 8, 0, 0)
local border = ApplySearchBorder(eb, EDIT_H, EDIT_CAP)
eb:SetScript("OnEditFocusGained", function(self)
for _, t in ipairs(border) do
t:SetVertexColor(ACCENT[1], ACCENT[2], ACCENT[3])
end
self:HighlightText()
end)
eb:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
eb:SetScript("OnEscapePressed", function(self)
self.reverting = true
self:ClearFocus()
end)
eb:SetScript("OnEditFocusLost", function(self)
for _, t in ipairs(border) do t:SetVertexColor(1, 1, 1) end
self:HighlightText(0, 0)
if get and set then
if not self.reverting then
local v = tonumber(self:GetText())
if v then set(v) end
end
self:Refresh()
end
self.reverting = nil
end)
eb.Refresh = function(self)
if get then self:SetText(tostring(get() or 0)) end
end
return eb
end
-- Search box wearing the common-search atlas kit: left/right caps (16x40
-- native) around a tiling middle, a magnifying-glass glyph pinned at the
-- left and a clear button at the right that appears only while there's
-- text. The border tints gold on focus like MakeEdit. Returns the EditBox
-- (so SetText/GetText/ClearFocus work directly); the caller wires its own
-- OnTextChanged via HookScript for the actual filtering. The internal
-- affordance/focus handlers are all HookScript too, so caller and widget
-- coexist without either clobbering the other's OnTextChanged.
local SEARCH_H = 26
local SEARCH_CAP = 10 -- 16px cap scaled from the atlas's 40px native height
local function MakeSearchBox(parent, width)
local container = CreateFrame("Frame", nil, parent)
container:SetSize(width, SEARCH_H)
local border = ApplySearchBorder(container, SEARCH_H, SEARCH_CAP)
local icon = container:CreateTexture(nil, "OVERLAY")
ApplyAtlas(icon, "common-search-magnifyingglass")
icon:SetSize(16, 16)
icon:SetPoint("LEFT", 8, 0)
local clear = CreateFrame("Button", nil, container)
clear:SetSize(13, 13)
clear:SetPoint("RIGHT", -(SEARCH_CAP - 1), 0)
local clearTex = clear:CreateTexture(nil, "OVERLAY")
ApplyAtlas(clearTex, "common-search-clearbutton")
clearTex:SetAllPoints()
clear:Hide()
local eb = CreateFrame("EditBox", nil, container)
eb:SetAutoFocus(false)
eb:SetFontObject(ChatFontNormal)
eb:SetTextInsets(2, 2, 0, 0)
eb:SetHeight(SEARCH_H)
eb:SetPoint("LEFT", icon, "RIGHT", 4, 0)
eb:SetPoint("RIGHT", clear, "LEFT", -3, 0)
local placeholder = eb:CreateFontString(nil, "OVERLAY", "GameFontDisable")
placeholder:SetPoint("LEFT", 2, 0)
placeholder:SetText("Search")
local function UpdateAffordances()
local has = (eb:GetText() or "") ~= ""
if has then clear:Show() else clear:Hide() end
if has or eb:HasFocus() then placeholder:Hide() else placeholder:Show() end
end
clear:SetScript("OnClick", function()
eb:SetText("")
eb:SetFocus()
end)
eb:HookScript("OnTextChanged", UpdateAffordances)
eb:HookScript("OnEditFocusGained", function()
for _, t in ipairs(border) do
t:SetVertexColor(ACCENT[1], ACCENT[2], ACCENT[3])
end
UpdateAffordances()
end)
eb:HookScript("OnEditFocusLost", function()
for _, t in ipairs(border) do t:SetVertexColor(1, 1, 1) end
UpdateAffordances()
end)
eb:SetScript("OnEnterPressed", function(self) self:ClearFocus() end)
eb:SetScript("OnEscapePressed", function(self) self:ClearFocus() end)
eb.container = container
return eb
end
-- Options slider wearing the MinimalSliderBar atlas kit (Left + tiling
-- _Middle + Right track, Button thumb) instead of OptionsSliderTemplate's
-- stock art; the template still supplies behavior, so the engine keeps
-- driving the thumb. Needs a global name — the template's Low/High/Text
-- labels are $parent-relative and only resolve with one; every caller
-- must pass a unique name. Low/High/Text go blank (the row already
-- carries its own label) and the live value reads instead in a small
-- fontstring to the slider's right.
-- get/set still deal in the widget's own min..max units; displayBase (optional)
-- only rescales the readout — passing the value that should read "1.00" makes
-- that the visible "default size" mark without moving where it sits physically
-- on the track.
local function MakeSlider(parent, name, w, minV, maxV, step, get, set, displayBase)
local s = CreateFrame("Slider", name, parent, "OptionsSliderTemplate")
s:SetWidth(w)
s:SetHeight(17)
s:SetOrientation("HORIZONTAL")
s:SetMinMaxValues(minV, maxV)
s:SetValueStep(step)
_G[name .. "Low"]:SetText("")
_G[name .. "High"]:SetText("")
_G[name .. "Text"]:SetText("")
-- MinimalSliderBar art: hide the stock track regions, re-lay the
-- three-piece track, and re-skin the engine thumb.
local thumb = s.GetThumbTexture and s:GetThumbTexture()
for i = 1, s:GetNumRegions() do
local r = select(i, s:GetRegions())
if r:IsObjectType("Texture") and r ~= thumb then r:Hide() end
end
local trackL = s:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(trackL, "Minimal_SliderBar_Left")
trackL:SetSize(11, 17)
trackL:SetPoint("LEFT", 0, 0)
local trackR = s:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(trackR, "Minimal_SliderBar_Right")
trackR:SetSize(11, 17)
trackR:SetPoint("RIGHT", 0, 0)
local trackM = s:CreateTexture(nil, "BACKGROUND")
ApplyAtlas(trackM, "_Minimal_SliderBar_Middle")
trackM:SetHeight(17)
trackM:SetPoint("LEFT", trackL, "RIGHT", 0, 0)
trackM:SetPoint("RIGHT", trackR, "LEFT", 0, 0)
if thumb then
ApplyAtlas(thumb, "Minimal_SliderBar_Button")
thumb:SetSize(20, 19)
end
local valueText = parent:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
valueText:SetPoint("LEFT", s, "RIGHT", 10, 0)
local function Display(value)
if displayBase and displayBase ~= 0 then value = value / displayBase end
valueText:SetText(string.format("%.2f", value))
end
s:SetScript("OnValueChanged", function(self, value)
Display(value)
if not self.suppress and set then set(value) end
end)
s.Refresh = function(self)
local v = (get and get()) or minV
self.suppress = true
self:SetValue(v)
self.suppress = nil
Display(v)
end
return s
end
--------------------------------------------------------------------------
-- Window shell: header, sidebar navigation, page plumbing
--------------------------------------------------------------------------
local window
local navButtons = {}
local pages = {}
local currentKey
-- "search" is a page too (results list), just never in the nav.
local PAGE_ORDER = { "general", "loot", "tweaks" }
local PAGE_TITLES = {
general = "General", loot = "Loot", tweaks = "Tweaks",
search = "Search",
}
local function NewPage(key)
local p = CreateFrame("Frame", nil, window)
p:SetPoint("TOPLEFT", INSET + SIDEBAR_W + PAD, -(HEADER_H + 14))
p:SetPoint("BOTTOMRIGHT", -CENTER_RIGHT, PAD + 6)
p:Hide()
p.pageKey = key
p.tracked = {}
p.Track = function(self, widget)
tinsert(self.tracked, widget)
return widget
end
p.Refresh = function(self)
for _, w in ipairs(self.tracked) do
if w.Refresh then w:Refresh() end
end
if self.OnRefresh then self:OnRefresh() end
end
pages[key] = p
return p
end
local function UpdateNav()
-- Active page: gold dot bullet + gold label; everything else parchment.
-- (currentKey may be "search", which has no nav button — all deselect.)
for key, b in pairs(navButtons) do
if key == currentKey then
b.dot:Show()
b.label:SetTextColor(ACCENT[1], ACCENT[2], ACCENT[3])
else
b.dot:Hide()
b.label:SetTextColor(C_PARCH[1], C_PARCH[2], C_PARCH[3])
end
end
end
local function UpdateFooter()
if not window then return end
window.footer:SetText("|cffffffffQuality of life for Ascension|r")
end
local function SelectPage(key)
HideDropdownList() -- an open dropdown belongs to the page being left
currentKey = key
for k, p in pairs(pages) do
if k == key then p:Show() else p:Hide() end
end
UpdateNav()
UpdateFooter()
if pages[key] then pages[key]:Refresh() end
-- Reset the detail pane to the page's own summary.
if SetDetail and pages[key] then
SetDetail(PAGE_TITLES[key] or "", pages[key].blurb)
end
end
--------------------------------------------------------------------------
-- Page: General
--------------------------------------------------------------------------
local function BuildGeneralPage()
local p = NewPage("general")
p.blurb = "The minimap button and version notices. Loot toasts have " ..