Better formatting for type names.

This commit is contained in:
Menotdan
2023-05-07 13:44:15 -04:00
parent c717a102fc
commit cffc3f7f5d
2 changed files with 30 additions and 2 deletions

View File

@@ -80,9 +80,9 @@ namespace FlaxEditor.Content
/// <param name="sb">The String Builder.</param>
protected virtual void OnBuildTooltipText(StringBuilder sb)
{
sb.Append("Type: ").Append(TypeName).AppendLine();
sb.Append("Type: ").Append(Utilities.Utils.TranslateTypeName(TypeName)).AppendLine();
sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine();
sb.Append("Path: ").Append(FlaxEditor.Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine();
sb.Append("Path: ").Append(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine();
}
/// <inheritdoc />

View File

@@ -20,6 +20,8 @@ using FlaxEditor.SceneGraph;
using FlaxEditor.Scripting;
using FlaxEngine;
using FlaxEngine.GUI;
using FlaxEditor.Options;
using System.Linq;
namespace FlaxEngine
{
@@ -1017,6 +1019,32 @@ namespace FlaxEditor.Utilities
node.Visible = isThisVisible | isAnyChildVisible;
}
/// <summary>
/// Gets the asset type, translating if possible, and if enabled in InterfaceOptions.TranslateTypes.
/// </summary>
/// <param name="typeName">The type name.</param>
/// <returns>The translated type name.</returns>
public static string TranslateTypeName(string typeName)
{
// TODO: Surely there is a better way to get this value.
if (!Editor.Instance.Options.Options.Interface.TranslateTypeNames)
{
return typeName;
}
string[] typeNamespaces = typeName.Split('.');
string lastNamespace = typeNamespaces.Last();
// TODO: Add better handling for unconventional type names.
try
{
// Adds spaces between capital letters.
return string.Concat(lastNamespace.Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
} catch {
return typeName;
}
}
/// <summary>
/// Gets the asset name relative to the project root folder (with asset file extension)
/// </summary>