dialogue system changes
This commit is contained in:
@@ -13,9 +13,9 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"welcome": [
|
"welcome": [
|
||||||
"Oh hello, [color=blue]{player}[/color]... You look great! What do you want from me?",
|
"Oh hello, {player}... You look great! What do you want from me?",
|
||||||
"Hey, [color=blue]{player}[/color]! Hope you have fun today! So what do you want?",
|
"Hey, {player}! Hope you have fun today! So what do you want?",
|
||||||
"Hi! What's up [color=blue]{player}[/color]?"
|
"Hi! What's up {player}?"
|
||||||
],
|
],
|
||||||
"else": [
|
"else": [
|
||||||
"Do you need something else?",
|
"Do you need something else?",
|
||||||
@@ -23,7 +23,7 @@
|
|||||||
],
|
],
|
||||||
"goodbye": [
|
"goodbye": [
|
||||||
"Was nice talking to you goodbye!",
|
"Was nice talking to you goodbye!",
|
||||||
"Have a great day, [color=blue]{player}[/color]!"
|
"Have a great day, {player}!"
|
||||||
],
|
],
|
||||||
"tipp": [
|
"tipp": [
|
||||||
[
|
[
|
||||||
|
@@ -11,7 +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.05
|
wait_time = 0.04
|
||||||
one_shot = true
|
one_shot = true
|
||||||
metadata/charsAtOnce = 60
|
metadata/charsAtOnce = 60
|
||||||
|
|
||||||
|
@@ -5,79 +5,80 @@ using System.Text.RegularExpressions;
|
|||||||
|
|
||||||
public partial class dialog_bubble : CanvasLayer
|
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 RichTextLabel richText;
|
||||||
public int dialogOptionsLength = 1;
|
public int dialogOptionsLength = 1;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
richText = GetNode<RichTextLabel>("box/rich_text_label");
|
richText = GetNode<RichTextLabel>("box/rich_text_label");
|
||||||
}
|
}
|
||||||
public void GetDialog(string file, string title, Variant actor, string playerName)
|
public void GetDialog(string file, string title, Variant actor, string playerName)
|
||||||
{
|
{
|
||||||
parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText().Replace("{player}", playerName));
|
playerName = "[color=blue]" + playerName + "[/color]";
|
||||||
GetNode<Label>("box/name_label").Text = title;
|
parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText().Replace("{player}", playerName));
|
||||||
GD.Print("Now talking to: " + actor);
|
GetNode<Label>("box/name_label").Text = title;
|
||||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = false;
|
GD.Print("Now talking to: " + actor);
|
||||||
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "villager")
|
if (GetParent().Name == "player") GetParent<player>().allowMovement = false;
|
||||||
WelcomeDialog();
|
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "villager")
|
||||||
Visible = true;
|
WelcomeDialog();
|
||||||
}
|
Visible = true;
|
||||||
public void WelcomeDialog()
|
}
|
||||||
{
|
public void WelcomeDialog()
|
||||||
string[] welcomeText = parsedDlg.AsGodotDictionary()["welcome"].AsStringArray();
|
{
|
||||||
Godot.Collections.Dictionary playerbeginoptions = parsedDlg.AsGodotDictionary()["playerbeginoptions"].AsGodotDictionary();
|
string[] welcomeText = parsedDlg.AsGodotDictionary()["welcome"].AsStringArray();
|
||||||
GD.Randomize();
|
Godot.Collections.Dictionary playerbeginoptions = parsedDlg.AsGodotDictionary()["playerbeginoptions"].AsGodotDictionary();
|
||||||
dlgLines.Add(welcomeText[GD.Randi() % welcomeText.Length]);
|
GD.Randomize();
|
||||||
MakeAnswerBox(new string[] { playerbeginoptions["talk"].AsStringArray()[GD.Randi() % playerbeginoptions["talk"].AsStringArray().Length], playerbeginoptions["goaway"].AsStringArray()[GD.Randi() % playerbeginoptions["goaway"].AsStringArray().Length] });
|
dlgLines.Add(welcomeText[GD.Randi() % welcomeText.Length]);
|
||||||
}
|
MakeAnswerBox(new string[] { playerbeginoptions["talk"].AsStringArray()[GD.Randi() % playerbeginoptions["talk"].AsStringArray().Length], playerbeginoptions["goaway"].AsStringArray()[GD.Randi() % playerbeginoptions["goaway"].AsStringArray().Length] });
|
||||||
public void CloseDialog()
|
}
|
||||||
{
|
public void CloseDialog()
|
||||||
Visible = false;
|
{
|
||||||
dlgPointer = 0;
|
Visible = false;
|
||||||
dlgLines.Clear();
|
dlgPointer = 0;
|
||||||
richText.VisibleCharacters = -1;
|
dlgLines.Clear();
|
||||||
GetNode<Label>("box/name_label").Text = "???";
|
richText.VisibleCharacters = -1;
|
||||||
richText.Text = "";
|
GetNode<Label>("box/name_label").Text = "???";
|
||||||
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
richText.Text = "";
|
||||||
}
|
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
|
||||||
public override void _Process(double delta)
|
}
|
||||||
{
|
public override void _Process(double delta)
|
||||||
if (richText.VisibleCharacters < Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length && GetNode<Timer>("typewriter_timer").IsStopped())
|
{
|
||||||
{
|
if (richText.VisibleCharacters < Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length && GetNode<Timer>("typewriter_timer").IsStopped())
|
||||||
richText.VisibleCharacters++;
|
{
|
||||||
GetNode<Timer>("typewriter_timer").Start();
|
richText.VisibleCharacters++;
|
||||||
}
|
GetNode<Timer>("typewriter_timer").Start();
|
||||||
if (Input.IsActionJustPressed("ui_cancel") && Visible) richText.VisibleCharacters = richText.Text.Length;
|
}
|
||||||
if (Input.IsActionJustPressed("ui_accept") && GetNode<PanelContainer>("box/panel_container").Visible == false && Visible && richText.VisibleCharacters == -1 | Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length <= richText.VisibleCharacters)
|
if (Input.IsActionJustPressed("ui_cancel") && Visible) richText.VisibleCharacters = richText.Text.Length;
|
||||||
{
|
if (Input.IsActionJustPressed("ui_accept") && GetNode<PanelContainer>("box/panel_container").Visible == false && Visible && richText.VisibleCharacters == -1 | Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length <= richText.VisibleCharacters)
|
||||||
if (dlgPointer < dlgLines.Count && dlgLines[dlgPointer] is string)
|
{
|
||||||
{
|
if (dlgPointer < dlgLines.Count && dlgLines[dlgPointer] is string)
|
||||||
richText.Text = dlgLines[dlgPointer].ToString();
|
{
|
||||||
richText.VisibleCharacters = 0;
|
richText.Text = dlgLines[dlgPointer].ToString();
|
||||||
GetNode<Timer>("typewriter_timer").Start();
|
richText.VisibleCharacters = 0;
|
||||||
}
|
GetNode<Timer>("typewriter_timer").Start();
|
||||||
dlgPointer++;
|
}
|
||||||
}
|
dlgPointer++;
|
||||||
if (dlgPointer > dlgLines.Count)
|
}
|
||||||
CloseDialog();
|
if (dlgPointer > dlgLines.Count)
|
||||||
|
CloseDialog();
|
||||||
|
|
||||||
//AnswerBox wait for typewrite effect to finish (garbage code)
|
//AnswerBox wait for typewrite effect to finish (garbage code)
|
||||||
GetNode<PanelContainer>("box/panel_container").Visible = richText.VisibleCharacters == -1 | Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length <= richText.VisibleCharacters && GetNode("box/panel_container/margin_container/v_box_container").GetChildCount() == dialogOptionsLength;
|
GetNode<PanelContainer>("box/panel_container").Visible = richText.VisibleCharacters == -1 | Regex.Replace(richText.Text, @"\[[^]]+\]", "").Length <= richText.VisibleCharacters && GetNode("box/panel_container/margin_container/v_box_container").GetChildCount() == dialogOptionsLength;
|
||||||
}
|
}
|
||||||
public void MakeAnswerBox(string[] dialogOptions)
|
public void MakeAnswerBox(string[] dialogOptions)
|
||||||
{
|
{
|
||||||
var parent = GetNode("box/panel_container/margin_container/v_box_container");
|
var parent = GetNode("box/panel_container/margin_container/v_box_container");
|
||||||
GD.Print(dialogOptions);
|
GD.Print(dialogOptions);
|
||||||
for (int i = 0; parent.GetChildCount() < dialogOptions.Length; i++)
|
for (int i = 0; parent.GetChildCount() < dialogOptions.Length; i++)
|
||||||
{
|
{
|
||||||
GD.Print(parent.GetChildren());
|
GD.Print(parent.GetChildren());
|
||||||
parent.AddChild(GD.Load<PackedScene>("res://scenes/gui/dlg_answer_button.tscn").Instantiate());
|
parent.AddChild(GD.Load<PackedScene>("res://scenes/gui/dlg_answer_button.tscn").Instantiate());
|
||||||
}
|
}
|
||||||
for (int i = 0; i < dialogOptions.Length; i++)
|
for (int i = 0; i < dialogOptions.Length; i++)
|
||||||
parent.GetChild<Button>(i).Text = dialogOptions[i];
|
parent.GetChild<Button>(i).Text = dialogOptions[i];
|
||||||
dialogOptionsLength = dialogOptions.Length;
|
dialogOptionsLength = dialogOptions.Length;
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -5,61 +5,61 @@ using System.Text.RegularExpressions;
|
|||||||
public partial class player : CharacterBody2D
|
public partial class player : CharacterBody2D
|
||||||
{
|
{
|
||||||
|
|
||||||
[Export] public string playerName;
|
[Export] public string playerName;
|
||||||
[Export] public int speed = 200;
|
[Export] public int speed = 200;
|
||||||
public bool allowMovement = true;
|
public bool allowMovement = true;
|
||||||
public Vector2 movement;
|
public Vector2 movement;
|
||||||
public AnimatedSprite2D animatedSprite;
|
public AnimatedSprite2D animatedSprite;
|
||||||
public Marker2D rotCenter;
|
public Marker2D rotCenter;
|
||||||
public RayCast2D dialogRayCast;
|
public RayCast2D dialogRayCast;
|
||||||
|
|
||||||
public override void _Ready()
|
public override void _Ready()
|
||||||
{
|
{
|
||||||
playerName = Regex.Replace(playerName, @"\[[^]]+\]", "");
|
playerName = Regex.Replace(playerName, @"\[[^]]+\]", "");
|
||||||
if (playerName.Length > 12)
|
if (playerName.Length > 12)
|
||||||
playerName = playerName.Substring(0, 12);
|
playerName = playerName.Substring(0, 12);
|
||||||
|
|
||||||
animatedSprite = GetNode<AnimatedSprite2D>("animated_sprite_2d");
|
animatedSprite = GetNode<AnimatedSprite2D>("animated_sprite_2d");
|
||||||
rotCenter = GetNode<Marker2D>("rotation_center");
|
rotCenter = GetNode<Marker2D>("rotation_center");
|
||||||
dialogRayCast = GetNode<RayCast2D>("rotation_center/ray_cast_2d");
|
dialogRayCast = GetNode<RayCast2D>("rotation_center/ray_cast_2d");
|
||||||
}
|
}
|
||||||
public override void _PhysicsProcess(double delta)
|
public override void _PhysicsProcess(double delta)
|
||||||
{
|
{
|
||||||
if (allowMovement) movement = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
if (allowMovement) movement = Input.GetVector("move_left", "move_right", "move_up", "move_down");
|
||||||
else movement = Vector2.Zero;
|
else movement = Vector2.Zero;
|
||||||
if (movement.Length() != 0) rotCenter.Rotation = new Vector2((float)Math.Round(movement.X, 0), (float)Math.Round(movement.Y, 0)).Angle();
|
if (movement.Length() != 0) rotCenter.Rotation = new Vector2((float)Math.Round(movement.X, 0), (float)Math.Round(movement.Y, 0)).Angle();
|
||||||
MoveAndCollide(movement * speed * (float)delta);
|
MoveAndCollide(movement * speed * (float)delta);
|
||||||
}
|
}
|
||||||
public override void _Process(double delta)
|
public override void _Process(double delta)
|
||||||
{
|
{
|
||||||
if (Input.IsActionJustPressed("ui_accept") && dialogRayCast.IsColliding() && allowMovement)
|
if (Input.IsActionJustPressed("ui_accept") && dialogRayCast.IsColliding() && allowMovement)
|
||||||
GetNode<dialog_bubble>("dialog_bubble").GetDialog(dialogRayCast.GetCollider().Get("file").AsString(), dialogRayCast.GetCollider().Get("title").AsString(), dialogRayCast.GetCollider().Get("actor"), playerName);
|
GetNode<dialog_bubble>("dialog_bubble").GetDialog(dialogRayCast.GetCollider().Get("file").AsString(), dialogRayCast.GetCollider().Get("title").AsString(), dialogRayCast.GetCollider().Get("actor"), playerName);
|
||||||
|
|
||||||
//animation system (with controller support wich cant get normalized vector)
|
//animation system (with controller support wich cant get normalized vector)
|
||||||
if (allowMovement == false)
|
if (allowMovement == false)
|
||||||
{
|
{
|
||||||
animatedSprite.Stop();
|
animatedSprite.Stop();
|
||||||
animatedSprite.Frame = 0;
|
animatedSprite.Frame = 0;
|
||||||
}
|
}
|
||||||
if (movement.Length() != 0)
|
if (movement.Length() != 0)
|
||||||
animatedSprite.Play();
|
animatedSprite.Play();
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
animatedSprite.Frame = 0;
|
animatedSprite.Frame = 0;
|
||||||
animatedSprite.Stop();
|
animatedSprite.Stop();
|
||||||
}
|
}
|
||||||
if (Math.Round(movement.X, 0) != 0)
|
if (Math.Round(movement.X, 0) != 0)
|
||||||
{
|
{
|
||||||
animatedSprite.Animation = "move_side";
|
animatedSprite.Animation = "move_side";
|
||||||
animatedSprite.FlipH = movement.X < 0.5;
|
animatedSprite.FlipH = movement.X < 0.5;
|
||||||
animatedSprite.SpeedScale = Math.Abs(movement.X * speed / 150);
|
animatedSprite.SpeedScale = Math.Abs(movement.X * speed / 150);
|
||||||
}
|
}
|
||||||
else if (Math.Round(movement.Y, 0) != 0)
|
else if (Math.Round(movement.Y, 0) != 0)
|
||||||
{
|
{
|
||||||
if (movement.Y > 0.05) animatedSprite.Animation = "move_down";
|
if (movement.Y > 0.05) animatedSprite.Animation = "move_down";
|
||||||
if (movement.Y < 0.05) animatedSprite.Animation = "move_up";
|
if (movement.Y < 0.05) animatedSprite.Animation = "move_up";
|
||||||
animatedSprite.FlipH = false;
|
animatedSprite.FlipH = false;
|
||||||
animatedSprite.SpeedScale = Math.Abs(movement.Y * speed / 150);
|
animatedSprite.SpeedScale = Math.Abs(movement.Y * speed / 150);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user