Item HUD management

This commit is contained in:
Marco 2025-01-31 13:03:38 +01:00
commit 13c4489017
17 changed files with 215 additions and 44 deletions

View file

@ -41,7 +41,10 @@ public partial class GameManager : Node2D
_player.HealthChanged += (newHealth, maxHealth) => _hud.UpdateHealth(newHealth, maxHealth);
_player.InteractableAreaEntered += (interactable) => _hud.UpdateInteractable(interactable);
Inventory.ItemAdded += (item) => _hud.AddInventoryItem(item);
Inventory.ItemRemoved += (item) => _hud.RemoveInventoryItem(item);
//_player.Connect(nameof(_player.HealthChanged), _hud, nameof(_hud.UpdateHealth));
}

View file

@ -1,12 +1,13 @@
using Godot;
using System;
using Cirno.Scripts.Resources;
public partial class Hud : CanvasLayer
{
[Signal]
public delegate void StartGameEventHandler();
private Label _healthLabel;
//private Label _healthLabel;
[Export]
public PackedScene SelectorScene { get; set; }
@ -14,10 +15,13 @@ public partial class Hud : CanvasLayer
[Export]
private Node2D _selector;
[Export] private Label _healthLabel;
[Export] private Container _itemsContainer;
public override void _Ready()
{
// Assuming the HUD has a Label node named "HealthLabel"
_healthLabel = GetNode<Label>("HealthLabel");
//_healthLabel = GetNode<Label>("HealthLabel");
}
public void ShowMessage(string text)
@ -56,4 +60,17 @@ public partial class Hud : CanvasLayer
//_selector.Position = _selector.tolo
}
public void AddInventoryItem(LootItem item)
{
TextureRect texture = new TextureRect();
texture.Texture = item.InventorySprite;
_itemsContainer.AddChild(texture);
}
public void RemoveInventoryItem(LootItem item)
{
}
}

View file

@ -10,6 +10,12 @@ public partial class InventoryManager : Node2D
public bool RedKeycard { get; set; }
private List<LootItem> _items = new List<LootItem>();
[Signal]
public delegate void ItemAddedEventHandler(LootItem item);
[Signal]
public delegate void ItemRemovedEventHandler(LootItem item);
// Called when the node enters the scene tree for the first time.
public override void _Ready()
@ -33,8 +39,10 @@ public partial class InventoryManager : Node2D
public bool AddItem(ItemTypes type, int amount = 1)
{
_items.Add(new LootItem() { Item = type, Amount = amount });
var item = new LootItem() { Item = type, Amount = amount };
_items.Add(item);
GD.Print($"Added {type} x{amount}");
EmitSignal(nameof(ItemAdded), item);
// switch (type)
// {
// // case ItemTypes.KeycardRed:

View file

@ -8,4 +8,9 @@ public partial class LootItem : Resource
[Export] public ItemTypes Item;
[Export] public int Amount;
[Export] public int Max;
[Export] public bool PickupIfMaxed;
[Export] public bool ConsumeOnUse;
[Export] public AtlasTexture InventorySprite;
[Export] public SpriteFrames WorldSprite;
}