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
|
|
|
|
2024-05-30 14:16:22 -07:00
|
|
|
public partial class InventorySlot : Container
|
2023-12-31 05:59:33 -08:00
|
|
|
{
|
2024-05-30 14:16:22 -07:00
|
|
|
private bool _isSelected = false;
|
2023-12-31 05:59:33 -08:00
|
|
|
|
2024-05-30 14:16:22 -07:00
|
|
|
public bool IsSelected
|
|
|
|
{
|
|
|
|
get => _isSelected;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
_isSelected = value;
|
|
|
|
if (_selectedFrame is not null)
|
|
|
|
{
|
|
|
|
_selectedFrame.Visible = _isSelected;
|
|
|
|
_frame.Visible = !_isSelected;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private TextureRect _textureRect;
|
|
|
|
|
|
|
|
private NinePatchRect _frame;
|
2023-12-31 05:59:33 -08:00
|
|
|
|
2024-05-30 14:16:22 -07:00
|
|
|
private NinePatchRect _selectedFrame;
|
|
|
|
|
|
|
|
private 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");
|
|
|
|
}
|
|
|
|
|
2024-05-30 14:16:22 -07:00
|
|
|
public override void _Ready()
|
2023-12-31 05:59:33 -08:00
|
|
|
{
|
2024-05-30 14:16:22 -07:00
|
|
|
_textureRect = GetNode<TextureRect>("TextureRect");
|
|
|
|
_frame = GetNode<NinePatchRect>("Frame");
|
|
|
|
_selectedFrame = GetNode<NinePatchRect>("SelectedFrame");
|
2023-12-31 05:59:33 -08:00
|
|
|
}
|
|
|
|
}
|