-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathTimeline.lua
More file actions
2462 lines (2154 loc) · 101 KB
/
Timeline.lua
File metadata and controls
2462 lines (2154 loc) · 101 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
local DF = _G["DetailsFramework"]
-- Setup timeline hooks for zoom-to-cursor and sticky ruler
-- Call this after creating a timeline with DF:CreateTimeLineFrame
function NSI:SetupTimelineHooks(timeline)
if not timeline then return end
local horizontalSlider = timeline.horizontalSlider
local scaleSlider = timeline.scaleSlider
local elapsedTimeFrame = timeline.elapsedTimeFrame
-- Override mousewheel: scroll = zoom-to-cursor, shift+scroll = vertical pan
if scaleSlider and horizontalSlider then
-- Storage for pre-zoom state
timeline.preZoomState = {}
timeline:SetScript("OnMouseWheel", function(self, delta)
if IsControlKeyDown() then
-- Vertical scroll
if timeline.verticalSlider then
local cur = timeline.verticalSlider:GetValue()
local vMin, vMax = timeline.verticalSlider:GetMinMaxValues()
timeline.verticalSlider:SetValue(math.max(vMin, math.min(vMax, cur - delta * 3)))
end
return
end
-- Zoom to cursor (always, no modifier needed)
local pixelPerSecond = timeline.options.pixels_per_second or 15
local currentScale = timeline.currentScale or 1
local cursorX = GetCursorPosition()
local uiScale = 1 / UIParent:GetEffectiveScale()
cursorX = cursorX * uiScale
local frameLeft = timeline:GetLeft() or 0
local mouseXInFrame = cursorX - frameLeft
local scrollPosition = horizontalSlider:GetValue()
local timeUnderMouse = (scrollPosition + mouseXInFrame) / (pixelPerSecond * currentScale)
timeline.preZoomState.timeUnderMouse = timeUnderMouse
timeline.preZoomState.mouseXInFrame = mouseXInFrame
timeline.preZoomState.pixelPerSecond = pixelPerSecond
local sMin, sMax = scaleSlider:GetMinMaxValues()
local newScale = math.max(sMin, math.min(sMax, currentScale * (delta > 0 and 1.15 or (1 / 1.15))))
scaleSlider:SetValue(newScale)
end)
-- Hook scale slider to adjust scroll after zoom
scaleSlider:HookScript("OnValueChanged", function(self)
local state = timeline.preZoomState
if state and state.timeUnderMouse then
local newScale = timeline.currentScale or 1
-- Calculate where the time under mouse is now
local timeInNewScale = state.timeUnderMouse * state.pixelPerSecond * newScale
-- Set scroll so the time stays under the mouse
local newScrollValue = max(0, timeInNewScale - state.mouseXInFrame)
local _, maxScroll = horizontalSlider:GetMinMaxValues()
horizontalSlider:SetValue(min(newScrollValue, maxScroll))
-- Clear state
timeline.preZoomState = {}
end
end)
end
-- Sticky ruler - keep elapsedTimeFrame fixed at top when scrolling vertically
-- but scroll horizontally with content
if elapsedTimeFrame and timeline.verticalSlider and horizontalSlider then
local headerWidth = timeline.options.header_width or 0
if timeline.options.header_detached then
headerWidth = 0
end
-- Create a clipping container for the ruler
local rulerContainer = CreateFrame("Frame", nil, timeline)
rulerContainer:SetPoint("TOPLEFT", timeline, "TOPLEFT", 0, 0)
rulerContainer:SetPoint("TOPRIGHT", timeline, "TOPRIGHT", 0, 0)
rulerContainer:SetHeight(timeline.options.elapsed_timeline_height or 20)
rulerContainer:SetClipsChildren(true)
rulerContainer:SetFrameLevel(timeline.body:GetFrameLevel() + 10)
-- Reparent elapsedTimeFrame to the clipping container
elapsedTimeFrame:SetParent(rulerContainer)
elapsedTimeFrame:SetFrameLevel(rulerContainer:GetFrameLevel() + 1)
elapsedTimeFrame:EnableMouse(false)
local function updateRulerPosition()
local scrollX = horizontalSlider:GetValue() or 0
local bodyWidth = timeline.body:GetWidth() or timeline:GetWidth()
elapsedTimeFrame:ClearAllPoints()
elapsedTimeFrame:SetPoint("TOPLEFT", rulerContainer, "TOPLEFT", -scrollX, 0)
elapsedTimeFrame:SetWidth(bodyWidth)
elapsedTimeFrame:SetHeight(timeline.options.elapsed_timeline_height or 20)
end
-- Hide original vertical time lines (we use gridOverlay instead for proper z-ordering)
local function repositionLines()
if elapsedTimeFrame.labels then
for i, label in pairs(elapsedTimeFrame.labels) do
if label.line then
label.line:Hide()
end
end
end
end
updateRulerPosition()
-- Update ruler position when scrolling horizontally
horizontalSlider:HookScript("OnValueChanged", function()
updateRulerPosition()
end)
hooksecurefunc(timeline, "SetData", function()
C_Timer.After(0.01, function()
updateRulerPosition()
repositionLines()
end)
end)
if scaleSlider then
scaleSlider:HookScript("OnValueChanged", function()
C_Timer.After(0.01, function()
updateRulerPosition()
repositionLines()
end)
end)
end
end
end
-- Get boss ability lines for the timeline
-- Returns array of timeline lines and max time
-- displayMode: "all" (default), "important" (important only), "combined" (one row)
function NSI:GetBossAbilityLines(encounterID, displayMode, requestedDifficulty)
if not encounterID or not self.BossTimelines or not self.BossTimelines[encounterID] then
return {}, 0
end
-- Default to "important_healer" if no mode specified (backwards compatible with old boolean param)
if displayMode == nil or displayMode == false then
displayMode = self.BossDisplayModes.IMPORTANT_HEALER
elseif displayMode == true then
-- Legacy: true meant filter important only
displayMode = self.BossDisplayModes.IMPORTANT_HEALER
end
local abilities, duration, phases, difficulty = self:GetBossTimelineAbilities(encounterID, requestedDifficulty)
if not abilities then return {}, 0 end
local lines = {}
local maxTime = duration or 0
-- Filter abilities based on display mode
local filteredAbilities = {}
for _, ability in ipairs(abilities) do
local include = true
if displayMode == self.BossDisplayModes.IMPORTANT_HEALER then
include = self:IsAbilityImportantForHealer(ability)
elseif displayMode == self.BossDisplayModes.IMPORTANT_TANK then
include = self:IsAbilityImportantForTank(ability)
elseif displayMode == self.BossDisplayModes.COMBINED_IMPORTANT then
include = self:IsAbilityImportant(ability)
end
-- SHOW_ALL and COMBINED include all abilities
if include then
table.insert(filteredAbilities, ability)
end
end
-- Handle combined modes - put all abilities on one row
if displayMode == self.BossDisplayModes.COMBINED or
displayMode == self.BossDisplayModes.COMBINED_IMPORTANT then
local combinedTimeline = {}
local allTimes = {}
for _, ability in ipairs(filteredAbilities) do
for i, time in ipairs(ability.times) do
table.insert(allTimes, {
time = time,
dur = ability.duration or 3,
spellID = ability.spellID,
name = ability.name,
category = ability.category,
color = ability.color,
})
end
end
-- Sort by time
table.sort(allTimes, function(a, b) return a.time < b.time end)
-- Create timeline blocks
for _, entry in ipairs(allTimes) do
table.insert(combinedTimeline, {
entry.time,
0,
true,
entry.dur,
entry.spellID,
payload = {
category = entry.category,
abilityName = entry.name,
isBossAbility = true,
},
})
end
table.insert(lines, {
spellId = nil,
icon = "Interface\\ICONS\\Achievement_Boss_KilJaeden",
text = "|cffff8800Boss Abilities|r",
timeline = combinedTimeline,
isBossAbility = true,
isCombined = true,
})
return lines, maxTime, phases, difficulty
end
-- Normal mode: group abilities by name (since same ability can appear in multiple phases)
local abilityGroups = {}
for _, ability in ipairs(filteredAbilities) do
local key = ability.name
if not abilityGroups[key] then
abilityGroups[key] = {
name = ability.name,
spellID = ability.spellID,
category = ability.category,
color = ability.color,
sortOrder = ability.sortOrder,
times = {},
durations = {},
}
end
-- Add all times from this ability
for i, time in ipairs(ability.times) do
table.insert(abilityGroups[key].times, time)
table.insert(abilityGroups[key].durations, ability.duration)
end
end
-- Convert to timeline lines, sorted by category then name
local sortedAbilities = {}
for _, data in pairs(abilityGroups) do
table.insert(sortedAbilities, data)
end
table.sort(sortedAbilities, function(a, b)
-- Sort by pre-computed sort order from ParseCategoryForDisplay
local aOrder = a.sortOrder or 99
local bOrder = b.sortOrder or 99
if aOrder ~= bOrder then
return aOrder < bOrder
end
return a.name < b.name
end)
for _, abilityData in ipairs(sortedAbilities) do
local timeline = {}
-- Sort times
local sortedTimes = {}
for i, time in ipairs(abilityData.times) do
table.insert(sortedTimes, {time = time, dur = abilityData.durations[i] or 3})
end
table.sort(sortedTimes, function(a, b) return a.time < b.time end)
-- Create timeline blocks
for _, entry in ipairs(sortedTimes) do
table.insert(timeline, {
entry.time,
0,
true,
entry.dur,
abilityData.spellID,
payload = {
category = abilityData.category,
important = abilityData.important,
isBossAbility = true,
},
})
end
-- Get icon
local lineIcon = nil
if abilityData.spellID then
local spellInfo = C_Spell.GetSpellInfo(abilityData.spellID)
if spellInfo then
lineIcon = spellInfo.iconID
end
end
-- Color-code the name by category
local color = abilityData.color or {0.7, 0.7, 0.7}
local coloredName = string.format("|cff%02x%02x%02x%s|r",
math.floor(color[1] * 255),
math.floor(color[2] * 255),
math.floor(color[3] * 255),
abilityData.name)
-- Check if ability is important for healer/tank roles
local abilityForCheck = {category = abilityData.category}
local isImportantHealer = self:IsAbilityImportantForHealer(abilityForCheck)
local isImportantTank = self:IsAbilityImportantForTank(abilityForCheck)
table.insert(lines, {
spellId = abilityData.spellID,
icon = nil, -- We'll use custom icons on the right instead
text = coloredName,
timeline = timeline,
isBossAbility = true,
category = abilityData.category,
bossIcon = lineIcon or "Interface\\ICONS\\INV_Misc_QuestionMark",
isImportantHealer = isImportantHealer,
isImportantTank = isImportantTank,
})
end
return lines, maxTime, phases, difficulty
end
-- Get timeline data from ProcessedReminder (player's own filtered reminders)
-- Returns data in DetailsFramework timeline format
-- bossDisplayMode: "all", "important", or "combined" (see BossDisplayModes)
function NSI:GetMyTimelineData(includeBossAbilities, bossDisplayMode)
if not self.ProcessedReminder then return nil end
-- Find which encounter has data
local encID = self.EncounterID
if not encID then
-- Try to find any encounter with data
for id, _ in pairs(self.ProcessedReminder) do
encID = id
break
end
end
if not encID or not self.ProcessedReminder[encID] then return nil end
-- Get difficulty from active reminder (default to Mythic)
local reminderDifficulty = "Mythic"
local activeReminder = NSRT.ActiveReminder
local reminderSource = NSRT.Reminders
if not activeReminder or activeReminder == "" then
activeReminder = NSRT.ActivePersonalReminder
reminderSource = NSRT.PersonalReminders
end
if activeReminder and activeReminder ~= "" and reminderSource[activeReminder] then
local diff = reminderSource[activeReminder]:match("Difficulty:([^;\n]+)")
if diff then
reminderDifficulty = strtrim(diff)
end
end
-- Data structure: playerReminders[playerName][spellKey] = {entries}
local playerReminders = {}
local maxTime = 0
-- Pre-calculate all phase start times for converting phase-relative times to absolute times
local phaseStarts = {}
for phase, _ in pairs(self.ProcessedReminder[encID]) do
phaseStarts[phase] = self:GetPhaseStart(encID, phase, reminderDifficulty) or 0
end
-- Iterate through all phases
for phase, reminders in pairs(self.ProcessedReminder[encID]) do
local phaseStart = phaseStarts[phase] or 0
for _, reminder in ipairs(reminders) do
local time = reminder.time
local spellID = reminder.spellID
-- Use settings default if dur not set in reminder
local dur = reminder.dur or (spellID and NSRT.ReminderSettings.SpellDuration or NSRT.ReminderSettings.TextDuration)
local text = reminder.text or reminder.rawtext
local glowUnit = reminder.glowunit
local glowUnitNames = ""
if glowUnit and #glowUnit > 0 then
for i, name in ipairs(glowUnit) do
glowUnitNames = glowUnitNames ..
NSAPI:Shorten(NSAPI:GetChar(name), 12, false, "GlobalNickNames") .. " "
end
else
glowUnitNames = nil
end
if time then
-- Convert phase-relative time to absolute time
local absoluteTime = phaseStart + time
-- Track max time for timeline length
if absoluteTime + dur > maxTime then
maxTime = absoluteTime + dur
end
-- For processed reminders, we don't have tag info
-- Use "You" as the player name since these are your reminders
local player = "You"
-- Determine the key for this ability
local abilityKey = spellID and tostring(spellID) or "text"
playerReminders[player] = playerReminders[player] or {}
playerReminders[player][abilityKey] = playerReminders[player][abilityKey] or {
spellID = spellID,
text = text,
entries = {}
}
table.insert(playerReminders[player][abilityKey].entries, {
time = absoluteTime,
dur = dur,
phase = phase,
text = text,
glowUnit = glowUnitNames,
})
end
end
end
-- Convert to timeline format
local lines = {}
-- Sort abilities by spellID then text
local sortedAbilities = {}
if playerReminders["You"] then
for abilityKey, data in pairs(playerReminders["You"]) do
table.insert(sortedAbilities, {key = abilityKey, data = data})
end
end
table.sort(sortedAbilities, function(a, b)
local aNum = tonumber(a.key)
local bNum = tonumber(b.key)
if aNum and bNum then
return aNum < bNum
elseif aNum then
return true
elseif bNum then
return false
else
return a.key < b.key
end
end)
-- Create lines
for _, ability in ipairs(sortedAbilities) do
local abilityData = ability.data
local spellID = abilityData.spellID
local timeline = {}
-- Sort entries by time
table.sort(abilityData.entries, function(a, b) return a.time < b.time end)
-- Create timeline blocks
for _, entry in ipairs(abilityData.entries) do
table.insert(timeline, {
entry.time,
0,
true,
entry.dur,
spellID,
payload = { phase = entry.phase, text = entry.text, glowUnit = entry.glowUnit },
})
end
-- Get display info
local lineIcon = nil
local lineName = ""
local lineSpellId = spellID
if spellID then
local spellInfo = C_Spell.GetSpellInfo(spellID)
if spellInfo then
lineIcon = spellInfo.iconID
lineName = spellInfo.name or ""
end
else
lineName = "Notes"
lineIcon = "Interface\\ICONS\\INV_Misc_Note_01"
end
table.insert(lines, {
spellId = lineSpellId,
icon = nil, -- We'll use custom icons on the right instead
text = lineName,
timeline = timeline,
isYourReminder = true,
reminderSpellIcon = lineIcon or "Interface\\ICONS\\INV_Misc_QuestionMark",
})
end
-- Add boss abilities if requested (at the top)
local phases = nil
local difficulty = nil
local finalLines = {}
if includeBossAbilities and encID then
local bossLines, bossMaxTime, bossPhases, bossDifficulty = self:GetBossAbilityLines(encID, bossDisplayMode, reminderDifficulty)
phases = bossPhases
difficulty = bossDifficulty
-- Add boss ability lines first
for _, line in ipairs(bossLines) do
table.insert(finalLines, line)
end
-- Add separator line if we have both player and boss abilities
if #lines > 0 and #bossLines > 0 then
table.insert(finalLines, {
spellId = nil,
icon = "Interface\\ICONS\\INV_Misc_Gear_01",
text = "|cff888888--- Your Reminders ---|r",
timeline = {},
isSeparator = true,
})
end
-- Use boss timeline length if longer
if bossMaxTime > maxTime then
maxTime = bossMaxTime
end
end
-- Append player reminder lines
for _, line in ipairs(lines) do
table.insert(finalLines, line)
end
local timelineLength = math.max(60, math.ceil(maxTime / 30) * 30)
return {
length = timelineLength,
defaultColor = {1, 1, 1, 1},
useIconOnBlocks = true,
lines = finalLines,
}, encID, phases, difficulty
end
-- Get timeline data from a reminder set (ALL reminders, for raid leaders)
-- Returns data in DetailsFramework timeline format
-- bossDisplayMode: "all", "important", or "combined" (see BossDisplayModes)
function NSI:GetAllTimelineData(reminderName, personal, includeBossAbilities, bossDisplayMode)
local source = personal and NSRT.PersonalReminders or NSRT.Reminders
local reminderStr = source[reminderName]
if not reminderStr then return nil end
-- Extract encounter ID from the reminder string
local encID = reminderStr:match("EncounterID:(%d+)")
encID = encID and tonumber(encID)
-- Extract difficulty from the reminder string (default to Mythic)
local reminderDifficulty = reminderStr:match("Difficulty:([^;\n]+)")
reminderDifficulty = reminderDifficulty and strtrim(reminderDifficulty) or "Mythic"
-- Data structure: playerReminders[playerName][spellKey] = {entries}
-- where spellKey is spellID or text (if no spellID)
local playerReminders = {}
local maxTime = 0
local discoveredPhases = {}
for line in reminderStr:gmatch('[^\r\n]+') do
local tag = line:match("tag:([^;]+)")
local time = line:match("time:(%d*%.?%d+)")
local spellID = line:match("spellid:(%d+)")
local dur = line:match("dur:(%d+)")
local text = line:match("text:([^;]+)")
local phase = line:match("ph:(%d+)") or "1"
local glowUnit = line:match("glowunit:([^;]+)")
local glowUnitNames = ""
if glowUnit then
for name in glowUnit:gmatch("([^%s:]+)") do
if name ~= "glowunit" then
glowUnitNames = glowUnitNames .. NSAPI:Shorten(NSAPI:GetChar(name), 12, false, "GlobalNickNames") .. " "
end
end
else
glowUnitNames = nil
end
if tag and time then
time = tonumber(time)
phase = tonumber(phase)
spellID = spellID and tonumber(spellID)
-- Use settings default if dur not specified in reminder string
if dur then
dur = tonumber(dur)
else
dur = spellID and NSRT.ReminderSettings.SpellDuration or NSRT.ReminderSettings.TextDuration
end
-- Track discovered phases for later phase start calculation
discoveredPhases[phase] = true
-- Determine the key for this ability
-- For spells: use spellID so each spell gets its own lane
-- For text-only: use "text" so all text reminders for a player are on one lane
local abilityKey = spellID and tostring(spellID) or "text"
-- Parse player names from tag (use [^,]+ to support UTF-8/accented characters)
for player in tag:gmatch("([^,]+)") do
player = strtrim(player)
local lowerPlayer = strlower(player)
-- Convert "everyone" and "all" to a unified "Everyone" lane
if lowerPlayer == "everyone" or lowerPlayer == "all" then
player = "Everyone"
-- Skip role/group tags
elseif lowerPlayer == "healer" or
lowerPlayer == "tank" or
lowerPlayer == "dps" or
lowerPlayer == "melee" or
lowerPlayer == "ranged" or
lowerPlayer:match("^group%d+$") or
lowerPlayer:match("^%d+$") then -- skip spec IDs
player = nil
end
if player then
playerReminders[player] = playerReminders[player] or {}
playerReminders[player][abilityKey] = playerReminders[player][abilityKey] or {
spellID = spellID,
text = text,
entries = {}
}
table.insert(playerReminders[player][abilityKey].entries, {
time = time,
dur = dur,
phase = phase,
text = text, -- store text per entry for tooltips
glowUnit = glowUnitNames,
})
end
end
end
end
-- Pre-calculate phase start times for converting phase-relative times to absolute times
local phaseStarts = {}
for phase, _ in pairs(discoveredPhases) do
phaseStarts[phase] = encID and self:GetPhaseStart(encID, phase, reminderDifficulty) or 0
end
-- Convert to timeline format
local lines = {}
-- First, get sorted list of players (Everyone first, then alphabetical)
local sortedPlayers = {}
for player in pairs(playerReminders) do
table.insert(sortedPlayers, player)
end
table.sort(sortedPlayers, function(a, b)
if a == "Everyone" then return true end
if b == "Everyone" then return false end
return a < b
end)
-- For each player, add all their abilities as separate lines
for _, player in ipairs(sortedPlayers) do
local abilities = playerReminders[player]
-- Sort abilities by spellID (numeric) or text (alphabetic)
local sortedAbilities = {}
for abilityKey, data in pairs(abilities) do
table.insert(sortedAbilities, {key = abilityKey, data = data})
end
table.sort(sortedAbilities, function(a, b)
-- Numeric keys (spellIDs) come before text keys
local aNum = tonumber(a.key)
local bNum = tonumber(b.key)
if aNum and bNum then
return aNum < bNum
elseif aNum then
return true
elseif bNum then
return false
else
return a.key < b.key
end
end)
-- Create a line for each ability
for _, ability in ipairs(sortedAbilities) do
local abilityData = ability.data
local spellID = abilityData.spellID
local timeline = {}
-- Sort entries by phase-relative time for consistent ordering
table.sort(abilityData.entries, function(a, b)
if a.phase ~= b.phase then return a.phase < b.phase end
return a.time < b.time
end)
-- Create timeline blocks with absolute times
for _, entry in ipairs(abilityData.entries) do
-- Convert phase-relative time to absolute time
local phaseStart = phaseStarts[entry.phase] or 0
local absoluteTime = phaseStart + entry.time
-- Track max time for timeline length
if absoluteTime + entry.dur > maxTime then
maxTime = absoluteTime + entry.dur
end
-- Format: {time, length, isAura, auraDuration, blockSpellId}
table.insert(timeline, {
absoluteTime, -- [1] time in seconds (absolute)
0, -- [2] length (0 for icon-based display)
true, -- [3] isAura (shows duration bar)
entry.dur, -- [4] auraDuration
spellID, -- [5] blockSpellId
payload = {phase = entry.phase, text = entry.text, glowUnit = entry.glowUnit}, -- use entry-specific text
})
end
-- Get display info
local lineIcon = nil
local lineName = ""
local lineSpellId = spellID
if spellID then
local spellInfo = C_Spell.GetSpellInfo(spellID)
if spellInfo then
lineIcon = spellInfo.iconID
lineName = spellInfo.name or ""
end
else
-- Text-only reminders: label the lane as "Notes"
lineName = "Notes"
lineIcon = "Interface\\ICONS\\INV_Misc_Note_01"
end
-- Get shortened player name
local shortPlayer = NSAPI:Shorten(player, 12, false, "GlobalNickNames") or player
-- Get class color for the player
local classColorHex = nil
local unitName = NSAPI:GetChar(player, true, "NorthernSkyRaidTools")
if unitName and UnitExists(unitName) then
local _, classFile = UnitClass(unitName)
if classFile then
local color = GetClassColorObj(classFile)
if color then
classColorHex = color:GenerateHexColor()
end
end
end
table.insert(lines, {
spellId = lineSpellId,
icon = nil, -- We'll use custom icons on the right instead
text = lineName, -- Spell name left-anchored
timeline = timeline,
isPlayerAssignment = true,
playerName = shortPlayer,
playerClassColor = classColorHex,
playerSpellIcon = lineIcon or "Interface\\ICONS\\INV_Misc_QuestionMark",
})
end
end
-- Add boss abilities if requested (at the top)
local phases = nil
local difficulty = nil
local finalLines = {}
if includeBossAbilities and encID then
local bossLines, bossMaxTime, bossPhases, bossDifficulty = self:GetBossAbilityLines(encID, bossDisplayMode, reminderDifficulty)
phases = bossPhases
difficulty = bossDifficulty
-- Add boss ability lines first
for _, line in ipairs(bossLines) do
table.insert(finalLines, line)
end
-- Add separator line if we have both player and boss abilities
if #lines > 0 and #bossLines > 0 then
table.insert(finalLines, {
spellId = nil,
icon = "Interface\\ICONS\\INV_Misc_Gear_01",
text = "|cff888888--- Player Reminders ---|r",
timeline = {},
isSeparator = true,
})
end
-- Use boss timeline length if longer
if bossMaxTime > maxTime then
maxTime = bossMaxTime
end
end
-- Append player reminder lines
for _, line in ipairs(lines) do
table.insert(finalLines, line)
end
-- Round up max time to nearest 30 seconds, minimum 60 seconds
local timelineLength = math.max(60, math.ceil(maxTime / 30) * 30)
return {
length = timelineLength,
defaultColor = {1, 1, 1, 1},
useIconOnBlocks = true,
lines = finalLines,
}, encID, phases, difficulty
end
-- Create the timeline window
function NSI:CreateTimelineWindow()
local window_width = 1100
local window_height = 550
local timelineWindow = DF:CreateSimplePanel(UIParent, window_width, window_height,
"|cFF00FFFFNorthern Sky|r Timeline", "NSUITimelineWindow", {
DontRightClickClose = true,
UseStatusBar = false,
UseScaleBar = true,
},
NSRT.NSUI.timeline_window)
timelineWindow:SetPoint("CENTER")
timelineWindow:SetFrameStrata("DIALOG")
timelineWindow:EnableMouse(true)
timelineWindow:SetMovable(true)
timelineWindow:RegisterForDrag("LeftButton")
timelineWindow:SetScript("OnDragStart", timelineWindow.StartMoving)
timelineWindow:SetScript("OnDragStop", timelineWindow.StopMovingOrSizing)
-- Create resize grip in bottom-right corner
local resizeGrip = CreateFrame("Button", nil, timelineWindow)
resizeGrip:SetSize(16, 16)
resizeGrip:SetPoint("BOTTOMRIGHT", timelineWindow, "BOTTOMRIGHT", -2, 2)
resizeGrip:SetNormalTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Up")
resizeGrip:SetHighlightTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Highlight")
resizeGrip:SetPushedTexture("Interface\\ChatFrame\\UI-ChatIM-SizeGrabber-Down")
resizeGrip:EnableMouse(true)
-- Custom resize logic to avoid the jump caused by StartSizing snapping to mouse position
resizeGrip.isResizing = false
resizeGrip:SetScript("OnMouseDown", function(self, button)
if button == "LeftButton" then
self.isResizing = true
-- Store initial state when drag starts
self.startWidth = timelineWindow:GetWidth()
self.startHeight = timelineWindow:GetHeight()
local scale = timelineWindow:GetEffectiveScale()
local cursorX, cursorY = GetCursorPosition()
self.startCursorX = cursorX / scale
self.startCursorY = cursorY / scale
-- Re-anchor to TOPLEFT so resize only affects bottom-right
local left = timelineWindow:GetLeft()
local top = timelineWindow:GetTop()
timelineWindow:ClearAllPoints()
timelineWindow:SetPoint("TOPLEFT", UIParent, "BOTTOMLEFT", left, top)
end
end)
resizeGrip:SetScript("OnMouseUp", function(self, button)
self.isResizing = false
end)
resizeGrip:SetScript("OnUpdate", function(self)
if not self.isResizing then return end
local scale = timelineWindow:GetEffectiveScale()
local cursorX, cursorY = GetCursorPosition()
cursorX = cursorX / scale
cursorY = cursorY / scale
-- Calculate delta from start position
local deltaX = cursorX - self.startCursorX
local deltaY = cursorY - self.startCursorY
-- Calculate new size (bottom-right resize: width increases with +X, height increases with -Y)
local newWidth = self.startWidth + deltaX
local newHeight = self.startHeight - deltaY
-- Clamp to bounds
local minWidth, minHeight, maxWidth, maxHeight = 1100, 550, 2000, 1200
newWidth = math.max(minWidth, math.min(maxWidth, newWidth))
newHeight = math.max(minHeight, math.min(maxHeight, newHeight))
timelineWindow:SetSize(newWidth, newHeight)
end)
timelineWindow.resizeGrip = resizeGrip
local options_dropdown_template = DF:GetTemplate("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
-- Mode: "my" = My Reminders (from ProcessedReminder), "all" = All Reminders (from raw strings)
timelineWindow.mode = "my"
-- Mode toggle dropdown
local function BuildModeDropdownOptions()
return {
{
label = "My Reminders",
value = "my",
onclick = function(_, _, value)
timelineWindow.mode = value
timelineWindow.reminderLabel:Hide()
timelineWindow.reminderDropdown:Hide()
if timelineWindow.playButton then timelineWindow.playButton:Show() end
self:RefreshTimelineForMode()
end
},
{
label = "All Reminders (Raid Leader)",
value = "all",
onclick = function(_, _, value)
timelineWindow.mode = value
timelineWindow.reminderLabel:Show()
timelineWindow.reminderDropdown:Show()
if timelineWindow.playButton then
-- Stop preview and hide play button in "All Reminders" mode
if timelineWindow.previewActive then
timelineWindow.previewActive = false
timelineWindow.previewStartTime = nil
if timelineWindow.timeline and timelineWindow.timeline.previewLine then
timelineWindow.timeline.previewLine:Hide()
end
NSI:HideAllReminders()
timelineWindow.playButton.text = "Play Preview"
timelineWindow.playButton:SetIcon(NSI.LSM:Fetch("statusbar", "play_icon"), 14, 14, "OVERLAY", nil, {0, 1, 0, 1})
end
timelineWindow.playButton:Hide()
end
self:RefreshTimelineForMode()
end
},
}
end
local modeLabel = DF:CreateLabel(timelineWindow, "View:", 11, "white")
modeLabel:SetPoint("TOPLEFT", timelineWindow, "TOPLEFT", 10, -30)
local modeDropdown = DF:CreateDropDown(timelineWindow, BuildModeDropdownOptions, "my", 200)
modeDropdown:SetTemplate(options_dropdown_template)
modeDropdown:SetPoint("LEFT", modeLabel, "RIGHT", 10, 0)
timelineWindow.modeDropdown = modeDropdown
-- Build reminder dropdown options function (for "All Reminders" mode)
local function BuildReminderDropdownOptions()
local options = {}
-- Add shared reminders
local sharedList = self:GetAllReminderNames(false)
for _, data in ipairs(sharedList) do
table.insert(options, {
label = data.name,
value = {name = data.name, personal = false},
onclick = function(_, _, value)
self:RefreshAllRemindersTimeline(value.name, value.personal)
timelineWindow.currentReminder = value
end
})
end
-- Add personal reminders with separator
local personalList = self:GetAllReminderNames(true)
if #personalList > 0 then
table.insert(options, {
label = "--- Personal ---",
value = nil,
})
for _, data in ipairs(personalList) do
table.insert(options, {
label = data.name .. " (Personal)",
value = {name = data.name, personal = true},
onclick = function(_, _, value)
self:RefreshAllRemindersTimeline(value.name, value.personal)
timelineWindow.currentReminder = value
end
})
end
end
return options
end
-- Reminder selection dropdown (only shown in "All Reminders" mode)
local reminderLabel = DF:CreateLabel(timelineWindow, "Reminder Set:", 11, "white")
reminderLabel:SetPoint("LEFT", modeDropdown, "RIGHT", 20, 0)
timelineWindow.reminderLabel = reminderLabel
reminderLabel:Hide() -- Hidden by default (My Reminders mode)
local reminderDropdown = DF:CreateDropDown(timelineWindow, BuildReminderDropdownOptions, nil, 300)
reminderDropdown:SetTemplate(options_dropdown_template)
reminderDropdown:SetPoint("LEFT", reminderLabel, "RIGHT", 10, 0)
timelineWindow.reminderDropdown = reminderDropdown
reminderDropdown:Hide() -- Hidden by default (My Reminders mode)
local options_button_template = DF:GetTemplate("button", "OPTIONS_BUTTON_TEMPLATE")
local playColor = { 20 / 255, 245 / 255, 87 / 255, 1 } -- {r,g,b,a}
local stopColor = { 247 / 255, 32 / 255, 61 / 255, 1 } -- {r,g,b,a}
local playButton = DF:CreateButton(timelineWindow, function()
if timelineWindow.previewActive then