Fixed inventory screen
This commit is contained in:
@@ -52,11 +52,21 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
private const int _itemsPerPage = 10;
|
||||
|
||||
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");
|
||||
|
||||
public void PopulateItems()
|
||||
{
|
||||
var inventory = GameRepo.InventoryItems.Value;
|
||||
var numberOfItemsToDisplay = Mathf.Min(inventory.Count, _itemsPerPage);
|
||||
var indexToStart = _currentPageNumber == InventoryPageNumber.FirstPage ? 0 : 10;
|
||||
var numberOfItemsToDisplay = _currentPageNumber == InventoryPageNumber.FirstPage ? Mathf.Min(inventory.Count, _itemsPerPage) : Mathf.Min(inventory.Count - _itemsPerPage, _itemsPerPage);
|
||||
var indexToStart = _currentPageNumber == InventoryPageNumber.FirstPage ? 0 : _itemsPerPage - 1;
|
||||
|
||||
ForwardArrow.Text = "";
|
||||
BackArrow.Text = "";
|
||||
@@ -84,30 +94,64 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
itemSlot.ItemTexture.Texture = item.Info.Texture;
|
||||
itemSlot.EquipBonus.Text = "...";
|
||||
}
|
||||
|
||||
if (ItemSlots.Any())
|
||||
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = SelectedItemFont;
|
||||
}
|
||||
|
||||
public override void _UnhandledInput(InputEvent @event)
|
||||
{
|
||||
var inventory = GameRepo.InventoryItems.Value;
|
||||
if (_currentPageNumber == InventoryPageNumber.FirstPage && inventory.Count > _itemsPerPage && Input.IsActionJustPressed(GameInputs.UiRight))
|
||||
if (ItemSlots.Any() && _currentPageNumber == InventoryPageNumber.FirstPage && inventory.Count > _itemsPerPage && Input.IsActionJustPressed(GameInputs.UiRight))
|
||||
{
|
||||
ClearItems();
|
||||
_currentIndex = 0;
|
||||
_currentPageNumber = InventoryPageNumber.SecondPage;
|
||||
PopulateItems();
|
||||
}
|
||||
|
||||
if (_currentPageNumber == InventoryPageNumber.SecondPage && Input.IsActionJustPressed(GameInputs.UiLeft))
|
||||
if (ItemSlots.Any() && _currentPageNumber == InventoryPageNumber.SecondPage && Input.IsActionJustPressed(GameInputs.UiLeft))
|
||||
{
|
||||
ClearItems();
|
||||
_currentIndex = 0;
|
||||
_currentPageNumber = InventoryPageNumber.FirstPage;
|
||||
PopulateItems();
|
||||
}
|
||||
|
||||
if (ItemSlots.Any() && Input.IsActionJustPressed(GameInputs.UiDown))
|
||||
{
|
||||
if (!inventory.Any() || _currentIndex + 1 >= _itemsPerPage)
|
||||
return;
|
||||
|
||||
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = ItemFont;
|
||||
_currentIndex++;
|
||||
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = SelectedItemFont;
|
||||
}
|
||||
|
||||
if (ItemSlots.Any() && Input.IsActionJustPressed(GameInputs.UiUp))
|
||||
{
|
||||
if (!inventory.Any() || _currentIndex <= 0)
|
||||
return;
|
||||
|
||||
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = ItemFont;
|
||||
_currentIndex--;
|
||||
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = SelectedItemFont;
|
||||
}
|
||||
|
||||
if (ItemSlots.Any() && Input.IsActionJustPressed(GameInputs.UiAccept))
|
||||
{
|
||||
if (_currentPageNumber == InventoryPageNumber.FirstPage)
|
||||
{
|
||||
var item = inventory.ElementAt(_currentIndex);
|
||||
if (item is IEquippable)
|
||||
ItemSlots.ElementAt(_currentIndex).ItemName.LabelSettings = EquippedItemFont;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void ClearItems()
|
||||
{
|
||||
var items = ItemsPage.GetChildren().OfType<ItemSlot>();
|
||||
foreach (var item in items)
|
||||
foreach (var item in ItemSlots)
|
||||
{
|
||||
ItemsPage.RemoveChild(item);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user