Improve property names displaying in UI and add Unit Test for it
This commit is contained in:
@@ -4,7 +4,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text;
|
||||
using FlaxEditor.CustomEditors.Editors;
|
||||
using FlaxEditor.Scripting;
|
||||
using FlaxEngine;
|
||||
@@ -13,8 +12,6 @@ namespace FlaxEditor.CustomEditors
|
||||
{
|
||||
internal static class CustomEditorsUtil
|
||||
{
|
||||
private static readonly StringBuilder CachedSb = new StringBuilder(256);
|
||||
|
||||
internal static readonly Dictionary<Type, string> InBuildTypeNames = new Dictionary<Type, string>()
|
||||
{
|
||||
{ typeof(bool), "bool" },
|
||||
@@ -46,51 +43,6 @@ namespace FlaxEditor.CustomEditors
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the property name for UI. Removes unnecessary characters and filters text. Makes it more user-friendly.
|
||||
/// </summary>
|
||||
/// <param name="name">The name.</param>
|
||||
/// <returns>The result.</returns>
|
||||
public static string GetPropertyNameUI(string name)
|
||||
{
|
||||
int length = name.Length;
|
||||
StringBuilder sb = CachedSb;
|
||||
sb.Clear();
|
||||
sb.EnsureCapacity(length + 8);
|
||||
int startIndex = 0;
|
||||
|
||||
// Skip some prefixes
|
||||
if (name.StartsWith("g_") || name.StartsWith("m_"))
|
||||
startIndex = 2;
|
||||
|
||||
// Filter text
|
||||
for (int i = startIndex; i < length; i++)
|
||||
{
|
||||
var c = name[i];
|
||||
|
||||
// Space before word starting with uppercase letter
|
||||
if (char.IsUpper(c) && i > 0)
|
||||
{
|
||||
if (i + 1 < length && !char.IsUpper(name[i + 1]))
|
||||
sb.Append(' ');
|
||||
}
|
||||
// Space instead of underscore
|
||||
else if (c == '_')
|
||||
{
|
||||
if (sb.Length > 0)
|
||||
sb.Append(' ');
|
||||
continue;
|
||||
}
|
||||
// Space before digits sequence
|
||||
else if (i > 1 && char.IsDigit(c) && !char.IsDigit(name[i - 1]))
|
||||
sb.Append(' ');
|
||||
|
||||
sb.Append(c);
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
internal static CustomEditor CreateEditor(ValueContainer values, CustomEditor overrideEditor, bool canUseRefPicker = true)
|
||||
{
|
||||
// Check if use provided editor
|
||||
|
||||
@@ -209,13 +209,13 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
if (editor is RemovedScriptDummy removed)
|
||||
{
|
||||
node.TextColor = Color.OrangeRed;
|
||||
node.Text = CustomEditorsUtil.GetPropertyNameUI(removed.PrefabObject.GetType().Name);
|
||||
node.Text = Utilities.Utils.GetPropertyNameUI(removed.PrefabObject.GetType().Name);
|
||||
}
|
||||
// Actor or Script
|
||||
else if (editor.Values[0] is SceneObject sceneObject)
|
||||
{
|
||||
node.TextColor = sceneObject.HasPrefabLink ? FlaxEngine.GUI.Style.Current.ProgressNormal : FlaxEngine.GUI.Style.Current.BackgroundSelected;
|
||||
node.Text = CustomEditorsUtil.GetPropertyNameUI(sceneObject.GetType().Name);
|
||||
node.Text = Utilities.Utils.GetPropertyNameUI(sceneObject.GetType().Name);
|
||||
}
|
||||
// Array Item
|
||||
else if (editor.ParentEditor?.Values?.Type.IsArray ?? false)
|
||||
@@ -225,7 +225,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
// Common type
|
||||
else if (editor.Values.Info != ScriptMemberInfo.Null)
|
||||
{
|
||||
node.Text = CustomEditorsUtil.GetPropertyNameUI(editor.Values.Info.Name);
|
||||
node.Text = Utilities.Utils.GetPropertyNameUI(editor.Values.Info.Name);
|
||||
}
|
||||
// Custom type
|
||||
else if (editor.Values[0] != null)
|
||||
|
||||
@@ -611,7 +611,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
var editor = CustomEditorsUtil.CreateEditor(scriptType, false);
|
||||
|
||||
// Create group
|
||||
var title = CustomEditorsUtil.GetPropertyNameUI(scriptType.Name);
|
||||
var title = Utilities.Utils.GetPropertyNameUI(scriptType.Name);
|
||||
var group = layout.Group(title, editor);
|
||||
if ((Presenter.Features & FeatureFlags.CacheExpandedGroups) != 0)
|
||||
{
|
||||
|
||||
@@ -32,7 +32,7 @@ namespace FlaxEditor.CustomEditors.Dedicated
|
||||
if (_presets != value)
|
||||
{
|
||||
_presets = value;
|
||||
TooltipText = CustomEditorsUtil.GetPropertyNameUI(_presets.ToString());
|
||||
TooltipText = Utilities.Utils.GetPropertyNameUI(_presets.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -137,7 +137,7 @@ namespace FlaxEditor.CustomEditors.Editors
|
||||
ExpandGroups = attributes.FirstOrDefault(x => x is ExpandGroupsAttribute) != null;
|
||||
|
||||
IsReadOnly |= !info.HasSet;
|
||||
DisplayName = Display?.Name ?? CustomEditorsUtil.GetPropertyNameUI(info.Name);
|
||||
DisplayName = Display?.Name ?? Utilities.Utils.GetPropertyNameUI(info.Name);
|
||||
var editor = Editor.Instance;
|
||||
TooltipText = editor.CodeDocs.GetTooltip(info, attributes);
|
||||
_membersOrder = editor.Options.Options.General.ScriptMembersOrder;
|
||||
|
||||
Reference in New Issue
Block a user