ScriptCore: Added LabelAttribute

This commit is contained in:
Simon Lübeß
2024-02-17 23:06:55 +01:00
parent 3c0302b06c
commit a07ea3276c
2 changed files with 38 additions and 1 deletions
+12 -1
View File
@@ -852,7 +852,18 @@ internal class EntityEditor
IEnumerable<Attribute> attributes = field.GetCustomAttributes(); IEnumerable<Attribute> attributes = field.GetCustomAttributes();
string prettyName = field.Name.ToPrettyName(); LabelAttribute? label = GetAttribute<LabelAttribute>(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); object? newValue = ShowFieldEditor(value, value?.GetType() ?? field.FieldType, prettyName, attributes);
+26
View File
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace GlitchyEngine.Editor;
/// <summary>
/// Specifies a string that will be shown as the label of the field in the editor.
/// </summary>
[AttributeUsage(AttributeTargets.Field)]
public sealed class LabelAttribute : Attribute
{
/// <summary>
/// The label of the field. If <see langword="null"/>, the actual field name will be shown instead of the "prettified" name that is shown for fields without the <see cref="LabelAttribute"/>.
/// </summary>
public string? Label { get; private set; }
/// <summary>
/// Initializes a new instance of the <see cref="RangeAttribute"/> with a minimum, maximum value and optionally a speed.
/// </summary>
/// <param name="label"><inheritdoc cref="Label"/></param>
public LabelAttribute(string? label)
{
Label = label;
}
}