fixed and improved code, added disabled answers

This commit is contained in:
2023-02-09 10:29:30 +01:00
parent bb96b09847
commit 85e3f05b8b
3 changed files with 39 additions and 38 deletions

View File

@@ -3,29 +3,29 @@
"intro": [
[
"Hello i'm {title}. Your name must be {player}! So...",
1
0
]
],
"welcome": [
[
"Oh hello, {player}... You look great! What can I do for you?",
{
"I just wanna talk": "tipp",
"Nevermind!": "goodbye"
"I just wanna talk": "<goto:>tipp",
"Nevermind!": "<goto:>goodbye"
}
],
[
"Hey, {player}! Hope you have fun today! So what do you want?",
{
"What's up": "tipp",
"Nothing": "goodbye"
"What's up": "<goto:>tipp",
"Nothing": "<goto:>goodbye"
}
],
[
"Hi! What's up {player}?",
{
"Can we talk?": "tipp",
"Have a great day!": "goodbye"
"Can we talk?": "<goto:>tipp",
"Have a great day!": "<goto:>goodbye"
}
]
],
@@ -33,39 +33,39 @@
[
"Do you need something else?",
{
"Can you tell me something else?": "tipp",
"No, thanks!": "goodbye"
"Can you tell me something else?": "<goto:>tipp",
"No, thanks!": "<goto:>goodbye"
}
],
[
"So can i help you with something else?",
{
"Tell me a bit more maybe": "tipp",
"I'm good, thank you!": "goodbye"
"Tell me a bit more maybe": "<goto:>tipp",
"I'm good, thank you!": "<goto:>goodbye"
}
]
],
"goodbye": [
[
"Was nice talking to you goodbye!",
0
"Was nice talking to you goodbye!"
],
[
"Have a great day, {player}!",
0
"Have a great day, {player}!"
]
],
"tipp": [
[
"You can walk arround with WASD on PC.",
"You can also use your joystick and D-Pad, if 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.",
"<goto:>else"
],
[
"[center][font s=80][wave amp=50 freq=15][rainbow]This is cool test text[/rainbow][/wave][/font][/center]",
"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.",
"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.",
"<goto:>else"
]
],
"story": [

View File

@@ -25,7 +25,7 @@ theme_override_colors/icon_pressed_color = Color(1, 1, 1, 1)
theme_override_colors/icon_hover_color = Color(1, 1, 1, 1)
theme_override_colors/icon_hover_pressed_color = Color(1, 1, 1, 1)
theme_override_colors/icon_focus_color = Color(1, 1, 1, 1)
theme_override_colors/icon_disabled_color = Color(0, 0, 0, 0)
theme_override_colors/icon_disabled_color = Color(1, 1, 1, 0)
theme_override_fonts/font = ExtResource("1_2bkol")
theme_override_font_sizes/font_size = 28
theme_override_styles/normal = SubResource("StyleBoxEmpty_mvyo0")

View File

@@ -12,7 +12,6 @@ public partial class dialog_bubble : CanvasLayer
/*TODO:
- Dont repeat the same randomized dialogue after you get asked do you need something "else"
- add controller support for answerboxes
- add tree support (example: "story" key)
- ability to add dialogue begin answers on the fly (special ones are colored)
they will be in a dictionary with event IDs or Dictionary keys it also needs an array wich ones are active*/
@@ -24,12 +23,15 @@ public partial class dialog_bubble : CanvasLayer
{
triggerArea = actor;
name = title;
parsedDlg = Json.ParseString(FileAccess.Open(file, FileAccess.ModeFlags.Read).GetAsText()
.Replace("{player}", "[color=cyan]" + playerName + "[/color]").Replace("{title}", "[color=purple]" + title + "[/color]"));
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() != "villager" || introducedVillager)
GetNode<Label>("box/name_label").Text = title;
if (GetParent().Name == "player") GetParent<player>().allowMovement = false;
//Get first key
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "villager")
if (introducedVillager)
GatherDialog("welcome");
@@ -38,6 +40,7 @@ public partial class dialog_bubble : CanvasLayer
else if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "message")
GatherDialog("message");
Visible = true;
}
@@ -45,7 +48,6 @@ public partial class dialog_bubble : CanvasLayer
{
dlgPointer = 0;
dlgLines = parsedDlg.AsGodotDictionary()[key].AsGodotArray();
if (dlgLines.VariantType == Variant.Type.Array)
dlgLines = dlgLines.AsGodotArray()[GD.RandRange(0, dlgLines.AsGodotArray().Count - 1)];
}
@@ -67,40 +69,41 @@ public partial class dialog_bubble : CanvasLayer
{
if (dlgPointer < dlgLines.AsGodotArray().Count)
{
//read and write the dialogue
if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.Float)
InDialogEvents((int)dlgLines.AsGodotArray()[dlgPointer]);
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.String)
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.String && !dlgLines.AsGodotArray()[dlgPointer].AsString().StartsWith("<goto:>"))
UpdateDialog();
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.String && dlgLines.AsGodotArray()[dlgPointer].AsString().StartsWith("<goto:>"))
{
GatherDialog(dlgLines.AsGodotArray()[dlgPointer].AsString().Replace("<goto:>", ""));
UpdateDialog();
}
else if (dlgLines.AsGodotArray()[dlgPointer].VariantType == Variant.Type.Dictionary)
MakeAnswerBox(Json.ParseString(dlgLines.AsGodotArray()[dlgPointer].AsGodotDictionary().Keys.ToString()).AsStringArray());
}
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 (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "villager")
{
GatherDialog("else");
UpdateDialog();
dlgPointer++;
}
else CloseDialog();
}
if (dlgPointer > dlgLines.AsGodotArray().Count)
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)
if (answer.VariantType == Variant.Type.String && answer.AsString().StartsWith("<goto:>"))
{
GatherDialog(answer.AsString());
GatherDialog(answer.AsString().Replace("<goto:>", ""));
UpdateDialog();
}
dlgPointer++;
@@ -121,7 +124,8 @@ public partial class dialog_bubble : CanvasLayer
for (int i = 0; parent.GetChildCount() < dialogOptions.Length; i++)
{
parent.AddChild(GD.Load<PackedScene>("res://scenes/gui/dlg_answer_button.tscn").Instantiate());
parent.GetChild<Button>(i).Text = dialogOptions[i];
if (dialogOptions[i].StartsWith("<!>")) parent.GetChild<Button>(i).Disabled = true;
parent.GetChild<Button>(i).Text = dialogOptions[i].Replace("<!>", "");
}
GetNode<PanelContainer>("box/panel_container").Visible = true;
parent.GetChild<Button>(0).GrabFocus();
@@ -131,9 +135,6 @@ public partial class dialog_bubble : CanvasLayer
switch (eventID)
{
case 0:
CloseDialog();
break;
case 1:
GetNode<Label>("box/name_label").Text = name;
triggerArea.Set("introducedVillager", true);
GatherDialog("welcome"); //not that logical conversation maybe split "welcome" and "what do you want"