welcome dialogue begin

This commit is contained in:
2023-02-04 21:01:07 +01:00
parent 9fa1d5987f
commit 1a142bcc9d
3 changed files with 28 additions and 16 deletions

View File

@@ -1,9 +1,8 @@
[gd_scene load_steps=6 format=3 uid="uid://bkm7365u1mm3o"]
[gd_scene load_steps=5 format=3 uid="uid://bkm7365u1mm3o"]
[ext_resource type="Script" path="res://src/scene-scripts/dialogue-system/dialog_bubble.cs" id="1_xtj1q"]
[ext_resource type="FontFile" uid="uid://cx6bvqk0ghmjv" path="res://assets/fonts/urbane-rounded-medium.otf" id="2_qrihj"]
[ext_resource type="Texture2D" uid="uid://04pdpdvkg2s" path="res://assets/textures/dialogue/dialogue_answer_ninepatch.png" id="3_n3y1v"]
[ext_resource type="PackedScene" uid="uid://cv87js42t1sty" path="res://scenes/gui/dlg_answer_button.tscn" id="4_r5f4t"]
[sub_resource type="StyleBoxEmpty" id="StyleBoxEmpty_5w2xu"]
@@ -101,11 +100,3 @@ theme_override_constants/margin_bottom = 30
[node name="v_box_container" type="VBoxContainer" parent="box/panel_container/margin_container"]
layout_mode = 2
[node name="answer_button" parent="box/panel_container/margin_container/v_box_container" instance=ExtResource("4_r5f4t")]
layout_mode = 2
text = "needs focus on mouse hover"
[node name="answer_button_2" parent="box/panel_container/margin_container/v_box_container" instance=ExtResource("4_r5f4t")]
layout_mode = 2
text = "jkbhjvvjvhgvhjv"

View File

@@ -29,5 +29,6 @@ theme_override_styles/hover = SubResource("StyleBoxEmpty_h66dw")
theme_override_styles/pressed = SubResource("StyleBoxEmpty_2axga")
theme_override_styles/disabled = SubResource("StyleBoxEmpty_s6xfc")
theme_override_styles/focus = SubResource("StyleBoxEmpty_trdc6")
text = "this is placeholder text"
icon = ExtResource("2_tkpfr")
alignment = 0

View File

@@ -9,12 +9,11 @@ public partial class dialog_bubble : CanvasLayer
public ArrayList dlgLines = new ArrayList();
public int dlgPointer = 0;
public RichTextLabel richText;
public int dialogOptionsLength;
public override void _Ready()
{
richText = GetNode<RichTextLabel>("box/rich_text_label");
dlgLines.Add("Hello! I'm a [color=purple]debug character[/color] and...");
dlgLines.Add("[center][b][wave amp=50 freq=15][rainbow]This is cool test text[/rainbow][/wave][/b][/center]"); //bbcode gets counted to so typewrite effect takes decades //make a seperate variable without bbcode and count that instead
}
public void GetDialog(string file, string title, Variant actor, string playerName)
{
@@ -22,16 +21,25 @@ public partial class dialog_bubble : CanvasLayer
GetNode<Label>("box/name_label").Text = title;
GD.Print("Now talking to: " + actor);
if (GetParent().Name == "player") GetParent<player>().allowMovement = false;
if (parsedDlg.AsGodotDictionary()["dialogType"].AsString() == "villager")
WelcomeDialog();
Visible = true;
}
public void WelcomeDialog()
{
string[] welcomeText = parsedDlg.AsGodotDictionary()["welcome"].AsStringArray();
dlgLines.Add(welcomeText[GD.Randi() % welcomeText.Length]);
MakeAnswerBox(new string[] { "talk", "go away" });
}
public void CloseDialog()
{
if (GetParent().Name == "player") GetParent<player>().allowMovement = true;
Visible = false;
dlgPointer = 0;
dlgLines.Clear();
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)
{
@@ -52,7 +60,19 @@ public partial class dialog_bubble : CanvasLayer
}
if (dlgPointer > dlgLines.Count)
CloseDialog();
//AnswerBox wait for typewrite effect to finish
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;
}
//get dialogue inside dialogLines and add them to
//richtextlabel and detect dictionarys in them and display them as prompts
}
public void MakeAnswerBox(string[] dialogOptions)
{
var button = GD.Load<PackedScene>("res://scenes/gui/dlg_answer_button.tscn");
var parent = GetNode("box/panel_container/margin_container/v_box_container");
for (int i = 0; parent.GetChildCount() < dialogOptions.Length; i++)
{
parent.AddChild(button.Instantiate());
parent.GetChild<Button>(i).Text = dialogOptions[i];
}
dialogOptionsLength = dialogOptions.Length;
}
}