-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathtimeline.lua
1438 lines (1187 loc) · 48 KB
/
timeline.lua
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
---@type detailsframework
local detailsFramework = _G ["DetailsFramework"]
if (not detailsFramework or not DetailsFrameworkCanLoad) then
return
end
local _
--lua locals
local unpack = table.unpack or unpack --lua local
local CreateFrame = CreateFrame
local PixelUtil = PixelUtil or DFPixelUtil
---@alias timelinecomponenttype
---| "line"
---| "block"
---| "length"
---| "header"
---| "timeline"
---| "body"
---@class df_timeline_options : table
---@field width number
---@field height number
---@field can_resize boolean
---@field line_height number
---@field line_padding number
---@field show_elapsed_timeline boolean
---@field elapsed_timeline_height number
---@field header_width number
---@field header_detached boolean if true the frameCanvas will have .headerFrame
---@field pixels_per_second number
---@field scale_min number
---@field scale_max number
---@field zoom_out_zero boolean if true, when the scale is reduced by mouse wheel, it will be set to 0
---@field use_perpixel_buttons boolean
---@field backdrop backdrop
---@field backdrop_color number[]
---@field backdrop_color_highlight number[]
---@field backdrop_border_color number[]
---@field slider_backdrop backdrop
---@field slider_backdrop_color number[]
---@field slider_backdrop_border_color number[]
---@field title_template string "ORANGE_FONT_TEMPLATE"
---@field text_tempate string "OPTIONS_FONT_TEMPLATE"
---@field on_enter fun(self:df_timeline_line) --line
---@field on_leave fun(self:df_timeline_line) --line
---@field on_create_line fun(self:df_timeline_line) --line
---@field on_refresh_line fun(self:df_timeline_line) --line
---@field block_on_enter fun(self:button)
---@field block_on_leave fun(self:button)
---@field block_on_click fun(self:button)
---@field block_on_create fun(self:df_timeline_line_block)
---@field block_on_set_data fun(self:button, data:table)
---@field block_on_create_auralength fun(self:df_timeline_line_block)
---@field block_on_create_blocklength fun(self:df_timeline_line_block)
---@field block_on_enter_auralength fun(self:df_timeline_line_block)
---@field block_on_leave_auralength fun(self:df_timeline_line_block)
---@field block_on_click_auralength fun(self:df_timeline_line_block, button:string)
---@field block_on_enter_blocklength fun(self:df_timeline_line_block)
---@field block_on_leave_blocklength fun(self:df_timeline_line_block)
---@field block_on_click_blocklength fun(self:df_timeline_line_block, button:string)
local timeline_options = {
width = 400,
height = 700,
line_height = 20,
line_padding = 1,
auto_height = false, --set the timeline height to the amount of lines it has
show_elapsed_timeline = true,
elapsed_timeline_height = 20,
--space to put the player/spell name and icons
header_width = 150,
header_detached = false,
--how many pixels will be use to represent 1 second
pixels_per_second = 20,
use_perpixel_buttons = false,
scale_min = 0.15,
scale_max = 1,
zoom_out_zero = false,
backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
backdrop_color = {0, 0, 0, 0.2},
backdrop_color_highlight = {.2, .2, .2, 0.4},
backdrop_border_color = {0.1, 0.1, 0.1, .2},
slider_backdrop = {edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true},
slider_backdrop_color = {0, 0, 0, 0.2},
slider_backdrop_border_color = {0.1, 0.1, 0.1, .2},
title_template = "ORANGE_FONT_TEMPLATE",
text_tempate = "OPTIONS_FONT_TEMPLATE",
---@param self df_timeline_line
on_enter = function(self)
self:SetBackdropColor(unpack(self.backdrop_color_highlight))
end,
on_leave = function(self)
self:SetBackdropColor(unpack(self.backdrop_color))
end,
-- block_on_enter = function(self)
-- end,
-- block_on_leave = function(self)
-- end,
-- block_on_click = function(self)
-- end,
-- block_on_set_data = function(self, data)
-- end,
-- block_on_enter_auralength = function()
-- end,
-- block_on_leave_auralength = function()
-- end,
}
---@class df_timeline_block_data : table
---@field [1] number timeInSeconds
---@field [2] number length
---@field [3] boolean? isAura
---@field [4] number? auraDuration
---@field [5] number? blockSpellId
---@field payload any
---@field customIcon any
---@field customName any
---@field isIconRow boolean?
---@field showRightIcon boolean?
---@field blockLengthHeight number? --need to remove
---@field blockLengthYOffset number? --need to remove
---@field auraLengthColor any
---@field auraLengthTexture any
---@field auraHeight number?
---@field auraYOffset number?
---@class df_timeline_linedata : table
---@field spellId number
---@field icon any
---@field coords number[]?
---@field text string?
---@field timeline df_timeline_block_data[]
---@field lineHeight number?
---@field disabled boolean?
---@field type string|number? helper to identify the line, defined by user
---@class df_timeline_scrolldata : table
---@field length number
---@field defaultColor number[]
---@field useIconOnBlocks boolean
---@field lines df_timeline_linedata[]
---@class df_timeline_line_blockinfo : table
---@field time number
---@field duration number
---@field spellId number
---@field payload any
---@field customIcon any
---@field customName any
---@class df_timeline_line_block : button
---@field type timelinecomponenttype
---@field icon texture
---@field text fontstring
---@field background texture
---@field blockLength df_timeline_line_blocklength
---@field info df_timeline_line_blockinfo
---@field blockData df_timeline_block_data
---@field timeline df_timeline
---@field backgroundBorder border_frame
---@class df_timeline_line_blocklength : button
---@field type timelinecomponenttype
---@field isMoving boolean
---@field Texture texture
---@field RightIcon texture
---@field block df_timeline_line_block
---@field timeline df_timeline
---@param auraLengthFrame df_timeline_line_blocklength
local registerForDrag = function(auraLengthFrame)
auraLengthFrame:SetMovable(true)
auraLengthFrame:SetScript("OnMouseDown", function()
do return end
auraLengthFrame.isMoving = true
auraLengthFrame:StartMoving()
auraLengthFrame:ClearAllPoints()
auraLengthFrame:SetScript("OnUpdate", function()
--get the timeline
local timeline = auraLengthFrame.timeline
local blockUnderMouse = timeline:GetBlockUnderMouse()
if (blockUnderMouse) then
print("underblock")
else
print("no block under mouse")
end
end)
end)
auraLengthFrame:SetScript("OnMouseUp", function()
do return end
auraLengthFrame:StopMovingOrSizing()
auraLengthFrame.isMoving = false
auraLengthFrame:SetScript("OnUpdate", nil)
--set the original point
--auraLengthFrame:ClearAllPoints()
--auraLengthFrame:SetPoint("topleft", cooldownSelectorScroll, "topleft", auraLengthFrame.originalXPoint, auraLengthFrame.originalYPoint)
end)
end
---@class df_timeline_line_mixin : frame
---@field lineHeader frame
---@field blocks df_timeline_line_block[]
---@field CreateBlock fun(self:df_timeline_line, index:number):df_timeline_line_block
---@field GetBlock fun(self:df_timeline_line, index:number):df_timeline_line_block
---@field SetBlocksFromData fun(self:df_timeline_line)
---@field GetAllBlocks fun(self:df_timeline_line):df_timeline_line_block[]
---@field CreateBlockLength fun(block:df_timeline_line_block):df_timeline_line_blocklength
---@field OnEnterBlockLength fun(self:df_timeline_line_block)
---@field OnLeaveBlockLength fun(self:df_timeline_line_block)
---@field Reset fun(self:df_timeline_line)
detailsFramework.TimeLine_LineMixin = {
GetAllBlocks = function(self)
return self.blocks
end,
SetBlocksFromData = function(self)
local timeline = self:GetParent():GetParent()
local data = timeline.data
local defaultColor = timeline.defaultColor --guarantee to have a value
self:Show()
--none of these values are scaled, need to calculate
local pixelPerSecond = timeline.pixelPerSecond
local totalLength = timeline.totalLength
local scale = timeline.currentScale
pixelPerSecond = pixelPerSecond * scale
local headerWidth = timeline.headerWidth
--dataIndex stores which line index from the data this line will use
--lineData store members: .text .icon .timeline
---@type df_timeline_linedata
local lineData = data.lines[self.dataIndex]
self.lineData = lineData
local mouseEnabled = not lineData.disabled
self.lineHeader:EnableMouse(mouseEnabled)
self:EnableMouse(mouseEnabled)
self:SetMouseClickEnabled(mouseEnabled)
self:SetPropagateMouseClicks(true)
self.enabled = mouseEnabled
if (lineData.lineHeight) then
self:SetHeight(lineData.lineHeight)
self.lineHeader:SetHeight(lineData.lineHeight)
else
self:SetHeight(timeline.options.line_height)
self.lineHeader:SetHeight(timeline.options.line_height)
end
self.spellId = lineData.spellId
--if there's an icon, anchor the text at the right side of the icon
--this is the title and icon of the title
if (lineData.icon) then
self.icon:SetTexture(lineData.icon)
if (lineData.coords) then
self.icon:SetTexCoord(unpack(lineData.coords))
else
self.icon:SetTexCoord(.1, .9, .1, .9)
end
self.text:SetText(lineData.text or "")
self.text:SetPoint("left", self.icon.widget, "right", 2, 0)
else
self.icon:SetTexture(nil)
self.text:SetText(lineData.text or "")
self.text:SetPoint("left", self, "left", 2, 0)
end
if (self.dataIndex % 2 == 1) then
self:SetBackdropColor(0, 0, 0, 0)
else
local r, g, b, a = unpack(self.backdrop_color)
self:SetBackdropColor(r, g, b, a)
end
self:SetWidth(timeline.body:GetWidth()) -- self:SetWidth(5000)
local timelineData = lineData.timeline
local spellId = lineData.spellId
local useIconOnBlock = data.useIconOnBlocks
local baseFrameLevel = timeline:GetFrameLevel() + 10
local errorHandler = geterrorhandler()
local rowStartBlock
for i = 1, #timelineData do
local blockInfo = timelineData[i]
local timeInSeconds = blockInfo[1]
local length = blockInfo[2]
local isAura = blockInfo[3]
local auraDuration = blockInfo[4]
local blockSpellId = blockInfo[5]
local payload = blockInfo.payload
local customIcon = blockInfo.customIcon
local customName = blockInfo.customName
local inRow = blockInfo.isIconRow
local showRightIcon = blockInfo.showRightIcon
local blockLengthHeight = blockInfo.blockLengthHeight or blockInfo.auraHeight
local blockLengthYOffset = blockInfo.blockLengthYOffset or blockInfo.auraYOffset
local xOffset = pixelPerSecond * timeInSeconds
local width = pixelPerSecond * length
if (timeInSeconds < -0.2) then
xOffset = xOffset / 2.5
end
local block = self:GetBlock(i)
block:Show()
block:SetFrameLevel(baseFrameLevel)
block.blockData = blockInfo
if (inRow) then
--when tagged as row, the icon will be attached to the latest block added into the line
local lastBlock = self:GetBlock(i-1)
PixelUtil.SetPoint(block, "left", lastBlock, "right", 2, 0)
if (not rowStartBlock) then
rowStartBlock = lastBlock
end
else
PixelUtil.SetPoint(block, "left", self, "left", xOffset + headerWidth, 0)
rowStartBlock = nil
end
auraDuration = auraDuration or 0
block.info.spellId = blockSpellId or spellId
block.info.time = timeInSeconds
block.info.duration = auraDuration
block.info.payload = payload
block.info.customIcon = customIcon --nil set to nil if not exists
block.info.customName = customName
block.text:SetText(customName or "")
if (useIconOnBlock) then
local iconTexture = lineData.icon
if (customIcon) then
iconTexture = customIcon
elseif (blockSpellId) then
local spellInfo = C_Spell.GetSpellInfo(blockSpellId)
iconTexture = spellInfo.iconID
end
block.icon:SetTexture(iconTexture)
block.icon:SetTexCoord(.1, .9, .1, .9)
block.icon:SetAlpha(.965)
block.icon:SetSize(self:GetHeight(), self:GetHeight())
if (timeInSeconds < -0.2) then
block.icon:SetDesaturated(true)
else
block.icon:SetDesaturated(false)
end
PixelUtil.SetSize(block, self:GetHeight(), self:GetHeight())
if (isAura) then
block.blockLength:Show()
local thisAuraDuration = auraDuration
if (timeInSeconds + thisAuraDuration > timeline.data.length) then
thisAuraDuration = timeline.data.length - timeInSeconds
end
local blockLengthTexture = blockInfo.auraLengthTexture
if (blockLengthTexture) then
block.blockLength.Texture:SetTexture(blockLengthTexture, true)
block.blockLength.Texture:SetHorizTile(true)
else
block.blockLength.Texture:SetColorTexture(1, 1, 1, 1)
end
local auraLengthColor = blockInfo.auraLengthColor
if (auraLengthColor) then
local r, g, b, a = detailsFramework:ParseColors(auraLengthColor)
block.blockLength.Texture:SetVertexColor(r, g, b, a or 0.5)
else
block.blockLength.Texture:SetVertexColor(1, 1, 1, 0.5)
end
block.blockLength.Texture:Show()
block.blockLength:SetWidth(pixelPerSecond * thisAuraDuration)
block.blockLength:SetHeight(blockLengthHeight and blockLengthHeight or block:GetHeight())
if (showRightIcon) then
block.blockLength.RightIcon:SetTexture(iconTexture)
block.blockLength.RightIcon:SetTexCoord(.1, .9, .1, .9)
block.blockLength.RightIcon:SetWidth(block.blockLength:GetHeight())
block.blockLength.RightIcon:Show()
else
block.blockLength.RightIcon:SetTexture(nil)
block.blockLength.RightIcon:Hide()
end
if (inRow) then
block.blockLength:SetPoint("bottomleft", rowStartBlock or block.icon, "bottomleft", 0, blockLengthYOffset)
else
block.blockLength:SetPoint("bottomleft", block.icon, "bottomleft", 0, blockLengthYOffset)
end
--block:SetWidth(max(pixelPerSecond * auraDuration, 16))
else
block.blockLength:Hide()
end
block.background:SetVertexColor(0, 0, 0, 0)
else
block.icon:SetTexture("")
block.background:SetVertexColor(0, 0, 0, 0)
PixelUtil.SetSize(block, max(width, 16), self:GetHeight())
block.blockLength:Hide()
end
if (timeline.options.block_on_set_data) then
xpcall(timeline.options.block_on_set_data, errorHandler, block, blockInfo)
end
if (timeline.options.block_on_click) then
block:SetMouseClickEnabled(true)
block:SetScript("OnClick", timeline.options.block_on_click)
end
end
end,
GetBlock = function(self, index)
local block = self.blocks[index]
if (not block) then --CreateBlock
block = self:CreateBlock(index)
end
return block
end,
CreateBlock = function(self, index)
---@type df_timeline_line_block
local block = CreateFrame("button", nil, self, "BackdropTemplate")
block:SetMouseClickEnabled(false)
self.blocks[index] = block
block.type = "block"
local background = block:CreateTexture(nil, "background")
background:SetColorTexture(1, 1, 1, 1)
local icon = block:CreateTexture(nil, "artwork")
local text = block:CreateFontString(nil, "artwork", "GameFontNormal")
local backgroundBorder = detailsFramework:CreateFullBorder("$parentBorder", block)
local iconOffset = UIParent:GetEffectiveScale() * -1
PixelUtil.SetPoint(backgroundBorder, "topleft", block, "topleft", -iconOffset, iconOffset)
PixelUtil.SetPoint(backgroundBorder, "topright", block, "topright", iconOffset, iconOffset)
PixelUtil.SetPoint(backgroundBorder, "bottomleft", block, "bottomleft", -iconOffset, -iconOffset)
PixelUtil.SetPoint(backgroundBorder, "bottomright", block, "bottomright", iconOffset, -iconOffset)
backgroundBorder:SetVertexColor(0, 0, 0, 1) --need to create a class for border frame
background:SetAllPoints()
icon:SetPoint("center", block, "center", 0, 0)
text:SetPoint("left", icon, "right", 2, 0)
detailsFramework:SetFontOutline(text, "OUTLINE")
block.icon = icon
block.text = text
block.background = background
block.backgroundBorder = backgroundBorder
local timeline = self:GetParent():GetParent()
block.timeline = timeline
---@type df_timeline_options
local timelineOptions = timeline.options
block:SetScript("OnEnter", timelineOptions.block_on_enter)
block:SetScript("OnLeave", timelineOptions.block_on_leave)
block:SetMouseClickEnabled(false)
---@diagnostic disable-next-line: missing-fields
block.info = {}
if (timelineOptions.block_on_create) then
timelineOptions.block_on_create(block)
end
detailsFramework.TimeLine_LineMixin.CreateBlockLength(block)
return block
end,
CreateBlockLength = function(block)
---@type df_timeline_line_blocklength
local blockLengthFrame = CreateFrame("button", nil, block)
blockLengthFrame:SetFrameLevel(block:GetFrameLevel() - 1)
blockLengthFrame:SetScript("OnEnter", detailsFramework.TimeLine_LineMixin.OnEnterBlockLength)
blockLengthFrame:SetScript("OnLeave", detailsFramework.TimeLine_LineMixin.OnLeaveBlockLength)
blockLengthFrame:SetScript("OnClick", detailsFramework.TimeLine_LineMixin.OnClickBlockLength)
--save reference of the block
blockLengthFrame.block = block
--save reference of the timeline
blockLengthFrame.timeline = block:GetParent():GetParent():GetParent()
blockLengthFrame.type = "length"
registerForDrag(blockLengthFrame)
local auraLengthTexture = blockLengthFrame:CreateTexture(nil, "border")
auraLengthTexture:SetColorTexture(1, 1, 1, 1)
auraLengthTexture:SetVertexColor(1, 1, 1, 0.1)
auraLengthTexture:SetAllPoints()
blockLengthFrame.Texture = auraLengthTexture
--icon which will be shown at the end of the blockLength frame if the icon is enabled
local rightIcon = blockLengthFrame:CreateTexture(nil, "border")
rightIcon:SetPoint("topright", blockLengthFrame, "topright", 0, 0)
rightIcon:SetPoint("bottomright", blockLengthFrame, "bottomright", 0, 0)
blockLengthFrame.RightIcon = rightIcon
detailsFramework:CreateHighlightTexture(blockLengthFrame, "highlightTexture")
block.blockLength = blockLengthFrame
---@type df_timeline
local timeline = block.timeline
local callbackFunc = timeline.options.block_on_create_auralength or timeline.options.block_on_create_blocklength
if (callbackFunc) then
callbackFunc(blockLengthFrame)
end
return blockLengthFrame
end,
OnEnterBlockLength = function(self)
---@type df_timeline
local timeline = self.timeline
local callbackFunc = timeline.options.block_on_enter_auralength or timeline.options.block_on_enter_blocklength
if (callbackFunc) then
callbackFunc(self)
end
end,
OnLeaveBlockLength = function(self)
---@type df_timeline
local timeline = self.timeline
local callbackFunc = timeline.options.block_on_leave_auralength or timeline.options.block_on_leave_blocklength
if (callbackFunc) then
callbackFunc(self)
end
end,
OnClickBlockLength = function(self, button)
---@type df_timeline
local timeline = self.timeline
local callbackFunc = timeline.options.block_on_click_auralength or timeline.options.block_on_click_blocklength
if (callbackFunc) then
callbackFunc(self, button)
end
end,
Reset = function(self)
--attention, it doesn't reset icon texture, text and background color
for i = 1, #self.blocks do
self.blocks[i]:Hide()
end
self:Hide()
self.lineHeader:Hide()
end,
}
---@class df_timeline_header_body : frame
---@field Buttons button[]
---@field originalHeight number
---@field Lines frame[]
---@class df_timeline_header : scrollframe
---@field type timelinecomponenttype
---@field body frame
---@field headerBody df_timeline_header_body
---@field verticalSlider slider
---@class df_timeline_body : frame
---@field type timelinecomponenttype
---@field Buttons button[]
---@field originalHeight number
---@field effectiveWidth number
---@class df_timeline_line : button, df_timeline_line_mixin
---@field type timelinecomponenttype
---@field index number
---@field spellId number
---@field icon df_image
---@field text df_label
---@field dataIndex number
---@field backdrop_color table
---@field backdrop_color_highlight table
---@field enabled boolean
---@field lineData df_timeline_linedata
---@class df_timeline : scrollframe, df_timeline_mixin, df_optionsmixin, df_framelayout, df_lineindicator
---@field type timelinecomponenttype
---@field body df_timeline_body
---@field onClickCallback fun(...)
---@field onClickCallbackFunc fun(...)
---@field onClickCallbackArgs any[]
---@field headerFrame df_timeline_header headerFrame only exists if the options.header_detached is true
---@field headerBody frame headerBody only exists if the options.header_detached is true
---@field resizeButton button
---@field elapsedTimeFrame df_elapsedtime
---@field horizontalSlider slider
---@field scaleSlider slider
---@field verticalSlider slider
---@field oldScale number
---@field currentScale number
---@field oldMinWidth number
---@field oldMaxWidth number
---@field scrolledWidth number
---@field data df_timeline_scrolldata
---@field lines df_timeline_line[]
---@field options df_timeline_options
---@field pixelPerSecond number
---@field totalLength number
---@field defaultColor table
---@field headerWidth number
---@field delayButtonRefreshTimer timer
---@class df_timeline_mixin : table
---@field GetLine fun(self:df_timeline, index:number):df_timeline_line
---@field GetAllLines fun(self:df_timeline):df_timeline_line[]
---@field GetBlockUnderMouse fun(self:df_timeline):df_timeline_line_block?
---@field GetBlockOrLengthUnderMouse fun(self:df_timeline):df_timeline_line_block|df_timeline_line_blocklength?
---@field GetLineUnderMouse fun(self:df_timeline):df_timeline_line?
---@field GetTimeUnderMouse fun(self:df_timeline):number
---@field GetBodyWidthUnderMouse fun(self:df_timeline):number
---@field GetBlocksAtTime fun(self:df_timeline, time:number?):df_timeline_line_block[]
---@field GetHorizontalScrolledWidth fun(self:df_timeline):number
---@field GetEffectivePixelPerSecond fun(self:df_timeline):number
---@field SetData fun(self:df_timeline, data:table)
---@field GetData fun(self:df_timeline):table
---@field RefreshTimeLine fun(self:df_timeline, bDelayButtonRefresh:boolean?, bFromScale:boolean?)
---@field RefreshResize fun(self:df_timeline)
---@field RefreshPerPixelButtons fun(self:df_timeline)
---@field ResetAllLines fun(self:df_timeline)
---@field SetCanResize fun(self:df_timeline, canResize:boolean)
---@field OnSizeChanged fun(self:df_timeline)
---@field SetOnClickCallback fun(self:df_timeline, callback:fun(), ...:any)
---@field UpdateOnClickCallback fun(self:df_timeline, button:button?)
---@field HideVerticalScroll fun(self:df_timeline)
---@field SetScale fun(self:df_timeline, scale:number)
detailsFramework.TimeLineMixin = {
GetHorizontalScrolledWidth = function(self)
return self.scrolledWidth
end,
HideVerticalScroll = function(self)
self.verticalSlider:Hide()
end,
SetOnClickCallback = function(self, callback, ...)
self.onClickCallbackArgs = {...}
self.onClickCallback = callback
self.onClickCallbackFunc = function(button)
local second = button.index
self.onClickCallback(second-1, unpack(self.onClickCallbackArgs))
end
self:UpdateOnClickCallback()
end,
UpdateOnClickCallback = function(self, button)
if (button) then
button:SetScript("OnClick", self.onClickCallbackFunc)
return
else
for i = 1, #self.body.Buttons do
local thisButton = self.body.Buttons[i]
if (thisButton:IsShown()) then
thisButton:SetScript("OnClick", self.onClickCallbackFunc)
end
end
end
end,
SetScale = function(self, scale)
local scaleSlider = self.scaleSlider
local minValue, maxValue = scaleSlider:GetMinMaxValues()
scale = max(minValue, min(maxValue, scale))
scaleSlider:SetValue(detailsFramework.Math.MapRangeClamped(minValue, maxValue, 0, 1, scale))
self:RefreshTimeLine()
end,
RefreshResize = function(self)
if (self.options.can_resize) then
self:SetResizable(true)
self.resizeButton:Show()
self:SetScript("OnSizeChanged", self.OnSizeChanged)
else
self:SetResizable(false)
self.resizeButton:Hide()
self:SetScript("OnSizeChanged", nil)
end
end,
SetCanResize = function(self, bCanResize)
self.options.can_resize = bCanResize
self:RefreshResize()
end,
OnSizeChanged = function(self)
local width, height = self:GetSize()
self.horizontalSlider:SetSize(width + 20, 20)
self.horizontalSlider:SetPoint("topleft", self, "bottomleft", 0, 0)
self.scaleSlider:SetSize(width + 20, 20)
self.scaleSlider:SetPoint("topleft", self.horizontalSlider, "bottomleft", 0, -2)
self.verticalSlider:SetSize(20, height - 2)
self.verticalSlider:SetPoint("topleft", self, "topright", 0, 0)
--self.body:SetHeight(height)
if (self.data.lines) then
self:RefreshTimeLine()
end
end,
GetAllLines = function(self)
return self.lines
end,
GetLine = function(self, index)
local line = self.lines[index]
if (not line) then
--create a new line
---@type df_timeline_line
line = CreateFrame("button", "$parentLine" .. index, self.body, "BackdropTemplate")
detailsFramework:Mixin(line, detailsFramework.TimeLine_LineMixin)
self.lines[index] = line
line.type = "line"
line.index = index
local yPosition
if (self.options.show_elapsed_timeline) then
yPosition = -((index-1) * (self.options.line_height + 1)) - 2 - self.options.elapsed_timeline_height
else
--need code cleanup as the 'else' stuff isn't in use anymore
yPosition = -((index-1) * (self.options.line_height + 1)) - 1
end
local yPadding = -10
yPosition = yPosition + yPadding
if (index == 1) then
line:SetPoint("topleft", self.body, "topleft", 1, yPosition)
else
line:SetPoint("topleft", self.lines[index-1], "bottomleft", 0, -1)
end
line:SetSize(1, self.options.line_height) --width is set when updating the frame
local detachedHeaderFrame = self.headerFrame
local lineHeader
if (detachedHeaderFrame) then
lineHeader = CreateFrame("frame", "$parentHeader", self.headerBody, "BackdropTemplate")
lineHeader.type = "header"
lineHeader:SetSize(detachedHeaderFrame:GetWidth(), self.options.line_height)
if (index == 1) then
lineHeader:SetPoint("topleft", self.headerBody, "topleft", 0, yPosition)
else
lineHeader:SetPoint("topleft", self.lines[index-1].lineHeader, "bottomleft", 0, -1)
end
detailsFramework:CreateHighlightTexture(lineHeader, "HighlightTexture")
lineHeader.HighlightTexture:SetDrawLayer("overlay", 1)
lineHeader.HighlightTexture:Hide()
lineHeader:EnableMouse(true)
lineHeader:SetScript("OnEnter", function() self.options.on_enter(line) lineHeader.HighlightTexture:Show() end)
lineHeader:SetScript("OnLeave", function() self.options.on_leave(line) lineHeader.HighlightTexture:Hide() end)
line:SetScript("OnEnter", function() self.options.on_enter(line) lineHeader.HighlightTexture:Show() end)
line:SetScript("OnLeave", function() self.options.on_leave(line) lineHeader.HighlightTexture:Hide() end)
lineHeader.Line = line
else
lineHeader = CreateFrame("frame", "$parentHeader", line, "BackdropTemplate")
lineHeader.type = "header"
lineHeader:SetPoint("topleft", line, "topleft", 0, 0)
lineHeader:SetPoint("bottomleft", line, "bottomleft", 0, 0)
line:SetScript("OnEnter", self.options.on_enter)
line:SetScript("OnLeave", self.options.on_leave)
end
--lineHeader:SetScript("OnEnter", self.options.header_on_enter)
--lineHeader:SetScript("OnLeave", self.options.header_on_leave)
line.lineHeader = lineHeader
--store the individual textures that shows the timeline information
line.blocks = {}
line:SetMouseClickEnabled(false)
line:SetBackdrop(self.options.backdrop)
line:SetBackdropColor(unpack(self.options.backdrop_color))
line:SetBackdropBorderColor(unpack(self.options.backdrop_border_color))
local icon = detailsFramework:CreateImage(lineHeader, "", self.options.line_height, self.options.line_height)
icon:SetPoint("left", lineHeader, "left", 2, 0)
line.icon = icon
local text = detailsFramework:CreateLabel(lineHeader, "", detailsFramework:GetTemplate("font", self.options.title_template))
text:SetPoint("left", icon.widget, "right", 2, 0)
line.text = text
line.backdrop_color = self.options.backdrop_color or {.1, .1, .1, .3}
line.backdrop_color_highlight = self.options.backdrop_color_highlight or {.3, .3, .3, .5}
if (self.options.on_create_line) then
self.options.on_create_line(line)
end
end
return line
end,
ResetAllLines = function(self)
for i = 1, #self.lines do
self.lines[i]:Reset()
end
end,
RefreshPerPixelButtons = function(self)
--local amountOfButtons = floor(self.body:GetWidth() / (pixelPerSecond * currentScale))
local amountOfButtons = self.totalLength
local buttonHeight = self:GetHeight()
local widthPerSecond = self.options.pixels_per_second * self.currentScale
--print("Updating Buttons...", amountOfButtons, "bodyHeight??", buttonHeight, "scale:", currentScale)
for i = 1, amountOfButtons do
local button = self.body.Buttons[i]
if (not button) then
button = CreateFrame("button", "$parentButton" .. i, self.body, "BackdropTemplate")
local overlayTexture = button:CreateTexture(nil, "overlay")
local r, g, b, a = detailsFramework:GetDefaultBackdropColor()
overlayTexture:SetColorTexture(1, 1, 1)
overlayTexture:SetAlpha(i % 2 == 0 and 0.01 or 0.02)
overlayTexture:SetAllPoints()
--create a highlight texture
local highlightTexture = button:CreateTexture(nil, "highlight")
highlightTexture:SetColorTexture(1, 1, 1, 0.05)
highlightTexture:SetAllPoints()
self.body.Buttons[i] = button
end
button:SetSize(widthPerSecond, buttonHeight)
local xPosition = (i - 1) * widthPerSecond
xPosition = xPosition + self.options.header_width
button:SetPoint("topleft", self.body, "topleft", xPosition, 0)
self:UpdateOnClickCallback(button)
button:Show()
button.index = i
end
for i = amountOfButtons+1, #self.body.Buttons do
self.body.Buttons[i]:Hide()
end
end,
GetBlockUnderMouse = function(self)
local allLines = self:GetAllLines()
for i = 1, #allLines do
local thisLine = allLines[i]
local allBlocksInTheLine = thisLine:GetAllBlocks()
for j = 1, #allBlocksInTheLine do
local thisBlock = allBlocksInTheLine[j]
if (thisBlock:IsShown()) then
if (thisBlock:IsMouseOver()) then
return thisBlock
end
end
end
end
return nil
end,
GetBlockOrLengthUnderMouse = function(self)
local allLines = self:GetAllLines()
for i = 1, #allLines do
local thisLine = allLines[i]
local allBlocksInTheLine = thisLine:GetAllBlocks()
for j = 1, #allBlocksInTheLine do
local thisBlock = allBlocksInTheLine[j]
if (thisBlock:IsShown()) then
if (thisBlock:IsMouseOver()) then
return thisBlock
end
local blockLength = thisBlock.blockLength
if (blockLength and blockLength:IsShown()) then
if (blockLength:IsMouseOver()) then
return blockLength
end
end
end
end
end
return nil
end,
GetLineUnderMouse = function(self)
local allLines = self:GetAllLines()
for i = 1, #allLines do
local thisLine = allLines[i]
if (thisLine:IsMouseOver()) then
return thisLine
end
end
return nil
end,
GetBodyWidthUnderMouse = function(self)
local x, y = GetCursorPosition()
local scale = 1 / UIParent:GetEffectiveScale()
x = x * scale
local left = self.body:GetLeft()
local width = x - left
return width
end,
GetTimeUnderMouse = function(self)
local bodyWidthUnderMouse = self:GetBodyWidthUnderMouse()
local time = bodyWidthUnderMouse / (self.pixelPerSecond * self.currentScale)
return time
end,
GetBlocksAtTime = function(self, time)
if (not time) then
time = self:GetTimeUnderMouse()
end
local blocks = {}
local allLines = self:GetAllLines()
local pixelsPerSecond = self:GetEffectivePixelPerSecond()
for i = 1, #allLines do
local thisLine = allLines[i]
local allBlocksInTheLine = thisLine:GetAllBlocks()
for j = 1, #allBlocksInTheLine do
local thisBlock = allBlocksInTheLine[j]
if (thisBlock:IsShown()) then
local blockWidth = thisBlock:GetWidth()
---@type df_timeline_line_blockinfo
local blockInfo = thisBlock.info
local blockTime = blockInfo.time
local startTime = blockTime
local endTime = blockTime + (blockWidth / pixelsPerSecond)
--blockTime = math.floor(blockTime)
--time = math.floor(time)
if (time >= startTime and time <= endTime) then
table.insert(blocks, thisBlock)
end
end
end
end