Fiddle with UI

This commit is contained in:
2024-09-10 20:38:22 -07:00
parent 7268cb445a
commit 0c9b1cd689
5 changed files with 55 additions and 35 deletions

View File

@@ -22,7 +22,17 @@ public partial class InventoryMenu : Control, IInventoryMenu
[Dependency]
public IGame Game => this.DependOn<IGame>();
// Player Info
private InventoryPageNumber _currentPageNumber = InventoryPageNumber.FirstPage;
private string ITEM_SLOT_SCENE = "res://src/inventory_menu/ItemSlot.tscn";
private const int _itemsPerPage = 10;
private int _currentIndex = 0;
private IItemSlot[] ItemSlots => ItemsPage.GetChildren().OfType<IItemSlot>().ToArray();
#region Control Nodes
[Node] public Label FloorLabel { get; set; } = default!;
[Node] public Label CurrentLevelLabel { get; set; } = default!;
[Node] public Label EXPValue { get; set; } = default!;
@@ -47,6 +57,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
[Node] public Button UseButton { get; set; } = default!;
[Node] public Button ThrowButton { get; set; } = default!;
[Node] public Button DropButton { get; set; } = default!;
#endregion
public void OnReady()
{
@@ -55,24 +66,15 @@ public partial class InventoryMenu : Control, IInventoryMenu
DropButton.Pressed += DropButtonPressed;
}
private InventoryPageNumber _currentPageNumber = InventoryPageNumber.FirstPage;
private string ITEM_SLOT_SCENE = "res://src/inventory_menu/ItemSlot.tscn";
private const int _itemsPerPage = 10;
private int _currentIndex = 0;
private IItemSlot[] ItemSlots => ItemsPage.GetChildren().OfType<IItemSlot>().ToArray();
public async Task RedrawInventory()
{
await HideUserActionPrompt();
ClearItems();
await ClearItems();
PopulateInventory();
PopulatePlayerInfo();
}
#pragma warning disable CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
public override void _UnhandledInput(InputEvent @event)
{
if (ItemSlots.Length == 0)
@@ -107,6 +109,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
DisplayUserActionPrompt();
}
}
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
private void PopulateItems()
{
@@ -114,12 +117,12 @@ public partial class InventoryMenu : Control, IInventoryMenu
PopulatePlayerInfo();
}
private void ClearItems()
private async Task ClearItems()
{
foreach (var item in ItemSlots)
ItemsPage.RemoveChildEx(item);
HideUserActionPrompt();
await HideUserActionPrompt();
}
private void PopulatePlayerInfo()
@@ -205,9 +208,9 @@ public partial class InventoryMenu : Control, IInventoryMenu
DropButton.Hide();
}
private async void ChangeInventoryPage(InventoryPageNumber pageToChangeTo)
private async Task ChangeInventoryPage(InventoryPageNumber pageToChangeTo)
{
ClearItems();
await ClearItems();
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
_currentIndex = 0;
_currentPageNumber = pageToChangeTo;
@@ -255,7 +258,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
}
}
private async void SetToUnselectedStyle(IItemSlot itemSlot)
private async Task SetToUnselectedStyle(IItemSlot itemSlot)
{
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
itemSlot.SetItemStyle();
@@ -263,7 +266,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
itemSlot.SetEquippedItemStyle();
}
private async void SetToSelectedStyle(IItemSlot itemSlot)
private async Task SetToSelectedStyle(IItemSlot itemSlot)
{
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
itemSlot.SetSelectedItemStyle();
@@ -273,7 +276,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
ItemEffectLabel.Text = $"{itemSlot.Item.Info.Description}";
}
private async void EquipOrUnequipItem()
private async Task EquipOrUnequipItem()
{
var itemSlot = ItemSlots[_currentIndex];
await ToSignal(GetTree().CreateTimer(0.2f), "timeout");
@@ -316,7 +319,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
{
var currentItem = ItemSlots[_currentIndex].Item;
if (currentItem is IEquipable)
EquipOrUnequipItem();
await EquipOrUnequipItem();
if (currentItem is ConsumableItem consumable)
consumable.Use();