From 7ada77f5e3bdbff09c9cbccc5e04d2281c563887 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 4 Oct 2022 23:31:20 +0200 Subject: [PATCH] Nodes - Added help URL and help button --- src/Artemis.Core/Services/NodeService.cs | 5 +++-- .../VisualScripting/Interfaces/INode.cs | 9 +++++++-- .../VisualScripting/NodeAttribute.cs | 16 ++++++++++++++++ src/Artemis.Core/VisualScripting/NodeData.cs | 19 +++++++++++++++++-- .../VisualScripting/Nodes/Node.cs | 14 ++++++++++++-- .../Screens/VisualScripting/NodeView.axaml | 15 +++++++++++++-- 6 files changed, 68 insertions(+), 10 deletions(-) diff --git a/src/Artemis.Core/Services/NodeService.cs b/src/Artemis.Core/Services/NodeService.cs index 5ebe8cc80..f09b20d04 100644 --- a/src/Artemis.Core/Services/NodeService.cs +++ b/src/Artemis.Core/Services/NodeService.cs @@ -75,8 +75,9 @@ internal class NodeService : INodeService string name = nodeAttribute?.Name ?? nodeType.Name; string description = nodeAttribute?.Description ?? string.Empty; string category = nodeAttribute?.Category ?? string.Empty; - - NodeData nodeData = new(plugin, nodeType, name, description, category, nodeAttribute?.InputType, nodeAttribute?.OutputType, (s, e) => CreateNode(s, e, nodeType)); + string helpUrl = nodeAttribute?.HelpUrl ?? string.Empty; + + NodeData nodeData = new(plugin, nodeType, name, description, category, helpUrl, nodeAttribute?.InputType, nodeAttribute?.OutputType, (s, e) => CreateNode(s, e, nodeType)); return NodeTypeStore.Add(nodeData); } diff --git a/src/Artemis.Core/VisualScripting/Interfaces/INode.cs b/src/Artemis.Core/VisualScripting/Interfaces/INode.cs index 022cddfaa..dce2df631 100644 --- a/src/Artemis.Core/VisualScripting/Interfaces/INode.cs +++ b/src/Artemis.Core/VisualScripting/Interfaces/INode.cs @@ -18,12 +18,12 @@ public interface INode : INotifyPropertyChanged, IBreakableModel /// /// Gets the name of the node /// - string Name { get; } + string Name { get; set; } /// /// Gets the description of the node /// - string Description { get; } + string Description { get; set; } /// /// Gets a boolean indicating whether the node is the exit node of the script @@ -44,6 +44,11 @@ public interface INode : INotifyPropertyChanged, IBreakableModel /// Gets or sets the Y-position of the node /// public double Y { get; set; } + + /// + /// Gets or sets the help URL of the node + /// + string HelpUrl { get; set; } /// /// Gets a read-only collection of the pins on this node diff --git a/src/Artemis.Core/VisualScripting/NodeAttribute.cs b/src/Artemis.Core/VisualScripting/NodeAttribute.cs index 4bd174502..c21574c03 100644 --- a/src/Artemis.Core/VisualScripting/NodeAttribute.cs +++ b/src/Artemis.Core/VisualScripting/NodeAttribute.cs @@ -24,6 +24,11 @@ public class NodeAttribute : Attribute /// public string Category { get; } = string.Empty; + /// + /// Gets the help URL of the node + /// + public string HelpUrl { get; init; } = string.Empty; + /// /// Gets the primary input type of the node /// @@ -65,5 +70,16 @@ public class NodeAttribute : Attribute Category = category; } + /// + /// Creates a new instance of the class + /// + public NodeAttribute(string name, string description, string category, string helpUrl) + { + Name = name; + Description = description; + Category = category; + HelpUrl = helpUrl; + } + #endregion } \ No newline at end of file diff --git a/src/Artemis.Core/VisualScripting/NodeData.cs b/src/Artemis.Core/VisualScripting/NodeData.cs index 6259f6ca6..d01dd9ab4 100644 --- a/src/Artemis.Core/VisualScripting/NodeData.cs +++ b/src/Artemis.Core/VisualScripting/NodeData.cs @@ -1,5 +1,6 @@ using System; using Artemis.Storage.Entities.Profile.Nodes; +using Castle.Core.Internal; namespace Artemis.Core; @@ -10,13 +11,14 @@ public class NodeData { #region Constructors - internal NodeData(Plugin plugin, Type type, string name, string description, string category, Type? inputType, Type? outputType, Func create) + internal NodeData(Plugin plugin, Type type, string name, string description, string category, string helpUrl, Type? inputType, Type? outputType, Func create) { Plugin = plugin; Type = type; Name = name; Description = description; Category = category; + HelpUrl = helpUrl; InputType = inputType; OutputType = outputType; _create = create; @@ -34,7 +36,15 @@ public class NodeData /// The returning node of type public INode CreateNode(INodeScript script, NodeEntity? entity) { - return _create(script, entity); + INode node = _create(script, entity); + if (string.IsNullOrWhiteSpace(node.Name)) + node.Name = Name; + if (string.IsNullOrWhiteSpace(node.Description)) + node.Description = Description; + if (string.IsNullOrWhiteSpace(node.HelpUrl)) + node.HelpUrl = HelpUrl; + + return node; } #endregion @@ -101,6 +111,11 @@ public class NodeData /// public string Category { get; } + /// + /// Gets the help URL of the node this data represents + /// + public string HelpUrl { get; } + /// /// Gets the primary input type of the node this data represents /// diff --git a/src/Artemis.Core/VisualScripting/Nodes/Node.cs b/src/Artemis.Core/VisualScripting/Nodes/Node.cs index e451f05aa..a6906ab57 100644 --- a/src/Artemis.Core/VisualScripting/Nodes/Node.cs +++ b/src/Artemis.Core/VisualScripting/Nodes/Node.cs @@ -46,7 +46,7 @@ public abstract class Node : BreakableModel, INode public string Name { get => _name; - protected set => SetAndNotify(ref _name, value); + set => SetAndNotify(ref _name, value); } private string _description; @@ -55,7 +55,7 @@ public abstract class Node : BreakableModel, INode public string Description { get => _description; - protected set => SetAndNotify(ref _description, value); + set => SetAndNotify(ref _description, value); } private double _x; @@ -76,6 +76,13 @@ public abstract class Node : BreakableModel, INode set => SetAndNotify(ref _y, value); } + /// + public string HelpUrl + { + get => _helpUrl; + set => SetAndNotify(ref _helpUrl, value); + } + /// public virtual bool IsExitNode => false; @@ -88,6 +95,7 @@ public abstract class Node : BreakableModel, INode public IReadOnlyCollection Pins => new ReadOnlyCollection(_pins); private readonly List _pinCollections = new(); + private string _helpUrl; /// public IReadOnlyCollection PinCollections => new ReadOnlyCollection(_pinCollections); @@ -106,6 +114,7 @@ public abstract class Node : BreakableModel, INode { _name = string.Empty; _description = string.Empty; + _helpUrl = string.Empty; _id = Guid.NewGuid(); } @@ -116,6 +125,7 @@ public abstract class Node : BreakableModel, INode { _name = name; _description = description; + _helpUrl = string.Empty; _id = Guid.NewGuid(); } diff --git a/src/Artemis.UI/Screens/VisualScripting/NodeView.axaml b/src/Artemis.UI/Screens/VisualScripting/NodeView.axaml index 7a26616ef..7adfdbbdf 100644 --- a/src/Artemis.UI/Screens/VisualScripting/NodeView.axaml +++ b/src/Artemis.UI/Screens/VisualScripting/NodeView.axaml @@ -4,6 +4,7 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:avalonia="clr-namespace:Material.Icons.Avalonia;assembly=Material.Icons.Avalonia" xmlns:visualScripting="clr-namespace:Artemis.UI.Screens.VisualScripting" + xmlns:controls="clr-namespace:FluentAvalonia.UI.Controls;assembly=FluentAvalonia" mc:Ignorable="d" d:DesignWidth="250" d:DesignHeight="150" x:Class="Artemis.UI.Screens.VisualScripting.NodeView" x:DataType="visualScripting:NodeViewModel"> @@ -37,7 +38,7 @@ ClipToBounds="True" Background="{DynamicResource ContentDialogBackground}"> - +