From cffc3f7f5d9ac0eedb28540e82470563e59d8300 Mon Sep 17 00:00:00 2001 From: Menotdan Date: Sun, 7 May 2023 13:44:15 -0400 Subject: [PATCH] Better formatting for type names. --- Source/Editor/Content/Items/AssetItem.cs | 4 ++-- Source/Editor/Utilities/Utils.cs | 28 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Content/Items/AssetItem.cs b/Source/Editor/Content/Items/AssetItem.cs index a8303b1d4..120d0e416 100644 --- a/Source/Editor/Content/Items/AssetItem.cs +++ b/Source/Editor/Content/Items/AssetItem.cs @@ -80,9 +80,9 @@ namespace FlaxEditor.Content /// The String Builder. 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(); } /// diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index 21e5fc0da..23adc9954 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -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; } + /// + /// Gets the asset type, translating if possible, and if enabled in InterfaceOptions.TranslateTypes. + /// + /// The type name. + /// The translated type name. + 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; + } + } + /// /// Gets the asset name relative to the project root folder (with asset file extension) ///