Refactor inventory menu logic
This commit is contained in:
@@ -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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user