-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDialogText.cs
79 lines (71 loc) · 1.98 KB
/
DialogText.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
using Godot;
namespace Game1.Core.Scripts
{
public class DialogText : RichTextLabel
{
private Polygon2D box;
private string[] dialog;
private int page = 0;
private bool active = false;
public override void _Ready()
{
box = GetParent<Polygon2D>();
SetProcessInput(true);
SetVisibleCharacters(0);
hide();
}
public override void _Input(InputEvent @event)
{
if (active && @event.IsActionPressed("left_click"))
{
GetTree().SetInputAsHandled();
if (VisibleCharacters >= GetTotalCharacterCount())
{
if (page < dialog.Length - 1)
{
page += 1;
SetBbcode(dialog[page]);
VisibleCharacters = 0;
}
else
{
hide();
page = 0;
}
}
else
{
VisibleCharacters = GetTotalCharacterCount();
}
}
}
private void _on_Timer_timeout()
{
VisibleCharacters += 1;
}
public void _ReceiveText(string text)
{
page = 0;
dialog = text.Split("\\n");
SetBbcode(dialog[0]);
SetVisibleCharacters(0);
show();
}
private void hide()
{
active = false;
EmitSignal(nameof(SignalDialogActive), active);
Visible = false;
box.Visible = false;
}
private void show()
{
active = true;
EmitSignal(nameof(SignalDialogActive), active);
Visible = true;
box.Visible = true;
}
[Signal]
delegate void SignalDialogActive(bool active);
}
}