-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRewatch.lua
More file actions
executable file
·2206 lines (2091 loc) · 105 KB
/
Rewatch.lua
File metadata and controls
executable file
·2206 lines (2091 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
-- Rewatch originally by Dezine, Argent Dawn, Europe (Coen van der Wel, Almere, the Netherlands).
-- Also maintained by bobn64 (Tyrahis, Shu'halo).
-- Please give full credit when you want to redistribute or modify this addon!
local rewatch_versioni = 50507;
--------------------------------------------------------------------------------------------------------------[ FUNCTIONS ]----------------------
-- Helper function to safely get specialization (for MoP Classic compatibility)
local function getDruidSpecialization()
-- Try GetSpecialization first (standard MoP API)
if(GetSpecialization) then
local spec = GetSpecialization();
if(spec) then
return spec;
end;
end;
-- Fallback: Try GetPrimaryTalentTree (older method)
if(GetPrimaryTalentTree) then
local tree = GetPrimaryTalentTree();
if(tree) then
-- For druids: 1=Balance, 2=Feral, 3=Guardian, 4=Restoration
return tree;
end;
end;
-- If neither works, return nil (will default to false/not resto)
return nil;
end;
-- Helper function to find a buff by name (for MoP Classic compatibility)
-- In MoP Classic, UnitBuff requires an index, so we need to search through buffs
local function findUnitBuff(unit, spellName, filter)
-- Validate unit parameter
if(not unit or not UnitExists(unit)) then
return nil;
end;
-- Try the new API first (MoP Classic supports UnitBuff with name as second parameter in some cases)
-- But if that fails, loop through buffs
local index = 1;
while true do
local name, icon, count, debuffType, duration, expirationTime, source, isStealable, nameplateShowPersonal, spellId = UnitBuff(unit, index, filter);
if not name then
break; -- No more buffs
end;
if name == spellName then
-- Found the buff, return expiration time (7th return value)
return name, icon, count, debuffType, duration, expirationTime, source, isStealable, nameplateShowPersonal, spellId;
end;
index = index + 1;
end;
return nil; -- Buff not found
end;
-- Helper function to safely set backdrop
local function safeSetBackdrop(frame, backdrop)
if(not frame) then return false; end;
-- Check if method exists and try to call it safely
if(type(frame.SetBackdrop) == "function") then
local success, err = pcall(frame.SetBackdrop, frame, backdrop);
if(success) then
return true;
end;
end;
return false;
end;
-- Helper function to safely set backdrop color
local function safeSetBackdropColor(frame, r, g, b, a)
if(not frame) then return false; end;
-- Check if method exists and try to call it safely
if(type(frame.SetBackdropColor) == "function") then
local success, err = pcall(frame.SetBackdropColor, frame, r, g, b, a or 1);
if(success) then
return true;
end;
end;
return false;
end;
-- display a message to the user in the chat pane
-- msg: the message to pass onto the user
-- return: void
function rewatch_Message(msg)
-- send the message to the chat pane
DEFAULT_CHAT_FRAME:AddMessage(rewatch_loc["prefix"]..msg, 1, 1, 1);
end
-- displays a message to the user in the raidwarning frame
-- msg: the message to pass onto the user
-- return: void
function rewatch_RaidMessage(msg)
-- send the message to the raid warning frame
RaidNotice_AddMessage(RaidWarningFrame, msg, { r = 1, g = 0.49, b = 0.04 });
end
-- loads the internal vars from the savedvariables
-- return: void
function rewatch_OnLoad()
-- reset changed var (options window)
rewatch_changedDimentions = false;
-- has been loaded before, get vars
if(rewatch_load) then
-- support
local supported, update = { "5.4", "5.4.1", 50402, 50403, 50404, 50405, 50406, 50407, 50408, 50409, 50500, 50501, 50502, 50503, 50504, 50505, 50506, 50507 }, false;
for _, version in ipairs(supported) do update = update or (version == rewatch_version) end;
-- supported? then update
if(update) then
update = false;
update = update or (rewatch_version == "5.4");
update = update or (rewatch_version == "5.4.1");
if(update) then
rewatch_load["Font"] = "Interface\\AddOns\\Rewatch\\Fonts\\BigNoodleTitling.ttf";
rewatch_load["Bar"] = "Interface\\AddOns\\Rewatch\\Textures\\Bar.tga";
rewatch_load["SpellBarWidth"] = 85;
rewatch_load["FontSize"] = 11;
rewatch_load["HighlightSize"] = 11;
rewatch_load["SpellBarHeight"] = 12;
rewatch_load["HealthBarHeight"] = 20;
rewatch_load["HealthDeficit"] = 0;
end;
if(rewatch_version < 50404) then
rewatch_load["AltMacro"] = "/shrug";
rewatch_load["CtrlMacro"] = "/cast [@mouseover] "..rewatch_loc["innervate"];
rewatch_load["ShiftMacro"] = "/stopmacro [@mouseover,nodead]\n/target [@mouseover]\n/run rewatch_rezzing = UnitName(\"target\");\n/cast [combat] "..rewatch_loc["rebirth"].."; "..rewatch_loc["revive"].."\n/targetlasttarget";
end;
if(rewatch_version < 50405) then
rewatch_load["BarColor"..rewatch_loc["lifebloom"]].a = 1;
rewatch_load["BarColor"..rewatch_loc["lifebloom"].."2"].a = 1;
rewatch_load["BarColor"..rewatch_loc["lifebloom"].."3"].a = 1;
rewatch_load["BarColor"..rewatch_loc["rejuvenation"]].a = 1;
rewatch_load["BarColor"..rewatch_loc["regrowth"]].a = 1;
rewatch_load["BarColor"..rewatch_loc["wildgrowth"]].a = 1;
rewatch_load["Scaling"] = 100;
rewatch_load["PBOAlpha"] = 0.2;
rewatch_load["Layout"] = "default";
end;
if(rewatch_version < 50407) then
rewatch_load["SortByRole"] = 1;
rewatch_load["ShowSelfFirst"] = 1;
end;
if(rewatch_version < 50507) then
rewatch_load["ShowIncomingHeals"] = 1;
rewatch_load["AltMacro"] = "/cast [@mouseover] "..rewatch_loc["naturescure"];
end;
-- get spec properties (safe check for MoP Classic)
rewatch_loadInt["InRestoSpec"] = false;
local spec = getDruidSpecialization();
if(spec == 4) then
rewatch_loadInt["InRestoSpec"] = true;
end;
rewatch_loadInt["HasBlooming"] = false;
for i=1, NUM_GLYPH_SLOTS do
if(select(6, GetGlyphSocketInfo(i)) == 434) then rewatch_loadInt["HasBlooming"] = true; end;
end;
-- set internal vars from loaded vars
rewatch_loadInt["Loaded"] = true;
rewatch_loadInt["GcdAlpha"] = rewatch_load["GcdAlpha"];
rewatch_loadInt["HideSolo"] = rewatch_load["HideSolo"];
rewatch_loadInt["Hide"] = rewatch_load["Hide"];
rewatch_loadInt["AutoGroup"] = rewatch_load["AutoGroup"];
rewatch_loadInt["WildGrowth"] = rewatch_load["WildGrowth"];
rewatch_loadInt["HealthColor"] = rewatch_load["HealthColor"];
rewatch_loadInt["FrameColor"] = rewatch_load["FrameColor"];
rewatch_loadInt["MarkFrameColor"] = rewatch_load["MarkFrameColor"];
rewatch_loadInt["MaxPlayers"] = rewatch_load["MaxPlayers"];
rewatch_loadInt["Highlighting"] = rewatch_load["Highlighting"];
rewatch_loadInt["Highlighting2"] = rewatch_load["Highlighting2"];
rewatch_loadInt["Highlighting3"] = rewatch_load["Highlighting3"];
rewatch_loadInt["ShowButtons"] = rewatch_load["ShowButtons"];
rewatch_loadInt["BarColor"..rewatch_loc["lifebloom"]] = rewatch_load["BarColor"..rewatch_loc["lifebloom"]];
rewatch_loadInt["BarColor"..rewatch_loc["lifebloom"].."2"] = rewatch_load["BarColor"..rewatch_loc["lifebloom"].."2"];
rewatch_loadInt["BarColor"..rewatch_loc["lifebloom"].."3"] = rewatch_load["BarColor"..rewatch_loc["lifebloom"].."3"];
rewatch_loadInt["BarColor"..rewatch_loc["rejuvenation"]] = rewatch_load["BarColor"..rewatch_loc["rejuvenation"]];
rewatch_loadInt["BarColor"..rewatch_loc["regrowth"]] = rewatch_load["BarColor"..rewatch_loc["regrowth"]];
rewatch_loadInt["BarColor"..rewatch_loc["wildgrowth"]] = rewatch_load["BarColor"..rewatch_loc["wildgrowth"]];
rewatch_loadInt["Labels"] = rewatch_load["Labels"];
rewatch_loadInt["ShowTooltips"] = rewatch_load["ShowTooltips"];
rewatch_loadInt["NameCharLimit"] = rewatch_load["NameCharLimit"];
rewatch_loadInt["Bar"] = rewatch_load["Bar"];
rewatch_loadInt["Font"] = rewatch_load["Font"];
rewatch_loadInt["FontSize"] = rewatch_load["FontSize"];
rewatch_loadInt["HighlightSize"] = rewatch_load["HighlightSize"];
rewatch_loadInt["ForcedHeight"] = rewatch_load["ForcedHeight"];
rewatch_loadInt["OORAlpha"] = rewatch_load["OORAlpha"];
rewatch_loadInt["PBOAlpha"] = rewatch_load["PBOAlpha"];
rewatch_loadInt["HealthDeficit"] = rewatch_load["HealthDeficit"];
rewatch_loadInt["DeficitThreshold"] = rewatch_load["DeficitThreshold"];
rewatch_loadInt["SpellBarWidth"] = rewatch_load["SpellBarWidth"];
rewatch_loadInt["SpellBarHeight"] = rewatch_load["SpellBarHeight"];
rewatch_loadInt["HealthBarHeight"] = rewatch_load["HealthBarHeight"];
rewatch_loadInt["Scaling"] = rewatch_load["Scaling"];
-- Force vertical stacking: always 1 frame per row
rewatch_loadInt["NumFramesWide"] = 1;
rewatch_load["NumFramesWide"] = 1;
rewatch_loadInt["AltMacro"] = rewatch_load["AltMacro"];
rewatch_loadInt["CtrlMacro"] = rewatch_load["CtrlMacro"];
rewatch_loadInt["ShiftMacro"] = rewatch_load["ShiftMacro"];
rewatch_loadInt["Layout"] = rewatch_load["Layout"];
rewatch_loadInt["SortByRole"] = rewatch_load["SortByRole"];
rewatch_loadInt["ShowIncomingHeals"] = rewatch_load["ShowIncomingHeals"];
rewatch_loadInt["ShowSelfFirst"] = rewatch_load["ShowSelfFirst"];
rewatch_loadInt["LockP"] = true;
-- update later
rewatch_changed = true;
-- apply possible changes
rewatch_DoUpdate();
-- set current version
rewatch_version = rewatch_versioni;
-- reset it all when new or no longer supported
else rewatch_load = nil; rewatch_version = nil; end;
-- not loaded before, initialise and welcome new user
else
rewatch_load = {};
rewatch_load["GcdAlpha"], rewatch_load["HideSolo"], rewatch_load["Hide"], rewatch_load["AutoGroup"] = 1, 0, 0, 1;
rewatch_load["HealthColor"] = { r=0; g=0.7; b=0};
rewatch_load["FrameColor"] = { r=0; g=0; b=0; a=0.3 };
rewatch_load["MarkFrameColor"] = { r=0; g=1; b=0; a=1 };
rewatch_load["BarColor"..rewatch_loc["lifebloom"]] = { r=0.6; g=0; b=0, a=1};
rewatch_load["BarColor"..rewatch_loc["lifebloom"].."2"] = { r=1; g=0.5; b=0, a=1};
rewatch_load["BarColor"..rewatch_loc["lifebloom"].."3"] = { r=0; g=0; b=0.8, a=1};
rewatch_load["BarColor"..rewatch_loc["rejuvenation"]] = { r=0.85; g=0.15; b=0.80, a=1};
rewatch_load["BarColor"..rewatch_loc["regrowth"]] = { r=0.05; g=0.3; b=0.1, a=1};
rewatch_load["BarColor"..rewatch_loc["wildgrowth"]] = { r=0.5; g=0.8; b=0.3, a=1};
rewatch_load["Labels"] = 0;
rewatch_load["SpellBarWidth"] = 85; rewatch_load["SpellBarHeight"] = 6;
rewatch_load["HealthBarHeight"] = 30; rewatch_load["Scaling"] = 100;
-- Force vertical stacking: always 1 frame per row
rewatch_load["NumFramesWide"] = 1;
rewatch_load["WildGrowth"] = 1;
rewatch_load["Bar"] = "Interface\\AddOns\\Rewatch\\Textures\\Bar.tga";
rewatch_load["Font"] = "Interface\\AddOns\\Rewatch\\Fonts\\BigNoodleTitling.ttf";
rewatch_load["FontSize"] = 11; rewatch_load["HighlightSize"] = 11;
rewatch_load["HealthDeficit"] = 0;
rewatch_load["DeficitThreshold"] = 0;
rewatch_load["ForcedHeight"] = 0;
rewatch_load["OORAlpha"] = 0.3;
rewatch_load["PBOAlpha"] = 0.2;
rewatch_load["NameCharLimit"] = 0; rewatch_load["MaxPlayers"] = 0;
rewatch_load["AltMacro"] = "/shrug";
rewatch_load["CtrlMacro"] = "/cast [@mouseover] "..rewatch_loc["innervate"];
rewatch_load["ShiftMacro"] = "/stopmacro [@mouseover,nodead]\n/target [@mouseover]\n/run rewatch_rezzing = UnitName(\"target\");\n/cast [combat] "..rewatch_loc["rebirth"].."; "..rewatch_loc["revive"].."\n/targetlasttarget";
rewatch_load["Layout"] = "default";
rewatch_load["SortByRole"] = 1;
rewatch_load["ShowSelfFirst"] = 1;
rewatch_load["ShowIncomingHeals"] = 1;
rewatch_load["Highlighting"] = {
-- todo: pandaria defaults
};
rewatch_load["Highlighting2"] = {
-- todo: pandaria defaults
};
rewatch_load["Highlighting3"] = {
-- todo: pandaria defaults
};
rewatch_load["ShowButtons"] = 1;
rewatch_load["ShowTooltips"] = 1;
rewatch_RaidMessage(rewatch_loc["welcome"]);
rewatch_Message(rewatch_loc["welcome"]);
rewatch_Message(rewatch_loc["info"]);
-- set current version
rewatch_version = rewatch_versioni;
end;
-- allow setup choice
if(rewatch_load["Installed"] ~= 1) then
rewatch_Layout(true);
end;
end;
-- pop up a window to allow the user to switch easily between layouts
-- firstRun: determines if the text shown explain this is the first run
function rewatch_Layout(firstRun)
StaticPopupDialogs["RewatchInstaller"] = {
button1 = "Minimalist",
button2 = "Compact",
button3 = "No thanks!",
OnAccept = function()
rewatch_Message("Setting layout to 'Minimalist'.");
-- Clear existing frames first
if(not InCombatLockdown()) then
rewatch_Clear();
end;
rewatch_load["ShowButtons"] = 0;
rewatch_load["NumFramesWide"] = 1;
rewatch_load["SpellBarWidth"] = 25;
rewatch_load["SpellBarHeight"] = 13;
rewatch_load["HealthBarHeight"] = 110;
rewatch_load["Layout"] = "vertical";
rewatch_loadInt["ShowButtons"] = rewatch_load["ShowButtons"];
rewatch_loadInt["NumFramesWide"] = rewatch_load["NumFramesWide"];
rewatch_loadInt["SpellBarWidth"] = rewatch_load["SpellBarWidth"];
rewatch_loadInt["SpellBarHeight"] = rewatch_load["SpellBarHeight"];
rewatch_loadInt["HealthBarHeight"] = rewatch_load["HealthBarHeight"];
rewatch_loadInt["Layout"] = rewatch_load["Layout"];
rewatch_changed = true;
rewatch_DoUpdate();
end,
OnCancel = function()
rewatch_Message("Setting layout to 'Compact'.");
-- Clear existing frames first
if(not InCombatLockdown()) then
rewatch_Clear();
end;
rewatch_load["ShowButtons"] = 1;
rewatch_load["NumFramesWide"] = 1;
rewatch_load["SpellBarWidth"] = 60;
rewatch_load["SpellBarHeight"] = 13;
rewatch_load["HealthBarHeight"] = 110;
rewatch_load["Layout"] = "vertical";
rewatch_loadInt["ShowButtons"] = rewatch_load["ShowButtons"];
rewatch_loadInt["NumFramesWide"] = rewatch_load["NumFramesWide"];
rewatch_loadInt["SpellBarWidth"] = rewatch_load["SpellBarWidth"];
rewatch_loadInt["SpellBarHeight"] = rewatch_load["SpellBarHeight"];
rewatch_loadInt["HealthBarHeight"] = rewatch_load["HealthBarHeight"];
rewatch_loadInt["Layout"] = rewatch_load["Layout"];
rewatch_changed = true;
rewatch_DoUpdate();
end,
OnAlt = function()
rewatch_Message("Nothing was changed!");
end,
timeout = 0,
whileDead = true,
hideOnEscape = false,
preferredIndex = 3,
notClosableByLogout = true
};
if(firstRun) then
StaticPopupDialogs["RewatchInstaller"].text = [[-----------------------[ Rewatch ]-----------------------
Welcome to Rewatch! As a quick assist, would you like to try one of the following two layout presets?
You can always call this popup again with "/rewatch layout". It pops up now because it's the first run of Rewatch (50507+).]];
else
StaticPopupDialogs["RewatchInstaller"].text = [[-----------------------[ Rewatch ]-----------------------
How would you like to try one of the following two layout presets?
You can always call this popup again with "/rewatch layout".]];
end;
StaticPopup_Show("RewatchInstaller");
rewatch_load["Installed"] = 1;
end;
-- cut a name by the specified name character limit
-- name: the name to be cut
-- return: the cut name
function rewatch_CutName(name)
-- strip realm name
local s = name:find("-"); if(s ~= nil) then name = name:sub(1, s-1).."*"; end;
-- fix length
if((rewatch_loadInt["NameCharLimit"] == 0) or (name:len() < rewatch_loadInt["NameCharLimit"])) then return name;
else return name:sub(1, rewatch_loadInt["NameCharLimit"]); end;
end;
-- update frame dimentions by changes in component sizes/margins
-- return: void
function rewatch_UpdateOffset()
if(rewatch_loadInt["Layout"] == "default") then
rewatch_loadInt["FrameWidth"] = (rewatch_loadInt["SpellBarWidth"]) * (rewatch_loadInt["Scaling"]/100);
rewatch_loadInt["ButtonSize"] = (rewatch_loadInt["SpellBarWidth"] / 5) * (rewatch_loadInt["Scaling"]/100);
rewatch_loadInt["FrameHeight"] = ((rewatch_loadInt["SpellBarHeight"]*(3+rewatch_loadInt["WildGrowth"])) + rewatch_loadInt["HealthBarHeight"]) * (rewatch_loadInt["Scaling"]/100) + (rewatch_loadInt["ButtonSize"]*rewatch_loadInt["ShowButtons"]);
elseif(rewatch_loadInt["Layout"] == "vertical") then
rewatch_loadInt["FrameWidth"] = ((rewatch_loadInt["SpellBarHeight"]*(3+rewatch_loadInt["WildGrowth"])) + rewatch_loadInt["HealthBarHeight"]) * (rewatch_loadInt["Scaling"]/100);
rewatch_loadInt["ButtonSize"] = (rewatch_loadInt["HealthBarHeight"] * (rewatch_loadInt["Scaling"]/100)) / 5;
rewatch_loadInt["FrameHeight"] = (rewatch_loadInt["SpellBarWidth"]) * (rewatch_loadInt["Scaling"]/100);
end;
end;
-- update everything
-- return: void
function rewatch_DoUpdate()
rewatch_UpdateOffset();
rewatch_CreateOptions();
rewatch_gcd:SetAlpha(rewatch_loadInt["GcdAlpha"]);
for i=1,rewatch_i-1 do local val = rewatch_bars[i]; if(val and val["Frame"]) then safeSetBackdropColor(val["Frame"], rewatch_loadInt["FrameColor"].r, rewatch_loadInt["FrameColor"].g, rewatch_loadInt["FrameColor"].b, rewatch_loadInt["FrameColor"].a); end; end;
if(((rewatch_i == 2) and (rewatch_loadInt["HideSolo"] == 1)) or (rewatch_loadInt["Hide"] == 1)) then rewatch_f:Hide(); else rewatch_ShowFrame(); end;
rewatch_OptionsFromData(true); rewatch_UpdateSwatch();
end;
-- pops up the tooltip bar
-- data: the data to put in the tooltip. either a spell name or player name.
-- return: void
function rewatch_SetTooltip(data)
-- ignore if not wanted
if(rewatch_loadInt["ShowTooltips"] ~= 1) then return; end;
-- is it a spell?
local md = rewatch_GetSpellId(data);
if(md < 0) then
-- if not, then is it a player?
md = rewatch_GetPlayer(data);
if(md >= 0) then
GameTooltip_SetDefaultAnchor(GameTooltip, UIParent);
GameTooltip:SetUnit(rewatch_bars[md]["Player"]);
end; -- do nothing with the tooltip if not
else
GameTooltip_SetDefaultAnchor(GameTooltip, UIParent);
GameTooltip:SetSpellBookItem(md, BOOKTYPE_SPELL);
end;
end;
-- gets the spell ID of the highest rank of the specified spell
-- spellName: the name of the spell to get the highest ranked spellId from
-- return: the corresponding spellId
function rewatch_GetSpellId(spellName)
-- get spell info and highest rank, return if the user can't cast it (not learned, etc)
local name, rank, icon = GetSpellInfo(spellName);
if(name == nil) then return -1; end;
-- loop through all book spells, return the number if it matches above data
local i, ispell, irank = 1, GetSpellBookItemName(1, BOOKTYPE_SPELL);
repeat
if ((ispell == name) and ((rank == irank) or (not irank))) then return i; end;
i, ispell, irank = i+1, GetSpellBookItemName(i+1, BOOKTYPE_SPELL);
until (not ispell);
-- return default -1
return -1;
end;
-- clears the entire list and resets it
-- return: void
function rewatch_Clear()
-- call each playerframe's Hide method
for i=1,rewatch_i-1 do local val = rewatch_bars[i]; if(val) then rewatch_HidePlayer(i); end; end;
rewatch_bars = nil; rewatch_bars = {}; rewatch_i = 1;
end;
-- get the number of the supplied player's place in the player table, or -1
-- player: name of the player to search for
-- return: the supplied player's table index, or -1 if not found
function rewatch_GetPlayer(player)
-- prevent nil entries
if(not player) then return -2; end;
-- for every seen player; return if the name matches the supplied name
local guid = UnitGUID(player);
-- ignore pet guid; this changes sometimes
if(not UnitIsPlayer(player)) then guid = false; end;
-- browse list and return corresponding id
for i=1,rewatch_i-1 do local val = rewatch_bars[i]; if(val) then
if(not guid) then
if(val["Player"] == player) then return i; end;
elseif(val["UnitGUID"] == guid) then return i;
-- recognise pets (Playername-pet != Petname)
elseif(val["Pet"]) then if(UnitGUID(val["Player"]) == UnitGUID(player)) then return i; end;
-- load bug, UnitGUID returns nil when not fully loaded, even on "player"
elseif((player == UnitName("player")) and (not val["UnitGUID"])) then val["UnitGUID"] = guid; return i; end;
end; end;
-- return -1 if not found
return -1;
end;
-- checks if the player or pet is in the group
-- player: name of the player or pet to check for
-- return: true, if the player is the user, or in the user's party or raid (or pet); false elsewise
function rewatch_InGroup(player)
-- catch a self-check; return true if searching for the user itself
if(UnitName("player") == player) then return true;
else
if((GetNumGroupMembers() > 0) and IsInRaid()) then
if(UnitPlayerOrPetInRaid(player)) then
return true;
end;
elseif(GetNumSubgroupMembers() > 0) then
if(UnitPlayerOrPetInParty(player)) then
return true;
end;
end;
end;
-- return
return false;
end;
-- colors the frame corresponding to the player with playerid accordingly
-- playerId: the index number of the player in the player table
-- return: void
function rewatch_SetFrameBG(playerId)
local frame = rewatch_bars[playerId]["Frame"];
if(not frame) then return; end;
if(rewatch_bars[playerId]["Notify3"]) then
safeSetBackdropColor(frame, 1.0, 0.0, 0.0, 1);
elseif(rewatch_bars[playerId]["Corruption"]) then
if(rewatch_bars[playerId]["CorruptionType"] == "Poison") then
safeSetBackdropColor(frame, 0.0, 0.3, 0, 1);
elseif(rewatch_bars[playerId]["CorruptionType"] == "Curse") then
safeSetBackdropColor(frame, 0.5, 0.0, 0.5, 1);
else
safeSetBackdropColor(frame, 0.0, 0.0, 0.5, 1);
end;
elseif(rewatch_bars[playerId]["Notify2"]) then
safeSetBackdropColor(frame, 1.0, 0.5, 0.1, 1);
elseif(rewatch_bars[playerId]["Notify"]) then
safeSetBackdropColor(frame, 0.9, 0.8, 0.2, 1);
elseif(rewatch_bars[playerId]["Mark"]) then
safeSetBackdropColor(frame, rewatch_loadInt["MarkFrameColor"].r, rewatch_loadInt["MarkFrameColor"].g, rewatch_loadInt["MarkFrameColor"].b, rewatch_loadInt["MarkFrameColor"].a);
else
safeSetBackdropColor(frame, rewatch_loadInt["FrameColor"].r, rewatch_loadInt["FrameColor"].g, rewatch_loadInt["FrameColor"].b, rewatch_loadInt["FrameColor"].a);
end;
end;
-- trigger the cooldown overlays
-- return: void
function rewatch_TriggerCooldown()
-- get global cooldown, and trigger it on all frames
local start, duration, enabled = GetSpellCooldown(rewatch_loc["rejuvenation"]); -- some non-cd spell
if(rewatch_gcd and rewatch_gcd.SetCooldown) then
rewatch_gcd:SetCooldown(start, duration);
elseif(CooldownFrame_SetTimer) then
-- Fallback to old API if available
CooldownFrame_SetTimer(rewatch_gcd, start, duration, enabled);
end;
end;
-- show the first rewatch frame, with the last 'flash' of the cooldown effect
-- return: void
function rewatch_ShowFrame()
rewatch_f:Show();
if(rewatch_gcd and rewatch_gcd.SetCooldown) then
rewatch_gcd:SetCooldown(GetTime()-1, 1.25);
elseif(CooldownFrame_SetTimer) then
-- Fallback to old API if available
CooldownFrame_SetTimer(rewatch_gcd, GetTime()-1, 1.25, 1);
end;
end;
-- adjusts the parent frame container's height
-- return: void
function rewatch_AlterFrame()
-- forcedHeight mode only alters width
if(rewatch_loadInt["ForcedHeight"] > 0) then
rewatch_AlterFrameWidth();
else
-- set height and width according to number of frames
local num = rewatch_f:GetNumChildren()-1;
-- Force vertical stacking: always use 1 frame per row
local numFramesWide = 1;
local height = math.max(rewatch_loadInt["ForcedHeight"], math.ceil(num/numFramesWide)) * rewatch_loadInt["FrameHeight"];
local width = math.min(numFramesWide, math.max(num, 1)) * rewatch_loadInt["FrameWidth"];
-- apply
rewatch_f:SetWidth(width); rewatch_f:SetHeight(height+10);
rewatch_gcd:SetWidth(rewatch_f:GetWidth()); rewatch_gcd:SetHeight(rewatch_f:GetHeight());
-- hide/show on solo
if(((num == 1) and (rewatch_loadInt["HideSolo"] == 1)) or (rewatch_loadInt["Hide"] == 1)) then rewatch_f:Hide(); else rewatch_f:Show(); end;
-- make sure frames have a solid height and width (bugfix)
for j=1,rewatch_i-1 do local val = rewatch_bars[j]; if(val) then
if(not((val["Frame"]:GetWidth() == rewatch_loadInt["FrameWidth"]) and (val["Frame"]:GetHeight() == rewatch_loadInt["FrameHeight"]))) then
val["Frame"]:SetWidth(rewatch_loadInt["FrameWidth"]); val["Frame"]:SetHeight(rewatch_loadInt["FrameHeight"]);
end;
end; end;
end;
end;
-- alter the frame width (instead of height) in forcedHeight mode (assumed)
-- return: void
function rewatch_AlterFrameWidth()
-- get number of frames
local num = rewatch_f:GetNumChildren()-1;
-- for each frame
local framesPerY, maxPerY = {}, 0;
for j=1,rewatch_i-1 do local val = rewatch_bars[j]; if(val) then
-- save Y to list
if(framesPerY[val["Frame"]:GetTop()]) then framesPerY[val["Frame"]:GetTop()] = framesPerY[val["Frame"]:GetTop()]+1; maxPerY = max(maxPerY, framesPerY[val["Frame"]:GetTop()]);
else framesPerY[val["Frame"]:GetTop()] = 1; maxPerY = max(maxPerY, 1); end;
-- make sure frames have a solid height and width (bugfix)
if(not((val["Frame"]:GetWidth() == rewatch_loadInt["FrameWidth"]) and (val["Frame"]:GetHeight() == rewatch_loadInt["FrameHeight"]))) then
val["Frame"]:SetWidth(rewatch_loadInt["FrameWidth"]); val["Frame"]:SetHeight(rewatch_loadInt["FrameHeight"]);
end;
end; end;
-- set width according to number of frames
-- Force vertical stacking: always use 1 frame per row
rewatch_loadInt["NumFramesWide"] = 1;
local numFramesWide = 1;
local height = rewatch_loadInt["ForcedHeight"] * rewatch_loadInt["FrameHeight"];
local width = math.min(numFramesWide, math.max(num, 1)) * rewatch_loadInt["FrameWidth"];
-- apply
rewatch_f:SetWidth(width+15); rewatch_f:SetHeight(height);
rewatch_gcd:SetWidth(rewatch_f:GetWidth()); rewatch_gcd:SetHeight(rewatch_f:GetHeight());
-- hide/show on solo
if(((num == 1) and (rewatch_loadInt["HideSolo"] == 1)) or (rewatch_loadInt["Hide"] == 1)) then rewatch_f:Hide(); else rewatch_f:Show(); end;
end;
-- snap the supplied frame to the grid when it's placed on a rewatch_f frame
-- frame: the frame to snap to a grid
-- return: void
function rewatch_SnapToGrid(frame)
-- return if in combat
if(InCombatLockdown()) then return -1; end;
-- get parent frame
local parent = frame:GetParent();
if(parent ~= UIParent) then
-- get frame's location relative to it's parent's
local dx, dy = frame:GetLeft()-parent:GetLeft(), frame:GetTop()-parent:GetTop();
-- make it snap (make dx a number closest to frame:GetWidth*n...)
dx = math.floor((dx/rewatch_loadInt["FrameWidth"])+0.5) * rewatch_loadInt["FrameWidth"];
dy = math.floor((dy/rewatch_loadInt["FrameHeight"])+0.5) * rewatch_loadInt["FrameHeight"];
-- check if this is outside the frame, remove it
if((dx < 0) or (dy > 0) or (dx+5 >= parent:GetWidth()) or ((dy*-1)+5 >= parent:GetHeight())) then
-- remove it from it's parent
frame:SetParent(UIParent); rewatch_AlterFrame();
rewatch_Message(rewatch_loc["offFrame"]);
-- if it's in the frame, move it
else
-- set id and get children
frame:SetID(1337); local children = { parent:GetChildren() };
-- move a frame to a new position if this frame covers it now
for i, child in ipairs(children) do if(child:GetID() ~= 1337) then
if((child:GetLeft() and (i>1))) then
if((math.abs(dx - (child:GetLeft()-parent:GetLeft())) < 1) and (math.abs(dy - (child:GetTop()-parent:GetTop())) < 1)) then
local x, y = rewatch_GetFramePos(parent); child:ClearAllPoints(); child:SetPoint("TOPLEFT", parent, "TOPLEFT", x, y);
child:SetPoint("BOTTOMRIGHT", parent, "TOPLEFT", x+rewatch_loadInt["FrameWidth"], y-rewatch_loadInt["FrameHeight"]); break;
end;
end;
end; end;
-- reset id and apply the snap location
frame:SetID(0); frame:ClearAllPoints(); frame:SetPoint("TOPLEFT", parent, "TOPLEFT", dx, dy);
frame:SetPoint("BOTTOMRIGHT", parent, "TOPLEFT", dx+rewatch_loadInt["FrameWidth"], dy-rewatch_loadInt["FrameHeight"]);
-- now, if in forced height mode, recalculate frame width
if(rewatch_loadInt["ForcedHeight"] > 0) then rewatch_AlterFrameWidth(); end;
end;
else
-- check if there's need to snap it back onto the frame
local dx, dy = frame:GetLeft()-rewatch_f:GetLeft(), frame:GetTop()-rewatch_f:GetTop();
if((dx > 0) and (dy < 0) and (dx < rewatch_f:GetWidth()) and (dy < rewatch_f:GetHeight())) then
frame:SetParent(rewatch_f); rewatch_AlterFrame();
rewatch_SnapToGrid(frame); rewatch_Message(rewatch_loc["backOnFrame"]);
end;
end;
end;
-- return the first available empty spot in the frame
-- frame: the outline (parent) frame in which the player frame should be positioned
-- return: position coordinates; { x, y }
function rewatch_GetFramePos(frame)
-- assume: there is at least one free position in the specified parent frame
local children = { frame:GetChildren() }; local x, y, found = 0, 0, false;
-- Force vertical stacking: always use 1 frame per row
local numFramesWide = 1;
-- walk through the available spots, left to right, top to bottom
for dy=0, 1-(ceil(frame:GetNumChildren()/numFramesWide)), -1 do for dx=0, numFramesWide-1 do
found, x, y = false, rewatch_loadInt["FrameWidth"]*dx, rewatch_loadInt["FrameHeight"]*dy;
-- check if there's a frame here already
for i, child in ipairs(children) do
if((child:GetLeft() and (i>1))) then
if((math.abs(x - (child:GetLeft()-frame:GetLeft())) < 1) and (math.abs(y - (child:GetTop()-frame:GetTop())) < 1)) then
found = true; break; --[[ break for children loop ]] end;
end;
end;
-- if not, we found a spot and we should break!
if(not found) then break; --[[ break for dxloop ]] end;
end; if(not found) then break; --[[ break for dy loop ]] end; end;
-- return either the found spot, or a formula based on array positioning (fallback)
if(found) then
-- Force vertical stacking: always use 1 frame per row
local numFramesWide = 1;
return frame:GetWidth()*((rewatch_i-1)%numFramesWide), math.floor((rewatch_i-1)/numFramesWide) * frame:GetHeight() * -1;
else
if(rewatch_loadInt["ForcedHeight"] > 0) then if(y < 1-frame:GetHeight()) then
-- Force vertical stacking: don't auto-increase width
rewatch_loadInt["NumFramesWide"] = 1;
return rewatch_GetFramePos(frame);
end; end;
return x, y;
end;
end;
-- compares the current player table to the party/raid schedule
-- return: void
function rewatch_ProcessGroup()
local name, i, n;
local names = {};
-- remove non-grouped players
for i=1,rewatch_i-1 do if(rewatch_bars[i]) then
if(not (rewatch_InGroup(rewatch_bars[i]["Player"]) or rewatch_bars[i]["Pet"])) then rewatch_HidePlayer(i); end;
end; end;
-- add self
if((rewatch_i == 1) and (rewatch_loadInt["ShowSelfFirst"] == 1)) then
rewatch_AddPlayer(UnitName("player"), nil);
end;
-- process raid group
if(IsInRaid()) then
n = GetNumGroupMembers();
-- for each group member, if he's not in the list, add him
for i=1, n do
name = GetRaidRosterInfo(i);
if((name) and (rewatch_GetPlayer(name) == -1)) then
table.insert(names, name);
end;
end;
-- process party group (only when not in a raid)
else
n = GetNumSubgroupMembers();
-- for each group member, if he's not in the list, add him
for i=1, n + 1 do
if(i > n) then name = UnitName("player"); else name = UnitName("party"..i); end;
if((name) and (rewatch_GetPlayer(name) == -1)) then
table.insert(names, name);
end;
end;
end;
-- sort by role
if(rewatch_loadInt["SortByRole"] == 1) then
local healers, tanks, others = {}, {}, {};
for i, name in pairs(names) do
role = UnitGroupRolesAssigned(name);
if(role == "TANK") then
table.insert(tanks, name);
elseif(role == "HEALER") then
table.insert(healers, name);
else table.insert(others, name); end;
end;
-- add players
rewatch_AddPlayers(tanks);
rewatch_AddPlayers(healers);
rewatch_AddPlayers(others);
-- or just by groups
else
rewatch_AddPlayers(names);
end;
end;
-- shortcut to allow adding a list of players at once
-- for further reference, see rewatch_AddPlayer()
function rewatch_AddPlayers(names)
for i, name in ipairs(names) do
rewatch_AddPlayer(name, nil);
end;
end;
-- create a spell button with icon and add it to the global player table
-- spellName: the name of the spell to create a bar for
-- playerId: the index number of the player in the player table
-- btnIcon: the string path and name with extension of the icon to use
-- relative: the name of the rewatch_bars[n] key, referencing to the relative cast bar for layout
-- return: the created spell button reference
function rewatch_CreateButton(spellName, playerId, btnIcon, relative)
-- build button
local button = CreateFrame("BUTTON", nil, rewatch_bars[playerId]["Frame"], "SecureActionButtonTemplate");
button:SetWidth(rewatch_loadInt["ButtonSize"]); button:SetHeight(rewatch_loadInt["ButtonSize"]);
button:SetPoint("TOPLEFT", rewatch_bars[playerId][relative], "BOTTOMLEFT", rewatch_loadInt["ButtonSize"]*rewatch_buttons[spellName]["Offset"], 0);
-- arrange clicking
button:RegisterForClicks("LeftButtonDown", "RightButtonDown");
button:SetAttribute("unit", rewatch_bars[playerId]["Player"]); button:SetAttribute("type1", "spell"); button:SetAttribute("spell1", spellName);
-- texture
button:SetNormalTexture(btnIcon); button:GetNormalTexture():SetTexCoord(0.1, 0.9, 0.1, 0.9);
button:SetHighlightTexture("Interface\\Buttons\\ButtonHilight-Square.blp");
-- apply modifier-click for nature's swiftness
if(spellName == rewatch_loc["healingtouch"]) then
button:SetAttribute("*type1", "macro"); button:SetAttribute("*macrotext1", "/stopcasting\n/cast "..rewatch_loc["naturesswiftness"].."\n/stopcasting\n/cast [target=mouseover] "..rewatch_loc["healingtouch"]);
button:SetAttribute("type2", "macro"); button:SetAttribute("macrotext2", "/stopcasting\n/cast "..rewatch_loc["naturesswiftness"].."\n/stopcasting\n/cast [target=mouseover] "..rewatch_loc["healingtouch"]);
elseif(spellName == rewatch_loc["nourish"]) then
button:SetAttribute("*type1", "macro"); button:SetAttribute("*macrotext1", "/stopcasting\n/cast "..rewatch_loc["naturesswiftness"].."\n/stopcasting\n/cast [target=mouseover] "..rewatch_loc["nourish"]);
button:SetAttribute("type2", "macro"); button:SetAttribute("macrotext2", "/stopcasting\n/cast "..rewatch_loc["naturesswiftness"].."\n/stopcasting\n/cast [target=mouseover] "..rewatch_loc["nourish"]);
elseif(spellName == rewatch_loc["removecorruption"]) then
-- Use mouseover targeting for Remove Corruption
button:SetAttribute("*type1", "macro"); button:SetAttribute("*macrotext1", "/stopcasting\n/cast [@mouseover,exists,help] "..rewatch_loc["removecorruption"].."; "..rewatch_loc["removecorruption"]);
button:SetAlpha(0.2);
elseif(spellName == rewatch_loc["naturescure"]) then
-- Use mouseover targeting for Nature's Cure
button:SetAttribute("*type1", "macro"); button:SetAttribute("*macrotext1", "/stopcasting\n/cast [@mouseover,exists,help] "..rewatch_loc["naturescure"].."; "..rewatch_loc["naturescure"]);
button:SetAlpha(0.2);
end;
-- apply tooltip support
button:SetScript("OnEnter", function() rewatch_SetTooltip(spellName); end);
button:SetScript("OnLeave", function() GameTooltip:Hide(); end);
-- return
return button;
end;
-- create a spell bar with text and add it to the global player table
-- spellName: the name of the spell to create a bar for
-- playerId: the index number of the player in the player table
-- relative: the name of the rewatch_bars[n] key, referencing to the relative castbar for layout
-- return: the created spell bar reference
function rewatch_CreateBar(spellName, playerId, relative)
-- create the bar
local b = CreateFrame("STATUSBAR", spellName..playerId, rewatch_bars[playerId]["Frame"], "TextStatusBar");
b:SetStatusBarTexture(rewatch_loadInt["Bar"]);
b:GetStatusBarTexture():SetHorizTile(false);
b:GetStatusBarTexture():SetVertTile(false);
-- arrange layout
if(rewatch_loadInt["Layout"] == "default") then
b:SetWidth(rewatch_loadInt["SpellBarWidth"] * (rewatch_loadInt["Scaling"]/100));
b:SetHeight(rewatch_loadInt["SpellBarHeight"] * (rewatch_loadInt["Scaling"]/100));
b:SetPoint("TOPLEFT", rewatch_bars[playerId][relative], "BOTTOMLEFT", 0, 0);
b:SetOrientation("horizontal");
elseif(rewatch_loadInt["Layout"] == "vertical") then
b:SetHeight(rewatch_loadInt["SpellBarWidth"] * (rewatch_loadInt["Scaling"]/100));
b:SetWidth(rewatch_loadInt["SpellBarHeight"] * (rewatch_loadInt["Scaling"]/100));
b:SetPoint("TOPLEFT", rewatch_bars[playerId][relative], "TOPRIGHT", 0, 0);
b:SetOrientation("vertical");
end;
-- if it's lifebloom, color frame background to 3rd stack of LB color
if(spellName == rewatch_loc["lifebloom"]) then
b:SetStatusBarColor(rewatch_loadInt["BarColor"..spellName.."3"].r, rewatch_loadInt["BarColor"..spellName.."3"].g, rewatch_loadInt["BarColor"..spellName.."3"].b, rewatch_loadInt["PBOAlpha"]);
else
b:SetStatusBarColor(rewatch_loadInt["BarColor"..spellName].r, rewatch_loadInt["BarColor"..spellName].g, rewatch_loadInt["BarColor"..spellName].b, rewatch_loadInt["PBOAlpha"]);
end;
-- set bar reach
b:SetMinMaxValues(0, 10); b:SetValue(10);
-- put text in bar
b.text = b:CreateFontString("$parentText", "ARTWORK", "GameFontHighlightSmall");
b.text:SetPoint("RIGHT", b); b.text:SetAllPoints();
if(rewatch_loadInt["Labels"] == 1) then b.text:SetText(spellName); else b.text:SetText(""); end;
-- overlay cast button
local bc = CreateFrame("BUTTON", nil, b, "SecureActionButtonTemplate");
bc:SetWidth(b:GetWidth());
bc:SetHeight(b:GetHeight());
bc:SetPoint("TOPLEFT", b, "TOPLEFT", 0, 0);
bc:RegisterForClicks("LeftButtonDown", "RightButtonDown"); bc:SetAttribute("type1", "spell"); bc:SetAttribute("unit", rewatch_bars[playerId]["Player"]);
bc:SetAttribute("spell1", spellName); bc:SetHighlightTexture("Interface\\Buttons\\WHITE8x8.blp"); bc:SetAlpha(0.2);
-- apply modifier-clicks for Genesis on Rejuvenation bar only
if(spellName == rewatch_loc["rejuvenation"]) then
bc:SetAttribute("*type1", "macro"); bc:SetAttribute("*macrotext1", "/cast "..rewatch_loc["genesis"]);
bc:SetAttribute("type2", "macro"); bc:SetAttribute("macrotext2", "/cast "..rewatch_loc["genesis"]);
end;
-- apply modifier-clicks for nature's swiftness on Regrowth bar only
if(spellName == rewatch_loc["regrowth"]) then
bc:SetAttribute("*type1", "macro"); bc:SetAttribute("*macrotext1", "/stopcasting\n/cast "..rewatch_loc["naturesswiftness"].."\n/stopcasting\n/cast [target=mouseover] "..rewatch_loc["regrowth"]);
bc:SetAttribute("type2", "macro"); bc:SetAttribute("macrotext2", "/stopcasting\n/cast "..rewatch_loc["naturesswiftness"].."\n/stopcasting\n/cast [target=mouseover] "..rewatch_loc["regrowth"]);
end;
-- apply tooltip support
bc:SetScript("OnEnter", function() rewatch_SetTooltip(spellName); end);
bc:SetScript("OnLeave", function() GameTooltip:Hide(); end);
-- return the reference to the spell bar
return b;
end;
-- update a bar by resetting spell duration
-- spellName: the name of the spell to reset it's duration from
-- player: player name
-- stacks: if given, the amount of LB stacks
-- return: void
function rewatch_UpdateBar(spellName, player, stacks)
-- this shouldn't happen, but just in case
if(not spellName) then return; end;
-- get player
local playerId = rewatch_GetPlayer(player);
-- add if needed
if(playerId < 0) then
if((rewatch_loadInt["AutoGroup"] == 0) or (spellName == rewatch_loc["wildgrowth"])) then return; end;
playerId = rewatch_AddPlayer(UnitName(player), nil);
if(playerId < 0) then return; end;
end;
-- lag may cause this 'inconsistency', fixie here
if(spellName == rewatch_loc["wildgrowth"]) then rewatch_bars[playerId]["RevertingWG"] = 0; end;
-- if the spell exists
if(rewatch_bars[playerId][spellName]) then
-- get buff duration (duration and expirationTime from UnitBuff are already haste-adjusted)
local name, icon, count, debuffType, buffDuration, expirationTime, source, isStealable, nameplateShowPersonal, spellId = findUnitBuff(player, spellName, "PLAYER");
local a = expirationTime; -- expiration time
if(a == nil) then return; end;
local b = a - GetTime();
-- update lifebloom stack counter
local c = "";
if(spellName == rewatch_loc["lifebloom"]) then
-- Use stack count from UnitBuff if available, otherwise use the stacks parameter, otherwise default to 1
local currentStacks = count or stacks or rewatch_bars[playerId]["LifebloomStacks"] or 1;
currentStacks = tonumber(currentStacks) or 1;
-- Update stored stack count
rewatch_bars[playerId]["LifebloomStacks"] = currentStacks;
-- Set color suffix: 1 stack = "", 2 stacks = "2", 3 stacks = "3"
if(currentStacks >= 3) then
c = "3";
elseif(currentStacks >= 2) then
c = "2";
else
c = ""; -- 1 stack uses the base color name
end;
-- third stack is applied without SPELL_AURA_APPLIED(_DOSE) so it must be fixed here
-- Use the duration from UnitBuff if available (already haste-adjusted)
if((rewatch_bars[playerId]["LifebloomStacks"] == 3) and (stacks == nil)) then
-- buffDuration from UnitBuff is already haste-adjusted, so use it if available
if(buffDuration and buffDuration > 0) then
b = buffDuration;
a = GetTime() + b;
else
-- Fallback: calculate haste-adjusted duration manually
local baseDuration = 15;
if(rewatch_loadInt["HasBlooming"]) then baseDuration = 10; end;
-- Get spell haste percentage (MoP Classic API)
local spellHaste = 0;
if(UnitSpellHaste) then
spellHaste = UnitSpellHaste("player") / 100.0;
elseif(GetSpellHaste) then
spellHaste = GetSpellHaste() / 100.0;
end;
-- Calculate haste-adjusted duration: baseDuration / (1 + haste)
-- Haste reduces duration by increasing tick frequency
if(spellHaste > 0) then
b = baseDuration / (1 + spellHaste);
else
b = baseDuration;
end;
a = GetTime() + b;
end;
end;
end;
-- update bar
rewatch_bars[playerId][spellName.."Bar"]:SetStatusBarColor(rewatch_loadInt["BarColor"..spellName..c].r, rewatch_loadInt["BarColor"..spellName..c].g, rewatch_loadInt["BarColor"..spellName..c].b, rewatch_loadInt["BarColor"..spellName..c].a);
-- set bar values
rewatch_bars[playerId][spellName] = a;
rewatch_bars[playerId][spellName.."Bar"]:SetMinMaxValues(0, b);
rewatch_bars[playerId][spellName.."Bar"]:SetValue(b);
end;
end;
-- clear a bar back to 0 because it's been dispelled or removed
-- spellName: the name of the spell to reset it's duration from
-- playerId: the index number of the player in the player table
-- return: void
function rewatch_DowndateBar(spellName, playerId)
-- if the spell exists for this player
if(rewatch_bars[playerId][spellName]) then
-- ignore if it's WG and we have no WG bar
if((spellName == rewatch_loc["wildgrowth"]) and (not rewatch_bars[playerId][spellName.."Bar"])) then return; end;
-- reset bar values
_, r = rewatch_bars[playerId][spellName.."Bar"]:GetMinMaxValues();
rewatch_bars[playerId][spellName.."Bar"]:SetValue(r);
rewatch_bars[playerId][spellName] = 0;
if(rewatch_loadInt["Labels"] == 0) then rewatch_bars[playerId][spellName.."Bar"].text:SetText(""); end;
-- check for wild growth overrides
if(spellName == rewatch_loc["wildgrowth"] and GetSpellCooldown(rewatch_loc["wildgrowth"])) then
if(rewatch_bars[playerId]["RevertingWG"] == 1) then
rewatch_bars[playerId]["RevertingWG"] = 0;
rewatch_bars[playerId][spellName.."Bar"]:SetStatusBarColor(rewatch_loadInt["BarColor"..spellName].r, rewatch_loadInt["BarColor"..spellName].g, rewatch_loadInt["BarColor"..spellName].b, rewatch_loadInt["PBOAlpha"]);
else
rewatch_bars[playerId]["RevertingWG"] = 1;
rewatch_bars[playerId][spellName.."Bar"]:SetStatusBarColor(0, 0, 0, 0.8);
r, b = GetSpellCooldown(spellName)
r = r + b; b = r - GetTime();
rewatch_bars[playerId][spellName] = r;
rewatch_bars[playerId][spellName.."Bar"]:SetMinMaxValues(0, b);
rewatch_bars[playerId][spellName.."Bar"]:SetValue(b);
end;
-- reset lifebloom stack counter
elseif(spellName == rewatch_loc["lifebloom"]) then
rewatch_bars[playerId]["LifebloomStacks"] = 0;
rewatch_bars[playerId][spellName.."Bar"]:SetStatusBarColor(rewatch_loadInt["BarColor"..spellName.."3"].r, rewatch_loadInt["BarColor"..spellName.."3"].g, rewatch_loadInt["BarColor"..spellName.."3"].b, rewatch_loadInt["PBOAlpha"]);
-- default
else
rewatch_bars[playerId][spellName.."Bar"]:SetStatusBarColor(rewatch_loadInt["BarColor"..spellName].r, rewatch_loadInt["BarColor"..spellName].g, rewatch_loadInt["BarColor"..spellName].b, rewatch_loadInt["PBOAlpha"]);
end;
end;
end;
-- add a player to the players table and create his bars and button
-- player: the name of the player
-- pet: if it's the pet of the named player ("pet" if so, nil if not)
-- return: the index number the player has been assigned
function rewatch_AddPlayer(player, pet)
-- return if in combat or if the max amount of players is passed
if(InCombatLockdown() or ((rewatch_loadInt["MaxPlayers"] > 0) and (rewatch_loadInt["MaxPlayers"] < rewatch_f:GetNumChildren()))) then return -1; end;
-- process pets
if(pet) then
player = player.."-pet"; pet = UnitName(player);
if(pet) then player = pet; end; pet = true;
else pet = false; end;
-- prepare table
rewatch_bars[rewatch_i] = {};
-- build frame with BackdropTemplate for MoP Classic compatibility