86 lines
2.2 KiB
GDScript
86 lines
2.2 KiB
GDScript
extends Control
|
|
|
|
# var main_scene := preload("res://scene/main.tscn") as PackedScene
|
|
|
|
@onready var settings = $Settings
|
|
@onready var animation_player = $AnimationPlayer as AnimationPlayer
|
|
@onready var animation_root = $AnimationRoot as Control
|
|
@onready var sfx = %Sfx as Sfx
|
|
@onready var newgame_btn = %NewGame as Button
|
|
@onready var resume_btn = %Resume as Button
|
|
@onready var quit_btn = %Quit as Button
|
|
|
|
var animation_finished = false
|
|
|
|
|
|
func _ready():
|
|
if GlobalConfig.DEBUG:
|
|
print("Index Page Ready")
|
|
# 推到 index 时禁用 paused
|
|
get_tree().paused = false
|
|
newgame_btn.pressed.connect(_on_newgame_pressed)
|
|
resume_btn.pressed.connect(_on_resume_pressed)
|
|
quit_btn.pressed.connect(_on_quit_pressed)
|
|
_check_resume_btn()
|
|
if SceneManager.first_entered:
|
|
SceneManager.first_entered = false
|
|
# 播放开始动画
|
|
animation_player.play("intro")
|
|
animation_player.animation_finished.connect(_on_intro_finished)
|
|
else:
|
|
animation_finished = true
|
|
|
|
|
|
func _on_intro_finished(_a):
|
|
animation_root.visible = false
|
|
animation_finished = true
|
|
|
|
|
|
func _check_resume_btn():
|
|
if not ArchiveManager.archives.has(1):
|
|
resume_btn.queue_free()
|
|
|
|
|
|
func _on_newgame_pressed():
|
|
sfx.global_play()
|
|
# 覆盖使用 1 号存档
|
|
ArchiveManager.create_and_use_new_archive(1)
|
|
_enter_main_scene()
|
|
|
|
|
|
func _on_resume_pressed():
|
|
sfx.global_play()
|
|
# 继续一号存档
|
|
if GlobalConfig.DEBUG:
|
|
print("Resume")
|
|
if ArchiveManager.archives.has(1):
|
|
# 设置 current_selected_archive_id 后,存档会自动加载
|
|
GlobalConfigManager.config.current_selected_archive_id = 1
|
|
else:
|
|
ArchiveManager.create_and_use_new_archive(1)
|
|
_enter_main_scene()
|
|
|
|
|
|
func _enter_main_scene():
|
|
# get_tree().change_scene_to_packed.call_deferred(main_scene)
|
|
get_tree().change_scene_to_file.call_deferred("res://scene/main.tscn")
|
|
|
|
|
|
func _on_quit_pressed():
|
|
# 退出时点击音效将无法播放
|
|
#sfx.global_play()
|
|
SceneManager.quit_game()
|
|
|
|
|
|
func _unhandled_input(event: InputEvent) -> void:
|
|
if event.is_action_pressed("escape"):
|
|
get_viewport().set_input_as_handled()
|
|
if not animation_finished:
|
|
# 跳过开始动画
|
|
animation_player.stop()
|
|
animation_root.visible = false
|
|
animation_finished = true
|
|
else:
|
|
# 设置菜单
|
|
settings.visible = true
|