2020-08-16 08:50:04 +02:00
|
|
|
extends Control
|
|
|
|
class_name DialogueBox
|
|
|
|
|
|
|
|
signal end
|
|
|
|
|
|
|
|
export (NodePath) var title_path
|
|
|
|
onready var title = get_node(title_path) as RichTextLabel
|
|
|
|
|
|
|
|
export (NodePath) var text_path
|
|
|
|
onready var text = get_node(text_path) as RichTextLabel
|
|
|
|
|
|
|
|
export (NodePath) var expression_path
|
|
|
|
onready var expression = get_node(expression_path) as RichTextLabel
|
|
|
|
|
|
|
|
var _dialogue : Array
|
|
|
|
var _index : int
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
assert(title != null)
|
|
|
|
assert(text != null)
|
|
|
|
|
|
|
|
func start(dialogue : Array):
|
|
|
|
_dialogue = dialogue
|
|
|
|
_index = 0
|
|
|
|
_update()
|
|
|
|
show()
|
|
|
|
|
|
|
|
func _input(event):
|
|
|
|
if event.is_action_pressed("ui_accept"):
|
2020-08-16 10:41:14 +02:00
|
|
|
if text.visible_characters < text.text.length():
|
|
|
|
text.visible_characters = text.text.length()
|
|
|
|
else:
|
|
|
|
next()
|
2020-08-16 08:50:04 +02:00
|
|
|
|
|
|
|
func next() -> void:
|
|
|
|
_index += 1
|
|
|
|
if _index >= _dialogue.size():
|
|
|
|
hide()
|
|
|
|
emit_signal('end')
|
|
|
|
return
|
|
|
|
_update()
|
|
|
|
|
|
|
|
func _update() -> void:
|
|
|
|
title.text = _dialogue[_index].name
|
2020-08-16 11:52:59 +02:00
|
|
|
title.rect_min_size.x = title.get_font('normal_font').get_string_size(title.text).x
|
2020-08-16 10:41:14 +02:00
|
|
|
text.text = _dialogue[_index].text
|
2020-08-16 08:50:04 +02:00
|
|
|
#expression = _dialogue[_index].expression
|
2020-08-16 10:41:14 +02:00
|
|
|
|
|
|
|
animate_text()
|
|
|
|
|
|
|
|
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
|
|
|
|
yield(get_tree().create_timer(0.05), 'timeout')
|