Big fix of inventory system, add accessory item type
This commit is contained in:
@@ -7,7 +7,7 @@ using System.Collections.Generic;
|
||||
|
||||
public interface IInventoryMenu : IControl
|
||||
{
|
||||
public void PopulateItems(List<InventoryItemInfo> items);
|
||||
public void PopulateItems(List<InventoryItem> items);
|
||||
|
||||
public void ClearItems();
|
||||
}
|
||||
@@ -25,11 +25,11 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
private int _currentSelection = 0;
|
||||
|
||||
public void PopulateItems(List<InventoryItemInfo> items)
|
||||
public void PopulateItems(List<InventoryItem> items)
|
||||
{
|
||||
foreach (var item in items)
|
||||
{
|
||||
var label = new ItemLabel(item) { Text = item.Name };
|
||||
var label = new ItemLabel(item) { Text = item.Info.Name };
|
||||
ItemList.AddChild(label);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem == GameRepo.EquippedWeapon || item.InventoryItem == GameRepo.EquippedArmor)
|
||||
if (item.InventoryItem == GameRepo.EquippedWeapon || item.InventoryItem == GameRepo.EquippedArmor || item.InventoryItem == GameRepo.EquippedAccessory)
|
||||
item.EquipItem();
|
||||
}
|
||||
}
|
||||
@@ -110,62 +110,78 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
var currentlySelectedItem = ItemList.GetChild<ItemLabel>(_currentSelection);
|
||||
|
||||
if (currentlySelectedItem.InventoryItem is WeaponInfo weapon && GameRepo.EquippedWeapon == weapon)
|
||||
if (currentlySelectedItem.InventoryItem is Weapon weapon && GameRepo.EquippedWeapon == weapon)
|
||||
{
|
||||
UnequipItem(currentlySelectedItem);
|
||||
GameRepo.OnWeaponEquipped(WeaponInfo.Default);
|
||||
GameRepo.OnWeaponEquipped(new Weapon());
|
||||
}
|
||||
else if (currentlySelectedItem.InventoryItem is ArmorInfo armor && GameRepo.EquippedArmor == armor)
|
||||
else if (currentlySelectedItem.InventoryItem is Armor armor && GameRepo.EquippedArmor == armor)
|
||||
{
|
||||
UnequipItem(currentlySelectedItem);
|
||||
GameRepo.OnArmorEquipped(null);
|
||||
}
|
||||
else if (currentlySelectedItem.InventoryItem is Accessory accessory && GameRepo.EquippedAccessory == accessory)
|
||||
{
|
||||
UnequipItem(currentlySelectedItem);
|
||||
GameRepo.OnAccessoryEquipped(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 EquipItem(ItemLabel currentItem) => EquipItemInternal(currentItem, (dynamic)currentItem.InventoryItem);
|
||||
|
||||
private void UnequipItem(ItemLabel item)
|
||||
{
|
||||
item.UnequipItem();
|
||||
}
|
||||
|
||||
private void EquipItemInternal(ItemLabel currentItem, Accessory accessory)
|
||||
{
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem is Accessory)
|
||||
UnequipItem(item);
|
||||
}
|
||||
|
||||
GameRepo.OnAccessoryEquipped(accessory);
|
||||
currentItem.EquipItem();
|
||||
}
|
||||
|
||||
private void EquipItemInternal(ItemLabel currentItem, Armor armor)
|
||||
{
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem is Armor)
|
||||
UnequipItem(item);
|
||||
}
|
||||
|
||||
GameRepo.OnArmorEquipped(armor);
|
||||
currentItem.EquipItem();
|
||||
}
|
||||
|
||||
private void EquipItemInternal(ItemLabel currentItem, Weapon weapon)
|
||||
{
|
||||
foreach (ItemLabel item in ItemList.GetChildren())
|
||||
{
|
||||
if (item.InventoryItem is Weapon)
|
||||
UnequipItem(item);
|
||||
}
|
||||
|
||||
GameRepo.OnWeaponEquipped(weapon);
|
||||
currentItem.EquipItem();
|
||||
}
|
||||
}
|
||||
|
||||
public partial class ItemLabel : Label
|
||||
{
|
||||
public ItemLabel(InventoryItemInfo inventoryItem)
|
||||
public ItemLabel(InventoryItem inventoryItem)
|
||||
{
|
||||
InventoryItem = inventoryItem;
|
||||
LabelSettings = UnequippedItemFont;
|
||||
}
|
||||
|
||||
public InventoryItemInfo InventoryItem { get; set; } = default!;
|
||||
public InventoryItem InventoryItem { get; set; } = default!;
|
||||
|
||||
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");
|
||||
|
||||
Reference in New Issue
Block a user