grunk/src/ui/menus/title_screen/title_screen.gd

61 lines
1.5 KiB
GDScript

extends Control
## Title screen!
# TODO is there a way to get this path without loading the level scene?
@export var save_path: String
@export_category("Game Scenes")
# TODO is there a way to get the appropriate level scene path here without loading the world scene?
@export_file("*.tscn") var level_scene: String
@export_file("*.tscn") var world_scene: String
@export var settings_scene: PackedScene
@onready var continue_button: Button = %Continue
@onready var settings_container: Control = %SettingsContainer
@onready var title_sfx: AudioStreamPlayer = %TitleSFX
@onready var title_drone: AudioStreamPlayer = %TitleDrone
func _ready() -> void:
Input.set_mouse_mode(Input.MOUSE_MODE_VISIBLE)
if FileAccess.file_exists(save_path):
continue_button.disabled = false
# Start preloading world and level in background
ResourceLoader.load_threaded_request(world_scene)
ResourceLoader.load_threaded_request(level_scene)
func stop_sounds() -> void:
title_sfx.stop()
title_drone.stop()
func continue_game() -> void:
GlobalSFXManager.confirm.play()
stop_sounds()
LoadingTools.load_save(save_path)
func new_game() -> void:
GlobalSFXManager.confirm.play()
stop_sounds()
LoadingTools.load_level(level_scene)
func show_settings() -> void:
GlobalSFXManager.forward.play()
var instance: Control = settings_scene.instantiate()
settings_container.add_child(instance)
func quit() -> void:
GlobalSFXManager.back.play()
get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
func _exit_tree() -> void:
stop_sounds()