mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Profile editor - Fix undoing profile editor commands
- Undoing a change to an existing keyframe's value restores the value instead of deleting the keyframe - Undoing "remove effect" puts the effect back in its place instead of below the next one - Undoing "toggle keyframes" restores what it was before - Undoing a brush change on a layer that had no brush removes the brush again, using the new Layer.RemoveLayerBrush - Undoing "add element" disables the element again - Undoing an event path change back to no path goes back to an event start node, like a new condition - MoveProfileElement says "Move folder" for folders - UpdateLayerProperty without a time no longer calls itself "Add ... keyframe"
This commit is contained in:
1 parent
504845c7d2
commit
0920cf8917
14 files changed
+80
-71
No files matched your search
@@ -55,6 +55,7 @@ public class AddProfileElement : IProfileEditorCommand, IDisposable
|
||||
public void Undo()
|
||||
{
|
||||
_isAdded = false;
|
||||
_subject.Disable();
|
||||
_target.RemoveChild(_subject);
|
||||
}
|
||||
|
||||
|
||||
@@ -56,6 +56,8 @@ public class ChangeLayerBrush : IProfileEditorCommand, IDisposable
|
||||
{
|
||||
if (_previousBrush != null)
|
||||
_layer.ChangeLayerBrush(_previousBrush);
|
||||
else
|
||||
_layer.RemoveLayerBrush();
|
||||
_executed = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,9 +29,7 @@ public class MoveProfileElement : IProfileEditorCommand
|
||||
_originalIndex = _subject.Parent.Children.IndexOf(_subject);
|
||||
}
|
||||
|
||||
if (subject is Folder)
|
||||
DisplayName = "Move folder";
|
||||
DisplayName = "Move layer";
|
||||
DisplayName = subject is Folder ? "Move folder" : "Move layer";
|
||||
}
|
||||
|
||||
#region Implementation of IProfileEditorCommand
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.LayerEffects;
|
||||
|
||||
@@ -12,6 +13,7 @@ public class RemoveLayerEffect : IProfileEditorCommand, IDisposable
|
||||
private readonly BaseLayerEffect _layerEffect;
|
||||
private readonly RenderProfileElement _renderProfileElement;
|
||||
private bool _executed;
|
||||
private int _order;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="RemoveLayerEffect" /> class.
|
||||
@@ -35,6 +37,7 @@ public class RemoveLayerEffect : IProfileEditorCommand, IDisposable
|
||||
/// <inheritdoc />
|
||||
public void Execute()
|
||||
{
|
||||
_order = _layerEffect.Order;
|
||||
_renderProfileElement.RemoveLayerEffect(_layerEffect);
|
||||
_executed = true;
|
||||
}
|
||||
@@ -42,6 +45,11 @@ public class RemoveLayerEffect : IProfileEditorCommand, IDisposable
|
||||
/// <inheritdoc />
|
||||
public void Undo()
|
||||
{
|
||||
// Removing the effect renumbered the effects below it, make room so it goes back in its old place
|
||||
foreach (BaseLayerEffect layerEffect in _renderProfileElement.LayerEffects.Where(e => e.Order >= _order))
|
||||
layerEffect.Order++;
|
||||
_layerEffect.Order = _order;
|
||||
|
||||
_renderProfileElement.AddLayerEffect(_layerEffect);
|
||||
_executed = false;
|
||||
}
|
||||
|
||||
+14
-23
@@ -14,6 +14,8 @@ public class ToggleLayerPropertyKeyframes<T> : IProfileEditorCommand
|
||||
private readonly LayerProperty<T> _layerProperty;
|
||||
private readonly TimeSpan _time;
|
||||
private LayerPropertyKeyframe<T>? _keyframe;
|
||||
private bool _addedKeyframe;
|
||||
private bool _wasEnabled;
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new instance of the <see cref="ToggleLayerPropertyKeyframes{T}" /> class.
|
||||
@@ -33,37 +35,26 @@ public class ToggleLayerPropertyKeyframes<T> : IProfileEditorCommand
|
||||
/// <inheritdoc />
|
||||
public void Execute()
|
||||
{
|
||||
if (_enable)
|
||||
{
|
||||
_layerProperty.KeyframesEnabled = true;
|
||||
_wasEnabled = _layerProperty.KeyframesEnabled;
|
||||
_addedKeyframe = false;
|
||||
_layerProperty.KeyframesEnabled = _enable;
|
||||
|
||||
// If there weren't any keyframes yet, add one with the current value at the current time
|
||||
if (!_layerProperty.Keyframes.Any())
|
||||
{
|
||||
// If executed before, reuse the previous keyframe
|
||||
_keyframe ??= new LayerPropertyKeyframe<T>(_layerProperty.CurrentValue, _time, Easings.Functions.Linear, _layerProperty);
|
||||
_layerProperty.AddKeyframe(_keyframe);
|
||||
}
|
||||
}
|
||||
else
|
||||
// If there weren't any keyframes yet, add one with the current value at the current time
|
||||
if (_enable && !_layerProperty.Keyframes.Any())
|
||||
{
|
||||
_layerProperty.KeyframesEnabled = false;
|
||||
// If executed before, reuse the previous keyframe
|
||||
_keyframe ??= new LayerPropertyKeyframe<T>(_layerProperty.CurrentValue, _time, Easings.Functions.Linear, _layerProperty);
|
||||
_layerProperty.AddKeyframe(_keyframe);
|
||||
_addedKeyframe = true;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Undo()
|
||||
{
|
||||
if (_enable)
|
||||
{
|
||||
if (_keyframe != null)
|
||||
_layerProperty.RemoveKeyframe(_keyframe);
|
||||
_layerProperty.KeyframesEnabled = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_layerProperty.KeyframesEnabled = true;
|
||||
}
|
||||
if (_addedKeyframe && _keyframe != null)
|
||||
_layerProperty.RemoveKeyframe(_keyframe);
|
||||
_layerProperty.KeyframesEnabled = _wasEnabled;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -39,6 +39,7 @@ public class UpdateLayerProperty<T> : IProfileEditorCommand
|
||||
_originalValue = originalValue;
|
||||
_newValue = newValue;
|
||||
_time = time;
|
||||
_hasKeyframe = _layerProperty.Keyframes.Any(k => k.Position == time);
|
||||
|
||||
DisplayName = $"Update {_layerProperty.PropertyDescription.Name ?? "property"}";
|
||||
}
|
||||
@@ -58,8 +59,9 @@ public class UpdateLayerProperty<T> : IProfileEditorCommand
|
||||
return;
|
||||
}
|
||||
|
||||
// If the layer had no keyframe yet but keyframes are enabled, a new keyframe will be returned
|
||||
if (!_hasKeyframe && _layerProperty.KeyframesEnabled)
|
||||
// If the layer had no keyframe yet but keyframes are enabled, a new keyframe will be returned. Without a time the
|
||||
// base value is changed instead
|
||||
if (!_hasKeyframe && _time != null && _layerProperty.KeyframesEnabled)
|
||||
{
|
||||
_newKeyframe = _layerProperty.SetCurrentValue(_newValue, _time);
|
||||
DisplayName = $"Add {_layerProperty.PropertyDescription.Name ?? "property"} keyframe";
|
||||
|
||||
Reference in new issue
Block a user