summaryrefslogtreecommitdiffstats
path: root/dialogue.gd
diff options
context:
space:
mode:
authorJan Tuomi <jan@jantuomi.fi>2025-12-04 23:40:19 +0200
committerJan Tuomi <jan@jantuomi.fi>2025-12-04 23:40:19 +0200
commit9e9f6984a500ec6eab02fa651eaaf3472c281c2a (patch)
treefcf4e698f185897a1b60236d9fcaeab0e88ac246 /dialogue.gd
parent872d1f9200584973b2156102f0e7f03b3d271687 (diff)
Improve dialogue
Diffstat (limited to 'dialogue.gd')
-rw-r--r--dialogue.gd27
1 files changed, 25 insertions, 2 deletions
diff --git a/dialogue.gd b/dialogue.gd
index f085ed8..311d5e2 100644
--- a/dialogue.gd
+++ b/dialogue.gd
@@ -1,11 +1,14 @@
class_name Dialogue
extends Node
-signal next
+signal next(arg: Variant)
@onready var parent: Node2D = get_parent()
@onready var cam: GameCamera = parent.get_node("GameCamera")
+enum Type { SAY, ASK }
+var type: Type
+
func say(who: Object, text: String):
var tb: TextBubble = preload("res://text_bubble.tscn").instantiate()
tb.text = text
@@ -16,9 +19,29 @@ func say(who: Object, text: String):
tb.add_to_group("text_bubbles")
parent.add_child(tb)
+ type = Type.SAY
await next
+func ask(who: Object, text: String, options: Array[String]) -> String:
+ var tb: TextBubble = preload("res://text_bubble.tscn").instantiate()
+ tb.text = text
+ tb.options = options
+ tb.connect("answered", _on_answered)
+ if who is Node2D:
+ tb.global_position = who.global_position + Vector2(0, -20)
+ else:
+ tb.global_position = cam.global_position
+
+ tb.add_to_group("text_bubbles")
+ parent.add_child(tb)
+ type = Type.ASK
+ return await next
+
func _process(_delta: float):
- if Input.is_action_just_pressed("action") or Input.is_action_just_pressed("jump"):
+ if type == Type.SAY and (Input.is_action_just_pressed("action") or Input.is_action_just_pressed("jump")):
get_tree().call_group("text_bubbles", "queue_free")
next.emit()
+
+func _on_answered(answer: String):
+ get_tree().call_group("text_bubbles", "queue_free")
+ next.emit(answer)