Example #1
0
        public static void Perform(IntVector2 offset, bool removeOriginals)
        {
            var rows = Document.Current.Rows.ToList();

            if (offset.Y > 0)
            {
                rows.Reverse();
            }
            foreach (var row in rows)
            {
                var track = row.Components.Get <AnimationTrackRow>()?.Track;
                if (track?.EditorState().Locked != false)
                {
                    continue;
                }
                var clips = track.Clips.Where(i => i.IsSelected).ToList();
                var keys  = new List <IKeyframe>();
                if (track.Animators.TryFind(nameof(AnimationTrack.Weight), out var weightAnimator, Document.Current.AnimationId))
                {
                    keys = weightAnimator.ReadonlyKeys.Where(k => clips.Any(c => c.BeginFrame <= k.Frame && k.Frame <= c.EndFrame)).ToList();
                }
                if (removeOriginals)
                {
                    foreach (var key in keys)
                    {
                        RemoveKeyframe.Perform(weightAnimator, key.Frame);
                    }
                }
                foreach (var clip in clips)
                {
                    if (removeOriginals)
                    {
                        AnimationClipToolbox.RemoveClip(track, clip);
                    }
                    else
                    {
                        SetProperty.Perform(clip, nameof(AnimationClip.IsSelected), false);
                    }
                }
                int numRows   = Document.Current.Rows.Count;
                var destRow   = Document.Current.Rows[(row.Index + offset.Y).Clamp(0, numRows - 1)];
                var destTrack = destRow.Components.Get <AnimationTrackRow>()?.Track;
                foreach (var clip in clips)
                {
                    var newClip = clip.Clone();
                    newClip.BeginFrame += offset.X;
                    newClip.EndFrame   += offset.X;
                    newClip.IsSelected  = true;
                    AnimationClipToolbox.InsertClip(destTrack, newClip);
                }
                foreach (var k in keys)
                {
                    var key = k.Clone();
                    key.Frame += offset.X;
                    SetKeyframe.Perform(destTrack, nameof(AnimationTrack.Weight), Document.Current.AnimationId, key);
                }
            }
        }
Example #2
0
 public static void Perform(IntVector2 cell)
 {
     if (TryFindClip(cell, out var track, out var clip))
     {
         Document.Current.History.DoTransaction(() => {
             AnimationClipToolbox.SplitClip(track, clip, cell.X);
         });
     }
 }
Example #3
0
 public static bool TryFindClip(IntVector2 cell, out AnimationTrack track, out AnimationClip clip)
 {
     track = null;
     clip  = null;
     if (cell.Y >= Document.Current.Animation.Tracks.Count)
     {
         return(false);
     }
     track = Document.Current.Animation.Tracks[cell.Y];
     return(AnimationClipToolbox.TryFindClip(track, cell.X, out clip) && cell.X > clip.BeginFrame);
 }
Example #4
0
 public static void Perform()
 {
     Document.Current.History.DoTransaction(() => {
         foreach (var track in Document.Current.Animation.Tracks)
         {
             var clips = track.Clips.Where(i => i.IsSelected).ToList();
             var keys  = new List <IKeyframe>();
             if (track.Animators.TryFind(nameof(AnimationTrack.Weight), out var weightAnimator, Document.Current.AnimationId))
             {
                 keys = weightAnimator.ReadonlyKeys.Where(k => clips.Any(c => c.BeginFrame <= k.Frame && k.Frame <= c.EndFrame)).ToList();
             }
             foreach (var key in keys)
             {
                 RemoveKeyframe.Perform(weightAnimator, key.Frame);
             }
             foreach (var clip in clips)
             {
                 AnimationClipToolbox.RemoveClip(track, clip);
             }
         }
     });
 }
Example #5
0
 public AddAnimationClipDialog(IntVector2 cell, string selectedAnimationId)
 {
     window = new Window(new WindowOptions {
         ClientSize = new Vector2(250, 140),
         FixedSize  = true,
         Title      = "Add Clip",
         Visible    = false,
     });
     rootWidget = new ThemedInvalidableWindowWidget(window)
     {
         Padding = new Thickness(8),
         Layout  = new VBoxLayout(),
         Nodes   =
         {
             new Widget         {
                 Layout = new TableLayout{
                     Spacing        = 4,
                     RowCount       = 3,
                     ColumnCount    = 2,
                     ColumnDefaults = new List <DefaultLayoutCell>{
                         new DefaultLayoutCell(Alignment.RightCenter)
                         {
                             StretchX = 1
                         },
                         new DefaultLayoutCell(Alignment.LeftCenter)
                         {
                             StretchX = 2
                         },
                     }
                 },
                 LayoutCell = new LayoutCell{
                     StretchY = 0
                 },
                 Nodes =
                 {
                     new ThemedSimpleText("Animation"),
                     (animationSelector = new ThemedDropDownList()),
                     new ThemedSimpleText("Begin Marker"),
                     (beginMarkerSelector = new ThemedDropDownList()),
                     new ThemedSimpleText("End Marker"),
                     (endMarkerSelector = new ThemedDropDownList())
                 }
             },
             new Widget         {
                 // Vertical stretcher
             },
             new Widget         {
                 Layout = new HBoxLayout{
                     Spacing = 8
                 },
                 LayoutCell = new LayoutCell{
                     StretchY = 0
                 },
                 Padding = new Thickness{
                     Top = 5
                 },
                 Nodes =
                 {
                     new Widget {
                         MinMaxHeight = 0
                     },
                     (okButton = new ThemedButton{
                         Text = "Ok"
                     }),
                     (cancelButton = new ThemedButton{
                         Text = "Cancel"
                     }),
                 },
             }
         }
     };
     rootWidget.FocusScope = new KeyboardFocusScope(rootWidget);
     foreach (var a in EnumerateAnimations())
     {
         animationSelector.Items.Add(new CommonDropDownList.Item(a.Id));
     }
     animationSelector.Index = 0;
     if (selectedAnimationId != null)
     {
         animationSelector.Index = animationSelector.Items.Select(i => i.Value).ToList().IndexOf(selectedAnimationId);
     }
     animationSelector.Changed += _ => RefreshMarkers();
     RefreshMarkers();
     cancelButton.Clicked += () => window.Close();
     okButton.Clicked     += () => {
         var animation = Document.Current.Animation.Owner.Animations.Find(animationSelector.Text);
         if (!animation.AnimationEngine.AreEffectiveAnimatorsValid(animation))
         {
             // Refreshes animation duration either
             animation.AnimationEngine.BuildEffectiveAnimators(animation);
         }
         if (animation.CalcDurationInFrames() == 0)
         {
             AlertDialog.Show("Please select an animation with non-zero duration", "Ok");
             return;
         }
         int beginFrame = (int?)beginMarkerSelector.Value ?? 0;
         int endFrame   = (int?)endMarkerSelector.Value ?? animation.CalcDurationInFrames();
         if (beginFrame >= endFrame)
         {
             AlertDialog.Show("Please select markers in ascending order", "Ok");
             return;
         }
         var track = Document.Current.Rows[cell.Y].Components.Get <Core.Components.AnimationTrackRow>().Track;
         Document.Current.History.DoTransaction(() => {
             var clip = new AnimationClip {
                 AnimationId      = animationSelector.Text,
                 BeginFrame       = cell.X,
                 InFrame          = beginFrame,
                 DurationInFrames = endFrame - beginFrame
             };
             AnimationClipToolbox.InsertClip(track, clip);
             Core.Operations.SetProperty.Perform(clip, nameof(AnimationClip.IsSelected), true);
         });
         window.Close();
     };
     cancelButton.SetFocus();
     window.ShowModal();
 }