From 1648171f0b830f17d972bc8c8be5fb0cab07a56f Mon Sep 17 00:00:00 2001 From: cmod31 Date: Fri, 3 Feb 2023 22:25:49 +0100 Subject: [PATCH] typewriting effect in dialogue --- scenes/gui/dialog_bubble.tscn | 4 ++++ .../dialogue-system/dialog_bubble.cs | 22 ++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/scenes/gui/dialog_bubble.tscn b/scenes/gui/dialog_bubble.tscn index 9fb8033..be9775e 100644 --- a/scenes/gui/dialog_bubble.tscn +++ b/scenes/gui/dialog_bubble.tscn @@ -9,6 +9,10 @@ script = ExtResource("1_5xn2c") metadata/_edit_use_anchors_ = true +[node name="typewriter_timer" type="Timer" parent="."] +wait_time = 0.05 +one_shot = true + [node name="box" type="ColorRect" parent="."] anchors_preset = -1 anchor_left = 0.083 diff --git a/src/scene-scripts/dialogue-system/dialog_bubble.cs b/src/scene-scripts/dialogue-system/dialog_bubble.cs index 0c07f75..176881b 100644 --- a/src/scene-scripts/dialogue-system/dialog_bubble.cs +++ b/src/scene-scripts/dialogue-system/dialog_bubble.cs @@ -7,11 +7,13 @@ public partial class dialog_bubble : CanvasLayer public Variant parsedDlg; public ArrayList dlgLines = new ArrayList(); public int dlgPointer = 0; + public RichTextLabel richText; public override void _Ready() { + richText = GetNode("box/rich_text_label"); dlgLines.Add("Hello! I'm a debug character and..."); - dlgLines.Add("[center][b][wave amp=50 freq=15][rainbow]This is cool test text[/rainbow][/wave][/b][/center]"); + dlgLines.Add("[center][b][wave amp=50 freq=15][rainbow]This is cool test text"); //bbcode gets counted to so typewrite effect takes decades //make a seperate variable without bbcode and count that instead } public void GetDialog(string file, string title, Variant actor) { @@ -26,15 +28,25 @@ public partial class dialog_bubble : CanvasLayer if (GetParent().Name == "player") GetParent().allowMovement = true; Visible = false; dlgPointer = 0; - GetNode("box/rich_text_label").Text = ""; + richText.VisibleCharacters = -1; GetNode