-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathCreate.lua
More file actions
executable file
·2604 lines (2287 loc) · 115 KB
/
Copy pathCreate.lua
File metadata and controls
executable file
·2604 lines (2287 loc) · 115 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 addonName, DF = ...
-- ============================================================
-- FRAMES CREATE MODULE
-- Contains frame creation functions
-- ============================================================
-- ============================================================
-- BINDING TOOLTIP
-- Separate tooltip showing click-cast bindings on unit frame hover.
-- Spell usability / cooldown shown out of combat only (secret values).
-- ============================================================
local issecretvalue = issecretvalue or function() return false end
local pairs, ipairs = pairs, ipairs
local wipe = wipe
local format = string.format
local tinsert = table.insert
local tsort = table.sort
local ceil = math.ceil
local InCombatLockdown = InCombatLockdown
local UnitExists = UnitExists
local UnitIsDeadOrGhost = UnitIsDeadOrGhost
local GetTime = GetTime
local IsShiftKeyDown = IsShiftKeyDown
local IsControlKeyDown = IsControlKeyDown
local IsAltKeyDown = IsAltKeyDown
local bindingTooltip = CreateFrame("GameTooltip", "DFBindingTooltip", UIParent, "GameTooltipTemplate")
bindingTooltip:SetFrameStrata("TOOLTIP")
if bindingTooltip.NineSlice then
for _, piece in pairs({"TopLeftCorner", "TopRightCorner", "BottomLeftCorner", "BottomRightCorner", "TopEdge", "BottomEdge", "LeftEdge", "RightEdge"}) do
if bindingTooltip.NineSlice[piece] then bindingTooltip.NineSlice[piece]:SetAlpha(0) end
end
end
DFBindingTooltipTextLeft1:SetFontObject(GameTooltipText)
local BINDING_SHORT_NAMES = {
LeftButton = "Left", RightButton = "Right", MiddleButton = "Middle",
}
local BINDING_SORT_ORDER = {
LeftButton = 1, MiddleButton = 2, RightButton = 3,
Button4 = 4, Button5 = 5, Button6 = 6, Button7 = 7, Button8 = 8,
Button9 = 9, Button10 = 10, Button11 = 11, Button12 = 12,
Button13 = 13, Button14 = 14, Button15 = 15, Button16 = 16,
}
-- Pre-allocated table for tooltip lines (wiped each call)
local lines = {}
local function getActiveModifier()
local mods = ""
if IsShiftKeyDown() then mods = mods .. "shift-" end
if IsControlKeyDown() then mods = mods .. "ctrl-" end
if IsAltKeyDown() then mods = mods .. "alt-" end
if IsMetaKeyDown and IsMetaKeyDown() then mods = mods .. "meta-" end
return mods
end
local function bindingMatchesMod(binding, activeMod)
local mods = binding.modifiers or ""
return mods == activeMod
end
-- Position the binding tooltip based on settings (mirrors PositionFrameTooltip pattern)
local function positionBindingTooltip(anchorFrame, db)
local anchor = db.tooltipBindingAnchor or "FRAME"
local anchorPos = db.tooltipBindingAnchorPos or "TOPRIGHT"
local offsetX = db.tooltipBindingX or 4
local offsetY = db.tooltipBindingY or 0
bindingTooltip:ClearAllPoints()
if anchor == "CURSOR" then
-- Approximate cursor-follow by anchoring to cursor position
local cursorX, cursorY = GetCursorPosition()
local scale = UIParent:GetEffectiveScale()
bindingTooltip:SetOwner(anchorFrame, "ANCHOR_NONE")
bindingTooltip:SetPoint("BOTTOMLEFT", UIParent, "BOTTOMLEFT", cursorX / scale + offsetX, cursorY / scale + offsetY)
elseif anchor == "FRAME" then
bindingTooltip:SetOwner(anchorFrame, "ANCHOR_NONE")
-- Use opposite anchor so tooltip appears on the correct side
local opposites = {
TOPLEFT = "BOTTOMRIGHT", TOP = "BOTTOM", TOPRIGHT = "BOTTOMLEFT",
LEFT = "RIGHT", CENTER = "CENTER", RIGHT = "LEFT",
BOTTOMLEFT = "TOPRIGHT", BOTTOM = "TOP", BOTTOMRIGHT = "TOPLEFT",
}
local tooltipAnchor = opposites[anchorPos] or "BOTTOMLEFT"
bindingTooltip:SetPoint(tooltipAnchor, anchorFrame, anchorPos, offsetX, offsetY)
else
-- DEFAULT — anchor to top-right of frame
bindingTooltip:SetOwner(anchorFrame, "ANCHOR_NONE")
bindingTooltip:SetPoint("TOPLEFT", anchorFrame, "TOPRIGHT", 4, 0)
end
end
function DF:ShowBindingTooltip(anchorFrame)
local CC = DF.ClickCast
if not CC or not CC.db or not CC.db.bindings then return end
-- Read settings from frame db (party/raid independent)
local db = DF.GetFrameDB and DF:GetFrameDB(anchorFrame) or (anchorFrame.isRaidFrame and DF:GetRaidDB() or DF:GetDB())
if not db.tooltipBindingEnabled then return end
local inCombat = InCombatLockdown()
if db.tooltipBindingDisableInCombat and inCombat then
bindingTooltip:Hide()
bindingTooltip.anchorFrame = nil
return
end
local activeMod = getActiveModifier()
bindingTooltip:ClearLines()
positionBindingTooltip(anchorFrame, db)
wipe(lines)
local unit = anchorFrame.unit
local isDead = false
if anchorFrame.dfIsTestFrame then
local testData = DF.GetTestUnitData and DF:GetTestUnitData(anchorFrame.index, anchorFrame.isRaidFrame)
isDead = testData and testData.status == "Dead"
elseif unit and UnitExists(unit) then
isDead = UnitIsDeadOrGhost(unit)
if issecretvalue(isDead) then isDead = false end
end
local smartResMode = CC.db.options and CC.db.options.smartResurrection or "disabled"
local resSpells = smartResMode ~= "disabled" and CC.GetPlayerResurrectionSpells and CC:GetPlayerResurrectionSpells() or nil
for _, binding in ipairs(CC.db.bindings) do
if binding.enabled ~= false and bindingMatchesMod(binding, activeMod) then
local keyName
local sortKey = 99
if binding.bindType == "mouse" then
keyName = BINDING_SHORT_NAMES[binding.button] or (binding.button and binding.button:match("Button(%d+)") and "Mouse " .. binding.button:match("Button(%d+)")) or binding.button
sortKey = BINDING_SORT_ORDER[binding.button] or 99
else
keyName = binding.key or "?"
end
local action = binding.spellName or binding.actionType or "?"
local r, g, b = 1, 1, 1
local suffix = ""
-- Smart Res: override action when target is dead
local smartResApplied = false
if isDead and resSpells and not CC:IsResurrectionSpell(binding.spellName) and binding.targetType ~= "hostile" then
if inCombat and smartResMode == "normal+combat" and resSpells.combat then
action = resSpells.combat
smartResApplied = true
elseif not inCombat then
action = resSpells.mass or resSpells.normal or action
smartResApplied = true
end
end
-- Resolve override spell name (safe in combat)
local spellRef = binding.spellId
if not smartResApplied then
if spellRef and C_Spell.GetOverrideSpell then
spellRef = C_Spell.GetOverrideSpell(spellRef) or spellRef
end
local ref = spellRef or binding.spellName
if ref and C_Spell.GetSpellName then
action = C_Spell.GetSpellName(ref) or action
end
end
if not inCombat and not smartResApplied then
spellRef = spellRef or binding.spellName
if spellRef and C_Spell.IsSpellUsable then
local usable = C_Spell.IsSpellUsable(spellRef)
if issecretvalue(usable) then usable = nil end
local cdLeft = 0
local hasSecretCD = false
if usable and C_Spell.GetSpellCharges then
local charges = C_Spell.GetSpellCharges(spellRef)
if charges then
if issecretvalue(charges.currentCharges) then
hasSecretCD = true
elseif charges.currentCharges == 0 then
usable = false
if not issecretvalue(charges.cooldownStartTime) then
cdLeft = charges.cooldownStartTime + charges.cooldownDuration - GetTime()
end
end
end
end
if usable and C_Spell.GetSpellCooldown then
local cd = C_Spell.GetSpellCooldown(spellRef)
if cd and cd.duration then
if issecretvalue(cd.duration) then
hasSecretCD = true
elseif cd.duration > 1.5 then
usable = false
if not issecretvalue(cd.startTime) then
cdLeft = cd.startTime + cd.duration - GetTime()
end
end
end
end
if usable ~= nil and not hasSecretCD then
r, g, b = usable and 0 or 1, usable and 1 or 0, 0
end
if cdLeft > 0 then
suffix = " (" .. ceil(cdLeft) .. "s)"
end
end
end
-- OOR check (works in and out of combat)
if unit and binding.spellId and C_Spell.IsSpellInRange then
local inRange = C_Spell.IsSpellInRange(binding.spellId, unit)
if not issecretvalue(inRange) and inRange == false then r, g, b = 1, 0, 0; suffix = " (OOR)" end
end
-- Dead check (works in and out of combat, skip if Smart Res overrode)
if isDead and not smartResApplied then r, g, b = 1, 0, 0; suffix = " (DEAD)" end
local hex = format("|cff%02x%02x%02x", r * 255, g * 255, b * 255)
tinsert(lines, {text = keyName .. ": " .. hex .. action .. suffix .. "|r", sort = sortKey, smartRes = smartResApplied})
end
end
tsort(lines, function(a, b) return a.sort < b.sort end)
local smartResShown = false
for _, line in ipairs(lines) do
if line.smartRes and smartResShown then
-- skip duplicate Smart Res lines
else
if line.smartRes then smartResShown = true end
bindingTooltip:AddLine(line.text, 0.7, 0.7, 0.7)
end
end
if #lines > 0 then bindingTooltip:Show() else bindingTooltip:Hide() end
bindingTooltip.anchorFrame = anchorFrame
end
bindingTooltip:RegisterEvent("MODIFIER_STATE_CHANGED")
bindingTooltip:RegisterEvent("SPELL_UPDATE_COOLDOWN")
bindingTooltip:SetScript("OnEvent", function(self)
if self.anchorFrame then DF:ShowBindingTooltip(self.anchorFrame) end
end)
-- Debug flag for duration API troubleshooting
-- Set to true to enable debug output: /run DandersFrames.debugDurationAPI = true
DF.debugDurationAPI = false
-- Debug print helper for duration API
local function DebugDuration(...)
if DF.debugDurationAPI then
print("|cFF00FF00[DF Duration Debug]|r", ...)
end
end
-- Test function to verify debug is working - call with: /run DandersFrames:TestDurationDebug()
function DF:TestDurationDebug()
print("|cFF00FF00[DF Duration Debug]|r === Debug Test ===")
print("|cFF00FF00[DF Duration Debug]|r debugDurationAPI flag:", self.debugDurationAPI and "ENABLED" or "DISABLED")
print("|cFF00FF00[DF Duration Debug]|r")
print("|cFF00FF00[DF Duration Debug]|r === API Availability ===")
print("|cFF00FF00[DF Duration Debug]|r C_UnitAuras exists:", C_UnitAuras ~= nil)
if C_UnitAuras then
print("|cFF00FF00[DF Duration Debug]|r .GetAuraDurationRemainingPercent:", C_UnitAuras.GetAuraDurationRemainingPercent ~= nil)
print("|cFF00FF00[DF Duration Debug]|r .GetAuraDurationRemaining:", C_UnitAuras.GetAuraDurationRemaining ~= nil)
print("|cFF00FF00[DF Duration Debug]|r .GetAuraDataByIndex:", C_UnitAuras.GetAuraDataByIndex ~= nil)
print("|cFF00FF00[DF Duration Debug]|r .DoesAuraHaveExpirationTime:", C_UnitAuras.DoesAuraHaveExpirationTime ~= nil)
end
print("|cFF00FF00[DF Duration Debug]|r C_CurveUtil exists:", C_CurveUtil ~= nil)
if C_CurveUtil then
print("|cFF00FF00[DF Duration Debug]|r .CreateColorCurve:", C_CurveUtil.CreateColorCurve ~= nil)
end
print("|cFF00FF00[DF Duration Debug]|r")
print("|cFF00FF00[DF Duration Debug]|r durationAPIMode:", self.durationAPIMode or "not set yet")
print("|cFF00FF00[DF Duration Debug]|r")
-- Try to get a sample aura to check its structure
print("|cFF00FF00[DF Duration Debug]|r === Sample Aura Check ===")
if C_UnitAuras and C_UnitAuras.GetAuraDataByIndex then
local auraData = C_UnitAuras.GetAuraDataByIndex("player", 1, "HELPFUL")
if auraData then
local auraName = "(protected)"
pcall(function() auraName = auraData.name or "?" end)
print("|cFF00FF00[DF Duration Debug]|r Found buff:", auraName)
print("|cFF00FF00[DF Duration Debug]|r .duration type:", type(auraData.duration))
print("|cFF00FF00[DF Duration Debug]|r .duration value:", tostring(auraData.duration))
print("|cFF00FF00[DF Duration Debug]|r .expirationTime:", auraData.expirationTime)
if type(auraData.duration) == "table" then
print("|cFF00FF00[DF Duration Debug]|r Duration is a TABLE - checking for methods...")
for k, v in pairs(auraData.duration) do
print("|cFF00FF00[DF Duration Debug]|r ." .. k .. " = " .. type(v))
end
elseif type(auraData.duration) == "number" then
print("|cFF00FF00[DF Duration Debug]|r Duration is a NUMBER (old style)")
end
else
print("|cFF00FF00[DF Duration Debug]|r No buffs found on player slot 1")
end
end
print("|cFF00FF00[DF Duration Debug]|r")
print("|cFF00FF00[DF Duration Debug]|r To enable continuous debug: /run DandersFrames.debugDurationAPI = true")
end
-- Track which API we're using (set once on first use)
DF.durationAPIMode = nil -- Will be "old" or "new" once detected
-- Register a simple slash command for debug (in case the main addon slash commands aren't loaded yet)
SLASH_DFDURATIONDEBUG1 = "/dfduration"
SlashCmdList["DFDURATIONDEBUG"] = function(msg)
if msg == "on" then
DF.debugDurationAPI = true
print("|cFF00FF00[DF Duration Debug]|r Debug ENABLED - watch for output when auras update")
elseif msg == "off" then
DF.debugDurationAPI = false
print("|cFF00FF00[DF Duration Debug]|r Debug DISABLED")
else
DF:TestDurationDebug()
end
end
-- Local caching of frequently used globals for performance
local pairs, ipairs, type, wipe = pairs, ipairs, type, wipe
local CreateFrame = CreateFrame
local UnitExists = UnitExists
local InCombatLockdown = InCombatLockdown
local RegisterUnitWatch = RegisterUnitWatch
-- ============================================================
-- SAFE UNIT WATCH REGISTRATION (combat lockdown protection)
-- ============================================================
-- Queue of frames waiting for unit watch registration after combat
DF.pendingUnitWatchFrames = DF.pendingUnitWatchFrames or {}
-- Queue of frames waiting for unit watch UNregistration after combat
DF.pendingUnitUnwatchFrames = DF.pendingUnitUnwatchFrames or {}
-- Manual visibility update for frames pending registration (combat fallback)
local function UpdatePendingFrameVisibility()
for frame in pairs(DF.pendingUnitWatchFrames) do
if frame and frame.unit then
if UnitExists(frame.unit) then
frame:Show()
else
frame:Hide()
end
end
end
end
-- Safe wrapper for RegisterUnitWatch that handles combat lockdown
function DF:SafeRegisterUnitWatch(frame)
if not frame then return end
-- If this frame is pending unregistration, cancel that
DF.pendingUnitUnwatchFrames[frame] = nil
if InCombatLockdown() then
-- Queue for later registration
DF.pendingUnitWatchFrames[frame] = true
-- Manual visibility fallback - show/hide based on UnitExists right now
if frame.unit then
if UnitExists(frame.unit) then
frame:Show()
else
frame:Hide()
end
end
-- Start combat roster watcher if not already running
if not DF.combatRosterWatcher then
DF.combatRosterWatcher = CreateFrame("Frame")
DF.combatRosterWatcher:RegisterEvent("GROUP_ROSTER_UPDATE")
DF.combatRosterWatcher:SetScript("OnEvent", function()
if InCombatLockdown() and next(DF.pendingUnitWatchFrames) then
UpdatePendingFrameVisibility()
end
end)
end
else
RegisterUnitWatch(frame)
end
end
-- Safe wrapper for UnregisterUnitWatch that handles combat lockdown
function DF:SafeUnregisterUnitWatch(frame)
if not frame then return end
-- If this frame is pending registration, cancel that
DF.pendingUnitWatchFrames[frame] = nil
if InCombatLockdown() then
-- Queue for later unregistration
DF.pendingUnitUnwatchFrames[frame] = true
-- Hide the frame immediately (this is safe during combat)
frame:Hide()
else
UnregisterUnitWatch(frame)
frame:Hide()
end
end
-- Process queued unit watch registrations/unregistrations after combat ends
function DF:ProcessPendingUnitWatch()
if InCombatLockdown() then return end
-- Process unregistrations first
for frame in pairs(DF.pendingUnitUnwatchFrames) do
if frame and frame.GetName then
UnregisterUnitWatch(frame)
frame:Hide()
end
end
wipe(DF.pendingUnitUnwatchFrames)
-- Then process registrations
for frame in pairs(DF.pendingUnitWatchFrames) do
if frame and frame.GetName then
RegisterUnitWatch(frame)
end
end
wipe(DF.pendingUnitWatchFrames)
end
-- ============================================================
-- UNIT EVENT REGISTRATION (performance optimization)
-- ============================================================
-- Using RegisterUnitEvent instead of RegisterEvent filters events
-- at the C++ level, preventing Lua from receiving events for units
-- we don't care about. This is critical for performance in cities
-- where many players/NPCs generate UNIT_* events constantly.
--
-- Added: 2025-01-20 for performance optimization
-- List of events that should use RegisterUnitEvent (have unit as first arg)
local UNIT_EVENTS_TO_FILTER = {
"UNIT_HEALTH",
"UNIT_MAXHEALTH",
"UNIT_NAME_UPDATE",
"UNIT_AURA",
"UNIT_ABSORB_AMOUNT_CHANGED",
"UNIT_HEAL_ABSORB_AMOUNT_CHANGED",
"UNIT_HEAL_PREDICTION",
"UNIT_CONNECTION",
"INCOMING_SUMMON_CHANGED",
"INCOMING_RESURRECT_CHANGED",
}
-- Register unit-specific events for a frame
-- This filters events at the C++ level so we only receive events for our unit
function DF:RegisterUnitEventsForFrame(frame, unit)
if not frame or not unit then return end
-- Unregister old unit events if unit changed
if frame.dfRegisteredUnit and frame.dfRegisteredUnit ~= unit then
for _, event in ipairs(UNIT_EVENTS_TO_FILTER) do
frame:UnregisterEvent(event)
end
end
-- Register for new unit using RegisterUnitEvent (C++ level filtering)
for _, event in ipairs(UNIT_EVENTS_TO_FILTER) do
frame:RegisterUnitEvent(event, unit)
end
frame.dfRegisteredUnit = unit
end
-- Unregister all unit events from a frame
function DF:UnregisterUnitEventsForFrame(frame)
if not frame then return end
for _, event in ipairs(UNIT_EVENTS_TO_FILTER) do
frame:UnregisterEvent(event)
end
frame.dfRegisteredUnit = nil
end
-- ============================================================
-- CONDITIONAL POWER EVENT REGISTRATION (performance optimization)
-- ============================================================
-- UNIT_POWER_UPDATE fires very frequently, so we only register
-- these events when the power bar is actually enabled.
function DF:UpdatePowerEventRegistration(frame)
if not frame then return end
local db = DF:GetFrameDB(frame)
local shouldRegister = db and db.resourceBarEnabled
-- Track registration state to avoid redundant calls
if frame.dfPowerEventsRegistered == shouldRegister then return end
if shouldRegister then
-- PERFORMANCE FIX 2025-01-20: Use RegisterUnitEvent for C++ level filtering
-- This prevents receiving power events for all units in the game world
local unit = frame.unit
if unit then
frame:RegisterUnitEvent("UNIT_POWER_UPDATE", unit)
frame:RegisterUnitEvent("UNIT_MAXPOWER", unit)
frame:RegisterUnitEvent("UNIT_DISPLAYPOWER", unit)
else
-- Fallback to global registration if unit not set yet
frame:RegisterEvent("UNIT_POWER_UPDATE")
frame:RegisterEvent("UNIT_MAXPOWER")
frame:RegisterEvent("UNIT_DISPLAYPOWER")
end
--[[ OLD CODE - Remove after testing
frame:RegisterEvent("UNIT_POWER_UPDATE")
frame:RegisterEvent("UNIT_MAXPOWER")
frame:RegisterEvent("UNIT_DISPLAYPOWER")
--]]
frame.dfPowerEventsRegistered = true
else
frame:UnregisterEvent("UNIT_POWER_UPDATE")
frame:UnregisterEvent("UNIT_MAXPOWER")
frame:UnregisterEvent("UNIT_DISPLAYPOWER")
frame.dfPowerEventsRegistered = false
end
end
-- Update power event registration for all frames (call when setting changes)
-- NOTE: Header children don't have individual event handlers so we skip them
function DF:UpdateAllPowerEventRegistration()
-- Party frames - use iterators if available (handles both legacy and header modes)
if DF.IteratePartyFrames then
DF:IteratePartyFrames(function(frame)
-- Only update legacy frames (header children don't use per-frame events)
if frame and not frame.dfIsHeaderChild and frame.RegisterEvent then
DF:UpdatePowerEventRegistration(frame)
end
end)
end
-- Raid frames - use iterators if available
if DF.IterateRaidFrames then
DF:IterateRaidFrames(function(frame)
if frame and not frame.dfIsHeaderChild and frame.RegisterEvent then
DF:UpdatePowerEventRegistration(frame)
end
end)
end
end
-- ============================================================
-- UNIFIED FRAME CREATION AND UPDATE SYSTEM
-- ============================================================
-- Unified frame creation for both party and raid frames
-- ============================================================
-- CREATE FRAME ELEMENTS
-- Creates all visual elements on a frame (health bar, text, etc.)
-- Used by both legacy CreateUnitFrame and new header system
-- ============================================================
function DF:CreateFrameElements(frame, isRaid)
if not frame then return end
if frame.dfElementsCreated then return end -- Don't create twice
-- Determine if raid based on frame property or parameter
if isRaid == nil then
isRaid = frame.isRaidFrame
end
local db = isRaid and DF:GetRaidDB() or DF:GetDB()
-- Store reference for DB lookups
frame.isRaidFrame = isRaid
-- ========================================
-- BACKGROUND
-- ========================================
frame.background = frame:CreateTexture(nil, "BACKGROUND")
frame.background:SetAllPoints()
frame.background:SetColorTexture(0, 0, 0, 0.8)
-- ========================================
-- MISSING HEALTH BAR (shows where health is missing)
-- ========================================
frame.missingHealthBar = CreateFrame("StatusBar", nil, frame)
local padding = db.framePadding or 0
frame.missingHealthBar:SetPoint("TOPLEFT", padding, -padding)
frame.missingHealthBar:SetPoint("BOTTOMRIGHT", -padding, padding)
frame.missingHealthBar:SetStatusBarTexture(db.healthTexture or "Interface\\TargetingFrame\\UI-StatusBar")
frame.missingHealthBar:SetMinMaxValues(0, 1)
frame.missingHealthBar:SetValue(0)
frame.missingHealthBar:SetReverseFill(true)
frame.missingHealthBar:SetFrameLevel(frame:GetFrameLevel() + 1)
local missingColor = db.missingHealthColor or {r = 0.5, g = 0, b = 0, a = 0.8}
frame.missingHealthBar:SetStatusBarColor(missingColor.r, missingColor.g, missingColor.b, missingColor.a or 0.8)
frame.missingHealthBar:Hide()
-- ========================================
-- HEALTH BAR
-- ========================================
frame.healthBar = CreateFrame("StatusBar", nil, frame)
frame.healthBar:SetPoint("TOPLEFT", padding, -padding)
frame.healthBar:SetPoint("BOTTOMRIGHT", -padding, padding)
frame.healthBar:SetStatusBarTexture(db.healthTexture or "Interface\\TargetingFrame\\UI-StatusBar")
frame.healthBar:SetMinMaxValues(0, 1)
frame.healthBar:SetValue(1)
-- ========================================
-- CONTENT OVERLAY (for text and icons above bars)
-- ========================================
frame.contentOverlay = CreateFrame("Frame", nil, frame)
frame.contentOverlay:SetAllPoints()
frame.contentOverlay:SetFrameLevel(frame:GetFrameLevel() + 25)
frame.contentOverlay:EnableMouse(false)
-- ========================================
-- NAME TEXT
-- ========================================
frame.nameText = frame.contentOverlay:CreateFontString(nil, "OVERLAY")
local nameOutline = db.nameTextOutline or "OUTLINE"
if nameOutline == "NONE" then nameOutline = "" end
DF:SafeSetFont(frame.nameText, db.nameFont or "Fonts\\FRIZQT__.TTF", db.nameFontSize or 11, nameOutline)
local nameAnchor = db.nameTextAnchor or "TOP"
frame.nameText:SetPoint(nameAnchor, frame, nameAnchor, db.nameTextX or 0, db.nameTextY or -2)
frame.nameText:SetTextColor(1, 1, 1, 1)
frame.nameText:SetDrawLayer("OVERLAY", 7)
-- ========================================
-- HEALTH TEXT
-- ========================================
frame.healthText = frame.contentOverlay:CreateFontString(nil, "OVERLAY")
local healthOutline = db.healthTextOutline or "OUTLINE"
if healthOutline == "NONE" then healthOutline = "" end
DF:SafeSetFont(frame.healthText, db.healthFont or "Fonts\\FRIZQT__.TTF", db.healthFontSize or 10, healthOutline)
local healthAnchor = db.healthTextAnchor or "CENTER"
frame.healthText:SetPoint(healthAnchor, frame, healthAnchor, db.healthTextX or 0, db.healthTextY or 0)
frame.healthText:SetTextColor(1, 1, 1, 1)
frame.healthText:SetDrawLayer("OVERLAY", 7)
-- ========================================
-- STATUS TEXT (Dead, Offline, AFK)
-- ========================================
frame.statusText = frame.contentOverlay:CreateFontString(nil, "OVERLAY")
local statusOutline = db.statusTextOutline or "OUTLINE"
if statusOutline == "NONE" then statusOutline = "" end
DF:SafeSetFont(frame.statusText, db.statusTextFont or "Fonts\\FRIZQT__.TTF", db.statusTextFontSize or 10, statusOutline)
local statusAnchor = db.statusTextAnchor or "CENTER"
frame.statusText:SetPoint(statusAnchor, frame, statusAnchor, db.statusTextX or 0, db.statusTextY or 0)
local statusColor = db.statusTextColor or {r = 1, g = 1, b = 1}
frame.statusText:SetTextColor(statusColor.r, statusColor.g, statusColor.b, 1)
frame.statusText:SetDrawLayer("OVERLAY", 7)
frame.statusText:Hide()
-- ========================================
-- PARTY INDEX TEXT
-- ========================================
frame.partyIndexText = frame.contentOverlay:CreateFontString(nil, "OVERLAY")
local partyIndexOutline = db.partyIndexTextOutline or "OUTLINE"
if partyIndexOutline == "NONE" then partyIndexOutline = "" end
DF:SafeSetFont(frame.partyIndexText, db.partyIndexTextFont or "Fonts\\FRIZQT__.TTF", db.partyIndexTextFontSize or 10, partyIndexOutline)
local partyIndexAnchor = db.partyIndexTextAnchor or "TOPLEFT"
frame.partyIndexText:SetPoint(partyIndexAnchor, frame, partyIndexAnchor, db.partyIndexTextX or 2, db.partyIndexTextY or -2)
local partyIndexColor = db.partyIndexTextColor or {r = 1, g = 1, b = 1}
frame.partyIndexText:SetTextColor(partyIndexColor.r, partyIndexColor.g, partyIndexColor.b, partyIndexColor.a or 1)
frame.partyIndexText:SetDrawLayer("OVERLAY", 7)
frame.partyIndexText:Hide()
-- Continue with the rest of the elements...
-- (Border, icons, power bar, auras, absorbs, etc.)
-- These are created by calling the internal element creation
DF:CreateFrameElementsExtended(frame, db)
-- Mark as created
frame.dfElementsCreated = true
end
-- Extended element creation (called from CreateFrameElements)
-- Creates all visual elements needed for a full unit frame
function DF:CreateFrameElementsExtended(frame, db)
if not frame or not db then return end
-- ========================================
-- BORDER
-- ========================================
frame.border = CreateFrame("Frame", nil, frame)
frame.border:SetAllPoints()
frame.border:SetFrameLevel(frame:GetFrameLevel() + 10)
local borderSize = db.borderSize or 1
local borderColor = db.borderColor or {r = 0, g = 0, b = 0, a = 1}
frame.border.top = frame.border:CreateTexture(nil, "BORDER")
frame.border.top:SetHeight(borderSize)
frame.border.top:SetPoint("TOPLEFT", 0, 0)
frame.border.top:SetPoint("TOPRIGHT", 0, 0)
frame.border.top:SetColorTexture(borderColor.r, borderColor.g, borderColor.b, borderColor.a)
frame.border.bottom = frame.border:CreateTexture(nil, "BORDER")
frame.border.bottom:SetHeight(borderSize)
frame.border.bottom:SetPoint("BOTTOMLEFT", 0, 0)
frame.border.bottom:SetPoint("BOTTOMRIGHT", 0, 0)
frame.border.bottom:SetColorTexture(borderColor.r, borderColor.g, borderColor.b, borderColor.a)
frame.border.left = frame.border:CreateTexture(nil, "BORDER")
frame.border.left:SetWidth(borderSize)
frame.border.left:SetPoint("TOPLEFT", 0, 0)
frame.border.left:SetPoint("BOTTOMLEFT", 0, 0)
frame.border.left:SetColorTexture(borderColor.r, borderColor.g, borderColor.b, borderColor.a)
frame.border.right = frame.border:CreateTexture(nil, "BORDER")
frame.border.right:SetWidth(borderSize)
frame.border.right:SetPoint("TOPRIGHT", 0, 0)
frame.border.right:SetPoint("BOTTOMRIGHT", 0, 0)
frame.border.right:SetColorTexture(borderColor.r, borderColor.g, borderColor.b, borderColor.a)
-- Helper function to set border color
frame.border.SetBorderColor = function(self, r, g, b, a)
self.top:SetColorTexture(r, g, b, a)
self.bottom:SetColorTexture(r, g, b, a)
self.left:SetColorTexture(r, g, b, a)
self.right:SetColorTexture(r, g, b, a)
end
-- ========================================
-- ROLE ICON
-- ========================================
frame.roleIcon = CreateFrame("Frame", nil, frame.contentOverlay)
frame.roleIcon:SetSize(18, 18)
frame.roleIcon:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -2)
frame.roleIcon:SetFrameLevel(frame.contentOverlay:GetFrameLevel() + 5)
frame.roleIcon:Hide()
frame.roleIcon.texture = frame.roleIcon:CreateTexture(nil, "OVERLAY")
frame.roleIcon.texture:SetAllPoints()
frame.roleIcon.texture:SetDrawLayer("OVERLAY", 7)
-- ========================================
-- LEADER ICON
-- ========================================
frame.leaderIcon = CreateFrame("Frame", nil, frame.contentOverlay)
frame.leaderIcon:SetSize(12, 12)
frame.leaderIcon:SetPoint("TOPLEFT", frame, "TOPLEFT", -2, 2)
frame.leaderIcon:SetFrameLevel(frame.contentOverlay:GetFrameLevel() + 5)
frame.leaderIcon:Hide()
frame.leaderIcon.texture = frame.leaderIcon:CreateTexture(nil, "OVERLAY")
frame.leaderIcon.texture:SetAllPoints()
frame.leaderIcon.texture:SetTexture("Interface\\GroupFrame\\UI-Group-LeaderIcon")
frame.leaderIcon.texture:SetDrawLayer("OVERLAY", 7)
-- ========================================
-- RAID TARGET ICON
-- ========================================
frame.raidTargetIcon = CreateFrame("Frame", nil, frame.contentOverlay)
frame.raidTargetIcon:SetSize(16, 16)
frame.raidTargetIcon:SetPoint("TOP", frame, "TOP", 0, 2)
frame.raidTargetIcon:SetFrameLevel(frame.contentOverlay:GetFrameLevel() + 5)
frame.raidTargetIcon:Hide()
frame.raidTargetIcon.texture = frame.raidTargetIcon:CreateTexture(nil, "OVERLAY")
frame.raidTargetIcon.texture:SetAllPoints()
frame.raidTargetIcon.texture:SetTexture("Interface\\TargetingFrame\\UI-RaidTargetingIcons")
frame.raidTargetIcon.texture:SetDrawLayer("OVERLAY", 6)
-- ========================================
-- READY CHECK ICON
-- ========================================
frame.readyCheckIcon = CreateFrame("Frame", nil, frame.contentOverlay)
frame.readyCheckIcon:SetSize(16, 16)
frame.readyCheckIcon:SetPoint("CENTER", frame, "CENTER", 0, 0)
frame.readyCheckIcon:SetFrameLevel(frame.contentOverlay:GetFrameLevel() + 5)
frame.readyCheckIcon:Hide()
frame.readyCheckIcon.texture = frame.readyCheckIcon:CreateTexture(nil, "OVERLAY")
frame.readyCheckIcon.texture:SetAllPoints()
frame.readyCheckIcon.texture:SetDrawLayer("OVERLAY", 7)
-- ========================================
-- CENTER STATUS ICON (DEPRECATED - kept for backward compatibility)
-- New individual icons created via CreateStatusIcons
-- ========================================
frame.centerStatusIcon = CreateFrame("Frame", nil, frame.contentOverlay)
frame.centerStatusIcon:SetSize(16, 16)
frame.centerStatusIcon:SetPoint("CENTER", frame, "CENTER", 0, 0)
frame.centerStatusIcon:SetFrameLevel(frame.contentOverlay:GetFrameLevel() + 5)
frame.centerStatusIcon:Hide()
frame.centerStatusIcon.texture = frame.centerStatusIcon:CreateTexture(nil, "OVERLAY")
frame.centerStatusIcon.texture:SetAllPoints()
frame.centerStatusIcon.texture:SetDrawLayer("OVERLAY", 6)
-- ========================================
-- NEW STATUS ICONS (Summon, Res, Phased, AFK, Vehicle, RaidRole)
-- ========================================
DF:CreateStatusIcons(frame)
-- ========================================
-- RESTED INDICATOR (solo mode) - Custom animated ZZZ with glow
-- ========================================
frame.restedIndicator = CreateFrame("Frame", nil, frame.contentOverlay)
frame.restedIndicator:SetSize(24, 18)
frame.restedIndicator:SetPoint("BOTTOMLEFT", frame, "TOPRIGHT", -18, -14)
frame.restedIndicator:SetFrameLevel(frame.contentOverlay:GetFrameLevel() + 5)
frame.restedIndicator:Hide()
-- Create 3 Z FontStrings with increasing sizes
local zSizes = {8, 11, 14}
local zOffsets = {0, 5, 12}
local zYOffsets = {0, 3, 7}
frame.restedIndicator.zTexts = {}
for i = 1, 3 do
local z = frame.restedIndicator:CreateFontString(nil, "OVERLAY")
z:SetFont("Fonts\\FRIZQT__.TTF", zSizes[i], "OUTLINE")
z:SetText("Z")
z:SetTextColor(1, 0.82, 0, 1)
z:SetPoint("BOTTOMLEFT", frame.restedIndicator, "BOTTOMLEFT", zOffsets[i], zYOffsets[i])
z:SetAlpha(0)
z.baseSize = zSizes[i]
frame.restedIndicator.zTexts[i] = z
end
-- Create glow texture
frame.restedGlow = frame:CreateTexture(nil, "BACKGROUND", nil, -8)
frame.restedGlow:SetPoint("TOPLEFT", frame, "TOPLEFT", -4, 4)
frame.restedGlow:SetPoint("BOTTOMRIGHT", frame, "BOTTOMRIGHT", 4, -4)
frame.restedGlow:SetTexture("Interface\\Buttons\\WHITE8x8")
frame.restedGlow:SetVertexColor(1, 0.82, 0, 0.3)
frame.restedGlow:SetBlendMode("ADD")
frame.restedGlow:Hide()
-- Animation state
frame.restedIndicator.animTime = 0
frame.restedIndicator.cycleDuration = 2.0
-- OnUpdate script for custom animation
frame.restedIndicator:SetScript("OnUpdate", function(self, elapsed)
self.animTime = self.animTime + elapsed
local cycle = self.animTime % self.cycleDuration
local progress = cycle / self.cycleDuration
for i, z in ipairs(self.zTexts) do
local zDelay = (i - 1) * 0.15
local zProgress = (progress - zDelay) % 1
local alpha, scale
if zProgress < 0.4 then
local t = zProgress / 0.4
alpha = t
scale = 0.5 + (t * 0.5)
elseif zProgress < 0.7 then
alpha = 1
scale = 1
else
local t = (zProgress - 0.7) / 0.3
alpha = 1 - t
scale = 1
end
z:SetAlpha(alpha)
local baseSize = z.baseSize
z:SetFont("Fonts\\FRIZQT__.TTF", baseSize * scale, "OUTLINE")
end
local glowAlpha = 0.2 + (math.sin(self.animTime * 3) * 0.15 + 0.1)
if frame.restedGlow and frame.restedGlow:IsShown() then
frame.restedGlow:SetAlpha(glowAlpha)
end
end)
frame.restedIndicator:SetScript("OnShow", function(self)
self.animTime = 0
for _, z in ipairs(self.zTexts) do
z:Show()
end
end)
frame.restedIndicator:SetScript("OnHide", function(self)
for _, z in ipairs(self.zTexts) do
z:Hide()
end
end)
-- ========================================
-- MISSING BUFF ICON
-- ========================================
frame.missingBuffFrame = CreateFrame("Frame", nil, frame.contentOverlay)
frame.missingBuffFrame:SetSize(24, 24)
frame.missingBuffFrame:SetPoint("CENTER", frame, "CENTER", 0, 0)
frame.missingBuffFrame:SetFrameLevel(frame.contentOverlay:GetFrameLevel() + 10)
local mbBorderSize = 2
frame.missingBuffBorderLeft = frame.missingBuffFrame:CreateTexture(nil, "BACKGROUND")
frame.missingBuffBorderLeft:SetPoint("TOPLEFT", 0, 0)
frame.missingBuffBorderLeft:SetPoint("BOTTOMLEFT", 0, 0)
frame.missingBuffBorderLeft:SetWidth(mbBorderSize)
frame.missingBuffBorderLeft:SetColorTexture(1, 0, 0, 1)
frame.missingBuffBorderRight = frame.missingBuffFrame:CreateTexture(nil, "BACKGROUND")
frame.missingBuffBorderRight:SetPoint("TOPRIGHT", 0, 0)
frame.missingBuffBorderRight:SetPoint("BOTTOMRIGHT", 0, 0)
frame.missingBuffBorderRight:SetWidth(mbBorderSize)
frame.missingBuffBorderRight:SetColorTexture(1, 0, 0, 1)
frame.missingBuffBorderTop = frame.missingBuffFrame:CreateTexture(nil, "BACKGROUND")
frame.missingBuffBorderTop:SetPoint("TOPLEFT", mbBorderSize, 0)
frame.missingBuffBorderTop:SetPoint("TOPRIGHT", -mbBorderSize, 0)
frame.missingBuffBorderTop:SetHeight(mbBorderSize)
frame.missingBuffBorderTop:SetColorTexture(1, 0, 0, 1)
frame.missingBuffBorderBottom = frame.missingBuffFrame:CreateTexture(nil, "BACKGROUND")
frame.missingBuffBorderBottom:SetPoint("BOTTOMLEFT", mbBorderSize, 0)
frame.missingBuffBorderBottom:SetPoint("BOTTOMRIGHT", -mbBorderSize, 0)
frame.missingBuffBorderBottom:SetHeight(mbBorderSize)
frame.missingBuffBorderBottom:SetColorTexture(1, 0, 0, 1)
frame.missingBuffIcon = frame.missingBuffFrame:CreateTexture(nil, "ARTWORK")
frame.missingBuffIcon:SetPoint("TOPLEFT", mbBorderSize, -mbBorderSize)
frame.missingBuffIcon:SetPoint("BOTTOMRIGHT", -mbBorderSize, mbBorderSize)
frame.missingBuffIcon:SetTexCoord(0.08, 0.92, 0.08, 0.92)
frame.missingBuffFrame:Hide()
-- ========================================
-- DEFENSIVE ICON
-- ========================================
frame.defensiveIcon = CreateFrame("Frame", nil, frame.contentOverlay)
frame.defensiveIcon:SetSize(24, 24)
frame.defensiveIcon:SetPoint("CENTER", frame, "CENTER", 0, 0)
frame.defensiveIcon:SetFrameLevel(frame.contentOverlay:GetFrameLevel() + 15)
frame.defensiveIcon:Hide()
local defBorderSize = 2
frame.defensiveIcon.borderLeft = frame.defensiveIcon:CreateTexture(nil, "BACKGROUND")
frame.defensiveIcon.borderLeft:SetPoint("TOPLEFT", 0, 0)
frame.defensiveIcon.borderLeft:SetPoint("BOTTOMLEFT", 0, 0)
frame.defensiveIcon.borderLeft:SetWidth(defBorderSize)
frame.defensiveIcon.borderLeft:SetColorTexture(0, 0.8, 0, 1)
frame.defensiveIcon.borderRight = frame.defensiveIcon:CreateTexture(nil, "BACKGROUND")
frame.defensiveIcon.borderRight:SetPoint("TOPRIGHT", 0, 0)
frame.defensiveIcon.borderRight:SetPoint("BOTTOMRIGHT", 0, 0)
frame.defensiveIcon.borderRight:SetWidth(defBorderSize)
frame.defensiveIcon.borderRight:SetColorTexture(0, 0.8, 0, 1)
frame.defensiveIcon.borderTop = frame.defensiveIcon:CreateTexture(nil, "BACKGROUND")
frame.defensiveIcon.borderTop:SetPoint("TOPLEFT", defBorderSize, 0)
frame.defensiveIcon.borderTop:SetPoint("TOPRIGHT", -defBorderSize, 0)
frame.defensiveIcon.borderTop:SetHeight(defBorderSize)
frame.defensiveIcon.borderTop:SetColorTexture(0, 0.8, 0, 1)
frame.defensiveIcon.borderBottom = frame.defensiveIcon:CreateTexture(nil, "BACKGROUND")
frame.defensiveIcon.borderBottom:SetPoint("BOTTOMLEFT", defBorderSize, 0)
frame.defensiveIcon.borderBottom:SetPoint("BOTTOMRIGHT", -defBorderSize, 0)
frame.defensiveIcon.borderBottom:SetHeight(defBorderSize)
frame.defensiveIcon.borderBottom:SetColorTexture(0, 0.8, 0, 1)
frame.defensiveIcon.texture = frame.defensiveIcon:CreateTexture(nil, "ARTWORK")
frame.defensiveIcon.texture:SetPoint("TOPLEFT", defBorderSize, -defBorderSize)
frame.defensiveIcon.texture:SetPoint("BOTTOMRIGHT", -defBorderSize, defBorderSize)
frame.defensiveIcon.texture:SetTexCoord(0.08, 0.92, 0.08, 0.92)
frame.defensiveIcon.cooldown = CreateFrame("Cooldown", nil, frame.defensiveIcon, "CooldownFrameTemplate")
frame.defensiveIcon.cooldown:SetAllPoints(frame.defensiveIcon.texture)
frame.defensiveIcon.cooldown:SetDrawEdge(false)
frame.defensiveIcon.cooldown:SetDrawSwipe(true)
frame.defensiveIcon.cooldown:SetReverse(true)
frame.defensiveIcon.cooldown:SetHideCountdownNumbers(false)
frame.defensiveIcon.count = frame.defensiveIcon:CreateFontString(nil, "OVERLAY")
DF:SafeSetFont(frame.defensiveIcon.count, "Fonts\\FRIZQT__.TTF", 10, "OUTLINE")
frame.defensiveIcon.count:SetPoint("BOTTOMRIGHT", -1, 1)
frame.defensiveIcon.count:SetTextColor(1, 1, 1, 1)
frame.defensiveIcon.unitFrame = frame
frame.defensiveIcon.auraType = "DEFENSIVE"
-- Tooltip handling for defensive icon
frame.defensiveIcon:SetScript("OnEnter", function(self)
if not self:IsShown() then return end
local anchorFrame = self.unitFrame
if not anchorFrame then return end
local iconDb = anchorFrame.isRaidFrame and DF:GetRaidDB() or DF:GetDB()
if not iconDb.tooltipDefensiveEnabled then return end
if iconDb.tooltipDefensiveDisableInCombat and InCombatLockdown() then return end
local anchorType = iconDb.tooltipDefensiveAnchor or "CURSOR"
if anchorType == "CURSOR" then
GameTooltip:SetOwner(self, "ANCHOR_CURSOR")
elseif anchorType == "FRAME" then
local anchorPos = iconDb.tooltipDefensiveAnchorPos or "BOTTOMRIGHT"
local offsetX = iconDb.tooltipDefensiveX or 0
local offsetY = iconDb.tooltipDefensiveY or 0
GameTooltip:SetOwner(self, "ANCHOR_NONE")
GameTooltip:ClearAllPoints()
GameTooltip:SetPoint(anchorPos, self, anchorPos, offsetX, offsetY)
else
GameTooltip_SetDefaultAnchor(GameTooltip, self)
end
if DF.testMode or DF.raidTestMode then
GameTooltip:AddLine("Pain Suppression", 1, 1, 1)
GameTooltip:AddLine("Defensive Cooldown (Test)", 0.8, 0.8, 0.8)
GameTooltip:Show()
elseif self.auraData and self.unitFrame then
local unit = self.unitFrame.unit
if unit and self.auraData.auraInstanceID and GameTooltip.SetUnitAuraByAuraInstanceID then
GameTooltip:SetUnitAuraByAuraInstanceID(unit, self.auraData.auraInstanceID)
GameTooltip:Show()
end
end
end)