-
Notifications
You must be signed in to change notification settings - Fork 41
/
Copy pathPlater_AnimationEditor.lua
1293 lines (1082 loc) · 44 KB
/
Plater_AnimationEditor.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
local Plater = Plater
local GameCooltip = GameCooltip2
local DF = DetailsFramework
local _
local GetSpellInfo = GetSpellInfo or function(spellID) if not spellID then return nil end local si = C_Spell.GetSpellInfo(spellID) if si then return si.name, nil, si.iconID, si.castTime, si.minRange, si.maxRange, si.spellID, si.originalIconID end end
--get templates
local options_text_template = DF:GetTemplate ("font", "OPTIONS_FONT_TEMPLATE")
local options_dropdown_template = DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE")
local options_switch_template = DF:GetTemplate ("switch", "OPTIONS_CHECKBOX_TEMPLATE")
local options_slider_template = DF:GetTemplate ("slider", "OPTIONS_SLIDER_TEMPLATE")
local options_button_template = DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE")
local scrollbox_size = {201, 405}
local scrollbox_lines = 11
local scrollbox_line_height = 28.7
local scrollbox_line_backdrop_color = {0, 0, 0, 0.5}
local scrollbox_line_backdrop_color_selected = {.6, .6, .1, 0.7}
local buttons_size = {120, 20}
local luaeditor_backdrop_color = {.2, .2, .2, .5}
local luaeditor_border_color = {0, 0, 0, 1}
local debugmode = false
local PLATER_OPTIONS_ANIMATION_TAB = 20
function Plater.CreateSpellAnimationPanel()
local f = PlaterOptionsPanelFrame
local mainFrame = PlaterOptionsPanelContainer
local animationFrame = mainFrame.AllFrames [PLATER_OPTIONS_ANIMATION_TAB]
--store which animation is being edited
local currentAnimation
local currentCopy
local previewEnabled = true
local previewLoopTime = 1
animationFrame.CurrentIndex = 1
animationFrame.SearchString = ""
animationFrame.AvailableSpells = {}
--set points
local startX = 10
local startY = -220 --menu and settings panel
local startYGeneralSettings = -150
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
local CLEUFrame = CreateFrame ("frame")
CLEUFrame.SpellCaptured = {}
CLEUFrame.PlayerSerial = UnitGUID ("player")
CLEUFrame:SetScript ("OnEvent", function (self, event)
local time, token, hidding, sourceGUID, sourceName, sourceFlag, sourceFlag2, targetGUID, targetName, targetFlag, targetFlag2, spellID, spellName, spellType, amount, overKill, school, resisted, blocked, absorbed, isCritical = CombatLogGetCurrentEventInfo()
if (token == "SPELL_DAMAGE" or token == "SPELL_PERIODIC_DAMAGE") then
if (CLEUFrame.PlayerSerial == sourceGUID) then
if (not CLEUFrame.SpellCaptured [spellID]) then
CLEUFrame.SpellCaptured [spellID] = {Token = token, Name = spellName, ID = spellID}
animationFrame.SelectSpellDropdown:Refresh()
end
end
end
end)
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> logic
function animationFrame.LoopPreview()
--simulate a hit in the nameplate
if (currentAnimation and #currentAnimation > 0) then
local spellName = GetSpellInfo (currentAnimation.info.spellid)
if (spellName and Plater.SPELL_WITH_ANIMATIONS [spellName]) then
for _, plateFrame in ipairs (Plater.GetAllShownPlates()) do
Plater.DoNameplateAnimation (plateFrame, Plater.SPELL_WITH_ANIMATIONS [spellName], spellName, false)
end
end
end
end
function animationFrame.StopPreview()
if (animationFrame.PreviewTicker) then
animationFrame.PreviewTicker:Cancel()
end
end
function animationFrame.UpdatePreview (newLoopTime)
if (animationFrame.PreviewTicker) then
animationFrame.PreviewTicker:Cancel()
end
previewLoopTime = newLoopTime or previewLoopTime
if (previewEnabled) then
animationFrame.PreviewTicker = C_Timer.NewTicker (previewLoopTime, animationFrame.LoopPreview)
end
end
animationFrame:HookScript ("OnShow", function()
animationFrame.BuildAnimationDataForScroll()
CLEUFrame:RegisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
Plater.RefreshIsEditingAnimations (true)
if (previewEnabled) then
animationFrame.UpdatePreview()
end
end)
animationFrame:HookScript ("OnHide", function()
CLEUFrame:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
Plater.RefreshIsEditingAnimations (false)
animationFrame.StopPreview()
end)
function animationFrame.GetAnimation (spellID)
return Plater.db.profile.spell_animation_list [spellID]
end
--runs when clicking in the add animation button
function animationFrame.AddNewAnimation()
--get the option selected in the dropdown
local spellID = animationFrame.SelectSpellDropdown.value
if (not spellID or type (spellID) ~= "number") then
return
end
--check if there's an animation for this spell
local db = Plater.db.profile.spell_animation_list
if (db [spellID]) then
Plater:Msg ("an animation for this spell already exists.")
return
end
local _, playerClass = UnitClass ("player")
--add the spell to the animation list
local newAnimationTable = {
info = {
time = time(),
desc = "",
class = playerClass,
spellid = spellID,
}
}
db [spellID] = newAnimationTable
--refresh the scrollbox
animationFrame.BuildAnimationDataForScroll()
--start editing this new animation
animationFrame.EditAnimation (spellID)
end
function animationFrame.ShowImportTextField()
animationFrame.ImportAnimation()
end
--when a text in the searchi field is changed, get the text and update the animation list
function animationFrame.OnSearchBoxTextChanged()
local text = animationFrame.AnimationSearchTextEntry:GetText()
animationFrame.SearchString = text:lower()
animationFrame.AnimationScrollBox:Refresh()
end
--build an index table to be used in the scroll selection
function animationFrame.BuildAnimationDataForScroll()
local db = Plater.db.profile.spell_animation_list
local t = {}
--get the player class and only show animations that is used on its class
local _, playerClass = UnitClass ("player")
for spellID, animationTable in pairs (db) do
if (animationTable.info.class == playerClass) then
tinsert (t, animationTable)
end
end
animationFrame.AnimationScrollBox:SetData (t)
animationFrame.AnimationScrollBox:Refresh()
end
--sort by name, index 5 holds the name:lower()
function animationFrame.SortScroll (t1, t2)
return t1[5] < t2[5]
end
--update the scroll list in the left side
function animationFrame.RefreshAnimationSelectScrollBox (self, data, offset, total_lines)
--animationFrame.SearchString
local dataInOrder = {}
if (animationFrame.SearchString ~= "") then
for i = 1, #data do
local animationTable = data[i]
local spellID = animationTable.info.spellid
local spellName, _, spellIcon = GetSpellInfo (spellID)
if (spellName) then
local spellNameLower = spellName:lower()
if (spellNameLower:find (animationFrame.SearchString)) then
dataInOrder [#dataInOrder+1] = {spellID, data[i], spellName, spellIcon, spellNameLower}
end
end
end
else
for i = 1, #data do
local animationTable = data[i]
local spellID = animationTable.info.spellid
local spellName, _, spellIcon = GetSpellInfo (spellID)
if (spellName) then
local spellNameLower = spellName:lower()
dataInOrder [#dataInOrder+1] = {spellID, data[i], spellName, spellIcon, spellNameLower}
end
end
end
table.sort (dataInOrder, animationFrame.SortScroll)
--update the scroll
for i = 1, total_lines do
local index = i + offset
local t = dataInOrder [index]
if (t) then
--get the data
local spellID = t[1]
local data = t[2]
local spellName = t[3]
local spellIcon = t[4]
--update the line
local line = self:GetLine (i)
line:UpdateLine (spellID, data, spellName, spellIcon)
if (data == currentAnimation) then
line:SetBackdropColor (unpack (scrollbox_line_backdrop_color_selected))
else
line:SetBackdropColor (unpack (scrollbox_line_backdrop_color))
end
end
end
end
function animationFrame.OnEnterScrollSelectionLine (self)
self:SetBackdropColor (.3, .3, .3, .6)
end
function animationFrame.OnLeaveScrollSelectionLine (self)
--check if the hover overed button is the current animation being edited
if (currentAnimation == self.Data) then
self:SetBackdropColor (unpack (scrollbox_line_backdrop_color_selected))
else
self:SetBackdropColor (unpack (scrollbox_line_backdrop_color))
end
end
function animationFrame.EditAnimation (spellID)
local animationObject = animationFrame.GetAnimation (spellID)
if (not animationObject) then
Plater:Msg ("animation not found")
return
end
currentAnimation = animationObject
--refresh the spell selection box
animationFrame.AnimationScrollBox:Refresh()
--update the editing animation
--animationFrame:HideAllConfigFrames()
animationFrame.EffectSelectionDropdown:Refresh()
animationFrame.EffectSelectionDropdown:Select (1, true)
animationFrame.OnSelectEffect (_, _, 1)
animationFrame.RefreshAddAnimationButtons()
if (animationFrame.IsExporting or animationFrame.IsImporting) then
animationFrame.HideStringField()
end
end
--user selected 'paste' in the context menu of 'self'
--copy the settings from the 'currentCopy' variable into the animation table for this widget
function animationFrame.PasteAnimationSettings (self)
if (not currentCopy or #currentCopy == 0) then
Plater:Msg ("there's no animation to paste.")
return
end
local spellID = self.SpellID
if (spellID) then
local animationObject = animationFrame.GetAnimation (spellID)
if (animationObject) then
--iterate among all copied animations
for i = 1, #currentCopy do
local thisCopiedEffect = currentCopy [i]
local copiedEffectType = thisCopiedEffect.animation_type
--below it iterates among all animation in the target animation object, if it doesn't find an effect table like the copied one, it needs to add it then
local shouldAdd = true
for i = 1, #animationObject do
local animationEffect = animationObject [i]
if (animationEffect.animation_type == copiedEffectType) then
--replace the effect settings
DF.table.copy (animationEffect, thisCopiedEffect)
shouldAdd = false
break
end
end
--if it fails to find a similar effect, add it
if (shouldAdd) then
tinsert (animationObject, DF.table.copy ({}, thisCopiedEffect))
end
end
animationFrame.EditAnimation (spellID)
Plater.RefreshDBUpvalues()
Plater:Msg ("settings applied!")
else
Plater:Msg ("animation net found")
end
else
Plater:Msg ("invalid spellID")
end
end
function animationFrame.OnClickMenuLine (self, spellID, option, value)
if (option == "editanimation") then
animationFrame.EditAnimation (spellID)
elseif (option == "copy") then
local animationObject = animationFrame.GetAnimation (self.SpellID)
--make a new table for the copied effects
currentCopy = {}
--animations stay in the indexed part of the animtion object
--copy the settings of these indexes into the copy table
for i = 1, #animationObject do
local effect = animationObject [i]
tinsert (currentCopy, DF.table.copy ({}, effect))
end
local spellName = GetSpellInfo (spellID)
if (spellName) then
Plater:Msg (spellName .. " copied.")
end
elseif (option == "export") then
animationFrame.ExportAnimation (self)
elseif (option == "paste") then
animationFrame.PasteAnimationSettings (self)
elseif (option == "remove") then
animationFrame.RemoveAnimation (self)
elseif (option == "export_table") then
animationFrame.ExportAnimation (self, true)
end
GameCooltip:Hide()
end
function animationFrame.OnClickScrollSelectionLine (self, button)
local spellID = self.SpellID
if (spellID) then
if (button == "LeftButton") then
animationFrame.EditAnimation (spellID)
elseif (button == "RightButton") then
--open menu
GameCooltip:Preset (2)
GameCooltip:SetType ("menu")
GameCooltip:SetOption ("TextSize", 10)
GameCooltip:SetOption ("FixedWidth", 200)
GameCooltip:SetOption ("ButtonsYModSub", -1)
GameCooltip:SetOption ("YSpacingModSub", -4)
GameCooltip:SetOwner (self, "topleft", "topright", 2, 0)
GameCooltip:SetFixedParameter (spellID)
GameCooltip:AddLine ("Edit Animation")
GameCooltip:AddMenu (1, animationFrame.OnClickMenuLine, "editanimation")
GameCooltip:AddIcon ([[Interface\BUTTONS\UI-GuildButton-PublicNote-Up]], 1, 1, 16, 16)
GameCooltip:AddLine ("Copy Settings")
GameCooltip:AddMenu (1, animationFrame.OnClickMenuLine, "copy")
GameCooltip:AddIcon ([[Interface\AddOns\Plater\images\icons]], 1, 1, 16, 16, 3/512, 21/512, 215/512, 233/512)
if (currentCopy) then
GameCooltip:AddLine ("Paste Settings")
GameCooltip:AddMenu (1, animationFrame.OnClickMenuLine, "paste")
GameCooltip:AddIcon ([[Interface\AddOns\Plater\images\icons]], 1, 1, 16, 16, 3/512, 21/512, 215/512, 233/512)
else
GameCooltip:AddLine ("Paste Settings", "", 1, "gray")
GameCooltip:AddMenu (1, animationFrame.OnClickMenuLine, "paste")
GameCooltip:AddIcon ([[Interface\AddOns\Plater\images\icons]], 1, 1, 16, 16, 3/512, 21/512, 215/512, 233/512, false, false, true)
end
GameCooltip:AddLine ("Export As a Text String", "", 1)
GameCooltip:AddIcon ([[Interface\BUTTONS\UI-GuildButton-MOTD-Up]], 1, 1, 16, 16, 1, 0, 0, 1)
GameCooltip:AddMenu (1, animationFrame.OnClickMenuLine, "export")
GameCooltip:AddLine ("Remove")
GameCooltip:AddMenu (1, animationFrame.OnClickMenuLine, "remove")
GameCooltip:AddIcon ([[Interface\AddOns\Plater\images\icons]], 1, 1, 16, 16, 3/512, 21/512, 235/512, 257/512)
--dev tool to export in database format
if (GetRealmName() == "Azralon") then
GameCooltip:AddLine ("$div")
GameCooltip:AddLine ("Export To Table (dev)", "", 1)
GameCooltip:AddIcon ([[Interface\BUTTONS\UI-GuildButton-MOTD-Up]], 1, 1, 16, 16, 1, 0, 0, 1)
GameCooltip:AddMenu (1, animationFrame.OnClickMenuLine, "export_table")
end
GameCooltip:Show()
end
end
end
--update a single line in the scroll list
function animationFrame.UpdateScrollLine (self, spellID, data, spellName, spellIcon)
self.Icon:SetTexture (spellIcon)
self.Icon:SetTexCoord (.1, .9, .1, .9)
self.AnimationName:SetText (spellName)
self.SpellID = spellID
self.Data = data
end
function animationFrame:HideAllConfigFrames()
for _, frame in pairs (animationFrame.AllConfigFrames) do
frame:Hide()
end
end
function animationFrame.OnSelectEffect (self, _, effectIndex)
if (not currentAnimation [effectIndex]) then
animationFrame.DisableOptions()
return
else
animationFrame.EnableOptions()
end
animationFrame.CurrentIndex = effectIndex
animationFrame:HideAllConfigFrames()
local animationData = currentAnimation [animationFrame.CurrentIndex]
local configFrame = animationFrame.AllConfigFrames [animationData.animation_type]
configFrame.Data = animationData
configFrame:RefreshOptions()
configFrame:Show()
end
function animationFrame.RefreshEffectListDropdown (self)
local t = {}
if (currentAnimation) then
for animationIndex, animationTable in ipairs (currentAnimation) do
tinsert (t, {label = " #" .. animationIndex .. " " .. animationTable.animation_type, value = animationIndex, onclick = animationFrame.OnSelectEffect})
end
end
return t
end
function animationFrame.AddNewShakeEffect()
if (currentAnimation) then
tinsert (currentAnimation, {
enabled = true,
animation_type = "frameshake",
scaleX = .1,
scaleY = 1,
absolute_sineX = false,
absolute_sineY = false,
duration = 0.1,
amplitude = 3,
frequency = 1,
fade_in = 0.01,
fade_out = 0.09,
cooldown = 0.5,
critical_scale = 1.05,
})
animationFrame.EffectSelectionDropdown:Refresh()
animationFrame.CurrentIndex = #currentAnimation
animationFrame.EffectSelectionDropdown:Select (#currentAnimation, true)
animationFrame.OnSelectEffect (_, _, #currentAnimation)
animationFrame.RefreshAddAnimationButtons()
end
end
function animationFrame.AddNewScaleEffect()
if (currentAnimation) then
tinsert (currentAnimation, {
enabled = true,
duration = 0.05, --seconds
animation_type = "scale",
cooldown = 0.75, --seconds
scale_upX = 1.03,
scale_upY = 1.03,
scale_downX = 0.97,
scale_downY = 0.97,
})
animationFrame.EffectSelectionDropdown:Refresh()
animationFrame.CurrentIndex = #currentAnimation
animationFrame.EffectSelectionDropdown:Select (#currentAnimation, true)
animationFrame.OnSelectEffect (_, _, #currentAnimation)
animationFrame.RefreshAddAnimationButtons()
end
end
function animationFrame.RefreshAddAnimationButtons()
animationFrame.AddShakeButton:Enable()
animationFrame.AddScaleButton:Enable()
if (not currentAnimation) then
animationFrame.AddShakeButton:Disable()
animationFrame.AddScaleButton:Disable()
return
end
for animationIndex, animationTable in ipairs (currentAnimation) do
if (animationTable.animation_type == "scale") then
animationFrame.AddScaleButton:Disable()
end
if (animationTable.animation_type == "frameshake") then
animationFrame.AddShakeButton:Disable()
end
end
end
local cooltipInjectionScrollLine = function (self, fixed_parameter)
GameCooltip:Preset (2)
GameCooltip:SetOption ("TextSize", 10)
GameCooltip:SetOption ("FixedWidth", 200)
local animationObject = animationFrame.GetAnimation (self.SpellID)
local lastEdited = date ("%d/%m/%Y", animationObject.info.time)
local spellName, _, spellIcon = GetSpellInfo (self.SpellID)
GameCooltip:AddLine (spellName, nil, 1, "yellow", "yellow", 11, "Friz Quadrata TT", "OUTLINE")
GameCooltip:AddIcon (spellIcon, 1, 1, 18, 18, .1, .9, .1, .9)
GameCooltip:AddLine ("Last Edited:", lastEdited)
if (animationObject.info.desc and animationObject.info.desc ~= "") then
GameCooltip:AddLine (animationObject.info.desc, "", 1, "gray")
end
end
local cooltipInjectionTable_ScrollLine = {
Type = "tooltip",
BuildFunc = cooltipInjectionScrollLine,
ShowSpeed = 0.016,
MyAnchor = "topleft",
HisAnchor = "topright",
X = 10,
Y = 0,
}
function animationFrame.RemoveAnimation (self)
local spellID = self.SpellID
if (spellID) then
--is removing the animation which is currently being edited?
if (currentAnimation == Plater.db.profile.spell_animation_list [spellID]) then
animationFrame.DisableOptions()
animationFrame.AddShakeButton:Disable()
animationFrame.AddScaleButton:Disable()
currentAnimation = nil
animationFrame.EffectSelectionDropdown:Refresh()
end
Plater.db.profile.spell_animation_list [spellID] = nil
Plater.RefreshDBUpvalues()
animationFrame.BuildAnimationDataForScroll()
end
end
function animationFrame.ImportAnimation()
animationFrame.IsExporting = nil
animationFrame.IsImporting = true
animationFrame.ImportStringField:Show()
animationFrame.AnimationConfigFrame:Hide()
animationFrame.ImportStringField:SetText ("")
animationFrame.ImportStringField:SetFocus (true)
end
function animationFrame.ExportDev (self)
local spellID = self.SpellID
local animationToExport = animationFrame.GetAnimation (spellID)
local copy = DF.table.copy ({}, animationToExport)
copy = {
[spellID] = copy
}
local spellName = GetSpellInfo (spellID)
local class = UnitClass ("player")
animationFrame.ImportStringField:SetText ("--" .. spellName .. " (" .. class .. ")\n" .. DF.table.dump (copy))
animationFrame.ImportStringField:SetFocus (true)
animationFrame.ImportStringField.editbox:HighlightText()
animationFrame.AnimationConfigFrame:Hide()
return
end
function animationFrame.ExportAnimation (self, isDev)
animationFrame.IsExporting = true
animationFrame.IsImporting = nil
animationFrame.ImportStringField:Show()
if (isDev) then
animationFrame.ExportDev (self)
return
end
local spellID = self.SpellID
local animationToExport = animationFrame.GetAnimation (spellID)
if (animationToExport) then
--export to string
animationFrame.ImportStringField:SetText (Plater.CompressData (animationToExport, "print") or "failed to export")
C_Timer.After (.1, function()
animationFrame.ImportStringField:SetFocus (true)
animationFrame.ImportStringField.editbox:HighlightText()
end)
animationFrame.AnimationConfigFrame:Hide()
end
end
function animationFrame.DoImportAnimation (animationObject)
local spellID = tonumber(animationObject.info.spellid)
local spellName = GetSpellInfo (spellID)
if not spellName then return end
local db = Plater.db.profile.spell_animation_list
db [spellID] = animationObject
Plater:Msg ("animation for spell " .. spellName .. " added!")
local _, class = UnitClass ("player")
if (class ~= animationObject.info.class) then
Plater:Msg ("this animation is for " .. animationObject.info.class .. " and won't show on this character.")
end
animationFrame.EditAnimation (spellID)
animationFrame.BuildAnimationDataForScroll()
Plater.RefreshDBUpvalues()
end
function animationFrame.ConfirmImportAnimation()
if (animationFrame.IsExporting) then
animationFrame.HideStringField()
return
end
local text = animationFrame.ImportStringField:GetText()
local animationObject = Plater.DecompressData (text, "print")
animationFrame.HideStringField()
if (animationObject) then
local db = Plater.db.profile.spell_animation_list
local spellID = tonumber(animationObject.info.spellid)
if (not spellID) then
Plater:Msg ("invalid animation.")
return
end
local spellName = GetSpellInfo (spellID)
if (not spellName) then
Plater:Msg ("the spell for this animation doesn't exists.")
return
end
--already have
if (db [spellID]) then
--show a box to confirm
DF:ShowPromptPanel ("Animation for " .. spellName .. " already exists, overwrite?", function()
--true
animationFrame.DoImportAnimation (animationObject)
end,
function()
return
end)
else
animationFrame.DoImportAnimation (animationObject)
end
else
Plater:Msg ("invalid animation.")
end
end
function animationFrame.HideStringField()
animationFrame.IsExporting = nil
animationFrame.IsImporting = nil
animationFrame.ImportStringField:Hide()
animationFrame.ImportStringField:SetText ("")
animationFrame.AnimationConfigFrame:Show()
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--> build the frames
local optionsTable = {
{type = "label", get = function() return "General Settings:" end, text_template = DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE")},
{
type = "toggle",
get = function() return Plater.db.profile.spell_animations end,
set = function (self, fixedparam, value)
Plater.db.profile.spell_animations = value
Plater.RefreshDBUpvalues()
end,
name = "Spell Animations Enabled",
desc = "If enabled some of your abilities will cause the nameplate to shake or play a special effect when the ability hits the enemy.\n\nCustomize each animation in the Animations tab.",
},
{
type = "range",
get = function() return Plater.db.profile.spell_animations_scale end,
set = function (self, fixedparam, value)
Plater.db.profile.spell_animations_scale = value
end,
min = 0.75,
max = 2.75,
step = 0.1,
name = "Overall Intensity",
desc = "Overall intensity scale of the spell animations.",
thumbscale = 1.8,
usedecimals = true,
},
}
DF:BuildMenu (animationFrame, optionsTable, 10, startYGeneralSettings, 330, true, options_text_template, options_dropdown_template, options_switch_template, true, options_slider_template, options_button_template, animationFrame.OnDataChange)
local scrollBoxHeight = 396 - 70
--dropdown select spell to add
local buildAddSpellOptions = function()
local t = {}
local db = Plater.db.profile.spell_animation_list
for spellID, spellInfo in pairs (CLEUFrame.SpellCaptured) do
if (not db [spellInfo.ID]) then
local _, _, spellIcon = GetSpellInfo (spellInfo.ID)
if (spellIcon) then
tinsert (t, {label = spellInfo.Name, value = spellInfo.ID, onclick = function()end, desc = "Spell ID: " .. spellInfo.ID, icon = spellIcon, texcoord = {.1, .9, .1, .9}})
end
end
end
return t
end
local selectSpellLabel = DF:CreateLabel (animationFrame, "Select Spell to Add Animation:", DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
local selectSpellDropdown = DF:CreateDropDown (animationFrame, buildAddSpellOptions, 1, 130, 20, "SelectSpellDropdown", _, DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
selectSpellDropdown:SetPoint ("topleft", selectSpellLabel, "bottomleft", 0, -2)
--button add spell
local addSpellButton = DF:CreateButton (animationFrame, animationFrame.AddNewAnimation, 40, 20, "Add", -1, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate ("font", "PLATER_BUTTON"))
addSpellButton:SetPoint ("left", selectSpellDropdown, "right", 2, 0)
addSpellButton.tooltip = function()
if (not next (CLEUFrame.SpellCaptured)) then
return "No spells to add?\n\nHit any npc with spells while this window is open to fill the dropdown with options."
else
return "Add animation for the selected spell."
end
end
--button import animation
local importButton = DF:CreateButton (animationFrame, animationFrame.ShowImportTextField, 26, 20, "", -1, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate ("font", "PLATER_BUTTON"))
importButton:SetIcon ([[Interface\AddOns\Plater\images\icons]], 16, 16, "overlay", {5/512, 19/512, 195/512, 210/512}, {1, .8, .2}, nil, nil, nil, false)
importButton:SetPoint ("left", addSpellButton, "right", 2, 0)
importButton:HookScript ("OnEnter", function()
GameCooltip:Preset (2)
GameCooltip:SetOption ("TextSize", 10)
GameCooltip:SetOption ("FixedWidth", 200)
GameCooltip:SetOwner (importButton.widget)
GameCooltip:AddLine ("Import Animation", "", 1, "yellow", "yellow", 12, nil, "OUTLINE")
GameCooltip:AddLine ("Add an animation from a string.\n\nYou can export to string by right clicking an animation in the menu below.")
GameCooltip:Show()
end)
importButton:HookScript ("OnLeave", function()
GameCooltip:Hide()
end)
--search box
local searchLabel = DF:CreateLabel (animationFrame, "Search:", DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
searchLabel:SetPoint ("topleft", selectSpellDropdown, "bottomleft", 0, -5)
local searchAnimationTextEntry = DF:CreateTextEntry (animationFrame, function()end, 200, 20, "AnimationSearchTextEntry", _, _, options_dropdown_template)
searchAnimationTextEntry:SetHook ("OnChar", animationFrame.OnSearchBoxTextChanged)
searchAnimationTextEntry:SetHook ("OnTextChanged", animationFrame.OnSearchBoxTextChanged)
searchAnimationTextEntry:SetPoint ("topleft", searchLabel, "bottomleft", 0, -2)
--scrollbox to select the spell animation to edit
local spellLabel = DF:CreateLabel (animationFrame, "Spell Animations", DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
spellLabel:SetPoint ("topleft", searchAnimationTextEntry, "bottomleft", 0, -5)
local animationSelectScrollBox = DF:CreateScrollBox (animationFrame, "$parentScrollBox", animationFrame.RefreshAnimationSelectScrollBox, {}, 200, scrollBoxHeight, scrollbox_lines, scrollbox_line_height)
animationSelectScrollBox:SetPoint ("topleft", spellLabel.widget, "bottomleft", 0, -2)
DF:ReskinSlider (animationSelectScrollBox)
animationFrame.AnimationScrollBox = animationSelectScrollBox
local createNewLineFunc = function (self, index)
--create a new line
local line = CreateFrame ("button", "$parentLine" .. index, self, BackdropTemplateMixin and "BackdropTemplate")
--set its parameters
line:SetPoint ("topleft", self, "topleft", 1, -((index-1) * (scrollbox_line_height+1)) - 1)
line:SetSize (scrollbox_size[1]-2, scrollbox_line_height)
line:RegisterForClicks ("LeftButtonDown", "RightButtonDown")
line:SetScript ("OnEnter", animationFrame.OnEnterScrollSelectionLine)
line:SetScript ("OnLeave", animationFrame.OnLeaveScrollSelectionLine)
line:SetScript ("OnClick", animationFrame.OnClickScrollSelectionLine)
line.CoolTip = cooltipInjectionTable_ScrollLine
GameCooltip:CoolTipInject (line)
line:SetBackdrop ({bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true, edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1})
line:SetBackdropColor (unpack (scrollbox_line_backdrop_color))
line:SetBackdropBorderColor (0, 0, 0, 1)
local icon = line:CreateTexture ("$parentIcon", "overlay")
icon:SetSize (scrollbox_line_height-4, scrollbox_line_height-4)
local animationName = DF:CreateLabel (line, "", DF:GetTemplate ("font", "PLATER_SCRIPTS_NAME"))
--setup anchors
icon:SetPoint ("left", line, "left", 2, 0)
animationName:SetPoint ("topleft", icon, "topright", 2, -2)
line.Icon = icon
line.AnimationName = animationName
line.UpdateLine = animationFrame.UpdateScrollLine
return line
end
--create the scrollbox lines
for i = 1, scrollbox_lines do
animationSelectScrollBox:CreateLine (createNewLineFunc)
end
--import box
--text editor
local luaeditor_backdrop_color = {.2, .2, .2, .5}
local luaeditor_border_color = {0, 0, 0, 1}
local edit_script_size = {620, 431}
local buttons_size = {120, 20}
local importStringField = DF:NewSpecialLuaEditorEntry (animationFrame, 825, edit_script_size[2] - 75, "ImportEditor", "$parentImportEditor", true)
importStringField:SetBackdrop ({edgeFile = [[Interface\Buttons\WHITE8X8]], edgeSize = 1, bgFile = [[Interface\Tooltips\UI-Tooltip-Background]], tileSize = 64, tile = true})
importStringField:SetBackdropBorderColor (unpack (luaeditor_border_color))
importStringField:SetBackdropColor (unpack (luaeditor_backdrop_color))
importStringField:Hide()
animationFrame.ImportStringField = importStringField
DF:ReskinSlider (importStringField.scroll)
--import button
local okayButton = DF:CreateButton (importStringField, animationFrame.ConfirmImportAnimation, buttons_size[1], buttons_size[2], "Okay", -1, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate ("font", "PLATER_BUTTON"))
okayButton:SetIcon ([[Interface\BUTTONS\UI-Panel-BiggerButton-Up]], 20, 20, "overlay", {0.1, .9, 0.1, .9})
--cancel button
local cancelButton = DF:CreateButton (importStringField, animationFrame.HideStringField, buttons_size[1], buttons_size[2], "Cancel", -1, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate ("font", "PLATER_BUTTON"))
cancelButton:SetIcon ([[Interface\BUTTONS\UI-Panel-MinimizeButton-Up]], 20, 20, "overlay", {0.1, .9, 0.1, .9})
okayButton:SetPoint ("topright", importStringField, "bottomright", 0, -7)
cancelButton:SetPoint ("right", okayButton, "left", -20, 0)
--editing settings of the animation
local animationConfigFrame = CreateFrame ("frame", "$parentAnimationConfig", animationFrame, BackdropTemplateMixin and "BackdropTemplate")
DF:ApplyStandardBackdrop (animationConfigFrame)
animationConfigFrame:SetPoint ("topleft", animationSelectScrollBox, "topright", 45, 53 + 70)
animationConfigFrame:SetSize (825, scrollBoxHeight + 53 + 5)
animationFrame.AnimationConfigFrame = animationConfigFrame
local animationPreviewFrame = CreateFrame ("frame", "$parentPreviewConfig", animationFrame, BackdropTemplateMixin and "BackdropTemplate")
DF:ApplyStandardBackdrop (animationPreviewFrame)
animationPreviewFrame:SetPoint ("topleft", animationConfigFrame, "bottomleft", 0, -5)
animationPreviewFrame:SetPoint ("topright", animationConfigFrame, "bottomright", 0, -5)
animationPreviewFrame:SetHeight (60)
animationFrame.AnimationPreviewFrame = animationPreviewFrame
local previewHeaderLabel = DF:CreateLabel (animationPreviewFrame, "Preview Settings:", DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
previewHeaderLabel:SetPoint ("topleft", animationPreviewFrame, "topleft", 5, -5)
--select effect dropdown (scale, shake)
local effectSelectionLabel = DF:CreateLabel (animationConfigFrame, "Effect:", DF:GetTemplate ("font", "ORANGE_FONT_TEMPLATE"))
local effectSelectionDropdown = DF:CreateDropDown (animationConfigFrame, animationFrame.RefreshEffectListDropdown, 1, 160, 20, "EffectSelectionDropdown", _, DF:GetTemplate ("dropdown", "OPTIONS_DROPDOWN_TEMPLATE"))
effectSelectionDropdown:SetPoint ("left", effectSelectionLabel, "right", 2, 0)
animationFrame.EffectSelectionDropdown = effectSelectionDropdown
--add shake effect
local addShakeButton = DF:CreateButton (animationConfigFrame, animationFrame.AddNewShakeEffect, 120, 20, "Add Shake Effect", -1, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate ("font", "PLATER_BUTTON"))
animationFrame.AddShakeButton = addShakeButton
--add scale effect
local addScaleButton = DF:CreateButton (animationConfigFrame, animationFrame.AddNewScaleEffect, 120, 20, "Add Scale Effect", -1, nil, nil, nil, nil, nil, DF:GetTemplate ("button", "OPTIONS_BUTTON_TEMPLATE"), DF:GetTemplate ("font", "PLATER_BUTTON"))
addScaleButton:SetPoint ("left", addShakeButton, "right", 2, 0)
animationFrame.AddScaleButton = addScaleButton
animationFrame.AllConfigFrames = {}
local scaleOptionsFrame = CreateFrame ("frame", "$parentScaleFrame", animationConfigFrame, BackdropTemplateMixin and "BackdropTemplate")
scaleOptionsFrame:Hide()
animationFrame.AllConfigFrames ["scale"] = scaleOptionsFrame
local shakeOptionsFrame = CreateFrame ("frame", "$parentShakeFrame", animationConfigFrame, BackdropTemplateMixin and "BackdropTemplate")
animationFrame.AllConfigFrames ["frameshake"] = shakeOptionsFrame
function animationFrame.DisableOptions()
for _, widget in ipairs (scaleOptionsFrame.widget_list) do
if (widget.Disable) then
widget:Disable()
end
end
for _, widget in ipairs (shakeOptionsFrame.widget_list) do
if (widget.Disable) then
widget:Disable()
end
end
end
function animationFrame.EnableOptions()
for _, widget in ipairs (scaleOptionsFrame.widget_list) do
if (widget.Enable) then
widget:Enable()
end
end
for _, widget in ipairs (shakeOptionsFrame.widget_list) do
if (widget.Enable) then
widget:Enable()
end
end
end
for _, frame in pairs (animationFrame.AllConfigFrames) do
frame:SetSize (460, 250)
frame:SetPoint ("topleft", animationConfigFrame, "topleft", 5, -5)
--frame:Hide()
frame.Data = {}
end
local scaleOptionsTable = {
{
type = "toggle",
get = function() return scaleOptionsFrame.Data.enabled end,
set = function (self, fixedparam, value)
scaleOptionsFrame.Data.enabled = value
end,
name = "Enabled",
},
{type = "blank"},
{
type = "range",
get = function() return scaleOptionsFrame.Data.duration end,
set = function (self, fixedparam, value)
scaleOptionsFrame.Data.duration = value
end,
min = 0.05,
max = 1,
step = 0.05,
usedecimals = true,
name = "Duration",
},
{type = "blank"},
{
type = "range",
get = function() return scaleOptionsFrame.Data.scale_upX end,
set = function (self, fixedparam, value)
scaleOptionsFrame.Data.scale_upX = value
end,
min = 0,
max = 20,
step = 0.05,