Browse Source

Fixed undo proeprty changes

Krzysztof Krysiński 3 days ago
parent
commit
2f4144535f

+ 9 - 2
src/PixiEditor.ChangeableDocument/Changes/NodeGraph/UpdateProperty_Change.cs

@@ -1,4 +1,5 @@
-using PixiEditor.ChangeableDocument.Changeables.Graph;
+using Drawie.Backend.Core.Shaders.Generation;
+using PixiEditor.ChangeableDocument.Changeables.Graph;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
 using PixiEditor.ChangeableDocument.ChangeInfos.NodeGraph;
 
@@ -39,6 +40,11 @@ internal class UpdatePropertyValue_Change : Change
         int outputsHash = CalculateOutputsHash(node);
 
         previousValue = GetValue(property);
+        if (previousValue is ShaderExpressionVariable expr)
+        {
+            previousValue = expr.GetConstant();
+        }
+
         string errors = string.Empty;
         if (!property.Validator.Validate(_value, out errors))
         {
@@ -165,6 +171,7 @@ internal class UpdatePropertyValue_Change : Change
 
     public override bool IsMergeableWith(Change other)
     {
-        return other is UpdatePropertyValue_Change change && change._nodeId == _nodeId && change._propertyName == _propertyName;
+        return other is UpdatePropertyValue_Change change && change._nodeId == _nodeId &&
+               change._propertyName == _propertyName;
     }
 }

+ 4 - 2
src/PixiEditor/Models/DocumentModels/DocumentUpdater.cs

@@ -835,8 +835,10 @@ internal class DocumentUpdater
         property.Errors = info.Errors;
 
         ProcessStructureMemberProperty(info, property);
-
-        property.InternalSetValue(info.Value);
+        var toSet = property.IsFunc
+            ? (info.Value as ShaderExpressionVariable)?.GetConstant() ?? info.Value
+            : info.Value;
+        property.InternalSetValue(toSet);
 
         if (info.Property == CustomOutputNode.OutputNamePropertyName)
         {

+ 12 - 1
src/PixiEditor/ViewModels/Nodes/Properties/SinglePropertyViewModel.cs

@@ -23,7 +23,13 @@ internal class SinglePropertyViewModel : NodePropertyViewModel<float>
     public double DoubleValue
     {
         get => Value;
-        set => Value = (float)value;
+        set
+        {
+            if (updateBlocker)
+                return;
+
+            Value = (float)value;
+        }
     }
 
     public double Min
@@ -44,6 +50,8 @@ internal class SinglePropertyViewModel : NodePropertyViewModel<float>
         set => SetProperty(ref sliderSettings, value);
     }
 
+    private bool updateBlocker = false;
+
     public SinglePropertyViewModel(NodeViewModel node, Type valueType) : base(node, valueType)
     {
     }
@@ -51,9 +59,12 @@ internal class SinglePropertyViewModel : NodePropertyViewModel<float>
     protected override void OnPropertyChanged(PropertyChangedEventArgs e)
     {
         base.OnPropertyChanged(e);
+
+        updateBlocker = true;
         if (e.PropertyName == nameof(Value))
         {
             OnPropertyChanged(nameof(DoubleValue));
         }
+        updateBlocker = false;
     }
 }