Repository navigation
Expand file tree
/
Copy pathPingGameUI.lua
More file actions
2309 lines (2069 loc) · 85.3 KB
/
Copy pathPingGameUI.lua
File metadata and controls
2309 lines (2069 loc) · 85.3 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 PingGameUI = {}
ns.PingGameUI = PingGameUI
local Utils = ns.Utils
local sformat = Utils.sformat
local mfloor = Utils.mfloor
local mmax = Utils.mmax
local mmin = Utils.mmin
local ipairs = Utils.ipairs
local pairs = Utils.pairs
local wipe = Utils.wipe
local GetTime = Utils.GetTime
local CreateFrame = Utils.CreateFrame
local PlayUISound = Utils.PlayUISound
local SOUND_CLICK = Utils.SOUND_CLICK
local GetBindingKey = GetBindingKey
local TARGET_ENEMY = 1
local TARGET_ALLY = 2
local TARGET_HAZARD = 3
local ALLY_SPAWN_ANIMS = { 77, 225 } -- shy, cower
local GAME_WIDTH = 600
local GAME_HEIGHT = 400
local TARGET_SIZE = 44
local SPAWN_MARGIN = 40
local MODEL_RETRY = 0.35 -- seconds before a blank 3D target asks for its creature again
local MODEL_GIVE_UP = 0.9 -- seconds before a still-blank 3D target shows its portrait
-- Every 3D model here (start-screen previews, round targets) is fed through
-- FeedModel. A PlayerModel comes back blank when fed while hidden, when the client
-- has not cached the creature yet, and after its window was hidden and shown again.
-- So a model is fed while visible, asked again after MODEL_RETRY, and checked at
-- MODEL_GIVE_UP: with a model file it counts as loaded (onLoaded runs once), still
-- blank it goes to onFail (the portrait stand-in). A newer feed cancels an older one.
local function ModelBlank(model)
if model.GetModelFileID then
local file = model:GetModelFileID()
return not file or file == 0
end
return model.modelPending
end
-- Probe: a ring of the last MODEL_LOG_MAX lines in BoundToLearnDB.modelLog: one per
-- 3D round target when it goes (its whole life, sampled by SampleTargetModels), plus
-- a line at each round start. Read from SavedVariables after a /reload.
local MODEL_LOG_MAX = 150
local function LogModelLine(line)
local log = BoundToLearnDB.modelLog
if type(log) ~= "table" then log = {}; BoundToLearnDB.modelLog = log end
log[#log + 1] = line
while #log > MODEL_LOG_MAX do table.remove(log, 1) end
end
local function FeedModel(model, npcID, onLoaded, onFail)
model.feedToken = (model.feedToken or 0) + 1
local token = model.feedToken
local function Current() return model.feedToken == token end
local loaded = false
local function Loaded(m)
if loaded or not Current() then return end
loaded = true
m.modelPending = false
if onLoaded then onLoaded(m) end
end
model.modelPending = true
model:SetScript("OnModelLoaded", Loaded)
model:SetCreature(npcID) -- a model switching creature is cleared (ClearModel) by its caller first
C_Timer.After(MODEL_RETRY, function()
if Current() and model.modelPending and model:IsVisible() then model:SetCreature(npcID) end
end)
C_Timer.After(MODEL_GIVE_UP, function()
-- A model its owner hid meanwhile (a target hit within MODEL_GIVE_UP) reads as
-- blank but proves nothing: only a model still on screen is judged.
if not Current() or not model:IsVisible() then return end
if ModelBlank(model) then
model.modelPending = false
if onFail then onFail(model) end
else
Loaded(model)
end
end)
end
-- Target visuals
local TARGET_COLORS = {
[TARGET_ENEMY] = { 0.9, 0.2, 0.2 },
[TARGET_ALLY] = { 0.2, 0.75, 0.3 },
[TARGET_HAZARD] = { 1.0, 0.75, 0.1 },
}
-- Fallback if atlases don't exist
local TARGET_LABELS = {
[TARGET_ENEMY] = "ATK",
[TARGET_ALLY] = "ALLY",
[TARGET_HAZARD] = "WARN",
}
-- Ping action name -> textureKit suffix (for ground pins on miss)
local PING_ACTION_KITS = {
attack = "Attack",
assist = "Assist",
warning = "Warning",
onmyway = "OnMyWay",
}
local DIFF_COLORS = {
Easy = { 0.30, 0.85, 0.30 },
Normal = { 1.00, 0.82, 0.00 },
Hard = { 1.00, 0.50, 0.10 },
Extreme = { 0.90, 0.15, 0.15 },
}
-- Race IDs per faction for portrait icons (used by C_CreatureInfo)
local ALLIANCE_RACE_IDS = { 1, 3, 4, 7, 11, 22 } -- Human, Dwarf, NightElf, Gnome, Draenei, Worgen
local HORDE_RACE_IDS = { 2, 5, 6, 8, 10, 9 } -- Orc, Undead, Tauren, Troll, BloodElf, Goblin
-- NPC IDs for 3D models (well-known city NPCs that always exist)
local ALLIANCE_NPC_IDS = {
68, -- Stormwind City Guard (Human)
5595, -- Ironforge Guard (Dwarf)
4262, -- Darnassus Sentinel (Night Elf)
5564, -- Gnomeregan Commando (Gnome)
44914, -- Gilnean Survivor (Worgen)
}
local HORDE_NPC_IDS = {
3296, -- Orgrimmar Grunt (Orc)
7980, -- Deathguard Lundmark (Undead)
3084, -- Bluffwatcher (Tauren)
5953, -- Sen'jin Guardian (Troll)
16227, -- Silvermoon City Guardian (Blood Elf)
}
-- Creatures this client never loads a model for, left out of every pick. The in-round
-- probe (BoundToLearnDB.modelLog) showed Forever has no Gilnean Survivor (44914):
-- never loaded, 3 of 3. One that fails to load during a session joins at runtime.
local unloadableNPC = {}
if Utils.IS_FOREVER then unloadableNPC[44914] = true end
-- A random creature from list that this client loads (the whole list if none does).
local function PickNPC(list)
local ok = {}
for _, id in ipairs(list) do
if not unloadableNPC[id] then ok[#ok + 1] = id end
end
if #ok == 0 then ok = list end
return ok[math.random(#ok)]
end
local playerFaction
-- Backgrounds: texture, music FileDataID, unlock requirement, display name
-- Music IDs from wowhead zone music database
-- Arena backgrounds, one per expansion, using the Adventure Guide backdrop art
-- shared with the song select (SongData.XPAC_BG). Music is resolved per
-- expansion at play time. Classic and TBC are always available; later
-- expansions unlock at score/combo milestones so the picker doubles as a
-- progression track. Names come from Blizzard's localized EXPANSION_NAME* keys.
local BACKGROUNDS = {
{ id = "classic", tier = 1, nameKey = "EXPANSION_NAME0" },
{ id = "tbc", tier = 2, nameKey = "EXPANSION_NAME1" },
{ id = "wrath", tier = 3, nameKey = "EXPANSION_NAME2", unlock = { type = "score", value = 1500, label = "Score 1500+" } },
{ id = "cataclysm", tier = 4, nameKey = "EXPANSION_NAME3", unlock = { type = "combo", value = 12, label = "12+ combo" } },
{ id = "pandaria", tier = 5, nameKey = "EXPANSION_NAME4", unlock = { type = "score", value = 3000, label = "Score 3000+" } },
{ id = "draenor", tier = 6, nameKey = "EXPANSION_NAME5", unlock = { type = "combo", value = 20, label = "20+ combo" } },
{ id = "legion", tier = 7, nameKey = "EXPANSION_NAME6", unlock = { type = "score", value = 5000, label = "Score 5000+" } },
{ id = "bfa", tier = 8, nameKey = "EXPANSION_NAME7", unlock = { type = "combo", value = 30, label = "30+ combo" } },
{ id = "shadowlands", tier = 9, nameKey = "EXPANSION_NAME8", unlock = { type = "score", value = 8000, label = "Score 8000+" } },
{ id = "dragonflight", tier = 10, nameKey = "EXPANSION_NAME9", unlock = { type = "score", value = 12000, label = "Score 12000+" } },
{ id = "midnight", tier = 11, nameKey = "EXPANSION_NAME11", nameFallback = "Midnight", unlock = { type = "combo", value = 45, label = "45+ combo" } },
}
-- Forever has no Midnight backdrop art.
if Utils.IS_FOREVER then BACKGROUNDS[#BACKGROUNDS] = nil end
for i = 1, #BACKGROUNDS do
local bg = BACKGROUNDS[i]
bg.name = _G[bg.nameKey] or bg.nameFallback or bg.nameKey
bg.atlas = ns.SongData.XPAC_BG[bg.tier]
end
-- Real WoW ping sound IDs (from wowhead sound database)
local PING_SOUNDS = {
attack = 233593, -- 10.1.7_UI_PingSystem_Attack
assist = 233592, -- 10.1.7_UI_PingSystem_Assist
warning = 233595, -- 10.1.7_UI_PingSystem_WarningDanger
onmyway = 233594, -- 10.1.7_UI_PingSystem_OnMyWay
}
-- Hazard icon textures (environmental dangers - fire, void zones, traps)
local HAZARD_ICONS = {
"Interface\\Icons\\Spell_Fire_SelfDestruct",
"Interface\\Icons\\Spell_Fire_FelImmolation",
"Interface\\Icons\\Ability_Mage_LivingBomb",
"Interface\\Icons\\Spell_Shadow_RainOfFire",
}
local mainFrame
local gameArea
local hudFrame
local startFrame
local resultsFrame
local pauseOverlay
local scoreText, timerText, comboText
local targetPool = {}
local activeTargetFrames = {} -- targetID -> frame
local floatingPool = {}
local groundPinPool = {}
-- Feedback still on screen. Their fades run on OnUpdate, which stops while the
-- arena is hidden, so a round's end clears them (ClearRoundEffects) instead of
-- leaving them to resume in the next round.
local liveFloating, liveGroundPins = {}, {}
local hoveredTargetID = nil
local debugHitbox = false
local isInitialized = false
local PlaySound = PlaySound
local PlayMusic = PlayMusic
local StopMusic = StopMusic
local function GetPingTrainerDB()
return BoundToLearn.db and BoundToLearn.db.pingTrainer
end
local function IsBackgroundUnlocked(bgID)
local pt = GetPingTrainerDB()
return pt and pt.unlockedBGs and pt.unlockedBGs[bgID]
end
local function UnlockBackground(bgID)
local pt = GetPingTrainerDB()
if not pt then return end
if not pt.unlockedBGs then pt.unlockedBGs = {} end
if pt.unlockedBGs[bgID] then return false end
pt.unlockedBGs[bgID] = true
return true
end
local function GetSelectedBackground()
local pt = GetPingTrainerDB()
if not pt then return BACKGROUNDS[1] end
if pt.randomBG then
local unlocked = {}
for i = 1, #BACKGROUNDS do
if IsBackgroundUnlocked(BACKGROUNDS[i].id) then
unlocked[#unlocked + 1] = BACKGROUNDS[i]
end
end
if #unlocked > 0 then
return unlocked[math.random(#unlocked)]
end
end
local selectedID = pt.background or "classic"
for i = 1, #BACKGROUNDS do
if BACKGROUNDS[i].id == selectedID then
return BACKGROUNDS[i]
end
end
return BACKGROUNDS[1]
end
-- Backgrounds are Adventure Guide atlases now, so route through SetAtlas; keep a
-- texture path branch in case a future entry uses a raw file.
-- The Adventure Guide backdrops carry a decorative header band across the top
-- (stone tiling + a gold streak). Crop it out and keep the scenic body, then let
-- that stretch to fill the arena.
local GetAtlasInfo = C_Texture and C_Texture.GetAtlasInfo
local BG_CROP_TOP = 0.27
local BG_CROP_BOTTOM = 0.03
local function ApplyBackground(tex, bg)
if bg and bg.atlas then
tex:SetAtlas(bg.atlas)
local info = GetAtlasInfo and GetAtlasInfo(bg.atlas)
if info then
local h = info.bottomTexCoord - info.topTexCoord
tex:SetTexCoord(info.leftTexCoord, info.rightTexCoord,
info.topTexCoord + h * BG_CROP_TOP, info.bottomTexCoord - h * BG_CROP_BOTTOM)
end
elseif bg and bg.texture then
tex:SetTexture(bg.texture)
end
end
local function IsMusicMuted()
local pt = GetPingTrainerDB()
return pt and pt.muteMusic
end
local function IsPingSoundMuted()
local pt = GetPingTrainerDB()
return pt and pt.mutePingSounds
end
local function StartBackgroundMusic(bg)
if not bg or IsMusicMuted() then return end
local musicID = bg.musicID or (bg.tier and ns.SongData.TierMusic and ns.SongData.TierMusic(bg.tier))
-- PlayMusic replaces the current zone music on the Music channel.
-- We don't need to touch the volume - PlayMusic overrides zone music directly.
if musicID then PlayMusic(musicID) end
end
local function StopBackgroundMusic()
StopMusic()
end
local function PlayPingSound(pingAction)
if IsPingSoundMuted() then return end
local soundID = PING_SOUNDS[pingAction]
if soundID then
PlaySound(soundID, "SFX")
end
end
local function CheckUnlocks(results)
local newUnlocks = {}
for i = 1, #BACKGROUNDS do
local bg = BACKGROUNDS[i]
if bg.unlock and not IsBackgroundUnlocked(bg.id) then
local u = bg.unlock
local earned = false
if u.type == "score" and results.score >= u.value then
earned = true
elseif u.type == "combo" and results.maxCombo >= u.value then
earned = true
elseif u.type == "accuracy" and results.accuracy >= u.value then
earned = true
end
if earned and UnlockBackground(bg.id) then
newUnlocks[#newUnlocks + 1] = bg
end
end
end
return newUnlocks
end
local function ToggleMuteMusic(v)
local pt = GetPingTrainerDB()
if pt then pt.muteMusic = v end
if v then StopBackgroundMusic()
else
local bg = GetSelectedBackground()
if ns.PingGame and ns.PingGame:IsRunning() then StartBackgroundMusic(bg) end
end
end
local function ToggleMutePingSounds(v)
local pt = GetPingTrainerDB()
if pt then pt.mutePingSounds = v end
end
local function AcquireFloating()
local frame = tremove(floatingPool)
if frame then
frame:Show()
return frame
end
frame = CreateFrame("Frame", nil, gameArea)
frame:SetSize(100, 20)
frame:SetFrameLevel(gameArea:GetFrameLevel() + 15)
local text = frame:CreateFontString(nil, "OVERLAY")
text:SetFont("Fonts\\FRIZQT__.TTF", 14, "OUTLINE")
text:SetPoint("CENTER")
frame.text = text
frame:Show()
return frame
end
local function ReleaseFloating(frame)
liveFloating[frame] = nil
frame:Hide()
frame:ClearAllPoints()
frame:SetScript("OnUpdate", nil)
frame:SetAlpha(1)
tinsert(floatingPool, frame)
end
local function ShowFloatingText(x, y, msg, r, g, b)
local frame = AcquireFloating()
liveFloating[frame] = true
frame:SetPoint("CENTER", gameArea, "BOTTOMLEFT", x, y)
frame.text:SetText(msg)
frame.text:SetTextColor(r, g, b)
frame:SetAlpha(1)
local elapsed = 0
frame:SetScript("OnUpdate", function(self, dt)
elapsed = elapsed + dt
local progress = elapsed / 0.8
if progress >= 1 then
ReleaseFloating(self)
return
end
self:SetPoint("CENTER", gameArea, "BOTTOMLEFT", x, y + progress * 40)
self:SetAlpha(1 - progress * progress)
end)
end
local GROUND_PIN_SIZE = 40
local GROUND_PIN_STEM = 70
local GROUND_PIN_DURATION = 1.2
local function AcquireGroundPin()
local frame = tremove(groundPinPool)
if frame then
frame:Show()
return frame
end
frame = CreateFrame("Frame", nil, gameArea)
frame:SetSize(GROUND_PIN_SIZE, GROUND_PIN_SIZE + GROUND_PIN_STEM)
frame:SetFrameLevel(gameArea:GetFrameLevel() + 12)
local stem = frame:CreateTexture(nil, "BACKGROUND")
stem:SetPoint("BOTTOM")
stem:SetSize(6, GROUND_PIN_STEM)
frame.stem = stem
local bg = frame:CreateTexture(nil, "ARTWORK")
bg:SetSize(GROUND_PIN_SIZE, GROUND_PIN_SIZE)
bg:SetPoint("TOP")
frame.bg = bg
local stroke = frame:CreateTexture(nil, "ARTWORK", nil, 2)
stroke:SetSize(GROUND_PIN_SIZE, GROUND_PIN_SIZE)
stroke:SetPoint("CENTER", bg)
frame.stroke = stroke
local icon = frame:CreateTexture(nil, "OVERLAY")
icon:SetSize(GROUND_PIN_SIZE * 0.6, GROUND_PIN_SIZE * 0.6)
icon:SetPoint("CENTER", bg)
frame.icon = icon
frame:Show()
return frame
end
local function ReleaseGroundPin(frame)
liveGroundPins[frame] = nil
frame:Hide()
frame:ClearAllPoints()
frame:SetScript("OnUpdate", nil)
frame:SetAlpha(1)
tinsert(groundPinPool, frame)
end
local function ShowGroundPin(x, y, kit)
local pin = AcquireGroundPin()
liveGroundPins[pin] = true
pin:SetPoint("BOTTOM", gameArea, "BOTTOMLEFT", x, y)
pin.bg:SetAtlas("Ping_GroundMarker_BG_" .. kit)
pin.stroke:SetAtlas("Ping_GroundMarker_Stroke_" .. kit)
pin.stem:SetAtlas("Ping_GroundMarker_Pin_" .. kit)
pin.icon:SetAtlas("Ping_Marker_Icon_" .. kit)
pin:SetAlpha(1)
local elapsed = 0
pin:SetScript("OnUpdate", function(self, dt)
elapsed = elapsed + dt
if elapsed > GROUND_PIN_DURATION then
ReleaseGroundPin(self)
return
end
-- Fade out in last 40%
local fadeStart = GROUND_PIN_DURATION * 0.6
if elapsed > fadeStart then
self:SetAlpha(1 - (elapsed - fadeStart) / (GROUND_PIN_DURATION - fadeStart))
end
end)
end
local function ClearRoundEffects()
for frame in pairs(liveFloating) do ReleaseFloating(frame) end
for frame in pairs(liveGroundPins) do ReleaseGroundPin(frame) end
end
local function AcquireTarget()
local frame = tremove(targetPool)
if frame then
frame:Show()
return frame
end
frame = CreateFrame("Button", nil, gameArea)
frame:SetSize(TARGET_SIZE, TARGET_SIZE)
frame:EnableMouse(true)
frame:RegisterForClicks() -- no click handling, just hover detection
-- Circular background
local bg = frame:CreateTexture(nil, "BACKGROUND")
bg:SetAllPoints()
bg:SetTexture("Interface\\COMMON\\Indicator-Gray")
bg:SetVertexColor(0.2, 0.2, 0.2, 0.8)
frame.bg = bg
-- Ring highlight (shows on hover)
local ring = frame:CreateTexture(nil, "BORDER")
ring:SetSize(TARGET_SIZE + 8, TARGET_SIZE + 8)
ring:SetPoint("CENTER")
ring:SetTexture("Interface\\COMMON\\Indicator-Yellow")
ring:SetAlpha(0.5)
frame.ring = ring
-- Icon (portrait/atlas)
local icon = frame:CreateTexture(nil, "ARTWORK")
icon:SetSize(TARGET_SIZE - 8, TARGET_SIZE - 8)
icon:SetPoint("CENTER")
frame.icon = icon
-- 3D model for full-body rendering
local model = CreateFrame("PlayerModel", nil, frame)
model:SetSize(TARGET_SIZE * 2.25, TARGET_SIZE * 3.4)
model:SetPoint("BOTTOM", 0, -10)
model:SetFrameLevel(frame:GetFrameLevel() + 1)
model:EnableMouse(false)
model:Hide()
frame.model = model
-- Invisible hit frame over model area (regular Frame = full-rect mouse detection)
local modelHit = CreateFrame("Frame", nil, frame)
modelHit:SetPoint("BOTTOMLEFT", model, "BOTTOMLEFT")
modelHit:SetPoint("BOTTOMRIGHT", model, "BOTTOMRIGHT")
modelHit:SetHeight(model:GetHeight() * 0.6)
modelHit:SetFrameLevel(model:GetFrameLevel() + 1)
modelHit:EnableMouse(true)
modelHit:SetScript("OnEnter", function()
local onEnter = frame:GetScript("OnEnter")
if onEnter then onEnter(frame) end
end)
modelHit:SetScript("OnLeave", function()
local onLeave = frame:GetScript("OnLeave")
if onLeave then onLeave(frame) end
end)
modelHit:Hide()
frame.modelHit = modelHit
-- Debug hitbox overlay (green = model hit area)
local dbgHit = modelHit:CreateTexture(nil, "OVERLAY", nil, 7)
dbgHit:SetAllPoints()
dbgHit:SetColorTexture(0, 1, 0, 0.15)
dbgHit:Hide()
frame.dbgHit = dbgHit
-- Unit ping marker (appears on ping - icon above head, no stem)
local UNIT_PIN_SIZE = 48
local unitPin = CreateFrame("Frame", nil, frame)
unitPin:SetSize(UNIT_PIN_SIZE, UNIT_PIN_SIZE)
unitPin:SetPoint("BOTTOM", frame, "TOP", 0, 4) -- default for portrait/blob mode
unitPin:SetFrameLevel(frame:GetFrameLevel() + 10)
local unitPinBG = unitPin:CreateTexture(nil, "ARTWORK")
unitPinBG:SetAllPoints()
unitPin.bg = unitPinBG
local unitPinIcon = unitPin:CreateTexture(nil, "OVERLAY")
unitPinIcon:SetSize(UNIT_PIN_SIZE * 0.6, UNIT_PIN_SIZE * 0.6)
unitPinIcon:SetPoint("CENTER", unitPinBG)
unitPin.icon = unitPinIcon
unitPin:Hide()
frame.unitPin = unitPin
-- Fallback label if atlas doesn't exist
local label = frame:CreateFontString(nil, "OVERLAY")
label:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
label:SetPoint("CENTER")
frame.label = label
-- Timer bar at bottom
local timerBG = frame:CreateTexture(nil, "ARTWORK", nil, 1)
timerBG:SetPoint("BOTTOM")
timerBG:SetSize(TARGET_SIZE - 4, 3)
timerBG:SetColorTexture(0.2, 0.2, 0.2, 0.6)
frame.timerBG = timerBG
local timerBar = frame:CreateTexture(nil, "OVERLAY")
timerBar:SetPoint("BOTTOMLEFT", 2, 0)
timerBar:SetHeight(3)
timerBar:SetColorTexture(1, 1, 1, 0.8)
frame.timerBar = timerBar
-- Hover detection
frame:SetScript("OnEnter", function(self)
if self.targetID then
hoveredTargetID = self.targetID
self.ring:SetAlpha(1)
-- Bright glow to show it's hovered
self.bg:SetVertexColor(self.baseColor[1] * 0.5, self.baseColor[2] * 0.5, self.baseColor[3] * 0.5, 0.95)
end
end)
frame:SetScript("OnLeave", function(self)
if hoveredTargetID == self.targetID then
hoveredTargetID = nil
end
self.ring:SetAlpha(0.5)
if self.baseColor then
self.bg:SetVertexColor(self.baseColor[1] * 0.3, self.baseColor[2] * 0.3, self.baseColor[3] * 0.3, 0.9)
end
end)
frame:Show()
return frame
end
local function ReleaseTarget(frame)
local p = frame.probe
if p then
frame.probe = nil
LogModelLine(sformat("npc %d %s: lived %.1fs, model on screen %.1fs, blank on screen %.1fs, "
.. "model file after %s, loaded %s, fell back %s, anim %s, past the arena %s, file %s display %s",
p.npc, p.kind, GetTime() - p.spawnAt, p.shown, p.blank,
p.fileAt and sformat("%.2fs", p.fileAt) or "never", p.loadedAt and sformat("%.2fs", p.loadedAt) or "never",
tostring(p.fellBack or false), tostring(p.anim), tostring(p.outside or false), tostring(p.file),
tostring(p.display)))
end
frame:Hide()
frame:ClearAllPoints()
frame:SetScript("OnUpdate", nil)
frame:SetAlpha(1)
frame:SetSize(TARGET_SIZE, TARGET_SIZE)
frame.ring:SetSize(TARGET_SIZE + 8, TARGET_SIZE + 8)
frame.bg:Show()
frame.ring:Show()
frame.icon:Hide()
frame.model:Hide()
frame.modelHit:Hide()
frame.dbgHit:Hide()
frame.unitPin:Hide()
frame.label:SetText("")
frame.targetID = nil
frame.baseColor = nil
if hoveredTargetID == frame.targetID then
hoveredTargetID = nil
end
tinsert(targetPool, frame)
end
-- Probe sampler: every 0.1 s of a round, each 3D target's model while it is on
-- screen. No model file counts as blank; an edge past the arena is noted.
local modelSampler
local function SampleTargetModels(ticker)
if not (gameArea and gameArea:IsVisible()) then
ticker:Cancel()
if modelSampler == ticker then modelSampler = nil end
return
end
local now = GetTime()
local aL, aR, aB, aT = gameArea:GetLeft(), gameArea:GetRight(), gameArea:GetBottom(), gameArea:GetTop()
for _, frame in pairs(activeTargetFrames) do
local p, m = frame.probe, frame.model
if p and m:IsVisible() then
p.shown = p.shown + 0.1
if ModelBlank(m) then
p.blank = p.blank + 0.1
else
p.fileAt = p.fileAt or (now - p.spawnAt)
p.file = m:GetModelFileID()
p.display = m.GetDisplayInfo and m:GetDisplayInfo()
end
local l, r, b, t = m:GetLeft(), m:GetRight(), m:GetBottom(), m:GetTop()
if l and aL and (l < aL or r > aR or b < aB or t > aT) then p.outside = true end
end
end
end
function PingGameUI:Initialize()
if isInitialized then return end
isInitialized = true
end
function PingGameUI:Toggle()
local PG = ns.PingGame
if not PG then return end
if PG:IsRunning() then
PG:Stop()
return
end
if mainFrame and mainFrame:IsShown() then
mainFrame:Hide()
return
end
if not mainFrame then
self:CreateUI()
end
self:ShowStartScreen()
mainFrame:Show()
end
function PingGameUI:CreateUI()
mainFrame = CreateFrame("Frame", "BoundToLearnPingGame", UIParent)
mainFrame:SetSize(GAME_WIDTH + 20, GAME_HEIGHT + 90)
mainFrame:SetPoint("CENTER")
mainFrame:SetFrameStrata("HIGH")
ns.Theme.StylePanel(mainFrame)
-- The picked expansion's backdrop behind the start screen (the round has its
-- own in the arena), dimmed so the labels and panels stay readable.
local backdrop = mainFrame:CreateTexture(nil, "ARTWORK")
backdrop:SetPoint("TOPLEFT", 7, -7)
backdrop:SetPoint("BOTTOMRIGHT", -7, 7)
backdrop:SetAlpha(0.85)
backdrop:SetVertexColor(0.7, 0.7, 0.72)
mainFrame.backdropTex = backdrop
mainFrame:SetMovable(true)
mainFrame:EnableMouse(true)
mainFrame:RegisterForDrag("LeftButton")
mainFrame:SetScript("OnDragStart", function(self)
if IsShiftKeyDown() then
self:StartMoving()
end
end)
mainFrame:SetScript("OnDragStop", mainFrame.StopMovingOrSizing)
-- A ping bound anywhere (this window or the client's Key Bindings) updates
-- the key list and the Start button while the window is open.
mainFrame:RegisterEvent("UPDATE_BINDINGS")
mainFrame:SetScript("OnEvent", function(self, event)
if event == "UPDATE_BINDINGS" and self:IsShown() and startFrame and startFrame:IsShown() then
PingGameUI:UpdateKeybindDisplay()
PingGameUI:UpdateStartButton()
end
end)
mainFrame:Hide()
mainFrame:SetScript("OnHide", function()
-- Closing the window ends a round still in play (or paused).
local PG = ns.PingGame
if PG and PG:IsRunning() then PG:Stop() end
StopBackgroundMusic()
end)
Utils.CloseOnEscape(mainFrame)
-- Title
local title = ns.Theme.CreateTitle(mainFrame, "Ping Trainer", 20)
title:SetPoint("TOP", 0, -11) -- below the window's border band (11)
-- Drag hint at upper right
local dragHint = mainFrame:CreateFontString(nil, "OVERLAY")
dragHint:SetFont("Fonts\\FRIZQT__.TTF", 9, "OUTLINE")
dragHint:SetPoint("TOPRIGHT", -28, -12)
dragHint:SetTextColor(0.55, 0.55, 0.55)
dragHint:SetText("Shift+drag to move")
-- Close button
local closeBtn = ns.Theme.CreateCloseButton(mainFrame, function()
local PG = ns.PingGame
if PG and PG:IsRunning() then PG:Stop() end
mainFrame:Hide()
end)
closeBtn:SetPoint("TOPRIGHT", -8, -8)
-- HUD
hudFrame = CreateFrame("Frame", nil, mainFrame)
hudFrame:SetSize(GAME_WIDTH, 20)
hudFrame:SetPoint("TOP", 0, -32)
hudFrame:Hide()
scoreText = hudFrame:CreateFontString(nil, "OVERLAY")
scoreText:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
scoreText:SetPoint("LEFT", 10, 0)
scoreText:SetTextColor(ns.Theme.RGB(ns.Theme.C.GOLD))
timerText = hudFrame:CreateFontString(nil, "OVERLAY")
timerText:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
timerText:SetPoint("CENTER")
timerText:SetTextColor(0.8, 0.8, 0.8)
comboText = hudFrame:CreateFontString(nil, "OVERLAY")
comboText:SetFont("Fonts\\FRIZQT__.TTF", 13, "OUTLINE")
comboText:SetPoint("RIGHT", -60, 0)
comboText:SetTextColor(ns.Theme.RGB(ns.Theme.C.ACCENT))
-- Sound toggle helpers for HUD
local function CreateSoundToggle(parent, label, getState, setState, xOff, tooltip)
local btn = CreateFrame("Button", nil, parent)
btn:SetSize(36, 14)
btn:SetPoint("RIGHT", xOff, 0)
local fs = btn:CreateFontString(nil, "OVERLAY")
fs:SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
fs:SetAllPoints()
btn.label = fs
btn.getState = getState
btn.setState = setState
btn.baseName = label
local function Refresh()
local muted = getState()
fs:SetText(muted and ("|cFF666666" .. label .. "|r") or ("|cFF88CC88" .. label .. "|r"))
end
btn:SetScript("OnClick", function()
setState(not getState())
Refresh()
end)
if tooltip then
btn:SetScript("OnEnter", function(self)
self.hovering = true
C_Timer.After(0.4, function()
if not self.hovering then return end
GameTooltip:SetOwner(self, "ANCHOR_TOP")
GameTooltip:AddLine(label)
GameTooltip:AddLine(tooltip, 0.8, 0.8, 0.8, true)
GameTooltip:Show()
end)
end)
btn:SetScript("OnLeave", function(self)
self.hovering = false
GameTooltip:Hide()
end)
end
btn.Refresh = Refresh
Refresh()
return btn
end
local hudMusicBtn = CreateSoundToggle(hudFrame, "Music", IsMusicMuted, ToggleMuteMusic, -130,
"Background music while you play.")
local hudPingBtn = CreateSoundToggle(hudFrame, "SFX", IsPingSoundMuted, ToggleMutePingSounds, -90,
"Sound effects: the ping and alert sounds during play. Music is a separate toggle.")
hudFrame.musicBtn = hudMusicBtn
hudFrame.pingBtn = hudPingBtn
local stopBtn = CreateFrame("Button", nil, hudFrame)
stopBtn:SetSize(44, 18)
stopBtn:SetPoint("RIGHT", -6, 0)
stopBtn:SetNormalFontObject("GameFontNormalSmall")
stopBtn:SetText("|cFFCC3333Stop|r")
stopBtn:GetFontString():SetFont("Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
stopBtn:SetScript("OnClick", function()
local PG = ns.PingGame
if PG and PG:IsRunning() then
C_Timer.After(0, function() PG:Stop() end)
end
end)
stopBtn:SetScript("OnEnter", function(self)
self:SetText("|cFFFF5555Stop|r")
end)
stopBtn:SetScript("OnLeave", function(self)
self:SetText("|cFFCC3333Stop|r")
end)
-- Game area with background
gameArea = CreateFrame("Frame", nil, mainFrame, "BackdropTemplate")
gameArea._btlNoLayoutCheck = true -- targets spawn anywhere, over each other
gameArea:SetSize(GAME_WIDTH, GAME_HEIGHT)
gameArea:SetPoint("TOP", 0, -54)
gameArea:SetBackdrop({
edgeFile = "Interface\\Tooltips\\UI-Tooltip-Border",
edgeSize = 10,
insets = { left = 2, right = 2, top = 2, bottom = 2 },
})
gameArea:SetBackdropBorderColor(ns.Theme.RGB(ns.Theme.C.BORDER, 0.7))
-- Arena-style background texture
local bgTex = gameArea:CreateTexture(nil, "BACKGROUND")
bgTex:SetAllPoints()
ApplyBackground(bgTex, GetSelectedBackground())
bgTex:SetVertexColor(0.8, 0.8, 0.8, 1)
gameArea.bgTex = bgTex
-- Subtle overlay to keep targets readable
local overlay = gameArea:CreateTexture(nil, "BACKGROUND", nil, 1)
overlay:SetAllPoints()
overlay:SetColorTexture(0, 0, 0, 0.05)
-- Keybind input frame (captures ping keys during gameplay)
local inputFrame = CreateFrame("Frame", nil, gameArea)
inputFrame:SetAllPoints()
inputFrame:EnableKeyboard(true)
inputFrame:SetPropagateKeyboardInput(true)
inputFrame:Hide()
gameArea.inputFrame = inputFrame
inputFrame:SetScript("OnKeyDown", function(_, key)
if key == "ESCAPE" then
inputFrame:SetPropagateKeyboardInput(false)
local PG = ns.PingGame
if PG and PG:IsRunning() then
C_Timer.After(0, function() PG:Stop() end)
end
return
end
-- Build full key with modifiers
local fullKey = ""
if IsAltKeyDown() then fullKey = fullKey .. "ALT-" end
if IsControlKeyDown() then fullKey = fullKey .. "CTRL-" end
if IsShiftKeyDown() then fullKey = fullKey .. "SHIFT-" end
fullKey = fullKey .. key
local PG = ns.PingGame
if not PG then
inputFrame:SetPropagateKeyboardInput(true)
return
end
local pingKeybinds = PG:GetPingKeybinds()
local pingAction = pingKeybinds[fullKey]
if pingAction then
inputFrame:SetPropagateKeyboardInput(false)
if hoveredTargetID then
PG:OnPingAction(hoveredTargetID, pingAction)
else
PG:OnPingMiss(pingAction)
end
else
inputFrame:SetPropagateKeyboardInput(true)
end
end)
-- Pause overlay
pauseOverlay = CreateFrame("Frame", nil, gameArea)
pauseOverlay:SetAllPoints()
pauseOverlay:SetFrameLevel(gameArea:GetFrameLevel() + 20)
pauseOverlay:EnableMouse(true)
pauseOverlay:Hide()
local pauseBG = pauseOverlay:CreateTexture(nil, "BACKGROUND")
pauseBG:SetAllPoints()
pauseBG:SetColorTexture(0, 0, 0, 0.7)
local pauseLabel = pauseOverlay:CreateFontString(nil, "OVERLAY")
pauseLabel:SetFont("Fonts\\FRIZQT__.TTF", 20, "OUTLINE")
pauseLabel:SetPoint("CENTER", 0, 10)
pauseLabel:SetText("|cFFFFD700Paused|r")
local resumeBtn = ns.Theme.CreateButton(pauseOverlay, "Resume", 100, 24)
resumeBtn:SetPoint("CENTER", 0, -20)
resumeBtn:SetScript("OnClick", function()
local PG = ns.PingGame
if PG then PG:Resume() end
end)
-- Health bar (between game area bottom and window bottom)
local healthFrame = CreateFrame("Frame", nil, mainFrame)
healthFrame:SetSize(GAME_WIDTH - 40, 14)
healthFrame:SetPoint("TOP", gameArea, "BOTTOM", 0, -6)
healthFrame:Hide()
local healthBG = healthFrame:CreateTexture(nil, "BACKGROUND")
healthBG:SetAllPoints()
healthBG:SetColorTexture(0.15, 0.15, 0.15, 0.8)
local healthBar = healthFrame:CreateTexture(nil, "ARTWORK")
healthBar:SetPoint("TOPLEFT", 1, -1)
healthBar:SetPoint("BOTTOMLEFT", 1, 1)
healthBar:SetWidth(healthFrame:GetWidth() - 2)
healthBar:SetColorTexture(0.2, 0.8, 0.2, 0.9)
healthFrame.bar = healthBar
-- Thin border lines around health bar
local borderTop = healthFrame:CreateTexture(nil, "OVERLAY")
borderTop:SetHeight(1)
borderTop:SetPoint("TOPLEFT")
borderTop:SetPoint("TOPRIGHT")
borderTop:SetColorTexture(0.4, 0.4, 0.4, 0.7)
local borderBot = healthFrame:CreateTexture(nil, "OVERLAY")
borderBot:SetHeight(1)
borderBot:SetPoint("BOTTOMLEFT")
borderBot:SetPoint("BOTTOMRIGHT")
borderBot:SetColorTexture(0.4, 0.4, 0.4, 0.7)
local healthText = healthFrame:CreateFontString(nil, "OVERLAY")
healthText:SetFont("Fonts\\FRIZQT__.TTF", 9, "OUTLINE")
healthText:SetPoint("CENTER")
healthText:SetTextColor(0.9, 0.9, 0.9)
healthFrame.text = healthText
mainFrame.healthFrame = healthFrame
self:CreateStartScreen()
self:CreateResultsScreen()
end
function PingGameUI:CreateStartScreen()
startFrame = CreateFrame("Frame", nil, mainFrame)
startFrame:SetPoint("TOPLEFT", mainFrame, "TOPLEFT", 10, -36)
startFrame:SetPoint("BOTTOMRIGHT", mainFrame, "BOTTOMRIGHT", -10, 14)
-- ===== Top: 3 showcase models side by side =====
local SHOWCASE_H = 200
local showcaseRow = CreateFrame("Frame", nil, startFrame)
showcaseRow:SetPoint("TOPLEFT", 0, 0)
showcaseRow:SetPoint("TOPRIGHT", 0, 0)
showcaseRow:SetHeight(SHOWCASE_H)
local SHOWCASE = {
{ npcID = 3296, anim = 26, facing = 0.3, kit = "Attack", label = "Attack", color = {1, 0.27, 0.27}, targetType = TARGET_ENEMY },
{ npcID = 68, anim = 225, facing = -0.2, kit = "Assist", label = "Assist", color = {0.27, 0.8, 0.27}, targetType = TARGET_ALLY },
{ npcID = 5953, anim = 4, facing = 0.15, kit = "Warning", label = "Warning", color = {1, 0.8, 0}, targetType = TARGET_HAZARD },
}
startFrame.showcaseCells = {}
local showcaseWidth = GAME_WIDTH - 20
local cellWidth = mfloor(showcaseWidth / 3)
for i, sc in ipairs(SHOWCASE) do
local cellCenter = (i - 1) * cellWidth + cellWidth / 2
local modelFrame = CreateFrame("PlayerModel", nil, showcaseRow)
modelFrame:SetSize(90, 130)
modelFrame:SetPoint("BOTTOM", showcaseRow, "BOTTOMLEFT", cellCenter, 34)
modelFrame:EnableMouse(false)