(Feat) Add build cost

This commit is contained in:
2026-07-14 14:25:02 +02:00
parent c9e923975d
commit 3657b870d8
27 changed files with 1270 additions and 990 deletions
+56
View File
@@ -0,0 +1,56 @@
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace Ashwild.UI
{
/// <summary>
/// One resource line of a build's cost, shown near the crosshair while placing: an icon plus an
/// "owned / required" count (e.g. 2/3). A pure, data-agnostic view — it is handed an icon, the two
/// numbers and an "affordable" flag and renders exactly that (tinting the count to signal a
/// shortfall), never resolving any domain data itself. CrosshairManager instantiates one of these
/// per cost line into its holder.
/// </summary>
[DisallowMultipleComponent]
public class BuildCostEntryUI : MonoBehaviour
{
#region Serialized Fields
[Header("References")]
[Tooltip("Icon of the required resource.")]
[SerializeField] private Image icon;
[Tooltip("Owned / required count for one placement (e.g. 2/3).")]
[SerializeField] private TMP_Text amountLabel;
[Header("Affordability Colours")]
[Tooltip("Amount colour when the player holds enough of this resource.")]
[SerializeField] private Color affordColor = Color.white;
[Tooltip("Amount colour when the player is short of this resource.")]
[SerializeField] private Color missingColor = new Color(1f, 0.35f, 0.35f);
#endregion
#region Public API
/// <summary>
/// Fills the line: sets the icon, the "owned / required" count, and tints it by affordability.
/// </summary>
public void Set(Sprite resourceIcon, int owned, int amount, bool affordable)
{
if (icon != null)
{
icon.sprite = resourceIcon;
icon.enabled = resourceIcon != null;
}
if (amountLabel != null)
{
amountLabel.text = $"{owned}/{amount}";
amountLabel.color = affordable ? affordColor : missingColor;
}
}
#endregion
}
}