From a07ea3276c69d001f9f1c0e54c121f8058782bf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sat, 17 Feb 2024 23:06:55 +0100 Subject: [PATCH] ScriptCore: Added LabelAttribute --- ScriptCore/Editor/EntityEditor.cs | 13 ++++++++++++- ScriptCore/Editor/LabelAttribute.cs | 26 ++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-) create mode 100644 ScriptCore/Editor/LabelAttribute.cs diff --git a/ScriptCore/Editor/EntityEditor.cs b/ScriptCore/Editor/EntityEditor.cs index a6dea52..32ee1e8 100644 --- a/ScriptCore/Editor/EntityEditor.cs +++ b/ScriptCore/Editor/EntityEditor.cs @@ -852,7 +852,18 @@ internal class EntityEditor IEnumerable attributes = field.GetCustomAttributes(); - string prettyName = field.Name.ToPrettyName(); + LabelAttribute? label = GetAttribute(attributes); + + string prettyName; + + if (label != null) + { + prettyName = label.Label ?? field.Name; + } + else + { + prettyName = field.Name.ToPrettyName(); + } object? newValue = ShowFieldEditor(value, value?.GetType() ?? field.FieldType, prettyName, attributes); diff --git a/ScriptCore/Editor/LabelAttribute.cs b/ScriptCore/Editor/LabelAttribute.cs new file mode 100644 index 0000000..61adcd3 --- /dev/null +++ b/ScriptCore/Editor/LabelAttribute.cs @@ -0,0 +1,26 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace GlitchyEngine.Editor; + +/// +/// Specifies a string that will be shown as the label of the field in the editor. +/// +[AttributeUsage(AttributeTargets.Field)] +public sealed class LabelAttribute : Attribute +{ + /// + /// The label of the field. If , the actual field name will be shown instead of the "prettified" name that is shown for fields without the . + /// + public string? Label { get; private set; } + + /// + /// Initializes a new instance of the with a minimum, maximum value and optionally a speed. + /// + /// + public LabelAttribute(string? label) + { + Label = label; + } +}