Fix up equipping inventory items, fill out the rest of the inventory labels

This commit is contained in:
2024-09-09 23:05:44 -07:00
parent 4986cca661
commit b5798e7bc0
17 changed files with 340 additions and 108 deletions

View File

@@ -54,15 +54,65 @@ public partial class InventoryMenu : Control, IInventoryMenu
private int _currentIndex = 0;
private ItemSlot[] ItemSlots => ItemsPage.GetChildren().OfType<ItemSlot>().ToArray();
private static LabelSettings ItemFont => GD.Load<LabelSettings>("res://src/ui/label_settings/MainTextRegular.tres");
private static LabelSettings SelectedItemFont => GD.Load<LabelSettings>("res://src/ui/label_settings/MainTextFontItalicized.tres");
private static LabelSettings EquippedItemFont => GD.Load<LabelSettings>("res://src/ui/label_settings/MainTextFontEquipped.tres");
private static LabelSettings SelectedEquippedItemFont => GD.Load<LabelSettings>("res://src/ui/label_settings/MainTextFontSelectedEquipped.tres");
private IItemSlot[] ItemSlots => ItemsPage.GetChildren().OfType<IItemSlot>().ToArray();
public void PopulateItems()
{
PopulatePlayerInfo();
PopulateInventory();
}
public void PopulatePlayerInfo()
{
FloorLabel.Text = $"Floor 0";
var currentLevel = GameRepo.PlayerStatInfo.Value.CurrentLevel;
CurrentLevelLabel.Text = $"Level {currentLevel:D2}";
var currentHP = GameRepo.PlayerStatInfo.Value.CurrentHP;
var maxHP = GameRepo.PlayerStatInfo.Value.MaximumHP;
HPValue.Text = $"{currentHP}/{maxHP}";
var currentVT = GameRepo.PlayerStatInfo.Value.CurrentVT;
var maxVT = GameRepo.PlayerStatInfo.Value.MaximumVT;
VTValue.Text = $"{currentVT}/{maxVT}";
var currentAttack = GameRepo.PlayerStatInfo.Value.CurrentAttack;
var maxAttack = GameRepo.PlayerStatInfo.Value.MaxAttack;
ATKValue.Text = $"{currentAttack}/{maxAttack}";
var currentDefense = GameRepo.PlayerStatInfo.Value.CurrentDefense;
var maxDefense = GameRepo.PlayerStatInfo.Value.MaxDefense;
DEFValue.Text = $"{currentDefense}/{maxDefense}";
var atkBonus = GameRepo.PlayerStatInfo.Value.BonusAttack;
var defBonus = GameRepo.PlayerStatInfo.Value.BonusDefense;
ATKBonusLabel.Text = atkBonus != 0 ? $"{atkBonus}" : "...";
DEFBonusLabel.Text = defBonus != 0 ? $"{defBonus}" : "...";
// TODO: Change font style when EXP Bonus effect is active
var currentExp = GameRepo.PlayerStatInfo.Value.CurrentEXP;
var expToNextLevel = GameRepo.PlayerStatInfo.Value.EXPToNextLevel;
EXPValue.Text = $"{currentExp}/{expToNextLevel}";
if (ItemSlots.Any())
{
ItemDescriptionTitle.Text = $"{ItemSlots.ElementAtOrDefault(_currentIndex).Item.Info.Name}";
ItemEffectLabel.Text = $"{ItemSlots.ElementAtOrDefault(_currentIndex).Item.Info.Description}";
}
else
{
ItemDescriptionTitle.Text = string.Empty;
ItemEffectLabel.Text = string.Empty;
}
}
private void PopulateInventory()
{
var inventory = GameRepo.InventoryItems.Value;
var numberOfItemsToDisplay = _currentPageNumber == InventoryPageNumber.FirstPage ? Mathf.Min(inventory.Count, _itemsPerPage) : Mathf.Min(inventory.Count - _itemsPerPage, _itemsPerPage);
@@ -88,15 +138,19 @@ public partial class InventoryMenu : Control, IInventoryMenu
var item = inventory.ElementAt(i + indexToStart);
var itemScene = GD.Load<PackedScene>(ITEM_SLOT_SCENE);
var itemSlot = itemScene.Instantiate<IItemSlot>();
itemSlot.Item = item;
ItemsPage.AddChildEx(itemSlot);
itemSlot.ItemName.Text = item.Info.Name;
itemSlot.ItemTexture.Texture = item.Info.Texture;
itemSlot.EquipBonus.Text = "...";
if (itemSlot.Item is IEquipable equipable && GameRepo.IsItemEquipped(equipable))
itemSlot.SetEquippedItemStyle();
}
if (ItemSlots.Any())
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = SelectedItemFont;
{
ItemSlots.ElementAt(_currentIndex).SetSelectedItemStyle();
if (ItemSlots.ElementAt(_currentIndex).Item is IEquipable equipable && GameRepo.IsItemEquipped(equipable))
ItemSlots.ElementAt(_currentIndex).SetEquippedSelectedItemStyle();
}
}
public override void _UnhandledInput(InputEvent @event)
@@ -120,31 +174,53 @@ public partial class InventoryMenu : Control, IInventoryMenu
if (ItemSlots.Any() && Input.IsActionJustPressed(GameInputs.UiDown))
{
if (!inventory.Any() || _currentIndex + 1 >= _itemsPerPage)
if (!inventory.Any())
return;
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = ItemFont;
_currentIndex++;
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = SelectedItemFont;
var oldItem = ItemSlots.ElementAt(_currentIndex);
ItemSlots.ElementAt(_currentIndex).SetItemStyle();
var index = new[] { _currentIndex + 1, _itemsPerPage - 1, ItemSlots.Count() - 1 };
_currentIndex = index.Min();
var newItem = ItemSlots.ElementAt(_currentIndex);
newItem.SetSelectedItemStyle();
if (oldItem.Item is IEquipable equipable && GameRepo.IsItemEquipped(equipable))
oldItem.SetEquippedItemStyle();
if (newItem.Item is IEquipable newEquipable && GameRepo.IsItemEquipped(newEquipable))
newItem.SetEquippedSelectedItemStyle();
}
if (ItemSlots.Any() && Input.IsActionJustPressed(GameInputs.UiUp))
{
if (!inventory.Any() || _currentIndex <= 0)
if (!inventory.Any())
return;
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = ItemFont;
_currentIndex--;
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = SelectedItemFont;
var oldItem = ItemSlots.ElementAt(_currentIndex);
ItemSlots.ElementAt(_currentIndex).SetItemStyle();
var index = new[] { _currentIndex - 1, 0 };
_currentIndex = index.Max();
var newItem = ItemSlots.ElementAt(_currentIndex);
newItem.SetSelectedItemStyle();
if (oldItem.Item is IEquipable equipable && GameRepo.IsItemEquipped(equipable))
oldItem.SetEquippedItemStyle();
if (newItem.Item is IEquipable newEquipable && GameRepo.IsItemEquipped(newEquipable))
newItem.SetEquippedSelectedItemStyle();
}
if (ItemSlots.Any() && Input.IsActionJustPressed(GameInputs.UiAccept))
{
if (_currentPageNumber == InventoryPageNumber.FirstPage)
var itemSlot = ItemSlots[_currentIndex];
if (itemSlot.Item is IEquipable equipableItem)
{
var item = inventory.ElementAt(_currentIndex);
if (item is IEquippable)
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = EquippedItemFont;
if (GameRepo.IsItemEquipped(equipableItem))
{
GameRepo.UnequipItem(equipableItem);
itemSlot.SetSelectedItemStyle();
}
else
{
GameRepo.EquipItem(equipableItem);
itemSlot.SetEquippedSelectedItemStyle();
}
}
}
}
@@ -153,7 +229,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
{
foreach (var item in ItemSlots)
{
ItemsPage.RemoveChild(item);
ItemsPage.RemoveChildEx(item);
}
}
}