47 lines
1.5 KiB
GDScript
47 lines
1.5 KiB
GDScript
extends Node
|
|
|
|
@export var dialogContainer: MarginContainer
|
|
@export var dialogTextLabel: RichTextLabel
|
|
|
|
var _current_dialog_counter: int = 0
|
|
var _current_dialog_text: DialogText = null
|
|
var _current_dialog_seconds: float = 1
|
|
|
|
func set_dialog_text(dialog_text: DialogText, seconds: float = 1) -> void:
|
|
_current_dialog_counter = -1
|
|
_current_dialog_text = dialog_text
|
|
_current_dialog_seconds = seconds
|
|
_next_dialog_line()
|
|
|
|
func _next_dialog_line() -> void:
|
|
_current_dialog_counter += 1
|
|
set_dialog_line(_current_dialog_text.get_line_raw(_current_dialog_counter), _current_dialog_seconds)
|
|
|
|
func _process(_delta: float) -> void:
|
|
if Input.is_action_just_pressed("ui_accept") and _current_dialog_text:
|
|
_next_dialog_line()
|
|
|
|
func set_dialog_line(text: String, seconds: float = 1) -> void:
|
|
dialogTextLabel.text = text
|
|
dialogTextLabel.visible_ratio = 0
|
|
var ratio: float = 0
|
|
|
|
if text.length() == 0:
|
|
dialogContainer.visible = false
|
|
%GameplayController.input_enabled = true
|
|
_current_dialog_text = null
|
|
return #a hacky way to clear the dialog box
|
|
else:
|
|
dialogContainer.visible = true
|
|
%GameplayController.input_enabled = false
|
|
|
|
var increment: float = (1 / seconds)/ 60.0
|
|
|
|
while true:
|
|
#don't interfere with other timers
|
|
if dialogTextLabel.visible_ratio < ratio or dialogTextLabel.visible_ratio >= 1:
|
|
return
|
|
dialogTextLabel.visible_ratio += increment
|
|
ratio = dialogTextLabel.visible_ratio
|
|
await get_tree().create_timer(1.0/60.0).timeout #update proportional to 60 FPS
|