-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfig.lua
More file actions
2060 lines (1900 loc) · 90.8 KB
/
Copy pathConfig.lua
File metadata and controls
2060 lines (1900 loc) · 90.8 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
-- Quartermaster -- Config
-- A modular, tabbed config panel. Each feature module owns a tab, registered via
-- QM.registerConfigTab{ name=, order=, build=function(page) } at load time; this
-- file just lays the tabs out down the left and builds each page lazily into the
-- content area on the right. New features add a tab instead of fighting for space
-- on one crowded panel -- that's the answer to "we'll run out of config room".
--
-- The reusable QM.Config.listEditor (a FauxScrollFrame list with add / reorder /
-- remove + a per-row amount) backs both the Buffs and Items tabs, so the
-- per-character add/reorder UX is one widget, not two.
--
-- Widget idioms (custom edit-box backdrop, value-in-title sliders, the upvalue
-- discipline) follow the sibling FearWardHelper config; see its CLAUDE.md.
local QM = Quartermaster
QM.Config = {}
local PANEL_BACKDROP = {
bgFile = "Interface\\DialogFrame\\UI-DialogBox-Background",
edgeFile = "Interface\\DialogFrame\\UI-DialogBox-Border",
tile = true, tileSize = 32, edgeSize = 16,
insets = { left = 5, right = 5, top = 5, bottom = 5 },
}
local EDITBOX_BACKDROP = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 9,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
}
-- Backdrop for the apply-mode drop button's popup menu (a touch heavier border than
-- the edit boxes so the floating list reads as a distinct panel).
local MENU_BACKDROP = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
tile = true, tileSize = 16, edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
}
-- Popups that float outside the tab-page hierarchy -- dropdown menus, the gear popup,
-- the modal dialogs -- are deliberately parented straight to the panel (not a tab's page)
-- so a ScrollFrame never clips them. That means hiding a page on tab switch never hides
-- them as a side effect. Anything built that way registers itself here once; selectTab()
-- and toggleConfig()'s hide branch close whatever's left open so a stray popup can't
-- survive a tab switch or a close/reopen of the panel.
local floaters = {}
local function registerFloater(frame)
floaters[table.getn(floaters) + 1] = frame
end
local function closeFloaters()
for i = 1, table.getn(floaters) do
if floaters[i]:IsShown() then floaters[i]:Hide() end
end
end
-- Route shift-clicked item links into whichever Quartermaster edit box currently has
-- focus (_linkSink, set by the add box on focus gain, cleared on focus loss).
local function routeLink(text)
local sink = QM.Config._linkSink
if text and sink and sink:IsVisible() then
sink:Insert(text)
sink:SetFocus()
return true
end
return false
end
-- On 1.12 a shift-click in the world/bags is handled by HandleModifiedItemClick, which
-- only forwards to ChatEdit_InsertLink when the CHAT edit box is visible -- so wrapping
-- ChatEdit_InsertLink alone never catches links destined for a custom box. We intercept
-- HandleModifiedItemClick itself (the real entry point), and still wrap
-- ChatEdit_InsertLink for the path that reaches it directly (clicking a link in chat).
local origModifiedClick = HandleModifiedItemClick
function HandleModifiedItemClick(link)
if link and IsModifiedClick("CHATLINK") and routeLink(link) then return true end
if origModifiedClick then return origModifiedClick(link) end
end
local origInsertLink = ChatEdit_InsertLink
function ChatEdit_InsertLink(text)
if routeLink(text) then return true end
if origInsertLink then return origInsertLink(text) end
return false
end
-- Drag/drop support. Vanilla has no API to read the item sitting on the cursor, so we
-- remember its link as it is picked up (from a bag or an equipped slot -- captured BEFORE
-- the pickup empties the source) and consume that when an item is dropped on a focused
-- add box. Cleared whenever a pickup leaves the cursor empty.
local origPickupContainer = PickupContainerItem
function PickupContainerItem(bag, slot)
local link = GetContainerItemLink(bag, slot)
if origPickupContainer then origPickupContainer(bag, slot) end
QM.Config._cursorLink = CursorHasItem() and link or nil
end
local origPickupInventory = PickupInventoryItem
function PickupInventoryItem(slot)
local link = GetInventoryItemLink("player", slot)
if origPickupInventory then origPickupInventory(slot) end
QM.Config._cursorLink = CursorHasItem() and link or nil
end
-- Drop the cursor's item into `box` (the add box). Returns true if a link was placed.
function QM.Config.dropCursorItem(box)
if not CursorHasItem() then return false end
local link = QM.Config._cursorLink
if link then box:Insert(link); box:SetFocus() end
ClearCursor()
QM.Config._cursorLink = nil
return link and true or false
end
-- ---------------------------------------------------------------------------
-- Small widget factories (shared by every tab)
-- ---------------------------------------------------------------------------
-- A text/numeric edit box with a tooltip-style backdrop (InputBoxTemplate's
-- border renders a black bar at small heights, hence the custom backdrop).
function QM.Config.editbox(parent, width, onCommit)
local e = CreateFrame("EditBox", nil, parent)
e:SetWidth(width); e:SetHeight(20)
e:SetAutoFocus(false)
e:SetFontObject(GameFontHighlightSmall)
e:SetTextInsets(5, 5, 2, 2)
e:SetBackdrop(EDITBOX_BACKDROP)
e:SetBackdropColor(0, 0, 0, 0.7)
e:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8)
local escaping = false
e:SetScript("OnEnterPressed", function() onCommit(this:GetText()); this:ClearFocus() end)
-- Escape means discard: suppress the focus-lost commit below so the box just reverts
-- to the saved value on the next repaint instead of committing the abandoned text.
e:SetScript("OnEscapePressed", function() escaping = true; this:ClearFocus() end)
-- Commit on focus loss too, not just Enter -- so a value typed then abandoned by
-- clicking elsewhere still lands rather than reverting silently. Tracked in
-- QM.Config._focusedEditBox so the panel's OnHide can force this even when hiding the
-- frame doesn't itself raise a focus-lost event (closing the config with a box still
-- focused).
e:SetScript("OnEditFocusGained", function() QM.Config._focusedEditBox = this end)
e:SetScript("OnEditFocusLost", function()
if QM.Config._focusedEditBox == this then QM.Config._focusedEditBox = nil end
if escaping then escaping = false
elseif onCommit then onCommit(this:GetText()) end
end)
return e
end
-- A checkbox; onClick gets the new boolean. Optional get() seeds the initial state.
function QM.Config.check(parent, text, x, y, onClick, get)
local cb = CreateFrame("CheckButton", nil, parent, "UICheckButtonTemplate")
cb:SetWidth(22); cb:SetHeight(22)
cb:SetPoint("TOPLEFT", x, y)
local fs = cb:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
fs:SetPoint("LEFT", cb, "RIGHT", 2, 0); fs:SetText(text)
cb.label = fs -- exposed so callers can chain a neighbour off its rendered width
cb:SetScript("OnClick", function() onClick(this:GetChecked() and true or false) end)
if get then cb:SetChecked(get() and true or false) end
return cb
end
-- A horizontal slider whose title carries the live value. onChange gets the new
-- value; optional get()/fmt() seed and format it. A guard flag suppresses the
-- OnValueChanged feedback while we seed the value.
function QM.Config.slider(parent, name, label, min, max, step, x, y, onChange, get, fmt)
local s = CreateFrame("Slider", name, parent, "OptionsSliderTemplate")
s:SetMinMaxValues(min, max)
s:SetValueStep(step)
s:SetWidth(170); s:SetHeight(16)
s:SetPoint("TOPLEFT", x, y)
getglobal(name .. "Low"):SetText("")
getglobal(name .. "High"):SetText("")
local function paint(v) getglobal(name .. "Text"):SetText(label .. ": " .. (fmt and fmt(v) or v)) end
s:SetScript("OnValueChanged", function()
if QM.Config._setting then return end
onChange(this:GetValue())
paint(this:GetValue())
end)
if get then
QM.Config._setting = true
s:SetValue(get())
QM.Config._setting = false
paint(get())
end
return s
end
-- A small gold section sub-header, so a page of controls reads as grouped clusters rather
-- than one long stack (matches the HUD's gold category labels).
function QM.Config.sectionHeader(page, text, x, y)
local fs = page:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
fs:SetPoint("TOPLEFT", x, y)
fs:SetText(text)
fs:SetTextColor(1, 0.82, 0)
return fs
end
-- A top-down layout cursor for a config page: stacks section headers and 1-or-2-column
-- checkbox rows while tracking the running Y, so a tab doesn't hand-compute every offset.
-- Non-checkbox controls (sliders, drop buttons) read `L.y` for their top and call
-- `L.advance(px)` to reserve their height. `col1`/`col2` are the two checkbox column x's.
function QM.Config.layout(page, top)
local L = { page = page, y = top or -8, col1 = 8, col2 = 300 }
function L.section(text)
L.y = L.y - 8
QM.Config.sectionHeader(page, text, 8, L.y)
L.y = L.y - 18
end
-- One row of up to two checkboxes; each arg is { label, setFn, getFn }. Returns the
-- left-column checkbox (a page-left handle later controls can anchor beneath).
function L.checks(a, b)
local c1 = QM.Config.check(page, a[1], L.col1, L.y, a[2], a[3])
if b then QM.Config.check(page, b[1], L.col2, L.y, b[2], b[3]) end
L.y = L.y - 24
return c1
end
function L.advance(px) L.y = L.y - (px or 12) end
return L
end
-- The shared "flat dark" button look used across the whole panel (the drop / icon /
-- state / tab / action buttons all read alike): the tooltip-style backdrop, plus a
-- hover-brighten on the border. Callers that need a custom OnEnter (a tooltip, an
-- enabled check) set their own afterwards.
local function styleFlatButton(b)
b:SetBackdrop(EDITBOX_BACKDROP)
b:SetBackdropColor(0, 0, 0, 0.7)
b:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8)
b:SetScript("OnEnter", function() this:SetBackdropBorderColor(0.9, 0.8, 0.2, 1) end)
b:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8) end)
end
-- A generic flat action button in the shared style. Centered label on `b.label`;
-- pressing nudges the label.
-- Caller sets the width; height defaults to 22. onClick is optional (wire it later if the
-- handler isn't in scope yet).
function QM.Config.button(parent, text, onClick)
local b = CreateFrame("Button", nil, parent)
b:SetHeight(22)
styleFlatButton(b)
local fs = b:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
fs:SetPoint("CENTER", 0, 0)
fs:SetText(text or "")
b.label = fs
b:SetScript("OnMouseDown", function() this.label:SetPoint("CENTER", 1, -1) end)
b:SetScript("OnMouseUp", function() this.label:SetPoint("CENTER", 0, 0) end)
if onClick then b:SetScript("OnClick", onClick) end
return b
end
-- A selectable button in the same style, for the config tab strip: b.setSelected(on)
-- shows the pressed/active look (lit background + gold border + bright label) and unselected
-- dims the label; the selected button ignores hover so the active tab stays lit.
function QM.Config.toggleButton(parent, text, onClick)
local b = QM.Config.button(parent, text, onClick)
b.label:SetTextColor(0.7, 0.7, 0.7)
function b.setSelected(on)
b.selected = on and true or false
if b.selected then
b:SetBackdropColor(0.22, 0.20, 0.05, 0.95)
b:SetBackdropBorderColor(0.9, 0.8, 0.2, 1)
b.label:SetTextColor(1, 1, 1)
else
b:SetBackdropColor(0, 0, 0, 0.7)
b:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8)
b.label:SetTextColor(0.7, 0.7, 0.7)
end
end
b:SetScript("OnEnter", function() if not this.selected then this:SetBackdropBorderColor(0.9, 0.8, 0.2, 1) end end)
b:SetScript("OnLeave", function() if not this.selected then this:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8) end end)
return b
end
-- A drop button (edit-box styled, like the in-row controls) showing the current value
-- and dropping a popup list to change it -- no cycling. Used for both the in-row apply
-- column and the bigger Row-order config control. `spec`:
-- width/height -- button size (height defaults to 18)
-- menuWidth -- popup width (defaults to width + 12)
-- values -- ordered list of stored values (menu order), or a function returning
-- one: the menu is then rebuilt on every open (dynamic sets, e.g.
-- profile names)
-- labels -- value -> display label (the menu entries + button face); optional
-- tips -- value -> tooltip line; optional
-- prefix -- shown before the value on the face, e.g. "Row order: Config"; optional
-- onSelect(v) -- called when a menu entry is picked
-- get() -- optional: when given, the button self-paints from it on build and
-- after each pick. Omit it for recycled rows (the caller repaints via
-- b.setValue each draw instead).
-- The popup floats on DIALOG strata so it draws above the list rows; the live value is
-- stashed on b.value for the hover tooltip.
function QM.Config.dropButton(parent, spec)
local values = spec.values
local labels = spec.labels or {}
local tips = spec.tips
local tipLines = spec.tipLines -- value -> array of lines; computed live on hover
-- (vs. the static `tips` map), for a preview that
-- depends on other UI state (e.g. a chosen character).
local width = spec.width or 46
local b = CreateFrame("Button", nil, parent)
b:SetWidth(width); b:SetHeight(spec.height or 18)
styleFlatButton(b)
-- Optional texture swatch behind the face: a full green progress bar drawn in the
-- candidate texture, so the picker previews the actual bar (spec.swatches: value->path).
-- The label sits on the swatch (a child frame draws above the button's own regions).
local faceSwatch
if spec.swatches then
faceSwatch = CreateFrame("StatusBar", nil, b)
faceSwatch:SetPoint("TOPLEFT", 3, -3); faceSwatch:SetPoint("BOTTOMRIGHT", -3, 3)
faceSwatch:SetMinMaxValues(0, 1); faceSwatch:SetValue(1)
faceSwatch:SetStatusBarColor(0.2, 0.8, 0.2)
end
local fs = (faceSwatch or b):CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
fs:SetPoint("CENTER", b, "CENTER", 0, 0)
b.label = fs
-- Paint the face from a stored value (also stashed for the tooltip). Exposed so the
-- recycled-row caller can repaint per draw.
function b.setValue(v)
b.value = v
-- staticLabel: the face always reads this fixed text (the value shows only in the open
-- menu) -- for a picker where the face is a live preview, e.g. the bar-texture swatch.
local txt = spec.staticLabel or labels[v] or v or "?"
if spec.prefix and not spec.staticLabel then txt = spec.prefix .. ": " .. txt end
fs:SetText(txt)
if faceSwatch and spec.swatches[v] then faceSwatch:SetStatusBarTexture(spec.swatches[v]) end
end
-- Popup menu, toggled on click. It is hosted on the PANEL (not the
-- button) at a high strata BY DEFAULT: parented under its button a drop menu sits inside
-- the tab's ScrollFrame, so it gets clipped where it overflows and shares the rows'
-- strata, landing behind the controls below. It still anchors to the button, so it
-- tracks position. (menuParent/menuStrata override for callers outside the panel.)
local MENU_ITEM_H = spec.swatches and 20 or 14
local menu = CreateFrame("Frame", nil, spec.menuParent or getglobal("Quartermaster_Config") or b)
menu:SetBackdrop(MENU_BACKDROP)
menu:SetBackdropColor(0, 0, 0, 0.95)
menu:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.9)
menu:SetWidth(spec.menuWidth or (width + 12))
menu:SetPoint("TOPLEFT", b, "BOTTOMLEFT", 0, 0)
menu:SetFrameStrata(spec.menuStrata or "FULLSCREEN_DIALOG")
menu:SetToplevel(true)
menu:Hide()
registerFloater(menu)
b.menu = menu
-- Entry buttons are pooled so a dynamic menu (spec.values as a FUNCTION, e.g. profile
-- names) can be rebuilt on every open; static menus build once below.
menu.items = {}
local function menuItem(i)
local item = menu.items[i]
if item then return item end
item = CreateFrame("Button", nil, menu)
item:SetHeight(MENU_ITEM_H)
item:SetPoint("TOPLEFT", menu, "TOPLEFT", 4, -(4 + (i - 1) * MENU_ITEM_H))
item:SetPoint("RIGHT", menu, "RIGHT", -4, 0)
-- A swatch entry previews the texture as a filled bar (a tinted ARTWORK texture, so
-- the label OVERLAY and the auto HIGHLIGHT still layer over it on the same button).
if spec.swatches then
local sw = item:CreateTexture(nil, "ARTWORK")
sw:SetPoint("TOPLEFT", 1, -1); sw:SetPoint("BOTTOMRIGHT", -1, 1)
sw:SetVertexColor(0.2, 0.8, 0.2)
item.swatch = sw
end
local ifs = item:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
ifs:SetPoint("LEFT", item, "LEFT", 4, 0)
item.label = ifs
local hl = item:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints(item); hl:SetTexture(0.3, 0.3, 0.8, 0.5)
item:SetScript("OnClick", function()
menu:Hide()
if spec.onSelect then spec.onSelect(this.value) end
if spec.get then b.setValue(this.value) end
end)
if tips or tipLines then
item:SetScript("OnEnter", function()
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
if tipLines then
local lines = tipLines(this.value) or {}
for i = 1, table.getn(lines) do GameTooltip:AddLine(lines[i]) end
else
GameTooltip:AddLine(tips[this.value] or "")
end
GameTooltip:Show()
end)
item:SetScript("OnLeave", function() GameTooltip:Hide() end)
end
menu.items[i] = item
return item
end
local function buildItems(vals)
local n = table.getn(vals)
for i = 1, n do
local item = menuItem(i)
item.value = vals[i]
item.label:SetText(labels[vals[i]] or vals[i])
if item.swatch then
if spec.swatches[vals[i]] then
item.swatch:SetTexture(spec.swatches[vals[i]]); item.swatch:Show()
else
item.swatch:Hide()
end
end
item:Show()
end
for i = n + 1, table.getn(menu.items) do menu.items[i]:Hide() end
menu:SetHeight(n * MENU_ITEM_H + 8)
end
if type(values) ~= "function" then buildItems(values) end
b:SetScript("OnEnter", function()
this:SetBackdropBorderColor(0.9, 0.8, 0.2, 1)
if tips and this.value then
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:AddLine(tips[this.value] or "")
GameTooltip:AddLine("Click to change", 0.5, 0.5, 0.5)
GameTooltip:Show()
end
end)
b:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8); GameTooltip:Hide() end)
b:SetScript("OnClick", function()
if menu:IsShown() then
menu:Hide()
return
end
-- Don't pop an empty menu (e.g. the Mail panel's profile drop before a character
-- is picked, or a character drop with no other tracked characters yet) -- there's
-- nothing to select, so it would just be a dead dropdown.
local vals = (type(values) == "function") and values() or values
if not vals or table.getn(vals) == 0 then return end
if type(values) == "function" then buildItems(vals) end
menu:Show()
end)
if spec.get then b.setValue(spec.get()) end
return b
end
-- ---------------------------------------------------------------------------
-- Reusable modal popups: name prompt, confirm, big text dialog
-- ---------------------------------------------------------------------------
-- One lazy instance each, floated on FULLSCREEN_DIALOG so they draw above the
-- panel and its scroll regions (StaticPopup lives on the panel's own DIALOG
-- strata and would z-fight it).
local function modalShell(width, height)
local p = CreateFrame("Frame", nil, getglobal("Quartermaster_Config") or UIParent)
p:SetWidth(width); p:SetHeight(height)
p:SetBackdrop(PANEL_BACKDROP)
p:SetBackdropColor(0, 0, 0, 1)
p:SetBackdropBorderColor(0.9, 0.8, 0.2, 1)
p:SetFrameStrata("FULLSCREEN_DIALOG")
p:SetToplevel(true)
p:EnableMouse(true) -- swallow clicks so they do not fall through
p:SetPoint("CENTER", 0, 40)
p:Hide()
registerFloater(p)
-- The DialogBox backdrop texture is itself semi-translucent; a solid black fill
-- inside the border makes the popup fully opaque.
local solid = p:CreateTexture(nil, "BACKGROUND")
solid:SetPoint("TOPLEFT", 5, -5)
solid:SetPoint("BOTTOMRIGHT", -5, 5)
solid:SetTexture(0, 0, 0, 1)
local title = p:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("TOPLEFT", 10, -9)
title:SetPoint("RIGHT", p, "RIGHT", -30, 0)
title:SetJustifyH("LEFT")
title:SetTextColor(1, 0.82, 0)
p.title = title
local close = CreateFrame("Button", nil, p, "UIPanelCloseButton")
close:SetWidth(26); close:SetHeight(26)
close:SetPoint("TOPRIGHT", 2, 2)
close:SetScript("OnClick", function() p:Hide() end)
local err = p:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
err:SetJustifyH("LEFT")
err:SetTextColor(1, 0.3, 0.3)
p.err = err
return p
end
-- Prompt for one line of text. onCommit(text) -> ok, err: on ok the popup closes,
-- otherwise err is shown and it stays open for another attempt.
local promptFrame
function QM.Config.promptText(titleText, initial, onCommit)
if not promptFrame then
local p = modalShell(300, 92)
promptFrame = p
-- No onCommit here (and OnEnterPressed set explicitly below): this is a one-shot
-- OK/Cancel action, not a persistent field, so closing it any other way (the X,
-- or the panel closing under it) must discard rather than auto-commit on blur.
p.box = QM.Config.editbox(p, 200)
p.box:SetScript("OnEnterPressed", function() p.commit(this:GetText()); this:ClearFocus() end)
p.box:SetPoint("TOPLEFT", 12, -32)
local ok = QM.Config.button(p, "OK", function() p.commit(p.box:GetText()) end)
ok:SetWidth(60)
ok:SetPoint("LEFT", p.box, "RIGHT", 8, 0)
p.err:SetPoint("TOPLEFT", p.box, "BOTTOMLEFT", 0, -4)
p.err:SetPoint("RIGHT", p, "RIGHT", -12, 0)
end
promptFrame.commit = function(text)
local ok, err = onCommit(text)
if ok then promptFrame:Hide() else promptFrame.err:SetText(err or "") end
end
promptFrame.title:SetText(titleText or "")
promptFrame.err:SetText("")
promptFrame.box:SetText(initial or "")
promptFrame:Show()
promptFrame.box:SetFocus()
promptFrame.box:HighlightText()
end
-- Accept/Cancel confirmation; onAccept runs on Accept.
local confirmFrame
function QM.Config.confirm(message, onAccept)
if not confirmFrame then
local p = modalShell(300, 100)
confirmFrame = p
local msg = p:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
msg:SetPoint("TOPLEFT", 12, -30)
msg:SetPoint("RIGHT", p, "RIGHT", -12, 0)
msg:SetJustifyH("LEFT")
p.msg = msg
local yes = QM.Config.button(p, "Accept", function()
p:Hide()
if p.onAccept then p.onAccept() end
end)
yes:SetWidth(80)
yes:SetPoint("BOTTOMLEFT", 12, 12)
local no = QM.Config.button(p, "Cancel", function() p:Hide() end)
no:SetWidth(80)
no:SetPoint("LEFT", yes, "RIGHT", 8, 0)
end
confirmFrame.title:SetText("Confirm")
confirmFrame.msg:SetText(message or "")
confirmFrame.onAccept = onAccept
confirmFrame:Show()
end
-- Big multiline text dialog for export/import strings. spec:
-- title, hint -- header + grey helper line
-- text -- prefilled content ("show" mode: selected for Ctrl+C)
-- buttonText -- action button label (defaults: Close / Import)
-- onCommit(text) -- "input" mode: -> ok, err; ok closes, err shows and stays open.
-- Omit onCommit for "show" mode (the action button just closes).
local textFrame
function QM.Config.textDialog(spec)
if not textFrame then
local p = modalShell(440, 260)
textFrame = p
local hint = p:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
hint:SetPoint("TOPLEFT", 12, -28)
hint:SetPoint("RIGHT", p, "RIGHT", -12, 0)
hint:SetJustifyH("LEFT")
hint:SetTextColor(0.7, 0.7, 0.7)
p.hint = hint
-- backdrop behind the scroll area so the box reads as an input (created before
-- the scroll frame so it draws underneath)
local boxBg = CreateFrame("Frame", nil, p)
boxBg:SetBackdrop(EDITBOX_BACKDROP)
boxBg:SetBackdropColor(0, 0, 0, 0.7)
boxBg:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8)
boxBg:SetPoint("TOPLEFT", 12, -44)
boxBg:SetPoint("BOTTOMRIGHT", -12, 44)
boxBg:EnableMouse(true)
local scroll = CreateFrame("ScrollFrame", "QuartermasterTextDialogScroll", p, "UIPanelScrollFrameTemplate")
scroll:SetPoint("TOPLEFT", boxBg, "TOPLEFT", 6, -6)
scroll:SetPoint("BOTTOMRIGHT", boxBg, "BOTTOMRIGHT", -8, 6)
-- Fixed oversized height + hidden scrollbar is the working 1.12 idiom for a
-- multiline box in this template (the box auto-scrolls to keep the cursor visible).
local box = CreateFrame("EditBox", nil, scroll)
box:SetWidth(390)
box:SetHeight(10000)
box:SetMultiLine(true)
box:SetAutoFocus(false)
box:SetFontObject(GameFontHighlightSmall)
box:SetScript("OnEscapePressed", function() this:ClearFocus() end)
box:SetScript("OnTextChanged", function() scroll:UpdateScrollChildRect() end)
-- in show mode a stray click must not cost the selection
box:SetScript("OnEditFocusGained", function() if p.selectAll then this:HighlightText() end end)
scroll:SetScrollChild(box)
p.box = box
boxBg:SetScript("OnMouseDown", function() box:SetFocus() end)
local scrollBar = getglobal("QuartermasterTextDialogScrollScrollBar")
if scrollBar then
scrollBar:Hide()
scrollBar.Show = function() end
end
p.action = QM.Config.button(p, "", function() p.onAction() end)
p.action:SetWidth(100)
p.action:SetPoint("BOTTOMLEFT", 12, 12)
p.err:SetPoint("LEFT", p.action, "RIGHT", 8, 0)
p.err:SetPoint("RIGHT", p, "RIGHT", -12, 0)
end
local p = textFrame
p.title:SetText(spec.title or "")
p.hint:SetText(spec.hint or "")
p.err:SetText("")
p.selectAll = not spec.onCommit
p.box:SetText(spec.text or "")
if spec.onCommit then
p.action.label:SetText(spec.buttonText or "Import")
p.onAction = function()
local ok, err = spec.onCommit(p.box:GetText())
if ok then p:Hide() else p.err:SetText(err or "") end
end
else
p.action.label:SetText(spec.buttonText or "Close")
p.onAction = function() p:Hide() end
end
p:Show()
p.box:SetFocus()
if p.selectAll then p.box:HighlightText() end
end
-- ---------------------------------------------------------------------------
-- Reusable list editor (FauxScrollFrame) -- add / reorder / remove + amount
-- ---------------------------------------------------------------------------
local ROW_H = 20
local VISIBLE = 11 -- rows shown at once (the list scrolls past this); the taller list still
-- fits above/within the (scrollable) page with the top controls + add row
local LIST_PAD = 4 -- inner padding of the bordered list container
-- Column geometry shared by the header labels and each row's controls, so the two
-- can never drift apart. Measured as RIGHT-edge offsets from the row's right edge.
local BTN_W = 20 -- reorder / delete button width
local BTN_GAP = 2
local AMT_W = 44 -- target / low edit-box width
local AMT_GAP = 6
local APPLY_W = 46 -- apply-mode drop button width (consumables only)
local APPLY_GAP = 6
local RECIPIENT_W = APPLY_W * 2.5 -- mail-recipient drop button width (Transfer only) --
-- wider than Use since it shows a character/custom name,
-- not a short mode label; shares APPLY_GAP/the Use slot
local TRACK_W = 44 -- track-axis drop button (Buff/CD/None)
local TRACK_GAP = 6
local GEAR_W = 18 -- per-row gear opener for the buff/enchant tracking popup
local GEAR_GAP = 3
local RESTOCK_W = 18 -- vendor-restock toggle, right of Target
local RESTOCK_GAP = 4
local STATE_W = 18 -- tristate enabled/hidden/off chip (leftmost column)
local STATE_GAP = 4
-- Row reorder/delete buttons, styled to match the edit boxes (dark tooltip backdrop)
-- since they sit right beside them. The glyph is an icon texture exposed as `b.icon`
-- so callers can recolour it (up/down are tinted green/grey per row by whether the
-- move is possible).
local function iconButton(parent, icon, onClick)
local b = CreateFrame("Button", nil, parent)
b:SetWidth(BTN_W); b:SetHeight(18)
styleFlatButton(b)
local t = b:CreateTexture(nil, "ARTWORK")
t:SetWidth(11); t:SetHeight(11)
t:SetPoint("CENTER", 0, 0)
t:SetTexture(icon)
b.icon = t
-- hover brightens the border (only while enabled); press nudges the glyph
b:SetScript("OnEnter", function() if this:IsEnabled() == 1 then this:SetBackdropBorderColor(0.9, 0.8, 0.2, 1) end end)
b:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8) end)
b:SetScript("OnMouseDown", function() this.icon:SetPoint("CENTER", 1, -1) end)
b:SetScript("OnMouseUp", function() this.icon:SetPoint("CENTER", 0, 0) end)
b:SetScript("OnClick", onClick)
return b
end
-- Icon textures for the row controls. up/down are our own white arrows (recoloured per
-- row); delete is the group-loot X (confirmed present on the 1.12 client).
local TEX_DIR = "Interface\\AddOns\\Quartermaster\\textures\\"
local ICON_UP = TEX_DIR .. "up"
local ICON_DOWN = TEX_DIR .. "down"
local ICON_CIRCLE = TEX_DIR .. "circle" -- tristate state chip, tinted per state
local ICON_DELETE = "Interface\\Buttons\\UI-GroupLoot-Pass-Up"
local ICON_GEAR = "Interface\\Icons\\INV_Misc_Gear_01" -- per-row track-config opener
local ICON_COIN = "Interface\\Icons\\INV_Misc_Coin_01" -- per-row vendor-restock toggle
local ICON_BAG = "Interface\\Icons\\INV_Misc_Bag_08" -- per-row bankable toggle (Transfer)
-- arrow tints: bright green when the row can move that way, grey when it can't
local MOVE_OK = { 0.2, 0.9, 0.2 }
local MOVE_NONE = { 0.5, 0.5, 0.5 }
-- Use-mode drop button. Modes match Consumables.APPLY_* ("none"/"self"/"weapon"/"mh"/"oh"/
-- "target"); kept as literals here to avoid a load-order dependency. "weapon" means both
-- weapons; "mh"/"oh" narrow it to one hand. "none" is a stocked/reagent row with no direct
-- use. Vendor auto-restock is a SEPARATE per-row toggle (see restockButton), independent of
-- this mode -- an item can be both "self" and restocked.
local APPLY_ORDER = { "none", "self", "target", "weapon", "mh", "oh" } -- menu order
local APPLY_LABEL = { none = "None", self = "Self", target = "Tgt", weapon = "Wpn", mh = "MH", oh = "OH" }
local APPLY_TIP = {
none = "Not applied directly -- count only (a stocked reagent)",
self = "Used on yourself (potions, elixirs, flasks, food)",
target = "Targeted items (scrolls, jujus) -- always cast on yourself",
weapon = "Applied to both weapons (stones, oils, poisons)",
mh = "Applied to the main hand only",
oh = "Applied to the off hand only",
}
-- The in-row Use column is just the shared drop button (QM.Config.dropButton) at the
-- narrow APPLY_W width, with no get() -- the row repaints it per draw from the entry's
-- stored mode via b.setValue. Picking a mode calls onSelect(mode) (wired to QM.setApply).
local function applyButton(parent, onSelect)
return QM.Config.dropButton(parent, {
width = APPLY_W, height = 18,
values = APPLY_ORDER, labels = APPLY_LABEL, tips = APPLY_TIP,
onSelect = onSelect,
})
end
-- Mail-recipient drop button (Transfer tab only). Unlike Use/Track the candidate list is
-- DYNAMIC (known characters + the manually managed custom list, see Transfer.lua's
-- QM.transferRecipients) and always includes a synthetic "(default)" entry mapping to a
-- nil row.mailRecipient (falls back to the character's own defaultMailRecipient). No
-- get() -- recycled rows repaint via b.setValue from the entry, like Use/Track.
local function recipientButton(parent, onSelect)
return QM.Config.dropButton(parent, {
width = RECIPIENT_W, height = 18,
values = function()
local v = { "(default)" }
local r = QM.transferRecipients and QM.transferRecipients() or {}
for i = 1, table.getn(r) do table.insert(v, r[i]) end
return v
end,
onSelect = onSelect,
})
end
-- Track-axis drop button (QM.TRACK_*). Unlike Use, it writes the ACCOUNT-WIDE item
-- record (QM.setItemTrack), not the per-row entry -- one source for every alt. No
-- get() (recycled rows repaint via b.setValue per draw from QM.itemTrack).
local TRACK_ORDER = { "buff", "cd", "food", "stock" }
local TRACK_LABEL = { buff = "Buff", cd = "CD", food = "Food", stock = "Stock" }
local TRACK_TIP = {
buff = "Track the buff/enchant time left; falls back to the item cooldown when down",
cd = "Track the item's usability cooldown only (healing/mana pots)",
food = "Like Buff, plus a sit-and-eat progress bar before the Well Fed buff lands",
stock = "Count only -- no timer, just the carried count vs target (reagents)",
}
local function trackButton(parent, onSelect)
return QM.Config.dropButton(parent, {
width = TRACK_W, height = 18,
values = TRACK_ORDER, labels = TRACK_LABEL, tips = TRACK_TIP,
onSelect = onSelect,
})
end
-- Tiny gear opener (shown on Buff rows): opens the per-item tracking popup. The glyph is
-- tinted per the match-rule state (b.icon:SetVertexColor in the row refresh); b.tipExtra,
-- if set, adds a line (the live validation state) to its tooltip.
local function gearButton(parent, onClick)
local b = CreateFrame("Button", nil, parent)
b:SetWidth(GEAR_W); b:SetHeight(18)
styleFlatButton(b)
local t = b:CreateTexture(nil, "ARTWORK")
t:SetWidth(14); t:SetHeight(14)
t:SetPoint("CENTER", 0, 0)
t:SetTexture(ICON_GEAR)
t:SetTexCoord(0.07, 0.93, 0.07, 0.93)
b.icon = t
b:SetScript("OnEnter", function()
this:SetBackdropBorderColor(0.9, 0.8, 0.2, 1)
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:AddLine("Configure buff/enchant tracking")
if this.tipExtra then local x = this.tipExtra(); if x then GameTooltip:AddLine(x) end end
GameTooltip:Show()
end)
b:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8); GameTooltip:Hide() end)
b:SetScript("OnMouseDown", function() this.icon:SetPoint("CENTER", 1, -1) end)
b:SetScript("OnMouseUp", function() this.icon:SetPoint("CENTER", 0, 0) end)
b:SetScript("OnClick", onClick)
return b
end
-- Vendor-restock toggle, right of Target: a coin glyph tinted gold when the entry buys up to
-- Target at a merchant that sells it, grey otherwise. Independent of the Use column -- an
-- item can be both used (self/weapon/target) AND restocked. b.on carries the current state
-- for the tooltip; the row refresh sets it and the tint each paint.
local RESTOCK_ON = { 0.95, 0.82, 0.20 }
local RESTOCK_OFF = { 0.45, 0.45, 0.45 }
local function restockButton(parent, onClick)
local b = CreateFrame("Button", nil, parent)
b:SetWidth(RESTOCK_W); b:SetHeight(18)
styleFlatButton(b)
local t = b:CreateTexture(nil, "ARTWORK")
t:SetWidth(13); t:SetHeight(13)
t:SetPoint("CENTER", 0, 0)
t:SetTexture(ICON_COIN)
t:SetTexCoord(0.07, 0.93, 0.07, 0.93)
b.icon = t
b:SetScript("OnEnter", function()
this:SetBackdropBorderColor(0.9, 0.8, 0.2, 1)
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:AddLine(this.on and "Vendor-restock: ON" or "Vendor-restock: OFF")
GameTooltip:AddLine("Buys up to Target from a merchant that sells it", 0.6, 0.6, 0.6)
GameTooltip:AddLine("Click to toggle", 0.5, 0.5, 0.5)
GameTooltip:Show()
end)
b:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8); GameTooltip:Hide() end)
b:SetScript("OnMouseDown", function() this.icon:SetPoint("CENTER", 1, -1) end)
b:SetScript("OnMouseUp", function() this.icon:SetPoint("CENTER", 0, 0) end)
b:SetScript("OnClick", onClick)
return b
end
-- Bankable toggle (Transfer tab only), the same right-of-Target slot restockButton uses on
-- the Tracker tab (the two never appear on the same list, so they share RESTOCK_W/GAP).
-- A bag glyph tinted green when the entry's excess (bag qty above Keep) is OK to bank on
-- /qm banksync, grey otherwise.
local BANKABLE_ON = { 0.30, 0.85, 0.35 }
local BANKABLE_OFF = { 0.45, 0.45, 0.45 }
local function bankableButton(parent, onClick)
local b = CreateFrame("Button", nil, parent)
b:SetWidth(RESTOCK_W); b:SetHeight(18)
styleFlatButton(b)
local t = b:CreateTexture(nil, "ARTWORK")
t:SetWidth(13); t:SetHeight(13)
t:SetPoint("CENTER", 0, 0)
t:SetTexture(ICON_BAG)
t:SetTexCoord(0.07, 0.93, 0.07, 0.93)
b.icon = t
b:SetScript("OnEnter", function()
this:SetBackdropBorderColor(0.9, 0.8, 0.2, 1)
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:AddLine(this.on and "Bankable: ON" or "Bankable: OFF")
GameTooltip:AddLine("OK to bank this item's excess on /qm banksync", 0.6, 0.6, 0.6)
GameTooltip:AddLine("Click to toggle", 0.5, 0.5, 0.5)
GameTooltip:Show()
end)
b:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8); GameTooltip:Hide() end)
b:SetScript("OnMouseDown", function() this.icon:SetPoint("CENTER", 1, -1) end)
b:SetScript("OnMouseUp", function() this.icon:SetPoint("CENTER", 0, 0) end)
b:SetScript("OnClick", onClick)
return b
end
-- Tristate enabled/hidden/off chip (the leftmost column). Modes match QM.itemState's
-- "enabled"/"hidden"/"off": one circle icon tinted three ways (a traffic-light "level
-- of involvement").
local STATE_COLOR = {
enabled = { 0.20, 0.80, 0.20 }, -- green: shown + counted
hidden = { 0.95, 0.75, 0.10 }, -- amber: counted but not shown
off = { 0.45, 0.45, 0.45 }, -- grey: ignored (kept in list)
}
local STATE_TIP = {
enabled = "Enabled -- shown in the tracker and counted for restock",
hidden = "Hidden -- not shown in the tracker, still counted for restock",
off = "Off -- ignored everywhere (kept in the list)",
}
local function stateButton(parent, onCycle)
local b = CreateFrame("Button", nil, parent)
b:SetWidth(STATE_W); b:SetHeight(STATE_W)
styleFlatButton(b)
local sw = b:CreateTexture(nil, "ARTWORK")
sw:SetWidth(STATE_W - 6); sw:SetHeight(STATE_W - 6)
sw:SetPoint("CENTER", 0, 0)
sw:SetTexture(ICON_CIRCLE) -- white circle, tinted per state via SetVertexColor
b.swatch = sw
b:SetScript("OnEnter", function()
this:SetBackdropBorderColor(0.9, 0.8, 0.2, 1)
if this.state then
GameTooltip:SetOwner(this, "ANCHOR_RIGHT")
GameTooltip:AddLine(STATE_TIP[this.state] or "")
GameTooltip:AddLine("Click to change", 0.5, 0.5, 0.5)
GameTooltip:Show()
end
end)
b:SetScript("OnLeave", function() this:SetBackdropBorderColor(0.4, 0.4, 0.4, 0.8); GameTooltip:Hide() end)
b:SetScript("OnClick", onCycle)
return b
end
-- Weapon-applied items track a temp-ENCHANT identity rather than a player buff.
local function isWeaponApply(apply)
return apply == "weapon" or apply == "mh" or apply == "oh"
end
-- Human-readable account of the in-force match rule, so the status line can tell the user HOW
-- an effect is identified (which enchant id/name, or which buff).
local function describeMatch(m)
if not m then return "nothing" end
if m.by == "enchantid" then return "enchant id " .. tostring(m.value) end
if m.by == "enchantname" then return "enchant name '" .. tostring(m.value) .. "'" end
if m.by == "icon" then return "the buff icon" end
if m.by == "name" then return "buff name '" .. tostring(m.value) .. "'" end
if m.by == "id" then return "buff id " .. tostring(m.value) end
return "nothing"
end
-- The per-item buff/enchant tracking popup opened by a row's gear button (one instance
-- per list editor, re-bound to whichever item's gear was clicked). Every field edits the
-- ACCOUNT-WIDE items[id] record (QM.setItemMatch / setItemMaxDuration), so configuring an
-- item once works on every alt. The status line tracks validation (QM.itemMatchStatus):
-- the rule auto-confirms the moment its effect is seen in game (QM's passive validateTick).
local function buildGearPopup(parent)
local p = CreateFrame("Frame", nil, parent)
p:SetWidth(236); p:SetHeight(166)
p:SetBackdrop(PANEL_BACKDROP)
p:SetBackdropColor(0, 0, 0, 1)
p:SetBackdropBorderColor(0.9, 0.8, 0.2, 1)
p:SetFrameStrata("FULLSCREEN_DIALOG")
p:SetToplevel(true)
p:EnableMouse(true) -- swallow clicks so they do not fall through to the rows
p:Hide()
registerFloater(p)
-- The DialogBox backdrop texture is itself semi-translucent, so the list shows through.
-- A solid black fill inside the border makes the popup fully opaque.
local solid = p:CreateTexture(nil, "BACKGROUND")
solid:SetPoint("TOPLEFT", 5, -5)
solid:SetPoint("BOTTOMRIGHT", -5, 5)
solid:SetTexture(0, 0, 0, 1)
local title = p:CreateFontString(nil, "OVERLAY", "GameFontNormal")
title:SetPoint("TOPLEFT", 10, -9)
title:SetPoint("RIGHT", p, "RIGHT", -30, 0)
title:SetJustifyH("LEFT")
title:SetTextColor(1, 0.82, 0)
local close = CreateFrame("Button", nil, p, "UIPanelCloseButton")
close:SetWidth(26); close:SetHeight(26)
close:SetPoint("TOPRIGHT", 2, 2)
close:SetScript("OnClick", function() p:Hide() end)
-- "Match by icon" stores match{ by="icon" } (the reliable native primitive), cleared
-- when a name/id is typed instead. A buff-tracked item already matches its own icon by
-- default, so this just makes that explicit / re-asserts it.
local iconCheck = QM.Config.check(p, "Match by buff icon", 8, -30, function(on)
local id = p.id; if not id then return end
if on then
local m = QM.itemMatchEffective(id, p.apply)
local val = (m and m.by == "icon" and m.value) or QM.itemMeta(id).icon
if not val then
local _, _, _, _, _, _, _, _, tex = GetItemInfo("item:" .. id)
val = tex
end
QM.setItemMatch(id, "icon", val)
p.nameBox:SetText("")
else
QM.setItemMatch(id, nil)
end
end)
p.iconCheck = iconCheck
-- Weapon items (no buff icon to match) get a "learn from weapon" button in the icon check's
-- place instead: the user puts the enchant on, then clicks to capture its identity off the
-- equipped weapon. refreshFields shows exactly one of the two for the item's apply mode.
local learnBtn = QM.Config.button(p, "Learn from weapon", function()
local id = p.id; if not id then return end
local r = QM.learnWeaponEnchantNow(id, p.apply)
if not r then p.setStatus("no temp enchant on the weapon to learn") end
p.refreshFields()
end)
learnBtn:SetWidth(150); learnBtn:SetPoint("TOPLEFT", 8, -30)
learnBtn:Hide()
p.learnBtn = learnBtn
local nameLabel = p:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
nameLabel:SetPoint("TOPLEFT", 12, -58)
local nameBox = QM.Config.editbox(p, 150, function(text)
local id = p.id; if not id then return end
text = QM.trim(text)
if text == "" then QM.setItemMatch(id, nil); return end
local num = tonumber(text)
local by, value
if isWeaponApply(p.apply) then
if num and QM.caps.equippedItem then by, value = "enchantid", num
else by, value = "enchantname", text end
else
if num and QM.caps.superwow then by, value = "id", num
else by, value = "name", text end
end
local ok, err = QM.setItemMatch(id, by, value)
if ok then iconCheck:SetChecked(false) else p.setStatus(err) end
end)
nameBox:SetPoint("TOPLEFT", nameLabel, "BOTTOMLEFT", 0, -4)
p.nameBox = nameBox
local durLabel = p:CreateFontString(nil, "ARTWORK", "GameFontNormalSmall")
durLabel:SetText("Duration (sec, 0 = auto)")
durLabel:SetPoint("TOPLEFT", nameBox, "BOTTOMLEFT", 0, -8)
local durBox = QM.Config.editbox(p, 56, function(text)
local n = tonumber(text)
QM.setItemMaxDuration(p.id, (n and n > 0) and n or nil)
end)
durBox:SetPoint("TOPLEFT", durLabel, "BOTTOMLEFT", 0, -4)
durBox:SetJustifyH("RIGHT")
p.durBox = durBox
-- Live validation state: the rule auto-confirms the moment the effect is seen in raid
-- (no manual probe). Red = nothing to match on; yellow = configured but not yet seen;