Add cinematic tools to the dialogue system

This commit is contained in:
Alice Gaudon 2020-08-17 11:37:50 +02:00
parent 4143db5931
commit 79e7954b50
6 changed files with 134 additions and 78 deletions

View File

@ -1,6 +1,44 @@
[
{"name": "Ely", "text": "What a shame...", "expression": "none"},
{"name": "Ely", "text": "I don't like being alone.", "expression": "none"},
{"name": "Ely", "text": "I just want to go home!", "expression": "none"},
{"name": "Ely", "text": "Hopefully someone will come by and rescue me...", "expression": "none"}
{"timer": 2, "auto": true},
{"name": "Ely", "text": "What a shame..."},
{"name": "Ely", "text": "I don't like being alone."},
{"name": "Ely", "text": "I just want to go home!"},
{"name": "Ely", "text": "Hopefully someone will come by and rescue me..."},
{"timer": 2, "auto": true},
{"name": "Crab", "expression": "eyes", "wait": true},
{"name": "Ely"},
{"name": "Crab", "expression": "first_step", "wait": true},
{"name": "Ely"},
{"name": "Crab", "expression": "second_step", "wait": true},
{"name": "Ely"},
{"name": "Crab", "expression": "third_step", "wait": true},
{"name": "Ely"},
{"name": "Crab", "text": "Hey you!"},
{"name": "Ely", "text": "... Huh?"},
{"name": "Crab", "text": "You ok buddy?"},
{"name": "Ely", "text": "I must be going crazy."},
{"name": "Crab", "text": "You don't look [i]that[/i] crazy to me."},
{"name": "Ely", "text": "You're a crab."},
{"name": "Crab", "text": "Yes."},
{"name": "Ely", "text": "You speak."},
{"name": "Crab", "text": "Of course I do you muffinhead."},
{"name": "Ely", "text": "Cuuuuute!", "expression": "blush"},
{"name": "Ely", "text": "..."},
{"name": "Ely", "text": "So you're a cute talking crab."},
{"name": "Crab", "text": "", "expression": "blush"},
{"name": "Ely", "text": "Do you have a name? [code](by any chance...)[/code]"},
{"name": "Crab", "text": "The name's Herbert."},
{"name": "Herbert", "text": "I am a [wave amp=20 freq=2]Pachygrapsus Marmoratus[/wave] as you [i]hoomans[/i] like to call us."},
{"name": "Ely", "text": "What brings you here Herbert?"},
{"name": "Ely", "text": "Also, what made you the first crab to talk to me [i]ever[/i]?"},
{"name": "Herbert", "text": "I'll tell you my tale, but then please tell me yours."},
{"name": "Ely", "text": "Sure!"},
{"name": "Crab", "text": "Everything was fine."},
{"name": "Crab", "text": "I was fine, my friends were fine..."},
{"name": "Crab", "text": "Even my brother Gary was starting to overcome his depression."},
{"name": "Crab", "text": "And then..."}
]

View File

@ -1,26 +0,0 @@
[
{"name": "Crab", "text": "Hey you!", "expression": "none"},
{"name": "Ely", "text": "... Huh?", "expression": "none"},
{"name": "Crab", "text": "You ok buddy?", "expression": "none"},
{"name": "Ely", "text": "I must be going crazy.", "expression": "none"},
{"name": "Crab", "text": "You don't look [i]that[/i] crazy to me.", "expression": "none"},
{"name": "Ely", "text": "You're a crab.", "expression": "none"},
{"name": "Crab", "text": "Yes.", "expression": "none"},
{"name": "Ely", "text": "You speak.", "expression": "none"},
{"name": "Crab", "text": "Of course I do you muffinhead.", "expression": "none"},
{"name": "Ely", "text": "Cuuuuute!", "expression": "blush"},
{"name": "Ely", "text": "...", "expression": "none"},
{"name": "Ely", "text": "So you're a cute talking crab.", "expression": "none"},
{"name": "Crab", "text": "", "expression": "blush"},
{"name": "Ely", "text": "Do you have a name? [code](by any chance...)[/code]", "expression": "none"},
{"name": "Crab", "text": "The name's Herbert.", "expression": "none"},
{"name": "Herbert", "text": "I am a [wave amp=20 freq=2]Pachygrapsus Marmoratus[/wave] as you [i]hoomans[/i] like to call us.", "expression": "none"},
{"name": "Ely", "text": "What brings you here Herbert?", "expression": "none"},
{"name": "Ely", "text": "Also, what made you the first crab to talk to me [i]ever[/i]?", "expression": "none"},
{"name": "Herbert", "text": "I'll tell you my tale, but then please tell me yours.", "expression": "none"},
{"name": "Ely", "text": "Sure!", "expression": "none"},
{"name": "Crab", "text": "Everything was fine.", "expression": "none"},
{"name": "Crab", "text": "I was fine, my friends were fine...", "expression": "none"},
{"name": "Crab", "text": "Even my brother Gary was starting to overcome his depression.", "expression": "none"},
{"name": "Crab", "text": "And then...", "expression": "none"}
]

View File

@ -10,13 +10,12 @@
[node name="Campfire (background)" type="AnimatedSprite" parent="."]
frames = ExtResource( 1 )
frame = 21
playing = true
centered = false
[node name="Ely" type="AnimatedSprite" parent="."]
frames = ExtResource( 2 )
frame = 33
frame = 132
playing = true
centered = false
@ -39,6 +38,6 @@ visible = false
[node name="IntroScript" type="Node" parent="."]
script = ExtResource( 4 )
dialogue_box_path = NodePath("../UI/Dialog")
ely_sprite_path = NodePath("../Ely")
herbert_sprite_path = NodePath("../Herbert")
intro_dialogue_1 = "res://dialogues/intro_1.json"
intro_dialogue_2 = "res://dialogues/intro_2.json"
intro_dialogue = "res://dialogues/intro_1.json"

View File

@ -77,8 +77,8 @@ script = ExtResource( 3 )
__meta__ = {
"_edit_use_anchors_": false
}
title_path = NodePath("MarginContainer/VBoxContainer/MarginContainer/MarginContainer/CharacterName")
text_path = NodePath("MarginContainer/VBoxContainer/MarginContainer2/MarginContainer/DialogText")
name_label_path = NodePath("MarginContainer/VBoxContainer/MarginContainer/MarginContainer/CharacterName")
text_label_path = NodePath("MarginContainer/VBoxContainer/MarginContainer2/MarginContainer/DialogText")
[node name="MarginContainer" type="MarginContainer" parent="."]
anchor_right = 1.0

View File

@ -4,58 +4,90 @@ class_name DialogueBox
signal end
signal update
export (NodePath) var title_path
onready var title = get_node(title_path) as RichTextLabel
export (NodePath) var name_label_path
onready var name_label = get_node(name_label_path) as RichTextLabel
export (NodePath) var text_path
onready var text = get_node(text_path) as RichTextLabel
export (NodePath) var text_label_path
onready var text_label = get_node(text_label_path) as RichTextLabel
export (NodePath) var expression_path
onready var expression = get_node(expression_path) as RichTextLabel
export (NodePath) var expression_node_path
onready var expression_node = get_node(expression_node_path) as RichTextLabel
var _dialogue : Array
var _index : int
var dialogue : Array
var index : int
var character_name : String = ""
var text : String = ""
var expression : String = ""
var waiting = false
var auto_advance = false
func _ready():
assert(title != null)
assert(text != null)
assert(name_label != null)
assert(text_label != null)
func start(dialogue : Array):
_dialogue = dialogue
_index = 0
_update()
show()
self.dialogue = dialogue
index = 0
update()
func _input(event):
if event.is_action_pressed("ui_accept"):
if text.visible_characters < text.text.length():
text.visible_characters = text.text.length()
if !waiting and event.is_action_pressed("ui_accept"):
if text_label.visible_characters < text_label.text.length():
text_label.visible_characters = text_label.text.length()
else:
next()
func next() -> void:
_index += 1
if _index >= _dialogue.size():
index += 1
if index >= dialogue.size():
hide()
emit_signal('end')
return
_update()
update()
func _update() -> void:
title.bbcode_text = _dialogue[_index].name
title.rect_min_size.x = title.get_font('normal_font').get_string_size(title.text).x
text.bbcode_text = _dialogue[_index].text
#expression = _dialogue[_index].expression
func update() -> void:
var line = dialogue[index]
# Self properties
character_name = line.get('name', '')
text = line.get('text', '')
expression = line.get('expression', '')
waiting = line.get('wait', false)
var timer = line.get('timer', 0)
auto_advance = line.get('auto', false)
if timer > 0:
waiting = true
# UI
name_label.bbcode_text = character_name
name_label.rect_min_size.x = name_label.get_font('normal_font').get_string_size(name_label.text).x
text_label.bbcode_text = text
if text == "":
hide()
else:
show()
emit_signal('update')
animate_text()
if timer > 0:
yield(get_tree().create_timer(timer), 'timeout')
stop_waiting()
func animate_text():
var animated = _index
text.visible_characters = 0
while animated == _index && text.visible_characters < text.text.length():
if text.text[text.visible_characters] == ' ':
text.visible_characters += 1
text.visible_characters += 1
var animated = index
text_label.visible_characters = 0
while animated == index && text_label.visible_characters < text_label.text.length():
if text_label.text[text_label.visible_characters] == ' ':
text_label.visible_characters += 1
text_label.visible_characters += 1
yield(get_tree().create_timer(0.05), 'timeout')
func stop_waiting():
waiting = false
if auto_advance:
next()

View File

@ -1,16 +1,16 @@
extends Node
class_name IntroScript
signal end_step
export (NodePath) var dialogue_box_path
onready var dialogue_box = get_node(dialogue_box_path)
export (NodePath) var ely_sprite_path
onready var ely_sprite = get_node(ely_sprite_path)
export (NodePath) var herbert_sprite_path
onready var herbert_sprite = get_node(herbert_sprite_path)
export (String, FILE, '*.json') var intro_dialogue_1 : String
export (String, FILE, '*.json') var intro_dialogue_2 : String
export (String, FILE, '*.json') var intro_dialogue : String
func _ready():
assert(dialogue_box != null)
@ -19,18 +19,31 @@ func _ready():
dialogue_box.connect('update', self, 'update_camera')
yield(get_tree().create_timer(2.0), 'timeout')
yield(start_dialogue(intro_dialogue_1), 'end')
yield(get_tree().create_timer(2.0), 'timeout')
do_crab_step()
yield(self, 'end_step')
yield(start_dialogue(intro_dialogue_2), 'end')
yield(start_dialogue(intro_dialogue), 'end')
func update_camera():
var line = dialogue_box._dialogue[dialogue_box._index]
if line.name == 'Crab' || line.name == 'Herbert':
var animation = dialogue_box.expression
if animation == "":
animation = "idle"
var sprite : AnimatedSprite
if dialogue_box.character_name == 'Crab' || dialogue_box.character_name == 'Herbert':
herbert_sprite.show()
sprite = herbert_sprite
else:
herbert_sprite.hide()
sprite = ely_sprite
var is_old_animation_loop = sprite.get_sprite_frames().get_animation_loop(sprite.get_animation())
var is_new_animation_loop = sprite.get_sprite_frames().get_animation_loop(animation)
if !is_old_animation_loop || !is_new_animation_loop:
sprite.frame = 0
sprite.play(animation)
if !is_new_animation_loop:
yield(sprite, 'animation_finished')
dialogue_box.stop_waiting()
func start_dialogue(dialog_path : String) -> DialogueAction:
var dialogue = DialogueAction.new()