- Some cleanup and tooltips

This commit is contained in:
Nils Hausfeld
2024-06-20 00:18:11 +02:00
parent cb1324fc2d
commit d7a0c69990
8 changed files with 61 additions and 57 deletions

View File

@@ -372,7 +372,7 @@ namespace FlaxEditor.Options
/// Gets or sets the visject connection curvature.
/// </summary>
[DefaultValue(true)]
[EditorDisplay("Visject"), EditorOrder(550)]
[EditorDisplay("Visject"), EditorOrder(550), Tooltip("Shows/hides the description panel in the visual scripting context menu.")]
public bool VisualScriptingDescriptionPanel { get; set; } = true;
private static FontAsset DefaultFont => FlaxEngine.Content.LoadAsyncInternal<FontAsset>(EditorAssets.PrimaryFont);

View File

@@ -197,7 +197,6 @@ namespace FlaxEditor.Surface
{
Groups = StateMachineGroupArchetypes,
CanSpawnNode = (_, _) => true,
Style = Style,
});
_cmStateMachineMenu.ShowExpanded = true;
}
@@ -215,7 +214,6 @@ namespace FlaxEditor.Surface
CanSpawnNode = CanUseNodeType,
ParametersGetter = null,
CustomNodesGroup = GetCustomNodes(),
Style = Style,
});
_cmStateMachineTransitionMenu.AddGroup(StateMachineTransitionGroupArchetype, false);
}

View File

@@ -7,8 +7,6 @@ using Real = System.Single;
#endif
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using FlaxEditor.CustomEditors.Editors;
using FlaxEditor.GUI;
@@ -468,7 +466,7 @@ namespace FlaxEditor.Surface.Archetypes
internal static void GetInputOutputDescription(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs)
{
inputs = null;
outputs = [("", new ScriptType(typeof(Dictionary<int, string>)))];
outputs = [("", new ScriptType(typeof(System.Collections.Generic.Dictionary<int, string>)))];
}
}

View File

@@ -248,17 +248,24 @@ namespace FlaxEditor.Surface.Archetypes
internal static void GetInputOutputDescription(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs)
{
var type = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
outputs = [(type.Name, type)];
var fields = type.GetMembers(BindingFlags.Public | BindingFlags.Instance).Where(x => x.IsField).ToArray();
var fieldsLength = fields.Length;
inputs = new (string, ScriptType)[fieldsLength];
for (var i = 0; i < fieldsLength; i++)
var typeName = (string)nodeArch.DefaultValues[0];
var type = TypeUtils.GetType(typeName);
if (type)
{
var field = fields[i];
inputs[i] = (field.Name, field.ValueType);
var fields = type.GetMembers(BindingFlags.Public | BindingFlags.Instance).Where(x => x.IsField).ToArray();
var fieldsLength = fields.Length;
inputs = new (string, ScriptType)[fieldsLength];
for (var i = 0; i < fieldsLength; i++)
{
var field = fields[i];
inputs[i] = (field.Name, field.ValueType);
}
outputs = [(type.Name, type)];
}
inputs = null;
outputs = null;
}
}
@@ -301,17 +308,23 @@ namespace FlaxEditor.Surface.Archetypes
internal static void GetInputOutputDescription(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs)
{
var type = TypeUtils.GetType((string)nodeArch.DefaultValues[0]);
inputs = [(type.Name, type)];
var fields = type.GetMembers(BindingFlags.Public | BindingFlags.Instance).Where(x => x.IsField).ToArray();
var fieldsLength = fields.Length;
outputs = new (string, ScriptType)[fieldsLength];
for (var i = 0; i < fieldsLength; i++)
var typeName = (string)nodeArch.DefaultValues[0];
var type = TypeUtils.GetType(typeName);
if (type)
{
var field = fields[i];
outputs[i] = (field.Name, field.ValueType);
inputs = [(type.Name, type)];
var fields = type.GetMembers(BindingFlags.Public | BindingFlags.Instance).Where(x => x.IsField).ToArray();
var fieldsLength = fields.Length;
outputs = new (string, ScriptType)[fieldsLength];
for (var i = 0; i < fieldsLength; i++)
{
var field = fields[i];
outputs[i] = (field.Name, field.ValueType);
}
}
inputs = null;
outputs = null;
}
}

View File

@@ -2,14 +2,11 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Text.RegularExpressions;
using FlaxEditor.GUI.ContextMenu;
using FlaxEditor.GUI.Input;
using FlaxEditor.Scripting;
using FlaxEditor.Surface.Archetypes;
using FlaxEngine;
using FlaxEngine.GUI;
using FlaxEngine.Utilities;
@@ -62,13 +59,12 @@ namespace FlaxEditor.Surface.ContextMenu
private bool _descriptionPanelVisible;
private readonly Panel _descriptionPanel;
private readonly Panel _descriptionPanelSeparator;
private readonly Image _descriptionClassImage;
private readonly Image _descriptionDeclaringClassImage;
private readonly Label _descriptionSignatureLabel;
private readonly Label _descriptionLabel;
private readonly SurfaceStyle _surfaceStyle;
private readonly VerticalPanel _descriptionInputPanel;
private readonly VerticalPanel _descriptionOutputPanel;
private readonly SurfaceStyle _surfaceStyle;
private VisjectCMItem _selectedItem;
/// <summary>
@@ -251,7 +247,7 @@ namespace FlaxEditor.Surface.ContextMenu
};
var spriteHandle = info.Style.Icons.BoxClose;
_descriptionClassImage = new Image(8, 12, 20, 20)
_descriptionDeclaringClassImage = new Image(8, 12, 20, 20)
{
Parent = _descriptionPanel,
Brush = new SpriteBrush(spriteHandle),
@@ -816,12 +812,12 @@ namespace FlaxEditor.Surface.ContextMenu
HideDescriptionPanel();
return;
}
Profiler.BeginEvent("VisjectCM.SetDescriptionPanelArchetype");
_descriptionInputPanel.RemoveChildren();
_descriptionOutputPanel.RemoveChildren();
ScriptType declaringType;
if (archetype.Tag is ScriptMemberInfo memberInfo)
{
@@ -844,7 +840,7 @@ namespace FlaxEditor.Surface.ContextMenu
else
AddInputOutputElement(archetype, memberInfo.ValueType, true, $"Return ({memberInfo.ValueType.Name})");
}
for(int i = 0; i < memberInfo.ParametersCount; i++)
{
var param = memberInfo.GetParameters()[i];
@@ -858,13 +854,13 @@ namespace FlaxEditor.Surface.ContextMenu
if (archetype.GetInputOutputDescription != null)
{
archetype.GetInputOutputDescription.Invoke(archetype, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs);
archetype.GetInputOutputDescription.Invoke(archetype, out (string Name, ScriptType Type)[] inputs, out (string Name, ScriptType Type)[] outputs);
if (inputs != null)
{
for (int i = 0; i < inputs.Length; i++)
{
AddInputOutputElement(archetype, inputs[i].Item2, false, $"{inputs[i].Item1} ({inputs[i].Item2.Name})");
AddInputOutputElement(archetype, inputs[i].Type, false, $"{inputs[i].Name} ({inputs[i].Type.Name})");
}
}
@@ -872,7 +868,7 @@ namespace FlaxEditor.Surface.ContextMenu
{
for (int i = 0; i < outputs.Length; i++)
{
AddInputOutputElement(archetype, outputs[i].Item2, true, $"{outputs[i].Item1} ({outputs[i].Item2.Name})");
AddInputOutputElement(archetype, outputs[i].Type, true, $"{outputs[i].Name} ({outputs[i].Type.Name})");
}
}
}
@@ -880,22 +876,22 @@ namespace FlaxEditor.Surface.ContextMenu
{
foreach (var element in archetype.Elements)
{
if (element.Type is NodeElementType.Input or NodeElementType.Output)
{
bool isOutput = element.Type == NodeElementType.Output;
if (element.ConnectionsType == null)
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"{element.Text} ({archetype.ConnectionsHints.ToString()})");
else
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"{element.Text} ({element.ConnectionsType.Name})");
}
if (element.Type is not (NodeElementType.Input or NodeElementType.Output))
continue;
bool isOutput = element.Type == NodeElementType.Output;
if (element.ConnectionsType == null)
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"{element.Text} ({archetype.ConnectionsHints.ToString()})");
else
AddInputOutputElement(archetype, element.ConnectionsType, isOutput, $"{element.Text} ({element.ConnectionsType.Name})");
}
}
}
_surfaceStyle.GetConnectionColor(declaringType, archetype.ConnectionsHints, out var declaringTypeColor);
_descriptionClassImage.Color = declaringTypeColor;
_descriptionClassImage.MouseOverColor = declaringTypeColor;
_descriptionDeclaringClassImage.Color = declaringTypeColor;
_descriptionDeclaringClassImage.MouseOverColor = declaringTypeColor;
float panelHeight = _descriptionSignatureLabel.Height;
if (string.IsNullOrEmpty(archetype.Description))
@@ -911,21 +907,21 @@ namespace FlaxEditor.Surface.ContextMenu
}
_descriptionPanelSeparator.Y = _descriptionLabel.Bounds.Bottom + 8f;
panelHeight += _descriptionLabel.Height + 32f;
_descriptionInputPanel.Y = panelHeight;
_descriptionOutputPanel.Y = panelHeight;
panelHeight += Mathf.Max(_descriptionInputPanel.Height, _descriptionOutputPanel.Height);
// Forcing the description panel to at least have a minimum height to not make the window size change too much in order to reduce jittering
// TODO: Remove the Mathf.Max and just set the height to panelHeight once the window jitter issue is fixed - Nils
_descriptionPanel.Height = Mathf.Max(135f, panelHeight);
Height = 400 + _descriptionPanel.Height;
UpdateWindowSize();
_descriptionPanelVisible = true;
Profiler.EndEvent();
}
@@ -962,7 +958,7 @@ namespace FlaxEditor.Surface.ContextMenu
elementPanel.AddChild(elementText);
elementPanel.Height = elementText.Height;
}
/// <summary>
/// Hides the description panel and resets the context menu to its original size
/// </summary>

View File

@@ -97,7 +97,7 @@ namespace FlaxEditor.Surface
/// <summary>
/// Gets description of inputs and outputs of the archetype. Used for special cases for the description panel.
/// </summary>
public delegate void GetElementsDescriptionFunc(NodeArchetype nodeArch, out (string, ScriptType)[] inputs, out (string, ScriptType)[] outputs);
public delegate void GetElementsDescriptionFunc(NodeArchetype nodeArch, out (string Name, ScriptType Type)[] inputs, out (string Name, ScriptType Type)[] outputs);
/// <summary>
/// Unique node type ID within a single group.

View File

@@ -468,7 +468,6 @@ namespace FlaxEditor.Surface
sb.Append('.');
sb.Append(name);
// Is a method and not a property
if (member.IsMethod)
{
sb.Append('(');
@@ -512,7 +511,7 @@ namespace FlaxEditor.Surface
return GetVisualScriptMemberShortDescription(property[0]);
}
}
return Editor.Instance.CodeDocs.GetTooltip(member);
}

View File

@@ -51,7 +51,7 @@ namespace FlaxEditor.Surface
{
TypeID = originalNodeId,
Title = "Missing Node :(",
Signature = ":(",
Signature = "Missing Node :(",
Description = ":(",
Flags = NodeFlags.AllGraphs,
Size = new Float2(200, 70),