extends Control # Constants const EARPLUG_FADE_DURATION := 1.0 const EARPLUG_DISPLAY_DURATION := 3.0 # Nodes @onready var video_player := $VideoStreamPlayer @onready var earplug_notice := $"耳机提示" as Control @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("uid://c4ycvdsabi7lw") # State var first_launching_game := true var earplug_notice_tween: Tween func _ready() -> void: earplug_notice.hide() if not GlobalConfigManager.config: SceneManager.checkout_index_page(false) return var game_launched_times = GlobalConfigManager.config.game_launched_times GlobalConfigManager.config.game_launched_times += 1 first_launching_game = (game_launched_times == 0) if GlobalConfigManager.config.skip_trailer: SceneManager.checkout_index_page(false) return _setup_video_player() _setup_language_settings(game_launched_times) _connect_button_signals() func _setup_video_player() -> void: video_player.play() video_player.finished.connect(_on_video_finished) func _setup_language_settings(game_launched_times: int) -> void: if game_launched_times == 0: _read_system_locale() _update_language_display() func _update_language_display() -> void: lang_label.text = GlobalConfigManager.get_locale_language_name() caption_label.text = GlobalConfigManager.get_locale_caption_name() caption_box.visible = (caption_label.text != "") func _connect_button_signals() -> void: lang_left_btn.pressed.connect(_on_lang_change.bind(-1)) lang_right_btn.pressed.connect(_on_lang_change.bind(1)) caption_left_btn.pressed.connect(_on_caption_change.bind(-1)) caption_right_btn.pressed.connect(_on_caption_change.bind(1)) func _read_system_locale() -> void: if not GlobalConfigManager.config: return var locale = OS.get_locale() var prefix = locale.split("_")[0] var config = GlobalConfigManager.config if GlobalConfig.LOCALE_PREFIX_MAPPING.has(prefix): config.language = GlobalConfig.LOCALE_PREFIX_MAPPING.get(prefix) GlobalConfigManager.update_locale(config.language, config.caption) print("[FirstLaunch] System locale: ", locale, " -> Language ID: ", GlobalConfigManager.config.language) 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, EARPLUG_FADE_DURATION) if first_launching_game: _show_first_launch_settings() else: _show_regular_launch_sequence() func _show_first_launch_settings() -> void: settings.show() confirm_btn.pressed.connect(_on_confirm_btn_pressed) func _show_regular_launch_sequence() -> void: settings.hide() earplug_notice_tween.tween_interval(EARPLUG_DISPLAY_DURATION) earplug_notice_tween.tween_property(earplug_notice, "modulate:a", 0.0, EARPLUG_FADE_DURATION) earplug_notice_tween.finished.connect(_on_earplug_notice_finished) func _on_confirm_btn_pressed() -> void: confirm_btn.disabled = true _fade_out_and_continue() func _fade_out_and_continue() -> void: var tween = create_tween() tween.tween_property(earplug_notice, "modulate:a", 0.0, EARPLUG_FADE_DURATION) 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 not event.is_action_pressed("escape") or first_launching_game: return if video_player.is_playing(): _skip_video() elif earplug_notice_tween and earplug_notice_tween.is_running(): _skip_earplug_notice() func _skip_video() -> void: get_viewport().set_input_as_handled() video_player.stop() _on_video_finished() func _skip_earplug_notice() -> void: get_viewport().set_input_as_handled() earplug_notice_tween.kill() earplug_notice.modulate.a = 0 _on_earplug_notice_finished() func _on_lang_change(direction: int) -> void: sfx_click.play() var config = GlobalConfigManager.config GlobalConfigManager.update_locale(config.language + direction, config.caption) _update_language_display() func _on_caption_change(direction: int) -> void: sfx_click.play() var config = GlobalConfigManager.config GlobalConfigManager.update_locale(config.language, config.caption + direction) caption_label.text = GlobalConfigManager.get_locale_caption_name()