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

47 lines
1.3 KiB
GDScript

extends CanvasLayer
# 使用场景:
# 1. 弹珠游戏
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().replace("{br}", "\n"))
var tween = create_tween()
tween.tween_property(label, "modulate:a", 1.0, 0.5)
# c02_弹珠游戏5 弹珠游戏最后的一句话显示时长延长
if translation_key == "c02_弹珠游戏5": # 注意是 line ID 而不是 title
tween.tween_interval(5.0)
else:
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)
$"Sfx红字特效音".play()