This repository was archived by the owner on Apr 12, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerBars.lua
More file actions
3071 lines (2736 loc) · 105 KB
/
TimerBars.lua
File metadata and controls
3071 lines (2736 loc) · 105 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
-- ----------------------
-- TimerBars
-- by Kitjan, lieandswell
-- ----------------------
local trace = print
--function maybe_trace(...)
--local so_far = ""
--local p = _G
--for idx = 1,40,1 do
--local v = select(idx,...)
--if not v then
--break
--end
--p = p[v]
--if not p then
--if so_far == "" then
--trace("global variable",v,"does not exist")
--else
--trace(so_far,"does not have member",v)
--end
--return;
--end
--so_far = so_far .. "." .. v
--end
--trace(so_far,"=",p)
--end
--
-- -------------
-- ADDON GLOBALS
-- -------------
TimerBars = {}
TimerBarsLoader = {}
-- -------------
-- ADDON MEMBERS
-- -------------
local g_GetActiveTalentGroup = _G.GetSpecialization
local g_UnitAffectingCombat = UnitAffectingCombat
local g_UnitIsFriend = UnitIsFriend
local g_UnitGUID = UnitGUID
local g_GetTime = GetTime
local g_GetSpellBookItemInfo = GetSpellBookItemInfo
local g_GetSpellTabInfo = GetSpellTabInfo
local g_GetNumSpellTabs = GetNumSpellTabs
local g_GetNumSpecializations = GetNumSpecializations
local g_GetSpecializationSpells = GetSpecializationSpells
local g_GetSpellInfo = GetSpellInfo
local g_GetSpellPowerCost = GetSpellPowerCost
local m_last_guid, m_last_cast, m_last_sent, m_last_cast_head, m_last_cast_tail
local m_bInCombat, m_bCombatWithBoss
local mfn_Bar_AuraCheck
local mfn_EnergyBar_OnUpdate
local mfn_AuraCheck_Single
local mfn_AuraCheck_TOTEM
local mfn_AuraCheck_BUFFCD
local mfn_AuraCheck_USABLE
local mfn_AuraCheck_EQUIPSLOT
local mfn_AuraCheck_POWER
local mfn_AuraCheck_CASTCD
local mfn_AuraCheck_AllStacks
local mfn_GetUnresolvedCooldown
local mfn_GetAutoShotCooldown
local mfn_GetSpellChargesCooldown
local mfn_GetSpellCooldown
local mfn_AddInstanceToStacks
local mfn_SetStatusBarValue
local mfn_ResetScratchStacks
local mfn_UpdateVCT
local m_scratch = {}
m_scratch.all_stacks =
{
min =
{
buffName = "",
duration = 0,
expirationTime = 0,
iconPath = "",
caster = ""
},
max =
{
duration = 0,
expirationTime = 0,
},
total = 0,
total_ttn = { 0, 0, 0 }
}
m_scratch.buff_stacks =
{
min =
{
buffName = "",
duration = 0,
expirationTime = 0,
iconPath = "",
caster = ""
},
max =
{
duration = 0,
expirationTime = 0,
},
total = 0,
total_ttn = { 0, 0, 0 }
}
m_scratch.bar_entry =
{
idxName = 0,
barSpell = "",
isSpellID = false,
}
-- TIMERBARS = {} is defined in the localization file, which must be loaded before this file
TIMERBARS.VERSION = GetAddOnMetadata("TimerBars", "Version")
local c_UPDATE_INTERVAL = 0.05
local c_MAXBARS = 20
-- Get the localized name of spell 75, which is "Auto Shot" in US English
local c_AUTO_SHOT_NAME = g_GetSpellInfo(75)
-- COMBAT_LOG_EVENT_UNFILTERED events where select(6,...) is the caster, 9 is the spellid, and 10 is the spell name
-- (used for Target-of-target monitoring)
local c_AURAEVENTS = {
SPELL_AURA_APPLIED = true,
SPELL_AURA_REMOVED = true,
SPELL_AURA_APPLIED_DOSE = true,
SPELL_AURA_REMOVED_DOSE = true,
SPELL_AURA_REFRESH = true,
SPELL_AURA_BROKEN = true,
SPELL_AURA_BROKEN_SPELL = true
}
TIMERBARS.BAR_DEFAULTS = {
Enabled = true,
AuraName = "",
Unit = "player",
BuffOrDebuff = "HELPFUL",
OnlyMine = true,
BarColor = { r=0.6, g=0.6, b=0.6, a=1.0 },
MissingBlink = { r=0.9, g=0.1, b=0.1, a=0.5 },
TimeFormat = "Fmt_SingleUnit",
vct_enabled = false,
vct_color = { r=0.6, g=0.6, b=0.0, a=0.3 },
vct_spell = "",
vct_extra = 0,
bDetectExtends = false,
show_text = true,
show_count = true,
show_time = true,
show_spark = true,
show_icon = false,
show_mypip = false,
show_all_stacks = false,
show_charges = true,
show_ttn1 = false,
show_ttn2 = false,
show_ttn3 = false,
show_text_user = "",
blink_enabled = false,
blink_ooc = true,
blink_boss = false,
blink_label = "",
buffcd_duration = 0,
buffcd_reset_spells = "",
usable_duration = 0,
append_cd = true,
append_usable = false,
}
TIMERBARS.GROUP_DEFAULTS = {
Enabled = true,
NumberBars = 3,
Scale = 1.0,
Width = 270,
Bars = { TIMERBARS.BAR_DEFAULTS, TIMERBARS.BAR_DEFAULTS, TIMERBARS.BAR_DEFAULTS },
Position = { "TOPLEFT", "TOPLEFT", 100, -100 },
FixedDuration = 0,
}
TIMERBARS.DEFAULTS = {
Version = TIMERBARS.VERSION,
OldVersion = TIMERBARS.VERSION,
Profiles = {},
Chars = {},
}
TIMERBARS.CHARACTER_DEFAULTS = {
Specs = {},
Locked = false,
Profiles = {},
}
TIMERBARS.PROFILE_DEFAULTS = {
name = "Default",
nGroups = 1,
Groups = { TIMERBARS.GROUP_DEFAULTS },
BarTexture = "BantoBar",
BarFont = "Fritz Quadrata TT",
BkgdColor = { 0, 0, 0, 0.8 },
BarSpacing = 3,
BarPadding = 3,
FontSize = 12,
FontOutline = 0,
}
TIMERBARS.SHORTENINGS= {
Enabled = "On",
AuraName = "Aura",
--Unit = "Unit",
BuffOrDebuff = "Typ",
OnlyMine = "Min",
BarColor = "Clr",
MissingBlink = "BCl",
TimeFormat = "TF",
vct_enabled = "VOn",
vct_color = "VCl",
vct_spell = "VSp",
vct_extra = "VEx",
bDetectExtends = "Ext",
show_text = "sTx",
show_count = "sCt",
show_time = "sTm",
show_spark = "sSp",
show_icon = "sIc",
show_mypip = "sPp",
show_all_stacks = "All",
show_charges = "Chg",
show_text_user = "sUr",
show_ttn1 = "sN1",
show_ttn2 = "sN2",
show_ttn3 = "sN3",
blink_enabled = "BOn",
blink_ooc = "BOC",
blink_boss = "BBs",
blink_label = "BTx",
buffcd_duration = "cdd",
buffcd_reset_spells = "cdr",
usable_duration = "udr",
append_cd = "acd",
append_usable = "aus",
--NumberBars = "NmB",
--Scale = "Scl",
--Width = "Cx",
--Bars = "Brs",
--Position = "Pos",
--FixedDuration = "FxD",
--Version = "Ver",
--OldVersion = "OVr",
--Profiles = "Pfl",
--Chars = "Chr",
--Specs = "Spc",
--Locked = "Lck",
--name = "nam",
--nGroups = "nGr",
--Groups = "Grp",
--BarTexture = "Tex",
--BarFont = "Fnt",
--BkgdColor = "BgC",
--BarSpacing = "BSp",
--BarPadding = "BPd",
--FontSize = "FSz",
--FontOutline = "FOl",
}
TIMERBARS.LENGTHENINGS= {
On = "Enabled",
Aura = "AuraName",
-- Unit = "Unit",
Typ = "BuffOrDebuff",
Min = "OnlyMine",
Clr = "BarColor",
BCl = "MissingBlink",
TF = "TimeFormat",
VOn = "vct_enabled",
VCl = "vct_color",
VSp = "vct_spell",
VEx = "vct_extra",
Ext = "bDetectExtends",
sTx = "show_text",
sCt = "show_count",
sN1 = "show_ttn1",
sN2 = "show_ttn2",
sN3 = "show_ttn3",
sTm = "show_time",
sSp = "show_spark",
sIc = "show_icon",
sPp = "show_mypip",
All = "show_all_stacks",
Chg = "show_charges",
sUr = "show_text_user",
BOn = "blink_enabled",
BOC = "blink_ooc",
BBs = "blink_boss",
BTx = "blink_label",
cdd = "buffcd_duration",
cdr = "buffcd_reset_spells",
udr = "usable_duration",
acd = "append_cd",
aus = "append_usable",
--NumberBars = "NmB",
--Scale = "Scl",
--Width = "Cx",
--Bars = "Brs",
--Position = "Pos",
--FixedDuration = "FxD",
--Version = "Ver",
--OldVersion = "OVr",
--Profiles = "Pfl",
--Chars = "Chr",
--Specs = "Spc",
--Locked = "Lck",
--name can't be compressed since it's used even when not the active profile
--nGroups = "nGr",
--Groups = "Grp",
--BarTexture = "Tex",
--BarFont = "Fnt",
--BkgdColor = "BgC",
--BarSpacing = "BSp",
--BarPadding = "BPd",
--FontSize = "FSz",
--FontOutline = "FOl";
}
-- -------------------
-- SharedMedia Support
-- -------------------
TimerBars.LSM = LibStub("LibSharedMedia-3.0", true)
if not TimerBars.LSM:Fetch("statusbar", "Aluminum", true) then TimerBars.LSM:Register("statusbar", "Aluminum", [[Interface\Addons\TimerBars\Textures\Aluminum.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Armory", true) then TimerBars.LSM:Register("statusbar", "Armory", [[Interface\Addons\TimerBars\Textures\Armory.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "BantoBar", true) then TimerBars.LSM:Register("statusbar", "BantoBar", [[Interface\Addons\TimerBars\Textures\BantoBar.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "DarkBottom", true) then TimerBars.LSM:Register("statusbar", "DarkBottom", [[Interface\Addons\TimerBars\Textures\Darkbottom.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Default", true) then TimerBars.LSM:Register("statusbar", "Default", [[Interface\Addons\TimerBars\Textures\Default.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Flat", true) then TimerBars.LSM:Register("statusbar", "Flat", [[Interface\Addons\TimerBars\Textures\Flat.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Glaze", true) then TimerBars.LSM:Register("statusbar", "Glaze", [[Interface\Addons\TimerBars\Textures\Glaze.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Gloss", true) then TimerBars.LSM:Register("statusbar", "Gloss", [[Interface\Addons\TimerBars\Textures\Gloss.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Graphite", true) then TimerBars.LSM:Register("statusbar", "Graphite", [[Interface\Addons\TimerBars\Textures\Graphite.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Minimalist", true) then TimerBars.LSM:Register("statusbar", "Minimalist", [[Interface\Addons\TimerBars\Textures\Minimalist.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Otravi", true) then TimerBars.LSM:Register("statusbar", "Otravi", [[Interface\Addons\TimerBars\Textures\Otravi.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Smooth", true) then TimerBars.LSM:Register("statusbar", "Smooth", [[Interface\Addons\TimerBars\Textures\Smooth.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Smooth v2", true) then TimerBars.LSM:Register("statusbar", "Smooth v2", [[Interface\Addons\TimerBars\Textures\Smoothv2.tga]]) end
if not TimerBars.LSM:Fetch("statusbar", "Striped", true) then TimerBars.LSM:Register("statusbar", "Striped", [[Interface\Addons\TimerBars\Textures\Striped.tga]]) end
-- ---------------
-- EXECUTIVE FRAME
-- ---------------
function TimerBars.ExecutiveFrame_OnEvent(self, event, ...)
local fnName = "ExecutiveFrame_"..event
local fn = TimerBars[fnName]
if ( fn ) then
fn(...)
end
end
function TimerBars.ExecutiveFrame_UNIT_SPELLCAST_SENT(unit, tgt, serialno, spellid)
-- BFA
-- 1. unit
-- 2. target
-- 3. serialno
-- 4. spellId
-- spell is nil when you mount up as death knight, but not as any other class ... ??
local spell = spell_id_to_name(spellid)
if unit == "player" and spell then
-- TODO: I hate to pay this memory cost for every "spell" ever cast.
-- Would be nice to at least garbage collect this data at some point, but that
-- may add more overhead than just keeping track of 100 spells.
if not m_last_sent then
m_last_sent = {}
end
m_last_sent[spell] = g_GetTime()
-- How expensive a second check do we need?
if ( m_last_guid[spell] or TimerBars.BarsForPSS ) then
local r = m_last_cast[m_last_cast_tail]
if not r then
r = { spell=spell, target=tgt, serial=serialno }
m_last_cast[m_last_cast_tail] = r
else
r.spell = spell
r.target = tgt
r.serial = serialno
end
m_last_cast_tail = m_last_cast_tail + 1
if ( m_last_cast_tail == 2 ) then
m_last_cast_head = 1
if ( m_last_guid[spell] ) then
TimerBars_ExecutiveFrame:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
TimerBars_ExecutiveFrame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
else
TimerBars_ExecutiveFrame:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
end
end
end
end
end
function spell_id_to_name(spellId)
local name = GetSpellInfo(spellId)
return name
end
function TimerBars.ExecutiveFrame_UNIT_SPELLCAST_SUCCEEDED(unit, serialno, spellid)
-- BFA:
-- 1. caster
-- 2. serialno
-- 3. spell id
local spell = spell_id_to_name(spellid)
if unit == "player" then
local found
local t = m_last_cast
local last = m_last_cast_tail-1
local i
for i = last,m_last_cast_head,-1 do
if t[i].spell == spell and t[i].serial == serialno then
found = i
break
end
end
if found then
if ( TimerBars.BarsForPSS ) then
local bar,one
for bar,one in pairs(TimerBars.BarsForPSS) do
local unitTarget = TimerBars.raid_members[t[found].target or ""]
TimerBars.Bar_OnEvent(bar, "PLAYER_SPELLCAST_SUCCEEDED", "player", spell, spellid, unitTarget);
end
end
if ( found == last ) then
m_last_cast_tail = 1
m_last_cast_head = 1
TimerBars_ExecutiveFrame:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
else
m_last_cast_head = found+1
end
end
end
end
function TimerBars.ExecutiveFrame_COMBAT_LOG_EVENT_UNFILTERED()
-- BFA 8.0: no event payload, need to get it manually
local tod, event, hideCaster, guidCaster, sourceName, sourceFlags, sourceRaidFlags, guidTarget,
nameTarget, _, _, spellid, spell = CombatLogGetCurrentEventInfo()
-- the time that's passed in appears to be time of day, not game time like everything else.
local time = g_GetTime()
-- TODO: Is checking r.state sufficient or must event be checked instead?
if ( guidCaster == TimerBars.guidPlayer and event=="SPELL_CAST_SUCCESS") then
local found
local t = m_last_cast
local last = m_last_cast_tail-1
local i
for i = last,m_last_cast_head,-1 do
if t[i].spell == spell then
found = i
break
end
end
if found then
if ( TimerBars.BarsForPSS ) then
local bar,one
for bar,one in pairs(TimerBars.BarsForPSS) do
local unitTarget = TimerBars.raid_members[t[found].target or ""]
TimerBars.Bar_OnEvent(bar, "PLAYER_SPELLCAST_SUCCEEDED", "player", spell, spellid, unitTarget);
end
end
local rBySpell = m_last_guid[spell]
if ( rBySpell ) then
local rByGuid = rBySpell[guidTarget]
if not rByGuid then
rByGuid = { time=time, dur=0, expiry=0 }
rBySpell[guidTarget] = rByGuid
else
rByGuid.time= time
rByGuid.dur = 0
rByGuid.expiry = 0
end
end
if ( found == last ) then
m_last_cast_tail = 1
m_last_cast_head = 1
TimerBars_ExecutiveFrame:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
else
m_last_cast_head = found+1
end
end
end
end
function TimerBars.ExecutiveFrame_ADDON_LOADED(addon)
if ( addon == "TimerBars") then
if ( not TimerBars_Visible ) then
TimerBars_Visible = true
end
m_last_cast = {} -- [n] = { spell, target, serial }
m_last_cast_head = 1
m_last_cast_tail = 1
m_last_guid = {} -- [spell][guidTarget] = { time, dur, expiry }
TimerBars.totem_drops = {} -- array 1-4 of precise times the totems appeared
SlashCmdList["TIMERBARS"] = TimerBars.SlashCommand
SLASH_TIMERBARS1 = "/timerbars"
SLASH_TIMERBARS2 = "/tbs"
SLASH_TIMERBARS3 = "/tmb"
end
end
function TimerBars.ExecutiveFrame_PLAYER_LOGIN()
TimerBarsLoader.SafeUpgrade()
TimerBars.ExecutiveFrame_PLAYER_TALENT_UPDATE()
TimerBars.guidPlayer = UnitGUID("player")
local _, player_CLASS = UnitClass("player")
if player_CLASS == "DEATHKNIGHT" then
TimerBars.is_DK = 1
elseif player_CLASS == "DRUID" then
TimerBars.is_Druid = 1
end
TimerBars_ExecutiveFrame:RegisterEvent("PLAYER_TALENT_UPDATE")
TimerBars_ExecutiveFrame:RegisterEvent("ACTIVE_TALENT_GROUP_CHANGED")
TimerBars_ExecutiveFrame:RegisterEvent("UNIT_TARGET")
TimerBars_ExecutiveFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
TimerBars_ExecutiveFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
TimerBars_ExecutiveFrame:RegisterEvent("GROUP_ROSTER_UPDATE")
if ( TimerBars.is_DK ) then
TimerBars.RegisterSpellcastSent();
end
TimerBars.Update()
TimerBars_ExecutiveFrame:UnregisterEvent("PLAYER_LOGIN")
TimerBars_ExecutiveFrame:UnregisterEvent("ADDON_LOADED")
TimerBars.ExecutiveFrame_ADDON_LOADED = nil
TimerBars.ExecutiveFrame_PLAYER_LOGIN = nil
TimerBarsLoader = nil
TimerBars.RefreshRaidMemberNames()
end
function TimerBars.RegisterSpellcastSent()
if ( TimerBars.nRegisteredSent ) then
TimerBars.nRegisteredSent = TimerBars.nRegisteredSent + 1
else
TimerBars.nRegisteredSent = 1
TimerBars_ExecutiveFrame:RegisterEvent("UNIT_SPELLCAST_SENT")
end
end
function TimerBars.UnregisterSpellcastSent()
if ( TimerBars.nRegisteredSent ) then
TimerBars.nRegisteredSent = TimerBars.nRegisteredSent - 1
if ( 0 == TimerBars.nRegisteredSent ) then
TimerBars.nRegisteredSent = nil
TimerBars_ExecutiveFrame:UnregisterEvent("UNIT_SPELLCAST_SENT")
TimerBars_ExecutiveFrame:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
TimerBars_ExecutiveFrame:UnregisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
end
end
end
function TimerBars.ExecutiveFrame_ACTIVE_TALENT_GROUP_CHANGED()
-- This is the only event we're guaranteed to get on a talent switch,
-- so we have to listen for it. However, the client may not yet have
-- the spellbook updates, so trying to evaluate the cooldows may fail.
-- This is one of the reasons the cooldown logic has to fail silently
-- and try again later
TimerBars.ExecutiveFrame_PLAYER_TALENT_UPDATE()
end
function TimerBars.ExecutiveFrame_PLAYER_TALENT_UPDATE()
if TimerBars.CharSettings then
local spec = g_GetActiveTalentGroup()
local profile_key = TimerBars.CharSettings.Specs[spec]
if not profile_key then
print("TimerBars: Switching to spec",spec,"for the first time")
profile_key = TimerBars.CreateProfile(CopyTable(TIMERBARS.PROFILE_DEFAULTS), spec)
end
TimerBars.ChangeProfile(profile_key);
end
end
function TimerBars.ExecutiveFrame_UNIT_TARGET(unitTargeting)
if m_bInCombat and not m_bCombatWithBoss then
if UnitLevel(unitTargeting .. 'target') == -1 then
m_bCombatWithBoss = true
if TimerBars.BossStateBars then
for bar, unused in pairs(TimerBars.BossStateBars) do
mfn_Bar_AuraCheck(bar)
end
end
end
end
end
function TimerBars.GetNameAndServer(unit)
local name, server = UnitName(unit)
if name and server then
return name .. '-' .. server
end
return name
end
function TimerBars.RefreshRaidMemberNames()
TimerBars.raid_members = {}
-- Note, if I did want to handle raid pets as well, they do not get the
-- server name decoration in the combat log as of 5.0.4
if IsInRaid() then
for i = 1, 40 do
local unit = "raid"..i
local name = TimerBars.GetNameAndServer(unit)
if ( name ) then TimerBars.raid_members[name] = unit end
end
elseif IsInGroup() then
for i = 1, 5 do
local unit = "party"..i
local name = TimerBars.GetNameAndServer(unit)
if ( name ) then TimerBars.raid_members[name] = unit end
end
end
-- Also get the player and their pet in directly
-- (don't need NameAndServer since the player will always have a nil server.)
local unit = "player"
local name = UnitName(unit)
TimerBars.raid_members[name] = unit
unit = "pet"
name = UnitName(unit)
if ( name ) then
TimerBars.raid_members[name] = unit
end
end
function TimerBars.ExecutiveFrame_GROUP_ROSTER_UPDATE()
TimerBars.RefreshRaidMemberNames();
end
function TimerBars.ExecutiveFrame_PLAYER_REGEN_DISABLED(unitTargeting)
m_bInCombat = true
m_bCombatWithBoss = false
if IsInRaid() then
for i = 1, 40 do
if UnitLevel("raid"..i.."target") == -1 then
m_bCombatWithBoss = true;
break;
end
end
elseif IsInGroup() then
for i = 1, 5 do
if UnitLevel("party"..i.."target") == -1 then
m_bCombatWithBoss = true;
break;
end
end
elseif UnitLevel("target") == -1 then
m_bCombatWithBoss = true
end
if TimerBars.BossStateBars then
for bar, unused in pairs(TimerBars.BossStateBars) do
mfn_Bar_AuraCheck(bar)
end
end
end
function TimerBars.ExecutiveFrame_PLAYER_REGEN_ENABLED(unitTargeting)
m_bInCombat = false
m_bCombatWithBoss = false
if TimerBars.BossStateBars then
for bar, unused in pairs(TimerBars.BossStateBars) do
mfn_Bar_AuraCheck(bar)
end
end
end
function TimerBars.RemoveDefaultValues(t, def, k)
if not k then k = "" end
if def == nil then
-- Some obsolete setting, or perhaps bUncompressed
return true
end
-- Never want to compress name since it's read from inactive profiles
-- Note: k was just for debugging, so it's got a leading space as part
-- of how the debugging string was built. This mechanism should probably
-- be revisited.
if type(t) ~= "table" then
return ((k~=" name") and (t == def))
end
if #t > 0 then
-- An array, like Groups or Bars. Compare each element against def[1]
for i,v in ipairs(t)do
local rhs = def[i]
if rhs == nil then rhs = def[1] end
if TimerBars.RemoveDefaultValues(v, rhs, k .. " " .. i) then
t[i] = nil
end
end
else
for kT, vT in pairs(t) do
if TimerBars.RemoveDefaultValues(t[kT], def[kT], k .. " " .. kT) then
t[kT] = nil
end
end
end
local fn = pairs(t)
return fn(t) == nil
end
function TimerBars.CompressProfile(profileSettings)
-- Remove unused bars/groups
for iG,vG in ipairs(profileSettings["Groups"]) do
if iG > profileSettings.nGroups then
profileSettings["Groups"][iG] = nil
elseif vG.NumberBars then
for iB, vB in ipairs(vG["Bars"]) do
if iB > vG.NumberBars then
vG["Bars"][iB] = nil
end
end
end
end
TimerBars.RemoveDefaultValues(profileSettings, TIMERBARS.PROFILE_DEFAULTS);
end
-- DEBUG: remove k, it's just for debugging
function TimerBars.AddDefaultsToTable(t, def, k)
if type(t) ~= "table" then return end
if def == nil then
return
end
if not k then k = "" end
local n = table.maxn(t)
if n > 0 then
for i=1,n do
local rhs = def[i]
if rhs == nil then rhs = def[1] end
if t[i] == nil then
t[i] = TimerBars.DeepCopy(rhs)
else
TimerBars.AddDefaultsToTable(t[i], rhs, k .. " " .. i)
end
end
else
for kD,vD in pairs(def) do
if t[kD] == nil then
if type(vD) == "table" then
t[kD] = TimerBars.DeepCopy(vD)
else
t[kD] = vD
end
else
TimerBars.AddDefaultsToTable(t[kD], vD, k .. " " .. kD)
end
end
end
end
function TimerBars.UncompressProfile(profileSettings)
-- Make sure the arrays have the right number of elements so that
-- AddDefaultsToTable will find them and fill them in
if profileSettings.nGroups then
if not profileSettings.Groups then
profileSettings.Groups = {}
end
if not profileSettings.Groups[profileSettings.nGroups] then
profileSettings.Groups[profileSettings.nGroups] = {}
end
end
if profileSettings.Groups then
for i,g in ipairs(profileSettings.Groups) do
if g.NumberBars then
if not g.Bars then
g.Bars = {}
end
if not g.Bars[g.NumberBars] then
g.Bars[g.NumberBars] = {}
end
end
end
end
TimerBars.AddDefaultsToTable(profileSettings, TIMERBARS.PROFILE_DEFAULTS)
profileSettings.bUncompressed = true
end
function TimerBars.ChangeProfile(profile_key)
if TimerBars_Profiles[profile_key] and
TimerBars.ProfileSettings ~= TimerBars_Profiles[profile_key] then
-- Compress the old profile by removing defaults
if TimerBars.ProfileSettings and TimerBars.ProfileSettings.bUncompressed then
TimerBars.CompressProfile(TimerBars.ProfileSettings)
end
-- Switch to the new profile
TimerBars.ProfileSettings = TimerBars_Profiles[profile_key]
local spec = g_GetActiveTalentGroup()
TimerBars.CharSettings.Specs[spec] = profile_key
-- fill in any missing defaults
TimerBars.UncompressProfile(TimerBars.ProfileSettings)
-- FIXME: We currently display 4 groups in the options UI, not nGroups
-- FIXME: We don't handle nGroups changing (showing/hiding groups based on nGroups changing)
-- Forcing 4 groups for now
TimerBars.ProfileSettings.nGroups = 4
for groupID = 1,4 do
if ( nil == TimerBars.ProfileSettings.Groups[groupID] ) then
TimerBars.ProfileSettings.Groups[groupID] = CopyTable( TIMERBARS.GROUP_DEFAULTS )
local groupSettings = TimerBars.ProfileSettings.Groups[groupID]
groupSettings.Enabled = false;
groupSettings.Position[4] = -100 - (groupID-1) * 100
end
end
-- Hide any groups not in use
local iGroup = TimerBars.ProfileSettings.nGroups + 1
while true do
local group = _G["TimerBars_Group"..iGroup]
if not group then
break
end
group:Hide()
iGroup = iGroup + 1
end
-- Update the bars and options panel (if it's open)
TimerBars.Update()
TimerBarsOptions.UIPanel_Update()
elseif not TimerBars_Profiles[profile_key] then
print("TimerBars profile",profile_key,"does not exist!") -- LOCME!
end
end
mfn_SetStatusBarValue = function (bar,texture,value,value0)
local pct0 = 0
if value0 then
pct0 = value0 / bar.max_value
if pct0 > 1 then pct0 = 1 end
end
-- This happened to me when there was lag right around the time
-- a bar was ending
if value < 0 then
value = 0
end
local pct = value / bar.max_value
texture.cur_value = value
if pct > 1 then pct = 1 end
local w = (pct-pct0) * bar:GetWidth()
if w < 1 then
texture:Hide()
else
texture:SetWidth(w)
texture:SetTexCoord(pct0,0, pct0,1, pct,0, pct,1)
texture:Show()
end
end
function TimerBarsLoader.Reset(bResetCharacter)
TimerBars_Globals = CopyTable( TIMERBARS.DEFAULTS )
if bResetCharacter == nil or bResetCharacter then
TimerBars.ResetCharacter()
end
end
function TimerBars.ResetCharacter(bCreateSpecProfile)
local charKey = UnitName("player") .. ' - ' .. GetRealmName();
TimerBars_CharSettings = CopyTable(TIMERBARS.CHARACTER_DEFAULTS)
TimerBars.CharSettings = TimerBars_CharSettings
if bCreateSpecProfile == nil or bCreateSpecProfile then
TimerBars.ExecutiveFrame_PLAYER_TALENT_UPDATE()
end
end
function TimerBars.AllocateProfileKey()
local n=TimerBars_Globals.NextProfile or 1
while TimerBars_Profiles["G"..n] do
n = n+1
end
if ( TimerBars_Globals.NextProfile==null or n >= TimerBars_Globals.NextProfile ) then
TimerBars_Globals.NextProfile = n+1
end
return "G"..n;
end
function TimerBars.FindUnusedNumericSuffix(prefix, defPrefix)
local suffix = defPrefix
if not suffix then suffix = 1 end
local candidate = prefix .. suffix
while ( TimerBars.FindProfileByName(candidate) ) do
suffix = suffix + 1
candidate = prefix .. suffix
end
return candidate;
end
function TimerBars.CreateProfile(settings, idxSpec, nameProfile)
if not nameProfile then
local prefix = UnitName("player") .. "-"..GetRealmName() .. "."
nameProfile = TimerBars.FindUnusedNumericSuffix(prefix, idxSpec)
end
settings.name = nameProfile
local keyProfile
for k,t in pairs(TimerBars_Globals.Profiles) do
if t.name == nameProfile then
keyProfile = k
break;
end
end
if not keyProfile then
keyProfile = TimerBars.AllocateProfileKey()
end
if TimerBars_CharSettings.Profiles[keyProfile] then
print("TimerBars: Clearing profile ",nameProfile); -- FIXME - Localization
else
print("TimerBars: Adding profile",nameProfile) -- FIXME - Localization
end
if idxSpec then
TimerBars.CharSettings.Specs[idxSpec] = keyProfile
end
TimerBars_CharSettings.Profiles[keyProfile] = settings
TimerBars_Profiles[keyProfile] = settings
return keyProfile
end
function TimerBarsLoader.RoundSettings(t)
for k,v in pairs(t) do
local typ = type(v)
if typ == "number" then
t[k] = tonumber(string.format("%0.4f",v))
elseif typ == "table" then
TimerBarsLoader.RoundSettings(v)
end
end
end
function TimerBarsLoader.MigrateSpec(specSettings, idxSpec)
if not specSettings or not specSettings.Groups or not specSettings.Groups[1] or not
specSettings.Groups[2] or not specSettings.Groups[3] or not specSettings.Groups[4] then
return false
end
-- Round floats to 0.00001, since old versions left really stange values of
-- BarSpacing and BarPadding around
TimerBarsLoader.RoundSettings(specSettings)
specSettings.Spec = nil
specSettings.Locked = nil
specSettings.nGroups = 4
specSettings.BarFont = TimerBarsLoader.FindFontName(specSettings.BarFont)
TimerBars.CreateProfile(specSettings, idxSpec)
return true
end
function TimerBarsLoader.MigrateCharacterSettings()
print("TimerBars: Migrating settings from", TimerBars_Settings["Version"]);
local oldSettings = TimerBars_Settings
TimerBars.ResetCharacter(false)
if ( not oldSettings["Spec"] ) then
TimerBars_Settings = nil
return
end
-- Blink was controlled purely by the alpha of MissingBlink for awhile,
-- But then I introduced an explicit blink_enabled variable. Fill that in