|
@@ -1,5 +1,6 @@
|
|
|
using System.Reflection;
|
|
|
using PixiEditor.ChangeableDocument.Changeables.Graph;
|
|
|
+using PixiEditor.ChangeableDocument.Changeables.Graph.Nodes;
|
|
|
using PixiEditor.Extensions.Common.Localization;
|
|
|
using PixiEditor.Fonts;
|
|
|
using PixiEditor.UI.Common.Fonts;
|
|
@@ -8,8 +9,6 @@ namespace PixiEditor.ViewModels.Nodes;
|
|
|
|
|
|
public class NodeTypeInfo
|
|
|
{
|
|
|
- public string UniqueName { get; }
|
|
|
-
|
|
|
public string DisplayName { get; }
|
|
|
|
|
|
public string? PickerName { get; }
|
|
@@ -20,26 +19,46 @@ public class NodeTypeInfo
|
|
|
|
|
|
public bool Hidden => PickerName is { Length: 0 };
|
|
|
|
|
|
+ public Type NodeViewModelType { get; }
|
|
|
+
|
|
|
public Type NodeType { get; }
|
|
|
|
|
|
public string Icon { get; }
|
|
|
|
|
|
- public NodeTypeInfo(Type type)
|
|
|
+ public NodeTypeInfo(Type viewModelType)
|
|
|
{
|
|
|
- NodeType = type;
|
|
|
-
|
|
|
- var attribute = type.GetCustomAttribute<NodeInfoAttribute>();
|
|
|
+ NodeViewModelType = viewModelType;
|
|
|
+ NodeType = GetNodeType(NodeViewModelType.BaseType);
|
|
|
+
|
|
|
+ var attribute = viewModelType.GetCustomAttribute<NodeViewModelAttribute>();
|
|
|
|
|
|
- UniqueName = attribute.UniqueName;
|
|
|
DisplayName = attribute.DisplayName;
|
|
|
PickerName = attribute.PickerName;
|
|
|
Category = attribute.Category ?? "";
|
|
|
|
|
|
- if (NodeIcons.IconMap.TryGetValue(type, out var icon))
|
|
|
+ if (NodeIcons.IconMap.TryGetValue(NodeType, out var icon))
|
|
|
{
|
|
|
Icon = icon;
|
|
|
}
|
|
|
|
|
|
FinalPickerName = (PickerName ?? DisplayName);
|
|
|
}
|
|
|
+
|
|
|
+ private Type GetNodeType(Type? baseType)
|
|
|
+ {
|
|
|
+ while (true)
|
|
|
+ {
|
|
|
+ if (baseType.IsGenericType)
|
|
|
+ {
|
|
|
+ var genericArgument = baseType.GetGenericArguments()[0];
|
|
|
+
|
|
|
+ if (genericArgument.IsAssignableTo(typeof(Node)))
|
|
|
+ {
|
|
|
+ return genericArgument;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ baseType = baseType.BaseType;
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|