mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-12 11:56:30 +00:00
Nodes - Added enum equality node
Conditions - Implemented event trigger conditions
This commit is contained in:
1 parent
00125d1478
commit
d6372dffad
16 files changed
+321
-93
No files matched your search
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.UI.Shared;
|
||||
using Stylet;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.CustomViewModels
|
||||
{
|
||||
public class EnumEqualsNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
private readonly EnumEqualsNode _node;
|
||||
|
||||
public EnumEqualsNodeCustomViewModel(EnumEqualsNode node) : base(node)
|
||||
{
|
||||
_node = node;
|
||||
}
|
||||
|
||||
public Enum Input
|
||||
{
|
||||
get => _node.Storage as Enum;
|
||||
set => _node.Storage = value;
|
||||
}
|
||||
|
||||
public BindableCollection<ValueDescription> EnumValues { get; } = new();
|
||||
|
||||
public override void OnActivate()
|
||||
{
|
||||
_node.InputPin.PinConnected += InputPinOnPinConnected;
|
||||
_node.InputPin.PinDisconnected += InputPinOnPinDisconnected;
|
||||
_node.PropertyChanged += NodeOnPropertyChanged;
|
||||
|
||||
if (_node.InputPin.Value != null && _node.InputPin.Value.GetType().IsEnum)
|
||||
EnumValues.AddRange(EnumUtilities.GetAllValuesAndDescriptions(_node.InputPin.Value.GetType()));
|
||||
base.OnActivate();
|
||||
}
|
||||
|
||||
public override void OnDeactivate()
|
||||
{
|
||||
_node.InputPin.PinConnected -= InputPinOnPinConnected;
|
||||
_node.InputPin.PinDisconnected -= InputPinOnPinDisconnected;
|
||||
_node.PropertyChanged -= NodeOnPropertyChanged;
|
||||
|
||||
base.OnDeactivate();
|
||||
}
|
||||
|
||||
private void InputPinOnPinDisconnected(object sender, SingleValueEventArgs<IPin> e)
|
||||
{
|
||||
EnumValues.Clear();
|
||||
}
|
||||
|
||||
private void InputPinOnPinConnected(object sender, SingleValueEventArgs<IPin> e)
|
||||
{
|
||||
EnumValues.Clear();
|
||||
if (_node.InputPin.Value != null && _node.InputPin.Value.GetType().IsEnum)
|
||||
EnumValues.AddRange(EnumUtilities.GetAllValuesAndDescriptions(_node.InputPin.Value.GetType()));
|
||||
}
|
||||
|
||||
private void NodeOnPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(Node.Storage))
|
||||
OnPropertyChanged(nameof(Input));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
<UserControl x:Class="Artemis.VisualScripting.Nodes.CustomViews.EnumEqualsNodeCustomView"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="clr-namespace:Artemis.VisualScripting.Nodes.CustomViews"
|
||||
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
|
||||
mc:Ignorable="d"
|
||||
d:DesignHeight="450" d:DesignWidth="800">
|
||||
<Grid>
|
||||
<ComboBox Width="140"
|
||||
materialDesign:ComboBoxAssist.ClassicMode="True"
|
||||
VerticalAlignment="Center"
|
||||
HorizontalAlignment="Stretch"
|
||||
SelectedValue="{Binding Input}"
|
||||
ItemsSource="{Binding EnumValues}"
|
||||
SelectedValuePath="Value"
|
||||
DisplayMemberPath="Description">
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
</ComboBox>
|
||||
</Grid>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,30 @@
|
||||
using System;
|
||||
using Artemis.Core;
|
||||
using Artemis.Core.Events;
|
||||
using Artemis.VisualScripting.Nodes.CustomViewModels;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes
|
||||
{
|
||||
[Node("Enum Equals", "Determines the equality between an input and a selected enum value", InputType = typeof(Enum), OutputType = typeof(bool))]
|
||||
public class EnumEqualsNode : Node<EnumEqualsNodeCustomViewModel>
|
||||
{
|
||||
public EnumEqualsNode() : base("Enum Equals", "Determines the equality between an input and a selected enum value")
|
||||
{
|
||||
InputPin = CreateInputPin<Enum>();
|
||||
OutputPin = CreateOutputPin<bool>();
|
||||
}
|
||||
|
||||
public InputPin<Enum> InputPin { get; }
|
||||
public OutputPin<bool> OutputPin { get; }
|
||||
|
||||
#region Overrides of Node
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Evaluate()
|
||||
{
|
||||
OutputPin.Value = InputPin.Value != null && InputPin.Value.Equals(Storage);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user