More inventory menu improvements

This commit is contained in:
2024-09-13 16:43:10 -07:00
parent f0e75703f6
commit 1d7d70e033
41 changed files with 995 additions and 275 deletions

View File

@@ -4,7 +4,6 @@ using Chickensoft.Introspection;
using GameJamDungeon;
using Godot;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
public interface IInventoryMenu : IControl
@@ -92,27 +91,18 @@ public partial class InventoryMenu : Control, IInventoryMenu
GameRepo.PlayerData.Inventory.EquippedAccessory.Sync += EquippedAccessory_Sync;
Game.StatRaisedAlert += Game_StatRaisedAlert;
AnimationPlayer.AnimationFinished += AnimationPlayer_AnimationFinished;
}
private async void AnimationPlayer_AnimationFinished(StringName animName)
{
if (animName == "status_up")
{
if (_currentIndex >= ItemSlots.Length - 1)
_currentIndex--;
if (_currentIndex <= 0)
_currentIndex = 0;
await RedrawInventory();
await ShowInventoryInfo();
}
SetProcessInput(false);
}
private async void Game_StatRaisedAlert(string statRaisedAlert)
{
SetProcessInput(false);
await HideUserActionPrompt();
await ShowInventoryInfo();
ItemEffectLabel.Text = statRaisedAlert;
AnimationPlayer.Play("status_up");
await ToSignal(GetTree().CreateTimer(1.5f), "timeout");
await RedrawInventory();
SetProcessInput(true);
}
private void EquippedAccessory_Sync(Accessory obj)
@@ -164,13 +154,26 @@ public partial class InventoryMenu : Control, IInventoryMenu
}
#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)
public override void _Input(InputEvent @event)
{
if (ItemSlots.Length == 0 || GetViewport().GuiGetFocusOwner() is Button)
return;
var inventory = GameRepo.PlayerData.Inventory;
if (@event.IsActionPressed(GameInputs.UiCancel))
{
if (UseButton.HasFocus() || DropButton.HasFocus() || ThrowButton.HasFocus())
{
HideUserActionPrompt();
ShowInventoryInfo();
}
else
{
EmitSignal(SignalName.ClosedMenu);
}
}
if (ItemSlots.Length == 0 || UseButton.HasFocus() || DropButton.HasFocus() || ThrowButton.HasFocus())
return;
if (@event.IsActionPressed(GameInputs.UiRight) && _currentPageNumber == InventoryPageNumber.FirstPage && inventory.Items.Count() > _itemsPerPage)
ChangeInventoryPage(InventoryPageNumber.SecondPage);
@@ -193,10 +196,14 @@ public partial class InventoryMenu : Control, IInventoryMenu
if (@event.IsActionPressed(GameInputs.UiAccept))
{
if (ItemSlots.Length == 0)
return;
DisplayUserActionPrompt();
}
if (@event.IsActionPressed(GameInputs.InventorySort))
{
inventory.Sort();
RedrawInventory();
}
}
#pragma warning restore CS4014 // Because this call is not awaited, execution of the current method continues before the call is completed
@@ -249,7 +256,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
UseButton.Text = "Use";
}
UseButton.GrabFocus();
UseButton.CallDeferred(MethodName.GrabFocus);
}
private async Task HideUserActionPrompt()
@@ -258,6 +265,9 @@ public partial class InventoryMenu : Control, IInventoryMenu
UseButton.Hide();
ThrowButton.Hide();
DropButton.Hide();
UseButton.ReleaseFocus();
ThrowButton.ReleaseFocus();
DropButton.ReleaseFocus();
}
private async Task ShowInventoryInfo()
@@ -335,21 +345,26 @@ public partial class InventoryMenu : Control, IInventoryMenu
private async Task EquipOrUnequipItem()
{
var itemSlot = ItemSlots[_currentIndex];
await ToSignal(GetTree().CreateTimer(0.2f), "timeout");
if (itemSlot.Item is IEquipable equipableItem)
{
if (GameRepo.PlayerData.Inventory.IsEquipped(equipableItem))
{
ItemEffectLabel.Text = $"{itemSlot.Item.GetType()} unequipped.";
GameRepo.PlayerData.Inventory.Unequip(equipableItem);
AnimationPlayer.Play("status_up");
itemSlot.SetSelectedItemStyle();
}
else
{
ItemEffectLabel.Text = $"{itemSlot.Item.GetType()} equipped.";
GameRepo.PlayerData.Inventory.Equip(equipableItem);
itemSlot.SetEquippedSelectedItemStyle();
AnimationPlayer.Play("status_up");
}
SetProcessInput(false);
await HideUserActionPrompt();
await ShowInventoryInfo();
await ToSignal(GetTree().CreateTimer(1.5f), "timeout");
await RedrawInventory();
SetProcessInput(true);
}
}
@@ -362,8 +377,6 @@ public partial class InventoryMenu : Control, IInventoryMenu
{
GameRepo.PlayerData.Inventory.Use(consumable);
}
await HideUserActionPrompt();
}
private async void ThrowButtonPressed()

View File

@@ -101,6 +101,33 @@ font = ExtResource("3_lm4o1")
font_size = 80
font_color = Color(0.737255, 0.705882, 0.690196, 1)
[sub_resource type="Animation" id="Animation_dg155"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer/ItemEffectLabel:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer/ItemEffectLabel:text")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [""]
}
[sub_resource type="Animation" id="Animation_7by7u"]
resource_name = "status_up"
length = 2.5
@@ -129,33 +156,6 @@ tracks/1/keys = {
"values": [""]
}
[sub_resource type="Animation" id="Animation_dg155"]
length = 0.001
tracks/0/type = "value"
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/path = NodePath("InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer/ItemEffectLabel:visible")
tracks/0/interp = 1
tracks/0/loop_wrap = true
tracks/0/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [true]
}
tracks/1/type = "value"
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/path = NodePath("InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer/ItemEffectLabel:text")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/keys = {
"times": PackedFloat32Array(0),
"transitions": PackedFloat32Array(1),
"update": 1,
"values": [""]
}
[sub_resource type="AnimationLibrary" id="AnimationLibrary_eivo2"]
_data = {
"RESET": SubResource("Animation_dg155"),
@@ -415,6 +415,7 @@ autowrap_mode = 2
[node name="UseItemPrompt" type="Label" parent="InventoryInfo/HBoxContainer/PlayerInfo/HBoxContainer/VBoxContainer"]
unique_name_in_owner = true
visible = false
custom_minimum_size = Vector2(800, 100)
layout_mode = 2
size_flags_horizontal = 0