-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSearchFrame.lua
More file actions
executable file
·941 lines (839 loc) · 35.6 KB
/
Copy pathSearchFrame.lua
File metadata and controls
executable file
·941 lines (839 loc) · 35.6 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
local L = LibStub("AceLocale-3.0"):GetLocale("Brannfred")
local LSM = LibStub("LibSharedMedia-3.0")
local MSQ = LibStub("Masque", true)
Brannfred.searchFrame = CreateFrame("Frame", "BrannfredSearchFrame", UIParent, "BackdropTemplate")
local main_font = "fonts/frizqt__.ttf"
local frame = Brannfred.searchFrame
frame:SetSize(420, 46)
frame:SetPoint("TOP", UIParent, "TOP", 0, -280)
frame:SetFrameStrata("HIGH")
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", frame.StartMoving)
frame:SetScript("OnDragStop", frame.StopMovingOrSizing)
frame:SetBackdrop({ edgeFile = "Interface/Buttons/WHITE8X8", edgeSize = 1 })
frame:SetBackdropBorderColor(0.25, 0.25, 0.25, 1)
-- Background as a separate BACKGROUND-layer texture so it never covers the border
local frameBg = frame:CreateTexture(nil, "BACKGROUND")
frameBg:SetColorTexture(0.07, 0.07, 0.07, 0.93)
frameBg:SetPoint("TOPLEFT", frame, "TOPLEFT", 1, -1)
frameBg:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -1, 1)
frame:Hide()
-- EditBox
Brannfred.searchEditBox = CreateFrame("EditBox", "BrannfredSearchEditBox", frame)
local editBox = Brannfred.searchEditBox
editBox:SetSize(390, 30)
editBox:SetPoint("CENTER", frame, "CENTER")
editBox:SetAutoFocus(false)
editBox:SetPropagateKeyboardInput(false)
editBox:SetFont(main_font, 15, "")
editBox:SetTextColor(0.95, 0.95, 0.95, 1)
-- Constants
local MAX_RESULTS = 50
local VISIBLE_ROWS = 10 -- may be updated by ApplyFrameSettings
local CONTENT_PAD = 1 -- may be updated by ApplyFrameSettings
local ROW_HEIGHT = 32
-- Context menu constants
local MAX_CTX_ROWS = 10
local CTX_ROW_HEIGHT = 28
local CTX_HEADER_H = 28
local CTX_WIDTH = 210
-- Type label lookup: reads the label field each provider declares
local function getTypeLabel(entryType)
for _, provider in ipairs(Brannfred.providers) do
if provider.type == entryType then
return provider.label or ""
end
end
return ""
end
-- Ensure UI text fields never receive booleans/tables from providers.
local function asText(value)
local t = type(value)
if t == "string" then return value end
if t == "number" then return tostring(value) end
return ""
end
-- State
local currentResults = {}
local selectedIndex = 1
local masqueGroup = nil
-- Context menu state
local ctxMenuOpen = false
local ctxEntry = nil
local ctxActions = {}
local ctxSelectedIdx = 1
-- Sentinel: returned by getContextActionForModifier when the user explicitly
-- set a modifier to "none" (disabled). Truthy so callers can distinguish it
-- from nil (= "no match found, try built-in fallback").
local CTX_DISABLED = {}
-- Forward declarations
local selectRow, showDescription, updateScrollBar
local openContextMenu, closeContextMenu, selectCtxRow, activateCtxAction
local getContextActionForModifier
-- Shared backdrop helper — border only, background handled by a separate texture
local BACKDROP = { edgeFile = "Interface/Buttons/WHITE8X8", edgeSize = 1 }
local function applyBackdrop(f)
f:SetBackdrop(BACKDROP)
f:SetBackdropBorderColor(0.25, 0.25, 0.25, 1)
end
-- ── Results dropdown ──────────────────────────────────────────────────────────
local resultsFrame = CreateFrame("Frame", "BrannfredResultsFrame", frame, "BackdropTemplate")
resultsFrame:SetWidth(420)
resultsFrame:SetPoint("TOPLEFT", frame, "BOTTOMLEFT", 0, -2)
resultsFrame:SetFrameStrata("HIGH")
applyBackdrop(resultsFrame)
local resultsBg = resultsFrame:CreateTexture(nil, "BACKGROUND")
resultsBg:SetColorTexture(0.07, 0.07, 0.07, 0.93)
resultsBg:SetPoint("TOPLEFT", resultsFrame, "TOPLEFT", 1, -1)
resultsBg:SetPoint("BOTTOMRIGHT", resultsFrame, "BOTTOMRIGHT", -1, 1)
resultsFrame:Hide()
-- ScrollFrame (clips rows to the visible area)
local scrollFrame = CreateFrame("ScrollFrame", nil, resultsFrame)
scrollFrame:SetPoint("TOPLEFT", resultsFrame, "TOPLEFT", 1, -1)
scrollFrame:SetPoint("BOTTOMRIGHT", resultsFrame, "BOTTOMRIGHT", -5, 1)
scrollFrame:EnableMouseWheel(true)
scrollFrame:SetScript("OnMouseWheel", function(self, delta)
local cur = self:GetVerticalScroll()
local max = self:GetVerticalScrollRange()
self:SetVerticalScroll(math.max(0, math.min(max, cur - delta * ROW_HEIGHT)))
updateScrollBar()
end)
local scrollChild = CreateFrame("Frame")
scrollChild:SetWidth(414) -- 420 - 1 border - 5 right (scrollbar area)
scrollFrame:SetScrollChild(scrollChild)
-- Scrollbar track + thumb (4 px strip on the right edge of resultsFrame)
local sbTrack = resultsFrame:CreateTexture(nil, "OVERLAY")
sbTrack:SetWidth(4)
sbTrack:SetColorTexture(0.12, 0.12, 0.12, 0.9)
sbTrack:SetPoint("TOPRIGHT", resultsFrame, "TOPRIGHT", -1, -1)
sbTrack:SetPoint("BOTTOMRIGHT", resultsFrame, "BOTTOMRIGHT", -1, 1)
sbTrack:Hide()
local sbThumb = resultsFrame:CreateTexture(nil, "OVERLAY")
sbThumb:SetWidth(4)
sbThumb:SetColorTexture(0.55, 0.55, 0.55, 0.9)
sbThumb:Hide()
updateScrollBar = function()
local total = #currentResults
if total <= VISIBLE_ROWS then
sbTrack:Hide()
sbThumb:Hide()
return
end
sbTrack:Show()
sbThumb:Show()
local trackH = VISIBLE_ROWS * ROW_HEIGHT
local thumbH = math.max(16, trackH * VISIBLE_ROWS / total)
sbThumb:SetHeight(thumbH)
local range = scrollFrame:GetVerticalScrollRange()
local frac = (range > 0) and (scrollFrame:GetVerticalScroll() / range) or 0
sbThumb:ClearAllPoints()
sbThumb:SetPoint("TOPRIGHT", resultsFrame, "TOPRIGHT", -CONTENT_PAD, -CONTENT_PAD - frac * (trackH - thumbH))
end
-- ── Description panel ─────────────────────────────────────────────────────────
local descFrame = CreateFrame("Frame", "BrannfredDescFrame", frame, "BackdropTemplate")
descFrame:SetWidth(420)
descFrame:SetPoint("TOPLEFT", resultsFrame, "BOTTOMLEFT", 0, -2)
descFrame:SetFrameStrata("HIGH")
applyBackdrop(descFrame)
local descBg = descFrame:CreateTexture(nil, "BACKGROUND")
descBg:SetColorTexture(0.07, 0.07, 0.07, 0.93)
descBg:SetPoint("TOPLEFT", descFrame, "TOPLEFT", 1, -1)
descBg:SetPoint("BOTTOMRIGHT", descFrame, "BOTTOMRIGHT", -1, 1)
descFrame:Hide()
local descIconBtn = CreateFrame("Button", nil, descFrame)
descIconBtn:SetSize(48, 48)
descIconBtn:SetPoint("TOPLEFT", descFrame, "TOPLEFT", 8, -8)
descIconBtn:EnableMouse(true)
local descIcon = descIconBtn:CreateTexture(nil, "ARTWORK")
descIcon:SetAllPoints()
descIcon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
local descEntry = nil
descIconBtn:SetScript("OnEnter", function(self)
if descEntry and descEntry.onIconTooltip then
descEntry.onIconTooltip(self)
end
end)
descIconBtn:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
local descName = descFrame:CreateFontString(nil, "OVERLAY")
descName:SetFont(main_font, 14, "OUTLINE")
descName:SetTextColor(1, 0.82, 0, 1)
descName:SetPoint("TOPLEFT", descFrame, "TOPLEFT", 64, -10)
descName:SetPoint("TOPRIGHT", descFrame, "TOPRIGHT", -8, -10)
descName:SetJustifyH("LEFT")
descName:SetWordWrap(false)
local descStats = descFrame:CreateFontString(nil, "OVERLAY")
descStats:SetFont(main_font, 11, "")
descStats:SetTextColor(0.7, 0.7, 0.7, 1)
descStats:SetPoint("TOPLEFT", descFrame, "TOPLEFT", 64, -32)
descStats:SetPoint("TOPRIGHT", descFrame, "TOPRIGHT", -8, -32)
descStats:SetJustifyH("LEFT")
descStats:SetWordWrap(true)
descStats:SetWidth(348)
local sep = descFrame:CreateTexture(nil, "BACKGROUND")
sep:SetHeight(1)
sep:SetColorTexture(0.25, 0.25, 0.25, 1)
sep:SetPoint("TOPLEFT", descFrame, "TOPLEFT", 8, -64)
sep:SetPoint("TOPRIGHT", descFrame, "TOPRIGHT", -8, -64)
local descText = descFrame:CreateFontString(nil, "OVERLAY")
descText:SetFont(main_font, 12, "")
descText:SetTextColor(0.85, 0.85, 0.85, 1)
descText:SetPoint("TOPLEFT", descFrame, "TOPLEFT", 8, -72)
descText:SetPoint("TOPRIGHT", descFrame, "TOPRIGHT", -8, -72)
descText:SetJustifyH("LEFT")
descText:SetJustifyV("TOP")
descText:SetWordWrap(true)
descText:SetNonSpaceWrap(false)
-- ── Rows ──────────────────────────────────────────────────────────────────────
local rows = {}
for i = 1, MAX_RESULTS do
local row = CreateFrame("Button", nil, scrollChild)
row:SetHeight(ROW_HEIGHT)
row:SetPoint("TOPLEFT", scrollChild, "TOPLEFT", 0, -(i - 1) * ROW_HEIGHT)
row:SetPoint("TOPRIGHT", scrollChild, "TOPRIGHT", 0, -(i - 1) * ROW_HEIGHT)
local hl = row:CreateTexture(nil, "HIGHLIGHT")
hl:SetAllPoints()
hl:SetColorTexture(1, 1, 1, 0.08)
local sel = row:CreateTexture(nil, "BACKGROUND")
sel:SetAllPoints()
sel:SetColorTexture(0.2, 0.6, 1, 0.18)
sel:Hide()
row.selTex = sel
-- Dedicated Button child so Masque can skin only the icon area
local iconBtn = CreateFrame("Button", nil, row)
iconBtn:SetSize(22, 22)
iconBtn:SetPoint("LEFT", row, "LEFT", 6, 0)
iconBtn:EnableMouse(true)
local icon = iconBtn:CreateTexture(nil, "ARTWORK")
icon:SetAllPoints()
icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
row.iconBtn = iconBtn
row.icon = icon
iconBtn:SetScript("OnEnter", function(self)
if row.entry then
selectRow(i)
if row.entry.onIconTooltip then
row.entry.onIconTooltip(self)
end
end
end)
iconBtn:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
-- Type label (right-aligned, gray)
local typeLabel = row:CreateFontString(nil, "OVERLAY")
typeLabel:SetFont(main_font, 10, "")
typeLabel:SetTextColor(0.45, 0.45, 0.45, 1)
typeLabel:SetPoint("RIGHT", row, "RIGHT", -8, 0)
typeLabel:SetWidth(0)
typeLabel:SetJustifyH("RIGHT")
row.typeLabel = typeLabel
-- Optional meta label (provider-defined short info, e.g. slot count)
local metaLabel = row:CreateFontString(nil, "OVERLAY")
metaLabel:SetFont(main_font, 11, "")
metaLabel:SetTextColor(0.65, 0.65, 0.65, 1)
metaLabel:SetPoint("RIGHT", typeLabel, "LEFT", -8, 0)
metaLabel:SetWidth(70)
metaLabel:SetJustifyH("RIGHT")
row.metaLabel = metaLabel
local text = row:CreateFontString(nil, "OVERLAY")
text:SetFont(main_font, 13, "")
text:SetTextColor(0.95, 0.95, 0.95, 1)
text:SetPoint("LEFT", icon, "RIGHT", 7, 0)
text:SetPoint("RIGHT", metaLabel, "LEFT", -4, 0)
text:SetJustifyH("LEFT")
row.text = text
row.entry = nil
local rowIndex = i
row:SetScript("OnEnter", function(self)
if self.entry then
selectRow(rowIndex)
-- If context menu is open, switch it to this entry
if ctxMenuOpen and ctxEntry ~= self.entry then
openContextMenu(self.entry)
end
end
end)
row:RegisterForClicks("LeftButtonUp", "RightButtonUp")
row:SetScript("OnClick", function(self, button)
if not self.entry then return end
if button == "RightButton" then
if ctxMenuOpen then
closeContextMenu()
else
selectRow(rowIndex)
openContextMenu(self.entry)
end
return
end
if self.entry._insertText then
editBox:SetText(self.entry._insertText)
editBox:SetFocus()
return
end
if IsShiftKeyDown() then
local action = getContextActionForModifier(self.entry, "shift")
if action and action ~= CTX_DISABLED then
Brannfred.AddToHistory(self.entry)
if not action.keepOpen then frame:Hide() end
action.func()
return
end
end
if IsControlKeyDown() then
local action = getContextActionForModifier(self.entry, "ctrl")
if action and action ~= CTX_DISABLED then
Brannfred.AddToHistory(self.entry)
if not action.keepOpen then frame:Hide() end
action.func()
return
end
end
if IsAltKeyDown() then
local action = getContextActionForModifier(self.entry, "alt")
if action and action ~= CTX_DISABLED then
Brannfred.AddToHistory(self.entry)
if not action.keepOpen then frame:Hide() end
action.func()
return
end
end
local primaryAction = getContextActionForModifier(self.entry, "primary")
Brannfred.AddToHistory(self.entry)
if primaryAction and primaryAction ~= CTX_DISABLED then
if not primaryAction.keepOpen then frame:Hide() end
primaryAction.func()
else
frame:Hide()
end
end)
row:RegisterForDrag("LeftButton")
row:SetScript("OnDragStart", function(self)
if self.entry and self.entry.onDrag then
Brannfred.AddToHistory(self.entry)
self.entry.onDrag()
local p = Brannfred.db and Brannfred.db.profile
local key = "closeOnDrag_" .. (self.entry.type or "")
if not p or p[key] ~= false then
frame:Hide()
end
end
end)
rows[i] = row
end
-- ── Context Menu ──────────────────────────────────────────────────────────────
local ctxFrame = CreateFrame("Frame", "BrannfredCtxFrame", frame, "BackdropTemplate")
ctxFrame:SetWidth(CTX_WIDTH)
ctxFrame:SetFrameStrata("HIGH")
applyBackdrop(ctxFrame)
local ctxBg = ctxFrame:CreateTexture(nil, "BACKGROUND")
ctxBg:SetColorTexture(0.07, 0.07, 0.07, 0.93)
ctxBg:SetPoint("TOPLEFT", ctxFrame, "TOPLEFT", 1, -1)
ctxBg:SetPoint("BOTTOMRIGHT", ctxFrame, "BOTTOMRIGHT", -1, 1)
ctxFrame:Hide()
local ctxHeader = ctxFrame:CreateFontString(nil, "OVERLAY")
ctxHeader:SetFont(main_font, 11, "")
ctxHeader:SetTextColor(0.55, 0.55, 0.55, 1)
ctxHeader:SetPoint("TOPLEFT", ctxFrame, "TOPLEFT", 8, -8)
ctxHeader:SetPoint("TOPRIGHT", ctxFrame, "TOPRIGHT", -8, -8)
ctxHeader:SetHeight(CTX_HEADER_H - 10)
ctxHeader:SetJustifyH("LEFT")
ctxHeader:SetWordWrap(false)
local ctxSep = ctxFrame:CreateTexture(nil, "BACKGROUND")
ctxSep:SetHeight(1)
ctxSep:SetColorTexture(0.3, 0.3, 0.3, 1)
ctxSep:SetPoint("TOPLEFT", ctxFrame, "TOPLEFT", 1, -CTX_HEADER_H)
ctxSep:SetPoint("TOPRIGHT", ctxFrame, "TOPRIGHT", -1, -CTX_HEADER_H)
local ctxRows = {}
for i = 1, MAX_CTX_ROWS do
local row = CreateFrame("Button", nil, ctxFrame)
row:SetHeight(CTX_ROW_HEIGHT)
row:SetPoint("TOPLEFT", ctxFrame, "TOPLEFT", 1, -(CTX_HEADER_H + 1 + (i - 1) * CTX_ROW_HEIGHT))
row:SetPoint("TOPRIGHT", ctxFrame, "TOPRIGHT", -1, -(CTX_HEADER_H + 1 + (i - 1) * CTX_ROW_HEIGHT))
local sel = row:CreateTexture(nil, "BACKGROUND")
sel:SetAllPoints()
sel:SetColorTexture(0.2, 0.6, 1, 0.18)
sel:Hide()
row.selTex = sel
local numText = row:CreateFontString(nil, "OVERLAY")
numText:SetFont(main_font, 10, "")
numText:SetTextColor(0.45, 0.45, 0.45, 1)
numText:SetPoint("LEFT", row, "LEFT", 6, 0)
numText:SetWidth(14)
numText:SetJustifyH("LEFT")
numText:SetText(i < MAX_CTX_ROWS and tostring(i) or "0")
row.numText = numText
local hintText = row:CreateFontString(nil, "OVERLAY")
hintText:SetFont(main_font, 10, "")
hintText:SetTextColor(0.45, 0.45, 0.45, 1)
hintText:SetPoint("RIGHT", row, "RIGHT", -6, 0)
hintText:SetWidth(30)
hintText:SetJustifyH("RIGHT")
row.hintText = hintText
local text = row:CreateFontString(nil, "OVERLAY")
text:SetFont(main_font, 12, "")
text:SetTextColor(0.9, 0.9, 0.9, 1)
text:SetPoint("LEFT", numText, "RIGHT", 4, 0)
text:SetPoint("RIGHT", hintText, "LEFT", -4, 0)
text:SetJustifyH("LEFT")
row.text = text
local idx = i
row:SetScript("OnEnter", function() selectCtxRow(idx) end)
row:RegisterForClicks("LeftButtonUp")
row:SetScript("OnClick", function() activateCtxAction(idx) end)
ctxRows[i] = row
end
-- ── Context menu functions ────────────────────────────────────────────────────
getContextActionForModifier = function(entry, modifier)
if not entry or not entry.context_actions then return nil end
local providerType = entry._originalType or entry.type
local key = "provmod_" .. providerType .. "_" .. modifier
local saved = Brannfred.db and Brannfred.db.profile[key]
-- Explicit "none" = user disabled this modifier; skip built-in fallback too.
if saved == "none" then return CTX_DISABLED end
-- Ignore legacy "default" sentinel from old saves.
local overrideName = (saved and saved ~= "default") and saved or nil
if overrideName then
for _, action in ipairs(entry.context_actions) do
if action.name == overrideName then return action end
end
end
-- Search for action with matching modifier (including "primary")
for _, action in ipairs(entry.context_actions) do
if action.modifier == modifier then return action end
end
return nil
end
selectCtxRow = function(index)
ctxSelectedIdx = index
for i = 1, MAX_CTX_ROWS do
ctxRows[i].selTex:SetShown(i == index)
end
end
activateCtxAction = function(index)
local action = ctxActions[index]
if not action then return end
local entry = ctxEntry
local keepOpen = action.keepOpen
Brannfred.AddToHistory(entry)
closeContextMenu()
if not keepOpen then frame:Hide() end
action.func()
end
openContextMenu = function(entry)
if not entry then return end
-- Use context_actions from the entry; all entries must have context_actions
local actions = entry.context_actions
if not actions or #actions == 0 then
return
end
ctxMenuOpen = true
ctxEntry = entry
ctxActions = actions
ctxSelectedIdx = 1
local providerType = entry._originalType or entry.type
-- Build actionName → modifier hint string (user overrides take priority)
local HINTS = { primary = "[En]", shift = "[Sh]", ctrl = "[Ct]", alt = "[Al]" }
local hintMap = {}
local profile = Brannfred.db and Brannfred.db.profile
for _, mod in ipairs({ "primary", "shift", "ctrl", "alt" }) do
local overrideName = profile and profile["provmod_" .. providerType .. "_" .. mod]
if overrideName and overrideName ~= "default" and HINTS[mod] then
hintMap[overrideName] = HINTS[mod]
end
end
-- Show [En] hint for the primary action (first context_action)
if #actions > 0 then
hintMap[actions[1].name] = "[En]"
end
for _, action in ipairs(actions) do
if action.modifier and HINTS[action.modifier] and not hintMap[action.name] then
local overrideName = profile and profile["provmod_" .. providerType .. "_" .. action.modifier]
if not overrideName or overrideName == "default" then
hintMap[action.name] = HINTS[action.modifier]
end
end
end
ctxHeader:SetText(asText(entry.name))
local count = math.min(#ctxActions, MAX_CTX_ROWS)
for i = 1, MAX_CTX_ROWS do
local action = ctxActions[i]
if action then
ctxRows[i].text:SetText(asText(action.name))
ctxRows[i].hintText:SetText(hintMap[action.name] or "")
ctxRows[i].selTex:Hide()
ctxRows[i]:Show()
else
ctxRows[i]:Hide()
end
end
ctxFrame:SetHeight(CTX_HEADER_H + 1 + count * CTX_ROW_HEIGHT + 2)
ctxFrame:ClearAllPoints()
ctxFrame:SetPoint("TOPLEFT", resultsFrame, "TOPRIGHT", 2, 0)
ctxFrame:Show()
selectCtxRow(1)
end
closeContextMenu = function()
ctxMenuOpen = false
ctxEntry = nil
ctxActions = {}
ctxFrame:Hide()
end
-- ── showDescription ───────────────────────────────────────────────────────────
showDescription = function(entry)
if not entry or entry._noPreview then
descFrame:Hide()
descEntry = nil
return
end
descEntry = entry
descIcon:SetTexture(entry.icon)
local dic = entry.iconColor
descIcon:SetVertexColor(dic and dic.r or 1, dic and dic.g or 1, dic and dic.b or 1)
descName:SetText(asText(entry.name))
local nc = entry.color
descName:SetTextColor(nc and nc.r or 1, nc and nc.g or 0.82, nc and nc.b or 0, 1)
local statsStr = asText(entry.getStats and entry.getStats() or "")
descStats:SetText(statsStr)
descStats:SetShown(statsStr ~= "")
local desc = asText(entry.getDesc and entry.getDesc() or "")
if desc ~= "" then
descText:SetText(desc)
local descH = descText:GetStringHeight()
descFrame:SetHeight(CONTENT_PAD * 2 + 68 + descH + 8)
sep:Show()
descText:Show()
else
descFrame:SetHeight(CONTENT_PAD * 2 + 60)
sep:Hide()
descText:Hide()
end
descFrame:Show()
end
-- ── selectRow ─────────────────────────────────────────────────────────────────
selectRow = function(index)
selectedIndex = index
for i = 1, MAX_RESULTS do
rows[i].selTex:SetShown(i == index)
end
local rowTop = (index - 1) * ROW_HEIGHT
local rowBottom = index * ROW_HEIGHT
local cur = scrollFrame:GetVerticalScroll()
local visH = VISIBLE_ROWS * ROW_HEIGHT
if rowTop < cur then
scrollFrame:SetVerticalScroll(rowTop)
elseif rowBottom > cur + visH then
scrollFrame:SetVerticalScroll(rowBottom - visH)
end
updateScrollBar()
if currentResults[index] then
showDescription(currentResults[index].entry)
else
descFrame:Hide()
end
end
-- ── updateResults ─────────────────────────────────────────────────────────────
local function updateResults(query)
closeContextMenu()
for i = 1, MAX_RESULTS do rows[i]:Hide() end
if query:match("^%s*$") then
currentResults = {}
resultsFrame:Hide()
descFrame:Hide()
return
end
currentResults = Brannfred.Search(query, MAX_RESULTS)
local count = #currentResults
if count == 0 then
resultsFrame:Hide()
descFrame:Hide()
return
end
for i = 1, count do
local entry = currentResults[i].entry
local c = entry.color
rows[i].entry = entry
rows[i].icon:SetTexture(entry.icon)
local ic = entry.iconColor
rows[i].icon:SetVertexColor(ic and ic.r or 1, ic and ic.g or 1, ic and ic.b or 1)
rows[i].text:SetText(asText(entry.name))
rows[i].text:SetTextColor(c and c.r or 0.95, c and c.g or 0.95, c and c.b or 0.95, 1)
rows[i].typeLabel:SetText(getTypeLabel(entry._originalType or entry.type))
rows[i].typeLabel:SetWidth(rows[i].typeLabel:GetStringWidth() + 4)
local lc = entry.labelColor
rows[i].typeLabel:SetTextColor(lc and lc.r or 0.45, lc and lc.g or 0.45, lc and lc.b or 0.45, 1)
rows[i].metaLabel:SetText(asText(entry.getMeta and entry.getMeta() or ""))
rows[i]:Show()
end
local vis = math.min(count, VISIBLE_ROWS)
scrollChild:SetHeight(count * ROW_HEIGHT)
scrollFrame:SetVerticalScroll(0)
resultsFrame:SetHeight(vis * ROW_HEIGHT + 2)
resultsFrame:Show()
selectRow(1)
end
-- ── EditBox scripts ───────────────────────────────────────────────────────────
-- ── Placeholder ───────────────────────────────────────────────────────────────
local placeholder = frame:CreateFontString(nil, "OVERLAY")
placeholder:SetFont(main_font, 15, "")
placeholder:SetTextColor(0.45, 0.45, 0.45, 1)
placeholder:SetText(L["Search..."])
placeholder:SetPoint("LEFT", editBox, "LEFT", 0, 0)
placeholder:SetJustifyH("LEFT")
editBox:SetScript("OnTextChanged", function(self)
placeholder:SetShown(self:GetText() == "")
updateResults(self:GetText())
end)
editBox:SetScript("OnKeyDown", function(self, key)
-- ── Context menu mode ────────────────────────────────────────────────────
if ctxMenuOpen then
self:SetPropagateKeyboardInput(false)
if key == "ESCAPE" or key == "TAB" then
closeContextMenu()
elseif key == "UP" then
local count = math.min(#ctxActions, MAX_CTX_ROWS)
selectCtxRow(ctxSelectedIdx > 1 and ctxSelectedIdx - 1 or count)
elseif key == "DOWN" then
local count = math.min(#ctxActions, MAX_CTX_ROWS)
selectCtxRow(ctxSelectedIdx < count and ctxSelectedIdx + 1 or 1)
elseif key == "ENTER" then
activateCtxAction(ctxSelectedIdx)
else
local numStr = key:match("^(%d)$")
if numStr then
local num = tonumber(numStr)
local idx = num == 0 and MAX_CTX_ROWS or num
if ctxActions[idx] then activateCtxAction(idx) end
end
end
return
end
-- ── Normal mode ──────────────────────────────────────────────────────────
if key == "ENTER" then
local selected = currentResults[selectedIndex]
if selected then
local entry = selected.entry
if entry._insertText then
editBox:SetText(entry._insertText)
editBox:SetFocus()
self:SetPropagateKeyboardInput(false)
return
end
if IsShiftKeyDown() then
local action = getContextActionForModifier(entry, "shift")
if action and action ~= CTX_DISABLED then
Brannfred.AddToHistory(entry)
if not action.keepOpen then frame:Hide() end
action.func()
self:SetPropagateKeyboardInput(false)
return
end
end
if IsControlKeyDown() then
local action = getContextActionForModifier(entry, "ctrl")
if action and action ~= CTX_DISABLED then
Brannfred.AddToHistory(entry)
if not action.keepOpen then frame:Hide() end
action.func()
self:SetPropagateKeyboardInput(false)
return
end
end
if IsAltKeyDown() then
local action = getContextActionForModifier(entry, "alt")
if action and action ~= CTX_DISABLED then
Brannfred.AddToHistory(entry)
if not action.keepOpen then frame:Hide() end
action.func()
self:SetPropagateKeyboardInput(false)
return
end
end
local primaryAction = getContextActionForModifier(entry, "primary")
Brannfred.AddToHistory(entry)
if primaryAction and primaryAction ~= CTX_DISABLED then
if not primaryAction.keepOpen then frame:Hide() end
primaryAction.func()
else
frame:Hide()
end
else
frame:Hide()
end
self:SetPropagateKeyboardInput(false)
return
end
-- Tab opens the context menu for the currently selected result
if key == "TAB" and resultsFrame:IsShown() and #currentResults > 0 then
local selected = currentResults[selectedIndex]
if selected then
openContextMenu(selected.entry)
end
self:SetPropagateKeyboardInput(false)
return
end
if resultsFrame:IsShown() then
if key == "UP" then
local count = math.min(#currentResults, MAX_RESULTS)
selectRow(selectedIndex > 1 and selectedIndex - 1 or count)
self:SetPropagateKeyboardInput(false)
return
elseif key == "DOWN" then
local count = math.min(#currentResults, MAX_RESULTS)
selectRow(selectedIndex < count and selectedIndex + 1 or 1)
self:SetPropagateKeyboardInput(false)
return
end
end
local mod = (IsShiftKeyDown() and "SHIFT-" or "")
.. (IsControlKeyDown() and "CTRL-" or "")
.. (IsAltKeyDown() and "ALT-" or "")
local action = GetBindingAction(mod .. key)
self:SetPropagateKeyboardInput(action == "CLICK BrannfredToggleButton:LeftButton")
end)
editBox:SetScript("OnEscapePressed", function()
if ctxMenuOpen then
closeContextMenu()
else
frame:Hide()
end
end)
editBox:EnableMouseWheel(true)
editBox:SetScript("OnMouseWheel", function(_, delta)
if resultsFrame:IsShown() then
local cur = scrollFrame:GetVerticalScroll()
local max = scrollFrame:GetVerticalScrollRange()
scrollFrame:SetVerticalScroll(math.max(0, math.min(max, cur - delta * ROW_HEIGHT)))
updateScrollBar()
end
end)
frame:SetScript("OnHide", function()
closeContextMenu()
resultsFrame:Hide()
descFrame:Hide()
scrollFrame:SetVerticalScroll(0)
editBox:SetText("")
editBox:ClearFocus()
end)
-- Visual inset ratio per border texture: fraction of edgeSize that is actually
-- opaque border pixels. Used to position the bg texture so it meets the visible
-- inner edge of the border (and not the transparent inner area of the 9-slice).
local TEXTURE_INSET_RATIO = {
["Interface/Buttons/WHITE8X8"] = 1.0, -- solid: full edgeSize
["Interface/Tooltips/UI-Tooltip-Border"] = 5 / 16, -- native inset=5, size=16
["Interface/DialogFrame/UI-DialogBox-Border"] = 11 / 32, -- native inset=11, size=32
["Interface/DialogFrame/UI-DialogBox-Gold-Border"] = 11 / 32,
["Interface/FriendsFrame/UI-Toast-Border"] = 4 / 12, -- native inset=4, size=12
}
local function bgInset(btex, bs)
if bs == 0 or btex == "none" then return 0 end
local r = TEXTURE_INSET_RATIO[btex] or (1 / 3)
return (r == 1.0) and bs or math.max(1, math.ceil(bs * r))
end
-- ── ApplyFrameSettings ────────────────────────────────────────────────────────
-- Called from Core.lua:OnEnable and whenever appearance/position options change.
-- Has full closure access to all local frame variables.
function Brannfred.ApplyFrameSettings() ---@diagnostic disable-line: duplicate-set-field
if not Brannfred.db then return end
local p = Brannfred.db.profile or {}
local w = p.frameWidth or 420
local fpath = LSM:Fetch("font", p.fontPath) or "fonts/frizqt__.ttf"
local fsize = p.fontSize or 13
-- Width (results/desc follow the main frame width)
frame:SetWidth(w)
resultsFrame:SetWidth(w)
descFrame:SetWidth(w)
editBox:SetWidth(w - 30)
-- Fonts
editBox:SetFont(fpath, fsize + 2, "")
placeholder:SetFont(fpath, fsize + 2, "")
for _, row in ipairs(rows) do
row.text:SetFont(fpath, fsize, "")
row.typeLabel:SetFont(fpath, math.max(6, fsize - 3), "")
row.metaLabel:SetFont(fpath, math.max(6, fsize - 2), "")
end
descName:SetFont(fpath, fsize + 1, "OUTLINE")
descStats:SetFont(fpath, math.max(6, fsize - 2), "")
descText:SetFont(fpath, math.max(6, fsize - 1), "")
-- Context menu fonts
ctxHeader:SetFont(fpath, math.max(6, fsize - 2), "")
for _, row in ipairs(ctxRows) do
row.text:SetFont(fpath, fsize, "")
row.numText:SetFont(fpath, math.max(6, fsize - 3), "")
row.hintText:SetFont(fpath, math.max(6, fsize - 3), "")
end
-- Visible rows + content padding
VISIBLE_ROWS = p.visibleRows or 10
CONTENT_PAD = p.contentPadding or (p.borderSize or 1)
local cp = CONTENT_PAD
-- Border
local bs = p.borderSize or 1
local btex = LSM:Fetch("border", p.borderTexture) or "Interface/Buttons/WHITE8X8"
local edgeFile = (bs == 0) and "" or btex
local bd = { edgeFile = edgeFile, edgeSize = bs }
local bgr, bgg, bgb, bga = p.bgR or 0.07, p.bgG or 0.07, p.bgB or 0.07, p.bgA or 0.93
local bdr, bdg, bdb, bda = p.borderR or 0.25, p.borderG or 0.25, p.borderB or 0.25, p.borderA or 1.0
-- Background textures: inset by the VISUAL border width (not full edgeSize)
-- so the bg meets the visible inner edge of the border without a gap.
local bgi = bgInset(btex, bs)
for _, bg in ipairs({ frameBg, resultsBg, descBg, ctxBg }) do
bg:ClearAllPoints()
bg:SetPoint("TOPLEFT", bg:GetParent(), "TOPLEFT", bgi, -bgi)
bg:SetPoint("BOTTOMRIGHT", bg:GetParent(), "BOTTOMRIGHT", -bgi, bgi)
bg:SetColorTexture(bgr, bgg, bgb, bga)
end
for _, f in ipairs({ frame, resultsFrame, descFrame, ctxFrame }) do
f:SetBackdrop(bd)
f:SetBackdropBorderColor(bdr, bdg, bdb, bda)
end
-- scrollFrame + scrollbar: inset by content padding
scrollFrame:ClearAllPoints()
scrollFrame:SetPoint("TOPLEFT", resultsFrame, "TOPLEFT", cp, -cp)
scrollFrame:SetPoint("BOTTOMRIGHT", resultsFrame, "BOTTOMRIGHT", -(cp + 4), cp)
scrollChild:SetWidth(w - cp * 2 - 4)
sbTrack:ClearAllPoints()
sbTrack:SetPoint("TOPRIGHT", resultsFrame, "TOPRIGHT", -cp, -cp)
sbTrack:SetPoint("BOTTOMRIGHT", resultsFrame, "BOTTOMRIGHT", -cp, cp)
-- Description panel elements: reanchor to content padding
-- Icon gets 6 px of extra inset on all sides for visual breathing room.
local ii = 6 -- icon inset
descIconBtn:ClearAllPoints()
descIconBtn:SetPoint("TOPLEFT", descFrame, "TOPLEFT", cp + ii, -(cp + ii))
descName:ClearAllPoints()
descName:SetPoint("TOPLEFT", descFrame, "TOPLEFT", cp + ii + 48 + 8, -(cp + ii))
descName:SetPoint("TOPRIGHT", descFrame, "TOPRIGHT", -cp, -(cp + ii))
descStats:ClearAllPoints()
descStats:SetPoint("TOPLEFT", descFrame, "TOPLEFT", cp + ii + 48 + 8, -(cp + ii + 18))
descStats:SetPoint("TOPRIGHT", descFrame, "TOPRIGHT", -cp, -(cp + ii + 18))
descStats:SetWidth(w - cp * 2 - ii - 48 - 8)
sep:ClearAllPoints()
sep:SetPoint("TOPLEFT", descFrame, "TOPLEFT", cp, -(cp + ii + 48 + ii))
sep:SetPoint("TOPRIGHT", descFrame, "TOPRIGHT", -cp, -(cp + ii + 48 + ii))
descText:ClearAllPoints()
descText:SetPoint("TOPLEFT", descFrame, "TOPLEFT", cp + ii, -(cp + ii + 48 + ii + 8))
descText:SetPoint("TOPRIGHT", descFrame, "TOPRIGHT", -(cp + ii), -(cp + ii + 48 + ii + 8))
descText:SetWidth(w - (cp + ii) * 2)
-- Masque icon skins (optional)
if MSQ and p.useMasque then
if not masqueGroup then
masqueGroup = MSQ:Group("Brannfred", "Icons")
masqueGroup:AddButton(descIconBtn, { Icon = descIcon })
for _, row in ipairs(rows) do
masqueGroup:AddButton(row.iconBtn, { Icon = row.icon })
end
end
masqueGroup:ReSkin()
else
if masqueGroup then
masqueGroup:Delete()
masqueGroup = nil
descIcon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
for _, row in ipairs(rows) do
row.icon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
end
end
end
end