diff --git a/Source/Editor/Surface/ContextMenu/VisjectCM.cs b/Source/Editor/Surface/ContextMenu/VisjectCM.cs index ae4cef3dc..005c164fd 100644 --- a/Source/Editor/Surface/ContextMenu/VisjectCM.cs +++ b/Source/Editor/Surface/ContextMenu/VisjectCM.cs @@ -51,6 +51,10 @@ namespace FlaxEditor.Surface.ContextMenu private Elements.Box _selectedBox; private NodeArchetype _parameterGetNodeArchetype; private NodeArchetype _parameterSetNodeArchetype; + private bool _useDescriptionPanel; + private string _currentDescriptionText; + private Panel _descriptionPanel; + private Label _descriptionLabel; /// /// The selected item @@ -82,6 +86,11 @@ namespace FlaxEditor.Surface.ContextMenu /// public bool CanSetParameters; + /// + /// True if the surface should make use of a description panel drawn at the bottom of the context menu + /// + public bool UseDescriptionPanel; + /// /// The groups archetypes. Cannot be null. /// @@ -127,9 +136,11 @@ namespace FlaxEditor.Surface.ContextMenu _parameterGetNodeArchetype = info.ParameterGetNodeArchetype ?? Archetypes.Parameters.Nodes[0]; if (info.CanSetParameters) _parameterSetNodeArchetype = info.ParameterSetNodeArchetype ?? Archetypes.Parameters.Nodes[3]; + _useDescriptionPanel = info.UseDescriptionPanel; + float descriptionHeight = 75; // Context menu dimensions - Size = new Float2(300, 400); + Size = new Float2(300, 400 + (_useDescriptionPanel ? descriptionHeight : 0)); var headerPanel = new Panel(ScrollBars.None) { @@ -187,7 +198,7 @@ namespace FlaxEditor.Surface.ContextMenu // Create first panel (for scrollbar) var panel1 = new Panel(ScrollBars.Vertical) { - Bounds = new Rectangle(0, _searchBox.Bottom + 1, Width, Height - _searchBox.Bottom - 2), + Bounds = new Rectangle(0, _searchBox.Bottom + 1, Width, Height - _searchBox.Bottom - (_useDescriptionPanel ? descriptionHeight : 0) - 2), Parent = this }; @@ -202,6 +213,27 @@ namespace FlaxEditor.Surface.ContextMenu }; _groupsPanel = panel2; + // Create description panel if enabled + if (_useDescriptionPanel) + { + var descriptionPanel = new Panel(ScrollBars.None) + { + Parent = this, + Bounds = new Rectangle(0, Height - descriptionHeight, Width, descriptionHeight), + BackgroundColor = Style.Current.BackgroundNormal, + }; + _descriptionPanel = descriptionPanel; + + var descriptionLabel = new Label(8,8,Width-16,Height-16) + { + Parent = _descriptionPanel, + HorizontalAlignment = TextAlignment.Near, + VerticalAlignment = TextAlignment.Near, + Wrapping = TextWrapping.WrapWords, + }; + _descriptionLabel = descriptionLabel; + } + // Init groups var nodes = new List(); foreach (var groupArchetype in info.Groups) @@ -549,6 +581,14 @@ namespace FlaxEditor.Surface.ContextMenu _groups[i].Open(animate); } + public void SetDescriptionText(string text) + { + if(!_useDescriptionPanel) + return; + _currentDescriptionText = text; + _descriptionLabel.Text = _currentDescriptionText; + } + /// /// Resets the view. /// diff --git a/Source/Editor/Surface/ContextMenu/VisjectCMItem.cs b/Source/Editor/Surface/ContextMenu/VisjectCMItem.cs index 9d582c491..ede6775e7 100644 --- a/Source/Editor/Surface/ContextMenu/VisjectCMItem.cs +++ b/Source/Editor/Surface/ContextMenu/VisjectCMItem.cs @@ -338,6 +338,13 @@ namespace FlaxEditor.Surface.ContextMenu return base.OnMouseUp(location, button); } + /// + public override void OnMouseEnter(Float2 location) + { + base.OnMouseEnter(location); + Group.ContextMenu.SetDescriptionText(_archetype.Description); + } + /// public override void OnMouseLeave() { diff --git a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs index 7f284420d..54f4e14e6 100644 --- a/Source/Editor/Surface/VisjectSurface.ContextMenu.cs +++ b/Source/Editor/Surface/VisjectSurface.ContextMenu.cs @@ -237,6 +237,7 @@ namespace FlaxEditor.Surface return new VisjectCM(new VisjectCM.InitInfo { CanSetParameters = CanSetParameters, + UseDescriptionPanel = UseContextMenuDescriptionPanel, Groups = NodeArchetypes, CanSpawnNode = CanUseNodeType, ParametersGetter = () => Parameters, diff --git a/Source/Editor/Surface/VisjectSurface.cs b/Source/Editor/Surface/VisjectSurface.cs index 78277dbe2..b3869f304 100644 --- a/Source/Editor/Surface/VisjectSurface.cs +++ b/Source/Editor/Surface/VisjectSurface.cs @@ -535,6 +535,11 @@ namespace FlaxEditor.Surface /// public virtual bool CanSetParameters => false; + /// + /// True of the context menu should make use of a description panel drawn at the bottom of the menu + /// + public virtual bool UseContextMenuDescriptionPanel => false; + /// /// Gets a value indicating whether surface supports/allows live previewing graph modifications due to value sliders and color pickers. True by default but disabled for shader surfaces that generate and compile shader source at flight. /// diff --git a/Source/Editor/Surface/VisualScriptSurface.cs b/Source/Editor/Surface/VisualScriptSurface.cs index ee0a3c6d6..f32bd2ea0 100644 --- a/Source/Editor/Surface/VisualScriptSurface.cs +++ b/Source/Editor/Surface/VisualScriptSurface.cs @@ -174,6 +174,9 @@ namespace FlaxEditor.Surface /// public override bool CanSetParameters => true; + /// + public override bool UseContextMenuDescriptionPanel => true; + /// public override bool CanUseNodeType(GroupArchetype groupArchetype, NodeArchetype nodeArchetype) {