Add jewels but no implementation yet (needed redesign of inventory menu to function correctly)
72 lines
1.6 KiB
C#
72 lines
1.6 KiB
C#
using Chickensoft.AutoInject;
|
|
using Chickensoft.Collections;
|
|
using Chickensoft.Introspection;
|
|
using Godot;
|
|
using System;
|
|
using Zennysoft.Game.Abstractions;
|
|
using Zennysoft.Game.Implementation;
|
|
using Zennysoft.Ma.Adapter;
|
|
|
|
namespace Zennysoft.Game.Ma;
|
|
|
|
[Meta(typeof(IAutoNode))]
|
|
public partial class ItemSlot : Button, IItemSlot
|
|
{
|
|
public override void _Notification(int what) => this.Notify(what);
|
|
|
|
[Dependency] private IPlayer _player => this.DependOn<IPlayer>();
|
|
|
|
[Node] public Label Equipped { get; set; } = default!;
|
|
|
|
[Node] public TextureRect ItemTexture { get; set; } = default!;
|
|
|
|
public AutoProp<InventoryItem> Item { get; } = new AutoProp<InventoryItem>(default);
|
|
|
|
public event Action<IItemSlot> ItemPressed;
|
|
|
|
public event Action<IItemSlot> ItemSelected;
|
|
|
|
public bool IsSelected { get; set; } = false;
|
|
|
|
public void OnResolved()
|
|
{
|
|
Item.Changed += Item_Changed;
|
|
FocusEntered += ItemSlot_FocusEntered;
|
|
Pressed += ItemSlot_Pressed;
|
|
}
|
|
|
|
public void SetItemEquipmentStatus(bool isEquipped)
|
|
{
|
|
if (isEquipped)
|
|
Equipped.Text = "E";
|
|
else
|
|
Equipped.Text = string.Empty;
|
|
}
|
|
|
|
private void ItemSlot_FocusEntered() => ItemSelected?.Invoke(this);
|
|
|
|
private void ItemSlot_Pressed()
|
|
{
|
|
if (Item.Value == null)
|
|
return;
|
|
|
|
ItemPressed?.Invoke(this);
|
|
}
|
|
|
|
private void Item_Changed(InventoryItem obj)
|
|
{
|
|
if (obj == null)
|
|
return;
|
|
|
|
Text = obj.ItemName;
|
|
ItemTexture.Texture = obj.GetTexture();
|
|
|
|
if (Item.Value is EquipableItem equipableItem && _player.EquipmentComponent.IsItemEquipped(equipableItem))
|
|
{
|
|
Equipped.Text = "E";
|
|
}
|
|
else
|
|
Equipped.Text = string.Empty;
|
|
}
|
|
}
|