- Added optional description panel to visject CM

- Enbaled description panel for visual scripting
- Archetype description now gets drawn in description panel
This commit is contained in:
Nils Hausfeld
2024-06-09 13:45:53 +02:00
parent 50c29f6a9b
commit fa67d0581e
5 changed files with 58 additions and 2 deletions

View File

@@ -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;
/// <summary>
/// The selected item
@@ -82,6 +86,11 @@ namespace FlaxEditor.Surface.ContextMenu
/// </summary>
public bool CanSetParameters;
/// <summary>
/// True if the surface should make use of a description panel drawn at the bottom of the context menu
/// </summary>
public bool UseDescriptionPanel;
/// <summary>
/// The groups archetypes. Cannot be null.
/// </summary>
@@ -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<NodeArchetype>();
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;
}
/// <summary>
/// Resets the view.
/// </summary>

View File

@@ -338,6 +338,13 @@ namespace FlaxEditor.Surface.ContextMenu
return base.OnMouseUp(location, button);
}
/// <inheritdoc />
public override void OnMouseEnter(Float2 location)
{
base.OnMouseEnter(location);
Group.ContextMenu.SetDescriptionText(_archetype.Description);
}
/// <inheritdoc />
public override void OnMouseLeave()
{

View File

@@ -237,6 +237,7 @@ namespace FlaxEditor.Surface
return new VisjectCM(new VisjectCM.InitInfo
{
CanSetParameters = CanSetParameters,
UseDescriptionPanel = UseContextMenuDescriptionPanel,
Groups = NodeArchetypes,
CanSpawnNode = CanUseNodeType,
ParametersGetter = () => Parameters,

View File

@@ -535,6 +535,11 @@ namespace FlaxEditor.Surface
/// </summary>
public virtual bool CanSetParameters => false;
/// <summary>
/// True of the context menu should make use of a description panel drawn at the bottom of the menu
/// </summary>
public virtual bool UseContextMenuDescriptionPanel => false;
/// <summary>
/// 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.
/// </summary>

View File

@@ -174,6 +174,9 @@ namespace FlaxEditor.Surface
/// <inheritdoc />
public override bool CanSetParameters => true;
/// <inheritdoc />
public override bool UseContextMenuDescriptionPanel => true;
/// <inheritdoc />
public override bool CanUseNodeType(GroupArchetype groupArchetype, NodeArchetype nodeArchetype)
{