mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Nodes - When usting custom VMs, create a VM for each presenter
This commit is contained in:
parent
7422a9667d
commit
ed33d8a148
@ -83,10 +83,7 @@ namespace Artemis.Core.Services
|
||||
// ignored
|
||||
}
|
||||
}
|
||||
|
||||
if (node is CustomViewModelNode customViewModelNode)
|
||||
customViewModelNode.BaseCustomViewModel = _kernel.Get(customViewModelNode.CustomViewModelType, new ConstructorArgument("node", node));
|
||||
|
||||
|
||||
node.Initialize(script);
|
||||
return node;
|
||||
}
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
using System;
|
||||
using Ninject;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using Ninject.Parameters;
|
||||
|
||||
namespace Artemis.Core
|
||||
{
|
||||
@ -149,14 +151,24 @@ namespace Artemis.Core
|
||||
|
||||
public abstract class Node<T> : CustomViewModelNode where T : ICustomNodeViewModel
|
||||
{
|
||||
[Inject]
|
||||
internal IKernel Kernel { get; set; } = null!;
|
||||
|
||||
protected Node()
|
||||
{ }
|
||||
|
||||
protected Node(string name, string description) : base(name, description)
|
||||
{ }
|
||||
|
||||
public override Type CustomViewModelType => typeof(T);
|
||||
public T CustomViewModel => (T) BaseCustomViewModel!;
|
||||
public virtual T GetViewModel()
|
||||
{
|
||||
return Kernel.Get<T>(new ConstructorArgument("node", this));
|
||||
}
|
||||
|
||||
public override ICustomNodeViewModel GetCustomViewModel()
|
||||
{
|
||||
return GetViewModel();
|
||||
}
|
||||
}
|
||||
|
||||
public abstract class CustomViewModelNode : Node
|
||||
@ -169,7 +181,6 @@ namespace Artemis.Core
|
||||
protected CustomViewModelNode(string name, string description) : base(name, description)
|
||||
{ }
|
||||
|
||||
public abstract Type CustomViewModelType { get; }
|
||||
public object? BaseCustomViewModel { get; set; }
|
||||
public abstract ICustomNodeViewModel GetCustomViewModel();
|
||||
}
|
||||
}
|
||||
@ -3,6 +3,7 @@ using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using Artemis.Core;
|
||||
using Artemis.VisualScripting.Editor.Controls.Wrapper;
|
||||
|
||||
namespace Artemis.VisualScripting.Editor.Controls
|
||||
@ -21,20 +22,29 @@ namespace Artemis.VisualScripting.Editor.Controls
|
||||
#region Dependency Properties
|
||||
|
||||
public static readonly DependencyProperty NodeProperty = DependencyProperty.Register(
|
||||
"Node", typeof(VisualScriptNode), typeof(VisualScriptNodePresenter), new PropertyMetadata(default(VisualScriptNode)));
|
||||
"Node", typeof(VisualScriptNode), typeof(VisualScriptNodePresenter), new PropertyMetadata(default(VisualScriptNode), NodePropertyChangedCallback));
|
||||
|
||||
public VisualScriptNode Node
|
||||
{
|
||||
get => (VisualScriptNode)GetValue(NodeProperty);
|
||||
get => (VisualScriptNode) GetValue(NodeProperty);
|
||||
set => SetValue(NodeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CustomViewModelProperty = DependencyProperty.Register(
|
||||
"CustomViewModel", typeof(ICustomNodeViewModel), typeof(VisualScriptNodePresenter), new PropertyMetadata(null));
|
||||
|
||||
public ICustomNodeViewModel CustomViewModel
|
||||
{
|
||||
get => (ICustomNodeViewModel) GetValue(CustomViewModelProperty);
|
||||
set => SetValue(CustomViewModelProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TitleBrushProperty = DependencyProperty.Register(
|
||||
"TitleBrush", typeof(Brush), typeof(VisualScriptNodePresenter), new PropertyMetadata(default(Brush)));
|
||||
|
||||
public Brush TitleBrush
|
||||
{
|
||||
get => (Brush)GetValue(TitleBrushProperty);
|
||||
get => (Brush) GetValue(TitleBrushProperty);
|
||||
set => SetValue(TitleBrushProperty, value);
|
||||
}
|
||||
|
||||
@ -56,8 +66,8 @@ namespace Artemis.VisualScripting.Editor.Controls
|
||||
}
|
||||
|
||||
Size neededSize = base.MeasureOverride(constraint);
|
||||
int width = (int)Math.Ceiling(neededSize.Width);
|
||||
int height = (int)Math.Ceiling(neededSize.Height);
|
||||
int width = (int) Math.Ceiling(neededSize.Width);
|
||||
int height = (int) Math.Ceiling(neededSize.Height);
|
||||
|
||||
return new Size(SnapToGridSize(width), SnapToGridSize(height));
|
||||
}
|
||||
@ -132,6 +142,20 @@ namespace Artemis.VisualScripting.Editor.Controls
|
||||
args.Handled = true;
|
||||
}
|
||||
|
||||
private void GetCustomViewModel()
|
||||
{
|
||||
if (Node?.Node is CustomViewModelNode customViewModelNode)
|
||||
CustomViewModel = customViewModelNode.GetCustomViewModel();
|
||||
else
|
||||
CustomViewModel = null;
|
||||
}
|
||||
|
||||
private static void NodePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is VisualScriptNodePresenter presenter)
|
||||
presenter.GetCustomViewModel();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -208,17 +208,7 @@
|
||||
</Border>
|
||||
|
||||
<Border x:Name="BrdCustomView" Grid.Column="1">
|
||||
<Border.Resources>
|
||||
<DataTemplate DataType="{x:Type core:CustomViewModelNode}">
|
||||
<ContentControl s:View.Model="{Binding BaseCustomViewModel}"/>
|
||||
</DataTemplate>
|
||||
|
||||
<DataTemplate DataType="{x:Type core:Node}">
|
||||
<Border />
|
||||
</DataTemplate>
|
||||
</Border.Resources>
|
||||
|
||||
<ContentControl Content="{Binding Node}" />
|
||||
<ContentControl s:View.Model="{TemplateBinding CustomViewModel}"/>
|
||||
</Border>
|
||||
|
||||
<Border x:Name="BrdOutputPins" Grid.Column="2">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user