Nodes - Show errors in node editor when a node fails to evaluate

This commit is contained in:
Robert committed 2022-09-01 20:33:55 +02:00
1 parent cd537051ca
commit eca8985fc4
9 files changed
+89 -48

No files matched your search

@@ -37,35 +37,38 @@
ClipToBounds="True"
Background="{DynamicResource ContentDialogBackground}">
<Border Background="{DynamicResource TaskDialogHeaderBackground}">
<Grid Classes="node-header"
VerticalAlignment="Top"
ColumnDefinitions="*,Auto">
<TextBlock VerticalAlignment="Center"
Margin="10 0 0 0"
Text="{CompiledBinding Node.Name}"
ToolTip.Tip="{CompiledBinding Node.Description}">
</TextBlock>
<Button VerticalAlignment="Center"
<Grid Classes="node-header" VerticalAlignment="Top" ColumnDefinitions="Auto,*,Auto">
<Button Grid.Column="0"
VerticalAlignment="Center"
IsVisible="{CompiledBinding Node.BrokenState, Converter={x:Static ObjectConverters.IsNotNull}}"
Classes="icon-button icon-button-small"
Grid.Column="1"
Margin="5"
Command="{CompiledBinding DeleteNode}">
Foreground="White"
Background="#E74C4C"
BorderBrush="#E74C4C"
Margin="5 0 0 0"
ToolTip.Tip="{CompiledBinding Node.BrokenState}"
Command="{CompiledBinding ShowBrokenState}">
<avalonia:MaterialIcon Kind="AlertCircle"></avalonia:MaterialIcon>
</Button>
<TextBlock Grid.Column="1" VerticalAlignment="Center" Margin="10 0 0 0" Text="{CompiledBinding Node.Name}" ToolTip.Tip="{CompiledBinding Node.Description}"/>
<Button Grid.Column="2" VerticalAlignment="Center" Classes="icon-button icon-button-small" Margin="5" Command="{CompiledBinding DeleteNode}">
<avalonia:MaterialIcon Kind="Close"></avalonia:MaterialIcon>
</Button>
</Grid>
</Border>
</Border>
<Grid Grid.Row="1" ColumnDefinitions="Auto,*,Auto" Margin="4">
<StackPanel Grid.Column="0" IsVisible="{CompiledBinding HasInputPins}">
<ItemsControl Items="{CompiledBinding InputPinViewModels}" Margin="4 0" />
<ItemsControl Items="{CompiledBinding InputPinCollectionViewModels}" />
</StackPanel>
<ContentControl Grid.Column="1"
<ContentControl Grid.Column="1"
Name="CustomViewModelContainer"
Content="{CompiledBinding CustomNodeViewModel}"
Content="{CompiledBinding CustomNodeViewModel}"
IsVisible="{CompiledBinding CustomNodeViewModel, Converter={x:Static ObjectConverters.IsNotNull}}" />
<StackPanel Grid.Column="2" IsVisible="{CompiledBinding HasOutputPins}">
@@ -8,6 +8,7 @@ using Artemis.Core.Events;
using Artemis.UI.Ninject.Factories;
using Artemis.UI.Screens.VisualScripting.Pins;
using Artemis.UI.Shared;
using Artemis.UI.Shared.Services;
using Artemis.UI.Shared.Services.NodeEditor;
using Artemis.UI.Shared.Services.NodeEditor.Commands;
using Avalonia;
@@ -21,9 +22,9 @@ namespace Artemis.UI.Screens.VisualScripting;
public class NodeViewModel : ActivatableViewModelBase
{
private readonly INodeEditorService _nodeEditorService;
private readonly IWindowService _windowService;
private ICustomNodeViewModel? _customNodeViewModel;
private ReactiveCommand<Unit, Unit>? _deleteNode;
private double _dragOffsetX;
private double _dragOffsetY;
private ObservableAsPropertyHelper<bool>? _hasInputPins;
@@ -34,14 +35,13 @@ public class NodeViewModel : ActivatableViewModelBase
private double _startX;
private double _startY;
public NodeViewModel(NodeScriptViewModel nodeScriptViewModel, INode node, INodeVmFactory nodeVmFactory, INodeEditorService nodeEditorService)
public NodeViewModel(NodeScriptViewModel nodeScriptViewModel, INode node, INodeVmFactory nodeVmFactory, INodeEditorService nodeEditorService, IWindowService windowService)
{
_nodeEditorService = nodeEditorService;
_windowService = windowService;
NodeScriptViewModel = nodeScriptViewModel;
Node = node;
DeleteNode = ReactiveCommand.Create(ExecuteDeleteNode, this.WhenAnyValue(vm => vm.IsStaticNode).Select(v => !v));
SourceList<PinViewModel> nodePins = new();
SourceList<PinCollectionViewModel> nodePinCollections = new();
@@ -61,7 +61,10 @@ public class NodeViewModel : ActivatableViewModelBase
nodePins.Connect().Merge(nodePinCollections.Connect().TransformMany(c => c.PinViewModels)).Bind(out ReadOnlyObservableCollection<PinViewModel> pins).Subscribe();
PinViewModels = pins;
DeleteNode = ReactiveCommand.Create(ExecuteDeleteNode, this.WhenAnyValue(vm => vm.IsStaticNode).Select(v => !v));
ShowBrokenState = ReactiveCommand.Create(ExecuteShowBrokenState);
this.WhenActivated(d =>
{
_isStaticNode = Node.WhenAnyValue(n => n.IsDefaultNode, n => n.IsExitNode)
@@ -152,17 +155,14 @@ public class NodeViewModel : ActivatableViewModelBase
set => RaiseAndSetIfChanged(ref _customNodeViewModel, value);
}
public ReactiveCommand<Unit, Unit>? DeleteNode
{
get => _deleteNode;
set => RaiseAndSetIfChanged(ref _deleteNode, value);
}
public bool IsSelected
{
get => _isSelected;
set => RaiseAndSetIfChanged(ref _isSelected, value);
}
public ReactiveCommand<Unit,Unit> ShowBrokenState { get; }
public ReactiveCommand<Unit, Unit> DeleteNode { get; }
public void StartDrag(Point mouseStartPosition)
{
@@ -195,4 +195,10 @@ public class NodeViewModel : ActivatableViewModelBase
{
_nodeEditorService.ExecuteCommand(NodeScriptViewModel.NodeScript, new DeleteNode(NodeScriptViewModel.NodeScript, Node));
}
private void ExecuteShowBrokenState()
{
if (Node.BrokenState != null && Node.BrokenStateException != null)
_windowService.ShowExceptionDialog(Node.BrokenState, Node.BrokenStateException);
}
}