summaryrefslogtreecommitdiff
path: root/Scripts
diff options
context:
space:
mode:
Diffstat (limited to 'Scripts')
-rw-r--r--Scripts/Game/Command.cs (renamed from Scripts/Command.cs)2
-rw-r--r--Scripts/Game/CommandParser.cs (renamed from Scripts/CommandParser.cs)2
-rw-r--r--Scripts/Game/Commands/LookCommand.cs (renamed from Scripts/Commands/LookCommand.cs)1
-rw-r--r--Scripts/Game/Game.cs25
-rw-r--r--Scripts/Game/Input.cs29
-rw-r--r--Scripts/Game/Output.cs43
-rw-r--r--Scripts/Game/OutputBlock.cs28
-rw-r--r--Scripts/Game/StatusLine.cs45
-rw-r--r--Scripts/InputContainer.cs50
-rw-r--r--Scripts/OutputContainer.cs52
-rw-r--r--Scripts/OutputRow.cs69
-rw-r--r--Scripts/StartMenu.cs46
12 files changed, 149 insertions, 243 deletions
diff --git a/Scripts/Command.cs b/Scripts/Game/Command.cs
index e784576..07d7c84 100644
--- a/Scripts/Command.cs
+++ b/Scripts/Game/Command.cs
@@ -1,6 +1,6 @@
using Godot;
-namespace Texty.Scripts
+namespace Texty.Scripts.Game
{
public enum CommandType
{
diff --git a/Scripts/CommandParser.cs b/Scripts/Game/CommandParser.cs
index 97d8025..5f8249a 100644
--- a/Scripts/CommandParser.cs
+++ b/Scripts/Game/CommandParser.cs
@@ -2,7 +2,7 @@ using System.Linq;
using Godot;
using Texty.Scripts.Commands;
-namespace Texty.Scripts
+namespace Texty.Scripts.Game
{
public class CommandParser : Node
{
diff --git a/Scripts/Commands/LookCommand.cs b/Scripts/Game/Commands/LookCommand.cs
index 08783a9..b7910cc 100644
--- a/Scripts/Commands/LookCommand.cs
+++ b/Scripts/Game/Commands/LookCommand.cs
@@ -1,4 +1,5 @@
using System.Linq;
+using Texty.Scripts.Game;
namespace Texty.Scripts.Commands
{
diff --git a/Scripts/Game/Game.cs b/Scripts/Game/Game.cs
new file mode 100644
index 0000000..50db736
--- /dev/null
+++ b/Scripts/Game/Game.cs
@@ -0,0 +1,25 @@
+using Godot;
+
+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)}");
+
+ public override void _Ready()
+ {
+ }
+
+ public void OnCommandSubmitted(Command command)
+ {
+ Output.Push($"! {command}");
+ }
+
+ public void OnUnknownInputSubmitted(string text)
+ {
+ Output.Push($"? {text}");
+ }
+ }
+} \ No newline at end of file
diff --git a/Scripts/Game/Input.cs b/Scripts/Game/Input.cs
new file mode 100644
index 0000000..2342ac2
--- /dev/null
+++ b/Scripts/Game/Input.cs
@@ -0,0 +1,29 @@
+using Godot;
+
+namespace Texty.Scripts.Game
+{
+ public class Input : PanelContainer
+ {
+ [Signal] public delegate void CommandSubmitted(Command command);
+ [Signal] public delegate void UnknownInputSubmitted(string text);
+
+ private CommandParser CommandParser => GetNodeOrNull<CommandParser>($"%{nameof(CommandParser)}");
+ private Label Prompt => GetNodeOrNull<Label>($"%{nameof(Prompt)}");
+ private LineEdit Text => GetNodeOrNull<LineEdit>($"%{nameof(Text)}");
+
+ public override void _Ready()
+ {
+ Text.GrabFocus();
+ }
+
+ public void OnTextEntered(string text)
+ {
+ Text.Clear();
+ var command = CommandParser.TryParse(text);
+ if (command != null)
+ EmitSignal(nameof(CommandSubmitted), command);
+ else
+ EmitSignal(nameof(UnknownInputSubmitted), text);
+ }
+ }
+} \ No newline at end of file
diff --git a/Scripts/Game/Output.cs b/Scripts/Game/Output.cs
new file mode 100644
index 0000000..be943f7
--- /dev/null
+++ b/Scripts/Game/Output.cs
@@ -0,0 +1,43 @@
+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!");
+ }
+
+ public void Clear()
+ {
+ BlockNodes.ToList().ForEach(block =>
+ {
+ LineContainer.RemoveChild(block);
+ block.QueueFree();
+ });
+ }
+
+ public void Push(string text)
+ {
+ 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
new file mode 100644
index 0000000..491958c
--- /dev/null
+++ b/Scripts/Game/OutputBlock.cs
@@ -0,0 +1,28 @@
+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
index 4a3fb23..ef98a0a 100644
--- a/Scripts/Game/StatusLine.cs
+++ b/Scripts/Game/StatusLine.cs
@@ -2,29 +2,26 @@ using Godot;
namespace Texty.Scripts.Game
{
- public class StatusLine : PanelContainer
- {
- private string _titleText = "Title Text";
-
- [Export]
- public string Title
- {
- get => _titleText;
- set
- {
- if (TitleLabel != null)
- TitleLabel.Text = value;
- _titleText = value;
- }
- }
+ public class StatusLine : PanelContainer
+ {
+ private string _titleText = "Title Text";
+ private RichTextLabel TitleLabel => GetNodeOrNull<RichTextLabel>($"%{nameof(TitleLabel)}");
- public RichTextLabel TitleLabel;
-
- public override void _Ready()
- {
- TitleLabel = GetNode<RichTextLabel>($"%{nameof(TitleLabel)}");
- TitleLabel.Text = _titleText;
- }
- }
-}
+ [Export]
+ public string Title
+ {
+ get => _titleText;
+ set
+ {
+ _titleText = value;
+ if (TitleLabel != null)
+ TitleLabel.Text = GodotSharp.Singleton.Tr(value);
+ }
+ }
+ public override void _Ready()
+ {
+ Title = _titleText;
+ }
+ }
+} \ No newline at end of file
diff --git a/Scripts/InputContainer.cs b/Scripts/InputContainer.cs
deleted file mode 100644
index 300d568..0000000
--- a/Scripts/InputContainer.cs
+++ /dev/null
@@ -1,50 +0,0 @@
-using Godot;
-
-namespace Texty.Scripts
-{
- public abstract class InputContainer : HBoxContainer
- {
- [Signal] public delegate void InputSubmitted(string text);
-
- public LineEdit InputField;
- public Button SubmitButton;
-
- public override void _Ready()
- {
- InputField = GetNode<LineEdit>(nameof(InputField));
- SubmitButton = GetNode<Button>(nameof(SubmitButton));
-
- SubmitButton.Disabled = InputField.Text.Empty();
- }
-
- public void OnInputChanged(string newText)
- {
- SubmitButton.Disabled = newText.Empty();
- }
-
- public void OnInputSubmitted(string newText)
- {
- SubmitText(newText);
- }
-
- public void OnInputSubmitted()
- {
- SubmitText(InputField.Text);
- }
-
- public void OnVisibilityChanged()
- {
- if (Visible)
- InputField.GrabFocus();
- else
- InputField.ReleaseFocus();
- }
-
- private void SubmitText(string newText)
- {
- if (newText.Empty()) return;
- EmitSignal(nameof(InputSubmitted), newText);
- InputField.Clear();
- }
- }
-} \ No newline at end of file
diff --git a/Scripts/OutputContainer.cs b/Scripts/OutputContainer.cs
deleted file mode 100644
index 5db1fe6..0000000
--- a/Scripts/OutputContainer.cs
+++ /dev/null
@@ -1,52 +0,0 @@
-using System.Linq;
-using Godot;
-
-namespace Texty.Scripts
-{
- public abstract class OutputContainer : PanelContainer
- {
- private double _lastScrollLimit;
-
- private VScrollBar _scrollBar;
-
- [Export(PropertyHint.Range, "10,40,1")] public int MaximumRows = 20;
-
- public VBoxContainer OutputRows;
- public ScrollContainer ScrollContainer;
-
- public override void _Ready()
- {
- ScrollContainer = GetNode<ScrollContainer>(nameof(ScrollContainer));
- _scrollBar = ScrollContainer.GetVScrollbar();
- OutputRows = ScrollContainer.GetNode<VBoxContainer>(nameof(OutputRows));
-
- _lastScrollLimit = _scrollBar.MaxValue;
- _scrollBar.Connect("changed", this, nameof(OnScrollLimitChanged));
- }
-
- public void Add(OutputRow row)
- {
- OutputRows.AddChild(row);
- ExpungeOldRows();
- }
-
- public void OnScrollLimitChanged()
- {
- if (!(_lastScrollLimit < _scrollBar.MaxValue)) return;
- _lastScrollLimit = _scrollBar.MaxValue;
- ScrollContainer.ScrollVertical = (int)_scrollBar.MaxValue;
- }
-
- private void ExpungeOldRows()
- {
- GD.Range(OutputRows.GetChildCount() - MaximumRows)
- .Select(idx => OutputRows.GetChild(idx))
- .ToList()
- .ForEach(row =>
- {
- OutputRows.RemoveChild(row);
- row.QueueFree();
- });
- }
- }
-} \ No newline at end of file
diff --git a/Scripts/OutputRow.cs b/Scripts/OutputRow.cs
deleted file mode 100644
index cfbb2e7..0000000
--- a/Scripts/OutputRow.cs
+++ /dev/null
@@ -1,69 +0,0 @@
-using System;
-using Godot;
-
-namespace Texty.Scripts
-{
- public abstract class OutputRow : VBoxContainer
- {
- [Signal] public delegate void InputTextChanged(string newText);
- [Signal] public delegate void OutputTextChanged(string newText);
-
- private string _inputText = "";
- private string _outputText = "";
-
- public Label Input;
- public Label Output;
-
- [Export]
- public string InputText
- {
- get => _inputText;
- set => UpdateText(Field.Input, value ?? "");
- }
-
- [Export]
- public string OutputText
- {
- get => _outputText;
- set => UpdateText(Field.Output, value ?? "");
- }
-
- public override void _Ready()
- {
- Input = GetNode<Label>(nameof(Input));
- UpdateLabel(Input, _inputText);
- Output = GetNode<Label>(nameof(Output));
- UpdateLabel(Output, _outputText);
- }
-
- private void UpdateText(Field field, string value)
- {
- switch (field)
- {
- case Field.Input:
- _inputText = value;
- EmitSignal(nameof(InputTextChanged), _inputText);
- UpdateLabel(Input, value);
- break;
- case Field.Output:
- _outputText = value;
- EmitSignal(nameof(OutputTextChanged), value);
- UpdateLabel(Output, value);
- break;
- default:
- throw new ArgumentOutOfRangeException(nameof(field), field, "No such field!");
- }
- }
-
- private static void UpdateLabel(Label label, string value)
- {
- if (label != null) label.Text = value;
- }
-
- private enum Field
- {
- Input,
- Output
- }
- }
-} \ No newline at end of file
diff --git a/Scripts/StartMenu.cs b/Scripts/StartMenu.cs
deleted file mode 100644
index a1f64cc..0000000
--- a/Scripts/StartMenu.cs
+++ /dev/null
@@ -1,46 +0,0 @@
-using Godot;
-
-namespace Texty.Scripts
-{
- public class StartMenu : MarginContainer
- {
- [Signal] public delegate void QuitGame();
- [Signal] public delegate void ShowCredits();
- [Signal] public delegate void StartGame();
-
- public Button CreditsButton;
- public Button QuitButton;
- public Button StartButton;
-
- public override void _Ready()
- {
- var buttons = FindNode("Buttons");
- CreditsButton = buttons.GetNode<Button>(nameof(CreditsButton));
- QuitButton = buttons.GetNode<Button>(nameof(QuitButton));
- StartButton = buttons.GetNode<Button>(nameof(StartButton));
- }
-
- public void OnCreditsButtonPressed()
- {
- EmitSignal(nameof(ShowCredits));
- }
-
- public void OnQuitButtonPressed()
- {
- EmitSignal(nameof(QuitGame));
- }
-
- public void OnStartButtonPressed()
- {
- EmitSignal(nameof(StartGame));
- }
-
- public void OnVisibilityChanged()
- {
- if(Visible)
- StartButton.GrabFocus();
- else
- StartButton.ReleaseFocus();
- }
- }
-} \ No newline at end of file