Add more interactive effects to inventory menu
This commit is contained in:
@@ -4,6 +4,7 @@ using Chickensoft.Introspection;
|
||||
using GameJamDungeon;
|
||||
using Godot;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
public interface IInventoryMenu : IControl
|
||||
{
|
||||
@@ -20,6 +21,9 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
[Dependency]
|
||||
public IGameRepo GameRepo => this.DependOn<IGameRepo>();
|
||||
|
||||
[Dependency]
|
||||
public IGame Game => this.DependOn<IGame>();
|
||||
|
||||
// Player Info
|
||||
[Node] public Label FloorLabel { get; set; } = default!;
|
||||
[Node] public Label CurrentLevelLabel { get; set; } = default!;
|
||||
@@ -43,12 +47,14 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
// User Prompt Menu
|
||||
[Node] public Label UseItemPrompt { get; set; } = default!;
|
||||
[Node] public Button UseButton { get; set; } = default!;
|
||||
[Node] public Button EquipButton { get; set; } = default!;
|
||||
[Node] public Button ThrowButton { get; set; } = default!;
|
||||
[Node] public Button DropButton { get; set; } = default!;
|
||||
|
||||
public void OnReady()
|
||||
{
|
||||
EquipButton.Pressed += EquipButtonPressed;
|
||||
UseButton.Pressed += UseButtonPressed;
|
||||
ThrowButton.Pressed += ThrowButtonPressed;
|
||||
DropButton.Pressed += DropButtonPressed;
|
||||
}
|
||||
|
||||
private InventoryPageNumber _currentPageNumber = InventoryPageNumber.FirstPage;
|
||||
@@ -127,30 +133,27 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
|
||||
var inventory = GameRepo.InventoryItems.Value;
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiRight) && _currentPageNumber == InventoryPageNumber.FirstPage && inventory.Count > _itemsPerPage)
|
||||
if (@event.IsActionPressed(GameInputs.UiRight) && _currentPageNumber == InventoryPageNumber.FirstPage && inventory.Count > _itemsPerPage)
|
||||
ChangeInventoryPage(InventoryPageNumber.SecondPage);
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiLeft) && _currentPageNumber == InventoryPageNumber.SecondPage)
|
||||
if (@event.IsActionPressed(GameInputs.UiLeft) && _currentPageNumber == InventoryPageNumber.SecondPage)
|
||||
ChangeInventoryPage(InventoryPageNumber.FirstPage);
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiDown))
|
||||
if (@event.IsActionPressed(GameInputs.UiDown))
|
||||
{
|
||||
SetToUnselectedStyle(ItemSlots.ElementAt(_currentIndex));
|
||||
_currentIndex = new[] { _currentIndex + 1, _itemsPerPage - 1, ItemSlots.Length - 1 }.Min();
|
||||
SetToSelectedStyle(ItemSlots.ElementAt(_currentIndex));
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiUp))
|
||||
if (@event.IsActionPressed(GameInputs.UiUp))
|
||||
{
|
||||
if (ItemSlots.Length == 0)
|
||||
return;
|
||||
|
||||
SetToUnselectedStyle(ItemSlots.ElementAt(_currentIndex));
|
||||
_currentIndex = new[] { _currentIndex - 1, 0 }.Max();
|
||||
SetToSelectedStyle(ItemSlots.ElementAt(_currentIndex));
|
||||
}
|
||||
|
||||
if (Input.IsActionJustPressed(GameInputs.UiAccept))
|
||||
if (@event.IsActionPressed(GameInputs.UiAccept))
|
||||
{
|
||||
if (ItemSlots.Length == 0 || GetViewport().GuiGetFocusOwner() is Button)
|
||||
return;
|
||||
@@ -164,42 +167,42 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
ItemEffectLabel.Hide();
|
||||
UseItemPrompt.Show();
|
||||
UseButton.Show();
|
||||
EquipButton.Show();
|
||||
EquipButton.Disabled = false;
|
||||
ThrowButton.Show();
|
||||
DropButton.Show();
|
||||
|
||||
var currentItem = ItemSlots.ElementAt(_currentIndex).Item;
|
||||
|
||||
if (currentItem is IEquipable equipable)
|
||||
{
|
||||
EquipButton.Disabled = false;
|
||||
EquipButton.FocusMode = FocusModeEnum.All;
|
||||
EquipButton.Text = GameRepo.IsItemEquipped(equipable) ? "Unequip" : "Equip";
|
||||
var isEquipped = GameRepo.IsItemEquipped(equipable);
|
||||
UseButton.Text = isEquipped ? "Unequip" : "Equip";
|
||||
ThrowButton.Disabled = isEquipped ? true : false;
|
||||
ThrowButton.FocusMode = isEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
DropButton.Disabled = isEquipped ? true : false;
|
||||
DropButton.FocusMode = isEquipped ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
}
|
||||
else
|
||||
{
|
||||
EquipButton.Disabled = true;
|
||||
EquipButton.FocusMode = FocusModeEnum.None;
|
||||
UseButton.Text = "Use";
|
||||
}
|
||||
|
||||
UseButton.Text = currentItem is ThrowableItem ? "Throw" : "Use";
|
||||
|
||||
UseButton.GrabFocus();
|
||||
}
|
||||
|
||||
private void HideUserActionPrompt()
|
||||
private async Task HideUserActionPrompt()
|
||||
{
|
||||
ItemDescriptionTitle.Show();
|
||||
ItemEffectLabel.Show();
|
||||
UseItemPrompt.Hide();
|
||||
UseButton.Hide();
|
||||
EquipButton.Hide();
|
||||
ThrowButton.Hide();
|
||||
DropButton.Hide();
|
||||
}
|
||||
|
||||
private void ChangeInventoryPage(InventoryPageNumber pageToChangeTo)
|
||||
private async void ChangeInventoryPage(InventoryPageNumber pageToChangeTo)
|
||||
{
|
||||
ClearItems();
|
||||
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
|
||||
_currentIndex = 0;
|
||||
_currentPageNumber = pageToChangeTo;
|
||||
PopulateItems();
|
||||
@@ -246,15 +249,17 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
}
|
||||
}
|
||||
|
||||
private void SetToUnselectedStyle(IItemSlot itemSlot)
|
||||
private async void SetToUnselectedStyle(IItemSlot itemSlot)
|
||||
{
|
||||
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
|
||||
itemSlot.SetItemStyle();
|
||||
if (itemSlot.Item is IEquipable equipable && GameRepo.IsItemEquipped(equipable))
|
||||
itemSlot.SetEquippedItemStyle();
|
||||
}
|
||||
|
||||
private void SetToSelectedStyle(IItemSlot itemSlot)
|
||||
private async void SetToSelectedStyle(IItemSlot itemSlot)
|
||||
{
|
||||
await ToSignal(GetTree().CreateTimer(0.1f), "timeout");
|
||||
itemSlot.SetSelectedItemStyle();
|
||||
if (itemSlot.Item is IEquipable newEquipable && GameRepo.IsItemEquipped(newEquipable))
|
||||
itemSlot.SetEquippedSelectedItemStyle();
|
||||
@@ -262,9 +267,10 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
ItemEffectLabel.Text = $"{itemSlot.Item.Info.Description}";
|
||||
}
|
||||
|
||||
private void EquipOrUnequipItem()
|
||||
private async void EquipOrUnequipItem()
|
||||
{
|
||||
var itemSlot = ItemSlots[_currentIndex];
|
||||
await ToSignal(GetTree().CreateTimer(0.2f), "timeout");
|
||||
if (itemSlot.Item is IEquipable equipableItem)
|
||||
{
|
||||
if (GameRepo.IsItemEquipped(equipableItem))
|
||||
@@ -300,10 +306,43 @@ public partial class InventoryMenu : Control, IInventoryMenu
|
||||
VTValue.Text = $"{currentVT}/{maxVT}";
|
||||
}
|
||||
|
||||
private void EquipButtonPressed()
|
||||
private async void UseButtonPressed()
|
||||
{
|
||||
EquipOrUnequipItem();
|
||||
HideUserActionPrompt();
|
||||
var currentItem = ItemSlots[_currentIndex].Item;
|
||||
if (currentItem is IEquipable)
|
||||
EquipOrUnequipItem();
|
||||
if (currentItem is ConsumableItem consumable)
|
||||
consumable.Use();
|
||||
|
||||
// TODO: Replace with animation player (for visual effects/sound effects?)
|
||||
await ToSignal(GetTree().CreateTimer(0.25f), "timeout");
|
||||
await HideUserActionPrompt();
|
||||
PopulatePlayerInfo();
|
||||
}
|
||||
|
||||
private async void ThrowButtonPressed()
|
||||
{
|
||||
var currentItem = ItemSlots[_currentIndex].Item;
|
||||
|
||||
if (_currentIndex >= ItemSlots.Length - 1)
|
||||
_currentIndex--;
|
||||
if (_currentIndex <= 0)
|
||||
_currentIndex = 0;
|
||||
Game.ToggleInventory();
|
||||
currentItem.Throw();
|
||||
}
|
||||
|
||||
private async void DropButtonPressed()
|
||||
{
|
||||
var currentItem = ItemSlots[_currentIndex].Item;
|
||||
|
||||
if (_currentIndex >= ItemSlots.Length - 1)
|
||||
_currentIndex--;
|
||||
if (_currentIndex <= 0)
|
||||
_currentIndex = 0;
|
||||
|
||||
Game.ToggleInventory();
|
||||
currentItem.Drop();
|
||||
}
|
||||
|
||||
private enum InventoryPageNumber
|
||||
|
||||
Reference in New Issue
Block a user