Browse Source

add cel to next empty frame if free

flabbet 7 months ago
parent
commit
d3773cb834

+ 1 - 2
src/PixiEditor.ChangeableDocument/Changes/Structure/DuplicateLayer_Change.cs

@@ -40,8 +40,7 @@ internal class DuplicateLayer_Change : Change
 
 
         InputProperty<Painter?> targetInput = parent.InputProperties.FirstOrDefault(x =>
         InputProperty<Painter?> targetInput = parent.InputProperties.FirstOrDefault(x =>
             x.ValueType == typeof(Painter) &&
             x.ValueType == typeof(Painter) &&
-            x.Connection != null &&
-            x.Connection.Node is StructureNode) as InputProperty<Painter?>;
+            x.Connection is { Node: StructureNode }) as InputProperty<Painter?>;
 
 
         List<IChangeInfo> operations = new();
         List<IChangeInfo> operations = new();
 
 

+ 1 - 0
src/PixiEditor/Models/Handlers/ICelHandler.cs

@@ -14,4 +14,5 @@ internal interface ICelHandler
     public Guid Id { get; }
     public Guid Id { get; }
     public bool IsVisible { get; }
     public bool IsVisible { get; }
     public IDocument Document { get; }
     public IDocument Document { get; }
+    bool IsWithinRange(int frame);
 }
 }

+ 7 - 1
src/PixiEditor/ViewModels/Document/CelViewModel.cs

@@ -16,7 +16,7 @@ internal abstract class CelViewModel : ObservableObject, ICelHandler
     private bool isVisibleBindable = true;
     private bool isVisibleBindable = true;
     private bool isSelected;
     private bool isSelected;
     private bool isCollapsed;
     private bool isCollapsed;
-    
+
     public bool IsCollapsed
     public bool IsCollapsed
     {
     {
         get => isCollapsed;
         get => isCollapsed;
@@ -24,6 +24,7 @@ internal abstract class CelViewModel : ObservableObject, ICelHandler
     }
     }
 
 
     public DocumentViewModel Document { get; }
     public DocumentViewModel Document { get; }
+
     protected DocumentInternalParts Internals { get; }
     protected DocumentInternalParts Internals { get; }
 
 
     IDocument ICelHandler.Document => Document;
     IDocument ICelHandler.Document => Document;
@@ -134,4 +135,9 @@ internal abstract class CelViewModel : ObservableObject, ICelHandler
         isVisibleBindable = isVisible;
         isVisibleBindable = isVisible;
         OnPropertyChanged(nameof(IsVisible));
         OnPropertyChanged(nameof(IsVisible));
     }
     }
+
+    public bool IsWithinRange(int frame)
+    {
+        return frame >= StartFrameBindable && frame < StartFrameBindable + DurationBindable;
+    }
 }
 }

+ 7 - 2
src/PixiEditor/ViewModels/SubViewModels/AnimationsViewModel.cs

@@ -138,9 +138,14 @@ internal class AnimationsViewModel : SubViewModel<ViewModelMain>
         if (activeDocument.AnimationDataViewModel.TryFindCels<CelGroupViewModel>(targetLayer,
         if (activeDocument.AnimationDataViewModel.TryFindCels<CelGroupViewModel>(targetLayer,
                 out CelGroupViewModel groupViewModel))
                 out CelGroupViewModel groupViewModel))
         {
         {
-            if (active == groupViewModel.StartFrameBindable + groupViewModel.DurationBindable - 1)
+            if (groupViewModel.Children.All(x => !x.IsWithinRange(active )))
             {
             {
-                return groupViewModel.StartFrameBindable + groupViewModel.DurationBindable;
+                return active;
+            }
+            
+            if (groupViewModel.Children.All(x => !x.IsWithinRange(active + 1)))
+            {
+                return active + 1;
             }
             }
         }
         }