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/Game | |
| parent | 1b477b62f8be8c546a35dbd1d2688ebf623c496f (diff) | |
| download | texty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.tar.xz texty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.zip | |
gui: split GUI into Terminal components
Diffstat (limited to 'Scripts/Game')
| -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/Game/Output.cs | 45 | ||||
| -rw-r--r-- | Scripts/Game/OutputBlock.cs | 28 | ||||
| -rw-r--r-- | Scripts/Game/StatusLine.cs | 27 |
5 files changed, 11 insertions, 111 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/Game/Output.cs b/Scripts/Game/Output.cs deleted file mode 100644 index abd3328..0000000 --- a/Scripts/Game/Output.cs +++ /dev/null @@ -1,45 +0,0 @@ -using System.Collections.Generic; -using System.Diagnostics; -using System.Linq; -using Godot; -using Godot.Collections; - -namespace Texty.Scripts.Game -{ - public class Output : PanelContainer - { - [Export(PropertyHint.File, "*.tscn")] public PackedScene OutputBlockScene; - public Array<string> TextBlocks => new Array<string>(BlockNodes.ToList().Select(block => block.Content)); - - private VBoxContainer LineContainer => GetNodeOrNull<VBoxContainer>($"%{nameof(LineContainer)}"); - - private IEnumerable<OutputBlock> BlockNodes => - GD.Range(LineContainer?.GetChildCount() ?? 0) - .Select(index => LineContainer.GetChild(index)) - .Cast<OutputBlock>(); - - public override void _Ready() - { - Debug.Assert(OutputBlockScene != null, "OutputBlockScene has not been configured!"); - Debug.Assert(OutputBlockScene.CanInstance(), "OutputBlockScene can not be instanced!"); - Clear(); - } - - public void Clear() - { - BlockNodes.ToList().ForEach(block => - { - LineContainer.RemoveChild(block); - block.QueueFree(); - }); - } - - public void Push(string text) - { - if (text.Empty()) return; - var block = OutputBlockScene.Instance<OutputBlock>(); - block.Content = text; - LineContainer.AddChild(block); - } - } -}
\ No newline at end of file diff --git a/Scripts/Game/OutputBlock.cs b/Scripts/Game/OutputBlock.cs deleted file mode 100644 index 491958c..0000000 --- a/Scripts/Game/OutputBlock.cs +++ /dev/null @@ -1,28 +0,0 @@ -using Godot; - -namespace Texty.Scripts.Game -{ - public class OutputBlock : MarginContainer - { - private string _content = ""; - - private RichTextLabel ContentLabel => GetNodeOrNull<RichTextLabel>($"%{nameof(ContentLabel)}"); - - [Export(PropertyHint.MultilineText)] - public string Content - { - get => ContentLabel?.BbcodeText ?? ""; - set - { - _content = value; - if (ContentLabel != null) - ContentLabel.BbcodeText = GodotSharp.Singleton.Tr(_content); - } - } - - public override void _Ready() - { - Content = _content; - } - } -}
\ No newline at end of file diff --git a/Scripts/Game/StatusLine.cs b/Scripts/Game/StatusLine.cs deleted file mode 100644 index 8e19cb4..0000000 --- a/Scripts/Game/StatusLine.cs +++ /dev/null @@ -1,27 +0,0 @@ -using Godot; - -namespace Texty.Scripts.Game -{ - public class StatusLine : PanelContainer - { - private string _titleText = ""; - private RichTextLabel TitleLabel => GetNodeOrNull<RichTextLabel>($"%{nameof(TitleLabel)}"); - - [Export] - public string Title - { - get => _titleText; - set - { - _titleText = value; - if (TitleLabel != null) - TitleLabel.BbcodeText = GodotSharp.Singleton.Tr(value); - } - } - - public override void _Ready() - { - Title = _titleText; - } - } -}
\ No newline at end of file |
