From 47c6d08f53e09d7ee7528e50b7fe0d3f75a9d267 Mon Sep 17 00:00:00 2001 From: vaporvee Date: Sun, 12 Feb 2023 10:44:23 +0100 Subject: [PATCH] improved typewriter and cleaned dialogue code --- scenes/gui/dialog_bubble.tscn | 6 +- .../dialogue-system/dialog_bubble.cs | 262 +++++++++--------- 2 files changed, 138 insertions(+), 130 deletions(-) diff --git a/scenes/gui/dialog_bubble.tscn b/scenes/gui/dialog_bubble.tscn index 3a51240..b7d45bb 100644 --- a/scenes/gui/dialog_bubble.tscn +++ b/scenes/gui/dialog_bubble.tscn @@ -11,9 +11,7 @@ script = ExtResource("1_xtj1q") metadata/_edit_use_anchors_ = true [node name="typewriter_timer" type="Timer" parent="."] -wait_time = 0.04 -one_shot = true -metadata/charsAtOnce = 60 +wait_time = 0.05 [node name="box" type="ColorRect" parent="."] anchors_preset = -1 @@ -102,3 +100,5 @@ theme_override_constants/margin_top = 30 theme_override_constants/margin_right = 60 theme_override_constants/margin_bottom = 30 metadata/_edit_lock_ = true + +[connection signal="timeout" from="typewriter_timer" to="." method="OnTypewriterTimerTimeout"] diff --git a/src/scene-scripts/dialogue-system/dialog_bubble.cs b/src/scene-scripts/dialogue-system/dialog_bubble.cs index 25948a1..bf51b29 100644 --- a/src/scene-scripts/dialogue-system/dialog_bubble.cs +++ b/src/scene-scripts/dialogue-system/dialog_bubble.cs @@ -1,146 +1,154 @@ using Godot; using System.Text.RegularExpressions; +using System.Threading.Tasks; public partial class dialog_bubble : CanvasLayer { - public Variant parsedDlg; - public Variant dlgLines; - public int dlgPointer = 0; - public RichTextLabel richText; - public string name; - public Area2D triggerArea; + public Variant parsedDlg; + public Variant dlgLines; + public int dlgPointer = 0; + public RichTextLabel richText; + public Timer typewriterTimer; + public string name; + public Area2D triggerArea; - /*TODO: + /*TODO: - Dont repeat the same randomized dialogue after you get asked do you need something "else" - add tree support (example: "story" key) - ability to add dialogue begin answers on the fly (special ones are colored) they will be in a dictionary with event IDs or Dictionary keys it also needs an array wich ones are active*/ - public override void _Ready() - { - richText = GetNode("box/rich_text_label"); - } - public void GetDialog(string file, string title, Area2D actor, string playerName, bool introducedVillager) - { - triggerArea = actor; - name = title; + public override void _Ready() + { + richText = GetNode("box/rich_text_label"); + typewriterTimer = GetNode("typewriter_timer"); + } + public void GetDialog(string file, string title, Area2D actor, string playerName, bool introducedVillager) + { + triggerArea = actor; + name = title; - parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText() - .Replace("{player}", "[color=cyan]" + playerName + "[/color]").Replace("{title}", "[color=purple]" + title + "[/color]")); + parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText() + .Replace("{player}", "[color=cyan]" + playerName + "[/color]").Replace("{title}", "[color=purple]" + title + "[/color]")); - if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() != "villager" || introducedVillager) - GetNode