|
@@ -17,7 +17,7 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
private int frameRateBindable = 60;
|
|
private int frameRateBindable = 60;
|
|
private int onionFrames = 1;
|
|
private int onionFrames = 1;
|
|
private double onionOpacity = 50;
|
|
private double onionOpacity = 50;
|
|
-
|
|
|
|
|
|
+
|
|
public DocumentViewModel Document { get; }
|
|
public DocumentViewModel Document { get; }
|
|
protected DocumentInternalParts Internals { get; }
|
|
protected DocumentInternalParts Internals { get; }
|
|
public IReadOnlyCollection<ICelHandler> KeyFrames => keyFrames;
|
|
public IReadOnlyCollection<ICelHandler> KeyFrames => keyFrames;
|
|
@@ -25,12 +25,15 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
public IReadOnlyCollection<ICelHandler> AllCels => allCels;
|
|
public IReadOnlyCollection<ICelHandler> AllCels => allCels;
|
|
|
|
|
|
public event Action<int, int> ActiveFrameChanged;
|
|
public event Action<int, int> ActiveFrameChanged;
|
|
-
|
|
|
|
|
|
+
|
|
private KeyFrameCollection keyFrames = new KeyFrameCollection();
|
|
private KeyFrameCollection keyFrames = new KeyFrameCollection();
|
|
private List<ICelHandler> allCels = new List<ICelHandler>();
|
|
private List<ICelHandler> allCels = new List<ICelHandler>();
|
|
private bool onionSkinningEnabled;
|
|
private bool onionSkinningEnabled;
|
|
private bool isPlayingBindable;
|
|
private bool isPlayingBindable;
|
|
|
|
|
|
|
|
+ private int? cachedFirstFrame;
|
|
|
|
+ private int? cachedLastFrame;
|
|
|
|
+
|
|
public int ActiveFrameBindable
|
|
public int ActiveFrameBindable
|
|
{
|
|
{
|
|
get => _activeFrameBindable;
|
|
get => _activeFrameBindable;
|
|
@@ -68,7 +71,7 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
Internals.ActionAccumulator.AddFinishedActions(new ToggleOnionSkinning_PassthroughAction(value));
|
|
Internals.ActionAccumulator.AddFinishedActions(new ToggleOnionSkinning_PassthroughAction(value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public int OnionFramesBindable
|
|
public int OnionFramesBindable
|
|
{
|
|
{
|
|
get => onionFrames;
|
|
get => onionFrames;
|
|
@@ -80,7 +83,7 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
Internals.ActionAccumulator.AddFinishedActions(new SetOnionSettings_Action(value, OnionOpacityBindable));
|
|
Internals.ActionAccumulator.AddFinishedActions(new SetOnionSettings_Action(value, OnionOpacityBindable));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public double OnionOpacityBindable
|
|
public double OnionOpacityBindable
|
|
{
|
|
{
|
|
get => onionOpacity;
|
|
get => onionOpacity;
|
|
@@ -89,10 +92,10 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
if (Document.BlockingUpdateableChangeActive)
|
|
if (Document.BlockingUpdateableChangeActive)
|
|
return;
|
|
return;
|
|
|
|
|
|
- Internals.ActionAccumulator.AddFinishedActions(new SetOnionSettings_Action(OnionFramesBindable, value));
|
|
|
|
|
|
+ Internals.ActionAccumulator.AddFinishedActions(new SetOnionSettings_Action(OnionFramesBindable, value));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public bool IsPlayingBindable
|
|
public bool IsPlayingBindable
|
|
{
|
|
{
|
|
get => isPlayingBindable;
|
|
get => isPlayingBindable;
|
|
@@ -105,9 +108,9 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- public int FirstFrame => keyFrames.Count > 0 ? keyFrames.Min(x => x.StartFrameBindable) : 0;
|
|
|
|
|
|
+ public int FirstFrame => cachedFirstFrame ??= keyFrames.Count > 0 ? keyFrames.Min(x => x.StartFrameBindable) : 0;
|
|
|
|
|
|
- public int LastFrame => keyFrames.Count > 0
|
|
|
|
|
|
+ public int LastFrame => cachedLastFrame ??= keyFrames.Count > 0
|
|
? keyFrames.Max(x => x.StartFrameBindable + x.DurationBindable)
|
|
? keyFrames.Max(x => x.StartFrameBindable + x.DurationBindable)
|
|
: DefaultEndFrame;
|
|
: DefaultEndFrame;
|
|
|
|
|
|
@@ -196,19 +199,19 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
ActiveFrameChanged?.Invoke(previousFrame, newFrame);
|
|
ActiveFrameChanged?.Invoke(previousFrame, newFrame);
|
|
OnPropertyChanged(nameof(ActiveFrameBindable));
|
|
OnPropertyChanged(nameof(ActiveFrameBindable));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void SetPlayingState(bool value)
|
|
public void SetPlayingState(bool value)
|
|
{
|
|
{
|
|
isPlayingBindable = value;
|
|
isPlayingBindable = value;
|
|
OnPropertyChanged(nameof(IsPlayingBindable));
|
|
OnPropertyChanged(nameof(IsPlayingBindable));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void SetOnionSkinning(bool value)
|
|
public void SetOnionSkinning(bool value)
|
|
{
|
|
{
|
|
onionSkinningEnabled = value;
|
|
onionSkinningEnabled = value;
|
|
OnPropertyChanged(nameof(OnionSkinningEnabledBindable));
|
|
OnPropertyChanged(nameof(OnionSkinningEnabledBindable));
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void SetOnionFrames(int frames, double opacity)
|
|
public void SetOnionFrames(int frames, double opacity)
|
|
{
|
|
{
|
|
onionFrames = frames;
|
|
onionFrames = frames;
|
|
@@ -221,9 +224,13 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
{
|
|
{
|
|
if (TryFindCels(keyFrameId, out CelViewModel keyFrame))
|
|
if (TryFindCels(keyFrameId, out CelViewModel keyFrame))
|
|
{
|
|
{
|
|
|
|
+ cachedFirstFrame = null;
|
|
|
|
+ cachedLastFrame = null;
|
|
|
|
+
|
|
keyFrame.SetStartFrame(newStartFrame);
|
|
keyFrame.SetStartFrame(newStartFrame);
|
|
keyFrame.SetDuration(newDuration);
|
|
keyFrame.SetDuration(newDuration);
|
|
keyFrames.NotifyCollectionChanged();
|
|
keyFrames.NotifyCollectionChanged();
|
|
|
|
+
|
|
OnPropertyChanged(nameof(FirstFrame));
|
|
OnPropertyChanged(nameof(FirstFrame));
|
|
OnPropertyChanged(nameof(LastFrame));
|
|
OnPropertyChanged(nameof(LastFrame));
|
|
OnPropertyChanged(nameof(FramesCount));
|
|
OnPropertyChanged(nameof(FramesCount));
|
|
@@ -261,8 +268,12 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
{
|
|
{
|
|
allCels.Add(iCel);
|
|
allCels.Add(iCel);
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
SortByLayers();
|
|
SortByLayers();
|
|
|
|
+
|
|
|
|
+ cachedFirstFrame = null;
|
|
|
|
+ cachedLastFrame = null;
|
|
|
|
+
|
|
OnPropertyChanged(nameof(FirstFrame));
|
|
OnPropertyChanged(nameof(FirstFrame));
|
|
OnPropertyChanged(nameof(LastFrame));
|
|
OnPropertyChanged(nameof(LastFrame));
|
|
OnPropertyChanged(nameof(FramesCount));
|
|
OnPropertyChanged(nameof(FramesCount));
|
|
@@ -290,6 +301,9 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
|
|
|
|
allCels.RemoveAll(x => x.Id == keyFrameId);
|
|
allCels.RemoveAll(x => x.Id == keyFrameId);
|
|
|
|
|
|
|
|
+ cachedFirstFrame = null;
|
|
|
|
+ cachedLastFrame = null;
|
|
|
|
+
|
|
OnPropertyChanged(nameof(FirstFrame));
|
|
OnPropertyChanged(nameof(FirstFrame));
|
|
OnPropertyChanged(nameof(LastFrame));
|
|
OnPropertyChanged(nameof(LastFrame));
|
|
OnPropertyChanged(nameof(FramesCount));
|
|
OnPropertyChanged(nameof(FramesCount));
|
|
@@ -376,7 +390,7 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
result = default;
|
|
result = default;
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
public void SortByLayers()
|
|
public void SortByLayers()
|
|
{
|
|
{
|
|
var allLayers = Document.StructureHelper.GetAllLayers();
|
|
var allLayers = Document.StructureHelper.GetAllLayers();
|
|
@@ -384,8 +398,9 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
var layerKeyFrames = new List<CelGroupViewModel>();
|
|
var layerKeyFrames = new List<CelGroupViewModel>();
|
|
foreach (var layer in allLayers)
|
|
foreach (var layer in allLayers)
|
|
{
|
|
{
|
|
- var group = unsortedKeyFrames.FirstOrDefault(x => x is CelGroupViewModel group && group.LayerGuid == layer.Id) as CelGroupViewModel;
|
|
|
|
- if(group != null)
|
|
|
|
|
|
+ var group = unsortedKeyFrames.FirstOrDefault(x =>
|
|
|
|
+ x is CelGroupViewModel group && group.LayerGuid == layer.Id) as CelGroupViewModel;
|
|
|
|
+ if (group != null)
|
|
{
|
|
{
|
|
layerKeyFrames.Insert(0, group);
|
|
layerKeyFrames.Insert(0, group);
|
|
}
|
|
}
|
|
@@ -398,9 +413,8 @@ internal class AnimationDataViewModel : ObservableObject, IAnimationHandler
|
|
layerKeyFrames.Add(group);
|
|
layerKeyFrames.Add(group);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-
|
|
|
|
|
|
+
|
|
this.keyFrames = new KeyFrameCollection(layerKeyFrames);
|
|
this.keyFrames = new KeyFrameCollection(layerKeyFrames);
|
|
OnPropertyChanged(nameof(KeyFrames));
|
|
OnPropertyChanged(nameof(KeyFrames));
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|