Repository navigation
Expand file tree
/
Copy pathGameUI.lua
More file actions
5056 lines (4527 loc) · 186 KB
/
Copy pathGameUI.lua
File metadata and controls
5056 lines (4527 loc) · 186 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 GameUI = {}
ns.GameUI = GameUI
local Utils = ns.Utils
local Theme = ns.Theme
local sformat = Utils.sformat
local mmin, mmax = Utils.mmin, Utils.mmax
local mabs = Utils.mabs
local mfloor = Utils.mfloor
local tinsert = Utils.tinsert
local tremove = Utils.tremove
local ipairs = Utils.ipairs
local CreateFrame = Utils.CreateFrame
local GetTime = Utils.GetTime
local wipe = Utils.wipe
local PlayUISound = Utils.PlayUISound
local SOUND_CLICK = Utils.SOUND_CLICK
local UIParent = UIParent
local GameTooltip = GameTooltip
local SendChatMessage = SendChatMessage
local IsMouseButtonDown = IsMouseButtonDown
local gameOverlay
local controlBar
local scoreFrame, scoreText, comboText, multiplierText, difficultyText, timerText
local modifierRow, modifierBtn, modifierDropdown
local achievementPanel
local songSelect
local mainMenu
local pauseOverlay, pauseText
local notePool = {}
local resultPool = {}
local hitZonePool = {}
local countdownFrame, countdownText, countdownPop, countdownPopAG
local usingNativeCountdown = false
local compBarFrame
local compBarButtons = {}
local dangerOverlay
local dangerPulseAG
local projectilePool = {}
local NOTE_POOL_SIZE = 30
local RESULT_POOL_SIZE = 10
local NOTE_SIZE = 40
GameUI.NOTE_SIZE = NOTE_SIZE -- Game:SeparateColumns keeps notes in one column this far apart
local ICON_CROP = 0.07
local COMP_BTN_SIZE = 48
local COMP_BTN_GAP = 6
local isInitialized = false
local RESULT_COLORS = {
perfect = { 0.2, 1.0, 0.2 },
great = { 1.0, 0.9, 0.2 },
good = { 1.0, 0.6, 0.1 },
miss = { 0.6, 0.2, 0.2 },
redHerring = { 0.8, 0.1, 0.1 },
}
local RESULT_LABELS = {
perfect = "PERFECT",
great = "GREAT",
good = "GOOD",
miss = "MISS",
redHerring = "FAKE",
}
local DIFFICULTIES = { "Easy", "Medium", "Hard", "Extreme" }
local DIFF_COLORS = {
Easy = { 0.30, 0.85, 0.30 },
Medium = { 1.00, 0.82, 0.00 },
Hard = { 1.00, 0.50, 0.10 },
Extreme = { 0.90, 0.15, 0.15 },
}
-- Row metrics for the achievement/trophy lists, shared by the refresh and
-- resize helpers so the panel can size itself to its content.
local ACH_ROW_H, ACH_ROW_PAD = 36, 2
local TROPHY_ROW_H, TROPHY_ROW_PAD = 40, 3
local ACH_PANEL_MAX_H = 420
-- Side tab fill: accent-dim when its panel is open, lit on hover, else neutral.
local function PaintSideTab(tab)
if tab.active then
Theme.SetFillColor(tab, Theme.C.ACCENT_DIM)
elseif tab.hovered then
Theme.SetFillColor(tab, Theme.C.BTN_HOVER)
else
Theme.SetFillColor(tab, Theme.C.BTN_NORMAL)
end
end
-- Modifier opener fill: accent-dim while its dropdown is open, lit on hover.
local function PaintModifierBtn(hovered)
if not modifierBtn then return end
if modifierDropdown and modifierDropdown:IsShown() then
Theme.SetFillColor(modifierBtn, Theme.C.ACCENT_DIM)
elseif hovered then
Theme.SetFillColor(modifierBtn, Theme.C.BTN_HOVER)
else
Theme.SetFillColor(modifierBtn, Theme.C.BTN_NORMAL)
end
end
local function ModifierRowClick(self)
local Mods = ns.Modifiers
if not Mods or not self.mod then return end
PlayUISound(SOUND_CLICK)
Mods:Toggle(self.mod.id)
GameUI:UpdateModifierButton()
GameUI:BuildModifierDropdown()
end
local function ModifierRowTooltip(self)
local m = self.mod
if not m then return end
GameTooltip:SetText(m.name)
GameTooltip:AddLine(m.desc, 1, 1, 1, true)
if m.descExtra then
GameTooltip:AddLine(m.descExtra, 0.6, 0.8, 1.0, true)
end
if self.isRequired then
local diff = BoundToLearn.db.game.difficulty
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Required for " .. diff .. " difficulty", 0.8, 0.8, 0.4, true)
elseif self.locked and m.unlockHint then
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Unlock: " .. m.unlockHint, 1, 0.5, 0.2, true)
end
end
function GameUI:Initialize()
if isInitialized then return end
isInitialized = true
self:CreateOverlay()
self:CreateNotePool()
self:CreateResultPool()
self:CreateScoreDisplay()
self:CreateControlBar()
self:CreatePauseOverlay()
self:CreateCountdown()
self:CreateDangerOverlay()
self:CreateStreakTitle()
end
function GameUI:CreateOverlay()
gameOverlay = CreateFrame("Frame", "BoundToLearnGameOverlay", UIParent)
gameOverlay:SetAllPoints()
gameOverlay:SetFrameStrata("FULLSCREEN")
gameOverlay:SetFrameLevel(50)
gameOverlay:Hide()
end
function GameUI:CreateNotePool()
for i = 1, NOTE_POOL_SIZE do
local f = CreateFrame("Frame", "BoundToLearnNote" .. i, gameOverlay)
f:SetSize(NOTE_SIZE, NOTE_SIZE)
f:SetFrameStrata("FULLSCREEN")
f:SetFrameLevel(60)
f:Hide()
local icon = f:CreateTexture(nil, "ARTWORK")
icon:SetPoint("TOPLEFT", 2, -2)
icon:SetPoint("BOTTOMRIGHT", -2, 2)
icon:SetTexCoord(ICON_CROP, 1 - ICON_CROP, ICON_CROP, 1 - ICON_CROP)
f.icon = icon
-- Rounded border overlay
local border = f:CreateTexture(nil, "OVERLAY")
border:SetPoint("TOPLEFT", -1, 1)
border:SetPoint("BOTTOMRIGHT", 1, -1)
border:SetAtlas("UI-HUD-ActionBar-IconFrame-Mouseover")
border:SetVertexColor(1, 1, 1, 0.8)
f.border = border
local label = f:CreateFontString(nil, "OVERLAY")
label:SetFont("Fonts\\FRIZQT__.TTF", 12, "OUTLINE")
label:SetPoint("TOPRIGHT", -2, -2)
label:SetShadowOffset(1, -1)
label:SetTextColor(1, 1, 1)
f.label = label
-- Bomb indicator: skull + fuse spark
local bombIcon = f:CreateTexture(nil, "OVERLAY", nil, 2)
bombIcon:SetSize(20, 20)
bombIcon:SetPoint("TOPLEFT", -6, 6)
bombIcon:SetAtlas("Warfronts-BaseMapIcons-Horde-Attacked-Large")
bombIcon:Hide()
f.bombIcon = bombIcon
local fuse = f:CreateTexture(nil, "OVERLAY", nil, 3)
fuse:SetSize(10, 10)
fuse:SetPoint("CENTER", bombIcon, "TOP", 2, 0)
fuse:SetAtlas("Spark")
fuse:SetBlendMode("ADD")
fuse:Hide()
f.fuse = fuse
-- Bomb blink animation (alpha pulse on the whole frame)
local blinkAG = f:CreateAnimationGroup()
blinkAG:SetLooping("BOUNCE")
local blink = blinkAG:CreateAnimation("Alpha")
blink:SetFromAlpha(1)
blink:SetToAlpha(0.4)
blink:SetDuration(0.25)
blink:SetSmoothing("IN_OUT")
f.blinkAG = blinkAG
-- Fuse spark shimmer
local fuseAG = fuse:CreateAnimationGroup()
fuseAG:SetLooping("BOUNCE")
local fuseAlpha = fuseAG:CreateAnimation("Alpha")
fuseAlpha:SetFromAlpha(1)
fuseAlpha:SetToAlpha(0.2)
fuseAlpha:SetDuration(0.15)
local fuseScale = fuseAG:CreateAnimation("Scale")
fuseScale:SetScaleFrom(1, 1)
fuseScale:SetScaleTo(1.4, 1.4)
fuseScale:SetDuration(0.15)
f.fuseAG = fuseAG
f.inUse = false
notePool[i] = f
end
end
function GameUI:CreateResultPool()
for i = 1, RESULT_POOL_SIZE do
local f = gameOverlay:CreateFontString(nil, "OVERLAY")
f:SetFont("Fonts\\FRIZQT__.TTF", 22, "OUTLINE")
f:Hide()
f.inUse = false
local ag = f:CreateAnimationGroup()
local translate = ag:CreateAnimation("Translation")
translate:SetOffset(0, 80)
translate:SetDuration(0.7)
translate:SetSmoothing("OUT")
f.animGroup = ag
resultPool[i] = f
end
end
function GameUI:CreateScoreDisplay()
local IsShiftKeyDown = IsShiftKeyDown
scoreFrame = CreateFrame("Frame", "BoundToLearnScoreHUD", UIParent)
scoreFrame:SetSize(240, 178)
scoreFrame:SetPoint("TOP", UIParent, "TOP", 0, -30)
scoreFrame:SetFrameStrata("FULLSCREEN")
scoreFrame:SetFrameLevel(70)
Theme.StylePanel(scoreFrame, 0.94)
scoreFrame:EnableMouse(true)
scoreFrame:SetMovable(true)
scoreFrame:SetClampedToScreen(true)
scoreFrame:Hide()
scoreFrame:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" and IsShiftKeyDown() then
self:StartMoving()
self.isMoving = true
end
end)
scoreFrame:SetScript("OnMouseUp", function(self)
if self.isMoving then
self:StopMovingOrSizing()
self.isMoving = false
end
end)
-- Accent line
local accent = scoreFrame:CreateTexture(nil, "ARTWORK")
accent:SetPoint("TOPLEFT", 6, -5)
accent:SetPoint("TOPRIGHT", -6, -5)
accent:SetHeight(2)
accent:SetColorTexture(Theme.RGB(Theme.C.ACCENT, 0.7))
-- Close button (top-right, below accent)
local closeBtn = Theme.CreateCloseButton(scoreFrame, function()
if ns.Game and ns.Game:IsRunning() then
ns.Game:Stop()
end
scoreFrame:Hide()
end)
closeBtn:SetSize(18, 18)
closeBtn:SetPoint("TOPRIGHT", -6, -8)
-- SCORE label (left) and Timer (right) on top row
local scoreLabel = scoreFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
scoreLabel:SetPoint("TOPLEFT", 14, -11)
scoreLabel:SetText("SCORE")
scoreLabel:SetTextColor(0.55, 0.55, 0.55)
timerText = scoreFrame:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
timerText:SetPoint("TOPRIGHT", -30, -11)
timerText:SetTextColor(0.7, 0.7, 0.7)
timerText:SetText("")
-- Score number
scoreText = scoreFrame:CreateFontString(nil, "OVERLAY")
scoreText:SetFont("Fonts\\FRIZQT__.TTF", 28, "OUTLINE")
scoreText:SetPoint("TOP", 0, -24)
scoreText:SetText("0")
scoreText:SetTextColor(1, 0.84, 0)
-- Divider below score
local divider1 = scoreFrame:CreateTexture(nil, "ARTWORK")
divider1:SetPoint("LEFT", 14, 0)
divider1:SetPoint("RIGHT", -14, 0)
divider1:SetPoint("TOP", scoreText, "BOTTOM", 0, -4)
divider1:SetHeight(1)
divider1:SetColorTexture(0.3, 0.3, 0.3, 0.5)
-- Combo (left) and Multiplier (right)
comboText = scoreFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
comboText:SetPoint("TOPLEFT", divider1, "BOTTOMLEFT", 0, -5)
comboText:SetText("")
comboText:SetTextColor(0.8, 0.8, 0.8)
multiplierText = scoreFrame:CreateFontString(nil, "OVERLAY", "GameFontNormal")
multiplierText:SetPoint("TOPRIGHT", divider1, "BOTTOMRIGHT", 0, -5)
multiplierText:SetText("")
multiplierText:SetTextColor(1, 1, 1)
-- Personal best text (between score and difficulty)
local bestText = scoreFrame:CreateFontString(nil, "OVERLAY")
bestText:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
bestText:SetPoint("TOP", divider1, "BOTTOM", 0, -7)
bestText:SetTextColor(0.65, 0.55, 0.4)
bestText:SetText("")
scoreFrame.bestText = bestText
-- Rank icon (tinted achievement symbol next to best score, clickable to open trophies)
local rankBtn = CreateFrame("Button", nil, scoreFrame)
rankBtn:SetSize(18, 18)
rankBtn:SetPoint("LEFT", bestText, "RIGHT", 3, 0)
rankBtn:RegisterForClicks("LeftButtonUp")
rankBtn:Hide()
local rankTex = rankBtn:CreateTexture(nil, "OVERLAY")
rankTex:SetAllPoints()
rankTex:SetAtlas("UI-HUD-MicroMenu-Achievements-Mouseover")
rankBtn.tex = rankTex
rankBtn:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
local diff = BoundToLearn.db.game.difficulty
GameUI:ShowAchievementPanel("trophies", diff)
end)
rankBtn:SetScript("OnEnter", function(self)
if not self.rankData then return end
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText(sformat("|cFF%s%s|r", self.rankData.color, self.rankData.name))
local next = self.nextRank
if next then
GameTooltip:AddLine(sformat("Next: %s (%d pts)", next.name, next.threshold), 0.7, 0.7, 0.7)
else
GameTooltip:AddLine("Highest rank achieved", 0.7, 0.7, 0.7)
end
GameTooltip:AddLine(" ")
GameTooltip:AddLine("Left-click to view trophies", 0.5, 0.5, 0.5)
GameTooltip:Show()
end)
rankBtn:SetScript("OnLeave", function() GameTooltip:Hide() end)
scoreFrame.rankBtn = rankBtn
-- Divider above difficulty row
local divider2 = scoreFrame:CreateTexture(nil, "ARTWORK")
divider2:SetPoint("LEFT", 14, 0)
divider2:SetPoint("RIGHT", -14, 0)
divider2:SetPoint("TOP", divider1, "BOTTOM", 0, -24)
divider2:SetHeight(1)
divider2:SetColorTexture(0.3, 0.3, 0.3, 0.5)
-- Difficulty selector row (4 buttons)
local diffRow = CreateFrame("Frame", nil, scoreFrame)
diffRow:SetSize(220, 20)
diffRow:SetPoint("TOP", divider2, "BOTTOM", 0, -3)
scoreFrame.diffRow = diffRow
difficultyText = {}
for i, name in ipairs(DIFFICULTIES) do
local btn = CreateFrame("Button", nil, diffRow)
btn:SetSize(53, 18)
btn:SetPoint("LEFT", (i - 1) * 55 + 1, 0)
btn:SetNormalFontObject("GameFontNormalSmall")
btn:SetHighlightFontObject("GameFontHighlightSmall")
btn:SetText(name)
btn.diffName = name
Theme.Round(btn)
Theme.SetBarHeight(btn, 10)
Theme.SetBorderShown(btn, false)
Theme.SetFill(btn, 0.14, 0.13, 0.12, 0.85)
btn:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
-- Clear saved toggles for modifiers required by the OLD difficulty
local Mods = ns.Modifiers
if Mods then
local oldRequired = Mods.REQUIRED_MODIFIERS[BoundToLearn.db.game.difficulty]
if oldRequired then
local saved = BoundToLearn.db.game.modifiers
if saved then
for _, reqId in ipairs(oldRequired) do
saved[reqId] = nil
end
end
end
end
BoundToLearn.db.game.difficulty = name
GameUI:UpdateDifficultyButtons()
GameUI:UpdateBestText()
GameUI:UpdateModifierButton()
if modifierDropdown and modifierDropdown:IsShown() then
GameUI:BuildModifierDropdown()
end
end)
difficultyText[i] = btn
end
-- Modifier selector row
modifierRow = CreateFrame("Frame", nil, scoreFrame)
modifierRow:SetSize(220, 20)
modifierRow:SetPoint("TOP", diffRow, "BOTTOM", 0, -2)
scoreFrame.modifierRow = modifierRow
modifierBtn = CreateFrame("Button", nil, modifierRow)
modifierBtn:SetSize(220, 18)
modifierBtn:SetPoint("CENTER")
modifierBtn:SetNormalFontObject("GameFontNormalSmall")
modifierBtn:SetHighlightFontObject("GameFontHighlightSmall")
Theme.Round(modifierBtn)
Theme.SetBarHeight(modifierBtn, 10)
Theme.SetBorderShown(modifierBtn, false)
Theme.SetFillColor(modifierBtn, Theme.C.BTN_NORMAL)
modifierBtn:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
GameUI.modifierOpener = modifierBtn
GameUI:ToggleModifierDropdown()
end)
modifierBtn:HookScript("OnEnter", function() PaintModifierBtn(true) end)
modifierBtn:HookScript("OnLeave", function() PaintModifierBtn(false) end)
GameUI:UpdateModifierButton()
-- Sidebar tab anchored flush to the right edge of scoreFrame, centered vertically
local sideTab = CreateFrame("Button", nil, scoreFrame)
sideTab:SetSize(18, 80)
sideTab:SetPoint("LEFT", scoreFrame, "RIGHT", -3, 0)
Theme.StyleCard(sideTab, Theme.C.BTN_NORMAL)
Theme.SetBorderShown(sideTab, false)
local tabIcon = sideTab:CreateTexture(nil, "ARTWORK")
tabIcon:SetSize(12, 12)
tabIcon:SetPoint("CENTER")
tabIcon:SetAtlas("UI-HUD-MicroMenu-Achievements-Mouseover")
sideTab.icon = tabIcon
sideTab:SetScript("OnClick", function()
PlayUISound(SOUND_CLICK)
GameUI:ToggleAchievementPanel()
end)
sideTab:SetScript("OnEnter", function(self)
self.hovered = true
PaintSideTab(self)
end)
sideTab:SetScript("OnLeave", function(self)
self.hovered = false
PaintSideTab(self)
end)
Theme.DelayedTooltip(sideTab, function()
GameTooltip:SetText("Achievements")
end)
scoreFrame.sideTab = sideTab
-- Leaderboard tab anchored flush to the left edge of scoreFrame
local lbTab = CreateFrame("Button", nil, scoreFrame)
lbTab:SetSize(18, 80)
lbTab:SetPoint("RIGHT", scoreFrame, "LEFT", 3, 0)
Theme.StyleCard(lbTab, Theme.C.BTN_NORMAL)
Theme.SetBorderShown(lbTab, false)
local lbIcon = lbTab:CreateTexture(nil, "ARTWORK")
lbIcon:SetSize(12, 12)
lbIcon:SetPoint("CENTER")
lbIcon:SetAtlas("UI-HUD-MicroMenu-GuildCommunities-Mouseover")
lbTab.icon = lbIcon
lbTab:SetScript("OnClick", function(self)
PlayUISound(SOUND_CLICK)
if ns.LeaderboardUI then ns.LeaderboardUI:Toggle() end
local lbf = _G.BoundToLearnLeaderboard
if lbf and not lbf._btlTabHooked then
lbf._btlTabHooked = true
lbf:HookScript("OnShow", function() GameUI:RefreshSideTabs() end)
lbf:HookScript("OnHide", function() GameUI:RefreshSideTabs() end)
end
GameUI:RefreshSideTabs()
end)
lbTab:SetScript("OnEnter", function(self)
self.hovered = true
PaintSideTab(self)
end)
lbTab:SetScript("OnLeave", function(self)
self.hovered = false
PaintSideTab(self)
end)
Theme.DelayedTooltip(lbTab, function()
GameTooltip:SetText("Leaderboard")
end, "ANCHOR_LEFT")
scoreFrame.lbTab = lbTab
end
function GameUI:RefreshSideTabs()
if not scoreFrame then return end
local st = scoreFrame.sideTab
if st then
st.active = achievementPanel and achievementPanel:IsShown() or false
PaintSideTab(st)
end
local lb = scoreFrame.lbTab
if lb then
local lbf = _G.BoundToLearnLeaderboard
lb.active = lbf and lbf:IsShown() or false
PaintSideTab(lb)
end
end
function GameUI:UpdateDifficultyButtons()
if not difficultyText then return end
local current = BoundToLearn.db.game.difficulty
for _, btn in ipairs(difficultyText) do
local c = DIFF_COLORS[btn.diffName]
if btn.diffName == current then
Theme.SetFill(btn, c[1] * 0.55, c[2] * 0.55, c[3] * 0.55, 0.9)
btn:GetFontString():SetTextColor(c[1], c[2], c[3])
else
Theme.SetFill(btn, 0.14, 0.13, 0.12, 0.85)
btn:GetFontString():SetTextColor(c[1] * 0.5, c[2] * 0.5, c[3] * 0.5)
end
end
end
function GameUI:UpdateBestText()
if not scoreFrame or not scoreFrame.bestText then return end
local diff = BoundToLearn.db.game.difficulty
local db = BoundToLearn.db.stats.difficultyBest
local best = db and db[diff]
local rb = scoreFrame.rankBtn
if best and best.highestScore > 0 then
local Ach = ns.Achievements
local rank = Ach and Ach:GetRank(best.highestScore)
scoreFrame.bestText:SetText(sformat("Best: |cFFFFCC00%d|r", best.highestScore))
if rank and rank.threshold > 0 and rb then
local c = rank.rgb
rb.tex:SetVertexColor(c[1], c[2], c[3], 1)
rb.rankData = rank
rb.nextRank = Ach:GetNextRank(best.highestScore)
rb:Show()
elseif rb then
rb:Hide()
end
else
scoreFrame.bestText:SetText("")
if rb then rb:Hide() end
end
end
function GameUI:UpdateModifierButton()
if not modifierBtn then return end
local Mods = ns.Modifiers
if not Mods then return end
modifierBtn:SetText("Modifiers")
local count = Mods:GetActiveCount()
local fs = modifierBtn:GetFontString()
if fs then
if count > 0 then
fs:SetTextColor(Theme.RGB(Theme.C.ACCENT_BRIGHT))
else
fs:SetTextColor(0.7, 0.7, 0.7)
end
end
end
function GameUI:ToggleModifierDropdown()
if modifierDropdown and modifierDropdown:IsShown() then
modifierDropdown:Hide()
return
end
self:BuildModifierDropdown()
end
function GameUI:BuildModifierDropdown()
local Mods = ns.Modifiers
if not Mods then return end
if not modifierDropdown then
modifierDropdown = CreateFrame("Frame", nil, UIParent)
modifierDropdown:Hide()
Theme.StylePanel(modifierDropdown, 0.97)
modifierDropdown:SetFrameStrata("FULLSCREEN_DIALOG")
modifierDropdown:SetFrameLevel(100)
modifierDropdown:SetClampedToScreen(true)
modifierDropdown.rows = {}
modifierDropdown:HookScript("OnShow", function() PaintModifierBtn(modifierBtn:IsMouseOver()) end)
modifierDropdown:HookScript("OnHide", function() PaintModifierBtn(modifierBtn:IsMouseOver()) end)
end
local opener = GameUI.modifierOpener or modifierBtn
local list = Mods.MODIFIER_LIST
local rowH = 26
local pad = 6
local rowW = 208
local ddH = #list * rowH + pad * 2
modifierDropdown:SetSize(220, ddH)
modifierDropdown:ClearAllPoints()
-- Drop down from the opener, or flip above it when there is not enough room
-- below; SetClampedToScreen keeps the remaining edges on-screen.
local opScale = opener:GetEffectiveScale() or 1
local ddScale = modifierDropdown:GetEffectiveScale() or 1
if (opener:GetBottom() or 0) * opScale < ddH * ddScale + 8 then
modifierDropdown:SetPoint("BOTTOMLEFT", opener, "TOPLEFT", 0, 2)
else
modifierDropdown:SetPoint("TOPLEFT", opener, "BOTTOMLEFT", 0, -2)
end
local active = Mods:GetActive()
local rows = modifierDropdown.rows
for i, m in ipairs(list) do
local row = rows[i]
if not row then
row = Theme.CreateToggle(modifierDropdown, "", nil, rowW)
-- Locked/required rows are Disabled; enable motion scripts so they
-- still fire OnEnter for the unlock tooltip and the hover wash.
row:SetMotionScriptsWhileDisabled(true)
Theme.DelayedTooltip(row, ModifierRowTooltip)
-- Subtle accent hover wash behind the row (same treatment as the
-- minimap menu), shown for locked and unlocked rows alike.
local hl = CreateFrame("Frame", nil, modifierDropdown)
hl:SetFrameLevel(modifierDropdown:GetFrameLevel())
hl:SetPoint("TOPLEFT", row, "TOPLEFT", -2, 1)
hl:SetPoint("BOTTOMRIGHT", row, "BOTTOMRIGHT", 2, -1)
Theme.Round(hl)
Theme.SetBarHeight(hl, 10)
Theme.SetBorderShown(hl, false)
Theme.SetFillColor(hl, Theme.C.ACCENT, 0)
row.hl = hl
row:HookScript("OnEnter", function(self) Theme.SetFillColor(self.hl, Theme.C.ACCENT, 0.15) end)
row:HookScript("OnLeave", function(self) Theme.SetFillColor(self.hl, Theme.C.ACCENT, 0) end)
rows[i] = row
end
local unlocked = Mods:IsUnlocked(m.id)
local isActive = active[m.id]
local isRequired = Mods:IsRequired(m.id)
row.mod = m
row.isRequired = isRequired
row.locked = not unlocked
row.Text:SetText(m.name)
row:ClearAllPoints()
row:SetPoint("TOPLEFT", modifierDropdown, "TOPLEFT", pad, -(pad + (i - 1) * rowH))
if isRequired then
row:Disable()
row:SetChecked(true)
row:SetScript("OnClick", nil)
elseif unlocked then
row:Enable()
row:SetChecked(isActive and true or false)
row:SetScript("OnClick", ModifierRowClick)
else
row:Disable()
row:SetChecked(false)
row:SetScript("OnClick", nil)
end
row:Show()
end
for i = #list + 1, #rows do
rows[i]:Hide()
end
modifierDropdown:Show()
end
function GameUI:UpdateTimer(remaining)
local str, tr, tg, tb = "", 0.7, 0.7, 0.7
if remaining then
str = sformat("%d:%02d", mfloor(remaining / 60), mfloor(remaining % 60))
if remaining <= 10 then
tr, tg, tb = 1, 0.3, 0.3
elseif remaining <= 30 then
tr, tg, tb = 1, 0.85, 0.3
end
end
if timerText then
timerText:SetText(str)
timerText:SetTextColor(tr, tg, tb)
end
local hf = self.healthFrame
if hf then
hf.timerFS:SetText(str)
hf.timerFS:SetTextColor(tr, tg, tb)
end
end
function GameUI:CreateControlBar()
controlBar = CreateFrame("Frame", nil, scoreFrame)
controlBar:SetPoint("TOPLEFT", scoreFrame.modifierRow, "BOTTOMLEFT", 0, -4)
controlBar:SetPoint("TOPRIGHT", scoreFrame.modifierRow, "BOTTOMRIGHT", 0, -4)
controlBar:EnableMouse(true)
local pauseBtn = Theme.CreateButton(controlBar, "Pause", 105, 22)
pauseBtn:SetPoint("TOPLEFT", scoreFrame.modifierRow, "BOTTOMLEFT", -1, -4)
pauseBtn:SetScript("OnClick", function()
if ns.Game then
if ns.Game:IsPaused() then
ns.Game:Resume()
else
ns.Game:Pause()
end
end
end)
controlBar.pauseBtn = pauseBtn
local stopBtn = Theme.CreateButton(controlBar, "Stop", 105, 22)
stopBtn:SetPoint("TOPRIGHT", scoreFrame.modifierRow, "BOTTOMRIGHT", 1, -4)
stopBtn:SetScript("OnClick", function()
if ns.Game then ns.Game:Stop() end
end)
controlBar.stopBtn = stopBtn
-- Start button (shown in ready state, hidden during gameplay)
local startBtn = Theme.CreateAccentButton(controlBar, "Start", 220, 22)
startBtn:SetPoint("TOP", 0, 0)
startBtn:SetScript("OnClick", function()
BoundToLearn.db.game.mode = "timed"
if BoundToLearn then BoundToLearn:ToggleGame() end
end)
startBtn:Hide()
controlBar.startBtn = startBtn
-- Practice button (below Start, shown in ready state)
local practiceBtn = Theme.CreateAccentButton(controlBar, "Practice", 108, 22)
practiceBtn:SetPoint("TOPLEFT", startBtn, "BOTTOMLEFT", 0, -2)
practiceBtn:SetScript("OnClick", function()
BoundToLearn.db.game.mode = "practice"
if BoundToLearn then BoundToLearn:ToggleGame() end
end)
practiceBtn:HookScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText("Practice Mode")
GameTooltip:AddLine("No time limit. Play until you stop.", 1, 1, 1, true)
GameTooltip:Show()
end)
practiceBtn:HookScript("OnLeave", function() GameTooltip:Hide() end)
practiceBtn:Hide()
controlBar.practiceBtn = practiceBtn
-- Competitive button (right of Practice, shown in ready state)
local compBtn = Theme.CreateAccentButton(controlBar, "Competitive", 108, 22)
compBtn:SetPoint("TOPRIGHT", startBtn, "BOTTOMRIGHT", 0, -2)
compBtn:SetScript("OnClick", function()
BoundToLearn.db.game.mode = "competitive"
if BoundToLearn then BoundToLearn:ToggleGame() end
end)
compBtn:HookScript("OnEnter", function(self)
GameTooltip:SetOwner(self, "ANCHOR_RIGHT")
GameTooltip:SetText("Competitive Mode")
GameTooltip:AddLine("15 fixed lanes (1-5, Shift, Ctrl), same for everyone.", 1, 1, 1, true)
GameTooltip:AddLine("Bomb notes destroy your lane if missed.", 1, 0.8, 0.3, true)
GameTooltip:AddLine("Extreme forces angled notes.", 0.6, 0.8, 1.0, true)
GameTooltip:AddLine("Pausing resets your score to zero.", 1, 0.5, 0.5, true)
GameTooltip:Show()
end)
compBtn:HookScript("OnLeave", function() GameTooltip:Hide() end)
compBtn:Hide()
controlBar.compBtn = compBtn
end
-- =====================================================================
-- Song select carousel: the game's ready-state menu. Pick a track and a
-- difficulty (deterministic per-difficulty charts), see per-song bests to
-- boast about, then Start / Practice / Competitive.
-- =====================================================================
local function SongBestScore(key, diff)
local ss = BoundToLearn.db.game.songScores
return (ss and ss[key] and ss[key][diff]) or 0
end
-- Best fraction (0-1) of a track the player has ever reached, across difficulties.
-- Song bubble insets: the progress ring, and the title when there is no ring.
local DONUT_LEFT, TITLE_LEFT = 8, 12
local function SongBestProgress(key)
local sp = BoundToLearn.db.game.songProgress
return (sp and sp[key]) or 0
end
local SONG_HISTORY_MAX = 8
function GameUI:RecordSongScore(score, accuracy, maxCombo)
local db = BoundToLearn.db.game
local key, diff = db.songKey, db.difficulty
if not key or not score then return false end
db.songScores = db.songScores or {}
db.songScores[key] = db.songScores[key] or {}
local prevBest = db.songScores[key][diff] or 0
local isNewBest = score > prevBest
if isNewBest then db.songScores[key][diff] = score end
-- Persisted per-song, per-difficulty attempt history (survives reloads) so the
-- results screen can chart this run against previous attempts.
db.songHistory = db.songHistory or {}
db.songHistory[key] = db.songHistory[key] or {}
local hist = db.songHistory[key][diff] or {}
hist[#hist + 1] = score
while #hist > SONG_HISTORY_MAX do tremove(hist, 1) end
db.songHistory[key][diff] = hist
-- Richer per-track, per-difficulty stats for the Tracks stats view: play count and
-- best accuracy / combo (best score already lives in songScores).
db.songStats = db.songStats or {}
db.songStats[key] = db.songStats[key] or {}
local st = db.songStats[key][diff] or { plays = 0, bestAccuracy = 0, bestCombo = 0 }
st.plays = (st.plays or 0) + 1
if accuracy and accuracy > (st.bestAccuracy or 0) then st.bestAccuracy = accuracy end
if maxCombo and maxCombo > (st.bestCombo or 0) then st.bestCombo = maxCombo end
db.songStats[key][diff] = st
-- Snapshot for ShowResultsOnSelect (prevBest is the best before this run).
self.songCompare = { prevBest = prevBest, score = score, isNewBest = isNewBest, history = hist }
return isNewBest
end
function GameUI:RecordSongProgress(key, frac)
if not key or not frac then return end
local db = BoundToLearn.db.game
db.songProgress = db.songProgress or {}
if (db.songProgress[key] or 0) < frac then
db.songProgress[key] = frac
end
if songSelect then songSelect.donutDirty = true end
end
-- Fill colour ramps with how full the bar is: green when barely filled (easy) through
-- yellow and orange to red when nearly full (hard).
local DIFF_RAMP = {
{ 0.00, 0.35, 0.82, 0.35 }, -- green
{ 0.38, 0.92, 0.86, 0.22 }, -- yellow
{ 0.68, 0.96, 0.52, 0.14 }, -- orange
{ 1.00, 0.95, 0.20, 0.14 }, -- red
}
local function DiffRampColor(frac)
frac = mmax(0, mmin(1, frac))
for i = 2, #DIFF_RAMP do
local a, b = DIFF_RAMP[i - 1], DIFF_RAMP[i]
if frac <= b[1] then
local t = (frac - a[1]) / (b[1] - a[1])
return a[2] + (b[2] - a[2]) * t, a[3] + (b[3] - a[3]) * t, a[4] + (b[4] - a[4]) * t
end
end
local last = DIFF_RAMP[#DIFF_RAMP]
return last[2], last[3], last[4]
end
-- Difficulty meter: a dark rounded track holding Blizzard's cast-bar fill, revealed to
-- the rating (fuller = harder) and coloured by the ramp above. The rounded track IS the
-- edge -- no ornate cast-bar frame, whose fixed padding leaves an extra ring on a small bar.
local CAST_FILL_TEX = "Interface\\CastingBar\\UI-CastingBar-Fill"
local function MakeDiffBar(parent, w, h)
local frame = CreateFrame("Frame", nil, parent)
frame:SetSize(w, h)
Theme.Round(frame)
Theme.SetBarHeight(frame, h)
Theme.SetFill(frame, 0.10, 0.04, 0.04, 1) -- dark ember track
Theme.SetBorderColor(frame, 0, 0, 0, 0.85)
frame:SetClipsChildren(true)
local bar = CreateFrame("StatusBar", nil, frame)
bar:SetPoint("TOPLEFT", 4, -2)
bar:SetPoint("BOTTOMRIGHT", -4, 2)
bar:SetMinMaxValues(0, 10)
if C_Texture.GetAtlasInfo("ui-castingbar-filling-standard") then
bar:SetStatusBarTexture(bar:CreateTexture())
bar:GetStatusBarTexture():SetAtlas("ui-castingbar-filling-standard")
else
bar:SetStatusBarTexture(CAST_FILL_TEX)
end
bar:SetStatusBarColor(1, 0.18, 0.13) -- interrupt red
frame.bar = bar
return frame
end
local function SetDiffBar(frame, rating, dim)
frame.bar:SetValue(rating)
frame.bar:SetStatusBarColor(DiffRampColor(rating / 10))
frame:SetAlpha(dim and 0.55 or 1)
end
-- In-round life gauge: the same rounded cast-bar track as the difficulty meter, but the
-- fill is the remaining life and the ramp runs the other way (full = green, empty = red).
local function MakeLifeBar(parent, w, h)
local frame = MakeDiffBar(parent, w, h)
frame.bar:SetMinMaxValues(0, 1)
return frame
end
local function SetLifeBar(frame, frac)
frac = mmax(0, mmin(1, frac))
frame.bar:SetValue(frac)
frame.bar:SetStatusBarColor(DiffRampColor(1 - frac))
end
-- A renown-style progress donut: a dim circular track with a coloured arc that
-- fills clockwise to a fraction. The arc is a paused radial sweep (Cooldown) and
-- a masked centre hole carves the ring. Used per song bubble to show how far the
-- player has gotten through that track.
-- Hollow progress ring drawn from anti-aliased line segments: a many-sided
-- circle outline, nothing in the centre (genuinely see-through), a few pixels
-- thick. Segments up to the fraction are accent-coloured, the rest faint. WoW
-- lines are anti-aliased, so the outline reads as smooth with no square pixels.
-- A ring texture (transparent center) rendered smoothly by the client. The fill
-- is a radial cooldown swipe of the same ring, so partial progress reads as a
-- clean arc with a see-through middle, exactly like the default UI's progress
-- rings. No line segments, so nothing looks faceted.
local DONUT_RING_TEX = "Interface\\Artifacts\\Artifacts-PerkRing-Final"
local DONUT_STATIC_DUR = 1000000
local function MakeDonut(parent, size)
local d = CreateFrame("Frame", nil, parent)
d:SetSize(size, size)
local track = d:CreateTexture(nil, "ARTWORK")
track:SetAllPoints()
track:SetTexture(DONUT_RING_TEX)
track:SetVertexColor(0.62, 0.62, 0.68, 0.28)
d.track = track
local cd = CreateFrame("Cooldown", nil, d)
cd:SetAllPoints()
cd:SetSwipeTexture(DONUT_RING_TEX)
cd:SetDrawBling(false)
cd:SetDrawEdge(false)
cd:SetHideCountdownNumbers(true)
cd:SetReverse(true)
d.cd = cd
return d
end
local function SetDonut(d, frac, r, g, b)
frac = mmax(0, mmin(1, frac or 0))
d.cd:SetSwipeColor(r, g, b, 1)
if frac <= 0 then
d.cd:Clear()
else
-- Freeze a very long cooldown so the swipe shows a static `frac` of the ring.
d.cd:SetCooldown(GetTime() - (1 - frac) * DONUT_STATIC_DUR, DONUT_STATIC_DUR)
end
end
-- The song select's buttons: the client's own button art.
local function MakeBubbleButton(parent, text, w, h)
local b = CreateFrame("Button", nil, parent, "UIPanelButtonTemplate")
b:SetSize(w, h)
b:SetText(text)
b.label = b:GetFontString()
return b
end
-- Groove radar: a five-axis polygon (DDR-style) showing a chart's character.
-- Axis labels come from SongData.RADAR_LABELS. Drawn with anti-aliased lines: a
-- faint pentagon grid + spokes with labels, plus an accent polygon for the
-- current per-song/per-difficulty values (updated by SetRadar).
local RADAR_AXES = 5
local function MakeRadar(parent, size)
local rf = CreateFrame("Frame", nil, parent)
rf:SetSize(size, size)
local R = size * 0.5 - 15
rf.vx, rf.vy = {}, {}
for k = 1, RADAR_AXES do
local ang = (k - 1) * 2 * math.pi / RADAR_AXES
rf.vx[k] = R * math.sin(ang)
rf.vy[k] = R * math.cos(ang)
end
for k = 1, RADAR_AXES do
local nk = (k % RADAR_AXES) + 1
local edge = rf:CreateLine(nil, "ARTWORK")
edge:SetThickness(1)
edge:SetColorTexture(1, 1, 1, 0.18)
edge:SetStartPoint("CENTER", rf, rf.vx[k], rf.vy[k])