diff options
| author | Sophia Pearson <codergal89@gmail.com> | 2022-09-05 20:35:53 +0200 |
|---|---|---|
| committer | Sophia Pearson <codergal89@gmail.com> | 2022-09-05 20:35:53 +0200 |
| commit | f20bd89dc4a7bf14a88b1effcaa1887b29314525 (patch) | |
| tree | d114787f68efd2a7d61d95fa9c84e8e5d69a7c11 /Scripts | |
| parent | 1b477b62f8be8c546a35dbd1d2688ebf623c496f (diff) | |
| download | texty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.tar.xz texty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.zip | |
gui: split GUI into Terminal components
Diffstat (limited to 'Scripts')
| -rw-r--r-- | Scripts/Game/CommandInputArea.cs (renamed from Scripts/Game/Input.cs) | 11 | ||||
| -rw-r--r-- | Scripts/Game/Game.cs | 11 | ||||
| -rw-r--r-- | Scripts/Terminal/InputArea.cs | 15 | ||||
| -rw-r--r-- | Scripts/Terminal/OutputArea.cs (renamed from Scripts/Game/Output.cs) | 5 | ||||
| -rw-r--r-- | Scripts/Terminal/OutputBlock.cs (renamed from Scripts/Game/OutputBlock.cs) | 2 | ||||
| -rw-r--r-- | Scripts/Terminal/StatusArea.cs (renamed from Scripts/Game/StatusLine.cs) | 4 |
6 files changed, 32 insertions, 16 deletions
diff --git a/Scripts/Game/Input.cs b/Scripts/Game/CommandInputArea.cs index 90a9962..7d0ba5c 100644 --- a/Scripts/Game/Input.cs +++ b/Scripts/Game/CommandInputArea.cs @@ -1,22 +1,21 @@ using Godot; +using Texty.Scripts.Terminal; namespace Texty.Scripts.Game { - public class Input : PanelContainer + public class CommandInputArea : InputArea { [Signal] public delegate void CommandSubmitted(Command command); [Signal] public delegate void UnknownInputSubmitted(string text); - + private CommandParser CommandParser => GetNodeOrNull<CommandParser>($"%{nameof(CommandParser)}"); - private Label PromptLabel => GetNodeOrNull<Label>($"%{nameof(PromptLabel)}"); - private LineEdit TextInput => GetNodeOrNull<LineEdit>($"%{nameof(TextInput)}"); - + public override void _Ready() { TextInput.GrabFocus(); } - public void OnTextEntered(string text) + public override void OnTextEntered(string text) { if (text.Empty()) return; 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<Input>($"%{nameof(Input)}"); - private Output Output => GetNodeOrNull<Output>($"%{nameof(Output)}"); - private StatusLine StatusLine => GetNodeOrNull<StatusLine>($"%{nameof(StatusLine)}"); + private InputArea InputArea => GetNodeOrNull<InputArea>($"%{nameof(InputArea)}"); + private OutputArea OutputArea => GetNodeOrNull<OutputArea>($"%{nameof(OutputArea)}"); + private StatusArea StatusArea => GetNodeOrNull<StatusArea>($"%{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/Terminal/InputArea.cs b/Scripts/Terminal/InputArea.cs new file mode 100644 index 0000000..eb78d38 --- /dev/null +++ b/Scripts/Terminal/InputArea.cs @@ -0,0 +1,15 @@ +using System; +using Godot; + +namespace Texty.Scripts.Terminal +{ + public abstract class InputArea : HBoxContainer + { + protected Label PromptLabel => GetNodeOrNull<Label>($"%{nameof(PromptLabel)}"); + protected LineEdit TextInput => GetNodeOrNull<LineEdit>($"%{nameof(TextInput)}"); + + public new bool HasFocus => TextInput?.HasFocus() ?? false; + + public abstract void OnTextEntered(string text); + } +}
\ No newline at end of file diff --git a/Scripts/Game/Output.cs b/Scripts/Terminal/OutputArea.cs index abd3328..6de4ac1 100644 --- a/Scripts/Game/Output.cs +++ b/Scripts/Terminal/OutputArea.cs @@ -3,10 +3,11 @@ using System.Diagnostics; using System.Linq; using Godot; using Godot.Collections; +using Texty.Scripts.Game; -namespace Texty.Scripts.Game +namespace Texty.Scripts.Terminal { - public class Output : PanelContainer + public class OutputArea : ScrollContainer { [Export(PropertyHint.File, "*.tscn")] public PackedScene OutputBlockScene; public Array<string> TextBlocks => new Array<string>(BlockNodes.ToList().Select(block => block.Content)); diff --git a/Scripts/Game/OutputBlock.cs b/Scripts/Terminal/OutputBlock.cs index 491958c..b611cb5 100644 --- a/Scripts/Game/OutputBlock.cs +++ b/Scripts/Terminal/OutputBlock.cs @@ -1,6 +1,6 @@ using Godot; -namespace Texty.Scripts.Game +namespace Texty.Scripts.Terminal { public class OutputBlock : MarginContainer { diff --git a/Scripts/Game/StatusLine.cs b/Scripts/Terminal/StatusArea.cs index 8e19cb4..1b1b6e3 100644 --- a/Scripts/Game/StatusLine.cs +++ b/Scripts/Terminal/StatusArea.cs @@ -1,8 +1,8 @@ using Godot; -namespace Texty.Scripts.Game +namespace Texty.Scripts.Terminal { - public class StatusLine : PanelContainer + public class StatusArea : HBoxContainer { private string _titleText = ""; private RichTextLabel TitleLabel => GetNodeOrNull<RichTextLabel>($"%{nameof(TitleLabel)}"); |
