Browse Source

Change name of properties in combine and separate color node depending on the mode

CPKreuz 11 months ago
parent
commit
755c064dea

+ 13 - 0
src/PixiEditor/Helpers/Extensions/CombineSeparateColorModeExtensions.cs

@@ -0,0 +1,13 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.CombineSeparate;
+
+namespace PixiEditor.Helpers.Extensions;
+
+internal static class CombineSeparateColorModeExtensions
+{
+    public static (string v1, string v2, string v3) GetLocalizedColorStringNames(this CombineSeparateColorMode mode) => mode switch
+    {
+        CombineSeparateColorMode.RGB => ("R", "G", "B"),
+        CombineSeparateColorMode.HSV => ("H", "S", "V"),
+        CombineSeparateColorMode.HSL => ("H", "S", "L"),
+    };
+}

+ 1 - 1
src/PixiEditor/Models/Events/NodePropertyValueChanged.cs

@@ -4,4 +4,4 @@ namespace PixiEditor.Models.Events;
 
 
 public delegate void NodePropertyValueChanged(INodePropertyHandler property, NodePropertyValueChangedArgs args);
 public delegate void NodePropertyValueChanged(INodePropertyHandler property, NodePropertyValueChangedArgs args);
 
 
-public record NodePropertyValueChangedArgs(object OldValue, object NewValue);
+public record NodePropertyValueChangedArgs(object? OldValue, object? NewValue);

+ 5 - 1
src/PixiEditor/ViewModels/Document/Nodes/CombineSeparate/CombineColorNodeViewModel.cs

@@ -1,7 +1,11 @@
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.CombineSeparate;
 using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.CombineSeparate;
+using PixiEditor.Helpers.Extensions;
+using PixiEditor.Models.Events;
+using PixiEditor.Models.Handlers;
 using PixiEditor.ViewModels.Nodes;
 using PixiEditor.ViewModels.Nodes;
+using PixiEditor.ViewModels.Nodes.Properties;
 
 
 namespace PixiEditor.ViewModels.Document.Nodes.CombineSeparate;
 namespace PixiEditor.ViewModels.Document.Nodes.CombineSeparate;
 
 
 [NodeViewModel("COMBINE_COLOR_NODE", "COLOR", "\ue908")]
 [NodeViewModel("COMBINE_COLOR_NODE", "COLOR", "\ue908")]
-internal class CombineColorNodeViewModel : NodeViewModel<CombineColorNode>;
+internal class CombineColorNodeViewModel() : CombineSeparateColorNodeViewModel<CombineColorNode>(true);

+ 53 - 0
src/PixiEditor/ViewModels/Document/Nodes/CombineSeparate/CombineSeparateColorNodeViewModel.cs

@@ -0,0 +1,53 @@
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes.CombineSeparate;
+using PixiEditor.Helpers.Extensions;
+using PixiEditor.Models.Events;
+using PixiEditor.Models.Handlers;
+using PixiEditor.ViewModels.Nodes;
+using PixiEditor.ViewModels.Nodes.Properties;
+
+namespace PixiEditor.ViewModels.Document.Nodes.CombineSeparate;
+
+internal abstract class CombineSeparateColorNodeViewModel<T>(bool isInput) : NodeViewModel<T> where T : Node
+{
+    private GenericEnumPropertyViewModel Mode { get; set; }
+    
+    private NodePropertyViewModel<double> V1 { get; set; }
+
+    private NodePropertyViewModel<double> V2 { get; set; }
+    
+    private NodePropertyViewModel<double> V3 { get; set; }
+
+    public override void OnInitialized()
+    {
+        Mode = FindInputProperty("Mode") as GenericEnumPropertyViewModel;
+        
+        Mode.ValueChanged += OnModeChanged;
+
+        if (isInput)
+        {
+            V1 = FindInputProperty<double>("R");
+            V2 = FindInputProperty<double>("G");
+            V3 = FindInputProperty<double>("B");
+        }
+        else
+        {
+            V1 = FindOutputProperty<double>("R");
+            V2 = FindOutputProperty<double>("G");
+            V3 = FindOutputProperty<double>("B");
+        }
+    }
+
+    private void OnModeChanged(INodePropertyHandler property, NodePropertyValueChangedArgs args)
+    {
+        if (args.NewValue == null) return;
+        
+        var mode = (CombineSeparateColorMode)args.NewValue;
+
+        var (v1, v2, v3) = mode.GetLocalizedColorStringNames();
+
+        V1.DisplayName = v1;
+        V2.DisplayName = v2;
+        V3.DisplayName = v3;
+    }
+}

+ 1 - 1
src/PixiEditor/ViewModels/Document/Nodes/CombineSeparate/SeparateColorNodeViewModel.cs

@@ -4,4 +4,4 @@ using PixiEditor.ViewModels.Nodes;
 namespace PixiEditor.ViewModels.Document.Nodes.CombineSeparate;
 namespace PixiEditor.ViewModels.Document.Nodes.CombineSeparate;
 
 
 [NodeViewModel("SEPARATE_COLOR_NODE", "COLOR", "\ue913")]
 [NodeViewModel("SEPARATE_COLOR_NODE", "COLOR", "\ue913")]
-internal class SeparateColorNodeViewModel : NodeViewModel<SeparateColorNode>;
+internal class SeparateColorNodeViewModel() : CombineSeparateColorNodeViewModel<SeparateColorNode>(false);