summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/DialogueBox.gd30
-rw-r--r--scripts/DwarfNPC.gd2
-rw-r--r--scripts/GUI.gd10
-rw-r--r--scripts/Game.gd18
4 files changed, 47 insertions, 13 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)
diff --git a/scripts/DwarfNPC.gd b/scripts/DwarfNPC.gd
index b6b8848..52565ba 100644
--- a/scripts/DwarfNPC.gd
+++ b/scripts/DwarfNPC.gd
@@ -4,7 +4,7 @@ class_name DwarfNPC
export (NodePath) var target
export (String, FILE, "*.json") var dialogue_file
onready var target_node = get_node(target)
-var dialogue_data = []
+var dialogue_data = {}
func load_text_file(path):
var f = File.new()
diff --git a/scripts/GUI.gd b/scripts/GUI.gd
index f885b10..0c8bf56 100644
--- a/scripts/GUI.gd
+++ b/scripts/GUI.gd
@@ -3,7 +3,7 @@ class_name GUI
export (bool) var show_debug = true
onready var debug_label = $TopRow/DebugLabel
-signal dialogue_next()
+signal dialogue_next(target)
# Called when the node enters the scene tree for the first time.
func _ready():
@@ -17,11 +17,11 @@ func _unhandled_input(event: InputEvent):
if event is InputEventKey:
if event.pressed and event.scancode == KEY_ESCAPE:
get_tree().quit()
- if event.pressed and event.is_action_pressed("ui_accept"):
- emit_signal("dialogue_next")
+# if event.pressed and event.is_action_pressed("ui_accept"):
+# emit_signal("dialogue_next")
func set_debug_text(text: String):
debug_label.set_text(text)
-func _on_NextButton_pressed():
- emit_signal("dialogue_next")
+func _on_DialogueBox_option_pressed(_text, target):
+ emit_signal("dialogue_next", target)
diff --git a/scripts/Game.gd b/scripts/Game.gd
index 25edde0..d5f3bb5 100644
--- a/scripts/Game.gd
+++ b/scripts/Game.gd
@@ -52,20 +52,24 @@ func change_level(num: int):
func _on_PlayerCharacter_initiate_dialogue(other: Node):
in_dialogue_with = other
- var dialogues = other.get_dialogue()
+ var dialogues: Dictionary = other.get_dialogue()
$CanvasLayer/GUI/BottomRow/DialogueBox.set_visible(true)
emit_signal("dialogue_begin")
- for i in range(dialogues.size()):
- var d = dialogues[i]
+ var id = "1"
+ while id != null:
+ var d: Dictionary = dialogues[String(id)]
var name = d["name"]
var body = d["body"]
- $CanvasLayer/GUI/BottomRow/DialogueBox/Name.set_text(name)
- $CanvasLayer/GUI/BottomRow/DialogueBox/Text.set_text(body)
- print("[%s] %s" % [name, body])
- yield($CanvasLayer/GUI, "dialogue_next")
+ var options = d.get("options", [[">>", null]])
+ $CanvasLayer/GUI/BottomRow/DialogueBox.set_dialogue(name, body, options)
+ print("[%s] \"%s\"" % [name, body])
+ var next_target = yield($CanvasLayer/GUI, "dialogue_next")
+ id = next_target
emit_signal("dialogue_next")
in_dialogue_with = null
$CanvasLayer/GUI/BottomRow/DialogueBox.set_visible(false)
+ $CanvasLayer/GUI/BottomRow/DialogueBox.free_buttons()
emit_signal("dialogue_end")
+