(Feat) add crafting discovery + notification + inventory tool tips
This commit is contained in:
@@ -24,6 +24,10 @@ namespace Ashwild.Inventory
|
||||
[Header("Context Menu")]
|
||||
[SerializeField] private SlotContextMenu contextMenu;
|
||||
|
||||
[Header("Hover Description")]
|
||||
[Tooltip("Same panel used by the inventory — assign the shared HoverDescriptionUI here too.")]
|
||||
[SerializeField] private HoverDescriptionUI hoverDescription;
|
||||
|
||||
private PlayerInventory inventory;
|
||||
private Tweener scaleTween;
|
||||
private Tweener alphaTween;
|
||||
@@ -51,7 +55,7 @@ namespace Ashwild.Inventory
|
||||
{
|
||||
// Visual setup that does not need the player.
|
||||
for (int i = 0; i < hotbarSlot.Length; i++)
|
||||
hotbarSlot[i].Initialize(i, InventoryUI.OnSwapRequested, OnSlotClicked);
|
||||
hotbarSlot[i].Initialize(i, InventoryUI.OnSwapRequested, OnSlotClicked, OnSlotHoverEnter, OnSlotHoverExit);
|
||||
|
||||
transform.localScale = Vector3.one * idleScale;
|
||||
if (canvasGroup != null)
|
||||
@@ -167,6 +171,40 @@ namespace Ashwild.Inventory
|
||||
hotbarSlot[index].UpdateVisual(inventory.GetSlot(index));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Shows the shared description panel for a hovered hotbar slot, but only while the inventory
|
||||
/// is open — during normal play the hotbar must not pop a description. The duration bar
|
||||
/// reflects the item's remaining uses/durability.
|
||||
/// </summary>
|
||||
private void OnSlotHoverEnter(int index)
|
||||
{
|
||||
if (hoverDescription == null || inventory == null || !PlayerEvents.IsInventoryOpen) return;
|
||||
|
||||
InventorySlot slot = inventory.GetSlot(index);
|
||||
if (slot == null || slot.IsEmpty)
|
||||
{
|
||||
hoverDescription.Hide();
|
||||
return;
|
||||
}
|
||||
|
||||
ItemData item = slot.ItemData;
|
||||
bool hasDuration = item.HasUses;
|
||||
float fill = hasDuration ? (float)slot.CurrentUses / item.MaxUses : 0f;
|
||||
string durationText = hasDuration ? $"{slot.CurrentUses} / {item.MaxUses}" : string.Empty;
|
||||
|
||||
hoverDescription.Show(new ItemDescriptionView(
|
||||
item.Icon, item.ItemName, item.Description, hasDuration, fill, durationText));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Hides the description panel when the pointer leaves a hotbar slot.
|
||||
/// </summary>
|
||||
private void OnSlotHoverExit()
|
||||
{
|
||||
if (hoverDescription != null)
|
||||
hoverDescription.Hide();
|
||||
}
|
||||
|
||||
private void UpdateSelection(int selectedIndex)
|
||||
{
|
||||
for (int i = 0; i < hotbarSlot.Length; i++)
|
||||
|
||||
Reference in New Issue
Block a user