From f20bd89dc4a7bf14a88b1effcaa1887b29314525 Mon Sep 17 00:00:00 2001 From: Sophia Pearson Date: Mon, 5 Sep 2022 20:35:53 +0200 Subject: gui: split GUI into Terminal components --- Scripts/Game/CommandInputArea.cs | 31 +++++++++++++++++++++++++++ Scripts/Game/Game.cs | 11 +++++----- Scripts/Game/Input.cs | 32 ---------------------------- Scripts/Game/Output.cs | 45 ---------------------------------------- Scripts/Game/OutputBlock.cs | 28 ------------------------- Scripts/Game/StatusLine.cs | 27 ------------------------ 6 files changed, 37 insertions(+), 137 deletions(-) create mode 100644 Scripts/Game/CommandInputArea.cs delete mode 100644 Scripts/Game/Input.cs delete mode 100644 Scripts/Game/Output.cs delete mode 100644 Scripts/Game/OutputBlock.cs delete mode 100644 Scripts/Game/StatusLine.cs (limited to 'Scripts/Game') diff --git a/Scripts/Game/CommandInputArea.cs b/Scripts/Game/CommandInputArea.cs new file mode 100644 index 0000000..7d0ba5c --- /dev/null +++ b/Scripts/Game/CommandInputArea.cs @@ -0,0 +1,31 @@ +using Godot; +using Texty.Scripts.Terminal; + +namespace Texty.Scripts.Game +{ + public class CommandInputArea : InputArea + { + [Signal] public delegate void CommandSubmitted(Command command); + [Signal] public delegate void UnknownInputSubmitted(string text); + + private CommandParser CommandParser => GetNodeOrNull($"%{nameof(CommandParser)}"); + + public override void _Ready() + { + TextInput.GrabFocus(); + } + + public override void OnTextEntered(string text) + { + if (text.Empty()) + return; + + TextInput.Clear(); + var command = CommandParser.TryParse(text); + if (command != null) + EmitSignal(nameof(CommandSubmitted), command); + else + EmitSignal(nameof(UnknownInputSubmitted), text); + } + } +} \ No newline at end of file diff --git a/Scripts/Game/Game.cs b/Scripts/Game/Game.cs index 50db736..ff7e4f7 100644 --- a/Scripts/Game/Game.cs +++ b/Scripts/Game/Game.cs @@ -1,12 +1,13 @@ using Godot; +using Texty.Scripts.Terminal; namespace Texty.Scripts.Game { public class Game : Node { - private Input Input => GetNodeOrNull($"%{nameof(Input)}"); - private Output Output => GetNodeOrNull($"%{nameof(Output)}"); - private StatusLine StatusLine => GetNodeOrNull($"%{nameof(StatusLine)}"); + private InputArea InputArea => GetNodeOrNull($"%{nameof(InputArea)}"); + private OutputArea OutputArea => GetNodeOrNull($"%{nameof(OutputArea)}"); + private StatusArea StatusArea => GetNodeOrNull($"%{nameof(StatusArea)}"); public override void _Ready() { @@ -14,12 +15,12 @@ namespace Texty.Scripts.Game public void OnCommandSubmitted(Command command) { - Output.Push($"! {command}"); + OutputArea.Push($"! {command}"); } public void OnUnknownInputSubmitted(string text) { - Output.Push($"? {text}"); + OutputArea.Push($"? {text}"); } } } \ No newline at end of file diff --git a/Scripts/Game/Input.cs b/Scripts/Game/Input.cs deleted file mode 100644 index 90a9962..0000000 --- a/Scripts/Game/Input.cs +++ /dev/null @@ -1,32 +0,0 @@ -using Godot; - -namespace Texty.Scripts.Game -{ - public class Input : PanelContainer - { - [Signal] public delegate void CommandSubmitted(Command command); - [Signal] public delegate void UnknownInputSubmitted(string text); - - private CommandParser CommandParser => GetNodeOrNull($"%{nameof(CommandParser)}"); - private Label PromptLabel => GetNodeOrNull