(Feat) Item Dqta

This commit is contained in:
2026-06-25 14:40:21 +02:00
parent 3597bacb1a
commit 931bc9c9e2
10 changed files with 372 additions and 20 deletions
+36
View File
@@ -13,6 +13,16 @@ namespace Ashwild.Inventory
[SerializeField] private TextMeshProUGUI quantityText;
[SerializeField] private Image highlightImage;
[Header("Uses Bar")]
[Tooltip("Root object of the uses/durability bar — shown only for items that track uses.")]
[SerializeField] private GameObject usageBarRoot;
[Tooltip("Filled image whose fillAmount maps to the remaining uses (Image Type = Filled).")]
[SerializeField] private Image usageBarFill;
[Tooltip("Icon tint applied when the item still has uses left.")]
[SerializeField] private Color normalTint = Color.white;
[Tooltip("Icon (and bar) tint applied when the item is depleted — a broken repairable tool / empty container.")]
[SerializeField] private Color depletedTint = Color.red;
private int slotIndex;
private Action<int, int> onSwapRequested;
private Action<int, bool> onClicked;
@@ -40,12 +50,17 @@ namespace Ashwild.Inventory
onClicked = clickCallback;
}
/// <summary>
/// Redraws the slot: icon, quantity, and the uses bar. Uses-tracked items (tools, multi-bite
/// food) show a fill bar for their remaining uses and turn red once depleted.
/// </summary>
public void UpdateVisual(InventorySlot slot)
{
if (slot == null || slot.IsEmpty)
{
iconImage.gameObject.SetActive(false);
quantityText.gameObject.SetActive(false);
if (usageBarRoot != null) usageBarRoot.SetActive(false);
}
else
{
@@ -55,9 +70,30 @@ namespace Ashwild.Inventory
quantityText.gameObject.SetActive(showQty);
if (showQty)
quantityText.text = slot.Quantity.ToString();
UpdateUsageBar(slot);
}
}
/// <summary>
/// Shows the uses bar and tints the icon red when the item is depleted; hides the bar entirely
/// for items that do not track uses. Preserves the current icon alpha so a mid-drag fade stays.
/// </summary>
private void UpdateUsageBar(InventorySlot slot)
{
bool hasUses = slot.ItemData.HasUses;
if (usageBarRoot != null)
usageBarRoot.SetActive(hasUses);
Color tint = (hasUses && slot.IsDepleted) ? depletedTint : normalTint;
tint.a = iconImage.color.a;
iconImage.color = tint;
if (hasUses && usageBarFill != null)
usageBarFill.fillAmount = (float)slot.CurrentUses / slot.ItemData.MaxUses;
}
public void SetSelected(bool selected)
{
if (highlightImage != null)