SupaLidlGame/UI/Inventory/InventorySlot.cs

53 lines
1.0 KiB
C#
Raw Normal View History

2023-12-31 05:59:33 -08:00
using Godot;
using GodotUtilities;
using GodotUtilities.SourceGenerators;
2024-05-29 14:55:23 -07:00
namespace SupaLidlGame.UI.Inventory;
2023-12-31 05:59:33 -08:00
[Scene]
public partial class InventorySlot : ColorRect
{
[Node("TextureRect")]
2024-05-29 14:55:23 -07:00
protected TextureRect _textureRect;
2023-12-31 05:59:33 -08:00
[Node("Selected")]
2024-05-29 14:55:23 -07:00
protected NinePatchRect _frame;
2023-12-31 05:59:33 -08:00
2024-05-29 14:55:23 -07:00
protected static Texture2D _placeholderTexture;
2023-12-31 05:59:33 -08:00
private Items.ItemMetadata _item;
public Items.ItemMetadata Item
{
get => _item;
set
{
_item = value;
if (_item is null)
{
2024-01-01 22:55:53 -08:00
_textureRect.Texture = null;
2023-12-31 05:59:33 -08:00
}
else
{
_textureRect.Texture = _item.Icon;
}
}
}
static InventorySlot()
{
_placeholderTexture = ResourceLoader.Load<Texture2D>(
"res://Assets/Sprites/UI/hotbar-inactive.png");
}
public override void _Notification(int what)
{
if (what == NotificationSceneInstantiated)
{
WireNodes();
}
base._Notification(what);
}
}