Rework game over logic and game initialization

This commit is contained in:
2025-10-27 15:04:01 -07:00
parent 720696aed0
commit 7e6dca1c29
46 changed files with 653 additions and 610 deletions

View File

@@ -28,8 +28,6 @@ public partial class InventoryMenu : Control, IInventoryMenu
[Dependency] public IPlayer Player => this.DependOn<IPlayer>();
[Dependency] public IMap _map => this.DependOn<IMap>();
private InventoryPageNumber _currentPageNumber = InventoryPageNumber.FirstPage;
private string ITEM_SLOT_SCENE = "res://src/ui/inventory_menu/ItemSlot.tscn";
@@ -62,11 +60,24 @@ public partial class InventoryMenu : Control, IInventoryMenu
[Node] public AnimationPlayer AnimationPlayer { get; set; } = default!;
#endregion
public void OnReady()
public InventoryMenu()
{
SetProcessInput(false);
SetProcess(false);
}
public void OnResolved()
{
UseButton.Pressed += UseButtonPressed;
ThrowButton.Pressed += ThrowButtonPressed;
DropButton.Pressed += DropButtonPressed;
Player.AttackComponent.CurrentAttack.Sync += AttackSync;
Player.AttackComponent.MaximumAttack.Sync += AttackSync;
Player.EquipmentComponent.EquippedWeapon.Sync += BonusSync;
Player.EquipmentComponent.EquippedArmor.Sync += BonusSync;
Player.EquipmentComponent.EquippedAccessory.Sync += BonusSync;
Player.DefenseComponent.CurrentDefense.Sync += DefenseSync;
Player.DefenseComponent.MaximumDefense.Sync += DefenseSync;
}
public void OnExitTree()
@@ -80,18 +91,6 @@ public partial class InventoryMenu : Control, IInventoryMenu
Player.DefenseComponent.MaximumDefense.Sync -= DefenseSync;
}
public void OnResolved()
{
SetProcessInput(false);
Player.AttackComponent.CurrentAttack.Sync += AttackSync;
Player.AttackComponent.MaximumAttack.Sync += AttackSync;
Player.EquipmentComponent.EquippedWeapon.Sync += BonusSync;
Player.EquipmentComponent.EquippedArmor.Sync += BonusSync;
Player.EquipmentComponent.EquippedAccessory.Sync += BonusSync;
Player.DefenseComponent.CurrentDefense.Sync += DefenseSync;
Player.DefenseComponent.MaximumDefense.Sync += DefenseSync;
}
public async Task DisplayMessage(string message)
{
SetProcessInput(false);
@@ -125,8 +124,6 @@ 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 _Input(InputEvent @event)
{
var inventory = Player.Inventory;
if (@event.IsActionPressed(GameInputs.UiCancel))
{
if (UseButton.HasFocus() || DropButton.HasFocus() || ThrowButton.HasFocus())
@@ -145,8 +142,12 @@ public partial class InventoryMenu : Control, IInventoryMenu
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);
if (@event.IsActionPressed(GameInputs.UiRight) && _currentPageNumber == InventoryPageNumber.FirstPage)
{
var inventory = Player.Inventory;
if (inventory.Items.Count > _itemsPerPage)
ChangeInventoryPage(InventoryPageNumber.SecondPage);
}
if (@event.IsActionPressed(GameInputs.UiLeft) && _currentPageNumber == InventoryPageNumber.SecondPage)
ChangeInventoryPage(InventoryPageNumber.FirstPage);
@@ -186,6 +187,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
if (@event.IsActionPressed(GameInputs.InventorySort))
{
var inventory = Player.Inventory;
inventory.Sort(Player.EquipmentComponent.EquippedWeapon.Value, Player.EquipmentComponent.EquippedArmor.Value, Player.EquipmentComponent.EquippedAccessory.Value);
if (_currentIndex > inventory.Items.Count - 1)
_currentIndex = inventory.Items.Count - 1;
@@ -357,7 +359,7 @@ public partial class InventoryMenu : Control, IInventoryMenu
else
{
ItemEffectLabel.Text = $"{equippableItem.GetType().Name} equipped.";
Player.EquipmentComponent.Equip(equippableItem);
Player.Equip(equippableItem);
itemSlot.SetEquippedSelectedItemStyle();
}