summaryrefslogtreecommitdiff
path: root/Scripts/Terminal
diff options
context:
space:
mode:
authorSophia Pearson <codergal89@gmail.com>2022-09-05 20:35:53 +0200
committerSophia Pearson <codergal89@gmail.com>2022-09-05 20:35:53 +0200
commitf20bd89dc4a7bf14a88b1effcaa1887b29314525 (patch)
treed114787f68efd2a7d61d95fa9c84e8e5d69a7c11 /Scripts/Terminal
parent1b477b62f8be8c546a35dbd1d2688ebf623c496f (diff)
downloadtexty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.tar.xz
texty-f20bd89dc4a7bf14a88b1effcaa1887b29314525.zip
gui: split GUI into Terminal components
Diffstat (limited to 'Scripts/Terminal')
-rw-r--r--Scripts/Terminal/InputArea.cs15
-rw-r--r--Scripts/Terminal/OutputArea.cs46
-rw-r--r--Scripts/Terminal/OutputBlock.cs28
-rw-r--r--Scripts/Terminal/StatusArea.cs27
4 files changed, 116 insertions, 0 deletions
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/Terminal/OutputArea.cs b/Scripts/Terminal/OutputArea.cs
new file mode 100644
index 0000000..6de4ac1
--- /dev/null
+++ b/Scripts/Terminal/OutputArea.cs
@@ -0,0 +1,46 @@
+using System.Collections.Generic;
+using System.Diagnostics;
+using System.Linq;
+using Godot;
+using Godot.Collections;
+using Texty.Scripts.Game;
+
+namespace Texty.Scripts.Terminal
+{
+ public class OutputArea : ScrollContainer
+ {
+ [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/Terminal/OutputBlock.cs b/Scripts/Terminal/OutputBlock.cs
new file mode 100644
index 0000000..b611cb5
--- /dev/null
+++ b/Scripts/Terminal/OutputBlock.cs
@@ -0,0 +1,28 @@
+using Godot;
+
+namespace Texty.Scripts.Terminal
+{
+ 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/Terminal/StatusArea.cs b/Scripts/Terminal/StatusArea.cs
new file mode 100644
index 0000000..1b1b6e3
--- /dev/null
+++ b/Scripts/Terminal/StatusArea.cs
@@ -0,0 +1,27 @@
+using Godot;
+
+namespace Texty.Scripts.Terminal
+{
+ public class StatusArea : HBoxContainer
+ {
+ 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