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

@@ -0,0 +1,24 @@
<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:screens="clr-namespace:Artemis.VisualScripting.Nodes.External.Screens"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
x:Class="Artemis.VisualScripting.Nodes.External.Screens.LayerPropertyNodeCustomView"
x:DataType="screens:LayerPropertyNodeCustomViewModel">
<Grid>
<StackPanel Spacing="5" VerticalAlignment="Top" IsVisible="{CompiledBinding !OutsideProfileContext}">
<ComboBox Classes="condensed" Items="{CompiledBinding ProfileElements}" SelectedItem="{CompiledBinding SelectedProfileElement}" />
<ComboBox Classes="condensed" Items="{CompiledBinding LayerProperties}" SelectedItem="{CompiledBinding SelectedLayerProperty}" />
</StackPanel>
<StackPanel IsVisible="{CompiledBinding OutsideProfileContext}" VerticalAlignment="Center">
<TextBlock Classes="BodyStrongTextBlockStyle" TextAlignment="Center">
Node not available
</TextBlock>
<TextBlock Classes="BodyTextBlockStyle" Foreground="{DynamicResource TextFillColorSecondary}" TextAlignment="Center">
This node cannot be used outside profile scripts.
</TextBlock>
</StackPanel>
</Grid>
</UserControl>
@@ -0,0 +1,18 @@
using Avalonia.Markup.Xaml;
using Avalonia.ReactiveUI;
namespace Artemis.VisualScripting.Nodes.External.Screens
{
public partial class LayerPropertyNodeCustomView : ReactiveUserControl<LayerPropertyNodeCustomViewModel>
{
public LayerPropertyNodeCustomView()
{
InitializeComponent();
}
private void InitializeComponent()
{
AvaloniaXamlLoader.Load(this);
}
}
}
@@ -0,0 +1,93 @@
using System.Collections.ObjectModel;
using System.Reactive.Linq;
using Artemis.Core;
using Artemis.UI.Shared.Services.NodeEditor;
using Artemis.UI.Shared.VisualScripting;
using Artemis.VisualScripting.Nodes.External.Commands;
using Avalonia.Controls.Mixins;
using DynamicData;
using ReactiveUI;
namespace Artemis.VisualScripting.Nodes.External.Screens;
public class LayerPropertyNodeCustomViewModel : CustomNodeViewModel
{
private readonly LayerPropertyNode _node;
private readonly INodeEditorService _nodeEditorService;
private bool _outsideProfileContext;
public LayerPropertyNodeCustomViewModel(LayerPropertyNode node, INodeScript script, INodeEditorService nodeEditorService) : base(node, script)
{
_node = node;
_nodeEditorService = nodeEditorService;
this.WhenActivated(d =>
{
if (_node.Script?.Context is not Profile profile)
{
OutsideProfileContext = true;
return;
}
OutsideProfileContext = false;
Observable.FromEventPattern<ProfileElementEventArgs>(x => profile.DescendentAdded += x, x => profile.DescendentAdded -= x).Subscribe(_ => GetProfileElements()).DisposeWith(d);
Observable.FromEventPattern<ProfileElementEventArgs>(x => profile.DescendentRemoved += x, x => profile.DescendentRemoved -= x).Subscribe(_ => GetProfileElements()).DisposeWith(d);
GetProfileElements();
GetLayerProperties();
});
NodeModified += (_, _) => this.RaisePropertyChanged(nameof(SelectedProfileElement));
NodeModified += (_, _) => this.RaisePropertyChanged(nameof(SelectedLayerProperty));
this.WhenAnyValue(vm => vm.SelectedProfileElement).Subscribe(_ => GetLayerProperties());
}
public ObservableCollection<RenderProfileElement> ProfileElements { get; } = new();
public ObservableCollection<ILayerProperty> LayerProperties { get; } = new();
public bool OutsideProfileContext
{
get => _outsideProfileContext;
set => this.RaiseAndSetIfChanged(ref _outsideProfileContext, value);
}
public RenderProfileElement? SelectedProfileElement
{
get => _node.ProfileElement;
set
{
if (value != null && !Equals(_node.ProfileElement, value))
_nodeEditorService.ExecuteCommand(Script, new UpdateLayerPropertyNodeSelectedProfileElement(_node, value));
}
}
public ILayerProperty? SelectedLayerProperty
{
get => _node.LayerProperty;
set
{
if (value != null && !Equals(_node.LayerProperty, value))
_nodeEditorService.ExecuteCommand(Script, new UpdateLayerPropertyNodeSelectedLayerProperty(_node, value));
}
}
private void GetProfileElements()
{
ProfileElements.Clear();
if (_node.Script?.Context is not Profile profile)
return;
List<RenderProfileElement> elements = new(profile.GetAllRenderElements());
ProfileElements.AddRange(elements.OrderBy(e => e.Order));
SelectedProfileElement = _node.ProfileElement;
}
private void GetLayerProperties()
{
LayerProperties.Clear();
if (_node.ProfileElement == null)
return;
LayerProperties.AddRange(_node.ProfileElement.GetAllLayerProperties().Where(l => !l.IsHidden && l.DataBindingsSupported));
SelectedLayerProperty = _node.LayerProperty;
}
}