1
0
mirror of https://github.com/Artemis-RGB/Artemis synced 2025-12-12 21:38:38 +00:00
This commit is contained in:
Robert 2024-02-23 21:15:34 +01:00
parent 49ed0205b7
commit bcf0b74fcc
4 changed files with 36 additions and 35 deletions

View File

@ -16,9 +16,9 @@ public interface INode : INotifyPropertyChanged, IBreakableModel
Guid Id { get; set; }
/// <summary>
/// Gets
/// Gets or sets the node data with information about this node
/// </summary>
NodeData NodeData { get; set; }
NodeData? NodeData { get; set; }
/// <summary>
/// Gets the name of the node

View File

@ -42,7 +42,7 @@ public abstract class Node : BreakableModel, INode
}
/// <inheritdoc />
public NodeData NodeData { get; set; }
public NodeData? NodeData { get; set; }
private string _name;

View File

@ -25,6 +25,8 @@ public abstract class Node<TStorage, TViewModel> : Node<TStorage>, ICustomViewMo
/// <param name="nodeScript"></param>
public virtual TViewModel GetViewModel(NodeScript nodeScript)
{
if (NodeData == null)
throw new ArtemisCoreException("Nodes without node data (default nodes or exit nodes) cannot have custom view models");
return NodeData.Provider.Plugin.Container.Resolve<TViewModel>(args: new object[] {this, nodeScript});
}

View File

@ -141,41 +141,9 @@ public partial class NodeViewModel : ActivatableViewModelBase
// Set up the custom node VM if needed
SetupCustomNodeViewModel();
});
}
private void SetupCustomNodeViewModel()
{
if (Node is not ICustomViewModelNode customViewModelNode)
return;
try
{
CustomNodeViewModel = customViewModelNode.GetCustomViewModel(NodeScriptViewModel.NodeScript);
}
catch (Exception e)
{
_logger.Error(e, "Failed to instantiate custom node view model");
}
if (customViewModelNode.ViewModelPosition == CustomNodeViewModelPosition.AbovePins)
DisplayCustomViewModelAbove = true;
else if (customViewModelNode.ViewModelPosition == CustomNodeViewModelPosition.BelowPins)
DisplayCustomViewModelBelow = true;
else
{
DisplayCustomViewModelBetween = true;
if (customViewModelNode.ViewModelPosition == CustomNodeViewModelPosition.BetweenPinsTop)
CustomViewModelVerticalAlignment = VerticalAlignment.Top;
else if (customViewModelNode.ViewModelPosition == CustomNodeViewModelPosition.BetweenPinsTop)
CustomViewModelVerticalAlignment = VerticalAlignment.Center;
else
CustomViewModelVerticalAlignment = VerticalAlignment.Bottom;
}
}
public bool IsStaticNode => _isStaticNode?.Value ?? true;
public bool HasInputPins => _hasInputPins?.Value ?? false;
public bool HasOutputPins => _hasOutputPins?.Value ?? false;
@ -226,4 +194,35 @@ public partial class NodeViewModel : ActivatableViewModelBase
if (Node.BrokenState != null && Node.BrokenStateException != null)
_windowService.ShowExceptionDialog(Node.BrokenState, Node.BrokenStateException);
}
private void SetupCustomNodeViewModel()
{
if (Node is not ICustomViewModelNode customViewModelNode)
return;
try
{
CustomNodeViewModel = customViewModelNode.GetCustomViewModel(NodeScriptViewModel.NodeScript);
}
catch (Exception e)
{
_logger.Error(e, "Failed to instantiate custom node view model");
}
if (customViewModelNode.ViewModelPosition == CustomNodeViewModelPosition.AbovePins)
DisplayCustomViewModelAbove = true;
else if (customViewModelNode.ViewModelPosition == CustomNodeViewModelPosition.BelowPins)
DisplayCustomViewModelBelow = true;
else
{
DisplayCustomViewModelBetween = true;
if (customViewModelNode.ViewModelPosition == CustomNodeViewModelPosition.BetweenPinsTop)
CustomViewModelVerticalAlignment = VerticalAlignment.Top;
else if (customViewModelNode.ViewModelPosition == CustomNodeViewModelPosition.BetweenPinsTop)
CustomViewModelVerticalAlignment = VerticalAlignment.Center;
else
CustomViewModelVerticalAlignment = VerticalAlignment.Bottom;
}
}
}