Repository navigation
Expand file tree
/
Copy pathCWT.lua
More file actions
641 lines (560 loc) · 22.5 KB
/
Copy pathCWT.lua
File metadata and controls
641 lines (560 loc) · 22.5 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
-- CWT.lua
-- Shows "USE COACH'S WHISTLE" when:
-- - Emerald Coach's Whistle equipped in trinket slot 13 or 14
-- - NOT in combat
-- - In a group or raid
-- - Inside a raid, dungeon, or Mythic+ instance
-- - No Coaching buff (or buff expiring in < 5 min)
--
-- /cwt — open settings
-- ============================================================
-- Constants
-- ============================================================
local ITEM_ID = 193718
local SPELL_COACHING = 389581
local TRINKET_1 = 13
local TRINKET_2 = 14
local WARN_SECS = 300
local TICK_INTERVAL = 30
local SOUND_ID = 204190
local FONT_SIZE_MIN = 18
local FONT_SIZE_MAX = 96
local FONT_FILE = "Fonts\\FRIZQT__.TTF"
local COLOR_PRESETS = {
{ label = "Red", r = 1.0, g = 0.15, b = 0.15 },
{ label = "Orange", r = 1.0, g = 0.55, b = 0.0 },
{ label = "Yellow", r = 1.0, g = 1.0, b = 0.0 },
{ label = "Green", r = 0.0, g = 1.0, b = 0.2 },
{ label = "White", r = 1.0, g = 1.0, b = 1.0 },
{ label = "Cyan", r = 0.0, g = 1.0, b = 1.0 },
}
local DB_DEFAULTS = {
posX = 0,
posY = 120,
fontSize = 46,
colorR = 1.0,
colorG = 0.15,
colorB = 0.15,
muted = false,
instanceOnly = true,
}
-- Pulse
local _sin = math.sin
local _pi2 = math.pi * 2
local PULSE_PERIOD = 1.4
local ALPHA_LO = 0.25
local ALPHA_HI = 1.00
local ALPHA_MID = (ALPHA_HI + ALPHA_LO) / 2
local ALPHA_AMP = (ALPHA_HI - ALPHA_LO) / 2
local pulseTime = 0
-- ============================================================
-- Conditions
-- ============================================================
local function WhistleEquipped()
return GetInventoryItemID("player", TRINKET_1) == ITEM_ID
or GetInventoryItemID("player", TRINKET_2) == ITEM_ID
end
local function CoachingBuffOK()
local data = C_UnitAuras.GetPlayerAuraBySpellID(SPELL_COACHING)
if not data then
-- GetPlayerAuraBySpellID returns nil both when the buff is genuinely
-- absent AND when aura data is restricted in an active M+ key (even
-- between pulls). We cannot distinguish the two from nil alone.
-- Safe default: if a M+ key is active, assume the buff is present to
-- avoid a false-positive warning. We will catch the real absence once
-- the key ends or via the UNIT_AURA event when the buff actually drops.
if C_ChallengeMode and C_ChallengeMode.IsChallengeModeActive
and C_ChallengeMode.IsChallengeModeActive() then
return true
end
return false
end
if not data.expirationTime or data.expirationTime == 0 then return true end
return (data.expirationTime - GetTime()) >= WARN_SECS
end
local function AuraAccessRestricted()
if C_RestrictedActions and C_RestrictedActions.IsRestrictionActive then
return C_RestrictedActions.IsRestrictionActive(Enum.AddOnRestrictionType.Combat)
or C_RestrictedActions.IsRestrictionActive(Enum.AddOnRestrictionType.Encounter)
end
return InCombatLockdown()
end
-- Returns true only when inside a raid, dungeon, or Mythic+ instance.
-- instanceType == "party" covers normal/heroic dungeons and Mythic+
-- instanceType == "raid" covers all raid difficulties
local function InInstanceContent()
local inInstance, instanceType = IsInInstance()
return inInstance and (instanceType == "raid" or instanceType == "party")
end
local function ShouldWarn()
if not WhistleEquipped() then return false end
if InCombatLockdown() then return false end
if not IsInGroup() then return false end
if CWTDB and CWTDB.instanceOnly and not InInstanceContent() then return false end
if AuraAccessRestricted() then return false end
if CoachingBuffOK() then return false end
return true
end
-- ============================================================
-- Frame
-- ============================================================
local frame = CreateFrame("Frame", "CWTFrame", UIParent)
frame:SetSize(900, 120)
frame:SetFrameStrata("HIGH")
frame:SetFrameLevel(100)
frame:Hide()
local label = frame:CreateFontString(nil, "OVERLAY")
label:SetAllPoints(frame)
label:SetFont(FONT_FILE, DB_DEFAULTS.fontSize, "OUTLINE")
label:SetTextColor(DB_DEFAULTS.colorR, DB_DEFAULTS.colorG, DB_DEFAULTS.colorB, 1)
label:SetShadowColor(0, 0, 0, 1)
label:SetShadowOffset(2, -2)
label:SetJustifyH("CENTER")
label:SetJustifyV("MIDDLE")
label:SetText("USE COACH'S WHISTLE")
local function ApplySavedAppearance()
if not CWTDB then return end
label:SetFont(FONT_FILE, CWTDB.fontSize or DB_DEFAULTS.fontSize, "OUTLINE")
label:SetTextColor(
CWTDB.colorR or DB_DEFAULTS.colorR,
CWTDB.colorG or DB_DEFAULTS.colorG,
CWTDB.colorB or DB_DEFAULTS.colorB, 1)
end
-- ============================================================
-- Pulse
-- ============================================================
frame:SetScript("OnShow", function(self)
pulseTime = 0
if not (CWTDB and CWTDB.muted) then
PlaySound(SOUND_ID, "Master")
end
self:SetScript("OnUpdate", function(_, elapsed)
pulseTime = (pulseTime + elapsed) % PULSE_PERIOD
frame:SetAlpha(ALPHA_MID + ALPHA_AMP * _sin(
pulseTime * _pi2 / PULSE_PERIOD + (math.pi / 2)))
end)
end)
frame:SetScript("OnHide", function(self)
self:SetScript("OnUpdate", nil)
self:SetAlpha(ALPHA_HI)
end)
-- ============================================================
-- Show / Hide
-- ============================================================
local previewMode = false
local function Show()
if not frame:IsShown() then frame:Show() end
end
local function Hide()
previewMode = false
frame:Hide()
end
-- ============================================================
-- Ticker (30s safety net)
-- ============================================================
local ticker = nil
local function StartTicker()
if ticker then return end
ticker = C_Timer.NewTicker(TICK_INTERVAL, function()
if previewMode then return end
if ShouldWarn() then Show() else if frame:IsShown() then Hide() end end
end)
end
local function StopTicker()
if ticker then ticker:Cancel(); ticker = nil end
end
-- ============================================================
-- Event gating
-- Only four events are registered at all times:
-- ADDON_LOADED — one-shot DB + settings init
-- PLAYER_LOGIN — initial equipment check
-- PLAYER_ENTERING_WORLD — zone-change equipment check
-- PLAYER_EQUIPMENT_CHANGED — equip/unequip gate
--
-- Everything else (combat, auras, roster, pet battle) lives
-- in TRACKED_EVENTS and is only registered via EnableTracking()
-- when the trinket is equipped. Characters without the whistle
-- pay zero per-event CPU cost after login.
-- ============================================================
local TRACKED_EVENTS = {
"PLAYER_REGEN_DISABLED",
"PLAYER_REGEN_ENABLED",
"UNIT_AURA",
"GROUP_ROSTER_UPDATE",
"PET_BATTLE_OPENING_START",
"PET_BATTLE_CLOSE",
}
local trackingActive = false
local function EnableTracking()
if trackingActive then return end
trackingActive = true
for _, e in ipairs(TRACKED_EVENTS) do events:RegisterEvent(e) end
StartTicker()
end
local function DisableTracking()
if not trackingActive then return end
trackingActive = false
for _, e in ipairs(TRACKED_EVENTS) do events:UnregisterEvent(e) end
StopTicker()
Hide()
end
-- ============================================================
-- Drag
-- ============================================================
local function EnableDrag()
frame:SetMovable(true)
frame:EnableMouse(true)
frame:RegisterForDrag("LeftButton")
frame:SetScript("OnDragStart", function(self) self:StartMoving() end)
frame:SetScript("OnDragStop", function(self)
self:StopMovingOrSizing()
if CWTDB then
local x, y = self:GetCenter()
local cx, cy = UIParent:GetCenter()
CWTDB.posX = x - cx
CWTDB.posY = y - cy
end
print("|cffff9900[CWT]|r Position saved.")
end)
end
local function DisableDrag()
frame:SetMovable(false)
frame:EnableMouse(false)
frame:SetScript("OnDragStart", nil)
frame:SetScript("OnDragStop", nil)
end
-- ============================================================
-- Debug print (shared by button and legacy slash)
-- ============================================================
local function PrintDebug()
local data = C_UnitAuras.GetPlayerAuraBySpellID(SPELL_COACHING)
local rem = 0
if data and data.expirationTime and data.expirationTime > 0 then
rem = math.max(0, data.expirationTime - GetTime())
end
local inInst, instType = IsInInstance()
print("|cffff9900[CWT Debug]|r ---")
print(" equipped = " .. tostring(WhistleEquipped()))
print(" inCombat = " .. tostring(InCombatLockdown()))
print(" inGroup = " .. tostring(IsInGroup()))
print(" inInstance = " .. tostring(inInst) .. " (" .. tostring(instType) .. ")")
print(" buffOK = " .. tostring(CoachingBuffOK()))
print(" remaining = " .. string.format("%.0f", rem) .. "s")
print(" ShouldWarn = " .. tostring(ShouldWarn()))
print(" visible = " .. tostring(frame:IsShown()))
print(" muted = " .. tostring(CWTDB and CWTDB.muted))
print(" fontSize = " .. tostring(CWTDB and CWTDB.fontSize))
print(" ticker = " .. tostring(ticker ~= nil))
print(" tracking = " .. tostring(trackingActive))
end
-- ============================================================
-- Settings panel
-- ============================================================
local CWTCategory
local muteBtn -- referenced in ApplyMuteLabel below
local function ApplyMuteLabel()
if not muteBtn then return end
local muted = CWTDB and CWTDB.muted
muteBtn:SetText(muted and "Unmute Sound" or "Mute Sound")
end
local function BuildSettingsCanvas()
local W = 600
local PAD = 20
local BTN_H = 26
local HALF_W = math.floor((W - PAD * 2 - 8) / 2)
local _floor = math.floor
local y = -10
local outer = CreateFrame("Frame")
outer:SetSize(W, 700)
outer:Hide()
local scrollFrame = CreateFrame("ScrollFrame", "CWTSettingsScroll", outer, "UIPanelScrollFrameTemplate")
scrollFrame:SetPoint("TOPLEFT", outer, "TOPLEFT", 0, 0)
scrollFrame:SetPoint("BOTTOMRIGHT", outer, "BOTTOMRIGHT", -26, 0)
local canvas = CreateFrame("Frame", nil, scrollFrame)
canvas:SetSize(W - 30, 900)
scrollFrame:SetScrollChild(canvas)
local function addGap(px) y = y - px end
local function sectionHeader(text)
local fs = canvas:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
fs:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD, y)
fs:SetText(text)
addGap(26)
end
local function divider()
local line = canvas:CreateTexture(nil, "ARTWORK")
line:SetColorTexture(0.3, 0.3, 0.3, 0.5)
line:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD, y)
line:SetPoint("TOPRIGHT", canvas, "TOPRIGHT", -PAD, y)
line:SetHeight(1)
addGap(14)
end
-- ── Position ─────────────────────────────────────────────
sectionHeader("Position")
local showBtn = CreateFrame("Button", nil, canvas, "UIPanelButtonTemplate")
showBtn:SetSize(HALF_W, BTN_H)
showBtn:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD, y)
showBtn:SetText("Show Warning")
local hideBtn = CreateFrame("Button", nil, canvas, "UIPanelButtonTemplate")
hideBtn:SetSize(HALF_W, BTN_H)
hideBtn:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD + HALF_W + 8, y)
hideBtn:SetText("Hide Warning")
addGap(BTN_H + 8)
local dragBtn = CreateFrame("Button", nil, canvas, "UIPanelButtonTemplate")
dragBtn:SetSize(HALF_W, BTN_H)
dragBtn:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD, y)
dragBtn:SetText("Drag to Reposition")
local resetBtn = CreateFrame("Button", nil, canvas, "UIPanelButtonTemplate")
resetBtn:SetSize(HALF_W, BTN_H)
resetBtn:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD + HALF_W + 8, y)
resetBtn:SetText("Reset Position")
addGap(BTN_H + 18)
divider()
-- ── Font Size ─────────────────────────────────────────────
sectionHeader("Font Size")
local sizeSlider = CreateFrame("Slider", "CWTSizeSlider", canvas, "OptionsSliderTemplate")
sizeSlider:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD + 8, y)
sizeSlider:SetWidth(W - PAD * 2 - 16)
sizeSlider:SetMinMaxValues(FONT_SIZE_MIN, FONT_SIZE_MAX)
sizeSlider:SetValueStep(2)
sizeSlider:SetObeyStepOnDrag(true)
sizeSlider:SetValue(DB_DEFAULTS.fontSize)
CWTSizeSliderLow:SetText(FONT_SIZE_MIN .. "pt")
CWTSizeSliderHigh:SetText(FONT_SIZE_MAX .. "pt")
CWTSizeSliderText:SetText("")
local sizeReadout = canvas:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
sizeReadout:SetPoint("BOTTOM", sizeSlider, "TOP", 0, 4)
local lastSize = DB_DEFAULTS.fontSize
local function refreshSize(v)
local s = _floor(v + 0.5)
sizeReadout:SetText(s .. "pt")
return s
end
refreshSize(sizeSlider:GetValue())
sizeSlider:SetScript("OnValueChanged", function(self, val)
if not CWTDB then return end
local s = refreshSize(val)
if s == lastSize then return end
lastSize = s
CWTDB.fontSize = s
label:SetFont(FONT_FILE, s, "OUTLINE")
end)
addGap(54)
divider()
-- ── Color ─────────────────────────────────────────────────
sectionHeader("Text Color")
for i, preset in ipairs(COLOR_PRESETS) do
local col = (i - 1) % 2
local row = _floor((i - 1) / 2)
local btn = CreateFrame("Button", nil, canvas, "UIPanelButtonTemplate")
btn:SetSize(HALF_W, BTN_H)
btn:SetPoint("TOPLEFT", canvas, "TOPLEFT",
PAD + col * (HALF_W + 8), y - row * (BTN_H + 4))
btn:SetText(preset.label)
local fs = btn:GetFontString()
if fs then fs:SetTextColor(preset.r, preset.g, preset.b, 1) end
local r, g, b = preset.r, preset.g, preset.b
btn:SetScript("OnClick", function()
if not CWTDB then return end
CWTDB.colorR, CWTDB.colorG, CWTDB.colorB = r, g, b
label:SetTextColor(r, g, b, 1)
end)
end
addGap(math.ceil(#COLOR_PRESETS / 2) * (BTN_H + 4) + 18)
divider()
-- ── Instance Only ─────────────────────────────────────────
sectionHeader("Visibility")
local instanceCB = CreateFrame("CheckButton", "CWTInstanceCB", canvas, "UICheckButtonTemplate")
instanceCB:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD - 2, y)
CWTInstanceCBText:SetText("Show only inside instances (raids, dungeons, Mythic+)")
CWTInstanceCBText:SetFontObject("GameFontNormal")
instanceCB:SetScript("OnClick", function(self)
if not CWTDB then return end
CWTDB.instanceOnly = self:GetChecked()
if ShouldWarn() then Show() else Hide() end
end)
addGap(BTN_H + 18)
divider()
-- ── Sound ─────────────────────────────────────────────────
sectionHeader("Sound")
muteBtn = CreateFrame("Button", nil, canvas, "UIPanelButtonTemplate")
muteBtn:SetSize(HALF_W, BTN_H)
muteBtn:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD, y)
ApplyMuteLabel()
addGap(BTN_H + 18)
divider()
-- ── Debug ─────────────────────────────────────────────────
sectionHeader("Debug")
local debugBtn = CreateFrame("Button", nil, canvas, "UIPanelButtonTemplate")
debugBtn:SetSize(HALF_W, BTN_H)
debugBtn:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD, y)
debugBtn:SetText("Debug State")
addGap(BTN_H + 18)
divider()
-- ── Footer ────────────────────────────────────────────────
local function fline(text, indent)
local fs = canvas:CreateFontString(nil, "OVERLAY", "GameFontNormalSmall")
fs:SetPoint("TOPLEFT", canvas, "TOPLEFT", PAD + (indent or 0), y)
fs:SetTextColor(0.72, 0.72, 0.72, 1)
fs:SetText(text)
addGap(18)
end
fline("|cFFFFD700CWT - Coach's Whistle Tracker|r")
fline("|cFFFFD700/cwt|r - Opens Options/Settings Menu", 8)
fline("|cFFFFD700Github:|r |cFF4DA6FF[https://github.com/Seems-Good/CWT]|r", 8)
fline("|cFFFFD700Guild:|r |cFF4DA6FF[https://seemsgood.org]|r", 8)
-- Trim canvas to actual content so there's no dead scroll space
canvas:SetHeight(-y + PAD)
-- ── Sync panel on open ────────────────────────────────────
outer:SetScript("OnShow", function()
if not CWTDB then return end
local sz = CWTDB.fontSize or DB_DEFAULTS.fontSize
lastSize = sz
sizeSlider:SetValue(sz)
refreshSize(sz)
ApplyMuteLabel()
instanceCB:SetChecked(CWTDB.instanceOnly ~= false)
end)
-- Close settings → stop drag preview
if SettingsPanel then
SettingsPanel:HookScript("OnHide", function()
DisableDrag()
if not ShouldWarn() then Hide() end
end)
end
-- ── Callbacks ─────────────────────────────────────────────
showBtn:SetScript("OnClick", function()
previewMode = true
Show()
end)
hideBtn:SetScript("OnClick", function()
DisableDrag()
Hide()
end)
dragBtn:SetScript("OnClick", function()
previewMode = true
Show()
EnableDrag()
print("|cffff9900[CWT]|r Drag the warning into position, then click Hide.")
end)
resetBtn:SetScript("OnClick", function()
if not CWTDB then return end
CWTDB.posX, CWTDB.posY = DB_DEFAULTS.posX, DB_DEFAULTS.posY
frame:ClearAllPoints()
frame:SetPoint("CENTER", UIParent, "CENTER", CWTDB.posX, CWTDB.posY)
print("|cffff9900[CWT]|r Position reset.")
end)
muteBtn:SetScript("OnClick", function()
if not CWTDB then return end
CWTDB.muted = not CWTDB.muted
ApplyMuteLabel()
print("|cffff9900[CWT]|r Sound " .. (CWTDB.muted and "muted." or "unmuted."))
end)
debugBtn:SetScript("OnClick", PrintDebug)
return outer
end
local function RegisterSettings()
if not (Settings and Settings.RegisterCanvasLayoutCategory) then return end
local canvas = BuildSettingsCanvas()
CWTCategory = Settings.RegisterCanvasLayoutCategory(canvas, "Coach's Whistle Tracker")
Settings.RegisterAddOnCategory(CWTCategory)
end
local function OpenConfig()
if CWTCategory and Settings and Settings.OpenToCategory then
Settings.OpenToCategory(CWTCategory:GetID())
end
end
-- ============================================================
-- Events
-- Only four events are registered at all times:
-- ADDON_LOADED — one-shot DB + settings init
-- PLAYER_LOGIN — initial equipment check
-- PLAYER_ENTERING_WORLD — zone-change equipment check
-- PLAYER_EQUIPMENT_CHANGED — equip/unequip gate
--
-- Everything else (combat, auras, roster, pet battle) lives
-- in TRACKED_EVENTS and is only registered via EnableTracking()
-- when the trinket is equipped. Characters without the whistle
-- pay zero per-event CPU cost after login.
-- ============================================================
local rosterPending = false
events = CreateFrame("Frame")
events:RegisterEvent("ADDON_LOADED")
events:RegisterEvent("PLAYER_LOGIN")
events:RegisterEvent("PLAYER_ENTERING_WORLD")
events:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")
events:SetScript("OnEvent", function(self, event, arg1)
if event == "ADDON_LOADED" and arg1 == "CWT" then
self:UnregisterEvent("ADDON_LOADED")
CWTDB = CWTDB or {}
for k, v in pairs(DB_DEFAULTS) do
if CWTDB[k] == nil then CWTDB[k] = v end
end
frame:ClearAllPoints()
frame:SetPoint("CENTER", UIParent, "CENTER", CWTDB.posX, CWTDB.posY)
ApplySavedAppearance()
RegisterSettings()
return
end
if event == "PLAYER_LOGIN" then
C_Timer.After(2, function()
if WhistleEquipped() then
EnableTracking()
if ShouldWarn() then Show() end
end
end)
return
end
if event == "PLAYER_ENTERING_WORLD" then
-- Always hide on zone change; deferred check re-shows if needed.
Hide()
DisableTracking()
C_Timer.After(2, function()
if WhistleEquipped() then
EnableTracking()
if ShouldWarn() then Show() end
end
end)
return
end
if event == "PLAYER_EQUIPMENT_CHANGED" then
if WhistleEquipped() then
EnableTracking()
if ShouldWarn() then Show() end
else
DisableTracking()
end
return
end
-- ── Everything below only fires when tracking is active ──
if event == "PLAYER_REGEN_DISABLED" or event == "PET_BATTLE_OPENING_START" then
Hide()
return
end
if event == "UNIT_AURA" then
if arg1 ~= "player" then return end
-- Defer one frame so PLAYER_REGEN_DISABLED fires first (race condition fix)
C_Timer.After(0, function()
if ShouldWarn() then Show() else Hide() end
end)
return
end
if event == "GROUP_ROSTER_UPDATE" then
if rosterPending then return end
rosterPending = true
C_Timer.After(0.5, function()
rosterPending = false
if ShouldWarn() then Show() else Hide() end
end)
return
end
-- PLAYER_REGEN_ENABLED, PET_BATTLE_CLOSE, and any future
-- tracked events fall through to here.
if ShouldWarn() then Show() else Hide() end
end)
-- ============================================================
-- Slash — /cwt opens config
-- ============================================================
SLASH_CWT1 = "/cwt"
SlashCmdList["CWT"] = function()
OpenConfig()
end