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

61 lines
1.5 KiB
GDScript3
Raw Normal View History

2025-04-22 21:30:11 -06:00
extends Control
## Title screen!
2025-04-22 22:10:08 -06:00
# TODO is there a way to get this path without loading the level scene?
@export var save_path: String
2025-04-22 21:30:11 -06:00
@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
2025-04-22 22:38:06 -06:00
@onready var title_sfx: AudioStreamPlayer = %TitleSFX
@onready var title_drone: AudioStreamPlayer = %TitleDrone
2025-04-22 21:30:11 -06:00
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)
2025-04-22 21:30:11 -06:00
func stop_sounds() -> void:
title_sfx.stop()
title_drone.stop()
2025-04-22 21:30:11 -06:00
func continue_game() -> void:
2025-08-15 15:51:11 -06:00
GlobalSFXManager.confirm.play()
stop_sounds()
2025-04-22 22:10:08 -06:00
LoadingTools.load_save(save_path)
2025-04-22 21:30:11 -06:00
func new_game() -> void:
2025-08-15 15:51:11 -06:00
GlobalSFXManager.confirm.play()
stop_sounds()
2025-04-22 21:30:11 -06:00
LoadingTools.load_level(level_scene)
func show_settings() -> void:
2025-08-15 15:51:11 -06:00
GlobalSFXManager.confirm.play()
2025-04-22 21:30:11 -06:00
var instance: Control = settings_scene.instantiate()
settings_container.add_child(instance)
func quit() -> void:
2025-08-15 15:51:11 -06:00
GlobalSFXManager.cancel.play()
2025-04-22 21:30:11 -06:00
get_tree().root.propagate_notification(NOTIFICATION_WM_CLOSE_REQUEST)
2025-04-22 22:38:06 -06:00
func _exit_tree() -> void:
stop_sounds()