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
@ -84,9 +84,6 @@ namespace Artemis.Core.Services
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node is CustomViewModelNode customViewModelNode)
|
|
||||||
customViewModelNode.BaseCustomViewModel = _kernel.Get(customViewModelNode.CustomViewModelType, new ConstructorArgument("node", node));
|
|
||||||
|
|
||||||
node.Initialize(script);
|
node.Initialize(script);
|
||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
using System;
|
using Ninject;
|
||||||
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Collections.ObjectModel;
|
using System.Collections.ObjectModel;
|
||||||
|
using Ninject.Parameters;
|
||||||
|
|
||||||
namespace Artemis.Core
|
namespace Artemis.Core
|
||||||
{
|
{
|
||||||
@ -149,14 +151,24 @@ namespace Artemis.Core
|
|||||||
|
|
||||||
public abstract class Node<T> : CustomViewModelNode where T : ICustomNodeViewModel
|
public abstract class Node<T> : CustomViewModelNode where T : ICustomNodeViewModel
|
||||||
{
|
{
|
||||||
|
[Inject]
|
||||||
|
internal IKernel Kernel { get; set; } = null!;
|
||||||
|
|
||||||
protected Node()
|
protected Node()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
protected Node(string name, string description) : base(name, description)
|
protected Node(string name, string description) : base(name, description)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public override Type CustomViewModelType => typeof(T);
|
public virtual T GetViewModel()
|
||||||
public T CustomViewModel => (T) BaseCustomViewModel!;
|
{
|
||||||
|
return Kernel.Get<T>(new ConstructorArgument("node", this));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ICustomNodeViewModel GetCustomViewModel()
|
||||||
|
{
|
||||||
|
return GetViewModel();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class CustomViewModelNode : Node
|
public abstract class CustomViewModelNode : Node
|
||||||
@ -169,7 +181,6 @@ namespace Artemis.Core
|
|||||||
protected CustomViewModelNode(string name, string description) : base(name, description)
|
protected CustomViewModelNode(string name, string description) : base(name, description)
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
public abstract Type CustomViewModelType { get; }
|
public abstract ICustomNodeViewModel GetCustomViewModel();
|
||||||
public object? BaseCustomViewModel { get; set; }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3,6 +3,7 @@ using System.Windows;
|
|||||||
using System.Windows.Controls;
|
using System.Windows.Controls;
|
||||||
using System.Windows.Input;
|
using System.Windows.Input;
|
||||||
using System.Windows.Media;
|
using System.Windows.Media;
|
||||||
|
using Artemis.Core;
|
||||||
using Artemis.VisualScripting.Editor.Controls.Wrapper;
|
using Artemis.VisualScripting.Editor.Controls.Wrapper;
|
||||||
|
|
||||||
namespace Artemis.VisualScripting.Editor.Controls
|
namespace Artemis.VisualScripting.Editor.Controls
|
||||||
@ -21,20 +22,29 @@ namespace Artemis.VisualScripting.Editor.Controls
|
|||||||
#region Dependency Properties
|
#region Dependency Properties
|
||||||
|
|
||||||
public static readonly DependencyProperty NodeProperty = DependencyProperty.Register(
|
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
|
public VisualScriptNode Node
|
||||||
{
|
{
|
||||||
get => (VisualScriptNode)GetValue(NodeProperty);
|
get => (VisualScriptNode) GetValue(NodeProperty);
|
||||||
set => SetValue(NodeProperty, value);
|
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(
|
public static readonly DependencyProperty TitleBrushProperty = DependencyProperty.Register(
|
||||||
"TitleBrush", typeof(Brush), typeof(VisualScriptNodePresenter), new PropertyMetadata(default(Brush)));
|
"TitleBrush", typeof(Brush), typeof(VisualScriptNodePresenter), new PropertyMetadata(default(Brush)));
|
||||||
|
|
||||||
public Brush TitleBrush
|
public Brush TitleBrush
|
||||||
{
|
{
|
||||||
get => (Brush)GetValue(TitleBrushProperty);
|
get => (Brush) GetValue(TitleBrushProperty);
|
||||||
set => SetValue(TitleBrushProperty, value);
|
set => SetValue(TitleBrushProperty, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,8 +66,8 @@ namespace Artemis.VisualScripting.Editor.Controls
|
|||||||
}
|
}
|
||||||
|
|
||||||
Size neededSize = base.MeasureOverride(constraint);
|
Size neededSize = base.MeasureOverride(constraint);
|
||||||
int width = (int)Math.Ceiling(neededSize.Width);
|
int width = (int) Math.Ceiling(neededSize.Width);
|
||||||
int height = (int)Math.Ceiling(neededSize.Height);
|
int height = (int) Math.Ceiling(neededSize.Height);
|
||||||
|
|
||||||
return new Size(SnapToGridSize(width), SnapToGridSize(height));
|
return new Size(SnapToGridSize(width), SnapToGridSize(height));
|
||||||
}
|
}
|
||||||
@ -132,6 +142,20 @@ namespace Artemis.VisualScripting.Editor.Controls
|
|||||||
args.Handled = true;
|
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
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -208,17 +208,7 @@
|
|||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<Border x:Name="BrdCustomView" Grid.Column="1">
|
<Border x:Name="BrdCustomView" Grid.Column="1">
|
||||||
<Border.Resources>
|
<ContentControl s:View.Model="{TemplateBinding CustomViewModel}"/>
|
||||||
<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}" />
|
|
||||||
</Border>
|
</Border>
|
||||||
|
|
||||||
<Border x:Name="BrdOutputPins" Grid.Column="2">
|
<Border x:Name="BrdOutputPins" Grid.Column="2">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user