70 lines
2.3 KiB
GDScript
70 lines
2.3 KiB
GDScript
class_name DialogBob
|
|
extends Node2D
|
|
|
|
|
|
signal dialog_finished(choice_selected: String)
|
|
|
|
const SPEED_SLOW = 10.0
|
|
const SPEED_NORMAL = 15.0
|
|
const SPEED_FAST = 20.0
|
|
|
|
@export var test: Array[DialogLine] = []
|
|
|
|
|
|
var text_box_label: RichTextLabel
|
|
|
|
|
|
var dialog_text: Array[Dictionary] = [
|
|
{speaker = "?", text = "...", speed = SPEED_SLOW},
|
|
{speaker = "Necra", text = "Hello?"},
|
|
{speaker = "?", text = "!", speed = SPEED_SLOW},
|
|
{speaker = "Necra", text = "Can... can I help you?", speed = SPEED_SLOW},
|
|
{speaker = "?", text = "EEEEEEHHHsh...", speed = SPEED_SLOW},
|
|
{speaker = "?", text = "*Cough* Sorry, my vocal cords are rusty. Yes.", speed = SPEED_FAST},
|
|
{speaker = "Bob", text = "I am Bob. There is a bat in my chest. Can you remove it?"},
|
|
{speaker = "Necra", text = "How did that... on second thought, nevermind."},
|
|
]
|
|
|
|
var current_line = 0
|
|
|
|
func _ready():
|
|
text_box_label.visible = true
|
|
text_box_label.text = ""
|
|
$Undead.modulate = Color(1.0,1.0,1.0,0)
|
|
next_line()
|
|
|
|
func _unhandled_input(event):
|
|
if event is InputEventKey:
|
|
if event.key_label == KEY_SPACE and event.is_released():
|
|
next_line()
|
|
|
|
var tween: Tween
|
|
func next_line():
|
|
if not text_box_label.visible: return
|
|
if tween:
|
|
if tween.is_running():
|
|
tween.pause()
|
|
tween.custom_step(20)
|
|
return
|
|
tween.kill()
|
|
if current_line >= dialog_text.size():
|
|
dialog_finished.emit("")
|
|
text_box_label.hide()
|
|
return
|
|
if current_line == 0:
|
|
create_tween().tween_property($Undead, "modulate", Color(1.0,1.0,1.0, .1), 1)
|
|
if current_line == 2:
|
|
create_tween().tween_property($Undead, "modulate", Color(1.0,1.0,1.0, .2), 1)
|
|
if current_line == 4:
|
|
create_tween().tween_property($Undead, "modulate", Color(1.0,1.0,1.0, .5), 1)
|
|
if current_line == 5:
|
|
create_tween().tween_property($Undead, "modulate", Color(1.0,1.0,1.0, 1), .2)
|
|
var next = dialog_text[current_line]
|
|
text_box_label.text = "%s: %s" % [next["speaker"], next["text"]]
|
|
text_box_label.visible_characters = next["speaker"].length() + 2
|
|
var remaining_characters = text_box_label.text.length() - text_box_label.visible_characters
|
|
var tween_duration = remaining_characters / (next["speed"] if next.has("speed") else SPEED_NORMAL)
|
|
|
|
tween = create_tween()
|
|
tween.tween_property(text_box_label, "visible_characters", text_box_label.text.length(), tween_duration)
|
|
current_line += 1
|