-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMagicRunes.lua
More file actions
1229 lines (1124 loc) · 40.2 KB
/
MagicRunes.lua
File metadata and controls
1229 lines (1124 loc) · 40.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--[[
**********************************************************************
MagicRunes - Death Knight rune cooldown displaye
**********************************************************************
This file is part of Magic Runes, a World of Warcraft Addon
Magic Runes is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Magic Runes is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with Magic Runes. If not, see <http://www.gnu.org/licenses/>.
**********************************************************************
]]
if select(2, UnitClass("player")) ~= "DEATHKNIGHT" then
return
end
MagicRunes = LibStub("AceAddon-3.0"):NewAddon("Magic Runes", "AceEvent-3.0", "FixedLibBars-1.0",
"AceTimer-3.0", "AceConsole-3.0", "LibMagicUtil-1.0")
local mod = MagicRunes
local L = LibStub("AceLocale-3.0"):GetLocale("MagicRunes", false)
-- Silently fail embedding if it doesn't exist
local LibStub = LibStub
local LDBIcon = LibStub("LibDBIcon-1.0", true)
local LDB = LibStub("LibDataBroker-1.1", true)
local AceGUIWidgetLSMlists = AceGUIWidgetLSMlists
local Logger = LibStub("LibLogger-1.0", true)
local C = LibStub("AceConfigDialog-3.0")
local media = LibStub("LibSharedMedia-3.0")
local UnitExists = UnitExists
local UnitAura = UnitAura
local UnitPower = UnitPower
local UnitPowerMax = UnitPowerMax
local GetRuneCooldown = GetRuneCooldown
local GetSpecialization = GetSpecialization or C_SpecializationInfo.GetSpecialization
local GetRuneType = GetRuneType or function() return GetSpecialization() end
local GetTime = GetTime
local InCombatLockdown = InCombatLockdown
local PlaySoundFile = PlaySoundFile
local GetSpellInfo = function(id) return MagicRunes.GetSpellInfo(id) end
local issecretvalue = issecretvalue or function() return false end
local fmt = string.format
local max = max
local cos = math.cos
local min = min
local pairs = pairs
local ipairs = ipairs
local select = select
local sort = sort
local tostring = tostring
local type = type
local unpack = unpack
local TWOPI = math.pi * 2
local ceil = math.ceil
local gcd = 1.5
local playerInCombat = InCombatLockdown()
local idleAlphaLevel
local addonEnabled = false
local db, isInGroup
local bars, hiddenBars = nil, nil
local runebars = {}
if Logger then
Logger:Embed(mod)
else
-- Enable info messages
mod.info = function(self, ...)
mod:Print(fmt(...))
end
mod.error = mod.info
mod.warn = mod.info
-- But disable debugging
mod.debug = function(self, ...)
end
mod.trace = mod.debug
mod.spam = mod.debug
end
local options
local runeInfo = {
{ "Blood", "B" },
{ "Frost", "F" },
{ "Unholy", "U" };
{ "Death", "D" },
}
local runeSets = {
["Blizzard Improved"] = {
"Interface\\AddOns\\MagicRunes\\Textures\\BlizzardBlood.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\BlizzardFrost.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\BlizzardUnholy.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\BlizzardDeath.tga",
},
["Blizzard"] = {
"Interface\\PlayerFrame\\UI-PlayerFrame-Deathknight-Blood",
"Interface\\PlayerFrame\\UI-PlayerFrame-Deathknight-Frost",
"Interface\\PlayerFrame\\UI-PlayerFrame-Deathknight-Unholy";
"Interface\\PlayerFrame\\UI-PlayerFrame-Deathknight-Death"
},
Japanese = {
"Interface\\AddOns\\MagicRunes\\Textures\\JapaneseBlood.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\JapaneseFrost.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\JapaneseUnholy.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\JapaneseDeath.tga",
},
["DKI/Vixen"] = {
"Interface\\AddOns\\MagicRunes\\Textures\\VixenBlood.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\VixenFrost.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\VixenUnholy.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\VixenDeath.tga",
},
["Gloss Orb by Camalus"] = {
"Interface\\AddOns\\MagicRunes\\Textures\\GlossOrbBlood.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\GlossOrbFrost.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\GlossOrbUnholy.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\GlossOrbDeath.tga",
},
["Punished by Lichborne"] = {
"Interface\\AddOns\\MagicRunes\\Textures\\PunishedBlood.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\PunishedFrost.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\PunishedUnholy.tga",
"Interface\\AddOns\\MagicRunes\\Textures\\PunishedDeath.tga",
},
}
mod.spellCache = {}
function mod:GetRuneIcon(icon, set)
if not set or not runeSets[set] then
set = db.runeSet or "Blizzard"
end
return runeSets[set][icon]
end
do
local sets
function mod:GetRuneSetList()
if not sets then
sets = {}
for runeSet in pairs(runeSets) do
sets[runeSet] = runeSet
end
end
return sets
end
end
local defaults = {
profile = {
displayType = mod.RUNE_DISPLAY,
flashMode = 2,
runeSet = "Blizzard",
hideBlizzardFrame = true,
flashTimes = 2,
readyFlash = true,
readyFlashDuration = 0.5,
sound = "None",
soundOccasion = 1, -- Never
font = "Friz Quadrata TT",
fontsize = 14,
hideAnchor = true,
iconScale = 1.0,
length = 250,
secondsOnly = false,
orientation = 1,
scale = 1.0,
showIcon = true,
showLabel = true,
showTimer = true,
alphaOOC = 1.0,
alphaReady = 1.0,
alphaGCD = 1.0,
alphaActive = 0.5,
fadeAlpha = true,
sortMethod = 1,
spacing = 1,
texture = "Minimalist",
bgtexture = "Minimalist",
timerOnIcon = false,
thickness = 25,
showSpark = true,
minimapIcon = {}
}
}
local function CacheSpellInfo(name, id, id2)
local localizedName, _, icon = GetSpellInfo(id)
if not localizedName then
id = id2
localizedName, _, icon = GetSpellInfo(id)
end
mod.spellCache[name] = { name = localizedName, icon = icon, id = id, shortname = name }
mod.spellCache[localizedName] = mod.spellCache[name]
end
function mod:GetRuneInfo(runeid, set)
if not runeid or runeid < 1 or runeid > 6 then
return
end
local type = GetRuneType(runeid)
local info = runeInfo[type] or runeInfo[1] -- seems sometimes the rune id is not correct. hmm
local icon = mod:GetRuneIcon(type, set)
if mod._vertical then
return info[2], icon, type, db.colors[info[1]]
else
return L[info[1]], icon, type, db.colors[info[1]]
end
end
function mod:OnInitialize()
mod:RegisterEvent("PLAYER_ENTERING_WORLD", "HandleBlizzardRuneFrameEvent")
-- Register some sound effects since they normally aren't available
media:Register("sound", "Drop", [[Sound\Interface\DropOnGround.wav]])
media:Register("sound", "Error", [[Sound\Interface\Error.wav]])
media:Register("sound", "Magic Click", [[Sound\Interface\MagicClick.wav]])
media:Register("sound", "Ping", [[Sound\Interface\MapPing.wav]])
media:Register("sound", "Socket Clunk", [[Sound\Interface\JewelcraftingFinalize.wav]])
media:Register("sound", "Whisper Ping", [[Sound\Interface\iTellMessage.wav]])
media:Register("sound", "Whisper", [[Sound\Interface\igTextPopupPing02.wav]])
self.db = LibStub("AceDB-3.0"):New("MagicRunesDB", defaults, "Default")
self.db.RegisterCallback(self, "OnProfileChanged", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileCopied", "OnProfileChanged")
self.db.RegisterCallback(self, "OnProfileReset", "OnProfileChanged")
MagicRunesDB.point = nil
MagicRunesDB.presets = nil
db = self.db.profile
idleAlphaLevel = playerInCombat and db.alphaReady or db.alphaOOC
mod._readyFlash2 = db.readyFlashDuration / 2
mod:UpdateLocalVariables()
-- spells
CacheSpellInfo("BLOODPLAGUE", 59879, 55078)
CacheSpellInfo("FROSTFEVER", 59921, 55095)
-- bar types
mod.RUNIC_BAR = 1
mod.RUNE_BAR = 2
mod.DOT_BAR = 3
mod.BUFF_BAR = 4
-- upgrade
if db.width then
db.thickness = db.height
db.length = db.width
db.width = nil
db.height = nil
end
-- initial rune status
mod:SetDefaultColors()
if LDB then
self.ldb = LDB:NewDataObject("Magic Runes",
{
type = "launcher",
label = L["Magic Runes"],
icon = "Interface\\PlayerFrame\\UI-PlayerFrame-Deathknight-Death",
tooltiptext = L["|cffffff00Left click|r to open the configuration screen.\n|cffffff00Right click|r to toggle the Magic Target window lock."],
OnClick = function(clickedframe, button)
if button == "LeftButton" then
mod:ToggleConfigDialog()
elseif button == "RightButton" then
mod:ToggleLocked()
end
end,
})
if LDBIcon then
LDBIcon:Register("MagicRunes", self.ldb, db.minimapIcon)
end
end
mod:SetupOptions()
end
mod.sortFunctions = {
function(a, b)
-- BarId
-- Prioritize non-secret values (rune bars) over secret values (runic bar)
local aSecret = issecretvalue(a.value)
local bSecret = issecretvalue(b.value)
if aSecret ~= bSecret then
return bSecret -- non-secret (false) comes before secret (true)
end
if db.reverseSort then
return (a.sortValue or 100) > (b.sortValue or 100)
else
return (a.sortValue or 100) < (b.sortValue or 100)
end
end,
function(a, b)
-- Rune, Time
-- Prioritize non-secret values (rune bars) over secret values (runic bar)
local aSecret = issecretvalue(a.value)
local bSecret = issecretvalue(b.value)
if aSecret ~= bSecret then
return bSecret -- non-secret (false) comes before secret (true)
end
local arune = a.type or a.sortValue
local brune = b.type or b.sortValue
if arune == brune then
if db.reverseSort then
return a.value > b.value
else
return a.value < b.value
end
elseif db.reverseSort then
return arune > brune
else
return arune < brune
end
end,
function(a, b)
-- Rune, Reverse Time
-- Prioritize non-secret values (rune bars) over secret values (runic bar)
local aSecret = issecretvalue(a.value)
local bSecret = issecretvalue(b.value)
if aSecret ~= bSecret then
return bSecret -- non-secret (false) comes before secret (true)
end
local arune = a.type or a.sortValue
local brune = b.type or b.sortValue
if arune == brune then
if db.reverseSort then
return a.value < b.value
else
return a.value > b.value
end
elseif db.reverseSort then
return arune > brune
end
return arune < brune
end,
function(a, b)
-- Time, Rune
-- Prioritize non-secret values (rune bars) over secret values (runic bar)
local aSecret = issecretvalue(a.value)
local bSecret = issecretvalue(b.value)
if aSecret ~= bSecret then
return bSecret -- non-secret (false) comes before secret (true)
end
if a.value == b.value then
if db.reverseSort then
return (a.type or a.sortValue) > (b.type or b.sortValue)
else
return (a.type or a.sortValue) < (b.type or b.sortValue)
end
elseif db.reverseSort then
return a.value > b.value
end
return a.value < b.value
end,
function(a, b)
-- Reverse Time, Rune
-- Prioritize non-secret values (rune bars) over secret values (runic bar)
local aSecret = issecretvalue(a.value)
local bSecret = issecretvalue(b.value)
if aSecret ~= bSecret then
return bSecret -- non-secret (false) comes before secret (true)
end
if a.value == b.value then
if db.reverseSort then
return (a.type or a.sortValue) > (b.type or b.sortValue)
else
return (a.type or a.sortValue) < (b.type or b.sortValue)
end
elseif db.reverseSort then
return a.value < b.value
end
return a.value > b.value
end,
}
function mod:OnEnable()
if not bars then
bars = mod:NewBarGroup(L["Runes"], nil, db.length, db.thickness)
bars:SetColorAt(1.00, 1, 1, 0, 1)
bars:SetColorAt(0.00, 0.5, 0.5, 0, 1)
bars.RegisterCallback(self, "AnchorMoved")
bars.ReverseGrowth = mod.__ReverseGrowth
mod.runebars = runebars
mod.bars = bars
mod:UpdateLocalVariables()
hiddenBars = mod:NewBarGroup("Hidden Bars", nil, 200, 20)
hiddenBars:Hide()
end
mod:ApplyProfile()
if self.SetLogLevel then
mod:SetLogLevel(self.logLevels.TRACE)
end
mod:RegisterEvent("UNIT_EXITED_VEHICLE", "HandleBlizzardRuneFrameEvent")
mod:RegisterEvent("RUNE_POWER_UPDATE")
if _G.GetRuneType then
mod:RegisterEvent("RUNE_TYPE_UPDATE")
else
mod:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED", "RefreshRuneTypes")
end
mod:RegisterEvent("PLAYER_REGEN_ENABLED")
mod:RegisterEvent("PLAYER_REGEN_DISABLED")
mod:RegisterEvent("UNIT_POWER_UPDATE", "UpdateRunicPower")
mod:RegisterEvent("UNIT_MAXPOWER", "UpdateRunicPower")
mod:RegisterEvent("PLAYER_UNGHOST", "PLAYER_REGEN_ENABLED")
mod:RegisterEvent("PLAYER_DEAD", "PLAYER_REGEN_ENABLED")
mod:RegisterEvent("PLAYER_ALIVE", "PLAYER_REGEN_ENABLED")
if UnitAura then
mod:RegisterEvent("UNIT_AURA", "UpdateBuffStatus")
mod:RegisterEvent("PLAYER_TARGET_CHANGED", "UpdateBuffStatus")
end
end
-- We mess around with bars so restore them to a prestine state
-- Yes, this is evil and all but... so much fun... muahahaha
function mod:ReleaseBar(bar)
bar.barId = nil
bar.type = nil
bar.notReady = nil
bar.iconPath = nil
bar.overlayTexture:SetAlpha(0)
bar.overlayTexture:Hide()
bar.gcdnotify = false
bar:SetScript("OnEnter", nil)
bar:SetScript("OnLeave", nil)
bar:SetValue(0)
bar:SetScale(1)
bar.spark:SetAlpha(1)
bar.ownerGroup:RemoveBar(bar.name)
bar.label:SetTextColor(1, 1, 1, 1)
bar.timerLabel:SetTextColor(1, 1, 1, 1)
end
function mod:CreateBars()
for id, bar in pairs(runebars) do
if bar then
mod:ReleaseBar(bar)
runebars[id] = nil
end
end
if not db.bars then
return
end
for id, data in ipairs(db.bars) do
if not data.hide then
local idName = data.type == mod.RUNIC_BAR and "runic" or "rune"
local bar = bars:NewCounterBar("MagicRunes:" .. id ..":"..idName, db.showRemaining and 0 or 10, 10)
if not bar.overlayTexture then
bar.overlayTexture = bar:CreateTexture(nil, "OVERLAY")
bar.overlayTexture:SetTexture("Interface/Buttons/UI-Listbox-Highlight2")
bar.overlayTexture:SetBlendMode("ADD")
bar.overlayTexture:SetVertexColor(1, 1, 1, 0.6)
bar.overlayTexture:SetAllPoints()
else
bar.overlayTexture:Show()
end
bar.overlayTexture:SetAlpha(0)
bar.barId = id
bar.sortValue = data.sortValue or id
bar:SetFrameLevel(100 + id) -- this is here to ensure a "consistent" order of the icons in case they are sorted somehow
runebars[id] = bar
if data.type == mod.RUNE_BAR then
local name, icon, type, color = mod:GetRuneInfo(data.runeid)
bar.type = type
bar:SetIcon(icon)
bar:SetLabel(name)
mod:SetBarColor(bar, color)
elseif data.type == mod.RUNIC_BAR then
mod:UpdateRunicPower()
mod:SetBarLabel(id, data)
mod:SetBarColor(bar, db.colors.Runic)
local icon = media:Fetch("statusbar", "Empty")
if icon then
bar:SetIcon()
bar:ShowIcon()
else
bar:HideIcon();
end
elseif data.type == mod.DOT_BAR then
-- mod:UpdateRunicPower()
mod:SetBarLabel(id, data)
mod:SetBarColor(bar, db.colors[data.spell])
bar:SetIcon(mod.spellCache[data.spell].icon)
end
if not db.showIcon then
bar:HideIcon()
end
if not db.showLabel then
bar:HideLabel()
end
if not db.showTimer then
bar:HideTimerLabel()
end
end
end
end
function mod:UpdateBarIcons()
for id, data in pairs(db.bars) do
if data.type == mod.RUNE_BAR and runebars[id] then
runebars[id]:SetIcon(mod:GetRuneIcon(GetRuneType(data.runeid)))
end
end
if mod.modules.RuneBars then
for id, f in pairs(mod.modules.RuneBars.bars) do
f.icon:SetTexture(mod:GetRuneIcon(GetRuneType(f.runeId)))
end
end
end
function mod:OnDisable()
mod:UnregisterAllEvents()
end
do
local numActiveRunes = 0
local activeRunes = {}
local now, updated, data, bar, playAlert, tmp, newValue
local numActiveDots, scriptActive, resort, currentRunicPower, currentMaxRunicPower
local runeData = { {}, {}, {}, {}, {}, {} }
local runeAlphaLevels = { 1, 1, 1, 1, 1, 1 }
local readyFlash = {}
local targetSpellInfo = {
BLOODPLAGUE = {},
FROSTFEVER = {},
}
function mod:UpdateRemainingTimes()
if db.flashTimes and db.flashMode == 2 then
mod:RefreshBarColors()
end
for id, barData in ipairs(db.bars) do
bar = runebars[id]
if bar and barData.type ~= mod.RUNIC_BAR then
data = runeData[barData.runeid]
if not data or data.remaining <= 0 then
if db.showRemaining then
bar:SetValue(0)
else
bar:SetValue(bar.maxValue)
end
else
if db.showRemaining then
bar:SetValue(data.remaining)
else
bar:SetValue(data.value)
end
end
end
end
end
local function UpdateBuffDurations(spellInfo)
for id, data in pairs(spellInfo) do
if data.expirationTime ~= nil then
if not data.ready then
data.remaining = data.expirationTime - now
data.value = data.duration - data.remaining
if data.remaining > 0 then
numActiveDots = numActiveDots + 1
if data.remaining < gcd and not data.notified then
if db.soundOccasion == 2 then
playAlert = true
end
data.notified = db.soundOccasion
end
end
else
if data.notified == 3 then
playAlert = true
end
data.notified = nil
end
else
-- just set defaults
data.remaining = 0
data.duration = 0
data.expirationTime = 0
data.ready = 0
end
end
end
local function UpdateRuneDetails(t)
for id = 1, 6 do
data = runeData[id]
data.remaining = max((data.start or 0) + (data.duration or 0) - now, 0)
data.value = (data.duration or 10) - (data.remaining or 0)
if data.ready or data.remaining <= 0 then
data.ready = true
data.alpha = idleAlphaLevel
if data.flashing then
data.flashTime = nil
data.flashPeriod = nil
data.flashing = nil
end
if data.notified == 3 then
playAlert = true
end
data.notified = nil
elseif data.remaining < gcd then
if not data.notified then
if db.soundOccasion == 2 then
playAlert = true
end
data.notified = db.soundOccasion
end
if mod.flashTimer then
if not data.flashing then
data.alpha = 1.0
data.flashTime = 0
data.flashPeriod = data.remaining / mod.flashTimer
data.flashing = true
else
if t then
data.flashTime = data.flashTime + t
end
if data.flashTime > TWOPI then
data.flashTime = data.flashTime - TWOPI
end
data.alpha = (cos(data.flashTime / data.flashPeriod) + 1) / 2
end
else
if db.fadeAlphaGCD then
tmp = data.remaining / gcd
data.alpha = db.alphaGCD * tmp + idleAlphaLevel * (1 - tmp)
else
data.alpha = db.alphaGCD
end
end
elseif db.fadeAlpha then
tmp = (data.remaining - gcd) / (10 - gcd)
data.alpha = db.alphaActive * tmp + db.alphaGCD * (1 - tmp)
else
data.alpha = db.alphaActive
end
data.alpha = max(0, min(1.0, data.alpha))
end
end
local function DoReadyFlash()
for id, data in pairs(readyFlash) do
if data then
local duration = now - data.start
bar = data.bar
if duration > db.readyFlashDuration then
readyFlash[id] = nil
bar.overlayTexture:SetAlpha(0)
elseif duration >= mod._readyFlash2 then
bar.overlayTexture:SetAlpha((db.readyFlashDuration - duration) / mod._readyFlash2)
else
bar.overlayTexture:SetAlpha(duration / mod._readyFlash2)
end
end
end
end
function mod:AddReadyFlash(bar)
for id, data in pairs(readyFlash) do
if data and data.bar == bar then
data.start = now
return
end
end
if not inserted then
readyFlash[#readyFlash + 1] = { start = now, bar = bar }
end
end
local function UpdateBarDisplay()
-- Check each bar for update
for id, barData in ipairs(db.bars) do
bar = runebars[id]
if bar then
if barData.type == mod.RUNIC_BAR then
-- Safely check for changes, avoiding secret value comparisons
local needsUpdate = true
pcall(function()
if bar.value == currentRunicPower and bar.maxValue == currentMaxRunicPower then
needsUpdate = false
end
end)
if needsUpdate or type(bar.value) ~= "nil" or type(bar.maxValue) ~= nil then
bar.value = currentRunicPower
bar:SetMaxValue(currentMaxRunicPower)
if db.showTimer then
bar.timerLabel:SetText(tostring(currentRunicPower))
end
end
-- Safely check if value is 0
local isZero = false
pcall(function()
if bar.value == 0 then
isZero = true
end
end)
if isZero then
bar:SetAlpha(idleAlphaLevel)
else
bar:SetAlpha(1.0)
end
elseif barData.type == mod.DOT_BAR or barData.type == mod.RUNE_BAR then
local isRuneBar
if barData.type == mod.DOT_BAR then
data = targetSpellInfo[barData.spell]
else
isRuneBar = true
data = runeData[barData.runeid]
-- Handle death runes changes
if bar.type ~= data.type then
local name, icon, type, color = mod:GetRuneInfo(barData.runeid)
bar.type = data.type
bar:SetLabel(name)
bar:SetIcon(icon)
mod:SetBarColor(bar, color)
end
end
if data.flashing or isRuneBar then
bar:SetAlpha(data.alpha)
end
if data.ready or data.remaining <= 0 then
if barData.type == mod.DOT_BAR then
-- Hide inactive dot bars
if bar.ownerGroup ~= hiddenBars then
resort = true
bars:MoveBarToGroup(bar, hiddenBars)
end
end
if bar.notReady or numActiveRunes == 0 then
if db.showRemaining then
bar:SetValue(0)
else
bar:SetValue(bar.maxValue)
end
bar.timerLabel:SetText("")
bar.notReady = nil
if bar.gcdnotify then
if db.readyFlash and barData.type == mod.RUNE_BAR then
mod:AddReadyFlash(bar)
end
end
bar.gcdnotify = nil
end
else
if barData.type == mod.DOT_BAR then
-- Show newly active dot bar
if bar.ownerGroup ~= bars then
hiddenBars:MoveBarToGroup(bar, bars)
resort = true
end
end
newValue = db.showRemaining and data.remaining or data.value
-- Safely check if value changed
local valueChanged = true
pcall(function()
if bar.value == newValue then
valueChanged = false
end
end)
if valueChanged then
if data.remaining < gcd then
bar.gcdnotify = true
end
bar:SetValue(max(0, newValue), data.duration)
if db.showTimer then
if data.remaining == 0 then
bar.timerLabel:SetText("")
elseif data.remaining > gcd or db.secondsOnly then
bar.timerLabel:SetText(fmt("%.0f", data.remaining))
else
bar.timerLabel:SetText(fmt("%.1f", data.remaining))
end
end
end
bar.notReady = true
end
end
end
end
end
function mod:UpdateBars(t)
currentRunicPower = UnitPower("player")
currentMaxRunicPower = UnitPowerMax("player")
resort, playAlert = nil, nil
numActiveDots = 0
now = GetTime()
-- Update the value and remaining time for all runes
UpdateRuneDetails(t)
-- this updates the remaining and current value of the dots/buffs
UpdateBuffDurations(targetSpellInfo)
-- Do the "rune is ready" flashing
if db.readyFlash and #readyFlash > 0 then
DoReadyFlash()
end
UpdateBarDisplay()
if resort then
mod:SetOrientation()
mod:SetSize()
hiddenBars:SortBars()
elseif db.sortMethod > 1 then
bars:SortBars()
end
if playAlert and mod.soundFile then
PlaySoundFile(mod.soundFile)
end
-- Execute the update method in each module
for _, module in pairs(mod.modules) do
if module.OnUpdate then
module:OnUpdate(t or 0, runeData, targetSpellInfo)
end
end
-- Check whether or not to cancel the OnUpdate method
if #readyFlash > 0 -- animations
or numActiveRunes > 0 -- runes are active
or numActiveDots > 0 -- dot display active
-- or currentRunicPower > 0 -- non-zero runic power
then
-- something is going on, and timer isn't active so enable it
if not scriptActive then
bars:SetScript("OnUpdate", mod.UpdateBars)
scriptActive = true
end
elseif scriptActive then
-- We're active, but have nothing to do - disable OnUpdate
bars:SetScript("OnUpdate", nil)
scriptActive = nil
end
end
function mod:UpdateBuffStatus(event, unit)
local spellInfo, filter
if event == "PLAYER_TARGET_CHANGED" then
unit = "target"
end
if unit == "target" then
spellInfo = targetSpellInfo
filter = "HARMFUL"
else
return
end
for _, data in pairs(spellInfo) do
data.ready = true
data.duration = 0
data.expirationTime = 0
end
if UnitExists(unit) then
-- don't update if the unit doesn't exist
local info
for id = 1, 40 do
local name, _, _, _, duration, expirationTime, isMine = UnitAura(unit, id, filter)
if name and isMine == "player" then
info = mod.spellCache[name]
if info then
data = spellInfo[info.shortname]
if data then
-- required since unholy blight shows up on the target too
data.expirationTime = expirationTime
data.duration = duration
data.ready = false
end
end
end
end
end
if not scriptActive then
mod.UpdateBars()
end
end
function mod:UpdateRuneStatus(id)
local data = runeData[id]
local change = false
local start, duration, ready = GetRuneCooldown(id)
if data.start ~= start or data.duration ~= duration or data.ready ~= ready then
data.start = start
data.duration = duration
data.ready = ready
changed = true
end
if not data.type then
data.type = GetRuneType(id)
changed = true
end
return changed
end
function mod:RUNE_POWER_UPDATE(_, _, _)
for rune = 1,6 do
if mod:UpdateRuneStatus(rune) then
if runeData[rune].ready then
if activeRunes[rune] then
activeRunes[rune] = nil
numActiveRunes = numActiveRunes - 1
end
else
if not activeRunes[rune] then
numActiveRunes = numActiveRunes + 1
activeRunes[rune] = true
end
end
end
end
if not scriptActive then
mod:UpdateBars()
end
end
function mod:RUNE_TYPE_UPDATE(_, rune)
runeData[rune].type = GetRuneType(rune)
if not scriptActive then
mod:UpdateBars()
end
end
function mod:RefreshRuneTypes()
for rune = 1, 6 do
runeData[rune].type = GetRuneType(rune)
end
if not scriptActive then
mod:UpdateBars()
end
end
function mod:UpdateRunicPower(_, unit)
if unit and unit ~= "player" then
return
end
local current = UnitPower("player")
local max = UnitPowerMax("player")
local bar
for id, data in ipairs(db.bars) do
bar = runebars[id]
if data.type == mod.RUNIC_BAR and bar then
bar.value = current
bar:SetMaxValue(max)
if db.showTimer then
bar.timerLabel:SetText(tostring(current))
end
end
end
if not scriptActive then
mod:UpdateBars()
end
end
end
function mod:AnchorMoved(cbk, group, button)
db.point = { group:GetPoint() }
end
function mod:SetBarColor(bar, color)
if not color then