diff options
| author | Jan Tuomi <jan.tuomi@valuemotive.com> | 2020-08-09 16:29:26 +0300 |
|---|---|---|
| committer | Jan Tuomi <jan.tuomi@valuemotive.com> | 2020-08-09 16:29:26 +0300 |
| commit | 08ae1a42c694ec409921225daa59ab42fac75d58 (patch) | |
| tree | 8130cc772a35cb081333d73c9015638e586aca41 /scripts/DialogueBox.gd | |
| parent | 1119130621fe5bbc048fb8404263acc65490d0cd (diff) | |
Allow options in dialoguemaster
Diffstat (limited to 'scripts/DialogueBox.gd')
| -rw-r--r-- | scripts/DialogueBox.gd | 30 |
1 files changed, 30 insertions, 0 deletions
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) |
