Files
Emberwild/Assets/GAME/Script/Editor/Database/AshwildUI.cs
T
2026-06-23 14:52:45 +02:00

90 lines
3.1 KiB
C#

using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using Ashwild.Inventory;
namespace Ashwild.EditorTools
{
/// <summary>
/// Small library of styled VisualElement builders shared by the Ashwild Database editor views
/// (cards, type badges, accent colours). Centralised so the item and recipe editors stay visually
/// consistent and free of inline-style duplication.
/// </summary>
public static class AshwildUI
{
#region Type Colours
/// <summary>
/// The accent colour that identifies an item type across the list badges, hero and cards.
/// </summary>
public static Color TypeColor(ItemType type)
{
switch (type)
{
case ItemType.Tool: return new Color(0.93f, 0.58f, 0.22f);
case ItemType.Weapon: return new Color(0.88f, 0.33f, 0.33f);
case ItemType.Consumable: return new Color(0.42f, 0.76f, 0.47f);
default: return new Color(0.47f, 0.57f, 0.69f);
}
}
#endregion
#region Builders
/// <summary>
/// Builds a titled card container; callers add their fields straight onto the returned element,
/// below its heading.
/// </summary>
public static VisualElement Card(string title)
{
VisualElement card = new VisualElement();
card.AddToClassList("ash-card");
Label heading = new Label(title);
heading.AddToClassList("ash-card__title");
card.Add(heading);
return card;
}
/// <summary>
/// Builds a small rounded badge tinted by a colour — used for item-type tags. The background is
/// a translucent wash of the colour with the text in the solid colour for legibility on dark.
/// </summary>
public static VisualElement Badge(string text, Color color)
{
Label badge = new Label(text);
badge.AddToClassList("ash-badge");
badge.style.color = color;
badge.style.backgroundColor = new Color(color.r, color.g, color.b, 0.16f);
return badge;
}
/// <summary>
/// Wraps a name text field in a row prefixed by a small pencil icon, signalling that the title
/// is editable. The field grows to fill the remaining width.
/// </summary>
public static VisualElement EditableNameRow(TextField nameField)
{
VisualElement row = new VisualElement();
row.AddToClassList("ash-namerow");
Texture pencil = EditorGUIUtility.IconContent("d_editicon.sml").image;
if (pencil == null) pencil = EditorGUIUtility.IconContent("editicon.sml").image;
if (pencil != null)
{
Image icon = new Image { image = pencil, scaleMode = ScaleMode.ScaleToFit };
icon.AddToClassList("ash-namerow__pencil");
row.Add(icon);
}
nameField.style.flexGrow = 1;
row.Add(nameField);
return row;
}
#endregion
}
}