xiandie/scene/trailer.gd
2025-07-15 18:45:03 +08:00

116 lines
3.9 KiB
GDScript

extends Control
@onready var video_player = $VideoStreamPlayer
@onready var earplug_notice = $"耳机提示"
@onready var sfx_click = $SfxClick as Sfx
@onready var settings = %"设置界面" as Control
@onready var lang_label = %LangLabel as Label
@onready var lang_left_btn = %LangLeft as Button
@onready var lang_right_btn = %LangRight as Button
@onready var caption_box = %CaptionBox as BoxContainer
@onready var caption_label = %CaptionLabel as Label
@onready var caption_left_btn = %CaptionLeft as Button
@onready var caption_right_btn = %CaptionRight as Button
@onready var confirm_btn = %ConfirmButton as Button
var packed_index_page := preload("res://scene/index_page.tscn")
var first_launching_game := true
func _ready() -> void:
earplug_notice.hide()
if GlobalConfigManager.config:
var game_launched_times = GlobalConfigManager.config.game_launched_times
GlobalConfigManager.config.game_launched_times = game_launched_times + 1
first_launching_game = game_launched_times == 0
if GlobalConfigManager.config.skip_trailer:
SceneManager.checkout_index_page(false)
return
video_player.play()
video_player.finished.connect(_on_video_finished)
lang_left_btn.pressed.connect(_on_lang_left_btn_pressed)
lang_right_btn.pressed.connect(_on_lang_right_btn_pressed)
caption_left_btn.pressed.connect(_on_caption_left_btn_pressed)
caption_right_btn.pressed.connect(_on_caption_right_btn_pressed)
var earplug_notice_tween: Tween
func _on_video_finished() -> void:
earplug_notice.visible = true
earplug_notice.modulate.a = 0
earplug_notice_tween = create_tween()
earplug_notice_tween.tween_property(earplug_notice, "modulate:a", 1.0, 1.0)
if not first_launching_game:
settings.hide()
earplug_notice_tween.tween_interval(3.0)
earplug_notice_tween.tween_property(earplug_notice, "modulate:a", 0.0, 1.0)
earplug_notice_tween.finished.connect(_on_earplug_notice_finished)
else:
settings.show()
confirm_btn.pressed.connect(_on_confirm_btn_pressed)
func _on_confirm_btn_pressed() -> void:
confirm_btn.disabled = true
var tween = create_tween()
tween.tween_property(earplug_notice, "modulate:a", 0.0, 1.0)
tween.finished.connect(_on_earplug_notice_finished)
func _on_earplug_notice_finished() -> void:
SceneManager.checkout_index_page(false)
func _unhandled_input(event: InputEvent) -> void:
if event.is_action_pressed("escape") and not first_launching_game:
if video_player.is_playing():
get_viewport().set_input_as_handled()
video_player.stop()
_on_video_finished()
elif earplug_notice_tween and earplug_notice_tween.is_running():
get_viewport().set_input_as_handled()
earplug_notice_tween.kill()
earplug_notice.modulate.a = 0
_on_earplug_notice_finished()
func _on_lang_left_btn_pressed() -> void:
sfx_click.play()
GlobalConfigManager.update_locale(
GlobalConfigManager.config.language - 1, GlobalConfigManager.config.caption
)
lang_label.text = GlobalConfigManager.get_locale_language_name()
caption_label.text = GlobalConfigManager.get_locale_caption_name()
caption_box.visible = caption_label.text != ""
func _on_lang_right_btn_pressed() -> void:
sfx_click.play()
GlobalConfigManager.update_locale(
GlobalConfigManager.config.language + 1, GlobalConfigManager.config.caption
)
lang_label.text = GlobalConfigManager.get_locale_language_name()
caption_label.text = GlobalConfigManager.get_locale_caption_name()
caption_box.visible = caption_label.text != ""
func _on_caption_left_btn_pressed() -> void:
sfx_click.play()
GlobalConfigManager.update_locale(
GlobalConfigManager.config.language, GlobalConfigManager.config.caption - 1
)
caption_label.text = GlobalConfigManager.get_locale_caption_name()
func _on_caption_right_btn_pressed() -> void:
sfx_click.play()
GlobalConfigManager.update_locale(
GlobalConfigManager.config.language, GlobalConfigManager.config.caption + 1
)
caption_label.text = GlobalConfigManager.get_locale_caption_name()