2020-08-16 08:50:04 +02:00
|
|
|
extends Control
|
|
|
|
class_name DialogueBox
|
|
|
|
|
|
|
|
signal end
|
2020-08-17 10:45:39 +02:00
|
|
|
signal update
|
2020-08-16 08:50:04 +02:00
|
|
|
|
2020-08-17 11:37:50 +02:00
|
|
|
export (NodePath) var name_label_path
|
|
|
|
onready var name_label = get_node(name_label_path) as RichTextLabel
|
2020-08-16 08:50:04 +02:00
|
|
|
|
2020-08-17 11:37:50 +02:00
|
|
|
export (NodePath) var text_label_path
|
|
|
|
onready var text_label = get_node(text_label_path) as RichTextLabel
|
2020-08-16 08:50:04 +02:00
|
|
|
|
2020-08-20 19:40:24 +02:00
|
|
|
#export (NodePath) var expression_node_path
|
|
|
|
#onready var expression_node = get_node(expression_node_path) as RichTextLabel
|
2020-08-16 08:50:04 +02:00
|
|
|
|
2020-08-18 11:55:07 +02:00
|
|
|
onready var music_player = get_node('/root/MusicPlayer') as MusicPlayer
|
2020-08-18 11:05:27 +02:00
|
|
|
|
2020-08-20 13:07:50 +02:00
|
|
|
onready var black_screen = $BlackScreen
|
2020-08-20 14:45:54 +02:00
|
|
|
onready var control_indicator = $MarginContainer/VBoxContainer/ControlIndicator
|
2020-08-20 13:07:50 +02:00
|
|
|
|
2020-08-17 11:37:50 +02:00
|
|
|
var dialogue : Array
|
|
|
|
var index : int
|
|
|
|
|
|
|
|
var character_name : String = ""
|
|
|
|
var text : String = ""
|
|
|
|
var expression : String = ""
|
|
|
|
var waiting = false
|
|
|
|
var auto_advance = false
|
2020-08-16 08:50:04 +02:00
|
|
|
|
|
|
|
func _ready():
|
2020-08-17 11:37:50 +02:00
|
|
|
assert(name_label != null)
|
|
|
|
assert(text_label != null)
|
2020-08-18 11:55:07 +02:00
|
|
|
assert(music_player != null)
|
2020-08-20 13:07:50 +02:00
|
|
|
assert(black_screen != null)
|
2020-08-20 14:45:54 +02:00
|
|
|
|
|
|
|
$MarginContainer.hide()
|
2020-08-16 08:50:04 +02:00
|
|
|
|
2020-08-20 10:35:25 +02:00
|
|
|
func start_dialogue(dialog_path : String) -> DialogueAction:
|
2020-08-20 19:40:24 +02:00
|
|
|
var action = DialogueAction.new()
|
|
|
|
action.dialogue_file_path = dialog_path
|
|
|
|
action.dialogue_box = self
|
|
|
|
action.start()
|
|
|
|
return action
|
2020-08-20 10:35:25 +02:00
|
|
|
|
2020-08-18 11:05:27 +02:00
|
|
|
func start(_dialogue : Array):
|
|
|
|
dialogue = _dialogue
|
2020-08-17 11:37:50 +02:00
|
|
|
index = 0
|
|
|
|
update()
|
2020-08-16 08:50:04 +02:00
|
|
|
|
|
|
|
func _input(event):
|
2020-08-17 11:37:50 +02:00
|
|
|
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()
|
2020-08-16 10:41:14 +02:00
|
|
|
else:
|
|
|
|
next()
|
2020-08-16 08:50:04 +02:00
|
|
|
|
|
|
|
func next() -> void:
|
2020-08-17 11:37:50 +02:00
|
|
|
index += 1
|
|
|
|
if index >= dialogue.size():
|
2020-08-20 13:07:50 +02:00
|
|
|
$MarginContainer.hide()
|
2020-08-16 08:50:04 +02:00
|
|
|
emit_signal('end')
|
|
|
|
return
|
2020-08-17 11:37:50 +02:00
|
|
|
update()
|
2020-08-16 08:50:04 +02:00
|
|
|
|
2020-08-17 11:37:50 +02:00
|
|
|
func update() -> void:
|
|
|
|
var line = dialogue[index]
|
|
|
|
|
|
|
|
# Self properties
|
|
|
|
character_name = line.get('name', '')
|
|
|
|
text = line.get('text', '')
|
|
|
|
expression = line.get('expression', '')
|
2020-08-18 11:05:27 +02:00
|
|
|
|
|
|
|
# Flow
|
2020-08-17 11:37:50 +02:00
|
|
|
waiting = line.get('wait', false)
|
|
|
|
auto_advance = line.get('auto', false)
|
|
|
|
|
2020-08-18 11:05:27 +02:00
|
|
|
# Timer
|
|
|
|
var timer = line.get('timer', 0)
|
2020-08-17 11:37:50 +02:00
|
|
|
if timer > 0:
|
|
|
|
waiting = true
|
|
|
|
|
2020-08-18 11:05:27 +02:00
|
|
|
# Audio
|
2020-08-18 11:55:07 +02:00
|
|
|
var audio = line.get('audio', null)
|
|
|
|
if audio != null:
|
|
|
|
if audio == '':
|
|
|
|
music_player.fade_out()
|
|
|
|
else:
|
|
|
|
music_player.play(audio)
|
2020-08-18 11:05:27 +02:00
|
|
|
|
2020-08-17 11:37:50 +02:00
|
|
|
# UI
|
2020-08-20 12:01:19 +02:00
|
|
|
var upside_down = line.get('upside_down', false)
|
|
|
|
if upside_down:
|
|
|
|
$MarginContainer/VBoxContainer.alignment = BoxContainer.ALIGN_BEGIN
|
|
|
|
$MarginContainer/VBoxContainer.add_child_below_node($MarginContainer/VBoxContainer/TextContainer, $MarginContainer/VBoxContainer/NameContainer)
|
2020-08-17 11:37:50 +02:00
|
|
|
else:
|
2020-08-20 12:01:19 +02:00
|
|
|
$MarginContainer/VBoxContainer.alignment = BoxContainer.ALIGN_END
|
|
|
|
$MarginContainer/VBoxContainer.add_child_below_node($MarginContainer/VBoxContainer/NameContainer, $MarginContainer/VBoxContainer/TextContainer)
|
|
|
|
|
2020-08-20 16:33:27 +02:00
|
|
|
if text != '':
|
2020-08-20 12:01:19 +02:00
|
|
|
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
|
|
|
|
|
2020-08-20 16:33:27 +02:00
|
|
|
if character_name == '': $MarginContainer/VBoxContainer/NameContainer.hide()
|
|
|
|
else: $MarginContainer/VBoxContainer/NameContainer.show()
|
|
|
|
|
2020-08-20 13:07:50 +02:00
|
|
|
if text == "": $MarginContainer.hide()
|
|
|
|
else: $MarginContainer.show()
|
2020-08-16 10:41:14 +02:00
|
|
|
|
2020-08-17 10:45:39 +02:00
|
|
|
emit_signal('update')
|
|
|
|
|
2020-08-20 13:07:50 +02:00
|
|
|
# Animation
|
|
|
|
var animation = line.get('animation', null)
|
|
|
|
if animation != null:
|
|
|
|
print('animate!' + animation)
|
2020-08-20 19:40:24 +02:00
|
|
|
if animation == 'fadein':
|
|
|
|
black_screen.modulate.a = 1
|
2020-08-20 13:07:50 +02:00
|
|
|
black_screen.animate(animation, timer)
|
|
|
|
elif expression == 'black':
|
2020-08-20 19:40:24 +02:00
|
|
|
black_screen.modulate.a = 1
|
2020-08-20 13:07:50 +02:00
|
|
|
black_screen.animate('black', 0)
|
|
|
|
else:
|
|
|
|
black_screen.animate(null, timer)
|
|
|
|
|
2020-08-16 10:41:14 +02:00
|
|
|
animate_text()
|
2020-08-17 11:37:50 +02:00
|
|
|
|
|
|
|
if timer > 0:
|
|
|
|
yield(get_tree().create_timer(timer), 'timeout')
|
|
|
|
stop_waiting()
|
2020-08-16 10:41:14 +02:00
|
|
|
|
|
|
|
func animate_text():
|
2020-08-17 11:37:50 +02:00
|
|
|
var animated = index
|
|
|
|
text_label.visible_characters = 0
|
2020-08-20 14:45:54 +02:00
|
|
|
control_indicator.hide()
|
2020-08-17 11:37:50 +02:00
|
|
|
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
|
2020-08-20 17:18:52 +02:00
|
|
|
|
|
|
|
var c = text_label.text[text_label.visible_characters - 1]
|
|
|
|
|
|
|
|
if $MarginContainer.visible:
|
|
|
|
if "abcdefghijklmnoprstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZÀàéÉçÇÈèùÙ.".rfind(c) >= 0:
|
|
|
|
if character_name == 'Ely': $GibberishPlayer2.play()
|
|
|
|
else: $GibberishPlayer1.play()
|
|
|
|
|
|
|
|
yield(get_tree().create_timer(0.4 if c == '.' else 0.05), 'timeout')
|
2020-08-20 14:45:54 +02:00
|
|
|
if !Globals.ui_accept_tip:
|
|
|
|
control_indicator.show_press('ui_accept')
|
|
|
|
Globals.ui_accept_tip = true
|
2020-08-20 13:07:50 +02:00
|
|
|
|
2020-08-17 11:37:50 +02:00
|
|
|
func stop_waiting():
|
|
|
|
waiting = false
|
|
|
|
if auto_advance:
|
|
|
|
next()
|
2020-08-20 13:07:50 +02:00
|
|
|
|