fixed generic item on ground and added icon

This commit is contained in:
cblech
2025-05-20 20:42:32 +02:00
parent 8fdb395ae8
commit ec5d42068e
5 changed files with 137 additions and 10 deletions
@@ -6,11 +6,11 @@ public partial class InteractionArea2D : Node2D
{
[Export] private Area2D _area;
[Export] private Label _label;
[Export] private SpriteSwitcher2D _sprites;
[Export] private SpriteSwitcher2D _sprites; // TODO: remove
[Export] private bool _showLabel = true;
[Export] private int _id;
[Export] private int _id; // TODO: remove
[Signal] public delegate void InteractedToolEventHandler(int id);
[Signal] public delegate void InteractedToolEventHandler(int id); // TODO: remove
[Signal] public delegate void InteractedEventHandler();
public void OnPlayerEntered(Node2D player)
@@ -34,7 +34,7 @@ public partial class InteractionArea2D : Node2D
}
}
public void SetSpriteActiveState(bool success, int id)
public void SetSpriteActiveState(bool success, int id) // TODO: remove
{
if (_id == id)
{
@@ -11,6 +11,7 @@ public partial class ItemOnGround2D : Node
private Label _itemLabel => GetNode<Label>("ItemLabel");
private Label _pickupErrorLabel => GetNode<Label>("PickupErrorLabel");
private Sprite2D _iconSprite => GetNode<Sprite2D>("Icon");
public ItemInstance itemInstance
{
@@ -22,6 +23,12 @@ public partial class ItemOnGround2D : Node
}
}
public override void _Ready()
{
UpdateVisuals();
_pickupErrorLabel.Text = "";
}
public void TryPickUp()
{
GD.Print("Trying to pick up item");
@@ -45,6 +52,14 @@ public partial class ItemOnGround2D : Node
public void UpdateVisuals()
{
_itemLabel.Text = itemInstance.blueprint?.name ?? "Error Item";
}
}
_iconSprite.Texture = itemInstance?.blueprint?.icon;
if (_iconSprite.Texture == null)
{
_itemLabel.Text = itemInstance?.blueprint?.name ?? "Error Item";
}
else
{
_itemLabel.Text = "";
}
}
}
@@ -10,7 +10,7 @@ public partial class ItemOnGroundSpawnWith : Node
{
if(_blueprint == null) return;
var parent = GetParent<ItemOnGround>();
var parent = GetParent<ItemOnGround2D>();
parent.itemInstance = new ItemInstance { blueprint = _blueprint };
}
}