(Feat) add crafting discovery + notification + inventory tool tips
This commit is contained in:
@@ -30,6 +30,11 @@ namespace Ashwild.UI
|
||||
[SerializeField] private Color gainColor = new Color(0.45f, 1f, 0.45f); // picked up / added
|
||||
[SerializeField] private Color lossColor = new Color(1f, 0.45f, 0.45f); // dropped / consumed
|
||||
|
||||
[Header("Discovery")]
|
||||
[Tooltip("Badge shown in the number slot when a new item/recipe is discovered.")]
|
||||
[SerializeField] private string discoveryLabel = "NEW";
|
||||
[SerializeField] private Color discoveryColor = new Color(1f, 0.85f, 0.3f);
|
||||
|
||||
private readonly List<NotificationItemUI> activeNotifications = new List<NotificationItemUI>();
|
||||
|
||||
private void OnEnable()
|
||||
@@ -37,6 +42,7 @@ namespace Ashwild.UI
|
||||
PlayerEvents.ItemAdded += OnItemAdded;
|
||||
PlayerEvents.ItemDropped += OnItemDropped;
|
||||
PlayerEvents.ItemConsumed += OnItemConsumed;
|
||||
PlayerEvents.RecipeDiscovered += OnRecipeDiscovered;
|
||||
PlayerEvents.FoodPlacedToCook += OnItemSpent;
|
||||
PlayerEvents.FuelAdded += OnItemSpent;
|
||||
}
|
||||
@@ -46,6 +52,7 @@ namespace Ashwild.UI
|
||||
PlayerEvents.ItemAdded -= OnItemAdded;
|
||||
PlayerEvents.ItemDropped -= OnItemDropped;
|
||||
PlayerEvents.ItemConsumed -= OnItemConsumed;
|
||||
PlayerEvents.RecipeDiscovered -= OnRecipeDiscovered;
|
||||
PlayerEvents.FoodPlacedToCook -= OnItemSpent;
|
||||
PlayerEvents.FuelAdded -= OnItemSpent;
|
||||
}
|
||||
@@ -53,6 +60,7 @@ namespace Ashwild.UI
|
||||
private void OnItemAdded(ItemData item, int quantity) => Push(item, quantity);
|
||||
private void OnItemDropped(ItemData item, int quantity) => Push(item, -quantity);
|
||||
private void OnItemConsumed(ItemData item) => Push(item, -1);
|
||||
private void OnRecipeDiscovered(Sprite icon, string recipeName) => PushDiscovery(icon, recipeName);
|
||||
|
||||
// Food placed on a cooking station or fuel fed to it both leave the inventory by one.
|
||||
private void OnItemSpent(ItemData item) => Push(item, -1);
|
||||
@@ -69,7 +77,8 @@ namespace Ashwild.UI
|
||||
// Merge only with a notification for the same item AND same direction
|
||||
for (int i = 0; i < activeNotifications.Count; i++)
|
||||
{
|
||||
if (activeNotifications[i] != null && activeNotifications[i].ItemData == item
|
||||
if (activeNotifications[i] != null && !activeNotifications[i].IsDiscovery
|
||||
&& activeNotifications[i].ItemData == item
|
||||
&& activeNotifications[i].IsGain == gain)
|
||||
{
|
||||
activeNotifications[i].AddQuantity(signedQuantity, displayDuration);
|
||||
@@ -94,6 +103,29 @@ namespace Ashwild.UI
|
||||
activeNotifications.Add(notification);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pushes a one-time "NEW" notification for a newly unlocked recipe: its result icon and name
|
||||
/// with the configured badge in the discovery colour. Never merges with anything.
|
||||
/// </summary>
|
||||
private void PushDiscovery(Sprite icon, string recipeName)
|
||||
{
|
||||
activeNotifications.RemoveAll(n => n == null);
|
||||
|
||||
GameObject go = Instantiate(notificationPrefab, container);
|
||||
NotificationItemUI notification = go.GetComponent<NotificationItemUI>();
|
||||
|
||||
float targetY = startOffsetY + activeNotifications.Count * (notificationHeight + spacing);
|
||||
|
||||
RectTransform rt = notification.RectTransform;
|
||||
rt.anchoredPosition = new Vector2(0f, targetY - 30f);
|
||||
|
||||
notification.InitializeDiscovery(icon, recipeName, discoveryLabel, discoveryColor, displayDuration, slideInDuration);
|
||||
|
||||
rt.DOAnchorPosY(targetY, slideInDuration).SetEase(slideInEase);
|
||||
|
||||
activeNotifications.Add(notification);
|
||||
}
|
||||
|
||||
private void LateUpdate()
|
||||
{
|
||||
// Clean up destroyed notifications and reposition remaining ones
|
||||
|
||||
Reference in New Issue
Block a user