Menu de inicio, nuevo nivel y ajustes en objetos
This commit is contained in:
1 parent
cd9f31c8c1
commit
827e16cf50
61 files changed
+2685
-3553
No files matched your search
@@ -0,0 +1,90 @@
|
||||
extends Control
|
||||
|
||||
## Intro provisional. Los diez segundos son una presentacion, no progreso ficticio.
|
||||
## Se carga el menu en paralelo y nunca se salta una carga real pendiente.
|
||||
## Sustituir IntroContent por un video/animacion no obliga a cambiar el menu.
|
||||
const MENU_PATH: String = "res://ui/menu/main_menu.tscn"
|
||||
|
||||
@export_category("Intro")
|
||||
## La intro es saltable desde el primer arranque; no necesita un archivo de guardado.
|
||||
@export_range(0.0, 60.0, 0.5) var intro_duration_seconds: float = 10.0
|
||||
|
||||
@onready var status_label: Label = $Margin/IntroContent/Status
|
||||
@onready var skip_button: Button = $Margin/IntroContent/Skip
|
||||
|
||||
var _elapsed: float = 0.0
|
||||
var _skip_requested: bool = false
|
||||
var _leaving: bool = false
|
||||
var _load_failed: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
$Margin/IntroContent/Hint.text = "Intro provisional de %g segundos" % intro_duration_seconds
|
||||
skip_button.pressed.connect(_on_skip_pressed)
|
||||
skip_button.grab_focus()
|
||||
_request_menu()
|
||||
|
||||
|
||||
## Inicia o reintenta la carga, sin bloquear el hilo que dibuja la intro.
|
||||
func _request_menu() -> void:
|
||||
_load_failed = false
|
||||
status_label.text = "Cargando..."
|
||||
skip_button.text = "SALTAR INTRO"
|
||||
skip_button.disabled = false
|
||||
var error: Error = ResourceLoader.load_threaded_request(MENU_PATH, "PackedScene")
|
||||
if error != OK:
|
||||
_show_error(error_string(error))
|
||||
else:
|
||||
set_process(true)
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
if _leaving or _load_failed:
|
||||
return
|
||||
_elapsed += delta
|
||||
var status: ResourceLoader.ThreadLoadStatus = ResourceLoader.load_threaded_get_status(MENU_PATH)
|
||||
if status == ResourceLoader.THREAD_LOAD_FAILED or status == ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:
|
||||
_show_error("No se pudo cargar el menu.")
|
||||
return
|
||||
if not _skip_requested and _elapsed < intro_duration_seconds:
|
||||
return
|
||||
if status != ResourceLoader.THREAD_LOAD_LOADED:
|
||||
status_label.text = "Cargando el menu..."
|
||||
return
|
||||
var menu: PackedScene = ResourceLoader.load_threaded_get(MENU_PATH) as PackedScene
|
||||
if menu == null:
|
||||
_show_error("El recurso del menu no es una escena.")
|
||||
return
|
||||
_leaving = true
|
||||
var error: Error = get_tree().change_scene_to_packed(menu)
|
||||
if error != OK:
|
||||
_leaving = false
|
||||
_show_error(error_string(error))
|
||||
|
||||
|
||||
func _on_skip_pressed() -> void:
|
||||
_skip_requested = true
|
||||
if _load_failed:
|
||||
_request_menu()
|
||||
else:
|
||||
skip_button.disabled = true
|
||||
|
||||
|
||||
## Escape/atras hace lo mismo que el boton, pero no abandona una carga pendiente.
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
_on_skip_pressed()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_WM_GO_BACK_REQUEST and is_node_ready():
|
||||
_on_skip_pressed()
|
||||
|
||||
|
||||
func _show_error(message: String) -> void:
|
||||
_load_failed = true
|
||||
set_process(false)
|
||||
status_label.text = "No se pudo abrir el menu.\n" + message
|
||||
skip_button.text = "REINTENTAR"
|
||||
skip_button.disabled = false
|
||||
Reference in new issue
Block a user