From 08ae1a42c694ec409921225daa59ab42fac75d58 Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sun, 9 Aug 2020 16:29:26 +0300 Subject: Allow options in dialogue --- scripts/DialogueBox.gd | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 scripts/DialogueBox.gd (limited to 'scripts/DialogueBox.gd') diff --git a/scripts/DialogueBox.gd b/scripts/DialogueBox.gd new file mode 100644 index 0000000..eb88ada --- /dev/null +++ b/scripts/DialogueBox.gd @@ -0,0 +1,30 @@ +extends ColorRect +class_name DialogueBox + +signal option_pressed(text, target) + +var btn_res = preload("res://scenes/DialogueOptionButton.tscn") + +func set_dialogue(name: String, body: String, options: Array): + $Name.set_text(name) + $Body.set_text(body) + + for child in $HBoxContainer.get_children(): + $HBoxContainer.remove_child(child) + + for option in options: + var opt_txt = option[0] + var opt_target = option[1] + + var btn: Button = btn_res.instance() + btn.set_text(opt_txt) + var err = btn.connect("pressed", self, "_on_DialogueOptionButton_pressed", [opt_txt, opt_target]) + if err: + return push_error(err) + $HBoxContainer.add_child(btn) + +func free_buttons(): + $HBoxContainer.call_deferred("queue_free") + +func _on_DialogueOptionButton_pressed(text: String, target): + emit_signal("option_pressed", text, target) -- cgit v1.3