Repository navigation
Expand file tree
/
Copy pathKeybindQuiz.lua
More file actions
1087 lines (949 loc) · 35.9 KB
/
Copy pathKeybindQuiz.lua
File metadata and controls
1087 lines (949 loc) · 35.9 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 KeybindQuiz = {}
ns.KeybindQuiz = KeybindQuiz
local Utils = ns.Utils
local sformat = Utils.sformat
local tinsert = Utils.tinsert
local ipairs = Utils.ipairs
local wipe = Utils.wipe
local CreateFrame = Utils.CreateFrame
local mmin = Utils.mmin
local mmax = Utils.mmax
local mfloor = Utils.mfloor
local UIParent = UIParent
local HasAction = HasAction
local GetActionInfo = GetActionInfo
local GetActionTexture = GetActionTexture
local GetActionText = GetActionText
local GetBindingKey = GetBindingKey
local C_Spell = C_Spell
local C_Timer = C_Timer
local GetTime = GetTime
local IsAltKeyDown = IsAltKeyDown
local IsControlKeyDown = IsControlKeyDown
local IsShiftKeyDown = IsShiftKeyDown
local InCombatLockdown = InCombatLockdown
local PlaySound = PlaySound
local ICON_SIZE = 80
local ICON_CROP = 0.07
local HEAP_ICON_SIZE = 36
local HEAP_X_OFFSET = 240
local HEAP_Y_BASE = -20
local HEAP_SCATTER = 34 -- a pile spreads over icon + 2 x this: overlapping, not a ball
local FLY_DURATION = 0.35
local MODIFIER_KEYS = {
LSHIFT = true, RSHIFT = true, LCTRL = true, RCTRL = true,
LALT = true, RALT = true,
}
local BAR_MAPPINGS = {
{ bindPrefix = "ACTIONBUTTON", btnPrefix = "ActionButton", startSlot = 1, barFrame = "MainMenuBar" },
{ bindPrefix = "MULTIACTIONBAR1BUTTON", btnPrefix = "MultiBarBottomLeftButton", startSlot = 61, barFrame = "MultiBarBottomLeft" },
{ bindPrefix = "MULTIACTIONBAR2BUTTON", btnPrefix = "MultiBarBottomRightButton", startSlot = 49, barFrame = "MultiBarBottomRight" },
{ bindPrefix = "MULTIACTIONBAR3BUTTON", btnPrefix = "MultiBarRightButton", startSlot = 25, barFrame = "MultiBarRight" },
{ bindPrefix = "MULTIACTIONBAR4BUTTON", btnPrefix = "MultiBarLeftButton", startSlot = 37, barFrame = "MultiBarLeft" },
{ bindPrefix = "MULTIACTIONBAR5BUTTON", btnPrefix = "MultiBar5Button", startSlot = 145, barFrame = "MultiBar5" },
{ bindPrefix = "MULTIACTIONBAR6BUTTON", btnPrefix = "MultiBar6Button", startSlot = 157, barFrame = "MultiBar6" },
{ bindPrefix = "MULTIACTIONBAR7BUTTON", btnPrefix = "MultiBar7Button", startSlot = 169, barFrame = "MultiBar7" },
}
-- State
local quizFrame, inputFrame, dimmer
local allCards = {}
local deck = {}
local currentIndex = 0
local correctPile = {}
local wrongPile = {}
local isRunning = false
local quizFinished = false
local waitingForNext = false
local advanceTimer
local wrongFlyTimer
local hiddenBars = {}
local roundNumber = 1
local isReviewRound = false
local isPractice = false
local quizStartTime = 0
local totalWrongAnswers = 0
local pendingFly -- { texture, whichPile, anchorFrame }
local pendingWrongIcon -- { texture, anchorFrame } for wrong answers awaiting fly timer
-- UI refs
local cardFrame, cardIcon, cardBorder, glowBorder
local cardName, promptText, answerLabel, answerKeybind
local progressText, correctCountText, wrongCountText, roundText, timerText
local correctHeapLabel, wrongHeapLabel
local heapPool = {}
local activeHeapIcons = { correct = {}, wrong = {} }
local flyerFrame
-- Helpers
local function GetAbilityName(slot)
local actionType, id = GetActionInfo(slot)
if actionType == "spell" and id and id > 0 then
local info = C_Spell.GetSpellInfo(id)
return info and info.name
elseif actionType == "macro" then
return GetActionText(slot)
elseif actionType == "item" and id then
return C_Item and C_Item.GetItemInfo and C_Item.GetItemInfo(id)
end
return nil
end
local function FormatKeybind(bind)
if not bind then return "" end
bind = bind:gsub("SHIFT%-", "S-")
bind = bind:gsub("CTRL%-", "C-")
bind = bind:gsub("ALT%-", "A-")
return bind
end
local function Shuffle(t)
for i = #t, 2, -1 do
local j = math.random(1, i)
t[i], t[j] = t[j], t[i]
end
end
local function DiscoverCards()
wipe(allCards)
local shouldIgnore = ns.Tracker and ns.Tracker.ShouldIgnoreAction
local seen = {}
for _, bar in ipairs(BAR_MAPPINGS) do
for i = 1, 12 do
local slot = bar.startSlot + (i - 1)
local btn = _G[bar.btnPrefix .. i]
if btn then
local actualSlot = btn.action or (btn.GetAction and btn:GetAction())
if actualSlot then slot = actualSlot end
end
if HasAction(slot) then
local keybind, keybind2 = GetBindingKey(bar.bindPrefix .. i)
if keybind and not seen[keybind] then
local skip = shouldIgnore and shouldIgnore(slot)
if not skip then
seen[keybind] = true
tinsert(allCards, {
slot = slot,
keybind = keybind,
keybind2 = keybind2,
texture = GetActionTexture(slot) or "Interface\\Icons\\INV_Misc_QuestionMark",
name = GetAbilityName(slot) or sformat("Slot %d", slot),
})
end
end
end
end
end
end
-- Class bars that aren't quizzed but should still be hidden so nothing is referenceable.
local EXTRA_BARS = {
{ barFrame = "PetActionBar", btnPrefix = "PetActionButton", count = 10 },
{ barFrame = "StanceBar", btnPrefix = "StanceButton", count = 10 },
}
-- Hide the action bars entirely for the duration of the quiz so there is nothing to
-- reference. Alpha (not Hide) keeps this out of protected-frame territory and is fully
-- reversible; both the bar frame and its buttons are dimmed so bar art disappears too.
-- Hiding the buttons directly guarantees they vanish even if the frame name is wrong.
local function DimBar(frameName, btnPrefix, count)
local frame = frameName and _G[frameName]
if frame then
hiddenBars[#hiddenBars + 1] = { region = frame, alpha = frame:GetAlpha() }
frame:SetAlpha(0)
end
for i = 1, count do
local btn = _G[btnPrefix .. i]
if btn then
hiddenBars[#hiddenBars + 1] = { region = btn, alpha = btn:GetAlpha() }
btn:SetAlpha(0)
end
end
end
local function HideActionBars()
wipe(hiddenBars)
for _, bar in ipairs(BAR_MAPPINGS) do
DimBar(bar.barFrame, bar.btnPrefix, 12)
end
for _, bar in ipairs(EXTRA_BARS) do
DimBar(bar.barFrame, bar.btnPrefix, bar.count)
end
end
local function RestoreActionBars()
for _, entry in ipairs(hiddenBars) do
entry.region:SetAlpha(entry.alpha)
end
wipe(hiddenBars)
end
local function CancelAdvanceTimer()
if advanceTimer then
advanceTimer:Cancel()
advanceTimer = nil
end
end
local function CancelWrongFlyTimer()
if wrongFlyTimer then
wrongFlyTimer:Cancel()
wrongFlyTimer = nil
end
end
local function ScheduleAdvance(delay)
CancelAdvanceTimer()
advanceTimer = C_Timer.NewTimer(delay, function()
advanceTimer = nil
if isRunning and waitingForNext and not quizFinished then
waitingForNext = false
KeybindQuiz:NextCard()
end
end)
end
-- Heap icon management
local function AcquireHeapIcon()
local icon = tremove(heapPool)
if icon then
return icon
end
local frame = CreateFrame("Frame", nil, quizFrame)
frame:SetSize(HEAP_ICON_SIZE, HEAP_ICON_SIZE)
local tex = frame:CreateTexture(nil, "ARTWORK")
tex:SetPoint("TOPLEFT", 3, -3)
tex:SetPoint("BOTTOMRIGHT", -3, 3)
tex:SetTexCoord(ICON_CROP, 1 - ICON_CROP, ICON_CROP, 1 - ICON_CROP)
frame.icon = tex
local border = frame:CreateTexture(nil, "OVERLAY")
border:SetPoint("TOPLEFT", -1, 1)
border:SetPoint("BOTTOMRIGHT", 1, -1)
border:SetAtlas("UI-HUD-ActionBar-IconFrame-Mouseover")
frame.border = border
return frame
end
local function ReleaseHeapIcon(frame)
frame:ClearAllPoints()
frame:Hide()
tinsert(heapPool, frame)
end
local function ClearHeapIcons(whichPile)
local icons = activeHeapIcons[whichPile]
for i = #icons, 1, -1 do
ReleaseHeapIcon(icons[i])
icons[i] = nil
end
end
local function AddHeapIcon(texture, whichPile, anchorFrame)
local frame = AcquireHeapIcon()
frame:SetFrameLevel(quizFrame:GetFrameLevel() + 2 + #activeHeapIcons[whichPile])
frame.icon:SetTexture(texture)
-- Random scatter for natural pile look
local offsetX = math.random(-HEAP_SCATTER, HEAP_SCATTER)
local offsetY = math.random(-HEAP_SCATTER, HEAP_SCATTER)
frame:SetPoint("CENTER", anchorFrame, "CENTER", offsetX, offsetY)
if whichPile == "correct" then
frame.border:SetVertexColor(0.3, 0.9, 0.3, 0.8)
else
frame.border:SetVertexColor(0.9, 0.3, 0.3, 0.8)
end
frame:Show()
tinsert(activeHeapIcons[whichPile], frame)
end
local function CompletePendingFly()
if pendingFly then
if flyerFrame then
flyerFrame:SetScript("OnUpdate", nil)
flyerFrame:Hide()
end
AddHeapIcon(pendingFly.texture, pendingFly.whichPile, pendingFly.anchorFrame)
pendingFly = nil
end
end
-- Fly animation: card icon shrinks and moves to the target heap
local function FlyToHeap(texture, whichPile, anchorFrame, onFinish)
if not flyerFrame then
flyerFrame = CreateFrame("Frame", nil, quizFrame)
flyerFrame:SetSize(ICON_SIZE, ICON_SIZE)
flyerFrame:SetFrameLevel(quizFrame:GetFrameLevel() + 50)
local tex = flyerFrame:CreateTexture(nil, "ARTWORK")
tex:SetPoint("TOPLEFT", 3, -3)
tex:SetPoint("BOTTOMRIGHT", -3, 3)
tex:SetTexCoord(ICON_CROP, 1 - ICON_CROP, ICON_CROP, 1 - ICON_CROP)
flyerFrame.icon = tex
local border = flyerFrame:CreateTexture(nil, "OVERLAY")
border:SetPoint("TOPLEFT", -1, 1)
border:SetPoint("BOTTOMRIGHT", 1, -1)
border:SetAtlas("UI-HUD-ActionBar-IconFrame-Mouseover")
flyerFrame.border = border
end
CompletePendingFly()
pendingFly = { texture = texture, whichPile = whichPile, anchorFrame = anchorFrame }
flyerFrame.icon:SetTexture(texture)
if whichPile == "correct" then
flyerFrame.border:SetVertexColor(0.3, 0.9, 0.3, 1)
else
flyerFrame.border:SetVertexColor(0.9, 0.3, 0.3, 1)
end
-- Start at card position
flyerFrame:ClearAllPoints()
flyerFrame:SetPoint("CENTER", cardFrame, "CENTER")
flyerFrame:SetSize(ICON_SIZE, ICON_SIZE)
flyerFrame:Show()
-- Animate via OnUpdate
local startTime = GetTime()
local startX, startY = cardFrame:GetCenter()
local endX, endY = anchorFrame:GetCenter()
flyerFrame:SetScript("OnUpdate", function(self, elapsed)
local now = GetTime()
local progress = mmin((now - startTime) / FLY_DURATION, 1.0)
-- Ease-out (decelerate)
local t = 1 - (1 - progress) * (1 - progress)
local curX = startX + (endX - startX) * t
local curY = startY + (endY - startY) * t
local curSize = ICON_SIZE + (HEAP_ICON_SIZE - ICON_SIZE) * t
self:ClearAllPoints()
self:SetSize(curSize, curSize)
self:SetPoint("CENTER", UIParent, "BOTTOMLEFT", curX, curY)
if progress >= 1.0 then
self:SetScript("OnUpdate", nil)
self:Hide()
pendingFly = nil
AddHeapIcon(texture, whichPile, anchorFrame)
if onFinish then onFinish() end
end
end)
end
-- Fly animation: heap icon grows and moves to the card position (reverse of FlyToHeap)
local function FlyFromHeap(texture, anchorFrame, onFinish)
if not flyerFrame then return end
flyerFrame.icon:SetTexture(texture)
flyerFrame.border:SetVertexColor(0.9, 0.3, 0.3, 1)
flyerFrame:ClearAllPoints()
flyerFrame:SetPoint("CENTER", anchorFrame, "CENTER")
flyerFrame:SetSize(HEAP_ICON_SIZE, HEAP_ICON_SIZE)
flyerFrame:Show()
local startTime = GetTime()
local startX, startY = anchorFrame:GetCenter()
local endX, endY = cardFrame:GetCenter()
flyerFrame:SetScript("OnUpdate", function(self)
local progress = mmin((GetTime() - startTime) / FLY_DURATION, 1.0)
local t = 1 - (1 - progress) * (1 - progress)
local curX = startX + (endX - startX) * t
local curY = startY + (endY - startY) * t
local curSize = HEAP_ICON_SIZE + (ICON_SIZE - HEAP_ICON_SIZE) * t
self:ClearAllPoints()
self:SetSize(curSize, curSize)
self:SetPoint("CENTER", UIParent, "BOTTOMLEFT", curX, curY)
if progress >= 1.0 then
self:SetScript("OnUpdate", nil)
self:Hide()
if onFinish then onFinish() end
end
end)
end
-- Glow effect on correct answer
local function FlashGlow()
if not glowBorder then return end
glowBorder:SetAlpha(0.8)
glowBorder:Show()
local startTime = GetTime()
local duration = 0.4
cardFrame:SetScript("OnUpdate", function(self, elapsed)
local now = GetTime()
local progress = (now - startTime) / duration
if progress >= 1.0 then
glowBorder:Hide()
self:SetScript("OnUpdate", nil)
return
end
-- Quick pulse up then fade out
local alpha
if progress < 0.3 then
alpha = 0.8
else
alpha = 0.8 * (1 - (progress - 0.3) / 0.7)
end
glowBorder:SetAlpha(mmax(alpha, 0))
end)
end
-- UI
local correctHeapAnchor, wrongHeapAnchor
local UpdateCounts
local function CreateQuizUI()
-- Dimmer
dimmer = CreateFrame("Frame", nil, UIParent)
dimmer:SetAllPoints()
dimmer:SetFrameStrata("FULLSCREEN")
dimmer:SetFrameLevel(10)
local dimTex = dimmer:CreateTexture(nil, "BACKGROUND")
dimTex:SetAllPoints()
dimTex:SetColorTexture(0, 0, 0, 0.5)
dimmer:EnableMouse(false)
dimmer:Hide()
-- Container (no visuals, just for positioning)
quizFrame = CreateFrame("Frame", "BoundToLearnQuizFrame", UIParent)
quizFrame:SetSize(500, 300)
quizFrame:SetPoint("CENTER", 0, 40)
quizFrame:SetFrameStrata("FULLSCREEN")
quizFrame:SetFrameLevel(15)
quizFrame:EnableMouse(false)
quizFrame:Hide()
ns.Theme.CheckLayoutOf(quizFrame)
-- Title
local title = ns.Theme.CreateTitle(quizFrame, "Keybind Quiz", 16)
title:SetPoint("TOP", 0, 10)
roundText = quizFrame:CreateFontString(nil, "OVERLAY")
roundText:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
roundText:SetPoint("TOP", title, "BOTTOM", 0, -4)
roundText:SetTextColor(0.55, 0.55, 0.55)
progressText = quizFrame:CreateFontString(nil, "OVERLAY")
progressText:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
progressText:SetPoint("TOP", roundText, "BOTTOM", 0, -2)
progressText:SetTextColor(0.8, 0.8, 0.8)
-- Card icon (centered)
cardFrame = CreateFrame("Frame", nil, quizFrame)
cardFrame:SetSize(ICON_SIZE, ICON_SIZE)
cardFrame:SetPoint("CENTER", 0, 10)
cardFrame._btlLayoutItem = true
cardIcon = cardFrame:CreateTexture(nil, "ARTWORK")
cardIcon:SetPoint("TOPLEFT", 4, -4)
cardIcon:SetPoint("BOTTOMRIGHT", -4, 4)
cardIcon:SetTexCoord(ICON_CROP, 1 - ICON_CROP, ICON_CROP, 1 - ICON_CROP)
cardBorder = cardFrame:CreateTexture(nil, "OVERLAY")
cardBorder:SetPoint("TOPLEFT", -2, 2)
cardBorder:SetPoint("BOTTOMRIGHT", 2, -2)
cardBorder:SetAtlas("UI-HUD-ActionBar-IconFrame-Mouseover")
cardBorder:SetVertexColor(1, 1, 1, 0.9)
-- Green glow (oversized border with additive blend)
glowBorder = cardFrame:CreateTexture(nil, "ARTWORK", nil, -1)
glowBorder:SetPoint("TOPLEFT", -10, 10)
glowBorder:SetPoint("BOTTOMRIGHT", 10, -10)
glowBorder:SetAtlas("UI-HUD-ActionBar-IconFrame-Mouseover")
glowBorder:SetVertexColor(0.2, 1.0, 0.3, 0.8)
glowBorder:SetBlendMode("ADD")
glowBorder:Hide()
-- Ability name (below card)
cardName = quizFrame:CreateFontString(nil, "OVERLAY")
cardName:SetFont("Fonts\\FRIZQT__.TTF", 21, "OUTLINE")
cardName:SetPoint("TOP", cardFrame, "BOTTOM", 0, -10)
cardName:SetWidth(280)
cardName:SetTextColor(1, 1, 1)
-- Prompt
promptText = quizFrame:CreateFontString(nil, "OVERLAY")
promptText:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
promptText:SetPoint("TOP", cardName, "BOTTOM", 0, -10)
promptText:SetTextColor(0.7, 0.7, 0.7)
-- Answer reveal
answerLabel = quizFrame:CreateFontString(nil, "OVERLAY")
answerLabel:SetFont("Fonts\\FRIZQT__.TTF", 16, "OUTLINE")
answerLabel:SetPoint("TOP", promptText, "BOTTOM", 0, -6)
answerLabel:SetTextColor(0.7, 0.7, 0.7)
answerLabel:Hide()
answerKeybind = quizFrame:CreateFontString(nil, "OVERLAY")
answerKeybind:SetFont("Fonts\\FRIZQT__.TTF", 30, "OUTLINE")
answerKeybind:SetPoint("TOP", answerLabel, "BOTTOM", 0, -4)
answerKeybind:Hide()
-- Heap anchors (invisible frames that heaps pile around), sized to the
-- whole scatter so the layout check sees the space a pile takes.
local heapZone = HEAP_ICON_SIZE + 2 * HEAP_SCATTER
correctHeapAnchor = CreateFrame("Frame", nil, quizFrame)
correctHeapAnchor:SetSize(heapZone, heapZone)
correctHeapAnchor:SetPoint("CENTER", -HEAP_X_OFFSET, HEAP_Y_BASE)
correctHeapAnchor._btlLayoutItem = true
wrongHeapAnchor = CreateFrame("Frame", nil, quizFrame)
wrongHeapAnchor:SetSize(heapZone, heapZone)
wrongHeapAnchor:SetPoint("CENTER", HEAP_X_OFFSET, HEAP_Y_BASE)
wrongHeapAnchor._btlLayoutItem = true
-- Heap labels
correctHeapLabel = quizFrame:CreateFontString(nil, "OVERLAY")
correctHeapLabel:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
correctHeapLabel:SetPoint("TOP", correctHeapAnchor, "BOTTOM", 0, -HEAP_ICON_SIZE - 4)
correctHeapLabel:SetTextColor(0.3, 0.8, 0.3)
wrongHeapLabel = quizFrame:CreateFontString(nil, "OVERLAY")
wrongHeapLabel:SetFont("Fonts\\FRIZQT__.TTF", 15, "OUTLINE")
wrongHeapLabel:SetPoint("TOP", wrongHeapAnchor, "BOTTOM", 0, -HEAP_ICON_SIZE - 4)
wrongHeapLabel:SetTextColor(0.8, 0.3, 0.3)
correctCountText = quizFrame:CreateFontString(nil, "OVERLAY")
correctCountText:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")
correctCountText:SetPoint("TOP", correctHeapLabel, "BOTTOM", 0, -2)
correctCountText:SetTextColor(0.3, 0.8, 0.3)
wrongCountText = quizFrame:CreateFontString(nil, "OVERLAY")
wrongCountText:SetFont("Fonts\\FRIZQT__.TTF", 18, "OUTLINE")
wrongCountText:SetPoint("TOP", wrongHeapLabel, "BOTTOM", 0, -2)
wrongCountText:SetTextColor(0.8, 0.3, 0.3)
-- Timer
timerText = quizFrame:CreateFontString(nil, "OVERLAY")
timerText:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
timerText:SetPoint("TOPRIGHT", quizFrame, "TOPRIGHT", -10, 10)
timerText:SetTextColor(0.6, 0.6, 0.6)
-- ESC hint, below the space the answer reveal takes
local escHint = quizFrame:CreateFontString(nil, "OVERLAY")
escHint:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
escHint:SetPoint("TOP", promptText, "BOTTOM", 0, -84)
escHint:SetTextColor(0.4, 0.4, 0.4)
escHint:SetText("ESC to exit")
-- Shown when the quiz is complete: the same mode again, or close.
local againBtn = ns.Theme.CreateAccentButton(quizFrame, "Try Again", 120, 28)
againBtn:SetPoint("TOPRIGHT", promptText, "BOTTOM", -6, -18)
againBtn:SetScript("OnClick", function() KeybindQuiz:TryAgain() end)
againBtn:Hide()
local closeBtn = ns.Theme.CreateButton(quizFrame, "Close", 120, 28)
closeBtn:SetPoint("TOPLEFT", promptText, "BOTTOM", 6, -18)
closeBtn:SetScript("OnClick", function() KeybindQuiz:Stop() end)
closeBtn:Hide()
quizFrame.againBtn, quizFrame.closeBtn = againBtn, closeBtn
-- Ready screen (standalone frame above dimmer)
local readyFrame = CreateFrame("Frame", nil, UIParent)
readyFrame:SetSize(300, 204)
readyFrame:SetPoint("CENTER", 0, 40)
readyFrame:SetFrameStrata("FULLSCREEN_DIALOG")
readyFrame:SetFrameLevel(50)
ns.Theme.StylePanel(readyFrame)
readyFrame:Hide()
ns.Utils.CloseOnEscape(readyFrame, function() KeybindQuiz:CancelReady() end)
local readyTitle = ns.Theme.CreateTitle(readyFrame, "Keybind Quiz", 18)
readyTitle:SetPoint("TOP", 0, -20)
local readyDesc = readyFrame:CreateFontString(nil, "OVERLAY")
readyDesc:SetFont("Fonts\\FRIZQT__.TTF", 13, "")
readyDesc:SetPoint("TOP", readyTitle, "BOTTOM", 0, -12)
readyDesc:SetWidth(260)
readyDesc:SetTextColor(0.7, 0.7, 0.7)
readyFrame.desc = readyDesc
local barNote = readyFrame:CreateFontString(nil, "OVERLAY")
barNote:SetFont("Fonts\\FRIZQT__.TTF", 11, "")
barNote:SetPoint("TOP", readyDesc, "BOTTOM", 0, -8)
barNote:SetWidth(260)
barNote:SetTextColor(0.95, 0.80, 0.35)
barNote:SetText("Your action bars are hidden during the quiz.")
local timedBtn = ns.Theme.CreateAccentButton(readyFrame, "Timed Run", 120, 28)
timedBtn:SetPoint("BOTTOMRIGHT", readyFrame, "BOTTOM", -6, 50)
local practiceBtn = ns.Theme.CreateButton(readyFrame, "Practice", 120, 28)
practiceBtn:SetPoint("BOTTOMLEFT", readyFrame, "BOTTOM", 6, 50)
local practiceHint = readyFrame:CreateFontString(nil, "OVERLAY")
practiceHint:SetFont("Fonts\\FRIZQT__.TTF", 9, "")
practiceHint:SetPoint("TOP", practiceBtn, "BOTTOM", 0, -2)
practiceHint:SetTextColor(0.45, 0.45, 0.45)
practiceHint:SetText("Not saved to stats")
local readyHint = readyFrame:CreateFontString(nil, "OVERLAY")
readyHint:SetFont("Fonts\\FRIZQT__.TTF", 10, "")
-- Clear of the dialog border, which is drawn inside the frame.
readyHint:SetPoint("BOTTOM", 0, 18)
readyHint:SetTextColor(0.4, 0.4, 0.4)
readyHint:SetText("ESC to cancel")
quizFrame.readyFrame = readyFrame
quizFrame.timedBtn = timedBtn
quizFrame.practiceBtn = practiceBtn
-- Input capture frame
inputFrame = CreateFrame("Frame", "BoundToLearnQuizInput", UIParent)
inputFrame:SetAllPoints()
inputFrame:SetFrameStrata("FULLSCREEN_DIALOG")
inputFrame:SetFrameLevel(100)
inputFrame:EnableKeyboard(true)
inputFrame:SetPropagateKeyboardInput(false)
inputFrame:Hide()
inputFrame:SetScript("OnKeyDown", function(_, key)
if MODIFIER_KEYS[key] then
inputFrame:SetPropagateKeyboardInput(true)
return
end
inputFrame:SetPropagateKeyboardInput(false)
if key == "ESCAPE" then
C_Timer.After(0, function() KeybindQuiz:Stop() end)
return
end
local fullKey = ""
if IsAltKeyDown() then fullKey = fullKey .. "ALT-" end
if IsControlKeyDown() then fullKey = fullKey .. "CTRL-" end
if IsShiftKeyDown() then fullKey = fullKey .. "SHIFT-" end
KeybindQuiz:PressKey(fullKey .. key)
end)
end
-- One answer press, from the key reader or the mouse catch (mouse binds).
function KeybindQuiz:PressKey(fullKey)
if not isRunning then return end
if quizFinished then
C_Timer.After(0, function() KeybindQuiz:Stop() end)
return
end
if waitingForNext then
CancelAdvanceTimer()
CancelWrongFlyTimer()
CompletePendingFly()
if pendingWrongIcon then
AddHeapIcon(pendingWrongIcon.texture, "wrong", pendingWrongIcon.anchorFrame)
pendingWrongIcon = nil
UpdateCounts()
end
waitingForNext = false
KeybindQuiz:NextCard()
return
end
KeybindQuiz:CheckAnswer(fullKey)
end
-- Logic
UpdateCounts = function()
correctCountText:SetText(sformat("%d", #correctPile))
wrongCountText:SetText(sformat("%d", #wrongPile))
correctHeapLabel:SetShown(#correctPile > 0)
wrongHeapLabel:SetShown(#wrongPile > 0)
end
local function RevealCard(card)
cardFrame:Show()
cardIcon:SetTexture(card.texture)
cardIcon:SetAlpha(1)
cardBorder:SetVertexColor(1, 1, 1, 0.9)
cardBorder:SetAlpha(1)
cardBorder:Show()
glowBorder:Hide()
cardFrame:SetScript("OnUpdate", nil)
cardName:SetText(card.name)
promptText:SetText("Press the correct keybind")
promptText:SetTextColor(0.7, 0.7, 0.7)
answerLabel:Hide()
answerKeybind:Hide()
progressText:SetText(sformat("%d / %d", currentIndex, #deck))
progressText:SetTextColor(0.8, 0.8, 0.8)
UpdateCounts()
end
local function ShowCurrentCard()
if currentIndex < 1 or currentIndex > #deck then return end
local card = deck[currentIndex]
if isReviewRound and wrongHeapAnchor then
-- Hide card content until fly animation finishes
cardFrame:Show()
cardIcon:SetAlpha(0)
cardBorder:SetAlpha(0)
cardName:SetText("")
promptText:SetText("")
answerLabel:Hide()
answerKeybind:Hide()
progressText:SetText(sformat("%d / %d", currentIndex, #deck))
FlyFromHeap(card.texture, wrongHeapAnchor, function()
if isRunning then
RevealCard(card)
end
end)
else
RevealCard(card)
end
end
function KeybindQuiz:CheckAnswer(pressedKey)
if not isRunning or waitingForNext then return end
if currentIndex < 1 or currentIndex > #deck then return end
local card = deck[currentIndex]
if pressedKey == card.keybind or pressedKey == card.keybind2 then
tinsert(correctPile, card)
FlashGlow()
promptText:SetText("|cFF44DD44Correct!|r")
answerLabel:Hide()
answerKeybind:Hide()
if BoundToLearn.db.game.soundEnabled then
PlaySound(891)
end
waitingForNext = true
-- Fly to correct heap, then advance
cardIcon:SetAlpha(0)
cardBorder:SetAlpha(0)
FlyToHeap(card.texture, "correct", correctHeapAnchor, function()
UpdateCounts()
end)
ScheduleAdvance(0.5)
else
tinsert(wrongPile, card)
totalWrongAnswers = totalWrongAnswers + 1
cardBorder:SetVertexColor(0.9, 0.2, 0.2, 1)
promptText:SetText("|cFFDD4444Not quite|r")
answerLabel:SetText("Correct keybind:")
answerLabel:Show()
answerKeybind:SetText("|cFFFFCC00" .. FormatKeybind(card.keybind) .. "|r")
answerKeybind:Show()
if BoundToLearn.db.game.soundEnabled then
PlaySound(846)
end
waitingForNext = true
-- Fly to wrong heap after a pause to absorb the correct answer
CancelWrongFlyTimer()
pendingWrongIcon = { texture = card.texture, anchorFrame = wrongHeapAnchor }
wrongFlyTimer = C_Timer.NewTimer(2.0, function()
wrongFlyTimer = nil
pendingWrongIcon = nil
if isRunning then
cardIcon:SetAlpha(0)
cardBorder:SetAlpha(0)
FlyToHeap(card.texture, "wrong", wrongHeapAnchor, function()
UpdateCounts()
end)
end
end)
ScheduleAdvance(3.0)
end
UpdateCounts()
end
function KeybindQuiz:NextCard()
if not isRunning then return end
-- Restore card visibility for next card
cardIcon:SetAlpha(1)
cardBorder:SetAlpha(1)
currentIndex = currentIndex + 1
if currentIndex > #deck then
self:FinishRound()
return
end
ShowCurrentCard()
end
function KeybindQuiz:FinishRound()
if #wrongPile == 0 then
quizFinished = true
cardIcon:SetTexture(nil)
cardIcon:SetAlpha(1)
cardBorder:Hide()
glowBorder:Hide()
cardFrame:SetScript("OnUpdate", nil)
local total = #correctPile
local elapsed = GetTime() - quizStartTime
quizFrame:SetScript("OnUpdate", nil)
local mins = mfloor(elapsed / 60)
local secs = mfloor(elapsed % 60)
local tenths = mfloor((elapsed * 10) % 10)
local timeStr
if mins > 0 then
timeStr = sformat("%d:%02d.%d", mins, secs, tenths)
else
timeStr = sformat("%d.%ds", secs, tenths)
end
timerText:SetText(timeStr)
cardName:SetText("|cFF44DD44Quiz Complete!|r")
if roundNumber == 1 then
promptText:SetText(sformat("Perfect: all %d correct on the first try (%s)", total, timeStr))
else
promptText:SetText(sformat("All %s learned in %d rounds (%s)",
Utils.Count(total, "ability", "abilities"), roundNumber, timeStr))
end
promptText:SetTextColor(0.7, 0.7, 0.7)
answerLabel:Hide()
answerKeybind:Hide()
progressText:SetText("Any key closes")
progressText:SetTextColor(0.5, 0.5, 0.5)
quizFrame.againBtn:Show()
quizFrame.closeBtn:Show()
if not isPractice and ns.Stats then
ns.Stats:RecordQuizSession({
totalAbilities = total,
rounds = roundNumber,
elapsed = elapsed,
wrongAnswers = totalWrongAnswers,
})
end
if BoundToLearn.db.game.soundEnabled then
PlaySound(888)
end
else
roundNumber = roundNumber + 1
isReviewRound = true
local reviewCount = #wrongPile
CancelWrongFlyTimer()
CompletePendingFly()
pendingWrongIcon = nil
wipe(deck)
for _, card in ipairs(wrongPile) do
tinsert(deck, card)
end
wipe(wrongPile)
ClearHeapIcons("wrong")
Shuffle(deck)
currentIndex = 0
cardIcon:SetTexture(nil)
cardIcon:SetAlpha(1)
cardBorder:SetAlpha(1)
cardBorder:SetVertexColor(0.8, 0.6, 0.2, 0.6)
glowBorder:Hide()
cardFrame:SetScript("OnUpdate", nil)
cardName:SetText("")
promptText:SetText(sformat("|cFFFFCC00Reviewing %d to practice...|r", reviewCount))
promptText:SetTextColor(0.7, 0.7, 0.7)
answerLabel:Hide()
answerKeybind:Hide()
roundText:SetText(sformat("Round %d", roundNumber))
progressText:SetText("")
UpdateCounts()
waitingForNext = true
ScheduleAdvance(1.5)
end
end
function KeybindQuiz:Start()
if InCombatLockdown() then
BoundToLearn:Print("Cannot start quiz during combat.")
return
end
if isRunning then return end
if quizFrame and (quizFrame:IsShown() or quizFrame.readyFrame:IsShown()) then return end
local gameInput = _G["BoundToLearnGameInput"]
if gameInput and gameInput:IsShown() then
BoundToLearn:Print("Stop the game first before starting the quiz.")
return
end
DiscoverCards()
if #allCards == 0 then
BoundToLearn:Print("No quizzable abilities found. Check your action bars and keybinds.")
return
end
if not quizFrame then CreateQuizUI() end
local readyFrame = quizFrame.readyFrame
readyFrame.desc:SetText(sformat("Quizzing %s from your action bars.", Utils.Count(#allCards, "ability", "abilities")))
local function StartQuiz(practice)
PlaySound(SOUNDKIT.IG_MAINMENU_OPTION_CHECKBOX_ON)
isPractice = practice
readyFrame:Hide()
KeybindQuiz:BeginRound()
end
quizFrame.timedBtn:SetScript("OnClick", function() StartQuiz(false) end)
quizFrame.practiceBtn:SetScript("OnClick", function() StartQuiz(true) end)
quizFrame.timedBtn:Show()
quizFrame.practiceBtn:Show()
dimmer:Show()
readyFrame:Show()
end
-- Close the start screen without starting (Esc, the layout check).
function KeybindQuiz:CancelReady()
if not quizFrame then return end
quizFrame.readyFrame:Hide()
dimmer:Hide()
end
-- Layout check: the round screen at its fullest (a long name, a wrong answer
-- revealed, both piles filled) without taking the bars or the keyboard.
local PREVIEW_ICON = "Interface\\Icons\\INV_Misc_QuestionMark"
function KeybindQuiz:LayoutPreview(show)
if isRunning then return end
if not show then
if not quizFrame then return end
ClearHeapIcons("correct")
ClearHeapIcons("wrong")
quizFrame:Hide()
dimmer:Hide()
return
end
if not quizFrame then CreateQuizUI() end
RevealCard({ texture = PREVIEW_ICON, name = "A Long Ability Name For The Layout Check" })
roundText:SetText("Round 1")
progressText:SetText("3 / 11")
timerText:SetText("0:42")
promptText:SetText("|cFFDD4444Not quite|r")
answerLabel:SetText("Correct keybind:")
answerLabel:Show()
answerKeybind:SetText("|cFFFFCC00S-4|r")
answerKeybind:Show()
correctHeapLabel:SetText("Correct")
wrongHeapLabel:SetText("Wrong")
correctHeapLabel:Show()
wrongHeapLabel:Show()
correctCountText:SetText("8")
wrongCountText:SetText("8")
for _ = 1, 8 do
AddHeapIcon(PREVIEW_ICON, "correct", correctHeapAnchor)
AddHeapIcon(PREVIEW_ICON, "wrong", wrongHeapAnchor)
end
dimmer:Show()
quizFrame:Show()
end
function KeybindQuiz:BeginRound()
wipe(deck)
wipe(correctPile)
wipe(wrongPile)
ClearHeapIcons("correct")
ClearHeapIcons("wrong")
for _, card in ipairs(allCards) do
tinsert(deck, card)
end
Shuffle(deck)
currentIndex = 0
roundNumber = 1
waitingForNext = false
quizFinished = false
isReviewRound = false
totalWrongAnswers = 0
isRunning = true
quizStartTime = GetTime()
quizFrame.againBtn:Hide()
quizFrame.closeBtn:Hide()
quizFrame:Show()
quizFrame:SetScript("OnUpdate", function()
if not isRunning then return end
local elapsed = GetTime() - quizStartTime
local mins = mfloor(elapsed / 60)
local secs = mfloor(elapsed % 60)
timerText:SetText(sformat("%d:%02d", mins, secs))
end)
-- The action bars are hidden during the quiz, so end it if combat starts: the
-- player needs their bars back to fight.
quizFrame:RegisterEvent("PLAYER_REGEN_DISABLED")