mirror of
https://github.com/Artemis-RGB/Artemis
synced 2026-11-11 19:36:28 +00:00
Visual Scripting - Fixed storage issues where connections would be lost
Visual Scripting - Added node duplication
This commit is contained in:
1 parent
c325a29cc0
commit
041ed8e0a0
11 files changed
+256
-60
No files matched your search
@@ -4,7 +4,7 @@ using Artemis.VisualScripting.Nodes.Operators.Screens;
|
||||
namespace Artemis.VisualScripting.Nodes.Operators;
|
||||
|
||||
[Node("Enum Equals", "Determines the equality between an input and a selected enum value", "Operators", InputType = typeof(Enum), OutputType = typeof(bool))]
|
||||
public class EnumEqualsNode : Node<int, EnumEqualsNodeCustomViewModel>
|
||||
public class EnumEqualsNode : Node<long, EnumEqualsNodeCustomViewModel>
|
||||
{
|
||||
public EnumEqualsNode() : base("Enum Equals", "Determines the equality between an input and a selected enum value")
|
||||
{
|
||||
@@ -21,6 +21,6 @@ public class EnumEqualsNode : Node<int, EnumEqualsNodeCustomViewModel>
|
||||
if (InputPin.Value == null)
|
||||
OutputPin.Value = false;
|
||||
else
|
||||
OutputPin.Value = Convert.ToInt32(InputPin.Value) == Storage;
|
||||
OutputPin.Value = Convert.ToInt64(InputPin.Value) == Storage;
|
||||
}
|
||||
}
|
||||
@@ -8,8 +8,20 @@
|
||||
x:DataType="screens:EnumEqualsNodeCustomViewModel">
|
||||
<ComboBox IsEnabled="{CompiledBinding EnumValues.Count}"
|
||||
Items="{CompiledBinding EnumValues}"
|
||||
SelectedIndex="{CompiledBinding CurrentValue}"
|
||||
SelectedItem="{CompiledBinding CurrentValue}"
|
||||
VirtualizationMode="Simple"
|
||||
PlaceholderText="Select a value"
|
||||
Classes="condensed"
|
||||
VerticalAlignment="Center" />
|
||||
VerticalAlignment="Center">
|
||||
<ComboBox.ItemsPanel>
|
||||
<ItemsPanelTemplate>
|
||||
<VirtualizingStackPanel />
|
||||
</ItemsPanelTemplate>
|
||||
</ComboBox.ItemsPanel>
|
||||
<ComboBox.ItemTemplate>
|
||||
<DataTemplate>
|
||||
<TextBlock Text="{Binding [1]}" />
|
||||
</DataTemplate>
|
||||
</ComboBox.ItemTemplate>
|
||||
</ComboBox>
|
||||
</UserControl>
|
||||
+25
-10
@@ -6,7 +6,10 @@ using Artemis.UI.Shared.Services.NodeEditor;
|
||||
using Artemis.UI.Shared.Services.NodeEditor.Commands;
|
||||
using Artemis.UI.Shared.VisualScripting;
|
||||
using Avalonia.Controls.Mixins;
|
||||
using Avalonia.Threading;
|
||||
using DynamicData;
|
||||
using FluentAvalonia.Core;
|
||||
using Humanizer;
|
||||
using ReactiveUI;
|
||||
|
||||
namespace Artemis.VisualScripting.Nodes.Operators.Screens;
|
||||
@@ -28,13 +31,11 @@ public class EnumEqualsNodeCustomViewModel : CustomNodeViewModel
|
||||
{
|
||||
EnumValues.Clear();
|
||||
if (_node.InputPin.ConnectedTo.First().Type.IsEnum)
|
||||
EnumValues.AddRange(Enum.GetValues(_node.InputPin.ConnectedTo.First().Type).Cast<Enum>());
|
||||
|
||||
this.RaisePropertyChanged(nameof(CurrentValue));
|
||||
AddEnumValues(_node.InputPin.ConnectedTo.First().Type);
|
||||
}
|
||||
|
||||
Observable.FromEventPattern<SingleValueEventArgs<IPin>>(x => _node.InputPin.PinConnected += x, x => _node.InputPin.PinConnected -= x)
|
||||
.Subscribe(p => EnumValues.AddRange(Enum.GetValues(p.EventArgs.Value.Type).Cast<Enum>()))
|
||||
.Subscribe(p => AddEnumValues(p.EventArgs.Value.Type))
|
||||
.DisposeWith(d);
|
||||
Observable.FromEventPattern<SingleValueEventArgs<IPin>>(x => _node.InputPin.PinDisconnected += x, x => _node.InputPin.PinDisconnected -= x)
|
||||
.Subscribe(_ => EnumValues.Clear())
|
||||
@@ -42,15 +43,29 @@ public class EnumEqualsNodeCustomViewModel : CustomNodeViewModel
|
||||
});
|
||||
}
|
||||
|
||||
public ObservableCollection<Enum> EnumValues { get; } = new();
|
||||
|
||||
public int CurrentValue
|
||||
private void AddEnumValues(Type type)
|
||||
{
|
||||
get => _node.Storage;
|
||||
Dispatcher.UIThread.Post(() =>
|
||||
{
|
||||
List<(long, string)> values = Enum.GetValues(type).Cast<Enum>().Select(e => (Convert.ToInt64(e), e.Humanize())).ToList();
|
||||
if (values.Count > 20)
|
||||
EnumValues.AddRange(values.OrderBy(v => v.Item2));
|
||||
else
|
||||
EnumValues.AddRange(Enum.GetValues(type).Cast<Enum>().Select(e => (Convert.ToInt64(e), e.Humanize())));
|
||||
|
||||
this.RaisePropertyChanged(nameof(CurrentValue));
|
||||
}, DispatcherPriority.Background);
|
||||
}
|
||||
|
||||
public ObservableCollection<(long, string)> EnumValues { get; } = new();
|
||||
|
||||
public (long, string) CurrentValue
|
||||
{
|
||||
get => EnumValues.FirstOrDefault(v => v.Item1 == _node.Storage);
|
||||
set
|
||||
{
|
||||
if (!Equals(_node.Storage, value))
|
||||
_nodeEditorService.ExecuteCommand(Script, new UpdateStorage<int>(_node, value));
|
||||
if (!Equals(_node.Storage, value.Item1))
|
||||
_nodeEditorService.ExecuteCommand(Script, new UpdateStorage<long>(_node, value.Item1));
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -11,7 +11,7 @@
|
||||
x:DataType="screens:StaticSKColorValueNodeCustomViewModel">
|
||||
<UserControl.Resources>
|
||||
<converters:SKColorToStringConverter x:Key="SKColorToStringConverter" />
|
||||
<converters:SKColorToColor2Converter x:Key="SKColorToColor2Converter" />
|
||||
<converters:SKColorToColorConverter x:Key="SKColorToColorConverter" />
|
||||
</UserControl.Resources>
|
||||
<Grid Height="24" ColumnDefinitions="*" Width="110">
|
||||
<TextBox Classes="condensed"
|
||||
@@ -22,7 +22,7 @@
|
||||
</Interaction.Behaviors>
|
||||
</TextBox>
|
||||
<controls:ColorPickerButton Classes="contained-color-picker-button"
|
||||
Color="{CompiledBinding CurrentValue, Converter={StaticResource SKColorToColor2Converter}}"
|
||||
Color="{CompiledBinding CurrentValue, Converter={StaticResource SKColorToColorConverter}}"
|
||||
ShowAcceptDismissButtons="False"
|
||||
FlyoutOpened="ColorPickerButton_OnFlyoutOpened"
|
||||
FlyoutClosed="ColorPickerButton_OnFlyoutClosed" />
|
||||
|
||||
Reference in new issue
Block a user