added multiline text support and more code changes

This commit is contained in:
2022-12-17 22:26:18 +01:00
parent 3307edef49
commit 9616c1f0d1
4 changed files with 42 additions and 28 deletions

View File

@@ -1,4 +1,6 @@
{ {
"dialogTitle": "Debug Character",
"dialogType": "villager",
"randomWelcomeText":[ "randomWelcomeText":[
"Oh hello, {0}... You look great! What do you want from me?", "Oh hello, {0}... You look great! What do you want from me?",
"Hey, {0}! Hope you have fun today!", "Hey, {0}! Hope you have fun today!",
@@ -8,14 +10,12 @@
"Was nice talking to you goodbye!", "Was nice talking to you goodbye!",
"Have a great day, {0}!" "Have a great day, {0}!"
], ],
"multiDebugTipp00":[ "multiTipp0":[
"You can walk arround with WASD on PC.", "You can walk arround with WASD on PC.",
"You can also use your joystick and D-Pad, if", "You can also use your joystick and D-Pad, if you have a controller.",
"you have a controller.", "You can interact with cupcakes and use the buggy placeholder clouds as a football."
"You can interact with cupcakes and",
"use the buggy placeholder clouds as a football."
], ],
"multiDebugTipp01":[ "multiTipp1":[
"Lorem ipsum dolor sit amet, consetetur sadipscing elitr,", "Lorem ipsum dolor sit amet, consetetur sadipscing elitr,",
"sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,", "sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,",
"sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.", "sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum.",
@@ -25,5 +25,16 @@
"Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet." "Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet."
] ]
} }
],
"multiDebugTipp2":[
"test1test1test1test1test1test1test1test1test1test1test1test1test1test1test1",
"test2test2test2test2test2test2test2test2test2test2test2test2test2test2test2",
"test3test3test3test3test3test3test3test3test3test3test3test3test3test3test3",
"So do you want to do xy for me?",
{
"Okay I'm doing that":[
"Good nice thank you!"
]
}
] ]
} }

View File

@@ -19,7 +19,6 @@ shape = SubResource("RectangleShape2D_pchpi")
[node name="dialog_trigger_area" parent="." instance=ExtResource("2_blpmd")] [node name="dialog_trigger_area" parent="." instance=ExtResource("2_blpmd")]
dialogFile = "res://dialog/npcs/villager_normal.json" dialogFile = "res://dialog/npcs/villager_normal.json"
dialogTitle = "Talking Cupcake"
[node name="collision_shape_2d" parent="dialog_trigger_area" index="0"] [node name="collision_shape_2d" parent="dialog_trigger_area" index="0"]
shape = SubResource("RectangleShape2D_d78tr") shape = SubResource("RectangleShape2D_d78tr")

View File

@@ -5,10 +5,8 @@ public partial class dialog_trigger_area : Area2D
{ {
[Export(PropertyHint.File, "*json")] [Export(PropertyHint.File, "*json")]
string dialogFile; string dialogFile;
[Export]
string dialogTitle;
public void OnInteraction(string playerName) public void OnInteraction(string playerName)
{ {
GetNode("/root/main/dialog_bubble").Call("ImportString",dialogTitle,dialogFile,playerName); GetNode("/root/main/dialog_bubble").Call("ImportString",dialogFile,playerName);
} }
} }

View File

@@ -6,32 +6,26 @@ using System.Collections.Generic;
public partial class dialog_bubble : CanvasLayer public partial class dialog_bubble : CanvasLayer
{ {
public Dictionary allDialog;
public List<string> currentDialogList = new List<string>(); public List<string> currentDialogList = new List<string>();
public string currentKey;
public string currentDialogLine; public string currentDialogLine;
public int dialogCounter; public int dialogCounter;
public string userName; public string userName;
public void ImportString(string dialogTitle, string dialogFile, string playerName) public void ImportString(string dialogFile, string playerName)
{ {
userName = playerName; userName = playerName;
GetNode<Label>("NameLabel").Text = dialogTitle; GetNode("/root/main/player").Call("ChangeProcess", false);
GD.Print("test"); currentKey = "multiTipp0";//2 is a selection menu needs to be planned before coding
GetNode("/root/main/player").Call("ChangeProcess",false);
string currentKey = "randomWelcomeText";
using var file = FileAccess.Open(dialogFile, FileAccess.ModeFlags.Read); using var file = FileAccess.Open(dialogFile, FileAccess.ModeFlags.Read);
string text = file.GetAsText(); string text = file.GetAsText();
var jsonFile = JSON.ParseString(text); allDialog = (Dictionary)JSON.ParseString(text);
Dictionary allDialog = (Dictionary)jsonFile; GetNode<Label>("NameLabel").Text = allDialog["dialogTitle"].ToString();
addText();
//Todo: add multiline text and actual running dialog. And go through string for other dictionaries wich always will be playeranswers //Todo: add multiline text and actual running dialog. And go through string for other dictionaries wich always will be playeranswers
if (currentKey.StartsWith("random"))
{
string[] dialogRand = allDialog[currentKey].AsStringArray();
currentDialogList.Add(dialogRand[GD.Randi() % dialogRand.Length]);
currentDialogList.Add("Test!");
}
else currentDialogList.Add(allDialog[currentKey].AsString());
} }
public void EndDialog() public void EndDialog()
{ {
@@ -40,6 +34,19 @@ public partial class dialog_bubble : CanvasLayer
Visible = false; Visible = false;
GetNode("/root/main/player").Call("ChangeProcess", true); GetNode("/root/main/player").Call("ChangeProcess", true);
} }
public void addText()
{
if (currentKey.StartsWith("random"))
{
string[] dialogRand = allDialog[currentKey].AsStringArray();
currentDialogList.Add(dialogRand[GD.Randi() % dialogRand.Length]);
}
if (currentKey.StartsWith("multi"))
{
string[] dialogMulti = allDialog[currentKey].AsStringArray();
currentDialogList.AddRange(dialogMulti);
}
}
public override void _Process(double delta) public override void _Process(double delta)
{ {
if (Input.IsActionJustPressed("ui_accept")) if (Input.IsActionJustPressed("ui_accept"))
@@ -52,9 +59,8 @@ public partial class dialog_bubble : CanvasLayer
currentDialogLine = String.Format(currentDialogLine, userName); currentDialogLine = String.Format(currentDialogLine, userName);
GetNode<Label>("TextLabel").Text = currentDialogLine; GetNode<Label>("TextLabel").Text = currentDialogLine;
} }
else GD.Print("No valid dialog available"); if (dialogCounter > currentDialogList.Count)
}
if(dialogCounter > currentDialogList.Count)
EndDialog(); EndDialog();
} }
}
} }