forked from nullfoxh/PlateBuffer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
core.lua
913 lines (719 loc) · 24.2 KB
/
core.lua
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
--[[
PlateBuffer
Nameplate auras for Wow TBC 2.4.3
https://github.com/nullfoxh
Core
]]--
local DEBUG = false
local DR_RESET_TIME = 18
local texCoord = { .1, .9, .2, .8 } -- for squares use { .07, .93, .07, .93 }
local font = "Interface\\AddOns\\PlateBuffer\\homespun.ttf"
---------------------------------------------------------------------------------------------
local ceil, floor, upper, format = math.ceil, math.floor, string.upper, string.format
local UnitGUID, UnitBuff, UnitDebuff, UnitCanAttack, UnitName, UnitIsPlayer, UnitLevel
= UnitGUID, UnitBuff, UnitDebuff, UnitCanAttack, UnitName, UnitIsPlayer, UnitLevel
local tostring, GetTime, GetSpellInfo, DebuffTypeColor, IsInInstance, UnitIsDeadOrGhost
= tostring, GetTime, GetSpellInfo, DebuffTypeColor, IsInInstance, UnitIsDeadOrGhost
local pairs, select, unpack, strsub, strsplit, tonumber, bit_band, table_sort, table_insert
= pairs, select, unpack, strsub, strsplit, tonumber, bit.band, table.sort, table.insert
local addonName = "PlateBuffer"
local print = function(msg) DEFAULT_CHAT_FRAME:AddMessage(format("|cffa0f6aa%s:|r ", addonName)..msg) end
local printf = function(...) print(format(...)) end
print("Loaded. Get updates from https://github.com/nullfoxh/PlateBuffer")
---------------------------------------------------------------------------------------------
local PB = CreateFrame("Frame")
local newChildren, numChildren = 0, 0
local updateTarget, updateMouseOver = false, false
local hasTarget, hasMouseover, targetPlate = false, false, nil
local visiblePlates, knownPlates, knownPlayers = {}, {}, {}
local playerGUID, targetGUID, focusGUID, mouseGUID = UnitGUID("player")
local uiScale = 0.7111
local DRLib = LibStub("DRData-1.0")
local DRCache, AuraCache, conf = {}, {}
local SpellData = PBAD
local ForceMouseoverUpdate = true
local MouseoverUpdateInterval = 0.1
local MouseoverUpdateNext = 0
local Watcher = CreateFrame("Frame")
local WatcherUpdateInterval = 0.1
local WatcherThrottle = 0
local WatchedFrames = {}
local WatcherActive = false
---------------------------------------------------------------------------------------------
-- WATCHER FRAME
---------------------------------------------------------------------------------------------
local function WatcherUpdate(self, elapsed)
WatcherThrottle = WatcherThrottle - elapsed
if WatcherThrottle < 0 then
WatcherThrottle = WatcherUpdateInterval
local time = GetTime()
local framecount = 0
for frame, expiration in pairs(WatchedFrames) do
if expiration < time then
frame:Hide()
WatchedFrames[frame] = nil
else
framecount = framecount + 1
end
end
if framecount == 0 then
Watcher:SetScript("OnUpdate", nil)
WatcherActive = false
end
end
end
local function PolledHideIn(frame, expiration)
if expiration == 0 then
frame:Hide()
WatchedFrames[frame] = nil
else
WatchedFrames[frame] = expiration
frame:Show()
if not WatcherActive then
Watcher:SetScript("OnUpdate", WatcherUpdate)
WatcherActive = true
end
end
end
---------------------------------------------------------------------------------------------
-- CREATE AURA FRAMES
---------------------------------------------------------------------------------------------
local function FormatTime(s)
if s > 3600 then
return format("%dh", ceil(s/3600)), s % 3600
elseif s > 60 then
return format("%dm", ceil(s/60)), s % 60
elseif s > 6 then
return floor(s), s - floor(s)
elseif s > 3 then
return format("|cffffff00%.1f|r", s), (s*10 - floor(s*10)) / 10
elseif s > 1 then
return format("|cffff0000%.1f|r", s), (s*10 - floor(s*10)) / 10
else
return format("|cffff0000.%d|r", s*10), (s*10 - floor(s*10)) / 10
end
end
--[[ Macumba's timers inspired by XiconPlateBuff's timer
local function FormatTime(s)
if s > 3600 then
return format("%dh", ceil(s/3600)), s % 3600
elseif s > 60 then
return format("%dm", ceil(s/60)), s % 60
elseif s > 6 then
return floor(s), s - floor(s)
elseif s > 3 then
return format("|cffffff00%.1f|r", s), (s*10 - floor(s*10)) / 10
elseif s > 1 then
return format("|cffff0000%.1f|r", s), (s*10 - floor(s*10)) / 10
else
return format("|cffff0000.%d|r", s*10), (s*10 - floor(s*10)) / 10
end
end ]]
local function UpdateTimer(self, elapsed)
if self.nextUpdate > 0 then
self.nextUpdate = self.nextUpdate - elapsed
else
local remain = self.expiration - GetTime()
if remain > 0 then
local time, nextUpdate = FormatTime(remain)
self.timer:SetText(time)
self.nextUpdate = nextUpdate
else
self.timer:Hide()
self:SetScript("OnUpdate", nil)
end
end
end
local function CreateAura(plate, i, aura, row)
if not plate.debuffs then plate.debuffs = {} end
local width, height = conf.auraWidth, conf.auraHeight
local perRow, spacing = conf.aurasPerRow, conf.auraSpacing*uiScale
local borderSize = conf.borderSize and conf.borderSize*uiScale or 1
local f = CreateFrame("Frame", nil, plate)
f:SetFrameStrata("BACKGROUND")
f.bg = f:CreateTexture(nil, "BACKGROUND")
f.bg:SetPoint("TOPLEFT", f, -borderSize, borderSize)
f.bg:SetPoint("BOTTOMRIGHT", f, borderSize, -borderSize)
f.bg:SetTexture("Interface\\ChatFrame\\ChatFrameBackground")
f.bg:SetVertexColor(0, 0, 0)
f:SetWidth(width)
f:SetHeight(height)
f.icon = f:CreateTexture(nil, "ARTWORK")
f.icon:SetAllPoints(f)
if not conf.disableCooldown then
f.cd = CreateFrame("Cooldown", nil, f, "PlateBufferCD")
f.cd:SetAllPoints(f)
else
f.cd = CreateFrame("Frame", nil, f)
f.cd:SetAllPoints(f)
end
f.count = f.cd:CreateFontString(nil, "OVERLAY")
f.count:SetFont(font, conf.fontSize * uiScale, "OUTLINE")
f.count:SetShadowColor(0, 0, 0)
f.count:SetShadowOffset(1, -1)
f.count:SetPoint("BOTTOMRIGHT", f.cd, "BOTTOMRIGHT", 1, 2)
f.count:SetJustifyH("RIGHT")
if not conf.disableDuration then
f.cd.noCooldownCount = true -- disable OmniCC
f.timer = f.cd:CreateFontString(nil, "OVERLAY")
f.timer:SetFont(font, conf.fontSize * uiScale, "OUTLINE")
f.timer:SetShadowColor(0, 0, 0)
f.timer:SetShadowOffset(1, -1)
f.timer:SetPoint("CENTER", f.cd, "CENTER", conf.fontOffx, conf.fontOffy)
f.timer:SetJustifyH("CENTER")
end
if i == 1 then
f:SetPoint("BOTTOMLEFT", plate, "TOP", conf.auraOffx-((width+spacing)*perRow-spacing)/2, conf.auraOffy)
elseif row > 1 then
f:SetPoint("BOTTOM", plate.debuffs[i-perRow], "TOP", 0, spacing)
else
f:SetPoint("LEFT", plate.debuffs[aura-1], "RIGHT", spacing, 0)
end
plate.debuffs[i] = f
return f
end
---------------------------------------------------------------------------------------------
-- HANDLE PLATE AURAS
---------------------------------------------------------------------------------------------
function PB:UpdatePlate(guid, name)
local plate = knownPlates[guid]
if plate then
PB:UpdatePlateAuras(plate, guid)
elseif name then
plate = PB:GetPlateByName(name)
if plate then
PB:OnPlateIdentified(plate, guid, true)
end
end
end
function PB:UpdatePlateAuras(plate, guid)
local plate = knownPlates[guid]
local auras = PB:GetUnitAuras(guid)
if not plate or not auras then
return
end
local i = 1
for row = 1, conf.auraRows do
for a = 1, conf.aurasPerRow do
local aura = auras[i]
if aura then
local button
if plate.debuffs and plate.debuffs[i] then
button = plate.debuffs[i]
else
button = CreateAura(plate, i, a, row)
end
button.icon:SetTexture(aura.icon)
button.icon:SetTexCoord(unpack(texCoord))
button.count:SetText(aura.count > 1 and aura.count)
if aura.type ~= "BUFF" then
local color = DebuffTypeColor[aura.type]
button.bg:SetVertexColor(color.r, color.g, color.b)
else
button.bg:SetVertexColor(0, 0, 0)
end
if aura.duration and aura.duration > 0 then
if not conf.disableCooldown then
button.cd:SetCooldown(aura.startTime, aura.duration)
button.cd:SetReverse()
end
if not conf.disableDuration then
button.timer:Show()
button.expiration = aura.expiration
button.nextUpdate = 0
button:SetScript("OnUpdate", UpdateTimer)
end
end
PolledHideIn(button, aura.expiration)
elseif plate.debuffs and plate.debuffs[i] then
PolledHideIn(plate.debuffs[i], 0)
end
i = i + 1
end
end
end
---------------------------------------------------------------------------------------------
-- HANDLE UNIT AURAS
---------------------------------------------------------------------------------------------
local function AuraSort(a, b)
if a and b then
if a.isMine and not b.isMine then
return true
elseif b.isMine and not a.isMine then
return false
end
return a.expiration < b.expiration
end
end
function PB:GetUnitAuras(guid)
if AuraCache[guid] then
local auras = {}
local time = GetTime()
for k, v in pairs(AuraCache[guid]) do
local aura = {}
aura.name, aura.spellID, aura.icon, aura.count, aura.type, aura.duration, aura.timeLeft, aura.startTime, aura.expiration, aura.isMine = PB:GetAuraInstance(guid, k)
if time < aura.expiration then
if aura.duration > 0 then
table_insert(auras, aura)
end
else
PB:RemoveAuraInstance(guid, k)
end
end
table_sort(auras, AuraSort)
return auras
end
return nil
end
function PB:SetAuraInstance(guid, spellName, spellID, icon, count, dtype, duration, timeLeft, isMine)
if not AuraCache[guid] then AuraCache[guid] = {} end
local time = GetTime()
AuraCache[guid][spellName] = { spellName, spellID, icon, count or 0, dtype or "none", duration, timeLeft, time-(duration-timeLeft), time+timeLeft, isMine}
end
-- AuraInstance: spellName, spellID, icon, count, type, duration, timeLeft, startTime, expiration, isMine
function PB:GetAuraInstance(guid, spellName)
if AuraCache[guid] and AuraCache[guid][spellName] then
return unpack(AuraCache[guid][spellName])
end
end
function PB:RemoveAuraInstance(guid, spellName)
if AuraCache[guid] and AuraCache[guid][spellName] then
AuraCache[guid][spellName] = nil
return true
end
return false
end
function PB:WipeAuraCache(guid)
if AuraCache[guid] then
AuraCache[guid] = nil
end
end
---------------------------------------------------------------------------------------------
-- HANDLE SPELLDATA
---------------------------------------------------------------------------------------------
function PB:GetSpellData(spellID, isPlayer)
if SpellData.auraInfo[spellID] then
local duration, debuffType = strsplit(";", SpellData.auraInfo[spellID])
debuffType = SpellData.debuffTypes[tonumber(debuffType)]
if isPlayer and SpellData.auraInfoPvP[spellID] then
return SpellData.auraInfoPvP[spellID], debuffType
else
return tonumber(duration), debuffType
end
end
end
function PB:IsTracked(name, isMine)
if not conf.auraList[name] then
return false
elseif conf.auraList[name] == "mine" and not isMine then
return false
elseif conf.auraList[name] == "mine" and isMine then
return true
elseif conf.auraList[name] == "all" then
return true
end
return false
end
---------------------------------------------------------------------------------------------
-- HANDLE DR DATA
---------------------------------------------------------------------------------------------
function PB:InitDR(guid, spellID, isPlayer)
local cat = DRLib:GetSpellCategory(spellID)
if cat then
if not isPlayer and not DRLib:IsPVE(cat) then
return 1
end
if not DRCache[guid] then
DRCache[guid] = {}
end
if not DRCache[guid][cat] then
DRCache[guid][cat] = { reset = 0, diminished = 1.0 }
end
if DRCache[guid][cat].reset <= GetTime() then
DRCache[guid][cat].diminished = 1.0
end
return DRCache[guid][cat].diminished
end
return 1
end
function PB:ApplyDR(guid, spellID, isPlayer)
local cat = DRLib:GetSpellCategory(spellID)
if cat then
if not isPlayer and not DRLib:IsPVE(cat) then
return
end
if not DRCache[guid] then
DRCache[guid] = {}
end
if not DRCache[guid][cat] then
DRCache[guid][cat] = { reset = 0, diminished = 1.0 }
end
local tracked = DRCache[guid][cat]
tracked.reset = GetTime() + DR_RESET_TIME
tracked.diminished = DRLib:NextDR(tracked.diminished)
end
end
function PB:ResetDR(guid)
if DRCache[guid] then
for cat in pairs (DRCache[guid]) do
DRCache[guid][cat].reset = 0
DRCache[guid][cat].diminished = 1.0
end
end
end
---------------------------------------------------------------------------------------------
-- HANDLE COMBATLOG AURAS
---------------------------------------------------------------------------------------------
local function IsPlayer(GUID)
return bit_band(strsub(GUID, 1, 5), 0x00F) == 0
end
function PB:OnAuraApplied(srcGUID, dstGUID, dstName, spellID, spellName, auraType, stackCount)
local isPlayer = IsPlayer(dstGUID)
local dr = 1
if DRLib:GetSpellCategory(spellID) then
dr = PB:InitDR(dstGUID, spellID, isPlayer)
end
if isPlayer then
knownPlayers[dstName] = dstGUID
end
local isMine = srcGUID == playerGUID
if not PB:IsTracked(spellName, isMine) then
return
end
local duration, debuffType = PB:GetSpellData(spellID, isPlayer)
if duration then
if auraType == "DEBUFF" then
auraType = debuffType
end
duration = duration * dr
if duration > 0 then
local _, _, icon = GetSpellInfo(spellID)
PB:SetAuraInstance(dstGUID, spellName, spellID, icon, stackCount, auraType, duration, duration, isMine)
PB:UpdatePlate(dstGUID, isPlayer and dstName or nil)
end
elseif DEBUG then
print(format('Missing aura info, please report: [%s] = "0;0", -- %s', spellID, spellName))
end
end
function PB:OnAuraRemoved(dstGUID, dstName, spellName, spellID, noUpdate)
local isPlayer = IsPlayer(dstGUID)
PB:ApplyDR(dstGUID, spellID, isPlayer)
if PB:RemoveAuraInstance(dstGUID, spellName) and not noUpdate then
PB:UpdatePlate(dstGUID, isPlayer and dstName or nil)
end
end
function PB:OnMeleeRefresh(srcGUID, dstGUID, dstName, spellID, spellName, auraType, stackCount)
local _, _, _, _, _, _, _, _, expiration = PB:GetAuraInstance(dstGUID, spellName)
if expiration and GetTime() <= expiration then
PB:ApplyDR(dstGUID, spellID, IsPlayer(dstGUID))
PB:OnAuraApplied(srcGUID, dstGUID, dstName, spellID, spellName, auraType, stackCount)
end
end
---------------------------------------------------------------------------------------------
-- PARSE COMBAT LOG EVENTS
---------------------------------------------------------------------------------------------
local friendly = COMBATLOG_OBJECT_REACTION_FRIENDLY
local function IsFriendly(flags)
return bit_band(flags, friendly) == friendly
end
function PB:COMBAT_LOG_EVENT_UNFILTERED(...)
local _, eventType, srcGUID, srcName, srcFlags, dstGUID, dstName, dstFlags, spellID, spellName, spellSchool, auraType, stackCount = select(1, ...)
if IsFriendly(dstFlags) then return end
if eventType == "SPELL_AURA_APPLIED" or eventType == "SPELL_AURA_APPLIED_DOSE" or eventType == "SPELL_AURA_REMOVED_DOSE" then
PB:OnAuraApplied(srcGUID, dstGUID, dstName, spellID, spellName, auraType, stackCount)
elseif eventType == "SPELL_AURA_REFRESH" then
PB:OnAuraRemoved(dstGUID, dstName, spellName, spellID, NOUPDATE)
PB:OnAuraApplied(srcGUID, dstGUID, dstName, spellID, spellName, auraType, stackCount)
elseif eventType == "SPELL_AURA_REMOVED" then
PB:OnAuraRemoved(dstGUID, dstName, spellName, spellID)
elseif eventType == "SPELL_DISPEL" or eventType == "SPELL_STOLEN" then
PB:OnAuraRemoved(dstGUID, dstName, spellName, spellID)
elseif eventType == "SPELL_CAST_SUCCESS" and spellSchool == 1 then
PB:OnMeleeRefresh(srcGUID, dstGUID, dstName, spellID, spellName, auraType, stackCount)
elseif eventType == "UNIT_DIED" then
PB:WipeAuraCache(dstGUID)
PB:ResetDR(dstGUID)
end
end
---------------------------------------------------------------------------------------------
-- UNIT_AURA
---------------------------------------------------------------------------------------------
local function round(num, numDecimalPlaces)
local mult = 10^(numDecimalPlaces or 0)
return floor(num * mult + 0.5) / mult
end
function PB:UNIT_AURA(unit, noUpdate)
if unit ~= "target" and unit ~= "focus" and unit ~= "mouseover" then
return
end
if not UnitCanAttack("player", unit) then
return
end
local needUpdate = false
local guid = UnitGUID(unit)
local time = GetTime()
for i = 1, 40 do
local name, rank, icon, count, dtype, duration, timeLeft, isMine = UnitDebuff(unit, i)
if not name then break end
if timeLeft and (isMine or (isMine == nil and duration and duration > 0)) then
if PB:IsTracked(name, true) then
-- Check if we have an existing instance of this aura, ignore if we do. Needed due to forced UNIT_AURA updates on mouseover.
local _, _, _, aCount, _, _, _, _, expiration = PB:GetAuraInstance(guid, name)
if not expiration or count ~= aCount or round(expiration, 1) ~= round(time+timeLeft, 1) then
PB:SetAuraInstance(guid, name, nil, icon, count, dtype, duration, timeLeft, true)
needUpdate = true
end
end
end
end
for i = 1, 40 do
local name, rank, icon, count, duration, timeLeft, isMine = UnitBuff(unit, i)
if not name then break end
if timeLeft and (isMine or (isMine == nil and duration and duration > 0)) then
if PB:IsTracked(name, true) then
-- Check if we have an existing instance of this aura, ignore if we do. Needed due to forced UNIT_AURA updates on mouseover.
local _, _, _, aCount, _, _, _, _, expiration = PB:GetAuraInstance(guid, name)
if not expiration or count ~= aCount or round(expiration, 1) ~= round(time+timeLeft, 1) then
PB:SetAuraInstance(guid, name, nil, icon, count, "BUFF", duration, timeLeft, true)
needUpdate = true
end
end
end
end
if needUpdate and not noUpdate then
PB:UpdatePlate(guid, UnitIsPlayer(unit) and UnitName(unit) or nil)
end
end
---------------------------------------------------------------------------------------------
-- EVENTS
---------------------------------------------------------------------------------------------
local function IsValidTarget(unit)
return UnitCanAttack("player", unit) == 1 and not UnitIsDeadOrGhost(unit)
end
function PB:PLAYER_TARGET_CHANGED()
targetPlate = nil
targetGUID = nil
hasTarget = IsValidTarget("target")
if hasTarget then
updateTarget = true
end
end
function PB:UPDATE_MOUSEOVER_UNIT()
mouseGUID = nil
hasMouseover = IsValidTarget("mouseover")
if hasMouseover then
updateMouseOver = true
end
end
function PB:PLAYER_FOCUS_CHANGED()
focusGUID = UnitGUID("focus")
PB:UNIT_AURA("focus")
end
function PB:VARIABLES_LOADED()
uiScale = tonumber(GetCVar("uiScale"))
end
function PB:UI_SCALE_CHANGED()
uiScale = tonumber(GetCVar("uiScale"))
end
function PB:ADDON_LOADED(addon)
if addon == "PlateBuffer" then
PB:UnregisterEvent("ADDON_LOADED")
conf = PBCONF.activeprofile
end
end
function PB:OnEvent(event, ...)
self[event](self, ...)
end
PB:SetScript("OnEvent", PB.OnEvent)
PB:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
PB:RegisterEvent("PLAYER_FOCUS_CHANGED")
PB:RegisterEvent("PLAYER_TARGET_CHANGED")
PB:RegisterEvent("UPDATE_MOUSEOVER_UNIT")
PB:RegisterEvent("VARIABLES_LOADED")
PB:RegisterEvent("UI_SCALE_CHANGED")
PB:RegisterEvent("ADDON_LOADED")
PB:RegisterEvent("UNIT_AURA")
---------------------------------------------------------------------------------------------
-- SETUP PLATES
---------------------------------------------------------------------------------------------
local function PlateOnShow(frame)
visiblePlates[frame] = true
frame.pbguid = nil
frame.pbname = frame.name:GetText()
frame.pblevel = frame.level:GetText()
frame.pbicon = nil
local guid = knownPlayers[frame.pbname]
if guid then
PB:OnPlateIdentified(frame, guid)
elseif hasTarget and not targetPlate then
updateTarget = true
end
end
local function PlateOnHide(frame)
if frame.pbguid then
knownPlates[frame.pbguid] = nil
frame.pbguid = nil
end
frame.pbname = nil
frame.pblevel = nil
frame.pbicon = nil
if targetPlate == frame then
targetPlate = nil
end
-- Hide debuffs
if frame.debuffs then
for i = 1, conf.auraRows*conf.aurasPerRow do
if frame.debuffs[i] then
PolledHideIn(frame.debuffs[i], 0)
else
break
end
end
end
visiblePlates[frame] = nil
end
local function SetupPlate(frame)
local _, _, _, highlight, nameText, levelText, _, raidIcon = frame:GetRegions()
-- For elvui compatibility
frame.icon = raidIcon
frame.name = nameText
frame.level = levelText
frame.highlight = highlight
if frame:GetScript("OnShow") then
frame:HookScript("OnShow", PlateOnShow)
else
frame:SetScript("OnShow", PlateOnShow)
end
if frame:GetScript("OnHide") then
frame:HookScript("OnHide", PlateOnHide)
else
frame:SetScript("OnHide", PlateOnHide)
end
frame.pbsetup = true
PlateOnShow(frame)
end
local function IsNameplate(frame)
if frame:GetName() then
return false
end
local overlay = frame:GetRegions()
if overlay and overlay:GetObjectType() == "Texture" then
return overlay:GetTexture() == "Interface\\Tooltips\\Nameplate-Border"
end
return false
end
local function GetNewPlates(newChildren, ...)
for i = numChildren + 1, newChildren do
local frame = select(i, ...)
if IsNameplate(frame) and not frame.pbsetup then
SetupPlate(frame)
end
end
end
function PB:OnUpdate(elapsed)
if updateTarget then
PB:UpdateTargetPlate()
end
if updateMouseOver then
PB:UpdateMouseOverPlate()
end
-- UNIT_AURA doesn't fire for mouseover in TBC, so force these updates.
if ForceMouseoverUpdate and hasMouseover then
MouseoverUpdateNext = MouseoverUpdateNext + elapsed
if MouseoverUpdateNext > MouseoverUpdateInterval then
MouseoverUpdateNext = 0
if IsValidTarget("mouseover") then
PB:UNIT_AURA("mouseover")
else
hasMouseover = false
end
end
end
newChildren = WorldFrame:GetNumChildren()
if newChildren > numChildren then
GetNewPlates(newChildren, WorldFrame:GetChildren())
numChildren = newChildren
end
end
PB:SetScript("OnUpdate", PB.OnUpdate)
---------------------------------------------------------------------------------------------
-- PLATE HANDLERS
---------------------------------------------------------------------------------------------
function PB:OnPlateIdentified(plate, guid, override)
local old = knownPlates[guid]
if old and plate ~= old then
if override then
PlateOnHide(old)
PlateOnShow(old)
else
return
end
end
knownPlates[guid] = plate
plate.pbguid = guid
PB:UpdatePlateAuras(plate, guid)
end
function PB:GetPlateByName(name)
for v in pairs(visiblePlates) do
if name == v.pbname then
return v
end
end
end
function PB:GetTargetPlate()
for v in pairs(visiblePlates) do
if v:IsShown() and v:GetAlpha() == 1 then
return v
end
end
end
function PB:GetMouseOverPlate()
-- compare name and level too as this can be pretty unreliable..
local name = UnitName("mouseover")
local level tostring(UnitLevel("mouseover"))
local count = 0
local plate
for v in pairs(visiblePlates) do
if v:IsShown() and v.highlight:IsShown() and name == v.pbname and level == v.pblevel then
plate = v
count = count + 1
end
end
-- this was a fun bug to hunt down
if count == 1 then
return plate
end
end
function PB:UpdateTargetPlate()
updateTarget = false
if IsValidTarget("target") then
targetGUID = UnitGUID("target")
local plate = PB:GetTargetPlate()
if plate then
targetPlate = plate
PB:UNIT_AURA("target", NOUPDATE)
PB:OnPlateIdentified(plate, targetGUID, true)
end
end
end
function PB:UpdateMouseOverPlate()
updateMouseOver = false
if IsValidTarget("mouseover") then
mouseGUID = UnitGUID("mouseover")
local plate
if mouseGUID == targetGUID then
return
elseif knownPlates[mouseGUID] then
PB:UNIT_AURA("mouseover")
return
elseif UnitIsPlayer("mouseover") then
plate = PB:GetPlateByName(UnitName("mouseover"))
else
plate = PB:GetMouseOverPlate()
end
if plate then
PB:UNIT_AURA("mouseover", NOUPDATE)
PB:OnPlateIdentified(plate, mouseGUID)
end
end
end