-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcode.lua
More file actions
787 lines (668 loc) · 27.6 KB
/
code.lua
File metadata and controls
787 lines (668 loc) · 27.6 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
local addonName, addon = ...
local LibClassicDurations
local LibAuraTypes
local LibSpellLocks
local db
local UnitAuraUniversal = UnitAura
local f = CreateFrame("Frame")
f:SetScript("OnEvent", function(self, event, ...)
return self[event](self, event, ...)
end)
local APILevel = math.floor(select(4,GetBuildInfo())/10000)
local function SetupDefaults(t, defaults)
for k,v in pairs(defaults) do
if type(v) == "table" then
if t[k] == nil then
t[k] = CopyTable(v)
else
SetupDefaults(t[k], v)
end
else
if t[k] == nil then t[k] = v end
end
end
end
local function RemoveDefaults(t, defaults)
for k, v in pairs(defaults) do
if type(t[k]) == 'table' and type(v) == 'table' then
RemoveDefaults(t[k], v)
if next(t[k]) == nil then
t[k] = nil
end
elseif t[k] == v then
t[k] = nil
end
end
return t
end
local defaults = {
portraitIcon = true,
playerPortraitIcon = true,
enemyBuffs = false,
hookTargetFrame = true,
verbosePortraitIcon = false,
largePersonalDebuffs = false,
}
-- Redefining blizzard consts
local AURA_START_X = 5;
local AURA_START_Y = 32;
local AURA_OFFSET_Y = 1;
local LARGE_AURA_SIZE = 21;
local SMALL_AURA_SIZE = 17;
local AURA_ROW_WIDTH = 122;
local TOT_AURA_ROW_WIDTH = 101;
local NUM_TOT_AURA_ROWS = 2;
local largeBuffList = {};
local largeDebuffList = {};
local PLAYER_UNITS = {
player = true,
pet = true,
};
local function ShouldAuraBeLargePersonalDebuffs(caster)
if not caster then
return false;
end
for token, value in pairs(PLAYER_UNITS) do
if UnitIsUnit(caster, token) then
return value;
end
end
end
local function ShouldAuraBeLargeAlways(caster)
return true
end
local ShouldAuraBeLarge = ShouldAuraBeLargeAlways
local UpdatePortraitIcon = function(frame, unit, maxPrio, maxPrioIndex, maxPrioFilter, targetType)
local auraCD = frame.CADPortraitFrame
local originalPortrait = auraCD.originalPortrait
local isLocked = LibSpellLocks:GetSpellLockInfo(unit)
local CUTOFF_AURA_TYPE = db.verbosePortraitIcon and "SPEED_BOOST" or "SILENCE"
local PRIO_SILENCE = LibAuraTypes.GetAuraTypePriority(CUTOFF_AURA_TYPE, targetType)
if isLocked and PRIO_SILENCE > maxPrio then
maxPrio = PRIO_SILENCE
maxPrioIndex = -1
end
if maxPrio >= PRIO_SILENCE then
local name, icon, _, _, duration, expirationTime, caster, _,_, spellId
if maxPrioIndex == -1 then
spellId, name, icon, duration, expirationTime = LibSpellLocks:GetSpellLockInfo(unit)
else
name, icon, _, _, duration, expirationTime, caster, _,_, spellId = UnitAuraUniversal(unit, maxPrioIndex, maxPrioFilter)
end
SetPortraitToTexture(auraCD.texture, icon)
auraCD:SetCooldown(expirationTime-duration, duration)
auraCD:Show()
else
auraCD:Hide()
end
end
f.SimpleTargetFrameHook = function(self)
local frame, frameName;
local frameIcon, frameCount, frameCooldown;
local numBuffs = 0;
-- local playerIsTarget = UnitIsUnit(PlayerFrame.unit, self.unit);
local selfName = self:GetName();
local unit = self.unit
local targetType = UnitIsFriend(unit, "player") and "ALLY" or "ENEMY"
--[[ PORTRAIT AURA ]]
local maxPrio = 0
local maxPrioFilter
local maxPrioIndex = 1
for i = 1, MAX_TARGET_BUFFS do
local buffName, icon, count, debuffType, duration, expirationTime, caster, canStealOrPurge, _ , spellId, _, _, casterIsPlayer, nameplateShowAll = UnitBuff(unit, i, nil);
if (buffName) then
frameName = selfName.."Buff"..(i);
frame = _G[frameName];
-- Handle cooldowns
frameCooldown = _G[frameName.."Cooldown"];
local durationNew, expirationTimeNew = LibClassicDurations:GetAuraDurationByUnit(unit, spellId, caster)
if duration == 0 and durationNew then
duration = durationNew
expirationTime = expirationTimeNew
end
CooldownFrame_Set(frameCooldown, expirationTime - duration, duration, duration > 0, true);
else
break;
end
end
local numDebuffs = 0;
local frameNum = 1;
local index = 1;
local maxDebuffs = self.maxDebuffs or MAX_TARGET_DEBUFFS;
while ( frameNum <= maxDebuffs and index <= maxDebuffs ) do
local debuffName, icon, count, debuffType, duration, expirationTime, caster, _, _, spellId, _, _, casterIsPlayer, nameplateShowAll = UnitDebuff(unit, index, "INCLUDE_NAME_PLATE_ONLY");
if ( debuffName ) then
if ( TargetFrame_ShouldShowDebuffs(self.unit, caster, nameplateShowAll, casterIsPlayer) ) then
frameName = selfName.."Debuff"..frameNum;
frame = _G[frameName];
-- Handle cooldowns
frameCooldown = _G[frameName.."Cooldown"];
local durationNew, expirationTimeNew = LibClassicDurations:GetAuraDurationByUnit(self.unit, spellId, caster)
if duration == 0 and durationNew then
duration = durationNew
expirationTime = expirationTimeNew
end
CooldownFrame_Set(frameCooldown, expirationTime - duration, duration, duration > 0, true);
frameNum = frameNum + 1;
end
else
break;
end
index = index + 1;
end
end
f:RegisterEvent("PLAYER_LOGOUT")
function f.PLAYER_LOGOUT(self, event)
RemoveDefaults(ClassicAuraDurationsDB, defaults)
end
f:RegisterEvent("PLAYER_LOGIN")
function f.PLAYER_LOGIN(self, event)
ClassicAuraDurationsDB = ClassicAuraDurationsDB or {}
SetupDefaults(ClassicAuraDurationsDB, defaults)
db = ClassicAuraDurationsDB
SLASH_CLASSICAURADURATIONS1= "/cad"
SLASH_CLASSICAURADURATIONS2= "/classicauraduration"
SlashCmdList["CLASSICAURADURATIONS"] = self.SlashCmd
LibClassicDurations = LibStub("LibClassicDurations", true)
if LibClassicDurations then
LibClassicDurations:RegisterFrame(addon)
UnitAuraUniversal = LibClassicDurations.UnitAuraWithBuffs
end
LibAuraTypes = LibStub("LibAuraTypes")
LibSpellLocks = LibStub("LibSpellLocks")
LibSpellLocks.RegisterCallback(addon, "UPDATE_INTERRUPT", function(event, guid)
if UnitGUID("target") == guid then
TargetFrame_UpdateAuras(TargetFrame)
end
end)
ShouldAuraBeLarge = db.largePersonalDebuffs and ShouldAuraBeLargePersonalDebuffs or ShouldAuraBeLargeAlways
local makePortraitOverlay = function(frame, portraitGlobalName)
local originalPortrait = _G[portraitGlobalName];
local auraCD = CreateFrame("Cooldown", "CAD"..portraitGlobalName, frame, "CooldownFrameTemplate")
auraCD:SetParent(frame)
auraCD:SetFrameStrata("LOW")
if frame == PlayerFrame then
auraCD:SetFrameLevel(2)
else
auraCD:SetFrameLevel(1)
end
auraCD:SetDrawEdge(false);
-- auraCD:SetHideCountdownNumbers(true);
auraCD:SetReverse(true)
auraCD:SetSwipeTexture("Interface\\CHARACTERFRAME\\TempPortraitAlphaMaskSmall")
auraCD:SetAllPoints(originalPortrait)
frame.CADPortraitFrame = auraCD
auraCD.originalPortrait = originalPortrait
local auraIconTexture = auraCD:CreateTexture(nil, "BORDER", nil, 2)
auraIconTexture:SetAllPoints(originalPortrait)
-- auraIconTexture:Hide()
-- SetPortraitToTexture(auraIconTexture, 136039)
auraCD.texture = auraIconTexture
auraCD:Hide()
end
makePortraitOverlay(TargetFrame, "TargetFramePortrait")
makePortraitOverlay(PlayerFrame, "PlayerPortrait")
if LibClassicDurations then
if db.hookTargetFrame then
if db.enemyBuffs then
hooksecurefunc("TargetFrame_UpdateAuras", f.EnemyBuffsTargetFrameHook)
LibClassicDurations.RegisterCallback(addon, "UNIT_BUFF", function(event, unit)
TargetFrame_UpdateAuras(TargetFrame)
end)
else
hooksecurefunc("TargetFrame_UpdateAuras", f.SimpleTargetFrameHook)
end
end
hooksecurefunc("CompactUnitFrame_UtilSetBuff", function(buffFrame, unit, index, filter)
local name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, _, spellId, canApplyAura = UnitBuff(unit, index, filter);
local durationNew, expirationTimeNew = LibClassicDurations:GetAuraDurationByUnit(unit, spellId, unitCaster)
if duration == 0 and durationNew then
duration = durationNew
expirationTime = expirationTimeNew
end
local enabled = expirationTime and expirationTime ~= 0;
if enabled then
local startTime = expirationTime - duration;
CooldownFrame_Set(buffFrame.cooldown, startTime, duration, true);
else
CooldownFrame_Clear(buffFrame.cooldown);
end
end)
hooksecurefunc("CompactUnitFrame_UtilSetDebuff", function(debuffFrame, unit, index, filter, isBossAura, isBossBuff)
local name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, _, spellId;
if (isBossBuff) then
name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, _, spellId = UnitBuff(unit, index, filter);
else
name, icon, count, debuffType, duration, expirationTime, unitCaster, canStealOrPurge, _, spellId = UnitDebuff(unit, index, filter);
end
local durationNew, expirationTimeNew = LibClassicDurations:GetAuraDurationByUnit(unit, spellId, unitCaster)
if duration == 0 and durationNew then
duration = durationNew
expirationTime = expirationTimeNew
end
local enabled = expirationTime and expirationTime ~= 0;
if enabled then
local startTime = expirationTime - duration;
CooldownFrame_Set(debuffFrame.cooldown, startTime, duration, true);
else
CooldownFrame_Clear(debuffFrame.cooldown);
end
end)
end
-- local portraitUnits = {}
-- if db.playerPortraitIcon then
-- table.insert(portraitUnits, "player")
-- end
-- if db.portraitIcon then
-- table.insert(portraitUnits, "target")
-- end
-- if #portraitUnits > 0 then
-- self:RegisterUnitEvent("UNIT_AURA", unpack(portraitUnits))
-- end
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("PLAYER_TARGET_CHANGED")
--[[
-- fuck this, PartyDebuffFrameTemplate doesn't create PartyMemberFrame1Debuff1Cooldown, even on live
-- ToT frame does ( and also using this), but it also just spams this function in some OnUpdate probably
hooksecurefunc("RefreshDebuffs", function(frame, unit, numDebuffs, suffix, checkCVar)
if not unit:find("party") then return end
local frameName = frame:GetName();
numDebuffs = numDebuffs or MAX_PARTY_DEBUFFS;
suffix = suffix or "Debuff";
local filter;
if ( checkCVar and SHOW_DISPELLABLE_DEBUFFS == "1" and UnitCanAssist("player", unit) ) then
filter = "RAID";
end
for i=1, numDebuffs do
local name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellId = UnitDebuff(unit, i, filter);
local debuffName = frameName..suffix..i;
print(unit, i, numDebuffs, name, spellId, caster)
if ( icon and ( SHOW_CASTABLE_DEBUFFS == "0" or not isEnemy or caster == "player" ) ) then
-- if we have an icon to show then proceed with setting up the aura
print(name, spellId, caster)
local durationNew, expirationTimeNew = LibClassicDurations:GetAuraDurationByUnit(unit, spellId, caster)
if duration == 0 and durationNew then
duration = durationNew
expirationTime = expirationTimeNew
local cdname = debuffName.."Cooldown"
local coolDown = _G[debuffName.."Cooldown"];
print("got duration", coolDown, frameName, cdname)
if ( coolDown ) then
print("setting", coolDown, expirationTime - duration, duration)
CooldownFrame_Set(coolDown, expirationTime - duration, duration, true);
end
end
end
end
end)
]]
local loader = CreateFrame('Frame', nil, SettingsPanel)
loader:SetScript('OnShow', function(self)
self:SetScript('OnShow', nil)
if not f.optionsPanel then
f.optionsPanel = f:CreateGUI("ClassicAuraDurations")
f.optionsPanel.category = Settings.RegisterCanvasLayoutCategory(f.optionsPanel, "ClassicAuraDurations")
Settings.RegisterAddOnCategory(f.optionsPanel.category)
end
end)
end
function f:PLAYER_TARGET_CHANGED()
if UnitExists("target") then
self:UNIT_AURA(nil, "target")
end
end
function f:UNIT_AURA(event, unit)
if unit == "player" or unit == "target" then
if unit == "player" and not db.playerPortraitIcon then return end
if unit == "target" and not db.portraitIcon then return end
local targetType = "ALLY"
if unit == "target" and (UnitReaction(unit, "player") or 0) < 4 then
targetType = "ENEMY"
end
local frame = unit == "player" and PlayerFrame or TargetFrame
local maxPrio = 0
local maxPrioFilter
local maxPrioIndex = 1
for index=1,100 do --debuffs
local name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellId, _, _, casterIsPlayer, nameplateShowAll = UnitAura(unit, index, "HARMFUL");
if not name then break end
local prio, spellType = LibAuraTypes.GetAuraInfo(spellId, targetType)
if prio and prio > maxPrio then
maxPrio = prio
maxPrioIndex = index
maxPrioFilter = "HARMFUL"
end
end
for index=1,100 do --buffs
local name, icon, count, debuffType, duration, expirationTime, caster, _, _, spellId, _, _, casterIsPlayer, nameplateShowAll = UnitAura(unit, index, "HELPFUL");
if not name then break end
local prio, spellType = LibAuraTypes.GetAuraInfo(spellId, targetType)
if prio and prio > maxPrio then
maxPrio = prio
maxPrioIndex = index
maxPrioFilter = "HELPFUL"
end
end
UpdatePortraitIcon(frame, unit, maxPrio, maxPrioIndex, maxPrioFilter, targetType)
end
end
local function MakeCheckbox(name, parent)
local cb = CreateFrame("CheckButton", name, parent, "UICheckButtonTemplate")
cb:SetWidth(25)
cb:SetHeight(25)
cb:Show()
local cblabel = cb:CreateFontString(nil, "OVERLAY")
cblabel:SetFontObject("GameFontHighlight")
cblabel:SetPoint("LEFT", cb,"RIGHT", 5,0)
cb.label = cblabel
return cb
end
local tooltipOnEnter = function(self, event)
GameTooltip:SetOwner(self, "ANCHOR_TOPLEFT")
GameTooltip:SetText(self.tooltipText, nil, nil, nil, nil, false);
GameTooltip:Show();
end
local tooltipOnLeave = function(self, event)
GameTooltip:Hide();
end
local function AddTooltip(widget, tooltipText)
widget.tooltipText = tooltipText
widget:SetScript("OnEnter", tooltipOnEnter)
widget:SetScript("OnLeave", tooltipOnLeave)
end
function f:CreateGUI(name, parent)
local frame = CreateFrame("Frame")
frame:Hide()
frame.parent = parent
frame.name = name
frame:SetScript("OnShow", function(self)
self.content.portraitIcon:SetChecked(db.portraitIcon)
self.content.verbosePortraitIcon:SetChecked(db.verbosePortraitIcon)
self.content.playerPortraitIcon:SetChecked(db.playerPortraitIcon)
if APILevel == 1 then
self.content.enemyBuffs:SetChecked(db.enemyBuffs)
self.content.hookTargetFrame:SetChecked(db.hookTargetFrame)
self.content.largePersonalDebuffs:SetChecked(db.largePersonalDebuffs)
self.content.largePersonalDebuffs:UpdateDisabled()
end
end)
-- frame:SetScript("OnHide", function(self) print("onHide") end)
local label = frame:CreateFontString(nil, "OVERLAY", "GameFontNormalLarge")
label:SetPoint("TOPLEFT", 10, -15)
label:SetPoint("BOTTOMRIGHT", frame, "TOPRIGHT", 10, -45)
label:SetJustifyH("LEFT")
label:SetJustifyV("TOP")
label:SetText(name)
local content = CreateFrame("Frame", "CADOptionsContent", frame)
content:SetPoint("TOPLEFT", 10, -10)
content:SetPoint("BOTTOMRIGHT", -10, 10)
frame.content = content
-- local warning = content:CreateFontString(nil, "OVERLAY")
-- warning:SetFontObject("GameFontHighlightSmall")
-- warning:SetPoint("TOPLEFT", 10, -40)
-- warning:SetText("If you're getting 'Script ran too long' errors consider turning enemy buffs off or switching to non-standard unitframes")
if APILevel == 1 then
local htt = MakeCheckbox(nil, content)
htt.label:SetText("Hook Target Frame")
htt:SetPoint("TOPLEFT", 10, -60)
content.hookTargetFrame = htt
htt:SetScript("OnClick",function(self,button)
f.Commands.hooktarget()
end)
AddTooltip(htt, "Enable aura durations on target frame")
local ebt = MakeCheckbox(nil, content)
ebt.label:SetText("Full Aura Replacement")
ebt:SetPoint("TOPLEFT", 10, -90)
content.enemyBuffs = ebt
ebt:SetScript("OnClick",function(self,button)
f.Commands.enemybuffs()
self.content.largePersonalDebuffs:UpdateDisabled()
end)
AddTooltip(ebt, [=[As opposed to only adding cooldown swipes, completely duplicates default aura handling.
This allows to display large personal debuffs and some enemy buffs.
May cause 'Script ran too long errors'
]=])
ebt.content = content
end
local pit = MakeCheckbox(nil, content)
pit.label:SetText("Show Portrait Icon")
pit:SetPoint("TOPLEFT", 10, -120)
content.portraitIcon = pit
pit:SetScript("OnClick",function(self,button)
f.Commands.portraiticon()
end)
AddTooltip(pit, "Show CCs and other effects in the portrait")
local vpi = MakeCheckbox(nil, content)
vpi.label:SetText("Verbose Portrait Icon")
vpi:SetPoint("TOPLEFT", 10, -150)
content.verbosePortraitIcon = vpi
vpi:SetScript("OnClick",function(self,button)
f.Commands.verboseicon()
end)
AddTooltip(vpi, "Lowers the threshold of effects for portrait display. Will include slows and anything remotely important")
local ppi = MakeCheckbox(nil, content)
ppi.label:SetText("Player Portrait Icon")
ppi:SetPoint("TOPLEFT", 10, -180)
content.playerPortraitIcon = ppi
ppi:SetScript("OnClick",function(self,button)
f.Commands.playericon()
end)
AddTooltip(ppi, "Show icon on Player Frame")
if APILevel == 1 then
local lpd = MakeCheckbox(nil, content)
lpd.label:SetText("Large Personal Debuffs")
lpd:SetPoint("TOPLEFT", 10, -210)
content.largePersonalDebuffs = lpd
lpd:SetScript("OnClick",function(self,button)
f.Commands.largepersonal()
end)
lpd.UpdateDisabled = function(self)
if not db.enemyBuffs then
self:Disable()
self.label:SetTextColor(0.5, 0.5, 0.5)
else
self:Enable()
self.label:SetTextColor(1,1,1)
end
end
AddTooltip(lpd, "Auras that aren't casted by player will be smaller. Lower OmniCC size threshold to still see numeric display on them.")
end
return frame
end
f.Commands = {
["portraiticon"] = function(v)
db.portraitIcon = not db.portraitIcon
end,
["playericon"] = function(v)
db.playerPortraitIcon = not db.playerPortraitIcon
end,
["verboseicon"] = function(v)
db.verbosePortraitIcon = not db.verbosePortraitIcon
end,
["largepersonal"] = function(v)
db.largePersonalDebuffs = not db.largePersonalDebuffs
ShouldAuraBeLarge = db.largePersonalDebuffs and ShouldAuraBeLargePersonalDebuffs or ShouldAuraBeLargeAlways
end,
["enemybuffs"] = function(v)
db.enemyBuffs = not db.enemyBuffs
ReloadUI()
end,
["hooktarget"] = function(v)
db.hookTargetFrame = not db.hookTargetFrame
ReloadUI()
end,
}
local helpMessage = {
"|cff00ff00/cad portraiticon|r",
"|cff00ff00/cad enemybuffs|r",
"|cff00ff00/cad hooktarget|r",
}
function f.SlashCmd(msg)
local k,v = string.match(msg, "([%w%+%-%=]+) ?(.*)")
if not k or k == "help" then
print("Usage:")
for k,v in ipairs(helpMessage) do
print(" - ",v)
end
end
if f.Commands[k] then
f.Commands[k](v)
end
end
f.EnemyBuffsTargetFrameHook = function(self)
local frame, frameName;
local frameIcon, frameCount, frameCooldown;
local numBuffs = 0;
local playerIsTarget = UnitIsUnit(PlayerFrame.unit, self.unit);
local selfName = self:GetName();
local canAssist = UnitCanAssist("player", self.unit);
local unit = self.unit
for i = 1, MAX_TARGET_BUFFS do
local buffName, icon, count, debuffType, duration, expirationTime, caster, canStealOrPurge, _ , spellId, _, _, casterIsPlayer, nameplateShowAll = LibClassicDurations:UnitAura(self.unit, i, "HELPFUL");
if (buffName) then
frameName = selfName.."Buff"..(i);
frame = _G[frameName];
if ( not frame ) then
if ( not icon ) then
break;
else
frame = CreateFrame("Button", frameName, self, "TargetBuffFrameTemplate");
frame.unit = self.unit;
end
end
if ( icon and ( not self.maxBuffs or i <= self.maxBuffs ) ) then
frame:SetID(i);
-- set the icon
frameIcon = _G[frameName.."Icon"];
frameIcon:SetTexture(icon);
-- set the count
frameCount = _G[frameName.."Count"];
if ( count > 1 and self.showAuraCount ) then
frameCount:SetText(count);
frameCount:Show();
else
frameCount:Hide();
end
-- Handle cooldowns
frameCooldown = _G[frameName.."Cooldown"];
local durationNew, expirationTimeNew = LibClassicDurations:GetAuraDurationByUnit(self.unit, spellId, caster)
if duration == 0 and durationNew then
duration = durationNew
expirationTime = expirationTimeNew
end
CooldownFrame_Set(frameCooldown, expirationTime - duration, duration, duration > 0, true);
-- Show stealable frame if the target is not the current player and the buff is stealable.
local frameStealable = _G[frameName.."Stealable"];
if ( not playerIsTarget and canStealOrPurge ) then
frameStealable:Show();
else
frameStealable:Hide();
end
-- set the buff to be big if the buff is cast by the player or his pet
numBuffs = numBuffs + 1;
largeBuffList[numBuffs] = true--ShouldAuraBeLarge(caster);
frame:ClearAllPoints();
frame:Show();
else
frame:Hide();
end
else
break;
end
end
for i = numBuffs + 1, MAX_TARGET_BUFFS do
local frame = _G[selfName.."Buff"..i];
if ( frame ) then
frame:Hide();
else
break;
end
end
local color;
local frameBorder;
local numDebuffs = 0;
local frameNum = 1;
local index = 1;
local maxDebuffs = self.maxDebuffs or MAX_TARGET_DEBUFFS;
while ( frameNum <= maxDebuffs and index <= maxDebuffs ) do
local debuffName, icon, count, debuffType, duration, expirationTime, caster, _, _, spellId, _, _, casterIsPlayer, nameplateShowAll = UnitDebuff(self.unit, index, "INCLUDE_NAME_PLATE_ONLY");
if ( debuffName ) then
if ( TargetFrame_ShouldShowDebuffs(self.unit, caster, nameplateShowAll, casterIsPlayer) ) then
frameName = selfName.."Debuff"..frameNum;
frame = _G[frameName];
if ( icon ) then
if ( not frame ) then
frame = CreateFrame("Button", frameName, self, "TargetDebuffFrameTemplate");
frame.unit = self.unit;
end
frame:SetID(index);
-- set the icon
frameIcon = _G[frameName.."Icon"];
frameIcon:SetTexture(icon);
-- set the count
frameCount = _G[frameName.."Count"];
if ( count > 1 and self.showAuraCount ) then
frameCount:SetText(count);
frameCount:Show();
else
frameCount:Hide();
end
-- Handle cooldowns
frameCooldown = _G[frameName.."Cooldown"];
local durationNew, expirationTimeNew = LibClassicDurations:GetAuraDurationByUnit(self.unit, spellId, caster)
if duration == 0 and durationNew then
duration = durationNew
expirationTime = expirationTimeNew
end
CooldownFrame_Set(frameCooldown, expirationTime - duration, duration, duration > 0, true);
-- set debuff type color
if ( debuffType ) then
color = DebuffTypeColor[debuffType];
else
color = DebuffTypeColor["none"];
end
frameBorder = _G[frameName.."Border"];
frameBorder:SetVertexColor(color.r, color.g, color.b);
-- set the debuff to be big if the buff is cast by the player or his pet
numDebuffs = numDebuffs + 1;
largeDebuffList[numDebuffs] = ShouldAuraBeLarge(caster);
frame:ClearAllPoints();
frame:Show();
frameNum = frameNum + 1;
end
end
else
break;
end
index = index + 1;
end
for i = frameNum, MAX_TARGET_DEBUFFS do
local frame = _G[selfName.."Debuff"..i];
if ( frame ) then
frame:Hide();
else
break;
end
end
self.auraRows = 0;
local mirrorAurasVertically = false;
if ( self.buffsOnTop ) then
mirrorAurasVertically = true;
end
local haveTargetofTarget;
if ( self.totFrame ) then
haveTargetofTarget = self.totFrame:IsShown();
end
self.spellbarAnchor = nil;
local maxRowWidth;
-- update buff positions
maxRowWidth = ( haveTargetofTarget and self.TOT_AURA_ROW_WIDTH ) or AURA_ROW_WIDTH;
TargetFrame_UpdateAuraPositions(self, selfName.."Buff", numBuffs, numDebuffs, largeBuffList, TargetFrame_UpdateBuffAnchor, maxRowWidth, 3, mirrorAurasVertically);
-- update debuff positions
maxRowWidth = ( haveTargetofTarget and self.auraRows < NUM_TOT_AURA_ROWS and self.TOT_AURA_ROW_WIDTH ) or AURA_ROW_WIDTH;
TargetFrame_UpdateAuraPositions(self, selfName.."Debuff", numDebuffs, numBuffs, largeDebuffList, TargetFrame_UpdateDebuffAnchor, maxRowWidth, 3, mirrorAurasVertically);
-- update the spell bar position
if ( self.spellbar ) then
Target_Spellbar_AdjustPosition(self.spellbar);
end
end