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 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Scripts/Game/CommandInputArea.cs (limited to 'Scripts/Game/CommandInputArea.cs') 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 -- cgit v1.2.3