-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDisplay.lua
More file actions
2086 lines (1828 loc) · 71.1 KB
/
Copy pathDisplay.lua
File metadata and controls
2086 lines (1828 loc) · 71.1 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
-- TrueShot Display: presentation layer for the queue overlay
local Engine = TrueShot.Engine
local GetTime = GetTime
local C_Spell_GetSpellTexture = C_Spell and C_Spell.GetSpellTexture
local C_Spell_GetSpellCooldown = C_Spell and C_Spell.GetSpellCooldown
local C_Spell_GetSpellCharges = C_Spell and C_Spell.GetSpellCharges
local C_Spell_GetSpellCooldownDuration = C_Spell and C_Spell.GetSpellCooldownDuration
local C_Spell_GetSpellChargeDuration = C_Spell and C_Spell.GetSpellChargeDuration
local C_ActionBar_GetActionCooldown = C_ActionBar and C_ActionBar.GetActionCooldown
local C_ActionBar_GetActionCooldownDuration = C_ActionBar and C_ActionBar.GetActionCooldownDuration
local C_ActionBar_GetActionChargeDuration = C_ActionBar and C_ActionBar.GetActionChargeDuration
local Masque = _G.LibStub and _G.LibStub("Masque", true)
local MasqueGroup = Masque and Masque:Group("TrueShot", "Queue")
TrueShot.Display = {}
local Display = TrueShot.Display
local SUCCESS_FLASH_DURATION = 0.35
local MIN_COOLDOWN_SWIPE_DURATION = 2.0
local CONTAINER_PADDING_X = 8
local CONTAINER_PADDING_Y = 6
local ICON_TEXTURE_INSET = 3
local QUEUE_STABILIZATION_TICKS = 2
local QUEUE_HIDE_STABILIZATION_TICKS = 5 -- nominal 5-tick hide threshold; 0.30s deadline may hide first
-- Combat updates run at 10 Hz. This bounds stale presentation to three ticks
-- even when the newest queue candidate oscillates on every update.
local MAX_QUEUE_STALE_AGE = 0.30
local displayedQueueState = { count = 0 }
local pendingQueueState = { count = 0 }
local pendingQueueTicks = 0
local pendingWindowStart = nil
local staleDeadlineForcedLastCommit = false
local allowImmediateQueueUpdate = false
local displayEnabled = false
-- Committed metadata snapshot (persisted alongside displayedQueueState)
local committedMeta = {
source = "none",
reason = nil,
reasonCode = "NO_AC_PRIMARY",
rawACStatus = "unavailable",
strictState = true,
rotationCatalogRole = "context_only",
fallbackDropReason = nil,
phase = nil,
aoeHintSpell = nil,
}
local function IsSecretValue(value)
return issecretvalue and issecretvalue(value) or false
end
local FILTERED_IDLE_DROP_REASONS = {
raw_ac_blacklisted = true,
raw_ac_locally_uncastable = true,
}
local function BuildIdleStateLabel(meta)
if meta.strictState == false
and type(meta.fallbackDropReason) == "string"
and FILTERED_IDLE_DROP_REASONS[meta.fallbackDropReason] then
return "No action (filtered)"
end
return "Waiting for Assisted Combat"
end
local function TruncateUTF8(value, maxCodepoints)
local byteLength = #value
local byteIndex = 1
local codepointCount = 0
local truncationByteIndex
while byteIndex <= byteLength do
if codepointCount == maxCodepoints and not truncationByteIndex then
truncationByteIndex = byteIndex
end
local first = value:byte(byteIndex)
local width
if first <= 0x7F then
width = 1
elseif first >= 0xC2 and first <= 0xDF then
width = 2
elseif first >= 0xE0 and first <= 0xEF then
width = 3
elseif first >= 0xF0 and first <= 0xF4 then
width = 4
else
return nil
end
if byteIndex + width - 1 > byteLength then return nil end
local second = width > 1 and value:byte(byteIndex + 1)
if second and (second < 0x80 or second > 0xBF) then return nil end
if width == 3 then
if first == 0xE0 and second < 0xA0 then return nil end
if first == 0xED and second > 0x9F then return nil end
elseif width == 4 then
if first == 0xF0 and second < 0x90 then return nil end
if first == 0xF4 and second > 0x8F then return nil end
end
for offset = 2, width - 1 do
local continuation = value:byte(byteIndex + offset)
if continuation < 0x80 or continuation > 0xBF then return nil end
end
byteIndex = byteIndex + width
codepointCount = codepointCount + 1
end
if truncationByteIndex then
return value:sub(1, truncationByteIndex - 1), true
end
return value, false
end
local function SnapshotCommittedMeta()
local meta = Engine.lastQueueMeta
if not meta then
committedMeta.source = "none"
committedMeta.reason = nil
committedMeta.reasonCode = nil
committedMeta.rawACStatus = nil
committedMeta.strictState = true
committedMeta.rotationCatalogRole = nil
committedMeta.fallbackDropReason = nil
committedMeta.phase = nil
committedMeta.aoeHintSpell = nil
return
end
committedMeta.source = meta.source
committedMeta.reason = meta.reason
committedMeta.reasonCode = meta.reasonCode
committedMeta.rawACStatus = meta.rawACStatus
committedMeta.strictState = meta.strictState == true
committedMeta.rotationCatalogRole = meta.rotationCatalogRole
committedMeta.fallbackDropReason = meta.fallbackDropReason
local phase = meta.phase
if IsSecretValue(phase) or type(phase) ~= "string" or phase == "" then
committedMeta.phase = nil
else
local truncatedPhase, wasTruncated = TruncateUTF8(phase, 24)
if truncatedPhase and wasTruncated then
truncatedPhase = truncatedPhase .. "…"
end
committedMeta.phase = truncatedPhase
end
local aoeHintSpell = meta.aoeHintSpell
if IsSecretValue(aoeHintSpell) or type(aoeHintSpell) ~= "number" then
committedMeta.aoeHintSpell = nil
else
committedMeta.aoeHintSpell = aoeHintSpell
end
end
local function BuildDecisionSourceLabel(meta)
if not meta or meta.strictState == true then return nil end
if meta.reasonCode == "AC_PRIMARY" then
return "Assisted Combat"
end
if meta.reasonCode ~= "EXPERIMENTAL_OVERRIDE" then return nil end
local reason = meta.reason
if IsSecretValue(reason) then
return "Experimental override"
end
if type(reason) ~= "string" then
return "Experimental override"
end
if reason == "" then
return "Experimental override"
end
local truncatedReason, wasTruncated = TruncateUTF8(reason, 24)
if not truncatedReason then
return "Experimental override"
end
if wasTruncated then
truncatedReason = truncatedReason .. "…"
end
return "Experimental: " .. truncatedReason
end
------------------------------------------------------------------------
-- Container frame
------------------------------------------------------------------------
local container = CreateFrame("Frame", "TrueShotFrame", UIParent,
"BackdropTemplate")
container:SetSize(200, 50)
container:SetPoint("CENTER", UIParent, "CENTER", 0, -50)
container:SetMovable(true)
container:EnableMouse(true)
container:SetClampedToScreen(true)
container:RegisterForDrag("LeftButton")
container:SetScript("OnDragStart", function(self)
if not TrueShot.GetOpt("locked") then
self:StartMoving()
end
end)
container:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
Display:SaveCurrentPosition()
end)
container:SetBackdrop({
bgFile = "Interface/Tooltips/UI-Tooltip-Background",
edgeFile = "Interface/Tooltips/UI-Tooltip-Border",
edgeSize = 12,
insets = { left = 3, right = 3, top = 3, bottom = 3 },
})
container:SetBackdropColor(0.04, 0.04, 0.04, 0.92)
container:SetBackdropBorderColor(0.55, 0.55, 0.55, 0.95)
local content = CreateFrame("Frame", nil, container)
content:SetPoint("TOPLEFT", container, "TOPLEFT", CONTAINER_PADDING_X, -CONTAINER_PADDING_Y)
Display.container = container
container:Hide()
container:SetClipsChildren(false)
local reasonText = container:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
reasonText:SetPoint("TOP", container, "BOTTOM", 0, -2)
reasonText:SetJustifyH("CENTER")
reasonText:SetTextColor(0.75, 0.85, 1.0, 0.9)
reasonText:Hide()
local phaseText = container:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
phaseText:SetPoint("BOTTOM", container, "TOP", 0, 2)
phaseText:SetJustifyH("CENTER")
phaseText:SetTextColor(1.0, 0.82, 0.0, 0.9)
phaseText:Hide()
------------------------------------------------------------------------
-- Icons
------------------------------------------------------------------------
local icons = {}
if MasqueGroup then
MasqueGroup:RegisterCallback(function()
for _, icon in ipairs(icons) do
if icon.keybind then
icon.keybind:ClearAllPoints()
icon.keybind:SetPoint("TOPRIGHT", icon, "TOPRIGHT", -2, -2)
end
end
end)
end
local function ClearCooldownText(icon)
if not icon or not icon.cooldownText then return end
icon.cooldownText:SetText("")
icon.cooldownText:Hide()
end
local function ClearCooldown(icon)
if not icon or not icon.cooldown then return end
if icon.cooldown.Clear then
icon.cooldown:Clear()
elseif icon.cooldown.SetCooldown then
icon.cooldown:SetCooldown(0, 0)
end
icon.cooldown:Hide()
ClearCooldownText(icon)
end
local function ClearChargeDisplay(icon)
if not icon then return end
if icon.chargeCooldown then icon.chargeCooldown:Hide() end
if icon.chargeCount then
icon.chargeCount:SetText("")
icon.chargeCount:Hide()
end
end
local function ResetStoredQueue(state)
local prevCount = state.count or 0
for i = 1, prevCount do
state[i] = nil
end
state.count = 0
end
local function StoreQueue(state, queue, count)
local prevCount = state.count or 0
for i = 1, count do
state[i] = queue[i]
end
for i = count + 1, prevCount do
state[i] = nil
end
state.count = count
end
local function QueuesMatch(state, queue, count)
if (state.count or 0) ~= count then return false end
for i = 1, count do
if state[i] ~= queue[i] then
return false
end
end
return true
end
local function ClearPendingQueue()
ResetStoredQueue(pendingQueueState)
pendingQueueTicks = 0
pendingWindowStart = nil
end
local keybindCache = {}
local keybindNameCache = {}
local keybindTextureCache = {}
local actionSlotCache = {}
local actionSlotNameCache = {}
local actionSlotTextureCache = {}
local keybindCacheDirty = true
local ACTION_BUTTON_BINDINGS = {
{ prefix = "ActionButton", commandPrefix = "ACTIONBUTTON" },
{ prefix = "MultiBarBottomLeftButton", commandPrefix = "MULTIACTIONBAR1BUTTON" },
{ prefix = "MultiBarBottomRightButton", commandPrefix = "MULTIACTIONBAR2BUTTON" },
{ prefix = "MultiBarRightButton", commandPrefix = "MULTIACTIONBAR3BUTTON" },
{ prefix = "MultiBarLeftButton", commandPrefix = "MULTIACTIONBAR4BUTTON" },
{ prefix = "MultiBar5Button", commandPrefix = "MULTIACTIONBAR5BUTTON" },
{ prefix = "MultiBar6Button", commandPrefix = "MULTIACTIONBAR6BUTTON" },
{ prefix = "MultiBar7Button", commandPrefix = "MULTIACTIONBAR7BUTTON" },
}
-- ElvUI support: click-binding format "CLICK ElvUI_BarXButtonY:LeftButton"
for i = 1, 15 do
ACTION_BUTTON_BINDINGS[#ACTION_BUTTON_BINDINGS + 1] = {
prefix = "ElvUI_Bar" .. i .. "Button",
commandPrefix = "CLICK ElvUI_Bar" .. i .. "Button",
commandSuffix = ":LeftButton",
}
end
local LegacyGetActionTexture = rawget(_G, "GetActionTexture")
local function NormalizeSpellName(name)
if type(name) ~= "string" then return nil end
name = name:gsub("^%s+", ""):gsub("%s+$", "")
if name == "" then return nil end
return name:lower()
end
local function ResolveSpellNameFromID(spellID)
if not spellID then return nil end
if C_Spell and C_Spell.GetSpellName then
local ok, name = pcall(C_Spell.GetSpellName, spellID)
if ok and not IsSecretValue(name) and name ~= nil then
return NormalizeSpellName(name)
end
end
return nil
end
local function ResolveSpellIDFromIdentifier(spellIdentifier)
if type(spellIdentifier) == "number" then
return spellIdentifier
end
if type(spellIdentifier) ~= "string" then
return nil
end
if C_Spell and C_Spell.GetSpellInfo then
local ok, info = pcall(C_Spell.GetSpellInfo, spellIdentifier)
if ok and not IsSecretValue(info) and info ~= nil and type(info) == "table" then
local spellID = info.spellID
if not IsSecretValue(spellID) and type(spellID) == "number" then
return spellID
end
end
end
return nil
end
local function ResolveSpellFromMacro(macroID)
if not macroID then
return nil, nil
end
if GetMacroSpell then
local macroSpell = GetMacroSpell(macroID)
local spellID = ResolveSpellIDFromIdentifier(macroSpell)
if spellID then
return spellID, ResolveSpellNameFromID(spellID)
end
if type(macroSpell) == "string" then
return nil, NormalizeSpellName(macroSpell)
end
end
if not GetMacroBody then
return nil, nil
end
local body = GetMacroBody(macroID)
if type(body) ~= "string" or body == "" then
return nil, nil
end
for line in body:gmatch("[^\r\n]+") do
local command, args = line:match("^%s*/(%S+)%s+(.+)$")
if command and args then
command = command:lower()
if command == "cast" or command == "castsequence" then
args = args:gsub("%b[]", "")
-- Strip castsequence reset options (e.g. "reset=target/combat")
args = args:gsub("^%s*reset=[^%s]*%s*", "")
local token = args:match("^%s*([^,;]+)")
if token then
token = token:gsub("^%s+", ""):gsub("%s+$", ""):gsub("^!", "")
local spellID = ResolveSpellIDFromIdentifier(tonumber(token) or token)
if spellID then
return spellID, ResolveSpellNameFromID(spellID)
end
local nameKey = NormalizeSpellName(token)
if nameKey then
return nil, nameKey
end
end
end
end
end
return nil, nil
end
local function ResolveActionSlotFromButton(button)
if not button then return nil end
if button.CalculateAction then
local ok, slot = pcall(button.CalculateAction, button)
if ok and not IsSecretValue(slot) and slot ~= nil then return slot end
end
return button.action
end
local function GetPreferredBindingKey(command)
local a, b = GetBindingKey(command)
if b and type(b) == "string" and b:find("%-") and (not a or (type(a) == "string" and not a:find("%-"))) then
return b
end
return a or b
end
local function GetPreferredBindingFromBindingEntry(key1, key2)
if key2 and type(key2) == "string" and key2:find("%-") and (not key1 or (type(key1) == "string" and not key1:find("%-"))) then
return key2
end
return key1 or key2
end
local function CacheSpellKeybind(spellID, spellNameKey, key)
if not key then return end
if spellID and not keybindCache[spellID] then
keybindCache[spellID] = key
end
if spellNameKey and not keybindNameCache[spellNameKey] then
keybindNameCache[spellNameKey] = key
end
end
local function CacheSpellActionSlot(spellID, spellNameKey, texture, slot)
if not slot then return end
if spellID and not actionSlotCache[spellID] then
actionSlotCache[spellID] = slot
end
if spellNameKey and not actionSlotNameCache[spellNameKey] then
actionSlotNameCache[spellNameKey] = slot
end
if texture and not actionSlotTextureCache[texture] then
actionSlotTextureCache[texture] = slot
end
end
local function RebuildKeybindCache()
wipe(keybindCache)
wipe(keybindNameCache)
wipe(keybindTextureCache)
wipe(actionSlotCache)
wipe(actionSlotNameCache)
wipe(actionSlotTextureCache)
for _, bar in ipairs(ACTION_BUTTON_BINDINGS) do
for btn = 1, 12 do
local bindCmd = bar.commandSuffix
and (bar.commandPrefix .. btn .. bar.commandSuffix)
or (bar.commandPrefix .. btn)
local key = GetPreferredBindingKey(bindCmd)
if key then
local button = _G[bar.prefix .. btn]
local slot = ResolveActionSlotFromButton(button)
if slot then
local actionType, id = GetActionInfo(slot)
if actionType == "spell" and id then
local nameKey = ResolveSpellNameFromID(id)
local texture = LegacyGetActionTexture and LegacyGetActionTexture(slot)
CacheSpellKeybind(id, nameKey, key)
CacheSpellActionSlot(id, nameKey, texture, slot)
elseif actionType == "macro" and id then
local spellID, spellNameKey = ResolveSpellFromMacro(id)
local texture = LegacyGetActionTexture and LegacyGetActionTexture(slot)
CacheSpellKeybind(spellID, spellNameKey, key)
CacheSpellActionSlot(spellID, spellNameKey, texture, slot)
if not spellID and not spellNameKey and texture then
if not keybindTextureCache[texture] then
keybindTextureCache[texture] = key
end
if not actionSlotTextureCache[texture] then
actionSlotTextureCache[texture] = slot
end
end
end
end
end
end
end
-- Also support direct keybindings to macros (not on action bars).
if GetNumBindings and GetBinding and GetMacroIndexByName then
for i = 1, GetNumBindings() do
local command, _cat, key1, key2 = GetBinding(i)
if type(command) == "string" and command:find("^MACRO ") then
local macroName = command:sub(7)
local macroID = GetMacroIndexByName(macroName)
if macroID and macroID > 0 then
local spellID, spellNameKey = ResolveSpellFromMacro(macroID)
local key = GetPreferredBindingFromBindingEntry(key1, key2)
CacheSpellKeybind(spellID, spellNameKey, key)
end
end
end
end
keybindCacheDirty = false
end
local keybindFrame = CreateFrame("Frame")
keybindFrame:RegisterEvent("ACTIONBAR_SLOT_CHANGED")
keybindFrame:RegisterEvent("ACTIONBAR_PAGE_CHANGED")
keybindFrame:RegisterEvent("UPDATE_BINDINGS")
keybindFrame:RegisterEvent("SPELLS_CHANGED")
keybindFrame:RegisterEvent("UPDATE_SHAPESHIFT_FORM")
keybindFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
keybindFrame:SetScript("OnEvent", function() keybindCacheDirty = true end)
local function GetKeybindForSpell(spellID)
if keybindCacheDirty then RebuildKeybindCache() end
local key = keybindCache[spellID]
if key then return key end
local nameKey = ResolveSpellNameFromID(spellID)
if nameKey then
key = keybindNameCache[nameKey]
if key then return key end
end
-- Best-effort texture fallback: icon IDs are not unique per spell,
-- so this can misattribute a keybind when spells share an icon.
if C_Spell_GetSpellTexture then
local texture = C_Spell_GetSpellTexture(spellID)
if texture then
key = keybindTextureCache[texture]
if key then
keybindCache[spellID] = key
if nameKey then
keybindNameCache[nameKey] = key
end
return key
end
end
end
return nil
end
local function GetActionSlotForSpell(spellID)
if keybindCacheDirty then RebuildKeybindCache() end
local slot = actionSlotCache[spellID]
if slot then return slot end
local nameKey = ResolveSpellNameFromID(spellID)
if nameKey then
slot = actionSlotNameCache[nameKey]
if slot then return slot end
end
if C_Spell_GetSpellTexture then
local texture = C_Spell_GetSpellTexture(spellID)
if texture then
slot = actionSlotTextureCache[texture]
if slot then
actionSlotCache[spellID] = slot
if nameKey then
actionSlotNameCache[nameKey] = slot
end
return slot
end
end
end
return nil
end
local function FormatKeybindForDisplay(key)
if type(key) ~= "string" then
return ""
end
-- Modifiers
key = key:gsub("SHIFT%-", "S-")
key = key:gsub("CTRL%-", "C-")
key = key:gsub("ALT%-", "A-")
-- Numpad
key = key:gsub("NUMPAD(%d)", "N%1")
key = key:gsub("NUMPADDECIMAL", "N.")
key = key:gsub("NUMPADPLUS", "N+")
key = key:gsub("NUMPADMINUS", "N-")
key = key:gsub("NUMPADMULTIPLY", "N*")
key = key:gsub("NUMPADDIVIDE", "N/")
-- Mouse
key = key:gsub("MOUSEWHEELUP", "MWU")
key = key:gsub("MOUSEWHEELDOWN", "MWD")
key = key:gsub("MIDDLEBUTTON", "M3")
key = key:gsub("BUTTON(%d+)", "M%1")
-- Navigation
key = key:gsub("PAGEUP", "PgU")
key = key:gsub("PAGEDOWN", "PgD")
key = key:gsub("INSERT", "Ins")
key = key:gsub("DELETE", "Del")
key = key:gsub("HOME", "Hm")
-- Common keys
key = key:gsub("BACKSPACE", "BkSp")
key = key:gsub("ESCAPE", "Esc")
key = key:gsub("SPACE", "Sp")
key = key:gsub("ENTER", "Ent")
key = key:gsub("TAB", "Tab")
key = key:gsub("CAPSLOCK", "CpLk")
key = key:gsub("NUMLOCK", "NmLk")
-- Arrows (anchored to avoid mangling gamepad PADD* tokens)
key = key:gsub("^UP$", "Up")
key = key:gsub("%-UP$", "-Up")
key = key:gsub("^DOWN$", "Dn")
key = key:gsub("%-DOWN$", "-Dn")
key = key:gsub("^LEFT$", "Lt")
key = key:gsub("%-LEFT$", "-Lt")
key = key:gsub("^RIGHT$", "Rt")
key = key:gsub("%-RIGHT$", "-Rt")
return key
end
local function CreateIcon(index)
local size = TrueShot.GetOpt("iconSize")
local spacing = TrueShot.GetOpt("iconSpacing")
local frame = CreateFrame("Frame", "TrueShotIcon" .. index,
content)
frame:SetSize(size, size)
frame:SetPoint("LEFT", content, "LEFT",
(index - 1) * (size + spacing), 0)
frame.slotBackground = frame:CreateTexture(nil, "BACKGROUND")
frame.slotBackground:SetAllPoints()
frame.slotBackground:SetAtlas("UI-HUD-ActionBar-IconFrame-Background")
frame.texture = frame:CreateTexture(nil, "ARTWORK")
frame.texture:SetPoint("TOPLEFT", frame, "TOPLEFT", ICON_TEXTURE_INSET, -ICON_TEXTURE_INSET)
frame.texture:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -ICON_TEXTURE_INSET, ICON_TEXTURE_INSET)
frame.texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
if frame.CreateMaskTexture and frame.texture.AddMaskTexture and frame.slotBackground.AddMaskTexture then
local mask = frame:CreateMaskTexture(nil, "ARTWORK")
mask:SetPoint("TOPLEFT", frame, "TOPLEFT", -6, 6)
mask:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 6, -6)
mask:SetAtlas("UI-HUD-ActionBar-IconFrame-Mask", false)
frame.texture:AddMaskTexture(mask)
frame.slotBackground:AddMaskTexture(mask)
frame.mask = mask
end
frame.cooldown = CreateFrame("Cooldown", nil, frame, "CooldownFrameTemplate")
frame.cooldown:ClearAllPoints()
frame.cooldown:SetPoint("TOPLEFT", frame, "TOPLEFT", ICON_TEXTURE_INSET, -ICON_TEXTURE_INSET)
frame.cooldown:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -ICON_TEXTURE_INSET, ICON_TEXTURE_INSET)
frame.cooldown:SetHideCountdownNumbers(true)
if frame.cooldown.SetDrawBling then frame.cooldown:SetDrawBling(false) end
if frame.cooldown.SetDrawEdge then frame.cooldown:SetDrawEdge(false) end
if frame.cooldown.SetSwipeColor then frame.cooldown:SetSwipeColor(0, 0, 0, 0.6) end
frame.cooldown:Hide()
-- Charge cooldown: edge ring above primary CD for charge-based spells
frame.chargeCooldown = CreateFrame("Cooldown", nil, frame, "CooldownFrameTemplate")
frame.chargeCooldown:ClearAllPoints()
frame.chargeCooldown:SetPoint("TOPLEFT", frame, "TOPLEFT", ICON_TEXTURE_INSET, -ICON_TEXTURE_INSET)
frame.chargeCooldown:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -ICON_TEXTURE_INSET, ICON_TEXTURE_INSET)
frame.chargeCooldown:SetHideCountdownNumbers(true)
if frame.chargeCooldown.SetDrawBling then frame.chargeCooldown:SetDrawBling(false) end
if frame.chargeCooldown.SetDrawSwipe then frame.chargeCooldown:SetDrawSwipe(false) end
if frame.chargeCooldown.SetDrawEdge then frame.chargeCooldown:SetDrawEdge(true) end
frame.chargeCooldown:SetFrameLevel(frame.cooldown:GetFrameLevel() + 1)
frame.chargeCooldown:Hide()
frame.chargeCount = frame:CreateFontString(nil, "OVERLAY", "NumberFontNormalSmall")
frame.chargeCount:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -2, 2)
frame.chargeCount:SetJustifyH("RIGHT")
frame.chargeCount:Hide()
-- Remaining cooldown text overlay. Parented to the cooldown frame so it
-- naturally sits above the swipe; visibility is gated explicitly by
-- UpdateCooldownText (option toggle, swipe option, secret guards).
frame.cooldownText = frame.cooldown:CreateFontString(nil, "OVERLAY", "NumberFontNormalLarge")
frame.cooldownText:SetPoint("CENTER", frame.cooldown, "CENTER", 0, 0)
frame.cooldownText:SetJustifyH("CENTER")
frame.cooldownText:SetJustifyV("MIDDLE")
frame.cooldownText:Hide()
frame.keybind = frame:CreateFontString(nil, "OVERLAY", "NumberFontNormalSmallGray")
frame.keybind:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -2, -2)
frame.keybind:SetJustifyH("RIGHT")
frame.success = frame:CreateTexture(nil, "OVERLAY")
frame.success:SetAllPoints()
frame.success:SetAtlas("UI-HUD-ActionBar-IconFrame-Mouseover")
frame.success:SetVertexColor(0.20, 1.00, 0.35, 1.0)
frame.success:SetBlendMode("ADD")
frame.success:Hide()
frame.successUntil = 0
frame.spellID = nil
frame.border = frame:CreateTexture(nil, "OVERLAY")
frame.border:SetAllPoints()
frame.border:SetAtlas("UI-HUD-ActionBar-IconFrame")
-- Override glow: pulsing overlay when TrueShot overrides AC
frame.glow = frame:CreateTexture(nil, "OVERLAY", nil, 2)
frame.glow:SetAllPoints()
frame.glow:SetAtlas("UI-HUD-ActionBar-IconFrame-Mouseover")
frame.glow:SetBlendMode("ADD")
frame.glow:SetAlpha(0)
frame.glow:Hide()
frame.glowAnim = frame.glow:CreateAnimationGroup()
frame.glowAnim:SetLooping("BOUNCE")
local fadeIn = frame.glowAnim:CreateAnimation("Alpha")
fadeIn:SetFromAlpha(0.3)
fadeIn:SetToAlpha(0.9)
fadeIn:SetDuration(0.4)
fadeIn:SetOrder(1)
fadeIn:SetSmoothing("IN_OUT")
if MasqueGroup then
-- Masque owns background and border; hide native versions
frame.slotBackground:Hide()
frame.border:Hide()
MasqueGroup:AddButton(frame, {
Icon = frame.texture,
Cooldown = frame.cooldown,
ChargeCooldown = frame.chargeCooldown,
HotKey = frame.keybind,
Normal = frame.border,
}, "Frame")
end
if index > 1 then
frame:SetAlpha(0.7)
end
frame:Hide()
return frame
end
local GLOW_COLORS = {
pin = { 0.0, 0.8, 1.0 },
prefer = { 0.4, 0.6, 1.0 },
hybrid = { 0.1, 0.9, 0.6 },
}
local function HideGlow(icon)
if not icon or not icon.glow then return end
icon.glowAnim:Stop()
icon.glow:Hide()
end
local function ShowGlow(icon, source)
if not icon or not icon.glow then return end
local color = GLOW_COLORS[source]
if not color then
HideGlow(icon)
return
end
icon.glow:SetVertexColor(color[1], color[2], color[3], 1.0)
icon.glow:Show()
if not icon.glowAnim:IsPlaying() then
icon.glowAnim:Play()
end
end
------------------------------------------------------------------------
-- AoE hint sub-icon (anchored below icon 1)
------------------------------------------------------------------------
local aoeHintIcon
local aoeHintDisplayed = nil -- currently shown spell
local aoeHintPending = nil -- candidate spell awaiting stabilization
local aoeHintPendingTicks = 0
local function CreateAoeHintIcon()
local size = TrueShot.GetOpt("iconSize") or 40
local frame = CreateFrame("Frame", "TrueShotAoeHint", content)
frame:SetSize(size, size)
frame.slotBackground = frame:CreateTexture(nil, "BACKGROUND")
frame.slotBackground:SetAllPoints()
frame.slotBackground:SetAtlas("UI-HUD-ActionBar-IconFrame-Background")
frame.texture = frame:CreateTexture(nil, "ARTWORK")
frame.texture:SetPoint("TOPLEFT", frame, "TOPLEFT", ICON_TEXTURE_INSET, -ICON_TEXTURE_INSET)
frame.texture:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", -ICON_TEXTURE_INSET, ICON_TEXTURE_INSET)
frame.texture:SetTexCoord(0.07, 0.93, 0.07, 0.93)
frame.border = frame:CreateTexture(nil, "OVERLAY")
frame.border:SetAllPoints()
frame.border:SetAtlas("UI-HUD-ActionBar-IconFrame")
frame.keybind = frame:CreateFontString(nil, "OVERLAY", "NumberFontNormalSmallGray")
frame.keybind:SetPoint("TOPRIGHT", frame, "TOPRIGHT", -1, -1)
frame.keybind:SetJustifyH("RIGHT")
-- Pulsing AoE glow
frame.glow = frame:CreateTexture(nil, "OVERLAY", nil, 2)
frame.glow:SetAllPoints()
frame.glow:SetAtlas("UI-HUD-ActionBar-IconFrame-Mouseover")
frame.glow:SetVertexColor(1.0, 0.5, 0.1, 1.0) -- orange
frame.glow:SetBlendMode("ADD")
frame.glow:SetAlpha(0)
frame.glow:Hide()
frame.glowAnim = frame.glow:CreateAnimationGroup()
frame.glowAnim:SetLooping("BOUNCE")
local glowFade = frame.glowAnim:CreateAnimation("Alpha")
glowFade:SetFromAlpha(0.25)
glowFade:SetToAlpha(0.75)
glowFade:SetDuration(0.5)
glowFade:SetOrder(1)
glowFade:SetSmoothing("IN_OUT")
-- Scale bounce on appear
frame.bounceAnim = frame:CreateAnimationGroup()
local scaleUp = frame.bounceAnim:CreateAnimation("Scale")
scaleUp:SetScale(1.35, 1.35)
scaleUp:SetDuration(0.12)
scaleUp:SetOrder(1)
scaleUp:SetSmoothing("OUT")
local scaleDown = frame.bounceAnim:CreateAnimation("Scale")
scaleDown:SetScale(1 / 1.35, 1 / 1.35)
scaleDown:SetDuration(0.15)
scaleDown:SetOrder(2)
scaleDown:SetSmoothing("IN")
frame:SetAlpha(1)
frame:Hide()
return frame
end
------------------------------------------------------------------------
-- Idle state (anchored at icon 1 with a separate status line)
------------------------------------------------------------------------
local idleFrame
local idleText
local function LayoutIdleState()
if not idleFrame or not icons[1] then return end
local size = TrueShot.GetOpt("iconSize") or 40
local firstScale = TrueShot.GetOpt("firstIconScale") or 1.3
idleFrame:SetSize(size, size)
idleFrame:SetScale(firstScale)
idleFrame:ClearAllPoints()
idleFrame:SetPoint("CENTER", icons[1], "CENTER", 0, 0)
idleText:ClearAllPoints()
idleText:SetPoint("TOP", container, "BOTTOM", 0, -2)
end
local function CreateIdleState()
local frame = CreateFrame("Frame", "TrueShotIdleFrame", content)
frame.slotBackground = frame:CreateTexture(nil, "BACKGROUND")
frame.slotBackground:SetAllPoints()
frame.slotBackground:SetAtlas("UI-HUD-ActionBar-IconFrame-Background")
frame.border = frame:CreateTexture(nil, "OVERLAY")
frame.border:SetAllPoints()
frame.border:SetAtlas("UI-HUD-ActionBar-IconFrame")
idleText = container:CreateFontString(nil, "OVERLAY", "GameFontHighlightSmall")
idleText:SetJustifyH("CENTER")
idleText:SetWordWrap(false)
idleText:SetTextColor(0.6, 0.6, 0.6, 0.9)
idleText:Hide()
idleFrame = frame
LayoutIdleState()
idleFrame:Hide()
end
local function HideIdleState()
if idleFrame then idleFrame:Hide() end
if idleText then idleText:Hide() end
end
local function ShowIdleState()
if not idleFrame then CreateIdleState() end
idleText:SetText(BuildIdleStateLabel(committedMeta))
idleFrame:Show()
idleText:Show()
end
local function RenderAoeHint(spellID)
local wasHidden = not aoeHintIcon or not aoeHintIcon:IsShown()
local prevSpell = aoeHintDisplayed
if not spellID then
aoeHintDisplayed = nil
if aoeHintIcon then
if aoeHintIcon.glowAnim then aoeHintIcon.glowAnim:Stop() end
if aoeHintIcon.glow then aoeHintIcon.glow:Hide() end
aoeHintIcon:Hide()
end
return
end
if not aoeHintIcon then
aoeHintIcon = CreateAoeHintIcon()
end
local texture = C_Spell_GetSpellTexture and C_Spell_GetSpellTexture(spellID)
if not texture then
aoeHintDisplayed = nil
aoeHintIcon.glowAnim:Stop()
aoeHintIcon.glow:Hide()
aoeHintIcon:Hide()
return
end
-- Only show when icon 1 is visible
if not icons[1] or not icons[1]:IsShown() then
aoeHintDisplayed = nil
aoeHintIcon.glowAnim:Stop()
aoeHintIcon.glow:Hide()
aoeHintIcon:Hide()
return
end
local iconSize = TrueShot.GetOpt("iconSize") or 40
local spacing = TrueShot.GetOpt("iconSpacing") or 4
local orient = TrueShot.GetOpt("orientation") or "LEFT"
aoeHintIcon:SetSize(iconSize, iconSize)
aoeHintIcon:SetAlpha(1)
aoeHintIcon:ClearAllPoints()
local aoePos = TrueShot.GetOpt("aoeHintPosition") or "BELOW"
if aoePos == "LEFT" then
-- Position to the left of the primary icon, offset past queue icons if RIGHT orientation
if orient == "RIGHT" then
-- Queue grows right; place left of container to avoid overlap with icon 2
aoeHintIcon:SetPoint("RIGHT", container, "LEFT", -spacing, 0)
else
aoeHintIcon:SetPoint("RIGHT", icons[1], "LEFT", -spacing, 0)
end
else
-- BELOW: always below icon 1, regardless of orientation
aoeHintIcon:SetPoint("TOP", icons[1], "BOTTOM", 0, -spacing)
end
aoeHintIcon.texture:SetTexture(texture)
if TrueShot.GetOpt("showKeybinds") then
local key = GetKeybindForSpell(spellID)
aoeHintIcon.keybind:SetText(FormatKeybindForDisplay(key))
else
aoeHintIcon.keybind:SetText("")
end
aoeHintIcon:Show()
aoeHintDisplayed = spellID
-- Animate on first appear or spell change
if wasHidden or prevSpell ~= spellID then
aoeHintIcon.glow:Show()
if not aoeHintIcon.glowAnim:IsPlaying() then
aoeHintIcon.glowAnim:Play()
end
aoeHintIcon.bounceAnim:Stop()