fixed and improved code, added disabled answers
This commit is contained in:
@@ -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,8 +48,7 @@ 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)];
|
||||
dlgLines = dlgLines.AsGodotArray()[GD.RandRange(0, dlgLines.AsGodotArray().Count - 1)];
|
||||
}
|
||||
|
||||
public void CloseDialog()
|
||||
@@ -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"
|
||||
|
Reference in New Issue
Block a user