improved typewriter and cleaned dialogue code
This commit is contained in:
@@ -11,9 +11,7 @@ script = ExtResource("1_xtj1q")
|
|||||||
metadata/_edit_use_anchors_ = true
|
metadata/_edit_use_anchors_ = true
|
||||||
|
|
||||||
[node name="typewriter_timer" type="Timer" parent="."]
|
[node name="typewriter_timer" type="Timer" parent="."]
|
||||||
wait_time = 0.04
|
wait_time = 0.05
|
||||||
one_shot = true
|
|
||||||
metadata/charsAtOnce = 60
|
|
||||||
|
|
||||||
[node name="box" type="ColorRect" parent="."]
|
[node name="box" type="ColorRect" parent="."]
|
||||||
anchors_preset = -1
|
anchors_preset = -1
|
||||||
@@ -102,3 +100,5 @@ theme_override_constants/margin_top = 30
|
|||||||
theme_override_constants/margin_right = 60
|
theme_override_constants/margin_right = 60
|
||||||
theme_override_constants/margin_bottom = 30
|
theme_override_constants/margin_bottom = 30
|
||||||
metadata/_edit_lock_ = true
|
metadata/_edit_lock_ = true
|
||||||
|
|
||||||
|
[connection signal="timeout" from="typewriter_timer" to="." method="OnTypewriterTimerTimeout"]
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
using Godot;
|
using Godot;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
public partial class dialog_bubble : CanvasLayer
|
public partial class dialog_bubble : CanvasLayer
|
||||||
{
|
{
|
||||||
@@ -7,6 +8,7 @@ public partial class dialog_bubble : CanvasLayer
|
|||||||
public Variant dlgLines;
|
public Variant dlgLines;
|
||||||
public int dlgPointer = 0;
|
public int dlgPointer = 0;
|
||||||
public RichTextLabel richText;
|
public RichTextLabel richText;
|
||||||
|
public Timer typewriterTimer;
|
||||||
public string name;
|
public string name;
|
||||||
public Area2D triggerArea;
|
public Area2D triggerArea;
|
||||||
|
|
||||||
@@ -18,6 +20,7 @@ public partial class dialog_bubble : CanvasLayer
|
|||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
richText = GetNode<RichTextLabel>("box/rich_text_label");
|
richText = GetNode<RichTextLabel>("box/rich_text_label");
|
||||||
|
typewriterTimer = GetNode<Timer>("typewriter_timer");
|
||||||
}
|
}
|
||||||
public void GetDialog(string file, string title, Area2D actor, string playerName, bool introducedVillager)
|
public void GetDialog(string file, string title, Area2D actor, string playerName, bool introducedVillager)
|
||||||
{
|
{
|
||||||
@@ -52,16 +55,12 @@ public partial class dialog_bubble : CanvasLayer
|
|||||||
//TODO:copy a clean default array and remove already used indexes and copy from clean array when its empty
|
//TODO:copy a clean default array and remove already used indexes and copy from clean array when its empty
|
||||||
}
|
}
|
||||||
|
|
||||||
public void CloseDialog()
|
|
||||||
{
|
|
||||||
Visible = false;
|
|
||||||
dlgPointer = 0;
|
|
||||||
richText.VisibleCharacters = -1;
|
|
||||||
GetNode<Label>("box/name_label").Text = "???";
|
|
||||||
richText.Text = "";
|
|
||||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
|
||||||
}
|
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
|
{
|
||||||
|
DialogControlls();
|
||||||
|
AnswerBoxControlls();
|
||||||
|
}
|
||||||
|
public void DialogControlls()
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("ui_cancel") && Visible) richText.VisibleCharacters = richText.Text.Length;
|
if (Input.IsActionJustPressed("ui_cancel") && Visible) richText.VisibleCharacters = richText.Text.Length;
|
||||||
|
|
||||||
@@ -85,36 +84,20 @@ public partial class dialog_bubble : CanvasLayer
|
|||||||
}
|
}
|
||||||
dlgPointer++;
|
dlgPointer++;
|
||||||
}
|
}
|
||||||
//Typewrite effect
|
|
||||||
if (richText.VisibleCharacters < Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length && GetNode<Timer>("typewriter_timer").IsStopped())
|
|
||||||
{
|
|
||||||
richText.VisibleCharacters++;
|
|
||||||
GetNode<Timer>("typewriter_timer").Start();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (dlgPointer > dlgLines.AsGodotArray().Count)
|
if (dlgPointer > dlgLines.AsGodotArray().Count)
|
||||||
CloseDialog();
|
CloseDialog();
|
||||||
|
|
||||||
//AnswerBox answer "logic"
|
|
||||||
if (GetNode<PanelContainer>("box/panel_container").Visible == true
|
|
||||||
&& GetNode("box/panel_container/margin_container").GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton() != null)
|
|
||||||
{
|
|
||||||
var answer = dlgLines.AsGodotArray()[dlgPointer - 1].AsGodotDictionary()[GetNode<Button>(GetNode("box/panel_container/margin_container")
|
|
||||||
.GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton().GetPath()).Text];
|
|
||||||
GetNode<PanelContainer>("box/panel_container").Visible = false;
|
|
||||||
if (answer.VariantType == Variant.Type.String && answer.AsString().StartsWith("<goto:>"))
|
|
||||||
{
|
|
||||||
GatherDialog(answer.AsString().Replace("<goto:>", ""));
|
|
||||||
UpdateDialog();
|
|
||||||
}
|
|
||||||
dlgPointer++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
public void UpdateDialog()
|
public void UpdateDialog()
|
||||||
{
|
{
|
||||||
richText.Text = dlgLines.AsGodotArray()[dlgPointer].ToString();
|
richText.Text = dlgLines.AsGodotArray()[dlgPointer].ToString();
|
||||||
richText.VisibleCharacters = 0;
|
richText.VisibleCharacters = 0;
|
||||||
GetNode<Timer>("typewriter_timer").Start();
|
typewriterTimer.Start();
|
||||||
|
}
|
||||||
|
public void OnTypewriterTimerTimeout()
|
||||||
|
{
|
||||||
|
if (richText.VisibleCharacters < Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length)
|
||||||
|
richText.VisibleCharacters++;
|
||||||
|
else typewriterTimer.Stop();
|
||||||
}
|
}
|
||||||
public void MakeAnswerBox(string[] dialogOptions)
|
public void MakeAnswerBox(string[] dialogOptions)
|
||||||
{
|
{
|
||||||
@@ -131,6 +114,22 @@ public partial class dialog_bubble : CanvasLayer
|
|||||||
GetNode<PanelContainer>("box/panel_container").Visible = true;
|
GetNode<PanelContainer>("box/panel_container").Visible = true;
|
||||||
parent.GetChild<Button>(0).GrabFocus();
|
parent.GetChild<Button>(0).GrabFocus();
|
||||||
}
|
}
|
||||||
|
public void AnswerBoxControlls()
|
||||||
|
{
|
||||||
|
if (GetNode<PanelContainer>("box/panel_container").Visible == true
|
||||||
|
&& GetNode("box/panel_container/margin_container").GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton() != null)
|
||||||
|
{
|
||||||
|
var answer = dlgLines.AsGodotArray()[dlgPointer - 1].AsGodotDictionary()[GetNode<Button>(GetNode("box/panel_container/margin_container")
|
||||||
|
.GetChild(0).GetChild<Button>(0).ButtonGroup.GetPressedButton().GetPath()).Text];
|
||||||
|
GetNode<PanelContainer>("box/panel_container").Visible = false;
|
||||||
|
if (answer.VariantType == Variant.Type.String && answer.AsString().StartsWith("<goto:>"))
|
||||||
|
{
|
||||||
|
GatherDialog(answer.AsString().Replace("<goto:>", ""));
|
||||||
|
UpdateDialog();
|
||||||
|
}
|
||||||
|
dlgPointer++;
|
||||||
|
}
|
||||||
|
}
|
||||||
public void InDialogEvents(int eventID) //maybe replaceable with jsonrpc?
|
public void InDialogEvents(int eventID) //maybe replaceable with jsonrpc?
|
||||||
{
|
{
|
||||||
switch (eventID)
|
switch (eventID)
|
||||||
@@ -143,4 +142,13 @@ public partial class dialog_bubble : CanvasLayer
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public void CloseDialog()
|
||||||
|
{
|
||||||
|
Visible = false;
|
||||||
|
dlgPointer = 0;
|
||||||
|
richText.VisibleCharacters = -1;
|
||||||
|
GetNode<Label>("box/name_label").Text = "???";
|
||||||
|
richText.Text = "";
|
||||||
|
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
||||||
|
}
|
||||||
}
|
}
|
Reference in New Issue
Block a user