summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJan Tuomi <jan.tuomi@valuemotive.com>2020-08-08 21:35:15 +0300
committerJan Tuomi <jan.tuomi@valuemotive.com>2020-08-08 21:35:15 +0300
commitbc72e9a407db4fcc830450c112de90f5d1c251a9 (patch)
tree6e9787e3e144243146687e8c39c8e6644946fbe3
parentc438ce2976c4dda931918c019a25e00104d0cbc2 (diff)
Improve dialogue system
-rw-r--r--scenes/GUI.tscn2
-rw-r--r--scenes/Game.tscn1
-rw-r--r--scenes/Level1.tscn27
-rw-r--r--scenes/Level2.tscn27
-rw-r--r--scripts/GUI.gd8
-rw-r--r--scripts/Game.gd17
-rw-r--r--scripts/PlayerCharacter.gd34
-rw-r--r--scripts/Scene1.gd21
8 files changed, 91 insertions, 46 deletions
diff --git a/scenes/GUI.tscn b/scenes/GUI.tscn
index 64b3b4e..63cfda8 100644
--- a/scenes/GUI.tscn
+++ b/scenes/GUI.tscn
@@ -74,6 +74,6 @@ anchor_top = 0.2
anchor_bottom = 0.4
margin_right = 40.0
margin_bottom = 14.0
-text = "Next"
+text = ">>"
valign = 1
[connection signal="pressed" from="BottomRow/DialogueBox/NextButton" to="." method="_on_NextButton_pressed"]
diff --git a/scenes/Game.tscn b/scenes/Game.tscn
index fe1432f..35d3bfd 100644
--- a/scenes/Game.tscn
+++ b/scenes/Game.tscn
@@ -12,4 +12,3 @@ script = ExtResource( 3 )
[node name="CanvasLayer" type="CanvasLayer" parent="."]
[node name="GUI" parent="CanvasLayer" instance=ExtResource( 2 )]
-[connection signal="dialogue_next" from="CanvasLayer/GUI" to="." method="_on_GUI_dialogue_next"]
diff --git a/scenes/Level1.tscn b/scenes/Level1.tscn
index 87924f5..36517cf 100644
--- a/scenes/Level1.tscn
+++ b/scenes/Level1.tscn
@@ -3,10 +3,33 @@
[ext_resource path="res://scenes/PlayerCharacter.tscn" type="PackedScene" id=1]
[ext_resource path="res://textures/world_tileset.tres" type="Texture" id=2]
[ext_resource path="res://scenes/DwarfNPC.tscn" type="PackedScene" id=3]
-[ext_resource path="res://scripts/Scene1.gd" type="Script" id=4]
[ext_resource path="res://externals/point_light.png" type="Texture" id=5]
[ext_resource path="res://scenes/Ladder.tscn" type="PackedScene" id=6]
+[sub_resource type="GDScript" id=46]
+script/source = "extends Node2D
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = \"text\"
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ pass # Replace with function body.
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(_delta):
+ pass
+
+func _unhandled_input(event):
+ if event is InputEventKey:
+ if event.pressed and event.scancode == KEY_ESCAPE:
+ get_tree().quit()
+"
+
[sub_resource type="OccluderPolygon2D" id=1]
polygon = PoolVector2Array( 8, 8, 0, 8, 0, 0, 8, 0 )
@@ -296,7 +319,7 @@ points = PoolVector2Array( 4, 4, 4, 0, 8, 0, 8, 8, 0, 8, 0, 4 )
0/z_index = 0
[node name="Scene1" type="Node2D"]
-script = ExtResource( 4 )
+script = SubResource( 46 )
[node name="YSort" type="YSort" parent="."]
diff --git a/scenes/Level2.tscn b/scenes/Level2.tscn
index 6312f9c..b24d11b 100644
--- a/scenes/Level2.tscn
+++ b/scenes/Level2.tscn
@@ -5,7 +5,30 @@
[ext_resource path="res://scenes/Ladder.tscn" type="PackedScene" id=3]
[ext_resource path="res://scenes/PlayerCharacter.tscn" type="PackedScene" id=4]
[ext_resource path="res://externals/point_light.png" type="Texture" id=5]
-[ext_resource path="res://scripts/Scene1.gd" type="Script" id=6]
+
+[sub_resource type="GDScript" id=46]
+script/source = "extends Node2D
+
+
+# Declare member variables here. Examples:
+# var a = 2
+# var b = \"text\"
+
+
+# Called when the node enters the scene tree for the first time.
+func _ready():
+ pass # Replace with function body.
+
+
+# Called every frame. 'delta' is the elapsed time since the previous frame.
+func _process(_delta):
+ pass
+
+func _unhandled_input(event):
+ if event is InputEventKey:
+ if event.pressed and event.scancode == KEY_ESCAPE:
+ get_tree().quit()
+"
[sub_resource type="OccluderPolygon2D" id=1]
polygon = PoolVector2Array( 8, 8, 0, 8, 0, 0, 8, 0 )
@@ -296,7 +319,7 @@ points = PoolVector2Array( 4, 4, 4, 0, 8, 0, 8, 8, 0, 8, 0, 4 )
0/z_index = 0
[node name="Scene2" type="Node2D"]
-script = ExtResource( 6 )
+script = SubResource( 46 )
[node name="YSort" type="YSort" parent="."]
diff --git a/scripts/GUI.gd b/scripts/GUI.gd
index de1106f..f885b10 100644
--- a/scripts/GUI.gd
+++ b/scripts/GUI.gd
@@ -12,10 +12,16 @@ func _ready():
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(_delta):
pass
+
+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")
func set_debug_text(text: String):
debug_label.set_text(text)
-
func _on_NextButton_pressed():
emit_signal("dialogue_next")
diff --git a/scripts/Game.gd b/scripts/Game.gd
index bb74c44..25edde0 100644
--- a/scripts/Game.gd
+++ b/scripts/Game.gd
@@ -1,12 +1,16 @@
extends Node
class_name Game
+signal dialogue_begin()
+signal dialogue_next()
+signal dialogue_end()
+
onready var gui: GUI = $CanvasLayer/GUI
var in_dialogue_with: Node = null
# Called when the node enters the scene tree for the first time.
-func _ready():
+func _ready():
update_debug_gui()
connect_signals()
@@ -50,6 +54,7 @@ func _on_PlayerCharacter_initiate_dialogue(other: Node):
in_dialogue_with = other
var dialogues = other.get_dialogue()
$CanvasLayer/GUI/BottomRow/DialogueBox.set_visible(true)
+ emit_signal("dialogue_begin")
for i in range(dialogues.size()):
var d = dialogues[i]
@@ -58,13 +63,9 @@ func _on_PlayerCharacter_initiate_dialogue(other: Node):
$CanvasLayer/GUI/BottomRow/DialogueBox/Name.set_text(name)
$CanvasLayer/GUI/BottomRow/DialogueBox/Text.set_text(body)
print("[%s] %s" % [name, body])
- if dialogues.size() - i > 1:
- yield($CanvasLayer/GUI, "dialogue_next")
+ yield($CanvasLayer/GUI, "dialogue_next")
+ emit_signal("dialogue_next")
- yield($Level/YSort/PlayerCharacter, "end_dialogue")
in_dialogue_with = null
$CanvasLayer/GUI/BottomRow/DialogueBox.set_visible(false)
-
-
-func _on_GUI_dialogue_next():
- pass # Replace with function body.
+ emit_signal("dialogue_end")
diff --git a/scripts/PlayerCharacter.gd b/scripts/PlayerCharacter.gd
index a4c902d..15b3421 100644
--- a/scripts/PlayerCharacter.gd
+++ b/scripts/PlayerCharacter.gd
@@ -3,14 +3,26 @@ class_name PlayerCharacter
export (int) var speed = 8
export (float) var walk_wobble_coeff = 5
-export (NodePath) var gui_node
+onready var gui: GUI = get_tree().get_root().get_node("Game/CanvasLayer/GUI")
+onready var game: Game = get_tree().get_root().get_node("Game")
signal initiate_dialogue(other)
-signal end_dialogue()
var velocity = Vector2()
var look_dir = 1 # right = 1, left = -1
var in_dialogue: bool = false
+enum DialogueState {
+ ACTIVE, # when dialogue in progress with a target
+ ENDED, # when dialogue exhausted via GUI
+ WALKED_OFF # when character moves out from dialogue target
+}
+var dialogue_state = DialogueState.WALKED_OFF
+
+func _ready():
+ yield(get_tree(), "idle_frame")
+ var err = game.connect("dialogue_end", self, "_on_Game_dialogue_end")
+ if err:
+ push_error(err)
func update_input_and_movement():
velocity = Vector2()
@@ -45,19 +57,21 @@ func _process(_delta):
$Sprite.set_scale(Vector2(look_dir, 1))
func _physics_process(_delta):
- update_input_and_movement()
- var slide_count = get_slide_count()
+ if dialogue_state != DialogueState.ACTIVE:
+ update_input_and_movement()
- # If there are no collisions, player must have exited dialogue
- if slide_count == 0 and in_dialogue:
- in_dialogue = false
- emit_signal("end_dialogue")
+ var slide_count = get_slide_count()
+ if slide_count == 0 and dialogue_state == DialogueState.ENDED:
+ dialogue_state = DialogueState.WALKED_OFF
# If the player is colliding with a Dialogue group node and does not have an
# active dialogue, run dialogue with the node
for idx in slide_count:
var coll = get_slide_collision(idx)
- if coll.collider.is_in_group("Dialogue") and not in_dialogue:
- in_dialogue = true
+ if coll.collider.is_in_group("Dialogue") and dialogue_state == DialogueState.WALKED_OFF:
+ dialogue_state = DialogueState.ACTIVE
emit_signal("initiate_dialogue", coll.collider)
break
+
+func _on_Game_dialogue_end():
+ dialogue_state = DialogueState.ENDED
diff --git a/scripts/Scene1.gd b/scripts/Scene1.gd
deleted file mode 100644
index ce8376c..0000000
--- a/scripts/Scene1.gd
+++ /dev/null
@@ -1,21 +0,0 @@
-extends Node2D
-
-
-# Declare member variables here. Examples:
-# var a = 2
-# var b = "text"
-
-
-# Called when the node enters the scene tree for the first time.
-func _ready():
- pass # Replace with function body.
-
-
-# Called every frame. 'delta' is the elapsed time since the previous frame.
-func _process(_delta):
- pass
-
-func _unhandled_input(event):
- if event is InputEventKey:
- if event.pressed and event.scancode == KEY_ESCAPE:
- get_tree().quit()