-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuffgui.lua
1192 lines (988 loc) · 37.4 KB
/
buffgui.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
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
if( not PaladinBuffer ) then return end
local Buff = PaladinBuffer:NewModule("BuffGUI", "AceEvent-3.0")
local L = PaladinBufferLocals
local blessings = {[GetSpellInfo(56520)] = "might", [GetSpellInfo(48934)] = "gmight", [GetSpellInfo(56521)] = "wisdom", [GetSpellInfo(48938)] = "gwisdom", [GetSpellInfo(20911)] = "sanct", [GetSpellInfo(25899)] = "gsanct", [GetSpellInfo(20217)] = "kings", [GetSpellInfo(25898)] = "gkings"}
local blessingIcons = {["gmight"] = select(3, GetSpellInfo(48934)), ["gwisdom"] = select(3, GetSpellInfo(48938)), ["gsanct"] = select(3, GetSpellInfo(25899)),["gkings"] = select(3, GetSpellInfo(25898)), ["might"] = select(3, GetSpellInfo(56520)), ["wisdom"] = select(3, GetSpellInfo(56521)), ["sanct"] = select(3, GetSpellInfo(20911)), ["kings"] = select(3, GetSpellInfo(20217))}
local classFrames, singleTimes, greaterTimes, singleTypes, greaterTypes = {}, {}, {}, {}, {}
local playerName = UnitName("player")
local inCombat, assignments, groupRoster, petUnits, guidMap
function Buff:Enable()
if( PaladinBuffer.disabled ) then
return
end
assignments = PaladinBuffer.db.profile.assignments[playerName]
groupRoster = PaladinBuffer.groupRoster
petUnits = PaladinBuffer.petUnits
guidMap = PaladinBuffer.guidMap
inCombat = InCombatLockdown()
self:RegisterEvent("UNIT_AURA")
self:RegisterEvent("PLAYER_REGEN_DISABLED")
self:RegisterEvent("PLAYER_REGEN_ENABLED")
self:RegisterMessage("PB_ROSTER_UPDATED", "UpdateClassFrames")
self:RegisterMessage("PB_ASSIGNMENTS_UPDATED", "UpdateFrame")
self:ScanGroup()
self:UpdateClassFrames()
end
function Buff:Disable()
self:UnregisterAllEvents()
self:UnregisterAllMessages()
if( blessingTimers ) then
for _, data in pairs(blessingTimers) do
for k in pairs(data) do data[k] = nil end
end
end
if( self.parent ) then
self.parent:Hide()
end
end
function Buff:UpdateFrame()
if( not self.frame or not self.parent:IsVisible() ) then
return
end
self:ScanGroup()
self:UpdateAuraTimes()
if( self.frame:IsVisible() ) then
self:UpdateColorStatus(self.frame, self.frame.filter)
end
for _, frame in pairs(classFrames) do
self:UpdateClassFrames()
self:UpdateColorStatus(frame, frame.filter)
end
end
function Buff:PLAYER_REGEN_DISABLED()
inCombat = true
if( self.frame ) then
-- Fade out the icon to show we're in combat
self.frame.icon:SetAlpha(0.50)
-- Stop any buffing in combat regardless
self.frame:SetAttribute("type1", nil)
self.frame:SetAttribute("type2", nil)
end
-- Find the a person of the class thats online (and in range if we can) that we can buff in combat
for classToken, frame in pairs(classFrames) do
local type, unit, spell = self:FindClosetToBuff(classToken)
if( not type ) then
frame.icon:SetAlpha(0.50)
else
frame.icon:SetAlpha(1.0)
end
frame:SetAttribute("type1", type)
frame:SetAttribute("unit1", unit)
frame:SetAttribute("spell1", spell)
frame:SetAttribute("type2", nil)
-- Setup attributes for the popouts
if( frame.popout and frame.popout[1] ) then
for _, pop in pairs(frame.popout) do
local type, unit, spell = PaladinBuffer.modules.BuffGUI:FindPlayerAssignment(pop.unit, UnitName(pop.unit), pop.classToken, true)
pop:SetAttribute("type", type)
pop:SetAttribute("unit", unit)
pop:SetAttribute("spell", spell)
end
end
end
-- Supposed to keep this hidden in combat
if( self.parent and PaladinBuffer.db.profile.frame.hideInCombat ) then
self.parent:Hide()
end
end
function Buff:PLAYER_REGEN_ENABLED()
inCombat = nil
if( updateQueued or ( self.frame and PaladinBuffer.db.profile.frame.hideInCombat ) ) then
updateQueued = nil
self:UpdateClassFrames()
end
if( self.frame and self.frame:IsVisible() ) then
self.frame.icon:SetAlpha(1.0)
for _, frame in pairs(classFrames) do
frame.icon:SetAlpha(1.0)
end
end
end
-- Get the units class, including the class translation if it's a Pet
function Buff:GetUnitClass(unit, skipOffline)
-- Not a pet
if( UnitIsPlayer(unit) ) then
-- We should not skip our offline check, and we should not wait for offline people.
if( not skipOffline and not PaladinBuffer.db.profile.offline and not UnitIsConnected(unit) ) then
return nil
end
return select(2, UnitClass(unit))
end
local family = UnitCreatureFamily(unit)
-- Make sure we want to merge pets into here, also that the pet exists annnnnnnd that it's not a water elemental
if( not PaladinBuffer.db.profile.mergePets or not family or not UnitExists(unit) or UnitName(unit) == L["Water Elemental"] ) then
return nil
-- Check for class overrides
elseif( family == L["Felguard"] or family == L["Voidwalker"] ) then
return "WARRIOR"
elseif( family == L["Succubus"] or family == L["Felhunter"] ) then
return "WARLOCK"
else
return select(2, UnitClass(unit))
end
end
-- Update if we have people in or out of range
function Buff:UpdateColorStatus(frame, filter)
local hasSingleOOR, lowestSingle, hasSingleMissing
local hasGreaterCast, hasGreaterOOR, lowestGreater, hasGreaterMissing
-- Check group roster
for name, unit in pairs(groupRoster) do
local classToken = self:GetUnitClass(unit)
if( classToken == filter or filter == "ALL" ) then
local greaterBlessing = PaladinBuffer.blessings[assignments[classToken]]
local guid = UnitGUID(unit)
-- Are we assigned to cast a single on this person?
if( assignments[name] ) then
-- Unlike greater blessings, we have to enforce the 30 yard range on singles :(
if( IsSpellInRange(PaladinBuffer.blessings[assignments[name]], unit) ~= 1 ) then
hasSingleOOR = true
end
local buffTime = singleTimes[guid]
if( not buffTime or singleTypes[guid] ~= assignments[name] ) then
hasSingleMissing = true
elseif( not lowestSingle or lowestSingle > buffTime ) then
lowestSingle = buffTime
end
-- Nope, a greater!
elseif( greaterBlessing ) then
-- Check if we have someone we can cast this initially on
if( IsSpellInRange(greaterBlessing, unit) == 1 ) then
hasGreaterCast = true
else
hasGreaterOOR = true
end
-- Find the lowest buff time + does someone have a buff missing
local buffTime = greaterTimes[guid]
if( not buffTime or greaterTypes[guid] ~= assignments[classToken] ) then
hasGreaterMissing = true
elseif( not lowestGreater or lowestGreater > buffTime ) then
lowestGreater = buffTime
end
end
end
end
local needRecast
local time = GetTime()
if( hasGreaterMissing ) then
needRecast = "greater"
elseif( hasSingleMissing ) then
needRecast = "single"
elseif( lowestSingle and ((lowestSingle - time) / 60) < PaladinBuffer.db.profile.singleThreshold ) then
needRecast = "single"
elseif( lowestGreater and ((lowestGreater - time) / 60) < PaladinBuffer.db.profile.greaterThreshold ) then
needRecast = "greater"
end
if( not needRecast ) then
frame:SetBackdropColor(PaladinBuffer.db.profile.frame.background.r, PaladinBuffer.db.profile.frame.background.g, PaladinBuffer.db.profile.frame.background.b, 1.0)
elseif( ( needRecast == "greater" and hasGreaterCast and hasGreaterOOR ) or ( needRecast == "single" and hasSingleOOR ) ) then
frame:SetBackdropColor(PaladinBuffer.db.profile.frame.cantRebuff.r, PaladinBuffer.db.profile.frame.cantRebuff.g, PaladinBuffer.db.profile.frame.cantRebuff.b, 1.0)
else
frame:SetBackdropColor(PaladinBuffer.db.profile.frame.needRebuff.r, PaladinBuffer.db.profile.frame.needRebuff.g, PaladinBuffer.db.profile.frame.needRebuff.b, 1.0)
end
end
function Buff:FindPlayerAssignment(unit, name, classToken, ignoreTime)
local assignedToken = assignments[name] or assignments[classToken]
if( not assignedToken ) then
return nil
end
local assignedName = PaladinBuffer.blessings[assignedToken]
-- We're entering combat, so just assign what we can and don't do any fancy checks
if( ignoreTime ) then
if( assignedName ) then
return "spell", unit, assignedName
end
return nil
end
-- Find out how much time is left
local type = PaladinBuffer.blessingTypes[assignedToken]
local secondsLeft = 0
local buffID = 1
while( true ) do
local buffName, rank, texture, count, debuffType, duration, endTime, isMine, isStealable = UnitAura(unit, buffID, "PLAYER")
if( not buffName ) then break end
buffID = buffID + 1
if( buffName == assignedName ) then
secondsLeft = (endTime - GetTime()) / 60
break
end
end
secondsLeft = secondsLeft / 60
-- Need to recast
if( ( type == "greater" and secondsLeft < PaladinBuffer.db.profile.greaterThreshold ) or ( type == "single" and secondsLeft < PaladinBuffer.db.profile.singleThreshold ) ) then
return "spell", unit, assignedName
end
return nil
end
-- Figure out who we could buff for this class
function Buff:FindClosetToBuff(classFilter)
-- Do we have an assignment for this glass?
local blessingToken = assignments[classFilter]
if( not blessingToken ) then
return nil
end
local blessingName = PaladinBuffer.blessings[blessingToken]
local closetInRange, closetOnline
for name, unit in pairs(groupRoster) do
local classToken = self:GetUnitClass(unit, true)
if( classToken == classFilter ) then
if( IsSpellInRange(blessingName, unit) == 1 and not UnitIsDeadOrGhost(unit) ) then
closetInRange = unit
end
if( UnitIsConnected(unit) ) then
closetOnline = unit
end
end
end
if( closetInRange or closetOnline ) then
return "spell", (closetInRange or closetOnline), blessingName
end
return nil
end
-- Find time left on the buff assigned to theree class/player
function Buff:GetBuffTimeLeft(unit, classToken)
local assignedToken = assignments[classToken]
if( UnitIsPlayer(unit) and assignments[UnitName(unit)] ) then
assignedToken = assignments[UnitName(unit)]
end
if( not assignedToken ) then
return nil
end
local assignedName = PaladinBuffer.blessings[assignedToken]
local buffID = 1
while( true ) do
local buffName, rank, texture, count, debuffType, duration, endTime, isMine, isStealable = UnitAura(unit, buffID, "PLAYER")
if( not buffName ) then break end
buffID = buffID + 1
if( buffName == assignedName ) then
return endTime - GetTime(), PaladinBuffer.blessingTypes[assignedToken]
end
end
return nil
end
-- Figure out who we're going to be casting this one
function Buff:FindLowestTime(classFilter, blessingName)
local classTotal = 0
local hasBuff = 0
local visibleRange = 0
local totalOnline = 0
local lowestTime, inSpellRange, spellDuration
for name, unit in pairs(groupRoster) do
local classToken = self:GetUnitClass(unit)
if( classToken == classFilter and not assignments[name] ) then
classTotal = classTotal + 1
-- We need an initial target, so we have to make sure at least one person is within range of us
if( IsSpellInRange(blessingName, unit) == 1 and not UnitIsDeadOrGhost(unit) ) then
visibleRange = visibleRange + 1
inSpellRange = unit
end
-- Check if they have the buff
local buffID = 1
while( true ) do
local buffName, rank, texture, count, debuffType, duration, endTime, isMine, isStealable = UnitAura(unit, buffID, "PLAYER")
if( not buffName ) then break end
if( blessingName == buffName ) then
hasBuff = hasBuff + 1
if( not lowestTime or lowestTime > endTime ) then
spellDuration = duration
lowestTime = endTime
end
break
end
buffID = buffID + 1
end
end
end
-- Nobody of this class is even in the raid
if( classTotal == 0 ) then
return "none"
end
-- Either nobody is in range for the initial spell, or the total people we have visible is below the threshold
-- regardless show that we can't hit them due to range.
if( not inSpellRange or (visibleRange / classTotal) < PaladinBuffer.db.profile.rangeThreshold ) then
return "oor"
end
-- Convert it from time into seconds left
if( lowestTime ) then
lowestTime = lowestTime - GetTime()
end
-- Either we don't have this buff on the class yet, or we do but the time is below the threshold percent
local timeType = "singleThreshold"
if( PaladinBuffer.blessingTypes[blessings[blessingName]] == "greater" ) then
timeType = "greaterThreshold"
end
if( hasBuff < visibleRange or not lowestTime or (lowestTime / 60) < PaladinBuffer.db.profile[timeType] ) then
return "cast", inSpellRange, (lowestTime or 0)
end
return "nil"
end
-- Return info for auto buffing on the lowest greater
function Buff:AutoBuffLowestGreater(filter)
local castSpellOn, castSpell, lowestTime
for assignment, spellToken in pairs(assignments) do
if( spellToken and PaladinBuffer.classList[assignment] and ( filter == "ALL" or filter == assignment ) ) then
local status, spellTarget, timeLeft = self:FindLowestTime(assignment, PaladinBuffer.blessings[spellToken])
if( status == "cast" ) then
if( not lowestTime or lowestTime > timeLeft ) then
castSpell = PaladinBuffer.blessings[spellToken]
castSpellOn = spellTarget
lowestTime = timeLeft
end
end
end
end
if( castSpellOn ) then
return "spell", castSpellOn, castSpell
end
return nil
end
-- Return info on auto buffing the lowest single
function Buff:AutoBuffLowestSingle(filter)
local lowestTime, castSpell, castSpellOn
-- Find the lowest single blessing we cast, or the first missing one
for assignment, spellToken in pairs(assignments) do
local unit = groupRoster[assignment]
if( unit and ( filter == "ALL" or filter == select(2, UnitClass(unit)) ) ) then
local blessingName = PaladinBuffer.blessings[spellToken]
if( IsSpellInRange(blessingName, unit) == 1 ) then
local buffID = 1
local foundBuff
while( true ) do
local buffName, rank, texture, count, debuffType, duration, endTime, isMine, isStealable = UnitAura(unit, buffID, "PLAYER")
if( not buffName ) then break end
if( buffName == blessingName ) then
foundBuff = true
if( not lowestTime or lowestTime >= endTime ) then
lowestTime = endTime
castSpell = blessingName
castSpellOn = unit
end
end
buffID = buffID + 1
end
-- They should have a buff up, but they don't, bad!
if( not foundBuff ) then
castSpell = blessingName
castSpellOn = unit
break
end
end
end
end
if( lowestTime ) then
lowestTime = lowestTime - GetTime()
end
-- Everyone has the buff, so check if the lowest is below the threshold
if( not lowestTime and castSpell and castSpellOn ) then
return "spell", castSpellOn, castSpell
elseif( lowestTime and (lowestTime / 60) < PaladinBuffer.db.profile.singleThreshold ) then
return "spell", castSpellOn, castSpell
else
return nil, nil, nil
end
end
-- Does an initial scan to get us our "base line" of time left on everything
function Buff:ScanGroup()
self:ScanAuras("player")
for i=1, GetNumRaidMembers() do
self:ScanAuras(PaladinBuffer.raidUnits[i])
end
if( GetNumRaidMembers() == 0 ) then
for i=1, GetNumPartyMembers() do
self:ScanAuras(PaladinBuffer.partyUnits[i])
end
end
self:UpdateAuraTimes()
end
-- Scan auras for the time left on the blessing
function Buff:ScanAuras(unit)
local class = self:GetUnitClass(unit)
local guid = UnitGUID(unit)
local name = UnitName(unit)
-- Remove the blessing timers we had for them last update
singleTimes[guid] = nil
singleTypes[guid] = nil
greaterTimes[guid] = nil
greaterTypes[guid] = nil
local id = 1
while( true ) do
local buffName, rank, texture, count, debuffType, duration, endTime, isMine, isStealable = UnitAura(unit, id, "PLAYER")
if( not buffName ) then break end
-- Store the lowest single and greater blessing we cast on them, if it was assigned for them
local spellToken = blessings[buffName]
if( spellToken and ( assignments[name] == spellToken or assignments[class] == spellToken ) ) then
local category = PaladinBuffer.blessingTypes[spellToken]
if( category == "single" and ( not singleTimes[guid] or singleTimes[guid] > endTime ) ) then
singleTimes[guid] = endTime
singleTypes[guid] = spellToken
elseif( category == "greater" and ( not greaterTimes[guid] or greaterTimes[guid] > endTime ) ) then
greaterTimes[guid] = endTime
greaterTypes[guid] = spellToken
end
end
id = id + 1
end
end
function Buff:UNIT_AURA(event, unit)
if( not UnitIsEnemy("player", unit) ) then
self:ScanAuras(unit)
self:UpdateAuraTimes()
end
end
-- Update buff timers on this frame
local function updateTimer(self)
local time = GetTime()
-- Find the lowest single blessing timer (if any)
local lowestTime
for guid, endTime in pairs(singleTimes) do
local unit = guidMap[guid]
if( ( not lowestTime or lowestTime > endTime ) and UnitExists(unit) ) then
if( singleTypes[guid] == assignments[UnitName(unit)] and ( self.filter == "ALL" or self.filter == Buff:GetUnitClass(unit) ) ) then
lowestTime = endTime
end
end
end
if( lowestTime and lowestTime >= time ) then
Buff:FormatTime(self.singleText, lowestTime - time)
else
self.singleText:SetText("")
end
-- Find the lowest greater blessing timer (if any)
local lowestTime
for guid, endTime in pairs(greaterTimes) do
local unit = guidMap[guid]
if( ( not lowestTime or lowestTime > endTime ) and UnitExists(unit) ) then
local classToken = Buff:GetUnitClass(unit)
if( greaterTypes[guid] == assignments[classToken] and ( self.filter == "ALL" or self.filter == classToken ) ) then
lowestTime = endTime
end
end
end
if( lowestTime and lowestTime >= time ) then
Buff:FormatTime(self.greaterText, lowestTime - time)
elseif( ( self.filter ~= "ALL" and not assignments[self.filter] ) or ( self.filter == "ALL" and not lowestTime ) ) then
self.greaterText:SetText(L["None"])
else
self.greaterText:SetText("---")
end
end
-- Update all frame aura timers
function Buff:UpdateAuraTimes()
for _, frame in pairs(classFrames) do
if( frame:IsVisible() ) then
updateTimer(frame)
end
end
if( self.frame and self.frame:IsVisible() ) then
updateTimer(self.frame)
end
end
-- Pop out bar
local function updatePopoutDuration(self)
-- Set buff text
if( UnitIsDeadOrGhost(self.unit) ) then
self.duration:SetText(L["Dead"])
elseif( not UnitIsConnected(self.unit) ) then
self.duration:SetText(L["Offline"])
else
local seconds = Buff:GetBuffTimeLeft(self.unit, self.classToken)
if( seconds and seconds > 0 ) then
Buff:FormatTime(self.duration, seconds)
else
self.duration:SetText(L["None"])
end
end
end
local function popoutPreClick(self)
if( inCombat ) then
return
end
local type, unit, spell = Buff:FindPlayerAssignment(self.unit, self.playerName, self.classToken)
self:SetAttribute("type", type)
self:SetAttribute("unit", unit)
self:SetAttribute("spell", spell)
end
local function popoutOnUpdate(self, elapsed)
self.timeElapsed = self.timeElapsed + elapsed
if( self.timeElapsed < 1 ) then
return
end
self.timeElapsed = 0
-- Update duration
updatePopoutDuration(self)
-- Range check
local assignedToken = assignments[self.playerName] or assignments[self.classToken]
if( not assignedToken ) then
self:SetBackdropColor(PaladinBuffer.db.profile.frame.background.r, PaladinBuffer.db.profile.frame.background.g, PaladinBuffer.db.profile.frame.background.b, 1.0)
return
end
local assignedName = PaladinBuffer.blessings[assignedToken]
local type = PaladinBuffer.blessingTypes[assignedToken]
local secondsLeft = 0
local buffID = 1
while( true ) do
local buffName, rank, texture, count, debuffType, duration, endTime, isMine, isStealable = UnitAura(self.unit, buffID, "PLAYER")
if( not buffName ) then break end
buffID = buffID + 1
if( buffName == assignedName ) then
secondsLeft = (endTime - GetTime()) / 60
break
end
end
-- Because of the texture used to get a solid color, things will appear brighter than they actually are compared to the main class ones
-- so we will reduce the color by around 30% to make it look roughly equal.
local colorReduct = 0.60
if( IsSpellInRange(assignedName, self.unit) ~= 1 or UnitIsDeadOrGhost(self.unit) ) then
self:SetBackdropColor(PaladinBuffer.db.profile.frame.cantRebuff.r * colorReduct, PaladinBuffer.db.profile.frame.cantRebuff.g * colorReduct, PaladinBuffer.db.profile.frame.cantRebuff.b * colorReduct, 1.0)
elseif( ( type == "greater" and secondsLeft < PaladinBuffer.db.profile.greaterThreshold ) or ( type == "single" and secondsLeft < PaladinBuffer.db.profile.singleThreshold ) ) then
self:SetBackdropColor(PaladinBuffer.db.profile.frame.needRebuff.r * colorReduct, PaladinBuffer.db.profile.frame.needRebuff.g * colorReduct, PaladinBuffer.db.profile.frame.needRebuff.b * colorReduct, 1.0)
else
self:SetBackdropColor(PaladinBuffer.db.profile.frame.background.r * colorReduct, PaladinBuffer.db.profile.frame.background.g * colorReduct, PaladinBuffer.db.profile.frame.background.b * colorReduct, 1.0)
end
end
local function popoutOnShow(self)
-- Owner name
local name = (UnitName(self.unit)) or UNKNOWN
local isPet = ""
if( not UnitIsPlayer(self.unit) ) then
isPet = L["[P] "]
end
self.name:SetFormattedText("%s|cff%02x%02x%02x%s|r", isPet, 255 * RAID_CLASS_COLORS[self.classToken].r, 255 * RAID_CLASS_COLORS[self.classToken].g, 255 * RAID_CLASS_COLORS[self.classToken].b, name)
self.playerName = name
updatePopoutDuration(self)
popoutOnUpdate(self, 2)
end
function Buff:CreatePopoutFrame(parent)
if( not self.popoutBackdrop ) then
self.popoutBackdrop = {
bgFile = "Interface\\ChatFrame\\ChatFrameBackground",
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
tile = false,
edgeSize = 0.8,
tileSize = 5,
insets = {left = 0, right = 0, top = 0, bottom = 0}
}
end
local frame = CreateFrame("Button", nil, parent, "SecureActionButtonTemplate,SecureHandlerShowHideTemplate")
frame:SetClampedToScreen(true)
frame:SetFrameStrata("HIGH")
frame:SetToplevel(true)
frame:SetHeight(32)
frame:SetWidth(65)
frame:SetBackdrop(self.popoutBackdrop)
frame:SetBackdropColor(PaladinBuffer.db.profile.frame.background.r, PaladinBuffer.db.profile.frame.background.g, PaladinBuffer.db.profile.frame.background.b, 1.0)
frame:SetBackdropBorderColor(PaladinBuffer.db.profile.frame.border.r, PaladinBuffer.db.profile.frame.border.g, PaladinBuffer.db.profile.frame.border.b, 1.0)
frame:RegisterForClicks("AnyDown")
frame:HookScript("OnShow", popoutOnShow)
frame:SetScript("PreClick", popoutPreClick)
frame:SetScript("OnUpdate", popoutOnUpdate)
frame.timeElapsed = 5
frame:Hide()
frame.name = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
frame.name:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -2)
frame.name:SetWidth(62)
frame.name:SetHeight(11)
frame.name:SetJustifyH("LEFT")
frame.duration = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
frame.duration:SetPoint("TOPLEFT", frame.name, "BOTTOMLEFT", 0, -4)
return frame
end
function Buff:BuildPopoutBar(parent)
for _, frame in pairs(parent.popout) do frame:Hide() end
local onShow, onHide = "self:RegisterAutoHide(0.20) \n self:AddToAutoHide(self:GetFrameRef('parent'))", ""
local newPop = true
local used = 0
-- Create the group thingys
for name, unit in pairs(groupRoster) do
local classToken = self:GetUnitClass(unit)
if( classToken == parent.filter ) then
used = used + 1
local popFrame = parent.popout[used]
if( not popFrame ) then
popFrame = self:CreatePopoutFrame(parent)
table.insert(parent.popout, popFrame)
parent.popout[1]:SetFrameRef("btn" .. used, popFrame)
newPop = true
end
popFrame.unit = unit
popFrame.classToken = classToken
onShow = onShow .. "\n self:GetFrameRef('btn" .. used .. "'):Show() \n self:AddToAutoHide(self:GetFrameRef('btn" .. used .. "'))"
onHide = onHide .. "\n self:GetFrameRef('btn" .. used .. "'):Hide()"
end
end
-- Now setup this secure stuff
if( parent.popout[1] ) then
parent:SetFrameRef("popout", parent.popout[1])
parent.popout[1]:SetFrameRef("parent", parent)
parent.popout[1]:SetAttribute("_onshow", onShow)
parent.popout[1]:SetAttribute("_onhide", onHide)
end
-- Reposition if a new one was added
if( newPop ) then
self:PositionPopoutBar(parent)
end
end
function Buff:PositionPopoutBar(parent)
local inColumn = 0
local lastColumn
for id, popFrame in pairs(parent.popout) do
-- Ugly, going to clean this up later.
-- Position frame to the left
if( PaladinBuffer.db.profile.frame.popDirection == "LEFT" ) then
if( id > 1 ) then
-- Every 4 frames, do a new column
if( inColumn == 4 ) then
popFrame:ClearAllPoints()
popFrame:SetPoint("TOPRIGHT", lastColumn, "BOTTOMRIGHT", 0, -2)
lastColumn = popFrame
inColumn = 0
else
popFrame:ClearAllPoints()
popFrame:SetPoint("TOPRIGHT", parent.popout[id - 1], "TOPLEFT", -2, 0)
end
else
lastColumn = popFrame
popFrame:ClearAllPoints()
popFrame:SetPoint("TOPRIGHT", parent, "TOPLEFT", -2, -1)
end
-- Position it to the right
elseif( PaladinBuffer.db.profile.frame.popDirection == "RIGHT" ) then
if( id > 1 ) then
-- Every 4 frames do a new column
if( inColumn == 4 ) then
popFrame:ClearAllPoints()
popFrame:SetPoint("BOTTOMRIGHT", lastColumn, "TOPRIGHT", 0, 2)
lastColumn = popFrame
inColumn = 0
else
popFrame:ClearAllPoints()
popFrame:SetPoint("TOPLEFT", parent.popout[id - 1], "TOPRIGHT", 2, 0)
end
else
lastColumn = popFrame
popFrame:ClearAllPoints()
popFrame:SetPoint("TOPLEFT", parent, "TOPRIGHT", 2, -2)
end
-- Position it up or down
elseif( PaladinBuffer.db.profile.frame.popDirection == "UP" or PaladinBuffer.db.profile.frame.popDirection == "DOWN" ) then
local point, relativeTo, mainOffset, secondOffset = "BOTTOM", "TOP", 3, 2
if( PaladinBuffer.db.profile.frame.popDirection == "DOWN" ) then
point = "TOP"
relativeTo = "BOTTOM"
mainOffset = -3
secondOffset = -2
end
if( id > 1 ) then
-- Every 2 frames, do a new column
if( inColumn == 2 ) then
popFrame:ClearAllPoints()
popFrame:SetPoint(point, lastColumn, relativeTo, 0, secondOffset)
lastColumn = popFrame
inColumn = 0
else
popFrame:ClearAllPoints()
popFrame:SetPoint("TOPRIGHT", parent.popout[id - 1], "TOPLEFT", -2, 0)
end
else
lastColumn = popFrame
popFrame:ClearAllPoints()
popFrame:SetPoint(point, parent, relativeTo, 0, mainOffset)
end
end
inColumn = inColumn + 1
end
end
-- Update the timer every 10 seconds
local function OnUpdate(self, elapsed)
self.timeElapsed = self.timeElapsed + elapsed
if( self.timeElapsed >= 5 ) then
self.timeElapsed = 0
updateTimer(self)
end
if( not inCombat ) then
self.rangedElapsed = self.rangedElapsed + elapsed
if( self.rangedElapsed >= 0.50 ) then
self.rangedElapsed = 0
Buff:UpdateColorStatus(self, self.filter)
end
end
end
-- Figure out who to buff
local function PreClick(self, mouse)
if( inCombat ) then
return
end
if( mouse == "LeftButton" ) then
local type, unit, spell = Buff:AutoBuffLowestGreater(self.filter)
self:SetAttribute("type1", type)
self:SetAttribute("unit1", unit)
self:SetAttribute("spell1", spell)
elseif( mouse == "RightButton" ) then
local type, unit, spell = Buff:AutoBuffLowestSingle(self.filter)
self:SetAttribute("type2", type)
self:SetAttribute("unit2", unit)
self:SetAttribute("spell2", spell)
end
end
function Buff:CreateSingleFrame(parent)
if( not self.backdrop ) then
self.backdrop = {
bgFile = "Interface\\Tooltips\\UI-Tooltip-Background",
edgeFile = "Interface\\ChatFrame\\ChatFrameBackground",
tile = false,
edgeSize = 0.8,
tileSize = 5,
insets = {left = 0, right = 0, top = 0, bottom = 0}
}
end
local frame = CreateFrame("Button", nil, parent or UIParent, "SecureActionButtonTemplate,SecureHandlerEnterLeaveTemplate")
frame:SetClampedToScreen(true)
frame:SetFrameStrata("LOW")
frame:SetHeight(32)
frame:SetWidth(65)
frame:SetBackdrop(self.backdrop)
frame:SetBackdropColor(PaladinBuffer.db.profile.frame.background.r, PaladinBuffer.db.profile.frame.background.g, PaladinBuffer.db.profile.frame.background.b, 1.0)
frame:SetBackdropBorderColor(PaladinBuffer.db.profile.frame.border.r, PaladinBuffer.db.profile.frame.border.g, PaladinBuffer.db.profile.frame.border.b, 1.0)
frame:SetScript("OnShow", updateTimer)
frame:SetScript("OnUpdate", OnUpdate)
frame:SetPoint("TOPLEFT", UIParent, "TOPLEFT", 450, -100)
frame:RegisterForClicks("AnyDown")
frame.timeElapsed = 0
frame.rangedElapsed = 0
frame:Hide()
frame:SetScript("PreClick", PreClick)
frame.icon = frame:CreateTexture(nil, "ARTWORK")
frame.icon:SetHeight(24)
frame.icon:SetWidth(24)
frame.icon:SetPoint("TOPLEFT", frame, "TOPLEFT", 2, -4)
frame.greaterText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
frame.greaterText:SetFont((GameFontHighlightSmall:GetFont()), 12)
frame.greaterText:SetPoint("TOPLEFT", frame.icon, "TOPRIGHT", 2, 1)
frame.singleText = frame:CreateFontString(nil, "ARTWORK", "GameFontHighlightSmall")
frame.singleText:SetFont((GameFontHighlightSmall:GetFont()), 12)
frame.singleText:SetPoint("TOPLEFT", frame.greaterText, "BOTTOMLEFT", 0, -2)
return frame
end
-- Functions for the parent frame
local function positionParent(self)
self:ClearAllPoints()
if( PaladinBuffer.db.profile.frame.position ) then
local scale = self:GetEffectiveScale()
self:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", PaladinBuffer.db.profile.frame.position.x / scale, PaladinBuffer.db.profile.frame.position.y / scale)
else
self:SetPoint("CENTER", UIParent, "CENTER")
end
end
local function OnShow(self)
updateTimer(self)
positionParent(self)
end
local function OnMouseDown(self)
if( not self.isMoving and IsAltKeyDown() and not PaladinBuffer.db.profile.frame.locked ) then
self.isMoving = true
self:StartMoving()
end
end
local function OnMouseUp(self)
if( self.isMoving ) then
local scale = self:GetEffectiveScale()
self.isMoving = nil
self:StopMovingOrSizing()
PaladinBuffer.db.profile.frame.position = {x = self:GetLeft() * scale, y = self:GetTop() * scale}
end
end
function Buff:SetParentFrame(frame)
frame:SetScript("OnShow", OnShow)
frame:SetScript("OnMouseDown", OnMouseDown)
frame:SetScript("OnMouseUp", OnMouseUp)
frame:SetScale(PaladinBuffer.db.profile.frame.scale)
frame:SetParent(UIParent)
frame:SetMovable(true)
positionParent(frame)
-- Set everything to this as a parent
for _, class in pairs(classFrames) do
if( class.filter ~= frame.filter ) then
class:SetScale(1.0)
class:SetParent(frame)
end
end
self.parent = frame
end
function Buff:ResetParentFrame(frame)
frame:SetScript("OnShow", updateTimer)
frame:SetScript("OnMouseDown", nil)
frame:SetScript("OnMouseUp", nil)
frame:SetMovable(false)
frame:SetParent(self.frame)
end
function Buff:CreateFrame()
if( self.frame ) then
return
end
-- Create it all!
self.frame = self:CreateSingleFrame()
self.frame.filter = "ALL"
self.frame.icon:SetTexture("Interface\\Icons\\Spell_Holy_Aspiration")
self.frame:Show()
-- This frame is supposed to be shown, so it can be the parent
if( PaladinBuffer.db.profile.frame.enabled ) then
self:SetParentFrame(self.frame)
end
end
-- Create the necessary class frames if we have to
function Buff:UpdateClassFrames()