Merge remote-tracking branch 'origin/feat/inport-props' into feat/craft-discovery
# Conflicts: # Assets/External/Animated PBR Chest Demo/Materials/WoodChest.mat # Packages/com.distantlands.cozy.core/Content/Integration/Import for BiRP.unitypackage.meta # Packages/com.distantlands.cozy.core/Content/Integration/Import for HDRP.unitypackage.meta # Packages/com.distantlands.cozy.core/Content/Integration/Import for URP.unitypackage.meta
This commit is contained in:
@@ -20,6 +20,7 @@ namespace Ashwild.UI
|
||||
private float hideTimer;
|
||||
private bool isHiding;
|
||||
private bool isDiscovery;
|
||||
private string message;
|
||||
|
||||
private Tweener fadeTween;
|
||||
private Tweener slideTween;
|
||||
@@ -34,6 +35,10 @@ namespace Ashwild.UI
|
||||
// A discovery notification (icon + name + "NEW" badge) never merges with a gain/loss one.
|
||||
public bool IsDiscovery => isDiscovery;
|
||||
|
||||
// The refusal text this notification shows, or null when it is not a message — used to collapse
|
||||
// repeats of the same reason onto the line already on screen.
|
||||
public string Message => message;
|
||||
|
||||
public void Initialize(ItemData item, int signedQuantity, Color numberColor, float displayDuration, float slideInDuration, Ease slideInEase)
|
||||
{
|
||||
itemData = item;
|
||||
@@ -81,6 +86,52 @@ namespace Ashwild.UI
|
||||
fadeTween = canvasGroup.DOFade(1f, slideInDuration).SetEase(Ease.OutQuad);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets up a plain message notification: a reason (e.g. "Inventory full") with no icon and no
|
||||
/// number, tinted by the caller. It carries no item, so it never merges with a gain/loss — a
|
||||
/// refusal is a one-off statement, not a running total.
|
||||
/// </summary>
|
||||
public void InitializeMessage(string text, Color messageColor, float displayDuration, float slideInDuration)
|
||||
{
|
||||
itemData = null;
|
||||
isDiscovery = true;
|
||||
message = text;
|
||||
hideTimer = displayDuration;
|
||||
isHiding = false;
|
||||
|
||||
if (iconImage != null)
|
||||
iconImage.gameObject.SetActive(false);
|
||||
|
||||
if (labelText != null)
|
||||
{
|
||||
labelText.text = text;
|
||||
labelText.color = messageColor;
|
||||
}
|
||||
|
||||
if (numberText != null)
|
||||
numberText.text = string.Empty;
|
||||
|
||||
canvasGroup.alpha = 0f;
|
||||
fadeTween = canvasGroup.DOFade(1f, slideInDuration).SetEase(Ease.OutQuad);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Restarts the display timer of a message already on screen, so repeating the same refused
|
||||
/// action keeps one line alive instead of queueing a duplicate behind it.
|
||||
/// </summary>
|
||||
public void RefreshMessage(float displayDuration)
|
||||
{
|
||||
hideTimer = displayDuration;
|
||||
|
||||
if (isHiding)
|
||||
{
|
||||
isHiding = false;
|
||||
fadeTween?.Kill();
|
||||
slideTween?.Kill();
|
||||
canvasGroup.alpha = 1f;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddQuantity(int signedAmount, float displayDuration)
|
||||
{
|
||||
totalQuantity += signedAmount;
|
||||
|
||||
@@ -59,6 +59,7 @@ namespace Ashwild.UI
|
||||
private class PendingNotification
|
||||
{
|
||||
public bool isDiscovery;
|
||||
public bool isMessage;
|
||||
public ItemData item;
|
||||
public int signedQuantity;
|
||||
public Sprite icon;
|
||||
@@ -71,6 +72,7 @@ namespace Ashwild.UI
|
||||
PlayerEvents.ItemDropped += OnItemDropped;
|
||||
PlayerEvents.ItemConsumed += OnItemConsumed;
|
||||
PlayerEvents.RecipeDiscovered += OnRecipeDiscovered;
|
||||
PlayerEvents.InteractionRefused += OnInteractionRefused;
|
||||
PlayerEvents.FoodPlacedToCook += OnItemSpent;
|
||||
PlayerEvents.FuelAdded += OnItemSpent;
|
||||
}
|
||||
@@ -81,6 +83,7 @@ namespace Ashwild.UI
|
||||
PlayerEvents.ItemDropped -= OnItemDropped;
|
||||
PlayerEvents.ItemConsumed -= OnItemConsumed;
|
||||
PlayerEvents.RecipeDiscovered -= OnRecipeDiscovered;
|
||||
PlayerEvents.InteractionRefused -= OnInteractionRefused;
|
||||
PlayerEvents.FoodPlacedToCook -= OnItemSpent;
|
||||
PlayerEvents.FuelAdded -= OnItemSpent;
|
||||
}
|
||||
@@ -98,6 +101,7 @@ namespace Ashwild.UI
|
||||
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);
|
||||
private void OnInteractionRefused(string reason) => PushMessage(reason);
|
||||
|
||||
// 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);
|
||||
@@ -146,6 +150,33 @@ namespace Ashwild.UI
|
||||
Enqueue(new PendingNotification { isDiscovery = true, icon = icon, label = recipeName });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enqueues a plain message telling the player why an interaction gave them nothing ("Inventory
|
||||
/// full"). Collapses onto an identical message that is still on screen — spamming the interact key
|
||||
/// against a full inventory must refresh one line, not stack ten of them — and is tinted with the
|
||||
/// loss colour, since it always reports something the player did not get.
|
||||
/// </summary>
|
||||
private void PushMessage(string message)
|
||||
{
|
||||
if (string.IsNullOrEmpty(message)) return;
|
||||
|
||||
activeNotifications.RemoveAll(n => n == null);
|
||||
|
||||
for (int i = 0; i < activeNotifications.Count; i++)
|
||||
{
|
||||
if (activeNotifications[i] != null && activeNotifications[i].Message == message)
|
||||
{
|
||||
activeNotifications[i].RefreshMessage(displayDuration);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
foreach (PendingNotification pending in pendingQueue)
|
||||
if (pending.isMessage && pending.label == message) return;
|
||||
|
||||
Enqueue(new PendingNotification { isMessage = true, label = message });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Adds a pending notification to the queue, dropping the oldest waiting one when the queue is
|
||||
/// full so the most recent notifications are never lost.
|
||||
@@ -189,7 +220,9 @@ namespace Ashwild.UI
|
||||
RectTransform rt = notification.RectTransform;
|
||||
rt.anchoredPosition = new Vector2(0f, targetY - 30f);
|
||||
|
||||
if (pending.isDiscovery)
|
||||
if (pending.isMessage)
|
||||
notification.InitializeMessage(pending.label, lossColor, displayDuration, slideInDuration);
|
||||
else if (pending.isDiscovery)
|
||||
notification.InitializeDiscovery(pending.icon, pending.label, discoveryLabel, discoveryColor, displayDuration, slideInDuration);
|
||||
else
|
||||
notification.Initialize(pending.item, pending.signedQuantity, pending.signedQuantity > 0 ? gainColor : lossColor, displayDuration, slideInDuration, slideInEase);
|
||||
|
||||
Reference in New Issue
Block a user