Personajes seleccionables
This commit is contained in:
1 parent
66f4d8b33b
commit
97335c9d21
42 files changed
+5282
-3106
No files matched your search
+58
-7
@@ -4,6 +4,7 @@ extends Control
|
||||
## Solo descubre escenas directamente dentro de levels, nunca sus subcarpetas.
|
||||
const LEVEL_DIRECTORY: String = "res://levels"
|
||||
|
||||
@onready var characters_panel: VBoxContainer = $Margin/Layout/Characters
|
||||
@onready var title_label: Label = $Margin/Layout/Title
|
||||
@onready var home_panel: VBoxContainer = $Margin/Layout/Home
|
||||
@onready var levels_panel: VBoxContainer = $Margin/Layout/Levels
|
||||
@@ -20,10 +21,17 @@ const LEVEL_DIRECTORY: String = "res://levels"
|
||||
@onready var loading_progress: ProgressBar = $Loading/Content/Progress
|
||||
|
||||
var _loading_path: String = ""
|
||||
var _selected_level_path: String = ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_process(false)
|
||||
# Volver desde una meta o abandonar exige una nueva eleccion, no un guardado de personaje.
|
||||
var session: RunSessionState = get_node_or_null("/root/RunSession") as RunSessionState
|
||||
if session != null:
|
||||
session.clear()
|
||||
characters_panel.connect("back_requested", _show_levels)
|
||||
characters_panel.connect("character_chosen", _on_character_chosen)
|
||||
play_button.pressed.connect(_show_levels)
|
||||
back_button.pressed.connect(_show_home)
|
||||
inventory_button.pressed.connect(_show_inventory)
|
||||
@@ -58,6 +66,8 @@ static func level_label(path: String) -> String:
|
||||
func _show_home() -> void:
|
||||
if not _loading_path.is_empty():
|
||||
return
|
||||
_selected_level_path = ""
|
||||
characters_panel.hide()
|
||||
inventory_panel.hide()
|
||||
home_panel.show()
|
||||
levels_panel.hide()
|
||||
@@ -71,6 +81,8 @@ func _show_home() -> void:
|
||||
func _show_levels() -> void:
|
||||
if not _loading_path.is_empty():
|
||||
return
|
||||
_selected_level_path = ""
|
||||
characters_panel.hide()
|
||||
for child: Node in level_list.get_children():
|
||||
level_list.remove_child(child)
|
||||
child.queue_free()
|
||||
@@ -83,7 +95,7 @@ func _show_levels() -> void:
|
||||
button.size_flags_horizontal = Control.SIZE_EXPAND_FILL
|
||||
# El texto no fuerza el ancho: sigue cabiendo en pantallas estrechas.
|
||||
button.clip_text = true
|
||||
button.pressed.connect(_load_level.bind(path))
|
||||
button.pressed.connect(_show_characters.bind(path))
|
||||
level_list.add_child(button)
|
||||
empty_label.visible = paths.is_empty()
|
||||
inventory_panel.hide()
|
||||
@@ -102,15 +114,39 @@ func _show_inventory() -> void:
|
||||
return
|
||||
home_panel.hide()
|
||||
levels_panel.hide()
|
||||
characters_panel.hide()
|
||||
error_label.hide()
|
||||
title_label.text = "OBJETOS RAROS"
|
||||
inventory_panel.call("show_collection")
|
||||
|
||||
|
||||
## La pantalla de carga real no introduce otros diez segundos artificiales.
|
||||
func _load_level(path: String) -> void:
|
||||
## Elegir nivel no inicia su carga: primero se elige una de las cuatro tarjetas.
|
||||
func _show_characters(path: String) -> void:
|
||||
if not _loading_path.is_empty():
|
||||
return
|
||||
_selected_level_path = path
|
||||
home_panel.hide()
|
||||
levels_panel.hide()
|
||||
inventory_panel.hide()
|
||||
error_label.hide()
|
||||
title_label.text = "ELEGIR PERSONAJE"
|
||||
characters_panel.call("show_roster", level_label(path))
|
||||
|
||||
|
||||
func _on_character_chosen(character: CharacterData) -> void:
|
||||
if _selected_level_path.is_empty() or character == null:
|
||||
return
|
||||
_load_level(_selected_level_path, character)
|
||||
|
||||
|
||||
## La pantalla de carga real no introduce otros diez segundos artificiales.
|
||||
func _load_level(path: String, character: CharacterData) -> void:
|
||||
if not _loading_path.is_empty():
|
||||
return
|
||||
var session: RunSessionState = get_node_or_null("/root/RunSession") as RunSessionState
|
||||
if session == null or character == null:
|
||||
_show_load_error("No se pudo preparar la seleccion de personaje.")
|
||||
return
|
||||
if not ResourceLoader.exists(path, "PackedScene"):
|
||||
_show_load_error("No se encuentra el nivel: " + path.get_file())
|
||||
return
|
||||
@@ -119,6 +155,8 @@ func _load_level(path: String) -> void:
|
||||
_show_load_error("No se pudo iniciar la carga: " + error_string(error))
|
||||
return
|
||||
_loading_path = path
|
||||
session.begin_level(path, character)
|
||||
characters_panel.hide()
|
||||
# Ocultar el panel tambien evita activaciones por teclado mientras se carga.
|
||||
levels_panel.hide()
|
||||
loading_panel.show()
|
||||
@@ -152,20 +190,33 @@ func _show_load_error(message: String) -> void:
|
||||
_loading_path = ""
|
||||
set_process(false)
|
||||
loading_panel.hide()
|
||||
_show_levels()
|
||||
var session: RunSessionState = get_node_or_null("/root/RunSession") as RunSessionState
|
||||
if session != null:
|
||||
session.clear()
|
||||
if not _selected_level_path.is_empty() and ResourceLoader.exists(_selected_level_path, "PackedScene"):
|
||||
_show_characters(_selected_level_path)
|
||||
else:
|
||||
_show_levels()
|
||||
error_label.text = message
|
||||
error_label.show()
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_cancel") and _loading_path.is_empty() and (levels_panel.visible or inventory_panel.visible):
|
||||
_show_home()
|
||||
if event.is_action_pressed("ui_cancel") and _loading_path.is_empty():
|
||||
if characters_panel.visible:
|
||||
_show_levels()
|
||||
elif levels_panel.visible or inventory_panel.visible:
|
||||
_show_home()
|
||||
else:
|
||||
return
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_WM_GO_BACK_REQUEST and is_node_ready() and _loading_path.is_empty():
|
||||
if levels_panel.visible or inventory_panel.visible:
|
||||
if characters_panel.visible:
|
||||
_show_levels()
|
||||
elif levels_panel.visible or inventory_panel.visible:
|
||||
_show_home()
|
||||
else:
|
||||
_quit_game()
|
||||
|
||||
Reference in new issue
Block a user