xiandie/scene/little_game/弹珠游戏/dialogue_balloon.gd

40 lines
1.1 KiB
GDScript

extends CanvasLayer
signal ball_dialogue_ended
@onready var label = %RichTextLabel as RichTextLabel
## The current line
var dialogue_line: DialogueLine:
set(value):
if value:
dialogue_line = value
apply_dialogue_line()
get:
return dialogue_line
func _ready() -> void:
layer = GlobalConfig.CANVAS_LAYER_DIALOG
func start(
dialogue_resource: DialogueResource, title: String, extra_game_states: Array = []
) -> void:
var temporary_game_states = [self] + extra_game_states
self.dialogue_line = await dialogue_resource.get_next_dialogue_line(
title, temporary_game_states
)
## Apply any changes to the balloon given a new [DialogueLine].
func apply_dialogue_line() -> void:
var translation_key = dialogue_line.translation_key
label.text = ("[wave amp=10.0 freq=5.0][shake rate=4.0 level=3]" + tr(translation_key).strip_edges())
var tween = create_tween()
tween.tween_property(label, "modulate:a", 1.0, 0.5)
tween.tween_interval(2.0)
tween.tween_property(label, "modulate:a", 0.0, 0.5)
tween.tween_callback(ball_dialogue_ended.emit)
tween.tween_callback(queue_free)