Repository navigation
Expand file tree
/
Copy pathCore.lua
More file actions
1011 lines (935 loc) · 38.6 KB
/
Copy pathCore.lua
File metadata and controls
1011 lines (935 loc) · 38.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
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 Utils = ns.Utils
local sformat = Utils.sformat
local pairs = Utils.pairs
local type = Utils.type
local mmax = Utils.mmax
local mfloor = Utils.mfloor
local mceil = Utils.mceil
local ipairs = Utils.ipairs
local PlayUISound = Utils.PlayUISound
local SOUND_CLICK = Utils.SOUND_CLICK
BoundToLearn = {}
BoundToLearn._ns = ns
ns.BoundToLearn = BoundToLearn
local DB_DEFAULTS = {
filter = {
mounts = true,
toys = true,
hearthstones = true,
teleports = true,
consumables = true,
professions = true,
skyriding = true,
nonCombatMacros = true,
buffs = true,
tracking = true,
petCare = true,
},
tracker = {
enabled = true,
showWidget = true,
widgetPosition = nil,
widgetScale = 1.0,
combatOnly = false,
hideInCombat = false,
blocklist = {},
maxSegments = 6,
},
game = {
difficulty = "Medium",
modifiers = {},
songKey = "s1", -- selected track for the rhythm game
songScores = {}, -- [songKey][difficulty] = best score
songProgress = {}, -- [songKey] = best fraction (0-1) reached
songHistory = {}, -- [songKey][difficulty] = { recent scores } for the results trend
songStats = {}, -- [songKey][difficulty] = { plays, bestAccuracy, bestCombo }
mode = "timed", -- "timed", "practice", "competitive"
compBarPos = false, -- saved competitive lane-bar position (drag setup)
duration = 90, -- seconds (timed/competitive)
fallSpeed = 150,
fallDistance = 300,
spawnInterval = 1.5,
maxActiveNotes = 3,
timingPerfect = 0.08,
timingGreat = 0.15,
timingGood = 0.25,
soundEnabled = true,
showCombo = true,
bars = {
main = true, -- ActionButton1-12
bottomLeft = true, -- MultiBarBottomLeft
bottomRight = false, -- MultiBarBottomRight
right = false, -- MultiBarRight
left = false, -- MultiBarLeft
bar6 = false, -- MultiBar5
bar7 = false, -- MultiBar6
bar8 = false, -- MultiBar7
},
},
pingTrainer = {
targetStyle = "portraits", -- "portraits", "blobs", "3d"
background = "classic", -- selected expansion background id
randomBG = false, -- randomize from unlocked backgrounds
unlockedBGs = { classic = true, tbc = true },
muteMusic = false,
mutePingSounds = false, -- ping SFX on by default
},
stats = {
sessions = {},
personalBest = {
longestCombo = 0,
highestScore = 0,
bestAccuracy = 0,
bestKeybindRatio = 0,
fastestQuiz = 0,
},
difficultyBest = {
Easy = { highestScore = 0, longestCombo = 0 },
Medium = { highestScore = 0, longestCombo = 0 },
Hard = { highestScore = 0, longestCombo = 0 },
Extreme = { highestScore = 0, longestCombo = 0 },
},
lifetimeClicks = 0,
lifetimeKeybinds = 0,
lifetimeGameNotes = 0,
lifetimeGameHits = 0,
lifetimeQuizzes = 0,
lifetimeQuizAbilities = 0,
scoreScaleV2 = false,
},
options = {
showMinimapButton = true,
firstRun = true,
showGameWarning = true,
muteChat = false,
},
leaderboard = {
Easy = {},
Medium = {},
Hard = {},
Extreme = {},
},
clickBlock = {
enabled = false,
mode = "all", -- "all", "cc", "interrupt", "custom"
customBlacklist = {}, -- { [spellID] = spellName }
},
audit = {
bars = {
main = true,
bottomLeft = true,
bottomRight = true,
right = true,
left = true,
bar6 = true,
bar7 = true,
bar8 = true,
},
skipBarSelection = false,
mmoMouse = false,
hasUniqueBinds = false,
uniqueBinds = {}, -- [BASEKEY] = "mouse" | "numpad" | "function" | "other"
includeGrouping = false,
keyboardLayout = "QWERTY",
},
achievements = {
unlocked = {}, -- [achievementID] = timestamp
},
minimap = {
angle = 220,
},
}
local function MergeDefaults(target, defaults)
for k, v in pairs(defaults) do
if target[k] == nil then
target[k] = v
elseif type(v) == "table" and type(target[k]) == "table" then
MergeDefaults(target[k], v)
end
end
end
local function OnInitialize()
if not BoundToLearnDB then
BoundToLearnDB = {}
end
MergeDefaults(BoundToLearnDB, DB_DEFAULTS)
BoundToLearn.db = BoundToLearnDB
-- One-time reset of score bests when scoring moved to the normalized money-score
-- (capped near 100k). Old bests were on a much larger, length-dependent scale and
-- would be permanently unbeatable. Combo and accuracy bests are scale-independent
-- and kept.
if not BoundToLearnDB.stats.scoreScaleV2 then
BoundToLearnDB.stats.personalBest.highestScore = 0
for _, d in pairs(BoundToLearnDB.stats.difficultyBest) do d.highestScore = 0 end
for _, board in pairs(BoundToLearnDB.leaderboard) do wipe(board) end
BoundToLearnDB.stats.scoreScaleV2 = true
end
BoundToLearnDB.options.colorTheme = nil -- the color themes are gone
-- Crash recovery for the round music fade: if a round set the Music volume
-- low/zero for a fade and a crash skipped the restore, put it back.
if BoundToLearnDB.pendingMusicRestore then
SetCVar("Sound_MusicVolume", BoundToLearnDB.pendingMusicRestore)
BoundToLearnDB.pendingMusicRestore = nil
end
-- One-time recovery for an earlier build that muted the Music channel via the
-- Sound_MusicVolume CVar and could leave it at 0 permanently on a crash.
if not BoundToLearnDB.musicVolRestored then
BoundToLearnDB.musicVolRestored = true
if (tonumber(GetCVar("Sound_MusicVolume")) or 0) == 0 then
SetCVar("Sound_MusicVolume", 0.4)
end
end
-- Competitive mode is removed from main for now (kept on the experimental
-- branch); fall back to timed if an old saved value still selects it.
if BoundToLearnDB.game.mode == "competitive" then
BoundToLearnDB.game.mode = "timed"
end
-- Migrate: filter moved from tracker.filter to top-level filter
if BoundToLearnDB.tracker and BoundToLearnDB.tracker.filter then
for k, v in pairs(BoundToLearnDB.tracker.filter) do
BoundToLearnDB.filter[k] = v
end
BoundToLearnDB.tracker.filter = nil
end
-- Migrate: skipNonCombat moved to shared filter
if BoundToLearnDB.audit and BoundToLearnDB.audit.skipNonCombat ~= nil then
BoundToLearnDB.filter.nonCombatMacros = BoundToLearnDB.audit.skipNonCombat
BoundToLearnDB.audit.skipNonCombat = nil
end
-- Migrate: Ping Trainer backgrounds are now per-expansion. Retire the old
-- zone-art ids, seed the always-on Classic/TBC backdrops, and reset any stale
-- selection to Classic.
local pt = BoundToLearnDB.pingTrainer
if pt then
pt.unlockedBGs = pt.unlockedBGs or {}
pt.unlockedBGs.orgrimmar = nil
pt.unlockedBGs.darnassus = nil
pt.unlockedBGs.naxxramas = nil
pt.unlockedBGs.classic = true
pt.unlockedBGs.tbc = true
if pt.background == "orgrimmar" or pt.background == "darnassus" or pt.background == "naxxramas" then
pt.background = "classic"
end
end
-- Migrate: money-score scale dropped 10x (SCORE_CAP 100000 -> 10000). Rescale
-- every stored score once so old bests stay comparable to new runs.
if not BoundToLearnDB.scoresRescaled10 then
BoundToLearnDB.scoresRescaled10 = true
local st = BoundToLearnDB.stats
if type(st) == "table" then
if type(st.personalBest) == "table" and type(st.personalBest.highestScore) == "number" then
st.personalBest.highestScore = mfloor(st.personalBest.highestScore / 10)
end
if type(st.difficultyBest) == "table" then
for _, d in pairs(st.difficultyBest) do
if type(d) == "table" and type(d.highestScore) == "number" then
d.highestScore = mfloor(d.highestScore / 10)
end
end
end
if type(st.sessions) == "table" then
for _, s in ipairs(st.sessions) do
if type(s) == "table" and type(s.score) == "number" then
s.score = mfloor(s.score / 10)
end
end
end
end
local ss = BoundToLearnDB.game and BoundToLearnDB.game.songScores
if type(ss) == "table" then
for _, perDiff in pairs(ss) do
if type(perDiff) == "table" then
for diff, sc in pairs(perDiff) do
if type(sc) == "number" then perDiff[diff] = mfloor(sc / 10) end
end
end
end
end
local lb = BoundToLearnDB.leaderboard
if type(lb) == "table" then
for _, board in pairs(lb) do
if type(board) == "table" then
for _, entry in ipairs(board) do
if type(entry) == "table" and type(entry.score) == "number" then
entry.score = mfloor(entry.score / 10)
end
end
end
end
end
end
-- Migrate: accuracy now weights hit quality (perfect/great/good) instead of only
-- subtracting misses, so old accuracy bests would sit unbeatable. Reset the accuracy
-- bests and the lifetime hit tally once so they rebuild on the new formula.
if not BoundToLearnDB.accuracyWeighted then
BoundToLearnDB.accuracyWeighted = true
local st = BoundToLearnDB.stats
if type(st) == "table" then
st.lifetimeGameHits = 0
st.lifetimeGameNotes = 0
if type(st.personalBest) == "table" then st.personalBest.bestAccuracy = 0 end
end
local g = BoundToLearnDB.game
if type(g) == "table" and type(g.songStats) == "table" then
for _, byDiff in pairs(g.songStats) do
if type(byDiff) == "table" then
for _, s in pairs(byDiff) do
if type(s) == "table" then s.bestAccuracy = 0 end
end
end
end
end
end
-- Migrate: ping SFX now defaults on; enable it once for installs from when it was off.
if not BoundToLearnDB.pingSfxDefaultOn then
BoundToLearnDB.pingSfxDefaultOn = true
if type(BoundToLearnDB.pingTrainer) == "table" then
BoundToLearnDB.pingTrainer.mutePingSounds = false
end
end
ns.version = C_AddOns.GetAddOnMetadata(ADDON_NAME, "Version")
SLASH_KBTRACK1 = "/kbtrack"
SlashCmdList["KBTRACK"] = function()
BoundToLearn:ToggleTracker()
end
SLASH_BOUNDTOLEARN1 = "/btl"
SlashCmdList["BOUNDTOLEARN"] = function(msg)
msg = msg and msg:lower():trim() or ""
if msg == "track" then
BoundToLearn:ToggleTracker()
elseif msg == "game" then
BoundToLearn:OpenGame()
elseif msg == "stats" then
BoundToLearn:ShowStats()
elseif msg == "o" or msg == "options" or msg == "config" or msg == "settings" then
BoundToLearn:OpenOptions()
elseif msg == "reset" then
if ns.Tracker then ns.Tracker:ResetSession() end
BoundToLearn:Print("Session reset.")
elseif msg == "reset scores" or msg == "resetscores" then
BoundToLearn:ConfirmResetScores()
elseif msg == "lb" or msg == "leaderboard" then
if ns.LeaderboardUI then ns.LeaderboardUI:Toggle() end
elseif msg == "accept" then
if ns.Leaderboard then ns.Leaderboard:AcceptChallenge() end
elseif msg == "decline" then
if ns.Leaderboard then ns.Leaderboard:DeclineChallenge() end
elseif msg:sub(1, 9) == "challenge" then
local target = msg:sub(11):trim()
if target == "" then target = "party" end
if ns.Leaderboard then ns.Leaderboard:SendChallenge(target) end
elseif msg == "enforce" or msg == "block" then
if ns.ClickBlock then ns.ClickBlock:Toggle() end
elseif msg == "enforce all" or msg == "block all" then
if ns.ClickBlock then ns.ClickBlock:SetMode("all"); ns.ClickBlock:Enable() end
elseif msg == "enforce cc" or msg == "block cc" then
if ns.ClickBlock then ns.ClickBlock:SetMode("cc"); ns.ClickBlock:Enable() end
elseif msg == "enforce interrupt" or msg == "block interrupt" then
if ns.ClickBlock then ns.ClickBlock:SetMode("interrupt"); ns.ClickBlock:Enable() end
elseif msg == "audit" or msg == "keybinds" then
if ns.KeybindAuditUI then ns.KeybindAuditUI:Toggle() end
elseif msg == "quiz" then
if ns.KeybindQuiz then ns.KeybindQuiz:Toggle() end
elseif msg == "debughitbox" then
if ns.PingGameUI then ns.PingGameUI:ToggleDebugHitbox() end
elseif msg == "wheeldbg" then
if ns.GameUI then ns.GameUI:DumpWheel() end
elseif msg:sub(1, 11) == "layoutcheck" then
ns.LayoutCheck:Run(msg:sub(13))
elseif msg == "mousetest" then
BoundToLearn:ToggleMouseTest()
elseif msg == "feedback" then
ns.Feedback:OpenGeneral()
elseif msg == "first" then
BoundToLearn:ShowWelcome()
elseif msg == "songcheck" then
BoundToLearn:SongCheck()
elseif msg == "chartcheck" then
if ns.Game then ns.Game:ChartCheck() end
elseif msg == "memcheck" then
BoundToLearn:MemCheck()
elseif msg == "auditlist" then
if ns.KeybindAudit then ns.KeybindAudit:ListActions() end
elseif msg == "modelcheck" then
if ns.PingGameUI then ns.PingGameUI:ModelCheck() end
elseif msg == "ping" then
if ns.PingGameUI then ns.PingGameUI:Toggle() end
elseif msg == "hide" then
if ns.TrackerUI then ns.TrackerUI:Hide() end
if ns.GameUI then ns.GameUI:Hide() end
elseif msg == "help" or msg == "?" then
BoundToLearn:PrintHelp()
elseif msg == "" then
BoundToLearn:ShowMinimapMenu()
else
BoundToLearn:Print(sformat("Unknown command: %s. Type /btl help for options.", msg))
end
end
end
local function OnPlayerLogin()
C_Timer.After(0.5, function()
if ns.Tracker then ns.Tracker:Initialize() end
if ns.TrackerUI then ns.TrackerUI:Initialize() end
if ns.Stats then ns.Stats:Initialize() end
if ns.Game then ns.Game:Initialize() end
if ns.GameUI then ns.GameUI:Initialize() end
if ns.StatsUI then ns.StatsUI:Initialize() end
if ns.Options then ns.Options:Initialize() end
if ns.Leaderboard then ns.Leaderboard:Initialize() end
if ns.LeaderboardUI then ns.LeaderboardUI:Initialize() end
if ns.ClickBlock then ns.ClickBlock:Initialize() end
if ns.PingGame then ns.PingGame:Initialize() end
if ns.PingGameUI then ns.PingGameUI:Initialize() end
end)
C_Timer.After(0.6, function()
if BoundToLearn.db.options.showMinimapButton then
BoundToLearn:CreateMinimapButton()
end
end)
-- Once per account, for a new install: the flag clears as it is queued.
if BoundToLearn.db.options.firstRun then
BoundToLearn.db.options.firstRun = false
C_Timer.After(2, function()
BoundToLearn:ShowWelcome()
end)
end
end
-- Event dispatch
local eventFrame = CreateFrame("Frame")
ns.eventFrame = eventFrame
eventFrame:RegisterEvent("ADDON_LOADED")
eventFrame:RegisterEvent("PLAYER_LOGIN")
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:SetScript("OnEvent", function(self, event, arg1, arg2)
if event == "ADDON_LOADED" and arg1 == ADDON_NAME then
OnInitialize()
self:UnregisterEvent("ADDON_LOADED")
elseif event == "PLAYER_LOGIN" then
OnPlayerLogin()
self.loginHandled = true
self:UnregisterEvent("PLAYER_LOGIN")
elseif event == "PLAYER_ENTERING_WORLD" then
if arg2 and not self.loginHandled then
OnPlayerLogin()
end
self:UnregisterEvent("PLAYER_ENTERING_WORLD")
end
end)
-- Public API
function BoundToLearn:ToggleTracker()
if not ns.Tracker then return end
local db = self.db.tracker
if db.enabled then
db.enabled = false
ns.Tracker:StopSession()
if ns.TrackerUI then ns.TrackerUI:Hide() end
else
db.enabled = true
ns.Tracker:StartSession()
if ns.TrackerUI then
ns.TrackerUI:OnSessionStart()
end
end
end
-- Probe (/btl songcheck, and the end of /btl layoutcheck): which tracks this
-- client plays. Printed, and saved in BoundToLearnDB.songReport for reading
-- from the SavedVariables file.
function BoundToLearn:SongCheck()
local repeats = ns.SongData.ArtRepeats()
local lines = {}
-- With game sound off the client answers "will not play" for every file,
-- which says nothing about the tracks.
if GetCVar("Sound_EnableAllSound") == "0" then
lines[1] = "Track check skipped: game sound is off (Settings, Audio, Enable Sound)."
else
local unplayable, disagree, total = ns.SongData.CheckTracks()
lines[1] = sformat("%d of %d tracks play here. Unplayable: %s",
total - #unplayable, total, #unplayable > 0 and table.concat(unplayable, " ") or "none")
if Utils.IS_FOREVER then
lines[2] = sformat("Differs from the Forever list: %s",
#disagree > 0 and table.concat(disagree, " ") or "none")
end
end
lines[#lines + 1] = sformat("Same picture on 4+ tracks: %s",
#repeats > 0 and table.concat(repeats, "; ") or "none")
-- What the client answered, so "0 tracks play" can be told apart from a
-- muted channel: the sound settings and the first track on two channels.
local first = ns.SongData.songs[1]
local function try(channel)
local willPlay, handle = PlaySoundFile(first.id, channel)
if handle then StopSound(handle) end
return sformat("%s=%s", channel, tostring(willPlay))
end
lines[#lines + 1] = sformat("Sound: all %s, sfx %s, music %s, master volume %s, music volume %s; %s (%d): %s %s",
tostring(GetCVar("Sound_EnableAllSound")), tostring(GetCVar("Sound_EnableSFX")),
tostring(GetCVar("Sound_EnableMusic")), tostring(GetCVar("Sound_MasterVolume")),
tostring(GetCVar("Sound_MusicVolume")), first.key, first.id, try("Master"), try("Music"))
BoundToLearnDB.songReport = lines
for _, line in ipairs(lines) do Utils.Print(line) end
end
-- Probe (/btl memcheck): this addon's memory as the client counts it, then again
-- after a full garbage collection (the first figure still holds garbage the client
-- has not collected yet). Printed, and saved in BoundToLearnDB.memReport.
function BoundToLearn:MemCheck()
local usage = (C_AddOns and C_AddOns.GetAddOnMemoryUsage) or GetAddOnMemoryUsage
UpdateAddOnMemoryUsage()
local before = usage(ADDON_NAME)
collectgarbage("collect")
UpdateAddOnMemoryUsage()
local after = usage(ADDON_NAME)
local charts, chartBytes = 0, 0
for _, chart in pairs(ns.SongCharts or {}) do
charts = charts + 1
chartBytes = chartBytes + #chart.notes
end
local lines = {
sformat("Version %s on %s, %s", tostring(ns.version), Utils.IS_FOREVER and "Forever" or "retail",
date("%Y-%m-%d %H:%M")),
sformat("Memory %.0f KB, %.0f KB after a full garbage collection", before, after),
sformat("Song charts: %d, %.0f KB of note text", charts, chartBytes / 1024),
}
BoundToLearnDB.memReport = lines
for _, line in ipairs(lines) do Utils.Print(line) end
end
-- Probe (/btl mousetest): middle click (every mouse has one) also presses
-- Action Button 1 and wheel up Action Button 2, until run again. Never saved
-- to the binding set; the old binds come back.
local MOUSE_TEST = { { key = "BUTTON3", action = "ACTIONBUTTON1" }, { key = "MOUSEWHEELUP", action = "ACTIONBUTTON2" } }
local mouseTestPrev
function BoundToLearn:ToggleMouseTest()
if InCombatLockdown() then
self:Print("Out of combat only.")
return
end
if mouseTestPrev == nil then
mouseTestPrev = {}
for i, bind in ipairs(MOUSE_TEST) do
mouseTestPrev[i] = GetBindingAction(bind.key) or ""
SetBinding(bind.key, bind.action)
end
self:Print("TEST: middle click now casts action bar 1 slot 1, and wheel up casts slot 2. /btl mousetest again undoes it.")
else
for i, bind in ipairs(MOUSE_TEST) do
local prev = mouseTestPrev[i]
SetBinding(bind.key, prev ~= "" and prev or nil)
end
mouseTestPrev = nil
self:Print("TEST over: middle click and wheel up have their own binds back.")
end
end
function BoundToLearn:ShowStats()
if ns.StatsUI then ns.StatsUI:Toggle() end
end
function BoundToLearn:OpenOptions()
if ns.Options then ns.Options:Toggle() end
end
function BoundToLearn:Print(msg)
if self.db and self.db.options.muteChat then return end
Utils.Print(msg)
end
function BoundToLearn:PrintHelp()
local lines = {
"|cFFFF8A33BoundToLearn|r - Keybind training companion",
" /btl track - Enable/disable keybind tracker",
" /btl game - Open keybind practice game",
" /btl lb - Show leaderboard",
" /btl challenge - Challenge your party to a round",
" /btl accept - Accept a challenge",
" /btl decline - Decline a challenge",
" /btl audit - Show keybind audit",
" /btl quiz - Start keybind quiz",
" /btl ping - Open ping trainer",
" /btl stats - Show statistics panel",
" /btl options - Open settings",
" /btl feedback - Report a problem or idea (link with details filled in)",
" /btl enforce - Toggle click blocking (keybind-only mode)",
" /btl enforce all - Block all ability clicks",
" /btl enforce cc - Block only CC/interrupt clicks",
" /btl reset - Reset current session",
" /btl hide - Hide all UI",
" /btl help - Show this help",
}
for _, line in ipairs(lines) do
print(line)
end
end
-- Hidden testing command (/btl reset scores): wipe all persistent progress.
-- Not listed in help; confirmed via a themed dialog so a user who stumbles on
-- it is warned about exactly what they lose before anything is erased.
function BoundToLearn:ConfirmResetScores()
ns.Theme.ShowConfirm({
title = "Reset Everything",
body = "Reset ALL BoundToLearn progress?\n\nThis permanently erases every achievement, trophy, personal best, high score, and leaderboard entry. It cannot be undone.",
acceptText = "Erase Everything",
onAccept = function()
local db = BoundToLearn.db
wipe(db.achievements.unlocked)
for _, board in pairs(db.leaderboard) do wipe(board) end
local s = db.stats
wipe(s.sessions)
local pb = s.personalBest
pb.longestCombo, pb.highestScore = 0, 0
pb.bestAccuracy, pb.bestKeybindRatio, pb.fastestQuiz = 0, 0, 0
for _, d in pairs(s.difficultyBest) do
d.highestScore, d.longestCombo = 0, 0
end
s.lifetimeClicks, s.lifetimeKeybinds = 0, 0
s.lifetimeGameNotes, s.lifetimeGameHits = 0, 0
s.lifetimeQuizzes, s.lifetimeQuizAbilities = 0, 0
BoundToLearn:Print("All scores, achievements, and trophies reset.")
end,
})
end
-- Minimap button
local minimapButton
function BoundToLearn:CreateMinimapButton()
if minimapButton then
minimapButton:Show()
return
end
local btn = CreateFrame("Button", "BoundToLearnMinimapButton", Minimap)
btn:SetSize(31, 31)
btn:SetFrameStrata("MEDIUM")
btn:SetFrameLevel(8)
btn:SetClampedToScreen(true)
btn:SetMovable(true)
btn:RegisterForDrag("LeftButton")
btn:RegisterForClicks("LeftButtonUp", "RightButtonUp")
-- Icon (keyboard-style icon using a standard texture)
local icon = btn:CreateTexture(nil, "ARTWORK")
icon:SetSize(18, 18)
icon:SetPoint("CENTER")
icon:SetTexture("Interface\\MacroFrame\\MacroFrame-Icon")
btn.icon = icon
-- Border (standard minimap button border)
local border = btn:CreateTexture(nil, "OVERLAY")
border:SetSize(50, 50)
border:SetPoint("TOPLEFT")
border:SetTexture(136430) -- Standard minimap button border
btn.border = border
-- Background
local bg = btn:CreateTexture(nil, "BACKGROUND")
bg:SetSize(24, 24)
bg:SetPoint("CENTER")
bg:SetTexture(136467) -- Standard minimap button background
btn.bg = bg
local function UpdatePosition(angle)
local rads = math.rad(angle)
local radius = (Minimap:GetWidth() / 2) + 5
local x = math.cos(rads) * radius
local y = math.sin(rads) * radius
btn:ClearAllPoints()
btn:SetPoint("CENTER", Minimap, "CENTER", x, y)
end
btn:SetScript("OnDragStart", function(self)
self.isDragging = true
self:SetScript("OnUpdate", function()
local mx, my = Minimap:GetCenter()
local cx, cy = GetCursorPosition()
local scale = Minimap:GetEffectiveScale()
cx, cy = cx / scale, cy / scale
local angle = math.deg(math.atan2(cy - my, cx - mx))
BoundToLearn.db.minimap.angle = angle
UpdatePosition(angle)
end)
end)
btn:SetScript("OnDragStop", function(self)
self.isDragging = false
self:SetScript("OnUpdate", nil)
end)
btn:SetScript("OnClick", function(self, mouseButton)
if mouseButton == "RightButton" then
BoundToLearn:OpenOptions()
else
-- Left click: show a quick menu
BoundToLearn:ShowMinimapMenu(self)
end
end)
btn:SetScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_LEFT")
GameTooltip:SetText("|cFFFF8A33BoundToLearn|r")
GameTooltip:AddLine("Left-click: Menu", 1, 1, 1)
GameTooltip:AddLine("Right-click: Options", 1, 1, 1)
GameTooltip:Show()
end)
btn:SetScript("OnLeave", function()
GameTooltip:Hide()
end)
UpdatePosition(BoundToLearn.db.minimap.angle)
btn:Show()
minimapButton = btn
end
-- Simple dropdown menu from minimap button
local minimapMenu
function BoundToLearn:ShowMinimapMenu(anchor)
if not minimapMenu then
minimapMenu = CreateFrame("Frame", "BoundToLearnMinimapMenu", UIParent)
minimapMenu:SetFrameStrata("FULLSCREEN_DIALOG")
-- Capture the mouse over the whole menu so hovers do not fall through to
-- the minimap buttons behind it (their tooltips were bleeding over the menu).
minimapMenu:EnableMouse(true)
ns.Theme.StylePanel(minimapMenu, 0.97)
minimapMenu:Hide()
-- Esc closes the menu instead of falling through to the game menu.
Utils.CloseOnEscape(minimapMenu)
local menuEntries = {
{ header = "Games" },
{ getText = function() return "Icon Game" end, func = function() self:OpenGame() end },
{ getText = function() return "Ping Trainer" end, func = function() if ns.PingGameUI then ns.PingGameUI:Toggle() end end },
{ header = "Practice" },
{ getText = function() return "Keybind Quiz" end, func = function() if ns.KeybindQuiz then ns.KeybindQuiz:Toggle() end end },
{ getText = function() return "Keybind Audit" end, func = function() if ns.KeybindAuditUI then ns.KeybindAuditUI:Toggle() end end },
{ header = "Tracker" },
{ getText = function()
return self.db.tracker.enabled and "Disable Tracker" or "Enable Tracker"
end, func = function() self:ToggleTracker() end },
{ separator = true },
{ getText = function() return "Statistics" end, func = function() self:ShowStats() end },
{ getText = function() return "Options" end, func = function() self:OpenOptions() end },
{ getText = function() return "Give feedback" end, func = function() ns.Feedback:OpenGeneral() end },
}
local menuBtns = {}
local yOff = -5
for _, item in ipairs(menuEntries) do
if item.header then
yOff = yOff - 6
local label = minimapMenu:CreateFontString(nil, "OVERLAY")
label:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
label:SetPoint("TOP", 0, yOff)
label:SetTextColor(ns.Theme.RGB(ns.Theme.C.GOLD))
label:SetText(item.header)
yOff = yOff - 18
elseif item.separator then
local div = minimapMenu:CreateTexture(nil, "ARTWORK")
div:SetHeight(1)
div:SetPoint("TOPLEFT", 6, yOff - 2)
div:SetPoint("TOPRIGHT", -6, yOff - 2)
div:SetColorTexture(ns.Theme.RGB(ns.Theme.C.BORDER, 0.35))
yOff = yOff - 5
else
local menuBtn = CreateFrame("Button", nil, minimapMenu)
menuBtn:SetSize(130, 22)
menuBtn:SetPoint("TOPLEFT", 5, yOff)
menuBtn:SetNormalFontObject("GameFontHighlightSmall")
menuBtn:SetHighlightFontObject("GameFontNormalSmall")
local hl = CreateFrame("Frame", nil, menuBtn)
hl:SetPoint("TOPLEFT", -1, 1)
hl:SetPoint("BOTTOMRIGHT", 1, -1)
ns.Theme.Round(hl)
ns.Theme.SetBarHeight(hl, 10)
ns.Theme.SetBorderShown(hl, false)
ns.Theme.SetFillColor(hl, ns.Theme.C.ACCENT, 0)
menuBtn:HookScript("OnEnter", function() ns.Theme.SetFillColor(hl, ns.Theme.C.ACCENT, 0.18) end)
menuBtn:HookScript("OnLeave", function() ns.Theme.SetFillColor(hl, ns.Theme.C.ACCENT, 0) end)
menuBtn:SetText(item.getText())
menuBtn:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
minimapMenu:Hide()
item.func()
end)
tinsert(menuBtns, { btn = menuBtn, getText = item.getText })
yOff = yOff - 26
end
end
minimapMenu:SetSize(140, -yOff + 5)
minimapMenu:SetScript("OnShow", function(self)
-- 130 is a floor: rows widen to the longest label.
local rowWidth = 130
for _, entry in ipairs(menuBtns) do
entry.btn:SetText(entry.getText())
rowWidth = mmax(rowWidth, mfloor(entry.btn:GetFontString():GetStringWidth()) + 20)
end
for _, entry in ipairs(menuBtns) do
entry.btn:SetWidth(rowWidth)
end
self:SetWidth(rowWidth + 10)
self:SetScript("OnUpdate", function(self)
if not self:IsMouseOver() and not (minimapButton and minimapButton:IsMouseOver())
and (IsMouseButtonDown("LeftButton") or IsMouseButtonDown("RightButton")) then
self:Hide()
end
end)
end)
minimapMenu:SetScript("OnHide", function(self)
self:SetScript("OnUpdate", nil)
end)
end
if minimapMenu:IsShown() then
minimapMenu:Hide()
return
end
minimapMenu:ClearAllPoints()
if anchor then
-- Hang straight down from the button so it reads as attached; clamping
-- keeps it on-screen when the button sits near a screen edge.
minimapMenu:SetClampedToScreen(true)
minimapMenu:SetPoint("TOP", anchor, "BOTTOM", 0, -2)
else
-- Bare /btl: drop the menu at the cursor.
local cx, cy = GetCursorPosition()
local scale = UIParent:GetEffectiveScale()
minimapMenu:SetPoint("TOP", UIParent, "BOTTOMLEFT", cx / scale, cy / scale)
end
minimapMenu:Show()
end
-- Welcome popup for first-time users
local welcomeFrame
function BoundToLearn:ShowWelcome()
if welcomeFrame then welcomeFrame:Show(); return end
local f = CreateFrame("Frame", "BoundToLearnWelcome", UIParent)
f:SetSize(420, 390)
f:SetPoint("CENTER")
f:SetFrameStrata("DIALOG")
ns.Theme.StylePanel(f)
f:EnableMouse(true)
f:SetMovable(true)
f:RegisterForDrag("LeftButton")
f:SetScript("OnDragStart", f.StartMoving)
f:SetScript("OnDragStop", f.StopMovingOrSizing)
local title = ns.Theme.CreateTitle(f, "Welcome to BoundToLearn", 18)
title:SetPoint("TOP", 0, -16)
local titleRule = ns.Theme.CreateDivider(f)
titleRule:SetPoint("TOPLEFT", 16, -40)
titleRule:SetPoint("TOPRIGHT", -16, -40)
-- Sections: a centered header over a left-aligned paragraph.
local ACC = ns.Theme.ACCENT_HEX
local sections = {
{ "Keybind Tracker",
"Automatically tracks whether you use keybinds or click your abilities. " ..
"A small floating widget shows your keybind ratio in real time. The goal: " ..
"build muscle memory so keybinds become second nature." },
{ "Practice Game",
"A rhythm-based minigame where spell icons fall toward your action bar. " ..
"Press the correct keybind at the right time to score points. Build combos " ..
"for multipliers and bonus rewards." },
{ "Getting Started",
"Use |cFF" .. ACC .. "/btl|r to see all commands, or right-click the minimap " ..
"button for quick access to options." },
}
local PAD, y = 20, -52
local textWidth = f:GetWidth() - PAD * 2
for _, section in ipairs(sections) do
local header = f:CreateFontString(nil, "OVERLAY", "GameFontNormal")
header:SetPoint("TOP", 0, y)
header:SetText(section[1])
y = y - header:GetStringHeight() - 4
local text = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
text:SetPoint("TOPLEFT", PAD, y)
text:SetWidth(textWidth)
text:SetJustifyH("LEFT")
text:SetSpacing(3)
text:SetText(section[2])
y = y - text:GetStringHeight() - 14
end
-- Shown once per account; unticking the box brings it back next login.
local cb = ns.Theme.CreateToggle(f, "Don't show again")
cb:SetWidth(mceil(cb.Text:GetUnboundedStringWidth()) + 26)
cb:SetPoint("BOTTOMRIGHT", -14, 14)
cb:SetChecked(true)
local function dismiss()
BoundToLearn.db.options.firstRun = not cb:GetChecked()
f:Hide()
end
local btn = ns.Theme.CreateAccentButton(f, "Got It", 100, 26)
btn:SetPoint("BOTTOM", 0, 16)
btn:SetScript("OnClick", dismiss)
-- Tall enough for the text above the button row.
f:SetHeight(-y + 50)
local close = ns.Theme.CreateCloseButton(f, dismiss)
close:SetPoint("TOPRIGHT", -8, -8)
f:Show()
welcomeFrame = f
end
-- Game start confirmation with "don't show again" option
local gameConfirmFrame
local function ShowGameConfirm()
if not gameConfirmFrame then
local f = CreateFrame("Frame", "BoundToLearnGameConfirm", UIParent)
f:SetSize(340, 200)
f:SetPoint("CENTER", 0, 60)
-- Above the song select (FULLSCREEN), which Start is pressed from.
f:SetFrameStrata("FULLSCREEN_DIALOG")
f:SetFrameLevel(200)
ns.Theme.StylePanel(f)
f:EnableMouse(true)
local body = f:CreateFontString(nil, "OVERLAY", "GameFontHighlight")
body:SetPoint("TOPLEFT", 20, -22)
body:SetPoint("TOPRIGHT", -20, -22)
body:SetJustifyH("CENTER")
body:SetSpacing(3)
body:SetText(
"Starting the practice game will |cFF" .. ns.Theme.OKAY_HEX .. "temporarily\n" ..
"disable your abilities|r so keypresses are\n" ..
"scored instead of casting spells.\n\n" ..
"Your abilities return to normal when the game ends."
)
-- Own row above the buttons, which fill the bottom edge.
local cb = ns.Theme.CreateToggle(f, "Don't ask again", nil, 160)
cb:SetPoint("BOTTOM", 0, 52)
f.dontAsk = cb
local startBtn = ns.Theme.CreateAccentButton(f, "Start", 100, 26)
startBtn:SetPoint("BOTTOMRIGHT", f, "BOTTOM", -4, 14)
startBtn:SetScript("OnClick", function()
if cb:GetChecked() then
BoundToLearn.db.options.showGameWarning = false
end
f:Hide()
if ns.Game then ns.Game:Start() end
end)
local cancelBtn = ns.Theme.CreateButton(f, "Cancel", 100, 26)
cancelBtn:SetPoint("BOTTOMLEFT", f, "BOTTOM", 4, 14)
cancelBtn:SetScript("OnClick", function()
f:Hide()
end)
f:Hide()
Utils.CloseOnEscape(f)
gameConfirmFrame = f
end
gameConfirmFrame.dontAsk:SetChecked(false)
gameConfirmFrame:Show()
end
BoundToLearn.ShowGameConfirm = ShowGameConfirm
function BoundToLearn:OpenGame()
if ns.Game and ns.Game:IsRunning() then
self:Print("Game is already running.")
return
end
if ns.GameUI then
ns.GameUI:Initialize()
ns.GameUI:ShowReadyState()
end
end
function BoundToLearn:ToggleGame()
if ns.Game then
if ns.Game:IsRunning() then
ns.Game:Stop()
else
if InCombatLockdown() then
self:Print("Cannot start game during combat.")
return
end
if self.db.options.showGameWarning then
ShowGameConfirm()
else
ns.Game:Start()
end
end
end
end
function BoundToLearn:UpdateMinimapButton()
if BoundToLearn.db.options.showMinimapButton then
self:CreateMinimapButton()
elseif minimapButton then
minimapButton:Hide()
end