typewriting effect in dialogue
This commit is contained in:
@@ -9,6 +9,10 @@
|
|||||||
script = ExtResource("1_5xn2c")
|
script = ExtResource("1_5xn2c")
|
||||||
metadata/_edit_use_anchors_ = true
|
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="."]
|
[node name="box" type="ColorRect" parent="."]
|
||||||
anchors_preset = -1
|
anchors_preset = -1
|
||||||
anchor_left = 0.083
|
anchor_left = 0.083
|
||||||
|
@@ -7,11 +7,13 @@ public partial class dialog_bubble : CanvasLayer
|
|||||||
public Variant parsedDlg;
|
public Variant parsedDlg;
|
||||||
public ArrayList dlgLines = new ArrayList();
|
public ArrayList dlgLines = new ArrayList();
|
||||||
public int dlgPointer = 0;
|
public int dlgPointer = 0;
|
||||||
|
public RichTextLabel richText;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
|
richText = GetNode<RichTextLabel>("box/rich_text_label");
|
||||||
dlgLines.Add("Hello! I'm a debug character and...");
|
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)
|
public void GetDialog(string file, string title, Variant actor)
|
||||||
{
|
{
|
||||||
@@ -26,15 +28,25 @@ public partial class dialog_bubble : CanvasLayer
|
|||||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
||||||
Visible = false;
|
Visible = false;
|
||||||
dlgPointer = 0;
|
dlgPointer = 0;
|
||||||
GetNode<RichTextLabel>("box/rich_text_label").Text = "";
|
richText.VisibleCharacters = -1;
|
||||||
GetNode<Label>("box/name_label").Text = "???";
|
GetNode<Label>("box/name_label").Text = "???";
|
||||||
|
richText.Text = "";
|
||||||
}
|
}
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("ui_accept"))
|
if (richText.VisibleCharacters < richText.Text.Length && GetNode<Timer>("typewriter_timer").IsStopped())
|
||||||
{
|
{
|
||||||
var textBlock = GetNode<RichTextLabel>("box/rich_text_label");
|
richText.VisibleCharacters++;
|
||||||
if (dlgPointer < dlgLines.Count && dlgLines[dlgPointer] is string) textBlock.Text = dlgLines[dlgPointer].ToString();
|
GetNode<Timer>("typewriter_timer").Start();
|
||||||
|
}
|
||||||
|
if (Input.IsActionJustPressed("ui_accept") && richText.VisibleCharacters == -1 | richText.Text.Length == richText.VisibleCharacters)
|
||||||
|
{
|
||||||
|
if (dlgPointer < dlgLines.Count && dlgLines[dlgPointer] is string)
|
||||||
|
{
|
||||||
|
richText.Text = dlgLines[dlgPointer].ToString();
|
||||||
|
richText.VisibleCharacters = 0;
|
||||||
|
GetNode<Timer>("typewriter_timer").Start();
|
||||||
|
}
|
||||||
dlgPointer++;
|
dlgPointer++;
|
||||||
}
|
}
|
||||||
if (dlgPointer > dlgLines.Count)
|
if (dlgPointer > dlgLines.Count)
|
||||||
|
Reference in New Issue
Block a user