-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathiCooldowns.lua
2399 lines (2354 loc) · 74.1 KB
/
iCooldowns.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
local _, iCD = ...
--options---------
local sounds = iCD.sounds
--end-of-options--
iCD.colors = {
['green'] = '|cff00ff00',
['yellow'] = '',
['red'] = '|cffff1a1a',
}
iCD.backdrop = {
bgFile = 'Interface\\Buttons\\WHITE8x8',
edgeFile = 'Interface\\Buttons\\WHITE8x8',
edgeSize = 1,
insets = {
left = 0,
right = 0,
top = 0,
bottom = 0,
}
}
iCD.barBD = {
bgFile = 'Interface\\Buttons\\WHITE8x8',
edgeFile = 'Interface\\Buttons\\WHITE8x8',
edgeSize = 1,
insets = {
left = 0,
right = 0,
top = 0,
bottom = 0,
}
}
iCD.onCD = {}
iCD.buffs = {}
iCD.PetBuffs = {}
iCD.BuffsI = {}
iCD.PetBuffsI = {}
iCD.BuffsC = {}
iCD.PetBuffsC = {}
iCD.debuffs = {}
iCD.DebuffsI = {}
iCD.DebuffsC = {}
iCD.spells = {}
iCD.extras = {}
iCD.soulbinds = {}
iCD.currentEssences = {major = {0,0}, minor = {}}
local currentAzeritePowers = {}
local buffFrames = {
['row5'] = true,
['buffsI'] = true,
['buffsC'] = true,
}
-- Covenant stuff
local currentCovenant = 0
--APIs to locals
local IsItemInRange,IsSpellInRange, UnitCastingInfo, GetItemCooldown, GetSpellCooldown, GetTime, GetSpellCharges, FindSpellOverrideByID =
IsItemInRange,IsSpellInRange, UnitCastingInfo, GetItemCooldown, GetSpellCooldown, GetTime, GetSpellCharges, FindSpellOverrideByID
--
local function spairs(t, order)
-- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end
-- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys
if order then
table.sort(keys, function(a,b) return order(t, a, b) end)
else
table.sort(keys)
end
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
local function UpdateAzeritePowers()
currentAzeritePowers = nil
currentAzeritePowers = {}
for _, itemLocation in AzeriteUtil.EnumerateEquipedAzeriteEmpoweredItems() do
for _,tier in pairs(C_AzeriteEmpoweredItem.GetAllTierInfo(itemLocation)) do
for _,azeriteID in pairs(tier.azeritePowerIDs) do
if C_AzeriteEmpoweredItem.IsPowerSelected(itemLocation, azeriteID) then
currentAzeritePowers[azeriteID] = true
break
end
end
end
end
end
function iCD:Soulbinds(id)
return iCD.soulbinds[id]
end
function iCD:Essences(essenceID, major, minRank)
return false
--[[
if major then
if minRank then
return iCD.currentEssences.major[1] == essenceID and iCD.currentEssences.major[2] >= minRank
end
return iCD.currentEssences.major[1] == essenceID
else
return minRank and (iCD.currentEssences.minor[essenceID] and iCD.currentEssences.minor[essenceID] >= minRank) or iCD.currentEssences.minor[essenceID]
end
--]]
end
local _auras = {
playerBuffs = {},
targetDebuffs = {},
petBuffs = {},
}
--isSelected = C_AzeriteEmpoweredItem.IsPowerSelected(itemLocation, powerid)
function iCD.UnitBuff(target,buffName,castByPlayer)
if target:lower() == "player" then
for k,v in pairs(_auras.playerBuffs) do
if v[1] == buffName then
if not castByPlayer or (castByPlayer and v[7] == 'player') then
return v[3], v[5], v[6], v[16], v[17], v[18]
end
end
end
elseif target:lower() == "pet" then
for k,v in pairs(_auras.petBuffs) do
if v[1] == buffName then
if not castByPlayer or (castByPlayer and v[7] == 'player') then
return v[3], v[5], v[6], v[16], v[17], v[18]
end
end
end
else
for i = 1, 129 do -- Buffs
local name, icon, count, debuffType, duration, expirationTime, sourceUnit, _, _, spellID,canApplyAura,isBossDebuff, castByPlayer, nameplateShowAll,timeMod,value1,value2,value3 = UnitBuff(target, i, castByPlayer and "player")
if not name then return end
if buffName == name then
return count, duration, expirationTime, value1, value2, value3
end
end
end
return
end
function iCD.UnitDebuff(target, buffName, castByPlayer)
if not target or target:lower() == "target" then
if not iCD.hasTargetDebuffs then
iCD.hasTargetDebuffs = true
for i = 1, 129 do -- Debuffs
local name, icon, count, debuffType, duration, expirationTime, sourceUnit, _, _, spellID,canApplyAura,isBossDebuff, castByPlayer, nameplateShowAll,timeMod,value1,value2,value3 = UnitDebuff((target and target or 'target'), i, castByPlayer and 'player')
if not name then return end
if buffName == name then
return count, duration, expirationTime, value1, value2, value3
end
end
end
for k,v in pairs(_auras.targetDebuffs) do
if v[1] == buffName then
if not castByPlayer or (castByPlayer and v[7] == 'player') then
return v[3], v[5], v[6], v[16], v[17], v[18]
end
end
end
else
for i = 1, 129 do -- Debuffs
local name, icon, count, debuffType, duration, expirationTime, sourceUnit, _, _, spellID,canApplyAura,isBossDebuff, castByPlayer, nameplateShowAll,timeMod,value1,value2,value3 = UnitDebuff((target and target or 'target'), i, castByPlayer and 'player')
if not name then return end
if buffName == name then
return count, duration, expirationTime, value1, value2, value3
end
end
end
return
end
do
local gcdInfo = {
left = 0,
duration = 0,
start = 0,
lastFrame = 0,
}
function iCD:getTimeAfterGCD(t)
local _time = GetTime()
if gcdInfo.lastFrame ~= _time then
local gS, gcdD = GetSpellCooldown(iCD.gcd)
local gCD = gS+gcdD-_time
gcdInfo = {
left = gCD,
duration = gcdD,
start = gS,
lastFrame = _time
}
end
if gcdInfo.start == 0 then
return "%.1f", t
end
if t <= gcdInfo.duration then
return '|cffFF9999(%.0f)', t-gcdInfo.duration
else
t = t - gcdInfo.duration
if t > 5 then
return '|cffFF9999%.0f', t
elseif t <= 0.05 then
return "|cffCCFFFF%.1f", t -- change color?
elseif t < 2 then
return '|cffCCFFFF%.1f', t
else
return '|cfffc2ffc%.1f', t
end
end
end
do
local castInfo = {
left = 0,
lastFrame = 0,
}
function iCD:getTimeAfterCast(t)
local _time = GetTime()
if castInfo.lastFrame ~= _time then
local name, _, _, startTimeMS, endTimeMS = UnitCastingInfo("player")
if endTimeMS then
castInfo.left = endTimeMS/1000 - _time
else
local _format, text = iCD:getTimeAfterGCD(t)
return _format, text
end
end
if castInfo.left > t then -- ready during cast, use gcd
local _format, text = iCD:getTimeAfterGCD(t)
return _format, text
end
t = t - castInfo.left
if t > 5 then
return '|cffFF9999%.0f', t
elseif t <= 0.05 then
return "%.1f", t
elseif t < 2 then
return '|cffCCFFFF%.1f', t
else
return '|cfffc2ffc%.1f', t
end
end
end
end
local addon = CreateFrame('Frame')
addon:SetScript("OnEvent", function(self, event, ...)
self[event](self, ...)
end)
iCD.customSpellTimers = {}
--Health bar
local invertedHPBar = iCD.setups.hpBar.inverted
do
local c = iCD.setups.hpBar
iCD.hpBar = CreateFrame('Statusbar', 'iCD_Health', UIParent)
iCD.hpBar:SetStatusBarTexture('Interface\\Buttons\\WHITE8x8')
iCD.hpBar:SetWidth(c.width)
iCD.hpBar:SetHeight(c.height)
iCD.hpBar:SetStatusBarColor(c.defaultColor[1], c.defaultColor[2], c.defaultColor[3], c.defaultColor[4])
iCD.hpBar:SetMinMaxValues(0,1)
if invertedHPBar then
iCD.hpBar:SetReverseFill(true)
end
iCD.hpBar:SetValue(0)
iCD.hpBar:SetPoint(c.position.from, UIParent, c.position.to, c.position.x,c.position.y)
iCD.hpBar.bg = CreateFrame('frame', nil, iCD.hpBar, "BackdropTemplate")
iCD.hpBar.bg:SetWidth(c.width)
iCD.hpBar.bg:SetHeight(c.height)
iCD.hpBar.bg:SetPoint('CENTER', iCD.hpBar, 'CENTER',0,0)
iCD.hpBar.bg:SetBackdrop(iCD.barBD)
iCD.hpBar.bg:SetBackdropBorderColor(0,0,0,1)
iCD.hpBar.bg:SetBackdropColor(0,0,0,0)
iCD.hpBar.flash = iCD.hpBar:CreateAnimationGroup()
iCD.hpBar.flash:SetLooping('REPEAT')
iCD.hpBar.flash:HookScript('OnPlay', function()
iCD.hpBar.anim = true
end)
iCD.hpBar.flash:HookScript('OnStop', function()
iCD.hpBar.anim = false
end)
iCD.hpBar.fadeOut = iCD.hpBar.flash:CreateAnimation('Alpha')
iCD.hpBar.fadeOut:SetDuration(0.15)
iCD.hpBar.fadeOut:SetFromAlpha(1)
iCD.hpBar.fadeOut:SetToAlpha(0)
iCD.hpBar.fadeOut:SetOrder(1)
iCD.hpBar.fadeIn = iCD.hpBar.flash:CreateAnimation('Alpha')
iCD.hpBar.fadeIn:SetDuration(0.15)
iCD.hpBar.fadeIn:SetFromAlpha(0)
iCD.hpBar.fadeIn:SetToAlpha(1)
iCD.hpBar.fadeIn:SetOrder(2)
end
--EH text
do
local c = iCD.setups.ehText
iCD.EHtext = iCD.hpBar:CreateFontString()
iCD.EHtext:SetFont(iCD.font, c.fontSize, 'OUTLINE')
iCD.EHtext:SetPoint(c.position.from, iCD.hpBar, c.position.to, c.position.x,c.position.y)
iCD.EHtext:SetText('')
end
local function setupFrame(f,n)
local c = iCD.setups[n]
if not c then print("iCD: ERROR - no setup found for :", n) return end
f:ClearAllPoints()
f:SetPoint(c.position.from, iCD.hpBar, c.position.to, c.position.x, c.position.y)
end
iCD.positions = {
row1 = {default = function(f) setupFrame(f, "row1") end, changed = false},
row2 = {default = function(f) setupFrame(f, "row2") end, changed = false},
row3 = {default = function(f) setupFrame(f, "row3") end, changed = false},
row4 = {default = function(f) setupFrame(f, "row4") end, changed = false},
row5 = {default = function(f) setupFrame(f, "row5") end, changed = false},
buffsI = {default = function(f) setupFrame(f, "buffsI") end, changed = false},
buffsC = {default = function(f) setupFrame(f, "buffsC") end, changed = false},
}
--row1
iCD.row1 = CreateFrame('frame', nil, UIParent)
iCD.row1:SetSize(20,20)
iCD.positions.row1.default(iCD.row1)
--row2
iCD.row2 = CreateFrame('frame', nil, UIParent)
iCD.row2:SetSize(20,20)
iCD.positions.row2.default(iCD.row2)
-- Row 3
iCD.row3 = CreateFrame('frame', nil, UIParent)
iCD.row3:SetSize(20,20)
iCD.positions.row3.default(iCD.row3)
-- Row 4 (only on cd)
iCD.row4 = CreateFrame('frame', nil, UIParent)
iCD.row4:SetSize(20,20)
iCD.positions.row4.default(iCD.row4)
-- Row 5 Big Buffs
iCD.row5 = CreateFrame('frame', nil, UIParent)
iCD.row5:SetSize(20,20)
iCD.positions.row5.default(iCD.row5)
-- Buffs (Important)
iCD.buffsI = CreateFrame('frame', nil, UIParent)
iCD.buffsI:SetSize(20,20)
iCD.positions.buffsI.default(iCD.buffsI)
-- Buffs (center)
iCD.buffsC = CreateFrame('frame', nil, UIParent)
iCD.buffsC:SetSize(20,20)
iCD.positions.buffsC.default(iCD.buffsC)
-- GCD
do
local c = iCD.setups.gcd
iCD.GCD = CreateFrame('Statusbar', nil, UIParent)
iCD.GCD:SetStatusBarTexture('Interface\\Buttons\\WHITE8x8')
iCD.GCD:SetWidth(c.width)
iCD.GCD:SetHeight(c.height)
iCD.GCD:SetStatusBarColor(c.defaultColor[1], c.defaultColor[2], c.defaultColor[3], c.defaultColor[4])
iCD.GCD:SetMinMaxValues(0,1)
iCD.GCD:SetValue(0)
iCD.GCD:SetPoint(c.position.from, iCD.hpBar, c.position.to, c.position.x, c.position.y)
iCD.GCD.bg = CreateFrame('frame', nil, iCD.GCD, "BackdropTemplate")
iCD.GCD.bg:SetWidth(c.width)
iCD.GCD.bg:SetHeight(c.height)
iCD.GCD.bg:SetPoint('CENTER', iCD.GCD, 'CENTER',0,0)
iCD.GCD.bg:SetBackdrop(iCD.barBD)
iCD.GCD.bg:SetBackdropBorderColor(0,0,0,1)
iCD.GCD.bg:SetBackdropColor(0,0,0,0)
end
-- Anchor for texts above health bar
iCD.textAnchor = CreateFrame('frame', nil, UIParent)
iCD.textAnchor:SetSize(40,20)
iCD.textAnchor:SetPoint('BOTTOM', iCD.hpBar, 'TOP',0,2)
-- Power Text
do
local c = iCD.setups.power
iCD.powerText = iCD.GCD:CreateFontString('iCD_powerText')
iCD.powerText:SetFont(iCD.font, c.fontSize, 'OUTLINE')
iCD.powerText:SetJustifyH(c.justifyH)
iCD.powerText:SetPoint(c.position.from, UIParent, c.position.to, c.position.x, c.position.y)
iCD.powerText:SetText('')
end
-- Out of range warning
do
local c = iCD.setups.outOfRange
iCD.outOfRangeFrame = CreateFrame('frame', nil, UIParent)
iCD.outOfRange = iCD.outOfRangeFrame:CreateFontString('iCD_outOfRange')
iCD.outOfRange:SetFont(iCD.font, c.fontSize, 'OUTLINE')
iCD.outOfRange:SetJustifyH(c.justifyH)
iCD.outOfRange:SetPoint(c.position.from, UIParent, c.position.to, c.position.x, c.position.y)
iCD.outOfRange:SetText(c.text)
iCD.outOfRange:SetTextColor(1,0,0)
iCD.outOfRange:Hide()
iCD.outOfRange.color = 1 -- red
iCD.outOfRange.flash = iCD.outOfRange:CreateAnimationGroup()
iCD.outOfRange.flash:SetLooping('REPEAT')
iCD.outOfRange.flash:HookScript('OnPlay', function()
iCD.outOfRange.anim = true
--iCD.outOfRange:Show()
end)
iCD.outOfRange.flash:HookScript('OnStop', function()
iCD.outOfRange.anim = false
-- iCD.outOfRange:Hide()
end)
iCD.outOfRange.fadeOut = iCD.outOfRange.flash:CreateAnimation('Alpha')
iCD.outOfRange.fadeOut:SetDuration(.25)
iCD.outOfRange.fadeOut:SetFromAlpha(1)
iCD.outOfRange.fadeOut:SetToAlpha(0)
iCD.outOfRange.fadeOut:SetOrder(1)
iCD.outOfRange.fadeIn = iCD.outOfRange.flash:CreateAnimation('Alpha')
iCD.outOfRange.fadeIn:SetDuration(.25)
iCD.outOfRange.fadeIn:SetFromAlpha(0)
iCD.outOfRange.fadeIn:SetToAlpha(1)
iCD.outOfRange.fadeIn:SetOrder(2)
end
iCD.frames = {
row1 = {},
row2 = {},
row3 = {},
row4 = {},
row5 = {},
buffsI = {},
buffsC = {},
}
iCD.textFrames = {}
local icdRangeCheckTimer = 0
function iCD:checkRange(force)
local t = GetTime()
if force or (t > icdRangeCheckTimer + 0.1) then
icdRangeCheckTimer = t
if UnitExists('target') then
local rangeID, rangeColor, range, lastRange = iCD:GetRange('target')
if rangeID == 3 then
if iCD.outOfRange.anim then
iCD.outOfRange.flash:Stop()
iCD.outOfRange:Hide()
end
elseif not iCD.outOfRange.anim then
iCD.outOfRange.flash:Play()
iCD.outOfRange:Show()
end
if iCD.outOfRange.currentColor ~= rangeID then
iCD.outOfRange:SetTextColor(rangeColor.r, rangeColor.g, rangeColor.b)
iCD.outOfRange.currentColor = rangeID
end
if iCD.outOfRange.currentRange ~= range then
iCD.outOfRange.currentRange = range
iCD.outOfRange:SetText(string.format("%d-%d\n%s", range, lastRange, iCD.setups.outOfRange.text))
end
elseif iCD.outOfRange.anim then
iCD.outOfRange.flash:Stop()
iCD.outOfRange:Hide()
end
end
end
function iCD:resetGlows()
if iCD.glowEffects then
for spellID, v in pairs(iCD.glowEffects) do -- Stop animations
for i = 1, #v do
if iCD.frames[iCD.glowEffects[spellID][i].row][iCD.glowEffects[spellID][i].id].anim then
iCD.frames[iCD.glowEffects[spellID][i].row][iCD.glowEffects[spellID][i].id].flash:Stop()
iCD.frames[iCD.glowEffects[spellID][i].row][iCD.glowEffects[spellID][i].id]:SetAlpha(1)
end
end
end
end
iCD.glowEffects = {}
iCD.glowSoundEffects = {}
end
function iCD:createTextString(id)
if not iCD.textFrames[id] then
iCD.textFrames[id] = iCD.textAnchor:CreateFontString()
iCD.textFrames[id]:SetFont(iCD.font, 12, 'OUTLINE')
iCD.textFrames[id]:SetWidth(25)
if id == 1 then
iCD.textFrames[id]:SetPoint('LEFT', iCD.textAnchor, 'LEFT', 0,0)
else
iCD.textFrames[id]:SetPoint('LEFT', iCD.textFrames[id-1], 'RIGHT', 0,0)
end
end
end
local function getGeneralCooldown(id)
if not id then -- gcd
local start, cooldown = GetSpellCooldown(61304)
return start, cooldown
end
if id < 0 then
local start, cooldown = GetItemCooldown(-id)
return start, cooldown, nil, nil, true
else
local charges,maxCharges,chargeStart,chargeDuration = GetSpellCharges(id)
if charges then
return chargeStart, chargeDuration, charges, maxCharges
end
local start, cooldown = GetSpellCooldown(id)
return start, cooldown
end
end
do
function iCD:updateFrame(id, row, frame, gcdInfo)
--local data = iCD.frames[row][id].data
if buffFrames[row] then
if frame.data.customText then
local text, f = frame.data.customText(frame.data, gcdInfo)
if f then
frame.cooldownText:SetFormattedText(f, text)
else
frame.cooldownText:SetText(text)
end
else
local text = frame.data.endTime-GetTime()
if text > 60 then
local s = (math.floor(text * 10 + 0.5) / 10)%60
local m = math.floor(text/60)
frame.cooldownText:SetFormattedText('%d:%.2d', m,s)
elseif text > 5 then
frame.cooldownText:SetFormattedText('%.0f', text)
elseif text > 0 then
frame.cooldownText:SetFormattedText('|cffff1a1a%.1f', text)
else
frame.cooldownText:SetText('')
end
if text <= 3 and text >= 0 then
if not frame.anim then
frame:SetAlpha(1)
frame.flash:Play()
end
elseif frame.anim then
frame:SetAlpha(1)
frame.flash:Stop()
end
end
else
local cost = false
local range = false
if frame.data.customCost then
if frame.data.customCost(frame.data, gcdInfo) then
cost = true
end
elseif frame.data.cost then
if select(2, IsUsableSpell(frame.data.spellName)) then
cost = true
end
end
if frame.data.customRange then
if not frame.data.customRange(frame.data, gcdInfo) then
range = true
end
elseif frame.data.range then
local rangeSpell = frame.data.customRangeSpell or frame.data.spellName
if frame.data.customRangeSpell and tonumber(frame.data.customRangeSpell) then
if not IsItemInRange(frame.data.customRangeSpell*-1, 'target') then
range = true
end
else
if IsSpellInRange(rangeSpell, 'target') == 0 then
range = true
end
end
end
if frame.data.AM and frame.data.AM(frame.data, gcdInfo) then
if frame.data.unMod ~= 'am' then
frame.tex:SetVertexColor(1,0,1,1)
frame.data.unMod = 'am'
end
elseif range then
if frame.data.unMod ~= 'range' then
frame.tex:SetVertexColor(1,0,0,1)
frame.data.unMod = 'range'
end
elseif cost then
if frame.data.unMod ~= 'cost' then
frame.tex:SetVertexColor(0.5,0.5,1,1)
frame.data.unMod = 'cost'
end
else
if frame.data.unMod ~= 'none' then
frame.tex:SetVertexColor(1,1,1,1)
frame.data.unMod = 'none'
end
end
local text = 0
if frame.data.customText then
text, f = frame.data.customText(frame.data, gcdInfo)
if f then
frame.cooldownText:SetFormattedText(f, text)
else
frame.cooldownText:SetText(text)
end
else
local gS, gcdD = getGeneralCooldown()
local gCD = gS+gcdD-GetTime()
local s, cd = 0,0
local readyDuringCast = false
if frame.data.customDuration then
text = frame.data.customDuration - GetTime()
elseif frame.data.showTimeAfterGCD then
local s,cd,c,m = getGeneralCooldown(frame.data.allowOverride and FindSpellOverrideByID(frame.data.usedBy) or frame.data.usedBy)
if c and c == m then
s = 0
end
local cdD = s+cd-GetTime()
if s > 0 then
if gcdD ~= cd then
if gCD > 0 then
text = cdD - gCD
else
text = cdD
end
end
end
elseif frame.data.showTimeAfterCast then
local s,cd,c,m = getGeneralCooldown(frame.data.allowOverride and FindSpellOverrideByID(frame.data.usedBy) or frame.data.usedBy)
if c and c == m then
s = 0
end
local cdD = s+cd-GetTime()
if s > 0 then
if gcdD ~= cd then
local name, _, _, startTimeMS, endTimeMS = UnitCastingInfo("player")
if endTimeMS then
local castLeft = endTimeMS/1000 - GetTime()
if castLeft < cdD then
if gCD > 0 and gCD > castLeft then
text = cdD - gCD
else
text = cdD-castLeft
end
else
if gCD > 0 then
text = cdD - gCD
else
text = cdD
end
readyDuringCast = true
end
elseif gCD > 0 then
text = cdD - gCD
else
text = cdD
end
end
end
else
local s,cd,c,m = getGeneralCooldown(frame.data.allowOverride and FindSpellOverrideByID(frame.data.usedBy) or frame.data.usedBy)
if c and c == m then
s = 0
end
local cdD = s+cd-GetTime()
if s > 0 then
if frame.data.ignoreGCD or frame.data.item then
text = cdD
else
if gcdD ~= cd then
text = cdD
end
end
end
end
if row == 'row2' then
if text > 0 then
local fade = true
if frame.data.stack then
local c,m,sd,d = GetSpellCharges(frame.data.usedBy)
if c > 0 then
fade = false
end
end
if fade then
frame:SetAlpha(.35)
else
frame:SetAlpha(1)
end
elseif text == 0 then
frame:SetAlpha(1)
frame.onCD = false
end
end
if (frame.data.showTimeAfterGCD and gcdD > 0) or (frame.data.showTimeAfterCast and text > 0) then
if text > 60 then
local s = (math.floor(text * 10 + 0.5) / 10)%60
local m = math.floor(text/60)
frame.cooldownText:SetFormattedText('%d:%.2d', m,s)
elseif text > 5 then
if readyDuringCast then
frame.cooldownText:SetFormattedText('|cffFF9999(%.0f)', text)
else
frame.cooldownText:SetFormattedText('|cffFF9999%.0f', text)
end
elseif text > 0 then
if text <= 0.05 then
frame.cooldownText:SetText('')
elseif text < 2 then
if readyDuringCast then
frame.cooldownText:SetFormattedText('|cffCCFFFF(%.1f)', text)
else
frame.cooldownText:SetFormattedText('|cffCCFFFF%.1f', text)
end
else
if readyDuringCast then
frame.cooldownText:SetFormattedText('|cfffc2ffc(%.1f)', text)
else
frame.cooldownText:SetFormattedText('|cfffc2ffc%.1f', text)
end
end
else
if row == 'row4' then
iCD:updateCDs()
else
frame.cooldownText:SetText('')
end
end
else
if text > 60 then
local s = (math.floor(text * 10 + 0.5) / 10)%60
local m = math.floor(text/60)
frame.cooldownText:SetFormattedText('%d:%.2d', m,s)
elseif text > 5 then
frame.cooldownText:SetFormattedText('%.0f', text)
elseif text > 0 then
if row == 'row1' and ((gCD + 0.1 > text) or (gcdD == 0 and text < 0.3))then
frame.cooldownText:SetFormattedText('|cff00ff00%.1f', text)
else
frame.cooldownText:SetFormattedText('|cffff1a1a%.1f', text)
end
else
if row == 'row4' then
iCD:updateCDs()
else
frame.cooldownText:SetText('')
end
end
end
end
end
if frame.data.stackFunc then
local txt, txtFormat = frame.data.stackFunc(frame.data, gcdInfo)
if txtFormat then
frame.stackText:SetFormattedText(txtFormat, txt)
else
frame.stackText:SetText(txt)
end
elseif frame.data.stack then
if type(frame.data.stack) == "boolean" then
local s,cd,c,m = getGeneralCooldown(frame.data.allowOverride and FindSpellOverrideByID(frame.data.usedBy) or frame.data.usedBy)
if m and m > 1 then
frame.stackText:SetText(c)
else
frame.stackText:SetText("")
end
else
frame.stackText:SetText(frame.data.stack)
end
end
end
end
function iCD:CreateNewFrame(id, row)
if iCD.frames[row][id] then
iCD.frames[row][id].cooldownText:SetText('')
iCD.frames[row][id].stackText:SetText('')
iCD.frames[row][id]:SetAlpha(1)
return
end
local c = iCD.setups[row]
iCD.frames[row][id] = CreateFrame('frame',nil,iCD[row], "BackdropTemplate")
iCD.frames[row][id]:SetSize(c.size,c.size)
--Backdrop
iCD.frames[row][id]:SetBackdrop(iCD.backdrop)
iCD.frames[row][id]:SetBackdropColor(0.2,0.2,0.2,0.5)
iCD.frames[row][id]:SetBackdropBorderColor(0,0,0,1)
iCD.frames[row][id]:SetFrameStrata('MEDIUM')
if c.horizontal then
if id == 1 then
iCD.frames[row][id]:SetPoint('LEFT', iCD[row] , 'LEFT', 0, 0)
else
iCD.frames[row][id]:SetPoint('LEFT', iCD.frames[row][id-1], 'RIGHT', 1, 0)
end
else
if id == 1 then
iCD.frames[row][id]:SetPoint('BOTTOM', iCD[row] , 'BOTTOM', 0, 0)
else
iCD.frames[row][id]:SetPoint('BOTTOM', iCD.frames[row][id-1], 'TOP', 0, 1)
end
end
--Icon
iCD.frames[row][id].tex = iCD.frames[row][id]:CreateTexture()
iCD.frames[row][id].tex:SetAllPoints(iCD.frames[row][id])
--Cooldown
iCD.frames[row][id].cooldownText = iCD.frames[row][id]:CreateFontString()
iCD.frames[row][id].cooldownText:SetIgnoreParentAlpha(true)
if row == 'row5' then
iCD.frames[row][id].cooldownText:SetFont(iCD.font, iCD.fontSize+4, 'OUTLINE')
iCD.frames[row][id].cooldownText:SetPoint('CENTER', iCD.frames[row][id], 'CENTER', 0,0)
else
iCD.frames[row][id].cooldownText:SetFont(iCD.font, iCD.fontSize, 'OUTLINE')
iCD.frames[row][id].cooldownText:SetPoint('BOTTOM', iCD.frames[row][id], 'BOTTOM', 0,0)
end
iCD.frames[row][id].cooldownText:SetTextColor(1,1,0.1,1)
--Stack
iCD.frames[row][id].stackText = iCD.frames[row][id]:CreateFontString()
iCD.frames[row][id].stackText:SetFont(iCD.font, iCD.stackFontSize, 'OUTLINE')
if row == 'row4' then
iCD.frames[row][id].stackText:SetPoint('TOPRIGHT', iCD.frames[row][id], 'TOPRIGHT', 0,0)
elseif row == 'buffsI' or row == 'buffsC' then
iCD.frames[row][id].stackText:SetPoint('RIGHT', iCD.frames[row][id], 'TOPRIGHT', 0,0)
else
iCD.frames[row][id].stackText:SetPoint('CENTER', iCD.frames[row][id], 'TOPRIGHT', 0,0)
end
iCD.frames[row][id].stackText:SetTextColor(1,1,1,1)
--Flash (glow)
iCD.frames[row][id].flash = iCD.frames[row][id]:CreateAnimationGroup()
iCD.frames[row][id].flash:SetLooping('REPEAT')
iCD.frames[row][id].flash:HookScript('OnPlay', function()
iCD.frames[row][id].anim = true
end)
iCD.frames[row][id].flash:HookScript('OnStop', function()
iCD.frames[row][id].anim = false
end)
iCD.frames[row][id].fadeOut = iCD.frames[row][id].flash:CreateAnimation('Alpha')
iCD.frames[row][id].fadeOut:SetDuration(0.25)
iCD.frames[row][id].fadeOut:SetFromAlpha(1)
iCD.frames[row][id].fadeOut:SetToAlpha(0)
iCD.frames[row][id].fadeOut:SetOrder(1)
iCD.frames[row][id].fadeIn = iCD.frames[row][id].flash:CreateAnimation('Alpha')
iCD.frames[row][id].fadeIn:SetDuration(0.25)
iCD.frames[row][id].fadeIn:SetFromAlpha(0)
iCD.frames[row][id].fadeIn:SetToAlpha(1)
iCD.frames[row][id].fadeIn:SetOrder(2)
end
function iCD:updateCDs()
local temp = {}
local tempExtras
for k,v in pairs(iCD.extras) do
local dura = v.customDuration - GetTime()
if dura > 0 then
temp[k] = v
temp[k].duration = dura
end
end
for k,v in pairs(iCD.onCD) do
--local spellIDToUse = k
if v.allowOverride then
k = FindSpellOverrideByID(k)
end
local s, cd
local s,cd,c,m,isItem = getGeneralCooldown(k)
if c and c == m then
s = 0
end
--[[
if v.charges then
local c,m,sd,d = GetSpellCharges(k)
if c == m then
s = 0
cd = d
else
s = sd
cd = d
end
elseif k < 0 then
s, cd = GetItemCooldown(-k)
isItem = true
else
s,cd = GetSpellCooldown(k)
end
--]]
local cdD = s+cd-GetTime()
local dura = 0
if s > 0 then
if isItem or v.ignoreGCD then
if isItem and v.ignoreGCD then
local _,gcdD = getGeneralCooldown()
if s > 0 and cd == gcdD then
dura = 0
else
dura = cdD
end
else
dura = cdD
end
else
local gS, gcdD = getGeneralCooldown()
local gCD = gS+gcdD-GetTime()
if (gCD + 0.05) < cdD then
dura = cdD
end
end
end
if dura > 0 then
v.duration = dura
temp[k] = v
end
end
local id = 1
for k,v in spairs(temp, function(t,a,b) return t[b].duration > t[a].duration end) do
iCD:CreateNewFrame(id, 'row4')
iCD.frames.row4[id].data = {}
iCD.frames.row4[id].data.usedBy = k
--allowOverride
--iCD.frames.row4[id].data.spellName = GetSpellInfo(k)
if v.customDuration then
iCD.frames.row4[id].data.customDuration = v.customDuration
end
if k < 0 then
--iCD.frames.row4[id].data.item = true
local itemName,_,_,_,_,_,_,_,_,icon = GetItemInfo(-k)
iCD.frames.row4[id].data.spellName = itemName
iCD.frames.row4[id].tex:SetTexture(v.icon or icon)
else
iCD.frames.row4[id].data.spellName = GetSpellInfo(k)
iCD.frames.row4[id].tex:SetTexture(v.icon or GetSpellTexture(k))
end
if v.stackFunc then
iCD.frames.row4[id].data.stackFunc = v.stackFunc
elseif v.stack then
iCD.frames.row4[id].data.stack = v.stack
end
if v.customText then
iCD.frames.row4[id].data.customText = v.customText
end
if v.ignoreGCD then
iCD.frames.row4[id].data.ignoreGCD = true
end
if v.charges then
iCD.frames.row4[id].data.charges = true
end
if v.showTimeAfterGCD then
iCD.frames.row4[id].data.showTimeAfterGCD = true
end
if v.showTimeAfterCast then
iCD.frames.row4[id].data.showTimeAfterCast = true
end
iCD.frames.row4[id].tex:SetVertexColor(1,1,1,1)
iCD.frames.row4[id].data.unMod = 'none'
iCD.frames.row4[id]:Show()
id = id + 1
end
iCD.row4:SetWidth((id-1)*(iCD.setups.row4.size+1)-1)
for i = id, #iCD.frames.row4 do
iCD.frames.row4[i].data = {}
iCD.frames.row4[i]:Hide()
end
temp = nil
end
function iCD:updateOnCD()
if not iCD.class or not iCD.specID then
return
end
local temp = {}
for k,v in pairs(iCD.general.row4) do
if not v.showFunc or (v.showFunc and v.showFunc()) and (not v.talent or iCD:IsTalentActive(v.talent)) and (not v.level or v.level <= iCD.level) then
if v.itemReq or k < 0 then
if type(v.itemReq) == 'table' then
for k,_ in pairs(v.itemReq) do
if IsEquippedItem(k) then
temp[k] = v
end
end
elseif k < 0 then
if v.utility or IsEquippedItem(-k) then
temp[k] = v
end
else
if IsEquippedItem(v.itemReq) then
temp[k] = v
end
end
else
temp[k] = v
end
end
end
for k,v in pairs(iCD.spellData.spec.row4) do
if (not v.showFunc or (v.showFunc and v.showFunc())) and (not v.talent or iCD:IsTalentActive(v.talent)) then
if v.itemReq or k < 0 then
if type(v.itemReq) == 'table' then
for k,_ in pairs(v.itemReq) do
if IsEquippedItem(k) then
temp[k] = v
end
end
elseif k < 0 then
if v.utility or IsEquippedItem(-k) then
temp[k] = v
end
else
if IsEquippedItem(v.itemReq) then
temp[k] = v
end
end
else