This repository has been archived by the owner on Jun 11, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 25
/
AnimationEditor.rbxmx
17649 lines (16657 loc) · 578 KB
/
AnimationEditor.rbxmx
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
<roblox xmlns:xmime="http://www.w3.org/2005/05/xmlmime" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://www.roblox.com/roblox.xsd" version="4">
<External>null</External>
<External>nil</External>
<Item class="Folder" referent="RBX9E1527C11C344E1583FD4792D54C6E7A">
<Properties>
<string name="Name">Plugin</string>
</Properties>
<Item class="Script" referent="RBX7C4413FB08E647B8A869426680264373">
<Properties>
<bool name="Disabled">true</bool>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">createBlockRig</string>
<string name="ScriptGuid"></string>
<ProtectedString name="Source"><![CDATA[local rigCreator = require(script.Parent.RigCreator)
local toolbar = plugin:CreateToolbar("Animations")
local button = toolbar:CreateButton(
"", -- The text next to the icon. Leave this blank if the icon is sufficient.
"Create Block Rig", -- hover text
"http://www.roblox.com/asset/?id=142301446" -- The icon file's name
)
button.Click:connect(function()
if (_G["AnimationEdit"] == true) then
print("Cannot create rig while in edit mode.")
return
end
--
local rig = rigCreator.CreateR6Rig()
rig:MoveTo(Vector3.new(0, 5.2, 0))
end)]]></ProtectedString>
</Properties>
</Item>
<Item class="Script" referent="RBXE47092D4EB914B6D8AAF426FE501BB5F">
<Properties>
<bool name="Disabled">true</bool>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">createMeshBoyRig</string>
<string name="ScriptGuid"></string>
<ProtectedString name="Source"><![CDATA[local rigCreator = require(script.Parent.RigCreator)
local toolbar = plugin:CreateToolbar("Animations")
local button = toolbar:CreateButton(
"", -- The text next to the icon. Leave this blank if the icon is sufficient.
"Create Man Rig", -- hover text
"http://www.roblox.com/asset/?id=142301579" -- The icon file's name.
)
button.Click:connect(function()
if (_G["AnimationEdit"] == true) then
print("Cannot create rig while in edit mode.")
return
end
local rig = rigCreator.CreateR6Rig()
local LArmMesh = Instance.new("CharacterMesh", rig)
LArmMesh.MeshId = 82907977
LArmMesh.BodyPart = 2
local RArmMesh = Instance.new("CharacterMesh", rig)
RArmMesh.MeshId = 82908019
RArmMesh.BodyPart = 3
local LLegMesh = Instance.new("CharacterMesh", rig)
LLegMesh.MeshId = 81487640
LLegMesh.BodyPart = 4
local RLegMesh = Instance.new("CharacterMesh", rig)
RLegMesh.MeshId = 81487710
RLegMesh.BodyPart = 5
local TorsoMesh = Instance.new("CharacterMesh", rig)
TorsoMesh.MeshId = 82907945
TorsoMesh.BodyPart = 1
local HeadMesh = Instance.new("SpecialMesh", rig.Head)
HeadMesh.MeshType = 0
HeadMesh.Scale = Vector3.new(1.25, 1.25, 1.25)
rig:MoveTo(Vector3.new(0, 5.2, 0))
end)]]></ProtectedString>
</Properties>
</Item>
<Item class="Script" referent="RBXF5512FC251E74CD0B688D433B5D9F7DB">
<Properties>
<bool name="Disabled">true</bool>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">createMeshGirlRig</string>
<string name="ScriptGuid"></string>
<ProtectedString name="Source"><![CDATA[local rigCreator = require(script.Parent.RigCreator)
local toolbar = plugin:CreateToolbar("Animations")
local button = toolbar:CreateButton(
"", -- The text next to the icon. Leave this blank if the icon is sufficient.
"Create Woman Rig", -- hover text
"http://www.roblox.com/asset/?id=142301608" -- The icon file's name.
)
button.Click:connect(function()
if (_G["AnimationEdit"] == true) then
print("Cannot create rig while in edit mode.")
return
end
local rig = rigCreator.CreateR6Rig()
local LArmMesh = Instance.new("CharacterMesh", rig)
LArmMesh.MeshId = 83001137
LArmMesh.BodyPart = 2
local RArmMesh = Instance.new("CharacterMesh", rig)
RArmMesh.MeshId = 83001181
RArmMesh.BodyPart = 3
local LLegMesh = Instance.new("CharacterMesh", rig)
LLegMesh.MeshId = 81628361
LLegMesh.BodyPart = 4
local RLegMesh = Instance.new("CharacterMesh", rig)
RLegMesh.MeshId = 81628308
RLegMesh.BodyPart = 5
local TorsoMesh = Instance.new("CharacterMesh", rig)
TorsoMesh.MeshId = 82987757
TorsoMesh.BodyPart = 1
local HeadMesh = Instance.new("SpecialMesh", rig.Head)
HeadMesh.MeshType = 0
HeadMesh.Scale = Vector3.new(1.25, 1.25, 1.25)
rig:MoveTo(Vector3.new(0, 5.2, 0))
end)]]></ProtectedString>
</Properties>
</Item>
<Item class="Script" referent="RBX158AAE6963B1477580A1D45249EEC870">
<Properties>
<bool name="Disabled">true</bool>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">createMeshRig</string>
<string name="ScriptGuid"></string>
<ProtectedString name="Source"><![CDATA[local rigCreator = require(script.Parent.RigCreator)
local toolbar = plugin:CreateToolbar("Animations")
local button = toolbar:CreateButton(
"", -- The text next to the icon. Leave this blank if the icon is sufficient.
"Create Mesh Rig", -- hover text
"http://www.roblox.com/asset/?id=142301531" -- The icon file's name.
)
button.Click:connect(function()
if (_G["AnimationEdit"] == true) then
print("Cannot create rig while in edit mode.")
return
end
local rig = rigCreator.CreateR6Rig()
local LArmMesh = Instance.new("CharacterMesh", rig)
LArmMesh.MeshId = 27111419
LArmMesh.BodyPart = 2
local RArmMesh = Instance.new("CharacterMesh", rig)
RArmMesh.MeshId = 27111864
RArmMesh.BodyPart = 3
local LLegMesh = Instance.new("CharacterMesh", rig)
LLegMesh.MeshId = 27111857
LLegMesh.BodyPart = 4
local RLegMesh = Instance.new("CharacterMesh", rig)
RLegMesh.MeshId = 27111882
RLegMesh.BodyPart = 5
local TorsoMesh = Instance.new("CharacterMesh", rig)
TorsoMesh.MeshId = 27111894
TorsoMesh.BodyPart = 1
local HeadMesh = Instance.new("SpecialMesh", rig.Head)
HeadMesh.MeshType = 0
HeadMesh.Scale = Vector3.new(1.25, 1.25, 1.25)
rig:MoveTo(Vector3.new(0, 5.2, 0))
end)]]></ProtectedString>
</Properties>
</Item>
<Item class="Script" referent="RBX6466DBE39F2847E2A6576793B25B732C">
<Properties>
<bool name="Disabled">false</bool>
<Content name="LinkedSource"><null></null></Content>
<string name="Name">AnimationEditor</string>
<string name="ScriptGuid"></string>
<ProtectedString name="Source"><![CDATA[--[[
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
NOTES FOR ANYBODY READING / MODIFYING THE EDITOR!
-Almost all UI code has been moved to the MenuHandler ModuleScript. There is still a lot of earlier UI code in here that can be cleaned, can probably reduce 500 - 1000 lines
-It would be nice to prebuild the timeline (as has been done with UI) so the generation does not need to be done in code
-Rewrite code that uses variables timelineScale, animationLength so that these can be calculated more cleanly instead of being done often
-MenuManager works by being passed functions to be called when they are done running.
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
--]]
local version = "3.3.2" --try to keep this up to date :)
_G["AnimationEdit"] = false
local toolbar = plugin:CreateToolbar("Animations")
local button = toolbar:CreateButton(
"Animation Editor",
"Create, preview and publish animations for character rigs", -- The text next to the icon. Leave Othis blank if the icon is sufficient.
"http://www.roblox.com/asset/?id=620849296" -- The icon file's name
)
--The envRoot is for a testing environment. When developing the plugin, you can loadstring instead of reloading studio.
local envRoot = script ~= nil and script.Parent or game.Workspace:findFirstChild("Plugin"):clone()
local rootPart
local menuManager = require(envRoot.AnimationEditor.MenuHandler)
local easingStyles = require(envRoot.AnimationEditor.EasingStyles)
local guis = envRoot.AnimationEditor.GUIs
local cleanup = {}--Parts to be cleaned up on close
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
-- 3.1 Flag Code
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
local fbxFlagExists, fbxFlagValue = pcall(function () return settings():GetFFlag("DebugStudioRigImporter") end)
--In the middle of a flag name transition...
if not fbxFlagExists then
fbxFlagExists, fbxFlagValue = pcall(function () return settings():GetFFlag("StudioFbxRigImporting") end)
end
-----------------------------------------...
local DebugEnabled = false
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
-- PREFERENCES
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
local preferences = {
["TweenCursor"] = plugin:GetSetting("AnimEditor_TweenCursor"),
["Snapping"] = true,
["TransparentSelect"] = plugin:GetSetting("AnimEditor_TransparentSelect"),
["Interpolation"] = plugin:GetSetting("AnimEditor_Interpolation"),
["Tooltips"] = plugin:GetSetting("AnimEditor_Tooltips")
}
if preferences["TweenCursor"] == nil then
preferences["TweenCursor"] = true
end
if preferences["TransparentSelect"] == nil then
preferences["TransparentSelect"] = true
end
if preferences["Tooltips"] == nil then
preferences["Tooltips"] = true
end
if preferences["Interpolation"] == nil then
preferences["Interpolation"] = true
end
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
-- G E N E R I C U T I L C O D E
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
local function Repeat(func)
local flag = true
spawn(function()
while flag do
func()
wait()
end
end)
return (function() flag = false end)
end
function repairedCFrameSnailVersion(cf)
local sq=math.sqrt
local x,y,z,a,b,c,d,e,f,g,h,i=cf:components()
local j,k,l=f*g-d*i,a*i-c*g,c*d-a*f
local m,n,o=d*l-k*g,j*g-l*a,a*k-j*d
local l1,l2,l3=sq(a^2+d^2+g^2),sq(j^2+k^2+l^2),sq(m^2+n^2+o^2)
return CFrame.new(x,y,z,a/l1,j/l2,m/l3,d/l1,k/l2,n/l3,g/l1,l/l2,o/l3)
end
function repairedCFrame(cf)
local x,y,z,a,b,c,d,e,f,g,h,i=cf:components()
local j,k,l=f*g-d*i,a*i-c*g,c*d-a*f
local m,n,o=d*l-k*g,j*g-l*a,a*k-j*d
local l1,l2,l3=(a^2+d^2+g^2)^0.5,(j^2+k^2+l^2)^0.5,(m^2+n^2+o^2)^0.5
return CFrame.new(x,y,z,a/l1,j/l2,m/l3,d/l1,k/l2,n/l3,g/l1,l/l2,o/l3)
end
function isCFrameBroken(cframe)
local x, y, z, a, b, c, d, e, f, g, h, i = cframe:components()
local r1 = Vector3.new(a, d, g)
local r2 = Vector3.new(b, e, h)
local r3 = Vector3.new(c, f, i)
local function fuzzyEq(a, b)
return math.abs(a - b) < 0.001
end
return (not fuzzyEq(r1.magnitude, 1) ) or (not fuzzyEq(r2.magnitude, 1) ) or (not fuzzyEq(r3.magnitude, 1) )
end
function approx(arg)
return math.floor(arg * 1000) / 1000
end
function spairs(t, order)
-- collect the keys
local keys = {}
for k in pairs(t) do keys[#keys+1] = k end
-- if order function given, sort by it by passing the table and keys a, b,
-- otherwise just sort the keys
if order then
table.sort(keys, function(a,b) return order(t, a, b) end)
else
table.sort(keys)
end
-- return the iterator function
local i = 0
return function()
i = i + 1
if keys[i] then
return keys[i], t[keys[i]]
end
end
end
----------- udim stuff ----------------------------
local function UD(a, b, c, d)
return UDim2.new(a, b, c, d)
end
local function CenterPos(w, h)
return UD(0.5, -w/2, 0.5, -h/2)
end
local function ConstSize(w, h)
return UD(0, w, 0, h)
end
function Make(ty, data)
local obj = Instance.new(ty)
for k, v in pairs(data) do
if type(k) == 'number' then
v.Parent = obj
else
obj[k] = v
end
end
return obj
end
function round(val)
return math.floor(val + 0.5)
end
function printCFrame(name, cf)
local anarray = {cf:components()}
local str = ""
for i,v in pairs(anarray) do
str = str .. " " .. i .. "# " .. v
end
print(name .. " " .. str)
end
function printVector(vec)
print("X " .. vec.x .. " Y " .. vec.y .. " Z " .. vec.z)
end
function tablelength(T)
local count = 0
for _ in pairs(T) do count = count + 1 end
return count
end
local function weldBetween(a, b, optionalParent)
local weld = Instance.new("Motor6D")
weld.Part0 = a
weld.Part1 = b
weld.C0 = CFrame.new()
weld.C1 = b.CFrame:inverse()*a.CFrame
weld.Parent = optionalParent ~= nil and optionalParent or a
return weld;
end
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
-- MOUSE EVENT CODE
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
local mouseOnLClick = {}
local mouseOnRClick = {}
local mouseOnLUp = {}
local mouseOnRUp = {}
function safeNil(item)
if (item == nil) then
return "NIL"
else
return item
end
end
function isSafeNIL(item)
return (item == "NIL")
end
function registerOn(event, guiElement, func)
guiElement = safeNil(guiElement)
local ord = 1
if (isSafeNIL(guiElement)) then
ord = 0
else
local parent = guiElement.Parent
while (parent ~= nil and parent ~= game.Workspace) do
ord = ord + 1
parent = parent.Parent
end
end
local eventInstance = { Element = guiElement, Function = func, Order = ord}
table.insert(event, eventInstance)
return eventInstance
end
function unregisterOn(event, guiElement)
guiElement = safeNil(guiElement)
local i=1
while i <= #event do
if event[i].Element == guiElement then
table.remove(event, i)
else
i = i + 1
end
end
end
function unregisterEvent(event, eventInstance)
local i=1
while i <= #event do
if event[i] == eventInstance then
table.remove(event, i)
-- print("Remove " .. eventInstance.Element.Name )
else
i = i + 1
end
end
end
function clearAllEvents()
mouseOnLClick = {}
mouseOnRClick = {}
mouseOnLUp = {}
mouseOnRUp = {}
end
function isIn(guiElement, X, Y)
if (X >= guiElement.AbsolutePosition.X and X <= guiElement.AbsolutePosition.X + guiElement.AbsoluteSize.X and
Y >= guiElement.AbsolutePosition.Y and Y <= guiElement.AbsolutePosition.Y + guiElement.AbsoluteSize.Y) then
return true
else
return false
end
end
function listEvent(event)
print("Event List --------------------------------------")
local i=1
while i <= #event do
local consume = "false"
if (event[i].Consume) then
consume = "true"
end
if (isSafeNIL(event[i].Element)) then
print("Nil " .. event[i].Order )
else
print(event[i].Element.Name .. " " .. event[i].Order)
end
i = i + 1
end
end
--------------------------------------------------------------------------------------------
-- GUI Mouse Handlers
--------------------------------------------------------------------------------------------
local function mouseCallbackCheck(list)
local mouse = plugin:GetMouse()
for _,elem in spairs(list, function(t, a, b) return t[a].Order > t[b].Order end) do
if (isSafeNIL(elem.Element)) then
if (elem.Function(mouse.X, mouse.Y)) then
break
end
elseif isIn(elem.Element, mouse.X, mouse.Y) then
if (elem.Function(mouse.X - elem.Element.AbsolutePosition.X, mouse.Y - elem.Element.AbsolutePosition.Y)) then
break
end
end
end
end
plugin:GetMouse().Button1Down:connect(function()
mouseCallbackCheck(mouseOnLClick)
end
)
plugin:GetMouse().Button2Down:connect(function()
mouseCallbackCheck(mouseOnRClick)
end
)
plugin:GetMouse().Button1Up:connect(function()
mouseCallbackCheck(mouseOnLUp)
end
)
plugin:GetMouse().Button2Up:connect(function()
mouseCallbackCheck(mouseOnRUp)
end
)
game:GetService("UserInputService").InputEnded:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 then
mouseCallbackCheck(mouseOnLUp)
end
end)
local mousePosition2d = Vector2.new()
game:GetService("UserInputService").InputChanged:connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
mousePosition2d = Vector2.new(input.Position.X, input.Position.Y)
end
end)
function saveModel()
local model = animationController.Parent:Clone()
model.Parent = game:GetService("ServerStorage")
model.Name = "AnimationEditorDebugModel"
end
function mouseRaycast(ignoreList)
local ray = workspace.CurrentCamera:ViewportPointToRay(mousePosition2d.X, mousePosition2d.Y)
ray = Ray.new(ray.Origin, ray.Direction.Unit * 512)
local part, point, normal
--infinite loop that is broken out of, so don't worry
while true do
part, point, normal = workspace:FindPartOnRayWithIgnoreList(ray, ignoreList)
if part then
local isTransparent = (part.Transparency > 0.9 and preferences["TransparentSelect"] == false) or part.Name == "SelectionPart"
local isHumanoidRootPart = part.Name == "HumanoidRootPart"
--calculate whether it's an active part or not
local isDisabled = false
local animatedPart = findAnimatedPart(part)
if animatedPart then
isDisabled = not partInclude[animatedPart.Name]
end
local shouldSkip = isTransparent or isHumanoidRootPart or isDisabled
if shouldSkip then
table.insert(ignoreList, part)
else
break
end
else
break
end
end
return part, point, normal
end
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
-- G L O B A L S (Globals for CTRL-F)
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
timelineUI = nil
menuUI = nil
saveUI = nil
loadUI = nil
stopAnimUI = nil
timeChangeUI = nil
selectedLine = nil
rotateMoveUI = nil
local timelinemarginSize = 40
local marginSize = 5
local lineSize = 10
local buttonSize = 15
local nameSize = 150
local headerSize = 45
local timelineLength = 0
local tickSeparation = 50
local ticks = 1
local tickSpacing = 0.25
local lineCount = 0
local cursorTime = 0
local timeScale = 0.05 -- Pixels per second of animation
--New Timeline
local tickIncrements = plugin:GetSetting("AnimEditor_TickIncrement") == nil and 0.1 or plugin:GetSetting("AnimEditor_TickIncrement")
local timelineWidth = 0
local dragSnapIncrements = plugin:GetSetting("AnimEditor_SnapIncrement") == nil and 0.05 or plugin:GetSetting("AnimEditor_SnapIncrement")
partList = {}
undoMemory = {}
redoMemory = {}
undoPointer = 0
partListByName = {}
partToItemMap = {}
partToLineNumber = {}
rootPart = nil
animationController = nil
partInclude = {}
cursorClick = false
modal = false
rotateMode = true
partSelection = nil
selectedKeyframe = nil
rotateStep = 0
moveStep = 0
game.Workspace:WaitForChild("Camera")
screenWidth = game.Workspace.Camera.ViewportSize.X
buttonOnColor = Color3.new(200/255, 200/255, 200/255)
buttonOffColor = Color3.new(50/255, 50/255, 50/255)
dropDownColor = Color3.new(21/255, 21/255, 21/255)--Color3.new(100/255, 100/255, 150/255)
local lastAutoSaveTime = 0
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
-- D R O P D O W N M E N U
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
dropDownMouseClickEater = nil
dropDownMenuClearEvent = nil
function displayDropDownMenu(parent, choiceList, x, y)
local retval = nil
modal = true
local numButtons = tablelength(choiceList)
-- create frame
local dropDownUI = Make('Frame', {
Parent = timelineUI.RootFrame,
Name = 'RootFrame',
Style = 'Custom',
Position = UD(0, x - 100, 0, y),
Size = UD(0, 100, 0, (marginSize) + numButtons * (buttonSize + marginSize)),
BackgroundColor3 = Color3.new(21/255, 21/255, 21/255),
BackgroundTransparency = 0.3,
ZIndex = 10,
})
local waitLock = false
local buttonIdx = 0
for idx, value in pairs(choiceList) do
local button = Make('TextButton', {
Parent = dropDownUI,
Name = value ..'Button',
Font = 'ArialBold',
FontSize = GuiSettings.TextMed,
TextColor3 = GuiSettings.TextColor,
Position = UD(0.05, 0, 0, marginSize + buttonIdx * (buttonSize + marginSize)),
Size = UD(0.9, 0, 0, buttonSize),
BackgroundColor3 = Color3.new(150/255, 150/255, 150/255),
BackgroundTransparency = 0,
Text = value,
ZIndex = 11,
})
button.MouseButton1Click:connect(function()
waitLock = true
retval = value
end)
buttonIdx = buttonIdx + 1
end
dropDownMouseClickEater = registerOn(mouseOnLClick, dropDownUI, function(x, y) return true end)
dropDownMenuClearEvent = registerOn(mouseOnLClick, nil, function(x, y)
waitLock = true
return true
end)
while( not waitLock ) do
wait()
end
dropDownUI.Parent = nil
unregisterEvent(mouseOnLClick, dropDownMouseClickEater)
unregisterEvent(mouseOnLClick, dropDownMenuClearEvent)
modal = false
return retval
end
function displayOptionsMenu(x, y)
if timelineUI.RootFrame:findFirstChild("OptionsRootFrame") ~= nil then timelineUI.RootFrame.OptionsRootFrame.Parent = nil end
modal = true
local loopButton = loopAnimation == true and "Loop: on" or "Loop: off"
local priorityType = "Priority: "..timelineUI.RootFrame.PriorityDisplay.Text
local cursorText = preferences["TweenCursor"] == true and "Tween Cursor: on" or "Tween Cursor: off"
local transparentToggle = preferences["TransparentSelect"] == true and "Select Invisible: yes" or "Select Invisible: no"
local choiceList = {"Change Length","Tick Interval: "..tostring(tickIncrements),"Snap Interval: "..tostring(dragSnapIncrements),loopButton, priorityType, cursorText, transparentToggle}
local choiceNames = {"Length","Tick","Snap","Loop","Priority","TweenCursor","TransparentToggle"}
local numButtons = tablelength(choiceList)
local buttonSize = buttonSize + 4
-- create frame
local dropDownUI = Make('Frame', {
Parent = timelineUI.RootFrame,
Name = 'OptionsRootFrame',
Style = 'Custom',
Position = UD(0, x, 0, y),
Size = UD(0, 200, 0, (marginSize) + numButtons * (buttonSize + marginSize)),
BackgroundColor3 = Color3.new(21/255, 21/255, 21/255),
BackgroundTransparency = 0.3,
ZIndex = 10,
})
local waitLock = false
local buttonIdx = 0
local buttons = {}
for idx, value in pairs(choiceList) do
local button = Make('TextButton', {
Parent = dropDownUI,
Name = value ..'Button',
Font = 'ArialBold',
FontSize = GuiSettings.TextMed,
TextColor3 = GuiSettings.TextColor,
Position = UD(0.05, 0, 0, marginSize + buttonIdx * (buttonSize + marginSize)),
Size = UD(0.9, 0, 0, buttonSize),
BackgroundColor3 = (idx %2) == 0 and Color3.new(150/255, 150/255, 150/255) or Color3.new(170/255, 170/255, 170/255),
BackgroundTransparency = 0,
Text = " "..value,
ZIndex = 11,
TextXAlignment = Enum.TextXAlignment.Left,
TextStrokeTransparency = 0.9,
})
buttons[choiceNames[idx]] = button
buttonIdx = buttonIdx + 1
end
buttons["Length"].MouseButton1Click:connect(function()
timeChangeUI.RootFrame.SaveNameFrame.AnimLengthBox.Text = tostring(animationLength)
timeChangeUI.Parent = game:GetService("CoreGui")
end)
buttons["Tick"].MouseButton1Click:connect(function()
tickChangeUI.RootFrame.SaveNameFrame.TickIncrementBox.Text = tostring(tickIncrements)
tickChangeUI.Parent = game:GetService("CoreGui")
end)
buttons["Snap"].MouseButton1Click:connect(function()
snapChangeUI.RootFrame.SaveNameFrame.SnapIncrementBox.Text = tostring(dragSnapIncrements)
snapChangeUI.Parent = game:GetService("CoreGui")
end)
buttons["Loop"].MouseButton1Click:connect(function()
loopAnimation = not loopAnimation
buttons["Loop"].Text = loopAnimation and "Loop: on" or "Loop: off"
end)
buttons["Priority"].MouseButton1Click:connect(function()
local mouse = plugin:GetMouse()
local newPriority = displayDropDownMenu(timelineUI.RootFrame.PriorityDisplay, animationPriorityList, x + 300, mouse.Y)
if (newPriority ~= nil) then
animationPriority = newPriority
timelineUI.RootFrame.PriorityDisplay.Text = newPriority
buttons["Priority"].Text = "Priority: "..newPriority
end
end)
buttons["TweenCursor"].MouseButton1Click:connect(function()
preferences["TweenCursor"] = not preferences["TweenCursor"]
buttons["TweenCursor"].Text = preferences["TweenCursor"] == true and "Tween Cursor: on" or "Tween Cursor: off"
end)
buttons["TransparentToggle"].MouseButton1Click:connect(function()
preferences["TransparentSelect"] = not preferences["TransparentSelect"]
buttons["TransparentToggle"].Text = preferences["TransparentSelect"] == true and "Select Invisible: yes" or "Select Invisible: no"
end)
local close
close = plugin:GetMouse().Button1Down:connect(function()
local mouse = plugin:GetMouse()
if mouse.X > x + (200) or mouse.X < x then
if mouse.Y > y + (marginSize) + numButtons * (buttonSize + marginSize) or mouse.Y < y then
close:disconnect()
dropDownUI:Destroy()
modal = false
end
end
end)
end
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
-- T E X T E N T R Y D I A L O G
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------
function showTextExtryDialog(title, default)
modal = true
local dialogUI = Make('ScreenGui',
{
Name = "SaveUI",
Make('Frame', {
Name = 'RootFrame',
Style = 'Custom',
Position = UD(0.5, -200, 0.5, 0),
Size = UD(0, 400, 0, marginSize + (lineSize + marginSize) * 5),
BackgroundColor3 = Color3.new(21/255, 21/255, 21/255),
BackgroundTransparency = 0.5,
Make('TextLabel', {
Name = 'TitleBar',
Font = 'ArialBold',
FontSize = 'Size14',
TextColor3 = GuiSettings.TextColor,
Position = UD(0.05, 0, 0, marginSize),
Size = UD(0.9, 0, 0, lineSize),
BackgroundTransparency = 1,
Text = title,
TextXAlignment = Enum.TextXAlignment.Left,
}),
Make('Frame', {
Parent = timelineUI,
Name = 'SaveNameFrame',
Style = 'Custom',
Position = UD(0.05, 0, 0, marginSize + (lineSize + marginSize) * 1),
Size = UD(0.9, 0, 0, lineSize * 2),
BackgroundColor3 = Color3.new(100/255, 100/255, 100/255),
BackgroundTransparency = 0.3,
Make('TextBox', {
Name = 'SaveNameBox',
Font = 'ArialBold',
FontSize = 'Size14',
TextColor3 = GuiSettings.TextColor,
Position = UD(0.05, 0, 0, 0),
Size = UD(0.9, 0, 1, 0),
BackgroundTransparency = 1,
Text = default,
TextXAlignment = Enum.TextXAlignment.Left,
}),
}),
Make('TextButton', {
Name = 'OKButton',
Font = 'ArialBold',
FontSize = GuiSettings.TextMed,
TextColor3 = GuiSettings.TextColor,
Position = UD(0.05, 0, 0, marginSize + (lineSize + marginSize) * 3),
Size = UD(0.4, 0, 0, lineSize * 2),
BackgroundColor3 = Color3.new(100/255, 100/255, 150/255),
BackgroundTransparency = 0,
Text = "OK",
}),
Make('TextButton', {
Name = 'CancelButton',
Font = 'ArialBold',
FontSize = GuiSettings.TextMed,
TextColor3 = GuiSettings.TextColor,
Position = UD(0.55, 0, 0, marginSize + (lineSize + marginSize) * 3),
Size = UD(0.4, 0, 0, lineSize * 2),
BackgroundColor3 = Color3.new(100/255, 100/255, 150/255),
BackgroundTransparency = 0,
Text = "Cancel",
}),
}),
})
local retval = default
local waitLock = false
dialogUI.RootFrame.OKButton.MouseButton1Click:connect(function()
retval = dialogUI.RootFrame.SaveNameFrame.SaveNameBox.Text
waitLock = true
end)
dialogUI.RootFrame.CancelButton.MouseButton1Click:connect(function()
retval = nil
waitLock = true
end)
dialogUI.Parent = game:GetService("CoreGui")
while( not waitLock ) do
wait()
end
dialogUI.Parent = nil
modal = false
return retval
end
--confirm dialogue
function showConfirmationDialog(text)
modal = true
local dialogUI = Make('ScreenGui',
{
Name = "SaveUI",
Make('Frame', {
Name = 'RootFrame',
Style = 'Custom',
Position = UD(0.5, -200, 0.5, 0),
Size = UD(0, 400, 0, marginSize + (lineSize + marginSize) * 5),
BackgroundColor3 = Color3.new(21/255, 21/255, 21/255),
BackgroundTransparency = 0.5,
BorderSizePixel = 0,
Make('TextLabel', {
Name = 'TitleBar',
Font = 'ArialBold',
FontSize = 'Size14',
TextColor3 = GuiSettings.TextColor,
Position = UD(0.05, 0, 0, marginSize),
Size = UD(0.9, 0, 0, lineSize * 2),
BackgroundTransparency = 1,
Text = text,
TextXAlignment = Enum.TextXAlignment.Left,
}),
Make('TextButton', {
Name = 'OKButton',
Font = 'ArialBold',
FontSize = GuiSettings.TextMed,
TextColor3 = GuiSettings.TextColor,
Position = UD(0.05, 0, 0, marginSize + (lineSize + marginSize) * 3),
Size = UD(0.4, 0, 0, lineSize * 2),
BackgroundColor3 = Color3.new(100/255, 100/255, 150/255),
BackgroundTransparency = 0,
Text = "OK",
}),
Make('TextButton', {
Name = 'CancelButton',
Font = 'ArialBold',
FontSize = GuiSettings.TextMed,
TextColor3 = GuiSettings.TextColor,
Position = UD(0.55, 0, 0, marginSize + (lineSize + marginSize) * 3),