Fix inventory menu, add armor as equippable item
This commit is contained in:
@@ -29,7 +29,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
var label = new WeaponLabel(item) { Text = item.Name };
|
||||
var label = new ItemLabel(item) { Text = item.Name };
|
||||
ItemList.AddChild(label);
|
||||
}
|
||||
|
||||
@@ -41,9 +41,15 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
{
|
||||
if (ItemList.GetChildCount() > 0)
|
||||
{
|
||||
var currentItem = ItemList.GetChild<Control>(_currentSelection);
|
||||
var currentItem = ItemList.GetChild<ItemLabel>(_currentSelection);
|
||||
SetCursorLocation(currentItem);
|
||||
}
|
||||
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem == GameRepo.EquippedWeapon || item.InventoryItem == GameRepo.EquippedArmor)
|
||||
item.EquipItem();
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearItems()
|
||||
@@ -86,11 +92,6 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
}
|
||||
}
|
||||
|
||||
private void UnequipItem(WeaponLabel item)
|
||||
{
|
||||
item.UnequipItem();
|
||||
}
|
||||
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
var input = Vector2.Zero;
|
||||
@@ -98,12 +99,67 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
SetCursorToPrevious();
|
||||
if (Input.IsActionJustPressed(GameInputs.MoveDown))
|
||||
SetCursorToNext();
|
||||
if (Input.IsActionJustPressed(GameInputs.Attack))
|
||||
EquipOrUnequipCurrentItem();
|
||||
}
|
||||
|
||||
public void EquipOrUnequipCurrentItem()
|
||||
{
|
||||
if (ItemList.GetChildCount() == 0)
|
||||
return;
|
||||
|
||||
var currentlySelectedItem = ItemList.GetChild<ItemLabel>(_currentSelection);
|
||||
|
||||
if (currentlySelectedItem.InventoryItem is WeaponInfo weapon && GameRepo.EquippedWeapon == weapon)
|
||||
{
|
||||
UnequipItem(currentlySelectedItem);
|
||||
GameRepo.OnWeaponEquipped(WeaponInfo.Default);
|
||||
}
|
||||
else if (currentlySelectedItem.InventoryItem is ArmorInfo armor && GameRepo.EquippedArmor == armor)
|
||||
{
|
||||
UnequipItem(currentlySelectedItem);
|
||||
GameRepo.OnArmorEquipped(null);
|
||||
}
|
||||
else
|
||||
EquipItem(currentlySelectedItem);
|
||||
}
|
||||
|
||||
private void EquipItem(ItemLabel currentItem)
|
||||
{
|
||||
if (currentItem.InventoryItem is WeaponInfo weaponInfo)
|
||||
{
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem is WeaponInfo)
|
||||
UnequipItem(item);
|
||||
}
|
||||
|
||||
GameRepo.OnWeaponEquipped(weaponInfo);
|
||||
currentItem.EquipItem();
|
||||
}
|
||||
|
||||
if (currentItem.InventoryItem is ArmorInfo armorInfo)
|
||||
{
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem is ArmorInfo)
|
||||
UnequipItem(item);
|
||||
}
|
||||
|
||||
GameRepo.OnArmorEquipped(armorInfo);
|
||||
currentItem.EquipItem();
|
||||
}
|
||||
}
|
||||
|
||||
private void UnequipItem(ItemLabel item)
|
||||
{
|
||||
item.UnequipItem();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class WeaponLabel : Label
|
||||
public partial class ItemLabel : Label
|
||||
{
|
||||
public WeaponLabel(InventoryItemInfo inventoryItem)
|
||||
public ItemLabel(InventoryItemInfo inventoryItem)
|
||||
{
|
||||
InventoryItem = inventoryItem;
|
||||
LabelSettings = UnequippedItemFont;
|
||||
@@ -111,8 +167,8 @@ public partial class WeaponLabel : Label
|
||||
|
||||
public InventoryItemInfo InventoryItem { get; set; } = default!;
|
||||
|
||||
private static LabelSettings UnequippedItemFont => GD.Load<LabelSettings>("res://src/vfx/Fonts/InventoryLabelSettings.tres");
|
||||
private static LabelSettings EquippedItemFont => GD.Load<LabelSettings>("res://src/vfx/Fonts/EquippedInventoryLabelSettings.tres");
|
||||
private static LabelSettings UnequippedItemFont => GD.Load<LabelSettings>("res://src/inventory_menu/InventoryLabelSettings.tres");
|
||||
private static LabelSettings EquippedItemFont => GD.Load<LabelSettings>("res://src/inventory_menu/EquippedInventoryLabelSettings.tres");
|
||||
|
||||
public void EquipItem()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user