From 8a61104868f2e30289e78caba6aa9bd6db61be88 Mon Sep 17 00:00:00 2001 From: Zenny Date: Fri, 7 Mar 2025 20:42:56 -0800 Subject: [PATCH] Refactor inventory menu logic --- .../Game/GameLogic.Output.cs | 8 -- .../Game/GameLogic.State.cs | 8 -- .../Game/GameRepo.cs | 14 ++-- .../states/GameLogic.State.InventoryOpened.cs | 25 ------- .../state/states/GameLogic.State.Playing.cs | 5 -- .../UI/InGameUI/InGameUILogic.State.cs | 1 + .../UI/InGameUI/state/InGameUILogic.Input.cs | 2 + .../UI/InGameUI/state/InGameUILogic.Output.cs | 6 +- .../state/States/InGameUI.State.Active.cs | 3 +- .../States/InGameUI.State.InventoryOpen.cs | 35 +++++++++ .../States/InGameUI.State.MinimapOpen.cs | 3 +- Zennysoft.Game.Ma/src/game/Game.cs | 42 +++++------ Zennysoft.Game.Ma/src/game/IGame.cs | 2 - .../src/inventory_menu/InventoryMenu.cs | 11 +-- Zennysoft.Game.Ma/src/items/EffectService.cs | 3 +- .../src/items/thrown/ThrownItem.cs | 1 - Zennysoft.Game.Ma/src/player/IPlayer.cs | 2 - Zennysoft.Game.Ma/src/player/Player.cs | 8 -- .../src/ui/in_game_ui/InGameUI.cs | 75 +++++-------------- 19 files changed, 94 insertions(+), 160 deletions(-) delete mode 100644 Zennysoft.Game.Ma.Implementation/Game/state/states/GameLogic.State.InventoryOpened.cs create mode 100644 Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.InventoryOpen.cs diff --git a/Zennysoft.Game.Ma.Implementation/Game/GameLogic.Output.cs b/Zennysoft.Game.Ma.Implementation/Game/GameLogic.Output.cs index d15878f9..6443c2d6 100644 --- a/Zennysoft.Game.Ma.Implementation/Game/GameLogic.Output.cs +++ b/Zennysoft.Game.Ma.Implementation/Game/GameLogic.Output.cs @@ -12,16 +12,8 @@ public partial class GameLogic public readonly record struct ExitPauseMenu; - public readonly record struct OpenInventory; - - public readonly record struct CloseInventory; - public readonly record struct SetPauseMode(bool IsPaused); - public readonly record struct ShowMiniMap; - - public readonly record struct HideMiniMap; - public readonly record struct ShowLostScreen; public readonly record struct ExitLostScreen; diff --git a/Zennysoft.Game.Ma.Implementation/Game/GameLogic.State.cs b/Zennysoft.Game.Ma.Implementation/Game/GameLogic.State.cs index 4caca1cb..4e18382e 100644 --- a/Zennysoft.Game.Ma.Implementation/Game/GameLogic.State.cs +++ b/Zennysoft.Game.Ma.Implementation/Game/GameLogic.State.cs @@ -14,24 +14,16 @@ public partial class GameLogic { var gameRepo = Get(); gameRepo.IsPaused.Sync += OnIsPaused; - gameRepo.OpenInventory += OnOpenInventory; - gameRepo.CloseInventory += OnCloseInventory; gameRepo.DoubleExpTimeStart += OnDoubleExpTimeStart; }); OnDetach(() => { var gameRepo = Get(); gameRepo.IsPaused.Sync -= OnIsPaused; - gameRepo.OpenInventory -= OnOpenInventory; - gameRepo.CloseInventory -= OnCloseInventory; gameRepo.DoubleExpTimeStart -= OnDoubleExpTimeStart; }); } - private void OnOpenInventory() => Output(new Output.OpenInventory()); - - private void OnCloseInventory() => Output(new Output.CloseInventory()); - private void OnDoubleExpTimeStart(int lengthOfTimeInSeconds) => Output(new Output.DoubleExpTimeStart(lengthOfTimeInSeconds)); public void OnIsPaused(bool isPaused) => Output(new Output.SetPauseMode(isPaused)); diff --git a/Zennysoft.Game.Ma.Implementation/Game/GameRepo.cs b/Zennysoft.Game.Ma.Implementation/Game/GameRepo.cs index 796d191e..e802d4ce 100644 --- a/Zennysoft.Game.Ma.Implementation/Game/GameRepo.cs +++ b/Zennysoft.Game.Ma.Implementation/Game/GameRepo.cs @@ -8,9 +8,7 @@ public interface IGameRepo : IDisposable { event Action? Ended; - event Action? OpenInventory; - - event Action? CloseInventory; + event Action? CloseInventoryEvent; event Action? AnnounceMessageOnMainScreenEvent; @@ -38,14 +36,15 @@ public interface IGameRepo : IDisposable public void RemoveItemFromInventory(IInventoryItem item); + public void CloseInventory(); + public double ExpRate { get; } } public class GameRepo : IGameRepo { public event Action? Ended; - public event Action? OpenInventory; - public event Action? CloseInventory; + public event Action? CloseInventoryEvent; public event Action? AnnounceMessageOnMainScreenEvent; public event Action? AnnounceMessageInInventoryEvent; public event Action? DoubleExpTimeStart; @@ -105,6 +104,11 @@ public class GameRepo : IGameRepo RemoveItemFromInventoryEvent?.Invoke(item); } + public void CloseInventory() + { + CloseInventoryEvent?.Invoke(); + } + public void OnGameEnded() { Pause(); diff --git a/Zennysoft.Game.Ma.Implementation/Game/state/states/GameLogic.State.InventoryOpened.cs b/Zennysoft.Game.Ma.Implementation/Game/state/states/GameLogic.State.InventoryOpened.cs deleted file mode 100644 index 1e526bd2..00000000 --- a/Zennysoft.Game.Ma.Implementation/Game/state/states/GameLogic.State.InventoryOpened.cs +++ /dev/null @@ -1,25 +0,0 @@ -using Chickensoft.Introspection; -using Chickensoft.LogicBlocks; - -namespace Zennysoft.Game.Ma.Implementation; - -public partial class GameLogic -{ - public partial record State - { - [Meta] - public partial record InventoryOpened : Playing, IGet - { - public InventoryOpened() - { - this.OnEnter(() => { Get().Pause(); Output(new Output.OpenInventory()); }); - this.OnExit(() => { Get().Resume(); Output(new Output.CloseInventory()); }); - } - - public Transition On(in Input.CloseInventory input) - { - return To(); - } - } - } -} diff --git a/Zennysoft.Game.Ma.Implementation/Game/state/states/GameLogic.State.Playing.cs b/Zennysoft.Game.Ma.Implementation/Game/state/states/GameLogic.State.Playing.cs index 40ba2d2c..2bbfe5d9 100644 --- a/Zennysoft.Game.Ma.Implementation/Game/state/states/GameLogic.State.Playing.cs +++ b/Zennysoft.Game.Ma.Implementation/Game/state/states/GameLogic.State.Playing.cs @@ -1,5 +1,4 @@ using Chickensoft.Introspection; -using Chickensoft.LogicBlocks; namespace Zennysoft.Game.Ma.Implementation; @@ -9,7 +8,6 @@ public partial class GameLogic { [Meta] public partial record Playing : State, - IGet, IGet, IGet, IGet, @@ -22,9 +20,6 @@ public partial class GameLogic public void OnEnded() => Input(new Input.GameOver()); - public Transition On(in Input.OpenInventory input) => To(); - - public Transition On(in Input.GameOver input) => To(); public Transition On(in Input.AskForTeleport input) => To(); diff --git a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/InGameUILogic.State.cs b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/InGameUILogic.State.cs index 56531884..4fd37443 100644 --- a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/InGameUILogic.State.cs +++ b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/InGameUILogic.State.cs @@ -24,6 +24,7 @@ public partial class InGameUILogic var gameRepo = Get(); gameRepo.AnnounceMessageOnMainScreenEvent -= OnAnnounceMessageOnMainScreen; gameRepo.AnnounceMessageInInventoryEvent -= OnAnnounceMessageInInventory; + gameRepo.RemoveItemFromInventoryEvent -= OnRemoveItemFromInventory; }); } diff --git a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/InGameUILogic.Input.cs b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/InGameUILogic.Input.cs index a65c3cc1..08464d27 100644 --- a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/InGameUILogic.Input.cs +++ b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/InGameUILogic.Input.cs @@ -5,5 +5,7 @@ public partial class InGameUILogic { public readonly record struct ShowMinimap; public readonly record struct HideMinimap; + public readonly record struct ShowInventory; + public readonly record struct HideInventory; } } diff --git a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/InGameUILogic.Output.cs b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/InGameUILogic.Output.cs index dc43b2b6..94409b07 100644 --- a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/InGameUILogic.Output.cs +++ b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/InGameUILogic.Output.cs @@ -8,7 +8,9 @@ public partial class InGameUILogic public readonly record struct AnnounceMessageOnMainScreen(string Message); public readonly record struct AnnounceMessageInInventory(string Message); public readonly record struct RemoveItemFromInventory(IInventoryItem Item); - public readonly record struct DisplayMinimap(); - public readonly record struct HideMinimap(); + public readonly record struct DisplayMinimap; + public readonly record struct HideMinimap; + public readonly record struct ShowInventory; + public readonly record struct HideInventory; } } diff --git a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.Active.cs b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.Active.cs index 5fc1f26f..faa33a08 100644 --- a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.Active.cs +++ b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.Active.cs @@ -7,9 +7,10 @@ public partial class InGameUILogic public partial record State { [Meta] - public partial record Active : State, IGet + public partial record Active : State, IGet, IGet { public Transition On(in Input.ShowMinimap input) => To(); + public Transition On(in Input.ShowInventory input) => To(); } } } diff --git a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.InventoryOpen.cs b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.InventoryOpen.cs new file mode 100644 index 00000000..a5e43790 --- /dev/null +++ b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.InventoryOpen.cs @@ -0,0 +1,35 @@ +using Chickensoft.Introspection; + +namespace Zennysoft.Game.Ma.Implementation; + +public partial class InGameUILogic +{ + public partial record State + { + [Meta] + public partial record InventoryOpen : Active, IGet + { + public InventoryOpen() + { + OnAttach(() => + { + var gameRepo = Get(); + gameRepo.CloseInventoryEvent += OnCloseInventoryEvent; + gameRepo.Pause(); + Output(new Output.ShowInventory()); + }); + OnDetach(() => + { + var gameRepo = Get(); + gameRepo.Resume(); + gameRepo.CloseInventoryEvent -= OnCloseInventoryEvent; + Output(new Output.HideInventory()); + }); + } + + private void OnCloseInventoryEvent() => Input(new Input.HideInventory()); + + public Transition On(in Input.HideInventory input) => To(); + } + } +} diff --git a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.MinimapOpen.cs b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.MinimapOpen.cs index 8774204d..b278f063 100644 --- a/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.MinimapOpen.cs +++ b/Zennysoft.Game.Ma.Implementation/UI/InGameUI/state/States/InGameUI.State.MinimapOpen.cs @@ -1,5 +1,4 @@ using Chickensoft.Introspection; -using Chickensoft.LogicBlocks; namespace Zennysoft.Game.Ma.Implementation; @@ -8,7 +7,7 @@ public partial class InGameUILogic public partial record State { [Meta] - public partial record MinimapOpen : State, IGet + public partial record MinimapOpen : Active, IGet { public MinimapOpen() { diff --git a/Zennysoft.Game.Ma/src/game/Game.cs b/Zennysoft.Game.Ma/src/game/Game.cs index e1ca487c..7b8abb5e 100644 --- a/Zennysoft.Game.Ma/src/game/Game.cs +++ b/Zennysoft.Game.Ma/src/game/Game.cs @@ -4,7 +4,6 @@ namespace Zennysoft.Game.Ma; using Chickensoft.AutoInject; using Chickensoft.Introspection; using Chickensoft.SaveFileBuilder; -using Zennysoft.Game.Ma.src.items; using Godot; using System; using System.IO.Abstractions; @@ -193,8 +192,6 @@ public partial class Game : Node3D, IGame .Handle((in GameLogic.Output.LoadMap _) => { Map.LoadMap(); }) .Handle((in GameLogic.Output.ShowFloorClearMenu _) => { FloorClearMenu.Show(); FloorClearMenu.FadeIn(); }) .Handle((in GameLogic.Output.ExitFloorClearMenu _) => { FloorClearMenu.FadeOut(); }) - .Handle((in GameLogic.Output.OpenInventory _) => { InGameUI.ShowInventoryScreen(); InGameUI.InventoryMenu.SetProcessInput(true); }) - .Handle((in GameLogic.Output.CloseInventory _) => { InGameUI.HideInventoryScreen(); InGameUI.InventoryMenu.SetProcessInput(false); }) .Handle((in GameLogic.Output.ShowAskForTeleport _) => { GameRepo.Pause(); InGameUI.UseTeleportPrompt.FadeIn(); InGameUI.SetProcessInput(true); }) .Handle((in GameLogic.Output.HideAskForTeleport _) => { GameRepo.Resume(); InGameUI.UseTeleportPrompt.FadeOut(); InGameUI.SetProcessInput(false); }) .Handle((in GameLogic.Output.ShowLostScreen _) => { DeathMenu.Show(); DeathMenu.FadeIn(); }) @@ -215,7 +212,6 @@ public partial class Game : Node3D, IGame PauseMenu.TransitionCompleted += OnPauseMenuTransitioned; PauseMenu.UnpauseButtonPressed += PauseMenu_UnpauseButtonPressed; - InGameUI.InventoryMenu.ClosedMenu += InventoryMenu_CloseInventory; InGameUI.UseTeleportPrompt.TeleportToNextFloor += UseTeleportPrompt_TeleportToNextFloor; InGameUI.UseTeleportPrompt.CloseTeleportPrompt += UseTeleportPrompt_CloseTeleportPrompt; @@ -245,14 +241,6 @@ public partial class Game : Node3D, IGame GameLogic.Input(new GameLogic.Input.PauseGame()); } - public void ToggleInventory() - { - if (GameLogic.Value is InventoryOpened) - GameLogic.Input(new GameLogic.Input.CloseInventory()); - else - GameLogic.Input(new GameLogic.Input.OpenInventory()); - } - public void FloorExitReached() { GameLogic.Input(new GameLogic.Input.AskForTeleport()); @@ -314,22 +302,28 @@ public partial class Game : Node3D, IGame } if (item is ThrowableItem throwableItem) { - if (throwableItem.ThrowableItemTag == ThrowableItemTag.DoubleExp) - GameRepo.StartDoubleEXP(TimeSpan.FromSeconds(30)); + switch (throwableItem.ThrowableItemTag) + { + case ThrowableItemTag.DoubleExp: + GameRepo.StartDoubleEXP(TimeSpan.FromSeconds(30)); + break; + case ThrowableItemTag.TeleportToRandomLocation: + _effectService.TeleportToRandomRoom(Player); + InGameUI.CloseInventory(); + break; + case ThrowableItemTag.CanChangeAffinity: + _effectService.ChangeAffinity(throwableItem); + break; + case ThrowableItemTag.WarpToExitIfFound: + _effectService.WarpToExit(Player); + InGameUI.CloseInventory(); + break; + } if (throwableItem.HealHPAmount > 0) Player.HealHP(throwableItem.HealHPAmount); if (throwableItem.HealVTAmount > 0) Player.HealVT(throwableItem.HealVTAmount); - - if (throwableItem.ThrowableItemTag == ThrowableItemTag.TeleportToRandomLocation) - _effectService.TeleportToRandomRoom(Player); - - if (throwableItem.ThrowableItemTag == ThrowableItemTag.CanChangeAffinity) - _effectService.ChangeAffinity(throwableItem); - - if (throwableItem.ThrowableItemTag == ThrowableItemTag.WarpToExitIfFound) - _effectService.WarpToExit(Player); } await ToSignal(GetTree().CreateTimer(1f), "timeout"); @@ -427,8 +421,6 @@ public partial class Game : Node3D, IGame GameRepo.EndDoubleExp(); } - private void InventoryMenu_CloseInventory() => GameLogic.Input(new GameLogic.Input.CloseInventory()); - public void NextFloorLoaded() { GameLogic.Input(new GameLogic.Input.HideFloorClearMenu()); diff --git a/Zennysoft.Game.Ma/src/game/IGame.cs b/Zennysoft.Game.Ma/src/game/IGame.cs index 2e326439..4d662744 100644 --- a/Zennysoft.Game.Ma/src/game/IGame.cs +++ b/Zennysoft.Game.Ma/src/game/IGame.cs @@ -27,8 +27,6 @@ public interface IGame : IProvide, IProvide, IProvid public void ThrowItem(IInventoryItem item); - public void ToggleInventory(); - public void FloorExitReached(); public void NextFloorLoaded(); diff --git a/Zennysoft.Game.Ma/src/inventory_menu/InventoryMenu.cs b/Zennysoft.Game.Ma/src/inventory_menu/InventoryMenu.cs index b89eb12e..fb38b7b0 100644 --- a/Zennysoft.Game.Ma/src/inventory_menu/InventoryMenu.cs +++ b/Zennysoft.Game.Ma/src/inventory_menu/InventoryMenu.cs @@ -15,8 +15,6 @@ public interface IInventoryMenu : IControl public Task DisplayMessage(string message); - event InventoryMenu.ClosedMenuEventHandler ClosedMenu; - public void RemoveItem(IInventoryItem item); } @@ -33,9 +31,6 @@ public partial class InventoryMenu : Control, IInventoryMenu [Dependency] public IGameEventDepot GameEventDepot => this.DependOn(); - [Signal] - public delegate void ClosedMenuEventHandler(); - private InventoryPageNumber _currentPageNumber = InventoryPageNumber.FirstPage; private string ITEM_SLOT_SCENE = "res://src/inventory_menu/ItemSlot.tscn"; @@ -178,7 +173,7 @@ public partial class InventoryMenu : Control, IInventoryMenu } else { - EmitSignal(SignalName.ClosedMenu); + _gameRepo.CloseInventory(); } } @@ -429,7 +424,7 @@ public partial class InventoryMenu : Control, IInventoryMenu if (_currentIndex <= 0) _currentIndex = 0; - EmitSignal(SignalName.ClosedMenu); + _gameRepo.CloseInventory(); } private async void DropButtonPressed() @@ -443,7 +438,7 @@ public partial class InventoryMenu : Control, IInventoryMenu if (_currentIndex <= 0) _currentIndex = 0; - EmitSignal(SignalName.ClosedMenu); + _gameRepo.CloseInventory(); } private async void RefreshUIAfterUserSelection() diff --git a/Zennysoft.Game.Ma/src/items/EffectService.cs b/Zennysoft.Game.Ma/src/items/EffectService.cs index 0f2dff04..34aac842 100644 --- a/Zennysoft.Game.Ma/src/items/EffectService.cs +++ b/Zennysoft.Game.Ma/src/items/EffectService.cs @@ -3,7 +3,7 @@ using System.Linq; using System; using Zennysoft.Game.Ma.Implementation; -namespace Zennysoft.Game.Ma.src.items; +namespace Zennysoft.Game.Ma; public class EffectService { @@ -189,7 +189,6 @@ public class EffectService var roomsGodotCollection = new Godot.Collections.Array(validRooms); var randomRoom = roomsGodotCollection.PickRandom(); var spawnPoint = randomRoom.PlayerSpawn; - _game.ToggleInventory(); player.TeleportPlayer(spawnPoint.Transform); } diff --git a/Zennysoft.Game.Ma/src/items/thrown/ThrownItem.cs b/Zennysoft.Game.Ma/src/items/thrown/ThrownItem.cs index 144b2519..ea03f9b7 100644 --- a/Zennysoft.Game.Ma/src/items/thrown/ThrownItem.cs +++ b/Zennysoft.Game.Ma/src/items/thrown/ThrownItem.cs @@ -1,6 +1,5 @@ using Chickensoft.AutoInject; using Chickensoft.Introspection; -using Zennysoft.Game.Ma.src.items; using Godot; using Zennysoft.Game.Ma.Implementation; using Zennysoft.Game.Abstractions; diff --git a/Zennysoft.Game.Ma/src/player/IPlayer.cs b/Zennysoft.Game.Ma/src/player/IPlayer.cs index 5388e6a7..a90995e6 100644 --- a/Zennysoft.Game.Ma/src/player/IPlayer.cs +++ b/Zennysoft.Game.Ma/src/player/IPlayer.cs @@ -10,8 +10,6 @@ public interface IPlayer : IKillable, IProvide> { public void Attack(); - public void ToggleInventory(); - public void PlayerPause(); public void TakeDamage(double damage, ElementType elementType = ElementType.None, bool isCriticalHit = false); diff --git a/Zennysoft.Game.Ma/src/player/Player.cs b/Zennysoft.Game.Ma/src/player/Player.cs index ee07f88a..5b354d77 100644 --- a/Zennysoft.Game.Ma/src/player/Player.cs +++ b/Zennysoft.Game.Ma/src/player/Player.cs @@ -266,11 +266,6 @@ public partial class Player : CharacterBody3D, IPlayer PlayerLogic.Input(new PlayerLogic.Input.Attack()); } - public void ToggleInventory() - { - Game.ToggleInventory(); - } - public void PlayerPause() { Game.TogglePause(); @@ -396,9 +391,6 @@ public partial class Player : CharacterBody3D, IPlayer public override void _UnhandledInput(InputEvent @event) { - if (@event.IsActionPressed(GameInputs.Inventory)) - ToggleInventory(); - if (@event.IsActionPressed(GameInputs.Pause)) PlayerPause(); diff --git a/Zennysoft.Game.Ma/src/ui/in_game_ui/InGameUI.cs b/Zennysoft.Game.Ma/src/ui/in_game_ui/InGameUI.cs index 7ed68fcd..c4c2e6d8 100644 --- a/Zennysoft.Game.Ma/src/ui/in_game_ui/InGameUI.cs +++ b/Zennysoft.Game.Ma/src/ui/in_game_ui/InGameUI.cs @@ -2,22 +2,13 @@ using Chickensoft.AutoInject; using Chickensoft.GodotNodeInterfaces; using Chickensoft.Introspection; using Godot; -using Renci.SshNet.Messages; using Zennysoft.Game.Ma.Implementation; namespace Zennysoft.Game.Ma; public interface IInGameUI : IControl { - public void ShowInventoryScreen(); - - public void HideInventoryScreen(); - - public void ShowMiniMap(); - - public void HideMiniMap(); - - event InGameUI.MinimapButtonReleasedEventHandler MinimapButtonReleased; + void CloseInventory(); } [Meta(typeof(IAutoNode))] @@ -39,9 +30,6 @@ public partial class InGameUI : Control, IInGameUI public InGameUILogic.IBinding InGameUILogicBinding { get; set; } = default!; - [Signal] - public delegate void MinimapButtonReleasedEventHandler(); - public void Setup() { InGameUILogic = new InGameUILogic(); @@ -53,31 +41,23 @@ public partial class InGameUI : Control, IInGameUI InGameUILogicBinding = InGameUILogic.Bind(); InGameUILogicBinding - .Handle((in InGameUILogic.Output.AnnounceMessageOnMainScreen output) => - { - PlayerInfoUI.DisplayMessage(output.Message); - }) - .Handle((in InGameUILogic.Output.AnnounceMessageInInventory output) => - { - InventoryMenu.DisplayMessage(output.Message); - }) - .Handle((in InGameUILogic.Output.RemoveItemFromInventory output) => - { - InventoryMenu.RemoveItem(output.Item); - }) - .Handle((in InGameUILogic.Output.DisplayMinimap _) => - { - ShowMiniMap(); - }) - .Handle((in InGameUILogic.Output.HideMinimap _) => - { - HideMiniMap(); - }); - ; + .Handle((in InGameUILogic.Output.AnnounceMessageOnMainScreen output) => { PlayerInfoUI.DisplayMessage(output.Message); }) + .Handle((in InGameUILogic.Output.AnnounceMessageInInventory output) => { InventoryMenu.DisplayMessage(output.Message); }) + .Handle((in InGameUILogic.Output.RemoveItemFromInventory output) => { InventoryMenu.RemoveItem(output.Item); }) + .Handle((in InGameUILogic.Output.DisplayMinimap _) => { MiniMap.SetProcessUnhandledInput(true); MiniMap.Show(); }) + .Handle((in InGameUILogic.Output.HideMinimap _) => { MiniMap.SetProcessUnhandledInput(false); MiniMap.Hide(); }) + .Handle((in InGameUILogic.Output.ShowInventory _) => { InventoryMenu.RefreshInventoryScreen(); InventoryMenu.Show(); InventoryMenu.SetProcessInput(true); }) + .Handle((in InGameUILogic.Output.HideInventory _) => { CloseInventory(); }); InGameUILogic.Start(); } + public void CloseInventory() + { + InventoryMenu.Hide(); + InventoryMenu.SetProcessInput(false); + } + public override void _UnhandledInput(InputEvent @event) { if (@event.IsActionPressed(GameInputs.MiniMap)) @@ -90,28 +70,11 @@ public partial class InGameUI : Control, IInGameUI GD.Print("MiniMap button released"); InGameUILogic.Input(new InGameUILogic.Input.HideMinimap()); } - } - public void HideInventoryScreen() - { - InventoryMenu.Hide(); - } - - public void HideMiniMap() - { - MiniMap.SetProcessUnhandledInput(false); - MiniMap.Hide(); - } - - public void ShowInventoryScreen() - { - InventoryMenu.RefreshInventoryScreen(); - InventoryMenu.Show(); - } - - public void ShowMiniMap() - { - MiniMap.SetProcessUnhandledInput(true); - MiniMap.Show(); + if (@event.IsActionPressed(GameInputs.Inventory)) + { + GD.Print("Inventory button pressed"); + InGameUILogic.Input(new InGameUILogic.Input.ShowInventory()); + } } }