(Feat) add crafting discovery + notification + inventory tool tips
This commit is contained in:
@@ -33,6 +33,9 @@ namespace Ashwild.Inventory
|
||||
[Header("Context Menu")]
|
||||
[SerializeField] private SlotContextMenu contextMenu;
|
||||
|
||||
[Header("Hover Description")]
|
||||
[SerializeField] private HoverDescriptionUI hoverDescription;
|
||||
|
||||
[Header("Categories")]
|
||||
[SerializeField] private InventoryCategoryManager categoryManager;
|
||||
|
||||
@@ -93,7 +96,7 @@ namespace Ashwild.Inventory
|
||||
int slotIndex = inventory.HotbarSize + i;
|
||||
GameObject slotGO = Instantiate(slotPrefab, slotContainer);
|
||||
SlotUI slotUI = slotGO.GetComponent<SlotUI>();
|
||||
slotUI.Initialize(slotIndex, OnSwapRequested, OnSlotClicked);
|
||||
slotUI.Initialize(slotIndex, OnSwapRequested, OnSlotClicked, OnSlotHoverEnter, OnSlotHoverExit);
|
||||
slotUIs[i] = slotUI;
|
||||
}
|
||||
|
||||
@@ -133,6 +136,9 @@ namespace Ashwild.Inventory
|
||||
if (contextMenu != null)
|
||||
contextMenu.Hide();
|
||||
|
||||
if (hoverDescription != null)
|
||||
hoverDescription.Hide();
|
||||
|
||||
if (categoryManager != null)
|
||||
categoryManager.Close();
|
||||
|
||||
@@ -192,6 +198,39 @@ namespace Ashwild.Inventory
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Builds the description payload for the hovered slot and shows the side panel. Empty slots
|
||||
/// keep the panel hidden. The duration bar reflects the item's remaining uses/durability.
|
||||
/// </summary>
|
||||
private void OnSlotHoverEnter(int index)
|
||||
{
|
||||
if (hoverDescription == null || inventory == null) 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 slot.
|
||||
/// </summary>
|
||||
private void OnSlotHoverExit()
|
||||
{
|
||||
if (hoverDescription != null)
|
||||
hoverDescription.Hide();
|
||||
}
|
||||
|
||||
private void RefreshSlot(int index)
|
||||
{
|
||||
if (slotUIs == null) return;
|
||||
|
||||
Reference in New Issue
Block a user