46 lines
912 B
GDScript3
46 lines
912 B
GDScript3
|
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"):
|
||
|
next()
|
||
|
|
||
|
func next() -> void:
|
||
|
_index += 1
|
||
|
if _index >= _dialogue.size():
|
||
|
hide()
|
||
|
emit_signal('end')
|
||
|
return
|
||
|
_update()
|
||
|
|
||
|
func _update() -> void:
|
||
|
text.text = _dialogue[_index].text
|
||
|
title.text = _dialogue[_index].name
|
||
|
#expression = _dialogue[_index].expression
|
||
|
if _index == _dialogue.size() - 1:
|
||
|
emit_signal('end')
|