Nodes - Reorganized code

This commit is contained in:
Robert committed 2022-03-30 20:10:43 +02:00
1 parent 69b881b044
commit 7c83d5345f
73 files changed
+1055 -738

No files matched your search

@@ -1,51 +0,0 @@
using Artemis.Core;
using Artemis.UI.Shared.Services.NodeEditor;
using Artemis.UI.Shared.Services.NodeEditor.Commands;
using Artemis.UI.Shared.VisualScripting;
using ReactiveUI;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color.CustomViewModels;
public class StaticSKColorValueNodeCustomViewModel : CustomNodeViewModel
{
private readonly StaticSKColorValueNode _node;
private readonly INodeEditorService _nodeEditorService;
private bool _applyChanges;
private SKColor? _currentValue;
public StaticSKColorValueNodeCustomViewModel(StaticSKColorValueNode node, INodeScript script, INodeEditorService nodeEditorService) : base(node, script)
{
_node = node;
_nodeEditorService = nodeEditorService;
_applyChanges = true;
NodeModified += (_, _) => CurrentValue = _node.Storage;
CurrentValue = _node.Storage;
}
public SKColor? CurrentValue
{
get => _currentValue;
set
{
if (_applyChanges && value != _node.Storage)
_nodeEditorService.ExecuteCommand(Script, new UpdateStorage<SKColor>(_node, value ?? SKColor.Empty));
this.RaiseAndSetIfChanged(ref _currentValue, value);
}
}
public void PauseUpdating()
{
_applyChanges = false;
}
public void ResumeUpdating()
{
_applyChanges = true;
SKColor updatedValue = CurrentValue ?? SKColor.Empty;
if (updatedValue != _node.Storage)
_nodeEditorService.ExecuteCommand(Script, new UpdateStorage<SKColor>(_node, updatedValue));
}
}
@@ -1,30 +0,0 @@
<UserControl xmlns="https://github.com/avaloniaui"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:converters="clr-namespace:Artemis.UI.Shared.Converters;assembly=Artemis.UI.Shared"
xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia"
xmlns:customViewModels="clr-namespace:Artemis.VisualScripting.Nodes.Color.CustomViewModels"
xmlns:behaviors="clr-namespace:Artemis.UI.Shared.Behaviors;assembly=Artemis.UI.Shared"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.VisualScripting.Nodes.Color.CustomViews.StaticSKColorValueNodeCustomView"
x:DataType="customViewModels:StaticSKColorValueNodeCustomViewModel">
<UserControl.Resources>
<converters:SKColorToStringConverter x:Key="SKColorToStringConverter" />
<converters:SKColorToColor2Converter x:Key="SKColorToColor2Converter" />
</UserControl.Resources>
<Grid Height="24" ColumnDefinitions="*" Width="110">
<TextBox Classes="condensed"
Watermark="#00000000"
Padding="2 2 30 2">
<Interaction.Behaviors>
<behaviors:LostFocusTextBoxBindingBehavior Text="{CompiledBinding CurrentValue, Converter={StaticResource SKColorToStringConverter}}"/>
</Interaction.Behaviors>
</TextBox>
<controls:ColorPickerButton Classes="contained-color-picker-button"
Color="{CompiledBinding CurrentValue, Converter={StaticResource SKColorToColor2Converter}}"
ShowAcceptDismissButtons="False"
FlyoutOpened="ColorPickerButton_OnFlyoutOpened"
FlyoutClosed="ColorPickerButton_OnFlyoutClosed" />
</Grid>
</UserControl>
@@ -1,29 +0,0 @@
using Artemis.VisualScripting.Nodes.Color.CustomViewModels;
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
using FluentAvalonia.UI.Controls;
namespace Artemis.VisualScripting.Nodes.Color.CustomViews;
public class StaticSKColorValueNodeCustomView : ReactiveUserControl<StaticSKColorValueNodeCustomViewModel>
{
public StaticSKColorValueNodeCustomView()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
private void ColorPickerButton_OnFlyoutOpened(ColorPickerButton sender, EventArgs args)
{
ViewModel?.PauseUpdating();
}
private void ColorPickerButton_OnFlyoutClosed(ColorPickerButton sender, EventArgs args)
{
ViewModel?.ResumeUpdating();
}
}
@@ -1,35 +0,0 @@
using Artemis.Core;
using Artemis.VisualScripting.Nodes.Color.CustomViewModels;
using SkiaSharp;
namespace Artemis.VisualScripting.Nodes.Color;
[Node("Color-Value", "Outputs a configurable color value.", "Static", InputType = typeof(SKColor), OutputType = typeof(SKColor))]
public class StaticSKColorValueNode : Node<SKColor, StaticSKColorValueNodeCustomViewModel>
{
#region Constructors
public StaticSKColorValueNode()
: base("Color", "Outputs a configurable color value.")
{
Output = CreateOutputPin<SKColor>();
Storage = new SKColor(255, 0, 0);
}
#endregion
#region Properties & Fields
public OutputPin<SKColor> Output { get; }
#endregion
#region Methods
public override void Evaluate()
{
Output.Value = Storage;
}
#endregion
}