summaryrefslogtreecommitdiffstats
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
parent872d1f9200584973b2156102f0e7f03b3d271687 (diff)
Improve dialogue
-rw-r--r--dialogue.gd27
-rw-r--r--dialogues/test1.gd6
-rw-r--r--docs/index.html2
-rw-r--r--docs/index.pckbin4604796 -> 4606972 bytes
-rw-r--r--docs/index.service.worker.js2
-rw-r--r--text_bubble.gd21
-rw-r--r--text_bubble.tscn46
7 files changed, 79 insertions, 25 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)
diff --git a/dialogues/test1.gd b/dialogues/test1.gd
index e7752b3..d411484 100644
--- a/dialogues/test1.gd
+++ b/dialogues/test1.gd
@@ -5,10 +5,12 @@ extends Dialogue
@onready var npc: Node2D = parent.get_node("DialogueTestNPC")
func _ready():
- player.request_state_init()
+ player.request_state_forced("DROP")
await say(player, "hello")
await say(npc, "well hi")
+ var answer = await ask(npc, "buy or sell?", ["buy", "sell"])
+ await say(npc, "it's %s time" % answer)
player.request_state_normal()
- print("dialogue done")
+ print("dialogue done, answer %s" % answer)
diff --git a/docs/index.html b/docs/index.html
index d691280..f437c23 100644
--- a/docs/index.html
+++ b/docs/index.html
@@ -112,7 +112,7 @@ body {
<script src="index.js"></script>
<script>
-const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"emscriptenPoolSize":8,"ensureCrossOriginIsolationHeaders":true,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":4604796,"index.wasm":38034280},"focusCanvas":true,"gdextensionLibs":[],"godotPoolSize":4,"serviceWorker":"index.service.worker.js"};
+const GODOT_CONFIG = {"args":[],"canvasResizePolicy":2,"emscriptenPoolSize":8,"ensureCrossOriginIsolationHeaders":true,"executable":"index","experimentalVK":false,"fileSizes":{"index.pck":4606972,"index.wasm":38034280},"focusCanvas":true,"gdextensionLibs":[],"godotPoolSize":4,"serviceWorker":"index.service.worker.js"};
const GODOT_THREADS_ENABLED = false;
const engine = new Engine(GODOT_CONFIG);
diff --git a/docs/index.pck b/docs/index.pck
index f2465a4..dbde122 100644
--- a/docs/index.pck
+++ b/docs/index.pck
Binary files differ
diff --git a/docs/index.service.worker.js b/docs/index.service.worker.js
index 5cd4eb6..fb84ef1 100644
--- a/docs/index.service.worker.js
+++ b/docs/index.service.worker.js
@@ -4,7 +4,7 @@
// Incrementing CACHE_VERSION will kick off the install event and force
// previously cached resources to be updated from the network.
/** @type {string} */
-const CACHE_VERSION = '1764878547|12827344433';
+const CACHE_VERSION = '1764884307|18241003549';
/** @type {string} */
const CACHE_PREFIX = 'MobileMetroidvan-sw-cache-';
const CACHE_NAME = CACHE_PREFIX + CACHE_VERSION;
diff --git a/text_bubble.gd b/text_bubble.gd
index 545f469..0e8c4ce 100644
--- a/text_bubble.gd
+++ b/text_bubble.gd
@@ -2,9 +2,22 @@ class_name TextBubble
extends Node2D
@export var text: String
+@export var options: Array[String]
-func _ready() -> void:
- $Label.text = text
+signal answered(text: String)
-func size() -> Vector2:
- return $ColorRect.size
+func _ready() -> void:
+ find_child("Label").text = text
+ var hbox: HBoxContainer = find_child("HBoxContainer")
+
+ var first = true
+ for option in options:
+ var btn = Button.new()
+ btn.text = option
+ hbox.add_child(btn)
+
+ btn.connect("pressed", func (): answered.emit(option))
+
+ if first:
+ btn.grab_focus.call_deferred()
+ first = false
diff --git a/text_bubble.tscn b/text_bubble.tscn
index 42ead69..0ac3e32 100644
--- a/text_bubble.tscn
+++ b/text_bubble.tscn
@@ -1,27 +1,43 @@
-[gd_scene load_steps=2 format=3 uid="uid://dglar4tto3f1s"]
+[gd_scene load_steps=3 format=3 uid="uid://dglar4tto3f1s"]
[ext_resource type="Script" uid="uid://dubgnmdd6p1rs" path="res://text_bubble.gd" id="1_bo3s3"]
+[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_j0576"]
+bg_color = Color(0.7372549, 0.69803923, 0.43529412, 1)
+
[node name="TextBubble" type="Node2D"]
+scale = Vector2(0.25, 0.25)
script = ExtResource("1_bo3s3")
-[node name="ColorRect" type="ColorRect" parent="."]
-offset_left = -26.0
-offset_top = -6.0
-offset_right = 14.0
-offset_bottom = 34.0
-scale = Vector2(1.3009955, 0.30328855)
-color = Color(1, 0.8980392, 0.7490196, 1)
-metadata/_edit_use_anchors_ = true
+[node name="PanelContainer" type="PanelContainer" parent="."]
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+theme_override_styles/panel = SubResource("StyleBoxFlat_j0576")
-[node name="Label" type="Label" parent="."]
-offset_left = -25.0
-offset_top = -3.0
-offset_right = 174.0
-offset_bottom = 20.0
-scale = Vector2(0.25, 0.25)
+[node name="MarginContainer" type="MarginContainer" parent="PanelContainer"]
+layout_mode = 2
+theme_override_constants/margin_left = 20
+theme_override_constants/margin_top = 5
+theme_override_constants/margin_right = 20
+theme_override_constants/margin_bottom = 5
+
+[node name="VBoxContainer" type="VBoxContainer" parent="PanelContainer/MarginContainer"]
+clip_contents = true
+layout_mode = 2
+size_flags_vertical = 4
+
+[node name="Label" type="Label" parent="PanelContainer/MarginContainer/VBoxContainer"]
+layout_mode = 2
+size_flags_horizontal = 4
theme_override_colors/font_color = Color(0, 0, 0, 1)
text = "foo"
horizontal_alignment = 1
vertical_alignment = 1
metadata/_edit_use_anchors_ = true
+
+[node name="HBoxContainer" type="HBoxContainer" parent="PanelContainer/MarginContainer/VBoxContainer"]
+layout_mode = 2
+alignment = 1