forked from Reloe/NorthernSkyRaidTools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReminders.lua
More file actions
1300 lines (1248 loc) · 57.1 KB
/
Reminders.lua
File metadata and controls
1300 lines (1248 loc) · 57.1 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
local _, NSI = ... -- Internal namespace
NSI.EncounterOrder = {
[3176] = 1, -- Imperator
[3177] = 2, -- Vorasius
[3179] = 3, -- Fallen-King
[3178] = 4, -- Dragons
[3180] = 5, -- Lightblinded Vanguard
[3181] = 6, -- Crown of the Cosmos
[3306] = 7, -- Chimaerus
[3182] = 8, -- Belo'ren
[3183] = 9, -- Midnight Falls
}
local symbols = {
star = 1,
circle = 2,
diamond = 3,
triangle = 4,
moon = 5,
square = 6,
cross = 7,
skull = 8,
}
function NSI:AddToReminder(info)
self.ProcessedReminder = self.ProcessedReminder or {}
self.ProcessedReminder[info.encID] = self.ProcessedReminder[info.encID] or {}
info.spellID = info.spellID and tonumber(info.spellID)
-- convert to booleans
if info.TTS == "true" then info.TTS = true end
if info.TTS == "false" then info.TTS = false end
-- default to user settings if not overwritten by the reminders
if info.TTS == nil then
info.TTS = (info.spellID and NSRT.ReminderSettings.SpellTTS) or ((not info.spellID) and NSRT.ReminderSettings.TextTTS)
end
if info.TTSTimer == nil then
-- set TTS timer to the specified duration or if no duration was specified, set it to the default value
info.TTSTimer = info.dur or ((info.spellID and NSRT.ReminderSettings.SpellTTSTimer) or NSRT.ReminderSettings.TextTTSTimer)
end
if info.dur == nil then
info.dur = info.spellID and NSRT.ReminderSettings.SpellDuration or NSRT.ReminderSettings.TextDuration
end
if info.countdown == nil then
info.countdown = info.spellID and NSRT.ReminderSettings.SpellCountdown or NSRT.ReminderSettings.TextCountdown
if info.countdown == 0 then info.countdown = false end
end
info.dur = tonumber(info.dur)
info.time = tonumber(info.time)
info.TTSTimer = tonumber(info.TTSTimer)
info.countdown = tonumber(info.countdown)
if info.dur > info.time then info.dur = info.time end -- force duration to be equal to time if an alert is set very early into the phase
if info.TTSTimer > info.time then info.TTSTimer = info.time end -- same for TTSTimer
if info.countdown and info.countdown > info.time then info.countdown = info.time end -- same for countdown
info.phase = info.phase and tonumber(info.phase)
if not info.phase then info.phase = 1 end
local rawtext = info.text
if info.text then
info.text = info.text:gsub("{(%a+)}", function(name) -- convert {star} to {rt1}, {orange} to {rt2} etc.
local id = symbols[name]
if id then
return ("{rt"..id.."}"):gsub("{rt(%d)}", "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_%1:0|t") -- convert {rt1} to the actual icon for display
end
end)
end
if (NSRT.ReminderSettings.SpellName or NSRT.ReminderSettings.SpellNameTTS) and info.spellID and not info.text then -- display spellname if text is empty, also make TTS that spellname
local spell = C_Spell.GetSpellInfo(info.spellID)
if spell then
info.text = NSRT.ReminderSettings.SpellName and spell.name or "" -- set text to SpellName
info.TTS = info.TTS and type(info.TTS) ~= "string" and spell.name or info.TTS -- Set TTS to SpellName
end
end
if info.TTS and info.text and type(info.TTS) == "boolean" then -- if tts is "true" convert it to the rawtext, which is the text before converting it to display raid-icons
info.TTS = rawtext
end
if info.TTS and type(info.TTS) == "string" and ((NSRT.ReminderSettings.AnnounceSpellDuration and info.spellID) or (NSRT.ReminderSettings.AnnounceTextDuration and not info.spellID)) and not info.IsAlert then
info.TTS = info.TTS.." in "..info.TTSTimer
end
if info.glowunit then
local glowtable = {}
for name in info.glowunit:gmatch("([^%s:]+)") do
if name ~= "glowunit" then
table.insert(glowtable, name)
end
end
info.glowunit = glowtable
end
if info.colors then
local colors = {}
for color in info.colors:gmatch("([^%s:]+)") do
table.insert(colors, tonumber(color))
end
info.colors = colors
end
-- play default sound if enabled and no TTS/Sound was specified
if NSRT.ReminderSettings.PlayDefaultSound and (type(info.TTS) == "boolean" or not info.TTS) and (not info.sound) and (not info.IsAlert) then
info.sound = NSRT.ReminderSettings.DefaultSound
end
self.ProcessedReminder[info.encID][info.phase] = self.ProcessedReminder[info.encID][info.phase] or {}
table.insert(self.ProcessedReminder[info.encID][info.phase],
{
notsticky = info.notsticky,
BarOverwrite = info.BarOverwrite or info.Type == "Bar",
IconOverwrite = info.IconOverwrite or info.Type == "Icon",
TTSTimer = info.TTSTimer,
rawtext = info.rawtext,
phase = info.phase,
colors = info.colors,
id = #self.ProcessedReminder[info.encID][info.phase]+1,
countdown = info.countdown and tonumber(info.countdown),
glowunit = info.glowunit,
sound = info.sound,
time = info.time,
text = info.text,
TTS = info.TTS,
spellID = info.spellID and tonumber(info.spellID),
dur = info.dur or 8,
skipdur = info.skipdur, -- with this true there will be no cooldown edge shown for icons
IsAlert = info.IsAlert,
})
end
function NSI:ProcessReminder()
local str = ""
self.ProcessedReminder = {}
local remindertable = {}
local addedreminders = {}
local personalremindertable = {}
local addedpersonalreminders = {}
self.DisplayedReminder = ""
self.DisplayedPersonalReminder = ""
self.DisplayedExtraReminder = ""
local pers = NSRT.ReminderSettings.PersonalReminderFrame.enabled
local shared = NSRT.ReminderSettings.ReminderFrame.enabled
-- UseTimelineReminders makes it process the note but then stops the display at a later point. This allows still displaying the note.
if (NSRT.ReminderSettings.enabled or NSRT.ReminderSettings.UseTimelineReminders) and self.Reminder then str = self.Reminder end
if NSRT.ReminderSettings.MRTNote or NSRT.ReminderSettings.UseTimelineReminders then
local note = VMRT and VMRT.Note and VMRT.Note.Text1 or ""
str = note and str ~= "" and str.."\n"..note or note or str
end
if NSRT.ReminderSettings.PersNote or NSRT.ReminderSettings.UseTimelineReminders then
local note = self.PersonalReminder
str = note and str ~= "" and str.."\n"..note or note or str
end
if str ~= "" then
local subgroup = self:GetSubGroup("player")
if not subgroup then subgroup = 1 end
subgroup = "group"..subgroup
local specid = C_SpecializationInfo.GetSpecializationInfo(C_SpecializationInfo.GetSpecialization())
local pos = self.spectable[specid]
local encID = 0
local mynickname = strlower(NSAPI:GetName("player", "GlobalNickNames"))
local myname = strlower(UnitName("player"))
local myrole = strlower(UnitGroupRolesAssigned("player"))
local myclass = strlower(select(2, UnitClass("player")))
pos = (self.meleetable[specid] or myrole == "tank") and "melee" or "ranged"
local extranote = ""
if not str:match('\n$') then
str = str..'\n'
end
for line in str:gmatch('([^\n]*)\n') do
local firstline = false
if line:find("EncounterID:") then
encID = line:match("EncounterID:(%d+)")
if encID then
encID = tonumber(encID)
firstline = true
end
end
local tag = line:match("tag:([^;]+)")
local time = line:match("time:(%d*%.?%d+)")
local text = line:match("text:([^;]+)")
local spellID = line:match("spellid:(%d+)")
local phase = line:match("ph:(%d+)")
local dur = line:match("dur:(%d+)")
local TTS = line:match("TTS:([^;]+)")
local TTSTimer = line:match("TTSTimer:(%d+)")
local countdown = line:match("countdown:(%d+)")
local sound = line:match("sound:([^;]+)")
local glowunit = line:match("glowunit:([^;]+)")
local bossSpellID = line:match("bossSpell:(%d+)")
local colors = line:match("colors:([^;]+)")
if time and tag and (text or spellID) and encID and encID ~= 0 and not firstline then
local displayLine = line
phase = phase and tonumber(phase) or 1
local key = encID..phase..time..tag..(text or spellID)
if (pers or shared) and (spellID or not NSRT.ReminderSettings.OnlySpellReminders) then -- only insert this if it's a spell or user wants to see text-reminders as well
-- display phase more readable
displayLine = displayLine:gsub("ph:"..phase, "P"..phase.." ")
-- convert to MM:SS format
local timeNum = tonumber(time)
if timeNum then
local minutes = math.floor(timeNum / 60)
local seconds = math.floor(timeNum % 60)
local timeFormatted = string.format("%d:%02d", minutes, seconds)
displayLine = displayLine:gsub("time:"..time, timeFormatted.." ")
end
if text then
local displayText = text:gsub("{(%a+)}", function(name) -- convert {star} to {rt1}, {orange} to {rt2} etc.
local id = symbols[name]
if id then
return ("{rt"..id.."}"):gsub("{rt(%d)}", "|TInterface\\TargetingFrame\\UI-RaidTargetingIcon_%1:0|t") -- convert {rt1} to the actual icon for display
end
end)
displayLine = displayLine:gsub("text:"..text, displayText.. " ")
end
-- convert to icon
if spellID then
local iconID = C_Spell.GetSpellTexture(tonumber(spellID))
if iconID then
local iconString = "\124T"..iconID..":12:12:0:0:64:64:4:60:4:60\124t"
displayLine = displayLine:gsub("spellid:%d+", iconString.. " ")
end
end
if bossSpellID then
local iconID = C_Spell.GetSpellTexture(tonumber(bossSpellID))
if iconID then
local iconString = "\124T"..iconID..":12:12:0:0:64:64:4:60:4:60\124t"
displayLine = displayLine:gsub("bossSpell:%d+", iconString.. " ")
end
end
-- cleanup stuff we don't want to have displayed
if glowunit then
displayLine = displayLine:gsub("glowunit:"..glowunit, "")
end
if countdown then
displayLine = displayLine:gsub("countdown:"..countdown, "")
end
if TTS then
displayLine = displayLine:gsub("TTS:"..TTS, "")
end
if TTSTimer then
displayLine = displayLine:gsub("TTSTimer:"..TTSTimer, "")
end
if sound then
displayLine = displayLine:gsub("sound:"..sound, "")
end
if dur then
displayLine = displayLine:gsub("dur:"..dur, "")
end
if colors then
displayLine = displayLine:gsub("colors:"..colors, "")
end
-- convert names to nicknames and color code them
local tagNames = ""
for name in tag:gmatch("(%S+)") do
tagNames = tagNames..NSAPI:Shorten(NSAPI:GetChar(strtrim(name), true), 12, false, "GlobalNickNames").." "
end
tagNames = strtrim(tagNames)
displayLine = displayLine:gsub("tag:([^;]+)", tagNames.." ")
-- remove remaining semicolons
displayLine = displayLine:gsub(";", "")
if shared and not addedreminders[key] then
table.insert(remindertable, {str = displayLine, time = tonumber(time), phase = phase})
addedreminders[key] = true
end
end
local tags = {}
tag = strlower(tag)
for name in tag:gmatch("(%S+)") do
tags[strtrim(name)] = true
end
specid = specid and tostring(specid)
if tag == "everyone" or
tags[myname] or
tags[mynickname] or
tags[myrole] or
tags[specid] or
tags[myclass] or
tags[subgroup] or
(pos and tags[pos])
then
if not addedpersonalreminders[key] then
addedpersonalreminders[key] = true
if pers then
if (spellID or not NSRT.ReminderSettings.OnlySpellReminders) then -- only insert this if it's a spell or user wants to see text-reminders as well
table.insert(personalremindertable, {str = displayLine, time = tonumber(time), phase = phase})
end
end
self:AddToReminder({text = text, phase = phase, colors = colors, countdown = countdown, glowunit = glowunit, sound = sound, time = time, spellID = spellID, dur = dur, TTS = TTS, TTSTimer = TTSTimer, encID = encID, Type = nil, notsticky = false})
end
end
else
if (not firstline) and (not line:find("invitelist:")) then
if NSRT.Settings["GlobalNickNames"] then
local words = {}
for word in line:gmatch("[^%s]+") do
local shortened = NSAPI:Shorten(NSAPI:GetChar(word, true), 12, false, "GlobalNickNames")
table.insert(words, shortened)
end
extranote = extranote..table.concat(words, " ").."\n"
else
extranote = extranote..line.."\n"
end
end
end
end
if shared then
table.sort(remindertable, function(a, b)
if a.phase == b.phase then
return a.time < b.time
else
return a.phase < b.phase
end
end)
for _, data in ipairs(remindertable) do
self.DisplayedReminder = self.DisplayedReminder..data.str.."\n"
end
end
if pers then
table.sort(personalremindertable, function(a, b)
if a.phase == b.phase then
return a.time < b.time
else
return a.phase < b.phase
end
end)
for _, data in ipairs(personalremindertable) do
self.DisplayedPersonalReminder = self.DisplayedPersonalReminder..data.str.."\n"
end
end
extranote = extranote:gsub("^%s*\n+", "")
self.DisplayedExtraReminder = extranote
end
if self.TimelineWindow and self.TimelineWindow:IsShown() then
self:RefreshTimelineForMode()
end
end
function NSI:UpdateExistingFrames() -- called when user changes settings to not require a reload
local parent = self.ReminderText or {}
for i=1, #parent do
local F = parent[i]
if F and F:IsShown() then
local s = NSRT.ReminderSettings.TextSettings
F.Text:SetFont(self.LSM:Fetch("font", s.Font), s.FontSize, "OUTLINE")
end
end
self:ArrangeStates("Texts")
self:MoveFrameSettings(self.TextMover, NSRT.ReminderSettings.TextSettings, true)
parent = self.ReminderIcon or {}
for i=1, #parent do
local F = parent[i]
if F and F:IsShown() then
local s = NSRT.ReminderSettings.IconSettings
F:SetSize(s.Width, s.Height)
F.Icon:SetAllPoints(F)
F.Border:SetAllPoints(F)
local anchor = NSRT.ReminderSettings.IconSettings.RightAlignedText and "RIGHT" or "LEFT"
local relativePoint = NSRT.ReminderSettings.IconSettings.RightAlignedText and "LEFT" or "RIGHT"
F.Text:ClearAllPoints()
F.Text:SetPoint(anchor, F, relativePoint, s.xTextOffset, s.yTextOffset)
F.Text:SetFont(self.LSM:Fetch("font", s.Font), s.FontSize, "OUTLINE")
F.TimerText:SetPoint("CENTER", F.Swipe, "CENTER", s.xTimer, s.yTimer)
F.TimerText:SetFont(self.LSM:Fetch("font", s.Font), s.TimerFontSize, "OUTLINE")
end
end
self:ArrangeStates("Icons")
self:MoveFrameSettings(self.IconMover, NSRT.ReminderSettings.IconSettings)
parent = self.UnitIcon or {}
for i=1, #parent do
local F = parent[i]
if F and F:IsShown() then
local s = NSRT.ReminderSettings.UnitIconSettings
F:SetSize(s.Width, s.Height) -- not setting points in this one because this is repeated every time the frame is shown as it needs a new frame to anchor to anyway
end
end
parent = self.ReminderBar or {}
for i=1, #parent do
local F = parent[i]
if F and F:IsShown() then
local s = NSRT.ReminderSettings.BarSettings
F:SetSize(s.Width, s.Height)
F:SetStatusBarTexture(self.LSM:Fetch("statusbar", s.Texture))
F:SetStatusBarColor(unpack(F.info.colors or s.colors))
F.Icon:SetPoint("RIGHT", F, "LEFT", s.xIcon, s.yIcon)
F.Icon:SetSize(s.Height, s.Height)
F.Text:SetPoint("LEFT", F.Icon, "RIGHT", s.xTextOffset, s.yTextOffset)
F.Text:SetFont(self.LSM:Fetch("font", s.Font), s.FontSize, "OUTLINE")
F.TimerText:SetPoint("RIGHT", F, "RIGHT", s.xTimer, s.yTimer)
F.TimerText:SetFont(self.LSM:Fetch("font", s.Font), s.TimerFontSize, "OUTLINE")
end
end
self:ArrangeStates("Bars")
self:MoveFrameSettings(self.BarMover, NSRT.ReminderSettings.BarSettings, false, true)
end
function NSI:ArrangeStates(Type)
local F = (Type == "Texts" and self.ReminderText) or (Type == "Icons" and self.ReminderIcon) or (Type == "Bars" and self.ReminderBar)
if not F then return end
local s = (Type == "Texts" and NSRT.ReminderSettings.TextSettings) or (Type == "Icons" and NSRT.ReminderSettings.IconSettings) or (Type == "Bars" and NSRT.ReminderSettings.BarSettings)
local pos = {}
for i=1, #F do
if F[i] and F[i]:IsShown() then
table.insert(pos, {Frame = F[i], id = F[i].info.id, expires = F[i].info.expires})
end
end
table.sort(pos, function(a, b)
if a.expires == b.expires then
return a.id < b.id
else
return a.expires < b.expires
end
end)
for i, v in ipairs(pos) do
local diff = Type == "Texts" and s.FontSize or s.Height
local Spacing = s.Spacing or 0
local yoffset = (s.GrowDirection == "Up" and (i-1) * (s.Height+Spacing) or (s.GrowDirection == "Down" and -(i-1) * (s.Height+Spacing))) or 0
local xoffset = Type == "Icons" and ((s.GrowDirection == "Right" and (i-1) * (s.Width+Spacing)) or (s.GrowDirection == "Left" and -(i-1) * (s.Width+Spacing))) or 0
v.Frame:ClearAllPoints()
if Type == "Texts" then
v.Frame:SetPoint("BOTTOMLEFT", "NSUIReminderTextMover", "BOTTOMLEFT", 0, 0 + yoffset)
v.Frame:SetPoint("TOPRIGHT", "NSUIReminderTextMover", "TOPRIGHT", 0, 0 + yoffset)
elseif Type == "Icons" then
v.Frame:SetPoint("BOTTOMLEFT", "NSUIReminderIconMover", "BOTTOMLEFT", 0 + xoffset, 0 + yoffset)
v.Frame:SetPoint("TOPRIGHT", "NSUIReminderIconMover", "TOPRIGHT", 0 + xoffset, 0 + yoffset)
elseif Type == "Bars" then
v.Frame:SetPoint("BOTTOMLEFT", "NSUIReminderBarMover", "BOTTOMLEFT", 0, 0 + yoffset)
v.Frame:SetPoint("TOPRIGHT", "NSUIReminderBarMover", "TOPRIGHT", 0, 0 + yoffset)
else
print("RELOE PLS FIX (Reminder anchoring issue @ NSI:ArrangeStates)")
end
end
end
function NSI:SetProperties(F, info, skipsound, s)
F:SetScript("OnUpdate", function()
self:UpdateReminderDisplay(info, F, skipsound)
end)
F:SetScript("OnHide", function()
if info.glowunit then
self:HideGlows(info.glowunit, "p"..info.phase.."id"..info.id)
end
if F.Swipe and NSRT.ReminderSettings.IconSettings.Glow > 0 then
self:HideGlows(nil, nil, F)
end
NSI:ArrangeStates(F.Type)
end)
F.info = info
if not info.spellID then
F.Text:SetTextColor(unpack(info.colors or s.colors))
return
end
local icon = C_Spell.GetSpellInfo(info.spellID).iconID
F.Icon:SetTexture(icon)
if F.Swipe then
if info.skipdur then
F.Swipe:SetCooldown(0, 0)
F.TimerText:Hide()
else
F.Swipe:SetCooldown(GetTime(), info.dur)
if NSRT.ReminderSettings.HideTimerText then
F.TimerText:Hide()
else
F.TimerText:SetTextColor(1, 1, 0, 1)
end
end
F.Text:SetTextColor(unpack(info.colors or s.colors))
elseif F:GetObjectType() == "StatusBar" then
F:SetStatusBarColor(unpack(info.colors or s.colors))
if F.TimerText then
F.TimerText:SetTextColor(1, 1, 1, 1)
end
end
F:RegisterEvent("UNIT_SPELLCAST_SUCCEEDED")
F:SetScript("OnEvent", function(self, e, ...)
local unit, _, spellID = ...
if (not issecretvalue(spellID)) and (not issecretvalue(info.spellID)) and spellID == info.spellID and UnitIsUnit("player", unit) and self:IsShown() then
self:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
self:Hide()
end
end)
end
function NSI:CreateText(info)
self.ReminderText = self.ReminderText or {}
local s = NSRT.ReminderSettings.TextSettings
for i=1, #self.ReminderText+1 do
if self.ReminderText[i] and not self.ReminderText[i]:IsShown() then
self:SetProperties(self.ReminderText[i], info, false, s)
return self.ReminderText[i]
end
if not self.ReminderText[i] then
self.ReminderText[i] = CreateFrame("Frame", 'NSUIReminderText' .. i, UIParent, "BackdropTemplate")
local offset = s.GrowDirection == "Up" and (i-1) * s.FontSize or -(i-1) * s.FontSize
self.ReminderText[i]:SetPoint("BOTTOMLEFT", "NSUIReminderTextMover", "BOTTOMLEFT", 0, 0 + offset)
self.ReminderText[i]:SetPoint("TOPRIGHT", "NSUIReminderTextMover", "TOPRIGHT", 0, 0 + offset)
self.ReminderText[i]:SetFrameStrata("HIGH")
self.ReminderText[i].Text = self.ReminderText[i]:CreateFontString(nil, "OVERLAY", "GameFontNormal")
self.ReminderText[i].Text:SetPoint("LEFT", self.ReminderText[i], "LEFT", 0, 0)
self.ReminderText[i].Text:SetFont(self.LSM:Fetch("font", s.Font), s.FontSize, "OUTLINE")
self.ReminderText[i].Text:SetShadowColor(0, 0, 0, 1)
self.ReminderText[i].Text:SetShadowOffset(0, 0)
self.ReminderText[i].Text:SetTextColor(unpack(info.colors or s.colors))
self:SetProperties(self.ReminderText[i], info, false, s)
return self.ReminderText[i]
end
end
end
function NSI:CreateIcon(info)
self.ReminderIcon = self.ReminderIcon or {}
local icon = C_Spell.GetSpellInfo(info.spellID).iconID
local s = NSRT.ReminderSettings.IconSettings
for i=1, #self.ReminderIcon+1 do
if self.ReminderIcon[i] and not self.ReminderIcon[i]:IsShown() then
self:SetProperties(self.ReminderIcon[i], info, false, s)
return self.ReminderIcon[i]
end
if not self.ReminderIcon[i] then
self.ReminderIcon[i] = CreateFrame("Frame", 'NSUIReminderIcon' .. i, UIParent, "BackdropTemplate")
local yoffset = (s.GrowDirection == "Up" and (i-1) * s.Height) or (s.GrowDirection == "Down" and -(i-1) * s.Height) or 0
local xoffset = (s.GrowDirection == "Right" and (i-1) * s.Width) or (s.GrowDirection == "Left" and -(i-1) * s.Width) or 0
self.ReminderIcon[i]:SetPoint("BOTTOMLEFT", "NSUIReminderIconMover", "BOTTOMLEFT", 0 + xoffset, 0 + yoffset)
self.ReminderIcon[i]:SetPoint("TOPRIGHT", "NSUIReminderIconMover", "TOPRIGHT", 0 + xoffset, 0 + yoffset)
self.ReminderIcon[i]:SetFrameStrata("HIGH")
self.ReminderIcon[i].Icon = self.ReminderIcon[i]:CreateTexture(nil, "ARTWORK")
self.ReminderIcon[i].Icon:SetAllPoints(self.ReminderIcon[i])
self.ReminderIcon[i].Border = CreateFrame("Frame", nil, self.ReminderIcon[i], "BackdropTemplate")
self.ReminderIcon[i].Border:SetAllPoints(self.ReminderIcon[i])
self.ReminderIcon[i].Border:SetBackdrop({
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1
})
self.ReminderIcon[i].Border:SetBackdropBorderColor(0, 0, 0, 1)
self.ReminderIcon[i].Text = self.ReminderIcon[i]:CreateFontString(nil, "OVERLAY", "GameFontNormal")
local anchor = NSRT.ReminderSettings.IconSettings.RightAlignedText and "RIGHT" or "LEFT"
local relativePoint = NSRT.ReminderSettings.IconSettings.RightAlignedText and "LEFT" or "RIGHT"
self.ReminderIcon[i].Text:SetPoint(anchor, self.ReminderIcon[i], relativePoint, s.xTextOffset, s.yTextOffset)
self.ReminderIcon[i].Text:SetFont(self.LSM:Fetch("font", s.Font), s.FontSize, "OUTLINE")
self.ReminderIcon[i].Text:SetShadowColor(0, 0, 0, 1)
self.ReminderIcon[i].Text:SetShadowOffset(0, 0)
self.ReminderIcon[i].Text:SetTextColor(unpack(info.colors or s.colors))
self.ReminderIcon[i].Swipe = CreateFrame("Cooldown", nil, self.ReminderIcon[i], "CooldownFrameTemplate")
self.ReminderIcon[i].Swipe:SetAllPoints()
self.ReminderIcon[i].Swipe:SetDrawBling(false)
self.ReminderIcon[i].Swipe:SetDrawEdge(false)
self.ReminderIcon[i].Swipe:SetReverse(true)
self.ReminderIcon[i].Swipe:SetHideCountdownNumbers(true)
self.ReminderIcon[i].TimerText = self.ReminderIcon[i].Swipe:CreateFontString(nil, "OVERLAY", "GameFontNormal")
self.ReminderIcon[i].TimerText:SetPoint("CENTER", self.ReminderIcon[i].Swipe, "CENTER", s.xTimer, s.yTimer)
self.ReminderIcon[i].TimerText:SetFont(self.LSM:Fetch("font", s.Font), s.TimerFontSize, "OUTLINE")
self.ReminderIcon[i].TimerText:SetShadowColor(0, 0, 0, 1)
self.ReminderIcon[i].TimerText:SetShadowOffset(0, 0)
self.ReminderIcon[i].TimerText:SetDrawLayer("OVERLAY", 7)
self:SetProperties(self.ReminderIcon[i], info, false, s)
return self.ReminderIcon[i]
end
end
end
function NSI:CreateUnitFrameIcon(info, name)
self.UnitIcon = self.UnitIcon or {}
local icon = C_Spell.GetSpellInfo(info.spellID).iconID
local unit = NSAPI:GetChar(name, true)
local i = UnitInRaid(unit)
if (not UnitExists(unit)) or (not i) then return end
local F = self.LGF.GetUnitFrame("raid"..i)
if not F then return end
local s = NSRT.ReminderSettings.UnitIconSettings
for i=1, #self.UnitIcon+1 do
if self.UnitIcon[i] and not self.UnitIcon[i]:IsShown() then
self.UnitIcon[i]:ClearAllPoints()
self.UnitIcon[i]:SetPoint(s.Position, F, s.Position, s.xOffset, s.yOffset)
self:SetProperties(self.UnitIcon[i], info, true, s)
return self.UnitIcon[i]
end
if not self.UnitIcon[i] then
self.UnitIcon[i] = CreateFrame("Frame", nil, UIParent, "BackdropTemplate")
self.UnitIcon[i]:SetSize(s.Width, s.Height)
self.UnitIcon[i]:SetPoint(s.Position, F, s.Position, s.xOffset, s.yOffset)
self.UnitIcon[i].Icon = self.UnitIcon[i]:CreateTexture(nil, "ARTWORK")
self.UnitIcon[i].Icon:SetAllPoints(self.UnitIcon[i])
self.UnitIcon[i].Icon:SetTexture(icon)
self.UnitIcon[i].Border = CreateFrame("Frame", nil, self.UnitIcon[i], "BackdropTemplate")
self.UnitIcon[i].Border:SetAllPoints(self.UnitIcon[i])
self.UnitIcon[i].Border:SetBackdrop({
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1
})
self.UnitIcon[i].Border:SetBackdropBorderColor(0, 0, 0, 1)
self:SetProperties(self.UnitIcon[i], info, true, s)
return self.UnitIcon[i]
end
end
end
function NSI:CreateBar(info)
self.ReminderBar = self.ReminderBar or {}
local icon = C_Spell.GetSpellInfo(info.spellID).iconID
local s = NSRT.ReminderSettings.BarSettings
for i=1, #self.ReminderBar+1 do
if self.ReminderBar[i] and not self.ReminderBar[i]:IsShown() then
self:SetProperties(self.ReminderBar[i], info, false, s)
return self.ReminderBar[i]
end
if not self.ReminderBar[i] then
self.ReminderBar[i] = CreateFrame("StatusBar", 'NSUIReminderBar' .. i, UIParent, "BackdropTemplate")
self.ReminderBar[i]:SetBackdrop({
bgFile = "Interface\\Buttons\\WHITE8x8",
tileSize = 0,
})
self.ReminderBar[i]:SetStatusBarTexture(self.LSM:Fetch("statusbar", s.Texture))
self.ReminderBar[i]:SetStatusBarColor(unpack(info.colors or s.colors))
self.ReminderBar[i]:SetBackdropColor(0, 0, 0, 0.8)
local offset = s.GrowDirection == "Up" and (i-1) * s.Height or -(i-1) * s.Height
self.ReminderBar[i]:SetPoint("BOTTOMLEFT", "NSUIReminderBarMover", "BOTTOMLEFT", 0, 0 + offset)
self.ReminderBar[i]:SetPoint("TOPRIGHT", "NSUIReminderBarMover", "TOPRIGHT", 0, 0 + offset)
self.ReminderBar[i]:SetFrameStrata("HIGH")
self.ReminderBar[i].Border = CreateFrame("Frame", nil, self.ReminderBar[i], "BackdropTemplate")
self.ReminderBar[i].Border:SetAllPoints(self.ReminderBar[i])
self.ReminderBar[i].Border:SetBackdrop({
edgeFile = "Interface\\Buttons\\WHITE8x8",
edgeSize = 1
})
self.ReminderBar[i].Border:SetBackdropBorderColor(0, 0, 0, 1)
self.ReminderBar[i].Icon = self.ReminderBar[i]:CreateTexture(nil, "ARTWORK")
self.ReminderBar[i].Icon:SetPoint("RIGHT", self.ReminderBar[i], "LEFT", s.xIcon, s.yIcon)
self.ReminderBar[i].Icon:SetSize(s.Height, s.Height)
self.ReminderBar[i].Text = self.ReminderBar[i]:CreateFontString(nil, "OVERLAY", "GameFontNormal")
self.ReminderBar[i].Text:SetPoint("LEFT", self.ReminderBar[i].Icon, "RIGHT", s.xTextOffset, s.yTextOffset)
self.ReminderBar[i].Text:SetFont(self.LSM:Fetch("font", s.Font), s.FontSize, "OUTLINE")
self.ReminderBar[i].Text:SetShadowColor(0, 0, 0, 1)
self.ReminderBar[i].Text:SetShadowOffset(0, 0)
self.ReminderBar[i].Text:SetTextColor(1, 1, 1, 1)
self.ReminderBar[i].TimerText = self.ReminderBar[i]:CreateFontString(nil, "OVERLAY", "GameFontNormal")
self.ReminderBar[i].TimerText:SetPoint("RIGHT", self.ReminderBar[i], "RIGHT", s.xTimer, s.yTimer)
self.ReminderBar[i].TimerText:SetFont(self.LSM:Fetch("font", s.Font), s.TimerFontSize, "OUTLINE")
self.ReminderBar[i].TimerText:SetShadowColor(0, 0, 0, 1)
self.ReminderBar[i].TimerText:SetShadowOffset(0, 0)
self:SetProperties(self.ReminderBar[i], info, false, s)
return self.ReminderBar[i]
end
end
end
function NSI:DisplayReminder(info)
local now = GetTime()
local dur = info.dur or 8
info.startTime = now
info.dur = dur
info.expires = now + dur
local rem = info.dur - (now - info.startTime)
if info.spellID and rem <= (0-NSRT.ReminderSettings.Sticky) or ((info.notsticky or not info.spellID) and rem <= 0) then
return
end
local remString
if rem < 3 then
if rem < 0 then
remString = ""
else
rem = math.floor(rem * 10 + 0.5) / 10
remString = string.format("%.1f", rem)
end
else
remString = tostring(math.ceil(rem))
end
local remString = (rem % 1 == 0) and string.format("%.1f", rem) or rem
local text = info.text ~= "" and info.text or ""
local F
if info.spellID then -- display icon if we have a spellID
if (NSRT.ReminderSettings.Bars or info.BarOverwrite) and not info.IconOverwrite then
F = self:CreateBar(info)
F:SetMinMaxValues(0, info.dur)
F:SetValue(0)
F:Show()
self:ArrangeStates("Bars")
F.Type = "Bars"
else
F = self:CreateIcon(info)
F:Show()
self:ArrangeStates("Icons")
F.Type = "Icons"
end
F.Text:SetText(text)
F.TimerText:SetText(remString)
else
F = self:CreateText(info)
F.Type = "Texts"
F.Text:SetText(text.." - ("..remString..")" or remString)
F:Show()
self:ArrangeStates("Texts")
end
if info.glowunit then
for i, name in ipairs(info.glowunit) do
self:GlowFrame(name, "p"..info.phase.."id"..info.id)
if info.spellID then
local UnitIcon = self:CreateUnitFrameIcon(info, name)
if UnitIcon then UnitIcon:Show() end
end
end
end
end
function NSI:UpdateReminderDisplay(info, F, skipsound)
local rem = info.dur - (GetTime() - info.startTime)
local SoundTimer = info.TTSTimer or (info.spellID and NSRT.ReminderSettings.SpellTTSTimer or NSRT.ReminderSettings.TextTTSTimer)
if rem <= SoundTimer and (not self.PlayedSound["ph"..info.phase.."id"..info.id]) and (not skipsound) then
self:PlayReminderSound(info)
self.PlayedSound["ph"..info.phase.."id"..info.id] = true
end
if info.countdown and rem <= info.countdown and (not self.StartedCountdown["ph"..info.phase.."id"..info.id]) and (not skipsound) then
NSAPI:TTSCountdown(info.countdown)
self.StartedCountdown["ph"..info.phase.."id"..info.id] = true
end
if info.spellID and rem <= (0-NSRT.ReminderSettings.Sticky) or ((info.notsticky or not info.spellID) and rem <= 0) then
F:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED")
F:Hide()
return
end
local remString
if rem < 3 then
if rem < 0 then
remString = ""
else
rem = math.floor(rem * 10 + 0.5) / 10
remString = string.format("%.1f", rem)
end
else
remString = tostring(math.ceil(rem))
end
local text = (info.skiptime and info.text) or (info.text and info.text ~= "" and info.text.." - ("..remString..")") or remString
if info.spellID and type(info.spellID) == "number" then
if F:GetObjectType() == "StatusBar" then
F:SetValue((GetTime()-info.startTime))
else
if rem <= 3 and F.TimerText then
F.TimerText:SetTextColor(1, 0, 0, 1)
end
if F.Swipe and NSRT.ReminderSettings.IconSettings.Glow > 0 and rem <= NSRT.ReminderSettings.IconSettings.Glow and not self.GlowStarted["ph"..info.phase.."id"..info.id] then
self.GlowStarted["ph"..info.phase.."id"..info.id] = true
self:GlowFrame(nil, nil, F)
end
end
if F.TimerText then F.TimerText:SetText(remString) end
else
F.Text:SetText(text)
end
end
function NSI:PlayReminderSound(info, default)
if info.TTS and issecretvalue(info.TTS) then NSAPI:TTS(info.TTS) return end
if default then -- so I can use this function outside of reminders basically
info = {sound = default, TTS = default, rawtext = default}
end
local sound = info.sound and self.LSM:Fetch("sound", info.sound)
if sound and sound ~= 1 then
PlaySoundFile(sound, "Master")
return
elseif info.TTS then
local TTS = (type(info.TTS) == "string" and info.TTS) or (info.rawtext and info.rawtext ~= "" and info.rawtext) or ""
sound = self.LSM:Fetch("sound", TTS)
if sound and sound ~= 1 then
PlaySoundFile(sound, "Master")
return
else
NSAPI:TTS(TTS)
end
end
end
function NSI:StartReminders(phase, testrun)
self:HideAllReminders()
self.AllGlows = {}
self.ReminderTimer = {}
if testrun then
if not self.ProcessedReminder then self:ProcessReminder() end
if not self.ProcessedReminder then return end
for encID, encData in pairs(self.ProcessedReminder) do
for i, info in ipairs(encData[phase] or {}) do
if info.IsAlert or not NSRT.ReminderSettings.UseTimelineReminders then
local time = math.max(info.time-info.dur, 0)
self.ReminderTimer[i] = C_Timer.NewTimer(time, function()
self:DisplayReminder(info)
end)
end
end
end
return
end
if not self.EncounterID then return end
if not self.ProcessedReminder[self.EncounterID] then return end
if not self.ProcessedReminder[self.EncounterID][phase] then return end
for i, info in ipairs(self.ProcessedReminder[self.EncounterID][phase]) do
if info.IsAlert or not NSRT.ReminderSettings.UseTimelineReminders then
local time = math.max(info.time-info.dur, 0)
self.ReminderTimer[i] = C_Timer.NewTimer(time, function()
self:DisplayReminder(info)
end)
end
end
end
function NSI:DelayAllReminders(delay)
if not self.ReminderTimer then return end
for i, v in ipairs(self.ReminderTimer) do
v:Cancel()
end
if not self.EncounterID then return end
if not self.ProcessedReminder[self.EncounterID] then return end
local phase = self.Phase or 1
if not self.ProcessedReminder[self.EncounterID][phase] then return end
local timediff = GetTime() - self.PhaseSwapTime -- time since phase change
local parents = {"ReminderText", "ReminderIcon", "ReminderBar", "UnitIcon"}
for _, parentname in ipairs(parents) do
if self[parentname] then
for i=1, #self[parentname] do
local F = self[parentname][i]
if F and F:IsShown() then
if F.info and F.info.dur then
F.info.expires = F.info.expires + delay
F.info.startTime = F.info.startTime + delay
self:UpdateReminderDisplay(F.info, F)
end
end
end
end
end
for i, info in ipairs(self.ProcessedReminder[self.EncounterID][phase]) do
if info.IsAlert or not NSRT.ReminderSettings.UseTimelineReminders then
if info.time-info.dur > timediff then -- if time is 0 then this reminder has already started
local time = math.max(info.time-info.dur-timediff+delay, 0)
info.time = info.time + delay
self.ReminderTimer[i] = C_Timer.NewTimer(time, function()
self:DisplayReminder(info)
end)
end
end
end
end
function NSI:HideAllReminders(FullReset)
self.PlayedSound = {}
self.StartedCountdown = {}
self.GlowStarted = {}
if self.ReminderTimer then
for i, v in ipairs(self.ReminderTimer) do
v:Cancel()
end
end
if self.AllGlows then
for k, v in pairs(self.AllGlows) do
self.LCG.PixelGlow_Stop(k, v)
end
end
local parent = self.ReminderText or {}
for i=1, #parent do
local F = parent[i]
if F then F:Hide() end
end
parent = self.ReminderIcon or {}
for i=1, #parent do
local F = parent[i]
if F then F:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED") F:Hide() end
end
parent = self.ReminderBar or {}
for i=1, #parent do
local F = parent[i]
if F then F:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED") F:Hide() end
end
parent = self.UnitIcon or {}
for i=1, #parent do
local F = parent[i]
if F then F:UnregisterEvent("UNIT_SPELLCAST_SUCCEEDED") F:Hide() end
end
if not FullReset then return end
self.ReminderTimer = nil
self.AllGlows = nil
self.Timelines = {}
if self.EncounterAlertStop[self.EncounterID] then self.EncounterAlertStop[self.EncounterID](self) end
self.EncounterID = nil
self.TestingReminder = false
self.ProcessedReminder = nil
end
function NSI:GetAllReminderNames(personal)
local list = {}
local tocheck = personal and NSRT.PersonalReminders or NSRT.Reminders
for k, v in pairs(tocheck) do
local encID = v:match("EncounterID:(%d+)")
if encID then
local order = self.EncounterOrder[tonumber(encID)] or 1000
table.insert(list, {name = k, order = order})
end
end
table.sort(list, function(a, b)
if a.order == b.order then
return a.name < b.name
else
return a.order < b.order
end
end)
return list
end
function NSI:SetReminder(name, personal)
if personal then
if name and NSRT.PersonalReminders[name] then
self.PersonalReminder = NSRT.PersonalReminders[name]
NSRT.ActivePersonalReminder = name
self:ProcessReminder()
self:UpdateReminderFrame(true)
else
self.PersonalReminder = ""
NSRT.ActivePersonalReminder = nil
self:ProcessReminder()
self:UpdateReminderFrame(true)
end
elseif name and NSRT.Reminders[name] then
self.Reminder = NSRT.Reminders[name]
NSRT.ActiveReminder = name
self:ProcessReminder()
self:UpdateReminderFrame(true)
else
self.Reminder = ""
NSRT.ActiveReminder = nil
self:ProcessReminder()
self:UpdateReminderFrame(true)
end
self:FireCallback("NSRT_REMINDER_CHANGED", self.PersonalReminder, self.Reminder)
end
function NSI:RemoveReminder(name, personal)
if personal then
if name and NSRT.PersonalReminders[name] then
NSRT.PersonalReminders[name] = nil
if NSRT.ActivePersonalReminder == name then
self:SetReminder(nil, true)
end
end
elseif name and NSRT.Reminders[name] then
NSRT.Reminders[name] = nil
NSRT.InviteList[name] = nil
if NSRT.ActiveReminder == name then
self:SetReminder(nil, false)
end
end
end
function NSI:ImportFullReminderString(str, personal, IsUpdate, name)
local name = ""
local values = ""
local diff = ""
if not str:match('\n$') then
str = str..'\n'
end
for line in str:gmatch('([^\n]*)\n') do
if line:find("EncounterID:") then
if values ~= "" then -- meaning we reached a new boss line as the previous one has values already
self:ImportReminder(name, values, false, personal, IsUpdate)
values = ""
name = ""
diff = ""
end
name = line:match("Name:([^;]+)")
diff = line:match("Difficulty:([^;]+)")
values = line.."\n"
elseif name ~= "" then
values = values..line.."\n"
end
end
if values ~= "" and name ~= "" then -- importing the last boss
self:ImportReminder(name, values, false, personal, IsUpdate, diff)
end
end
function NSI:ImportReminder(name, values, activate, personal, IsUpdate, diff)
if not name then name = "Default Reminder" end
local newname = diff and name.." - "..diff or name
if personal then
if NSRT.PersonalReminders[newname] and not IsUpdate then -- if name already exists we add a 2 at the end
self:ImportReminder(name.." 2", values, activate, personal, IsUpdate, diff)
return
end
NSRT.PersonalReminders[newname] = values
if activate then
self:SetReminder(newname, true)
end
return
end
if NSRT.Reminders[newname] and not IsUpdate then -- if name already exists we add a 2 at the end
self:ImportReminder(name.." 2", values, activate, personal, IsUpdate, diff)
return
end
NSRT.Reminders[newname] = values
NSRT.InviteList[newname] = self:InviteListFromReminder(values)
if activate then
self:SetReminder(newname)
end
end
function NSI:InviteListFromReminder(str)
local list = {}
local found = false