Repository navigation
Expand file tree
/
Copy pathKeybindAuditUI.lua
More file actions
1539 lines (1375 loc) · 60.2 KB
/
Copy pathKeybindAuditUI.lua
File metadata and controls
1539 lines (1375 loc) · 60.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local ADDON_NAME, ns = ...
local KeybindAuditUI = {}
ns.KeybindAuditUI = KeybindAuditUI
local Utils = ns.Utils
local sformat = Utils.sformat
local mfloor = Utils.mfloor
local mmin, mmax = Utils.mmin, Utils.mmax
local ipairs = Utils.ipairs
local pairs = Utils.pairs
local tinsert = Utils.tinsert
local CreateFrame = Utils.CreateFrame
local PlayUISound = Utils.PlayUISound
local SOUND_CLICK = Utils.SOUND_CLICK
local UIParent = UIParent
local BAR_FRAME_MAP = {
{ key = "main", label = "Action Bar 1", prefix = "ActionButton", barFrame = "MainMenuBar" },
{ key = "bottomLeft", label = "Action Bar 2", prefix = "MultiBarBottomLeftButton", barFrame = "MultiBarBottomLeft" },
{ key = "bottomRight", label = "Action Bar 3", prefix = "MultiBarBottomRightButton", barFrame = "MultiBarBottomRight" },
{ key = "right", label = "Action Bar 4", prefix = "MultiBarRightButton", barFrame = "MultiBarRight" },
{ key = "left", label = "Action Bar 5", prefix = "MultiBarLeftButton", barFrame = "MultiBarLeft" },
{ key = "bar6", label = "Action Bar 6", prefix = "MultiBar5Button", barFrame = "MultiBar5" },
{ key = "bar7", label = "Action Bar 7", prefix = "MultiBar6Button", barFrame = "MultiBar6" },
{ key = "bar8", label = "Action Bar 8", prefix = "MultiBar7Button", barFrame = "MultiBar7" },
}
local ISSUE_ROW_HEIGHT = 36
local SEVERITY_COLORS = {
high = { 0.8, 0.2, 0.2 },
medium = { 0.8, 0.6, 0.2 },
low = { 0.6, 0.6, 0.3 },
}
local auditFrame, dimmer
local setupPage, resultsPage, methodologyPage, categoryDetailPage, uniqueBindsPanel
local barOverlays = {}
local barToggles = {}
local lastResults
local gradeText, scoreText, summaryText
local categoryBars = {}
local barSummaryLabels = {}
local issueRows = {}
local issueContainer, issueScrollChild
local function GetBarColor(score)
if score >= 90 then return 0.2, 0.8, 0.2 end
if score >= 70 then return 0.8, 0.8, 0.2 end
if score >= 50 then return 0.8, 0.6, 0.2 end
return 0.6, 0.3, 0.3
end
local function GetDb()
return BoundToLearn.db.audit
end
local function LoadBarToggles()
local db = GetDb()
-- Always sync with actual bar visibility
for _, barDef in ipairs(BAR_FRAME_MAP) do
local visible = ns.KeybindAudit.IsBarVisible(barDef.prefix)
db.bars[barDef.key] = visible
barToggles[barDef.key] = visible
end
end
local function SaveBarToggles()
local db = GetDb()
for key, val in pairs(barToggles) do
db.bars[key] = val
end
end
local function UpdateBarOverlay(overlay, included)
local word = included and "Included" or "Excluded"
overlay.label:SetText(overlay.barLabel .. " (" .. word .. ")")
if included then
overlay.bg:SetColorTexture(0.1, 0.6, 0.1, 0.25)
overlay.border:SetColorTexture(0.2, 0.8, 0.2, 0.8)
overlay.label:SetTextColor(0.3, 1.0, 0.3)
else
overlay.bg:SetColorTexture(0.4, 0.1, 0.1, 0.25)
overlay.border:SetColorTexture(0.6, 0.2, 0.2, 0.6)
overlay.label:SetTextColor(0.8, 0.4, 0.4)
end
end
local function FindLastVisibleButton(prefix)
for i = 12, 1, -1 do
local btn = _G[prefix .. i]
if btn and btn:IsVisible() then return btn end
end
return nil
end
local function PositionOverlay(overlay, barDef)
overlay:ClearAllPoints()
local btn1 = _G[barDef.prefix .. "1"]
local lastBtn = FindLastVisibleButton(barDef.prefix)
if btn1 and lastBtn then
overlay:SetPoint("TOPLEFT", btn1, "TOPLEFT", -6, 6)
overlay:SetPoint("BOTTOMRIGHT", lastBtn, "BOTTOMRIGHT", 6, -6)
end
end
local function CreateBarOverlay(barDef)
local btn1 = _G[barDef.prefix .. "1"]
if not btn1 then return nil end
local overlay = CreateFrame("Button", nil, UIParent)
overlay:SetFrameStrata("FULLSCREEN_DIALOG")
overlay:SetFrameLevel(10)
local bg = overlay:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetColorTexture(0.1, 0.6, 0.1, 0.25)
overlay.bg = bg
local border = overlay:CreateTexture(nil, "BORDER")
border:SetPoint("TOPLEFT", 0, 0)
border:SetPoint("TOPRIGHT", 0, 0)
border:SetHeight(2)
border:SetColorTexture(0.2, 0.8, 0.2, 0.8)
overlay.border = border
local label = overlay:CreateFontString(nil, "OVERLAY")
label:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
label:SetPoint("CENTER", 0, 6)
label:SetText(barDef.label)
overlay.label = label
overlay.barLabel = barDef.label
local hint = overlay:CreateFontString(nil, "OVERLAY")
hint:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
hint:SetPoint("CENTER", 0, -8)
hint:SetText("Click to toggle")
hint:SetTextColor(0.7, 0.7, 0.7)
overlay.hint = hint
overlay.barKey = barDef.key
overlay:SetScript("OnClick", function(self)
PlayUISound(SOUND_CLICK)
barToggles[self.barKey] = not barToggles[self.barKey]
UpdateBarOverlay(self, barToggles[self.barKey])
SaveBarToggles()
-- Sync setup page checkboxes
if setupPage and setupPage.barCheckboxes then
local cb = setupPage.barCheckboxes[self.barKey]
if cb then cb:SetChecked(barToggles[self.barKey]) end
end
end)
overlay:Hide()
return overlay
end
local function CreateScoreBar(parent, label, yOffset, categoryIndex)
local row = CreateFrame("Button", nil, parent)
row:SetSize(240, 18)
row:SetPoint("TOPLEFT", 20, yOffset)
local highlight = row:CreateTexture(nil, "HIGHLIGHT")
highlight:SetAllPoints()
highlight:SetColorTexture(1, 1, 1, 0.08)
local lbl = row:CreateFontString(nil, "OVERLAY")
lbl:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
lbl:SetPoint("LEFT", 0, 0)
lbl:SetWidth(95)
lbl:SetJustifyH("LEFT")
lbl:SetTextColor(0.8, 0.8, 0.8)
lbl:SetText(label)
row.label = lbl
local bg = row:CreateTexture(nil, "BACKGROUND")
bg:SetPoint("LEFT", 100, 0)
bg:SetSize(110, 12)
bg:SetColorTexture(ns.Theme.RGB(ns.Theme.C.PANEL_DARK))
row.bg = bg
local fill = row:CreateTexture(nil, "ARTWORK")
fill:SetPoint("LEFT", 100, 0)
fill:SetSize(110, 12)
fill:SetColorTexture(0.2, 0.8, 0.2, 1)
row.fill = fill
local val = row:CreateFontString(nil, "OVERLAY")
val:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
val:SetPoint("LEFT", 218, 0)
val:SetTextColor(0.9, 0.9, 0.9)
row.value = val
row:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
KeybindAuditUI:ShowCategoryDetail(categoryIndex)
end)
return row
end
local function SetScoreBar(bar, score)
local clamped = mmax(0, mmin(100, score))
bar.fill:SetWidth(mmax(1, 110 * clamped / 100))
local r, g, b = GetBarColor(score)
bar.fill:SetColorTexture(r, g, b, 1)
bar.fill:Show()
bar.value:SetTextColor(0.9, 0.9, 0.9)
bar.value:SetText(tostring(mfloor(score)))
end
-- Grouping can't be scored without at least one role holding two bound abilities.
-- Show N/A rather than a bare 0 (which reads as a failing grade); the reason lands
-- in the recommendations list.
local function SetScoreBarNA(bar)
bar.fill:Hide()
bar.value:SetTextColor(0.5, 0.5, 0.5)
bar.value:SetText("N/A")
end
local function CreateIssueRow(parent, index)
local row = CreateFrame("Frame", nil, parent)
row:SetSize(250, ISSUE_ROW_HEIGHT)
row:SetPoint("TOPLEFT", 0, -(index - 1) * ISSUE_ROW_HEIGHT)
local strip = row:CreateTexture(nil, "ARTWORK")
strip:SetSize(3, ISSUE_ROW_HEIGHT - 4)
strip:SetPoint("LEFT", 0, 0)
strip:SetColorTexture(0.8, 0.6, 0.2, 1)
row.strip = strip
local icon = row:CreateTexture(nil, "ARTWORK")
icon:SetSize(20, 20)
icon:SetPoint("LEFT", 8, 0)
icon:SetTexCoord(0.07, 0.93, 0.07, 0.93)
icon:Hide()
row.icon = icon
local text = row:CreateFontString(nil, "OVERLAY")
text:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
text:SetPoint("TOPLEFT", 34, -3)
text:SetWidth(210)
text:SetJustifyH("LEFT")
text:SetTextColor(0.9, 0.9, 0.9)
row.text = text
-- Under the text, so a recommendation that wraps pushes it down.
local detail = row:CreateFontString(nil, "OVERLAY")
detail:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
detail:SetPoint("TOPLEFT", text, "BOTTOMLEFT", 0, -3)
detail:SetWidth(210)
detail:SetJustifyH("LEFT")
detail:SetTextColor(0.6, 0.6, 0.6)
row.detail = detail
row:Hide()
return row
end
local function CreateCheckbox(parent, label, yOffset, onClick)
local cb = ns.Theme.CreateToggle(parent, label, nil, 130)
cb:SetPoint("TOPLEFT", 20, yOffset)
cb.label = cb.Text
cb:SetScript("OnClick", function(self)
PlayUISound(SOUND_CLICK)
if onClick then onClick(self:GetChecked()) end
end)
return cb
end
function KeybindAuditUI:CreateFrame()
if auditFrame then return end
-- Dimmer
dimmer = CreateFrame("Frame", nil, UIParent)
dimmer:SetAllPoints(UIParent)
dimmer:SetFrameStrata("FULLSCREEN")
dimmer:EnableMouse(false)
local dimBg = dimmer:CreateTexture(nil, "BACKGROUND")
dimBg:SetAllPoints()
dimBg:SetColorTexture(0, 0, 0, 0.6)
dimmer:Hide()
-- Bar overlays
for _, barDef in ipairs(BAR_FRAME_MAP) do
barOverlays[barDef.key] = CreateBarOverlay(barDef)
end
-- Main frame
auditFrame = CreateFrame("Frame", "BoundToLearnAuditFrame", UIParent)
auditFrame:SetSize(580, 480)
auditFrame:SetPoint("CENTER")
auditFrame:SetFrameStrata("FULLSCREEN_DIALOG")
auditFrame:SetFrameLevel(20)
ns.Theme.StylePanel(auditFrame)
auditFrame:EnableMouse(true)
auditFrame:SetMovable(true)
auditFrame:RegisterForDrag("LeftButton")
auditFrame:SetClampedToScreen(true)
auditFrame:SetScript("OnDragStart", auditFrame.StartMoving)
auditFrame:SetScript("OnDragStop", auditFrame.StopMovingOrSizing)
auditFrame:SetScript("OnHide", function()
self:HideBarOverlays()
end)
Utils.CloseOnEscape(auditFrame)
local close = ns.Theme.CreateCloseButton(auditFrame, function() auditFrame:Hide() end)
close:SetPoint("TOPRIGHT", -8, -8)
-- Title
local title = ns.Theme.CreateTitle(auditFrame, "Keybind Audit", 16)
title:SetPoint("TOP", 0, -12)
-- Header, left of the close button.
local feedbackBtn = ns.Feedback.CreateButton(auditFrame, function()
local page = (resultsPage and resultsPage:IsShown() and "results")
or (methodologyPage and methodologyPage:IsShown() and "methodology")
or (categoryDetailPage and categoryDetailPage:IsShown() and "category detail")
or "setup"
local db = GetDb()
local bars = {}
for key, on in pairs(db.bars or {}) do
if on then bars[#bars + 1] = key end
end
table.sort(bars)
return "Keybind Audit", {
"Page: " .. page,
sformat("Keyboard: %s, MMO mouse: %s, grouping: %s", tostring(db.keyboardLayout),
tostring(db.mmoMouse), tostring(db.includeGrouping)),
"Bars: " .. (#bars > 0 and table.concat(bars, ", ") or "none"),
}
end)
ns.Feedback.PlaceBesideClose(feedbackBtn, close)
-- Back, top left on the title row (mirrors Give feedback): one level up.
-- Hidden on setup, the first page.
local backBtn = ns.Theme.CreateButton(auditFrame, "Back", 70, 22)
backBtn:SetPoint("TOPLEFT", 14, -12)
backBtn:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
KeybindAuditUI:GoBack()
end)
backBtn:Hide()
auditFrame.backBtn = backBtn
-- The results follow the bars: a keybind or a bar slot changed while they
-- are open re-scans them (once, after the burst of events settles).
local rescanPending = false
auditFrame:RegisterEvent("UPDATE_BINDINGS")
auditFrame:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
auditFrame:SetScript("OnEvent", function()
if rescanPending or not (resultsPage and resultsPage:IsShown()) then return end
rescanPending = true
C_Timer.After(0.3, function()
rescanPending = false
if resultsPage:IsShown() then KeybindAuditUI:RefreshResults() end
end)
end)
-- Divider under the title in the window border's bronze (measured from the
-- Dialog frame's lit metal), with its darker underside.
local accent = auditFrame:CreateTexture(nil, "ARTWORK")
accent:SetPoint("TOP", 0, -34)
accent:SetSize(550, 1)
accent:SetColorTexture(0.55, 0.41, 0.27)
local accentShade = auditFrame:CreateTexture(nil, "ARTWORK")
accentShade:SetPoint("TOP", accent, "BOTTOM")
accentShade:SetSize(550, 1)
accentShade:SetColorTexture(0.30, 0.21, 0.13)
-- Under the divider: the audit is opinion, and its methodology is one click
-- away ("here"). Hidden on the methodology page itself.
local note = CreateFrame("Frame", nil, auditFrame)
note:SetPoint("TOP", accent, "BOTTOM", 0, -3)
note:SetHeight(14)
local noteText = note:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
noteText:SetPoint("LEFT")
noteText:SetText("This is extremely subjective and still heavily a WIP. See current methodology ")
local here = CreateFrame("Button", nil, note)
local hereText = here:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
hereText:SetPoint("LEFT")
hereText:SetText("here")
here:SetFontString(hereText)
here:SetNormalFontObject("GameFontNormalSmall")
here:SetHighlightFontObject("GameFontHighlightSmall")
here:SetSize(hereText:GetStringWidth() + 1, 14)
here:SetPoint("LEFT", noteText, "RIGHT", 0, 0)
here:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
KeybindAuditUI:ToggleMethodology()
end)
local dot = note:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
dot:SetPoint("LEFT", here, "RIGHT", 0, 0)
dot:SetText(".")
note:SetWidth(noteText:GetStringWidth() + here:GetWidth() + dot:GetStringWidth())
auditFrame.methNote = note
self:CreateSetupPage()
self:CreateResultsPage()
self:CreateMethodologyPage()
self:CreateCategoryDetailPage()
resultsPage:Hide()
methodologyPage:Hide()
categoryDetailPage:Hide()
auditFrame:Hide()
end
function KeybindAuditUI:CreateSetupPage()
setupPage = CreateFrame("Frame", nil, auditFrame)
setupPage:SetAllPoints()
local desc = setupPage:CreateFontString(nil, "OVERLAY")
desc:SetFont("Fonts\\FRIZQT__.TTF", 11, "")
desc:SetPoint("TOPLEFT", 25, -58)
desc:SetWidth(530)
desc:SetJustifyH("LEFT")
desc:SetTextColor(0.6, 0.6, 0.6)
desc:SetText("Select which bars to include by clicking them on screen, or use the checkboxes below.")
-- Bar checkboxes (two columns of 4)
local barCheckY = -104
local barCheckboxes = {}
local BARS_PER_COL = 4
for i, barDef in ipairs(BAR_FRAME_MAP) do
local col = (i - 1) < BARS_PER_COL and 0 or 1
local row = (i - 1) % BARS_PER_COL
local cb = CreateCheckbox(setupPage, barDef.label, barCheckY - row * 28, function(checked)
barToggles[barDef.key] = checked
SaveBarToggles()
local overlay = barOverlays[barDef.key]
if overlay and overlay:IsShown() then
UpdateBarOverlay(overlay, checked)
end
KeybindAuditUI:UpdateStartButtonState()
end)
if col == 1 then
cb:ClearAllPoints()
cb:SetPoint("TOPLEFT", 160, barCheckY - row * 28)
end
barCheckboxes[barDef.key] = cb
end
setupPage.barCheckboxes = barCheckboxes
-- Toggle-all button above the bar list.
local toggleAllBtn = ns.Theme.CreateButton(setupPage, "Toggle All", 90, 20)
toggleAllBtn:SetPoint("TOPLEFT", 20, -76)
toggleAllBtn:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
local allOn = true
for _, barDef in ipairs(BAR_FRAME_MAP) do
if not barToggles[barDef.key] then allOn = false; break end
end
KeybindAuditUI:SetAllBars(not allOn)
end)
setupPage.toggleAllBtn = toggleAllBtn
-- Right column options
local optX = 330
local mmoMouseCb = ns.Theme.CreateToggle(setupPage, "I use an MMO mouse (12-button)", nil, 230)
mmoMouseCb:SetPoint("TOPLEFT", optX, -82)
mmoMouseCb:SetScript("OnClick", function(self)
PlayUISound(SOUND_CLICK)
GetDb().mmoMouse = self:GetChecked()
end)
setupPage.mmoMouseCb = mmoMouseCb
local mmoHint = setupPage:CreateFontString(nil, "OVERLAY")
mmoHint:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
mmoHint:SetPoint("TOPLEFT", optX + 30, -108)
mmoHint:SetWidth(200)
mmoHint:SetJustifyH("LEFT")
mmoHint:SetTextColor(0.55, 0.55, 0.55)
mmoHint:SetText("Number keys won't be penalized as distant since they're on your thumb.")
-- FN / other unique binds: declare keys the player physically has on their mouse.
local fnBindsCb = ns.Theme.CreateToggle(setupPage, "I have FN or other unique binds", nil, 230)
fnBindsCb:SetPoint("TOPLEFT", optX, -132)
fnBindsCb:SetScript("OnClick", function(self)
PlayUISound(SOUND_CLICK)
local on = self:GetChecked()
GetDb().hasUniqueBinds = on
if setupPage.setKeysBtn then setupPage.setKeysBtn:SetShown(on) end
end)
setupPage.fnBindsCb = fnBindsCb
local setKeysBtn = ns.Theme.CreateButton(setupPage, "Set unique keys", 130, 20)
setKeysBtn:SetPoint("TOPLEFT", optX + 20, -158)
setKeysBtn:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
KeybindAuditUI:ShowUniqueBindsPanel()
end)
setKeysBtn:Hide()
setupPage.setKeysBtn = setKeysBtn
local skipBarsCb = ns.Theme.CreateToggle(setupPage, "Skip this setup next time", nil, 230)
skipBarsCb:SetPoint("TOPLEFT", optX, -186)
skipBarsCb:SetScript("OnClick", function(self)
PlayUISound(SOUND_CLICK)
GetDb().skipBarSelection = self:GetChecked()
end)
setupPage.skipBarsCb = skipBarsCb
local skipBarsHint = setupPage:CreateFontString(nil, "OVERLAY")
skipBarsHint:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
skipBarsHint:SetPoint("TOPLEFT", optX + 30, -212)
skipBarsHint:SetWidth(200)
skipBarsHint:SetJustifyH("LEFT")
skipBarsHint:SetTextColor(0.55, 0.55, 0.55)
skipBarsHint:SetText("Next time you open the audit, click Settings (bottom-left) to change these options.")
-- Grouping checkbox (experimental)
-- 236 wide ends 14 inside the right border (11).
local groupingCb = ns.Theme.CreateToggle(setupPage, "Include grouping score |cFFFF8800Experimental|r", nil, 236)
groupingCb:SetPoint("TOPLEFT", optX, -242)
groupingCb:SetScript("OnClick", function(self)
PlayUISound(SOUND_CLICK)
GetDb().includeGrouping = self:GetChecked()
end)
setupPage.groupingCb = groupingCb
local groupingHint = setupPage:CreateFontString(nil, "OVERLAY")
groupingHint:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
groupingHint:SetPoint("TOPLEFT", optX + 30, -268)
groupingHint:SetWidth(200)
groupingHint:SetJustifyH("LEFT")
groupingHint:SetTextColor(0.55, 0.55, 0.55)
groupingHint:SetText("Scores whether defensives, CCs, and offensive cooldowns are on nearby keys. Uses SpellData classifications.")
-- Keyboard layout selector (under bar checkboxes)
local layoutLabel = setupPage:CreateFontString(nil, "OVERLAY")
layoutLabel:SetFont("Fonts\\FRIZQT__.TTF", 11, "")
layoutLabel:SetPoint("TOPLEFT", 20, -234)
layoutLabel:SetTextColor(0.8, 0.8, 0.8)
layoutLabel:SetText("Keyboard layout:")
local LAYOUT_OPTIONS = { "QWERTY", "AZERTY", "QWERTZ", "DVORAK" }
local layoutButtons = {}
for i, layoutName in ipairs(LAYOUT_OPTIONS) do
local btn = CreateFrame("Button", nil, setupPage)
btn:SetSize(56, 18)
btn:SetPoint("TOPLEFT", layoutLabel, "BOTTOMLEFT", (i - 1) * 60, -4)
local btnBg = btn:CreateTexture(nil, "BACKGROUND")
btnBg:SetAllPoints()
btn.bg = btnBg
local btnText = btn:CreateFontString(nil, "OVERLAY")
btnText:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
btnText:SetPoint("CENTER")
btnText:SetText(layoutName)
btn.label = btnText
btn.layoutName = layoutName
btn:SetScript("OnClick", function(self)
PlayUISound(SOUND_CLICK)
GetDb().keyboardLayout = self.layoutName
for _, b in ipairs(layoutButtons) do
local selected = b.layoutName == self.layoutName
b.bg:SetColorTexture(selected and 0.2 or 0.1, selected and 0.5 or 0.1, selected and 0.2 or 0.1, selected and 0.5 or 0.3)
b.label:SetTextColor(selected and 0.3 or 0.6, selected and 1.0 or 0.6, selected and 0.3 or 0.6)
end
end)
tinsert(layoutButtons, btn)
end
setupPage.layoutButtons = layoutButtons
-- Run Audit button
local runBtn = ns.Theme.CreateAccentButton(setupPage, "Start Audit", 140, 30)
runBtn:SetPoint("BOTTOM", 0, 20)
runBtn:SetScript("OnClick", function()
if not KeybindAuditUI:AnyBarEnabled() then return end
PlayUISound(SOUND_CLICK)
SaveBarToggles()
KeybindAuditUI:ShowResults()
end)
setupPage.runBtn = runBtn
KeybindAuditUI:UpdateStartButtonState()
end
function KeybindAuditUI:AnyBarEnabled()
for _, barDef in ipairs(BAR_FRAME_MAP) do
if barToggles[barDef.key] then return true end
end
return false
end
function KeybindAuditUI:UpdateStartButtonState()
local runBtn = setupPage and setupPage.runBtn
if not runBtn then return end
local any = self:AnyBarEnabled()
runBtn:SetEnabled(any)
runBtn:SetAlpha(any and 1 or 0.4)
end
function KeybindAuditUI:SetAllBars(on)
for _, barDef in ipairs(BAR_FRAME_MAP) do
barToggles[barDef.key] = on
local cb = setupPage and setupPage.barCheckboxes and setupPage.barCheckboxes[barDef.key]
if cb then cb:SetChecked(on) end
local overlay = barOverlays[barDef.key]
if overlay and overlay:IsShown() then
UpdateBarOverlay(overlay, on)
end
end
SaveBarToggles()
self:UpdateStartButtonState()
end
-- Unique-bind entry: declare keys in unusual spots and where they live, so a key the
-- player keeps on their mouse scores as reachable instead of a far function-row stretch.
local UNIQUE_LOCATIONS = { "mouse", "numpad", "function", "other" }
local UNIQUE_LOC_LABEL = { mouse = "Mouse", numpad = "Numpad", ["function"] = "Fn row", other = "Other" }
local function NextLocation(loc)
for i = 1, #UNIQUE_LOCATIONS do
if UNIQUE_LOCATIONS[i] == loc then
return UNIQUE_LOCATIONS[(i % #UNIQUE_LOCATIONS) + 1]
end
end
return UNIQUE_LOCATIONS[1]
end
local function NormalizeUniqueKey(text)
local key = (text or ""):upper():gsub("%s", "")
if key == "" then return nil end
if key:match("^[A-Z0-9]$") then return nil end -- reject plain single letters/numbers
return key
end
function KeybindAuditUI:RefreshUniqueBinds()
local p = uniqueBindsPanel
if not p then return end
local binds = GetDb().uniqueBinds or {}
local keys = {}
for k in pairs(binds) do keys[#keys + 1] = k end
table.sort(keys)
for i = 1, #p.rows do
local row = p.rows[i]
local key = keys[i]
if key then
row.keyFS:SetText(key)
row.locBtn:SetText(UNIQUE_LOC_LABEL[binds[key]] or binds[key])
row.locBtn.key = key
row.rm.key = key
row:Show()
else
row:Hide()
end
end
p.overflow:SetShown(#keys > #p.rows)
end
function KeybindAuditUI:ShowUniqueBindsPanel()
GetDb().uniqueBinds = GetDb().uniqueBinds or {}
if not uniqueBindsPanel then
local p = CreateFrame("Frame", nil, auditFrame)
p:SetPoint("TOPLEFT", 20, -58)
p:SetPoint("BOTTOMRIGHT", -20, 18)
p:SetFrameStrata("FULLSCREEN_DIALOG")
p:SetFrameLevel(auditFrame:GetFrameLevel() + 20)
ns.Theme.StylePanel(p, 0.98)
p:EnableMouse(true)
local title = p:CreateFontString(nil, "OVERLAY")
title:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
title:SetPoint("TOP", 0, -10)
title:SetText("Unique keys and where they are")
title:SetTextColor(ns.Theme.RGB(ns.Theme.C.ACCENT_BRIGHT))
local hint = p:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
hint:SetPoint("TOP", title, "BOTTOM", 0, -4)
hint:SetWidth(500)
hint:SetJustifyH("CENTER")
hint:SetText("Type a key such as F11 or NUMPAD4 (plain letters and numbers are not allowed), pick where it lives, then Add. Mouse counts as fully reachable; the rest count as a far reach.")
local edit = CreateFrame("EditBox", nil, p, "InputBoxTemplate")
edit:SetSize(120, 20)
edit:SetPoint("TOPLEFT", 40, -70)
edit:SetAutoFocus(false)
p.newLoc = "mouse"
local locBtn = ns.Theme.CreateButton(p, "Mouse", 80, 20)
locBtn:SetPoint("LEFT", edit, "RIGHT", 14, 0)
locBtn:SetScript("OnClick", function()
p.newLoc = NextLocation(p.newLoc)
locBtn:SetText(UNIQUE_LOC_LABEL[p.newLoc])
end)
local addBtn = ns.Theme.CreateAccentButton(p, "Add", 60, 22)
addBtn:SetPoint("LEFT", locBtn, "RIGHT", 14, 0)
local function doAdd()
local key = NormalizeUniqueKey(edit:GetText())
if not key then return end
GetDb().uniqueBinds[key] = p.newLoc
edit:SetText("")
KeybindAuditUI:RefreshUniqueBinds()
end
addBtn:SetScript("OnClick", doAdd)
edit:SetScript("OnEnterPressed", function() doAdd(); edit:ClearFocus() end)
edit:SetScript("OnEscapePressed", function() edit:ClearFocus() end)
p.rows = {}
for i = 1, 8 do
local row = CreateFrame("Frame", nil, p)
row:SetSize(320, 20)
row:SetPoint("TOPLEFT", 40, -100 - (i - 1) * 24)
local keyFS = row:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
keyFS:SetPoint("LEFT", 0, 0)
keyFS:SetWidth(90)
keyFS:SetJustifyH("LEFT")
row.keyFS = keyFS
local rowLoc = ns.Theme.CreateButton(row, "Mouse", 80, 18)
rowLoc:SetPoint("LEFT", 96, 0)
rowLoc:SetScript("OnClick", function(self)
local newLoc = NextLocation(GetDb().uniqueBinds[self.key])
GetDb().uniqueBinds[self.key] = newLoc
self:SetText(UNIQUE_LOC_LABEL[newLoc])
end)
row.locBtn = rowLoc
local rm = ns.Theme.CreateButton(row, "Remove", 70, 18)
rm:SetPoint("LEFT", rowLoc, "RIGHT", 12, 0)
rm:SetScript("OnClick", function(self)
GetDb().uniqueBinds[self.key] = nil
KeybindAuditUI:RefreshUniqueBinds()
end)
row.rm = rm
row:Hide()
p.rows[i] = row
end
local overflow = p:CreateFontString(nil, "OVERLAY", "GameFontDisableSmall")
overflow:SetPoint("TOPLEFT", 40, -100 - 8 * 24)
overflow:SetText("Showing the first 8 keys.")
overflow:Hide()
p.overflow = overflow
local doneBtn = ns.Theme.CreateButton(p, "Done", 90, 24)
doneBtn:SetPoint("BOTTOM", 0, 14)
doneBtn:SetScript("OnClick", function() PlayUISound(SOUND_CLICK); p:Hide() end)
uniqueBindsPanel = p
end
self:RefreshUniqueBinds()
uniqueBindsPanel:Show()
end
function KeybindAuditUI:CreateResultsPage()
resultsPage = CreateFrame("Frame", nil, auditFrame)
resultsPage:SetAllPoints()
-- Left column header
gradeText = resultsPage:CreateFontString(nil, "OVERLAY")
gradeText:SetFont("Fonts\\FRIZQT__.TTF", 38, "OUTLINE")
gradeText:SetPoint("TOP", resultsPage, "TOPLEFT", 140, -60)
scoreText = resultsPage:CreateFontString(nil, "OVERLAY")
scoreText:SetFont("Fonts\\FRIZQT__.TTF", 13, "")
scoreText:SetPoint("TOP", gradeText, "BOTTOM", 0, -4)
scoreText:SetTextColor(0.8, 0.8, 0.8)
summaryText = resultsPage:CreateFontString(nil, "OVERLAY")
summaryText:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
summaryText:SetPoint("TOP", scoreText, "BOTTOM", 0, -6)
summaryText:SetTextColor(0.7, 0.7, 0.7)
summaryText:SetWidth(250)
-- Score bars (clickable for detail drill-down)
local barY = -148
local categories = { "Coverage", "Reachability", "Modifier Usage", "Anti-patterns" }
for i, cat in ipairs(categories) do
categoryBars[i] = CreateScoreBar(resultsPage, cat, barY - (i - 1) * 22, i)
end
-- Grouping bar (5th, shown only when enabled)
categoryBars[5] = CreateScoreBar(resultsPage, "Grouping |cFFFF8A33(Exp)|r", barY - 4 * 22, 5)
ns.Theme.DelayedTooltip(categoryBars[5], function(self)
GameTooltip:SetText("Experimental", ns.Theme.RGB(ns.Theme.C.ACCENT))
GameTooltip:AddLine("This score measures physical key proximity of\nabilities that share a role (defensives, CCs, etc).\n\nSpell classification may not cover all abilities.\nTreat this as a guideline, not a strict score.", 0.7, 0.7, 0.7, true)
end)
categoryBars[5]:Hide()
-- Divider (positioned dynamically based on grouping bar visibility)
local div = resultsPage:CreateTexture(nil, "ARTWORK")
div:SetSize(250, 1)
div:SetPoint("TOPLEFT", 15, -256)
div:SetColorTexture(ns.Theme.RGB(ns.Theme.C.BORDER, 0.35))
resultsPage.divider = div
-- Per-bar summary
for i = 1, 8 do
local lbl = resultsPage:CreateFontString(nil, "OVERLAY")
lbl:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
lbl:SetPoint("TOPLEFT", 20, -264 - (i - 1) * 16)
lbl:SetWidth(250)
lbl:SetJustifyH("LEFT")
lbl:Hide()
barSummaryLabels[i] = lbl
end
-- Skipped macros note
local skippedLabel = resultsPage:CreateFontString(nil, "OVERLAY")
skippedLabel:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
skippedLabel:SetPoint("BOTTOMLEFT", 20, 42)
skippedLabel:SetWidth(250)
skippedLabel:SetJustifyH("LEFT")
skippedLabel:SetTextColor(0.5, 0.5, 0.5)
skippedLabel:Hide()
resultsPage.skippedLabel = skippedLabel
-- Right column: Recommendations
local rightX = 290
-- Vertical divider
local vDiv = resultsPage:CreateTexture(nil, "ARTWORK")
vDiv:SetSize(1, 1)
vDiv:SetPoint("TOPLEFT", rightX - 10, -54)
vDiv:SetPoint("BOTTOMLEFT", rightX - 10, 40)
vDiv:SetColorTexture(ns.Theme.RGB(ns.Theme.C.BORDER, 0.35))
local recHeader = resultsPage:CreateFontString(nil, "OVERLAY")
recHeader:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
recHeader:SetPoint("TOPLEFT", rightX, -56)
recHeader:SetTextColor(0.9, 0.9, 0.9)
recHeader:SetText("Recommendations")
issueContainer = CreateFrame("ScrollFrame", "BoundToLearnAuditScroll", resultsPage, "UIPanelScrollFrameTemplate")
issueContainer:SetPoint("TOPLEFT", rightX, -76)
issueContainer:SetPoint("BOTTOMRIGHT", -15, 44)
ns.Theme.StyleScrollBar(issueContainer.ScrollBar or _G["BoundToLearnAuditScrollScrollBar"])
issueScrollChild = CreateFrame("Frame", nil, issueContainer)
issueScrollChild:SetSize(250, 1)
issueContainer:SetScrollChild(issueScrollChild)
-- Room for every action bar's section header and its rows.
for i = 1, 48 do
issueRows[i] = CreateIssueRow(issueScrollChild, i)
end
-- No issues message
local noIssues = resultsPage:CreateFontString(nil, "OVERLAY")
noIssues:SetFont("Fonts\\FRIZQT__.TTF", 11, "")
noIssues:SetPoint("TOP", issueContainer, "TOP", 0, -40)
noIssues:SetTextColor(0.4, 0.7, 0.4)
noIssues:SetText("No issues found. Nice work.") -- set per result in ShowResults
noIssues:Hide()
resultsPage.noIssues = noIssues
-- Back (top left, on the frame) returns to setup; the results re-scan by
-- themselves when a keybind or a bar slot changes (no Refresh button).
end
function KeybindAuditUI:CreateMethodologyPage()
methodologyPage = CreateFrame("Frame", nil, auditFrame)
methodologyPage:SetAllPoints()
local scrollFrame = CreateFrame("ScrollFrame", "BoundToLearnAuditMethScroll", methodologyPage, "UIPanelScrollFrameTemplate")
-- Starts under the divider (the methodology note is hidden on this page);
-- the scroll bar hangs right of the frame and must clear the right border (11).
scrollFrame:SetPoint("TOPLEFT", 15, -44)
scrollFrame:SetPoint("BOTTOMRIGHT", -36, 44)
ns.Theme.StyleScrollBar(scrollFrame.ScrollBar or _G["BoundToLearnAuditMethScrollScrollBar"])
local content = CreateFrame("Frame", nil, scrollFrame)
content:SetWidth(520)
scrollFrame:SetScrollChild(content)
local text = content:CreateFontString(nil, "OVERLAY")
text:SetFont("Fonts\\FRIZQT__.TTF", 12, "")
text:SetPoint("TOPLEFT", 0, 0)
text:SetWidth(520)
text:SetJustifyH("LEFT")
text:SetTextColor(0.75, 0.75, 0.75)
local methBody =
"|cFFFF8A33Overview|r\n"
.. "The audit scans your action bars and scores your keybind setup on a 0-100 scale "
.. "across four categories.\n\n"
.. "|cFFFF8A33Coverage (40%)|r\n"
.. "Percentage of filled action bar slots that have a keybind assigned. "
.. "Every ability on your bars should be reachable without clicking.\n\n"
.. "|cFFFF8A33Reachability (30%)|r\n"
.. "How close your keybinds are to your movement keys. Each bound slot is scored:\n"
.. " |cFF66DD66Prime keys (100)|r: 1-5, Q, E, R, F, G, Z, X, C, V, T, B, `, Tab, mouse buttons\n"
.. " |cFFDDDD44Acceptable (60)|r: 6, Y, H, N, Space, the mouse wheel\n"
.. " |cFFDD8844Poor (20)|r: 7-0, -, =, F1-F12, and the right hand's keys: everything right of "
.. "6/Y/H/N (U, I, O, P, J, K, L, M and on), the numpad, arrows and the Insert/Home block\n"
.. "A modifier combo on a prime key (Shift-Q, Ctrl-3) keeps its 100. On an acceptable or "
.. "poor key the hand already stretches, and holding Shift, Ctrl or Alt spreads it further: "
.. "those combos score 40 and 10. A far key or stretch combo is listed with a nudge toward "
.. "a closer key while you still have near keys or combos free; once every one is taken, a "
.. "stretch combo is no longer listed.\n\n"
.. "|cFFFF8A33Modifier Usage (15%)|r\n"
.. "Modifiers are expected only once your abilities outnumber your prime keys (22 above, "
.. "29 with the MMO mouse option). Past that, scored by how many of the extra abilities sit on "
.. "Shift, Ctrl or Alt combos of near keys; a combo on a far key does not count.\n\n"
.. "|cFFFF8A33Anti-patterns (15%)|r\n"
.. "Starts at 100 and deducts for common issues:\n"
.. " Keyboard turning (A/D bound to turn): -40\n"
.. " Each unbound ability: -5 (max -40)\n"
.. " Each poor-tier keybind: -3 (max -20)\n\n"
.. "|cFFFF8A33Grouping|r |cFFFF8800(Experimental, opt-in)|r\n"
.. "Measures physical key proximity of abilities that share a role "
.. "(defensives, CCs, offensive cooldowns, interrupts). Abilities are classified "
.. "using spell data. For each role with 2+ bound abilities, the average pairwise "
.. "distance between their keys is scored:\n"
.. " |cFF66DD66Same key / adjacent (dist 0-1.5): 90-100|r\n"
.. " |cFFDDDD44Nearby (dist 1.5-3.5): 60-75|r\n"
.. " |cFFDD8844Distant (dist 3.5+): 20-40|r\n"
.. "Distance is measured on your selected keyboard layout (QWERTY, AZERTY, etc). "
.. "When enabled, weights redistribute: Coverage 35%, Reachability 25%, "
.. "Modifiers 12%, Anti-patterns 13%, Grouping 15%.\n\n"
.. "|cFFFF8A33Grading|r\n"
.. "A+ (95+) A (90+) A- (85+) B+ (80+) B (75+) B- (70+)\n"
.. "C+ (65+) C (60+) D (50+) F (below 50)\n\n"
.. "|cFFFF8A33MMO Mouse|r\n"
.. "When enabled, number row keys (6-0, -, =) are treated as prime keys "
.. "since they map to your thumb grid."
text:SetText((methBody:gsub("FF8A33", ns.Theme.ACCENT_HEX)))
content:SetHeight(text:GetStringHeight() + 10)
end
function KeybindAuditUI:ToggleMethodology()
if methodologyPage:IsShown() then
methodologyPage:Hide()
auditFrame.methNote:Show()
if methodologyPage.returnToResults then
resultsPage:Show()
else
setupPage:Show()
self:ShowBarOverlays()
end
else
methodologyPage.returnToResults = resultsPage:IsShown() or categoryDetailPage:IsShown()
auditFrame.methNote:Hide()
methodologyPage:Show()
setupPage:Hide()
resultsPage:Hide()
categoryDetailPage:Hide()
self:HideBarOverlays()
end
self:UpdateBackButton()
end
-- Back is shown on every page but setup.
function KeybindAuditUI:UpdateBackButton()
if auditFrame and auditFrame.backBtn then auditFrame.backBtn:SetShown(not setupPage:IsShown()) end
end
-- One level up: methodology to where it was opened from, a category's detail
-- to the scorecard, the scorecard to setup.
function KeybindAuditUI:GoBack()
if methodologyPage:IsShown() then
self:ToggleMethodology()
elseif categoryDetailPage:IsShown() then
categoryDetailPage:Hide()
resultsPage:Show()
elseif resultsPage:IsShown() then
self:ShowSetup()
end
self:UpdateBackButton()
end
local TIER_COLORS = {
prime = "|cFF66DD66",
acceptable = "|cFFDDDD44",
poor = "|cFFDD8844",
}
local function BuildCoverageDetail(results)
local lines = {}
tinsert(lines, sformat("|cFFFF8A33Score: %d / 100|r", results.scores.coverage))
tinsert(lines, sformat("\n%d of %d filled slots have keybinds assigned.", results.totalBound, results.totalFilled))
tinsert(lines, "\n\n|cFFFF8A33Per-bar breakdown:|r")
for _, barDef in ipairs(results.barOrder) do
local barData = results.bars[barDef.key]
if barData and not barData.excluded and barData.filledCount > 0 then
local ratio = barData.boundCount / barData.filledCount * 100
local r, g, b = GetBarColor(ratio)
tinsert(lines, sformat(" %s: |cFF%02x%02x%02x%d / %d bound|r",
barData.label, r * 255, g * 255, b * 255, barData.boundCount, barData.filledCount))
end
end
local unbound = {}
for _, slot in ipairs(results.allSlots) do
if not slot.keybind then tinsert(unbound, slot) end
end
if #unbound > 0 then
tinsert(lines, "\n\n|cFFFF8A33Unbound abilities:|r")
for _, slot in ipairs(unbound) do
tinsert(lines, sformat(" |cFFDD8844%s|r on %s, slot %d", slot.actionName, slot.barLabel, slot.barIndex))
end
end
tinsert(lines, "\n\n|cFF666666Coverage measures how many of your action bar abilities have keybinds. Every ability you use in combat should be reachable via keyboard.|r")
return table.concat(lines, "\n")
end