diff options
Diffstat (limited to 'Scripts/Terminal')
| -rw-r--r-- | Scripts/Terminal/InputArea.cs | 15 | ||||
| -rw-r--r-- | Scripts/Terminal/OutputArea.cs | 46 | ||||
| -rw-r--r-- | Scripts/Terminal/OutputBlock.cs | 28 | ||||
| -rw-r--r-- | Scripts/Terminal/StatusArea.cs | 27 |
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 |
