necra-prototypes/dialog/dialog_map.gd
Antonio Dell'Annunziata 8040db6cfd
All checks were successful
/ test (push) Successful in 1s
Fix click through bugs
2025-03-16 16:41:39 +01:00

82 lines
3.2 KiB
GDScript

class_name DialogMap
extends Node2D
signal dialog_finished
const SPEED_SLOW = 10.0
const SPEED_NORMAL = 15.0
const SPEED_FAST = 20.0
@export var map_point_number = 0
var text_box_label: RichTextLabel
var dialog_text: Array[Dictionary]
var current_line = 0
func _ready():
_setup_text()
text_box_label.visible = true
text_box_label.text = ""
next_line()
func _setup_text():
match map_point_number:
0:
dialog_text = [
{speaker = "Necra", text = "A small path leads away from the crypt."},
{speaker = "Necra", text = "I follow it slowly into the dark forest."},
{speaker = "Necra", text = "After some time on the path I see a strange tree in full blossom."},
{speaker = "Necra", text = "Strange, everything else seems dead and decaying."},
{speaker = "Necra", text = "But this tree with it's blood red foliage defies the rest."},
{speaker = "Necra", text = "I notice a body sitting on the ground, laying against the massive stem amongs the tentacle like roots."},
]
1:
dialog_text = [
{speaker = "Necra", text = "The path continues leading me away from the tree."},
{speaker = "Necra", text = "It gets less muddy and eventually turns into a poorly maintained brick road."},
{speaker = "Necra", text = "The road ends at a tower."},
{speaker = "Necra", text = "Something is dangling from the roof, it's hard to make out through the tree tops."},
{speaker = "Necra", text = "I can either go up to the rooftop, or continue deeper into the woods."},
]
2:
dialog_text = [
{speaker = "Necra", text = "I enter the tower ruins."},
{speaker = "Necra", text = "A stone staircase leads up the side of the small room."},
{speaker = "Necra", text = "I have to be careful climbing up, some stairs are missing."},
{speaker = "Necra", text = "On the roof I see an old wooden construct, a rope attached to it."},
{speaker = "Necra", text = "The rope holds a body at the neck over the steep descend."},
{speaker = "Necra", text = "Branches of dead trees seem to stretch toward it, trying to reach it desperately."},
]
3:
dialog_text = [
{speaker = "Necra", text = "The forest is way harder to pass now, without a discernible path."},
{speaker = "Necra", text = "I need all my strength to fight through the undergrowth."},
{speaker = "Necra", text = "Suddenly it clears into a small glade."},
{speaker = "Necra", text = "A headless body lies in the middle."},
]
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 current_line >= dialog_text.size():
dialog_finished.emit()
text_box_label.hide()
return
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)
if tween:
tween.kill()
tween = create_tween()
tween.tween_property(text_box_label, "visible_characters", text_box_label.text.length(), tween_duration)
current_line += 1