Item Notifications

This commit is contained in:
Marco 2025-03-06 15:03:14 +01:00
commit 0438ed4a04
8 changed files with 98 additions and 25 deletions

View file

@ -19,7 +19,12 @@ public partial class Hud : CanvasLayer
[Export]
public PackedScene WeaponContainerTemplate { get; private set; }
[Export]
public PackedScene ItemNotificationTemplate { get; private set; }
[Export] public float ItemsNotificationTimeout { get; private set; } = 3f;
[Export]
private Node2D _selector;
@ -60,8 +65,19 @@ public partial class Hud : CanvasLayer
// Assuming the HUD has a Label node named "HealthLabel"
//_healthLabel = GetNode<Label>("HealthLabel");
_gameOverPanel.Hide();
InventoryManager.Instance.ItemAdded += OnItemAdded;
}
private void OnItemAdded(LootItem item, int currentamount)
{
var instance = ItemNotificationTemplate.Instantiate<ItemNotification>();
_itemsContainer.CallDeferred("add_child", instance);
instance.Init(item, currentamount, ItemsNotificationTimeout);
}
public void ShowMessage(string text)
{
var message = GetNode<Label>("Message");

View file

@ -0,0 +1,40 @@
using Cirno.Scripts.Resources;
using Godot;
namespace Cirno.Scripts.UI;
public partial class ItemNotification : Container
{
public LootItem Item { get; private set; }
[Export]
public TextureRect Icon { get; private set; }
[Export]
public Label DescriptionLabel { get; private set; }
private double _counter = 0;
private double _timeout = 0;
public override void _Process(double delta)
{
_counter += delta;
if (_counter >= _timeout)
{
QueueFree();
}
}
public void Init(LootItem item, int total, float timeout)
{
_timeout = timeout;
_counter = 0;
Item = item;
UpdateCounter(item, total);
}
private void UpdateCounter(LootItem item, int total)
{
DescriptionLabel.Text = $"{item.ItemName} +{item.Amount} ({total})";
Icon.Texture = item.InventorySprite;
}
}

View file

@ -0,0 +1 @@
uid://bysbukjjv8nc2

View file

@ -3,7 +3,7 @@ using Godot;
namespace Cirno.Scripts.UI;
public partial class WeaponAmmoCounter : Control
public partial class WeaponAmmoCounter : Container
{
public LootItem Item { get; private set; }