mirror of
https://github.com/Artemis-RGB/Artemis
synced 2025-12-13 05:48:35 +00:00
Nodes - Properly implemented custom VMs
This commit is contained in:
parent
7eadc58bee
commit
61d7f1e1fb
@ -386,7 +386,7 @@ namespace Artemis.Core
|
||||
|
||||
if (Timeline.EventOverlapMode != TimeLineEventOverlapMode.Toggle)
|
||||
_toggledOnByEvent = false;
|
||||
|
||||
|
||||
DisplayCondition.Run();
|
||||
bool conditionMet = DisplayCondition.Result;
|
||||
if (Parent is RenderProfileElement parent && !parent.DisplayConditionMet)
|
||||
|
||||
@ -51,8 +51,8 @@ namespace Artemis.Core.Services
|
||||
private INode CreateNode(Type nodeType)
|
||||
{
|
||||
INode node = _kernel.Get(nodeType) as INode ?? throw new InvalidOperationException($"Node {nodeType} is not an INode");
|
||||
if (node.CustomViewModelType != null)
|
||||
node.CustomViewModel = _kernel.Get(node.CustomViewModelType);
|
||||
if (node is CustomViewModelNode customViewModelNode)
|
||||
customViewModelNode.BaseCustomViewModel = _kernel.Get(customViewModelNode.CustomViewModelType);
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@ -16,9 +16,6 @@ namespace Artemis.Core
|
||||
public IReadOnlyCollection<IPin> Pins { get; }
|
||||
public IReadOnlyCollection<IPinCollection> PinCollections { get; }
|
||||
|
||||
public Type? CustomViewModelType { get; }
|
||||
public object? CustomViewModel { get; set; }
|
||||
|
||||
event EventHandler Resetting;
|
||||
|
||||
void Evaluate();
|
||||
|
||||
@ -6,6 +6,8 @@ namespace Artemis.Core
|
||||
{
|
||||
public abstract class Node : CorePropertyChanged, INode
|
||||
{
|
||||
public event EventHandler Resetting;
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
private string _name;
|
||||
@ -48,15 +50,6 @@ namespace Artemis.Core
|
||||
private readonly List<IPinCollection> _pinCollections = new();
|
||||
public IReadOnlyCollection<IPinCollection> PinCollections => new ReadOnlyCollection<IPinCollection>(_pinCollections);
|
||||
|
||||
public Type? CustomViewModelType { get; private set; }
|
||||
public object? CustomViewModel { get; set; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
|
||||
public event EventHandler Resetting;
|
||||
|
||||
#endregion
|
||||
|
||||
#region Construtors
|
||||
@ -67,8 +60,8 @@ namespace Artemis.Core
|
||||
|
||||
protected Node(string name, string description)
|
||||
{
|
||||
this.Name = name;
|
||||
this.Description = description;
|
||||
Name = name;
|
||||
Description = description;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -135,11 +128,6 @@ namespace Artemis.Core
|
||||
return pin;
|
||||
}
|
||||
|
||||
protected void RegisterCustomViewModel<T>()
|
||||
{
|
||||
CustomViewModelType = typeof(T);
|
||||
}
|
||||
|
||||
public abstract void Evaluate();
|
||||
|
||||
public virtual void Reset()
|
||||
@ -149,4 +137,34 @@ namespace Artemis.Core
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
public abstract class Node<T> : CustomViewModelNode
|
||||
{
|
||||
protected Node()
|
||||
{
|
||||
}
|
||||
|
||||
protected Node(string name, string description) : base(name, description)
|
||||
{
|
||||
}
|
||||
|
||||
public override Type CustomViewModelType => typeof(T);
|
||||
public T? CustomViewModel => (T?) BaseCustomViewModel;
|
||||
}
|
||||
|
||||
public abstract class CustomViewModelNode : Node
|
||||
{
|
||||
/// <inheritdoc />
|
||||
protected CustomViewModelNode()
|
||||
{
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
protected CustomViewModelNode(string name, string description) : base(name, description)
|
||||
{
|
||||
}
|
||||
|
||||
public abstract Type CustomViewModelType { get; }
|
||||
public object? BaseCustomViewModel { get; set; }
|
||||
}
|
||||
}
|
||||
@ -41,7 +41,7 @@
|
||||
<Separator Grid.Row="1" Grid.Column="0" Style="{StaticResource MaterialDesignDarkSeparator}" Margin="-2 0" />
|
||||
|
||||
<Grid Grid.Row="2" Grid.Column="0">
|
||||
<controls:VisualScriptEditor Script="{Binding Script}" AvailableNodes="{Binding AvailableNodes}" />
|
||||
<controls:VisualScriptEditor Script="{Binding RenderProfileElement.DisplayCondition}" AvailableNodes="{Binding AvailableNodes}" />
|
||||
|
||||
<!--<ScrollViewer HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Background="{StaticResource MaterialDesignCardBackground}">
|
||||
<ContentControl s:View.Model="{Binding ActiveItem}" />
|
||||
|
||||
@ -27,15 +27,6 @@ namespace Artemis.UI.Screens.ProfileEditor.DisplayConditions
|
||||
_dataModelConditionsVmFactory = dataModelConditionsVmFactory;
|
||||
|
||||
AvailableNodes = _nodeService.AvailableNodes;
|
||||
Script = new NodeScript<bool>("Display Condition (TODO)", "TODO");
|
||||
}
|
||||
|
||||
|
||||
private NodeScript<bool> _script;
|
||||
public NodeScript<bool> Script
|
||||
{
|
||||
get => _script;
|
||||
private set => SetAndNotify(ref _script, value);
|
||||
}
|
||||
|
||||
private IEnumerable<NodeData> _availableNodes;
|
||||
|
||||
@ -207,6 +207,7 @@
|
||||
</StackPanel>
|
||||
</Border>
|
||||
|
||||
<!-- TODO: Figure out how to only use this for CustomViewModelNode -->
|
||||
<Border x:Name="BrdCustomView" Grid.Column="1">
|
||||
<ContentControl s:View.Model="{Binding Node.CustomViewModel}"/>
|
||||
</Border>
|
||||
|
||||
@ -4,12 +4,10 @@ using Artemis.VisualScripting.Nodes.CustomViewModels;
|
||||
namespace Artemis.VisualScripting.Nodes
|
||||
{
|
||||
[Node("Integer-Value", "Outputs an configurable integer value.")]
|
||||
public class StaticIntegerValueNode : Node
|
||||
public class StaticIntegerValueNode : Node<StaticIntegerValueNodeCustomViewModel>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private StaticIntegerValueNodeCustomViewModel _customViewModel = new();
|
||||
|
||||
public OutputPin<int> Output { get; }
|
||||
|
||||
#endregion
|
||||
@ -20,7 +18,6 @@ namespace Artemis.VisualScripting.Nodes
|
||||
: base("Integer", "Outputs an configurable integer value.")
|
||||
{
|
||||
Output = CreateOutputPin<int>();
|
||||
RegisterCustomViewModel<StaticIntegerValueNodeCustomViewModel>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -29,19 +26,17 @@ namespace Artemis.VisualScripting.Nodes
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
Output.Value = _customViewModel.Input;
|
||||
Output.Value = CustomViewModel.Input;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Node("Double-Value", "Outputs a configurable double value.")]
|
||||
public class StaticDoubleValueNode : Node
|
||||
public class StaticDoubleValueNode : Node<StaticDoubleValueNodeCustomViewModel>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private StaticDoubleValueNodeCustomViewModel _customViewModel = new();
|
||||
|
||||
public OutputPin<double> Output { get; }
|
||||
|
||||
#endregion
|
||||
@ -52,7 +47,6 @@ namespace Artemis.VisualScripting.Nodes
|
||||
: base("Double", "Outputs a configurable double value.")
|
||||
{
|
||||
Output = CreateOutputPin<double>();
|
||||
RegisterCustomViewModel<StaticDoubleValueNodeCustomViewModel>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -61,19 +55,17 @@ namespace Artemis.VisualScripting.Nodes
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
Output.Value = _customViewModel.Input;
|
||||
Output.Value = CustomViewModel.Input;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
[Node("String-Value", "Outputs a configurable string value.")]
|
||||
public class StaticStringValueNode : Node
|
||||
public class StaticStringValueNode : Node<StaticStringValueNodeCustomViewModel>
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private StaticStringValueNodeCustomViewModel _customViewModel = new();
|
||||
|
||||
public OutputPin<string> Output { get; }
|
||||
|
||||
#endregion
|
||||
@ -84,7 +76,6 @@ namespace Artemis.VisualScripting.Nodes
|
||||
: base("String", "Outputs a configurable string value.")
|
||||
{
|
||||
Output = CreateOutputPin<string>();
|
||||
RegisterCustomViewModel<StaticStringValueNodeCustomViewModel>();
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -93,7 +84,7 @@ namespace Artemis.VisualScripting.Nodes
|
||||
|
||||
public override void Evaluate()
|
||||
{
|
||||
Output.Value = _customViewModel.Input;
|
||||
Output.Value = CustomViewModel.Input;
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -101,7 +92,5 @@ namespace Artemis.VisualScripting.Nodes
|
||||
|
||||
#region CustomViewModels
|
||||
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user