Menus de muerte pausa y personajes renovados
This commit is contained in:
1 parent
97335c9d21
commit
6a267b2cf4
54 files changed
+14033
-3170
No files matched your search
+240
-15
@@ -1,60 +1,285 @@
|
||||
extends CanvasLayer
|
||||
|
||||
## Salida minima de los escenarios de prueba. Abandonar no confirma los raros encontrados.
|
||||
## Se usa una escena compartida para que el boton se pueda editar visualmente.
|
||||
## Pausa y resultados compartidos por todos los LevelRoot. No modifica las reglas de combate.
|
||||
## Los hallazgos de raros solo se confirman al superar el nivel.
|
||||
const MENU_PATH: String = "res://ui/menu/main_menu.tscn"
|
||||
const MENU_SCRIPT: Script = preload("res://ui/menu/main_menu.gd")
|
||||
|
||||
enum Screen { PLAYING, PAUSED, CONFIRM_EXIT, DEFEAT, VICTORY }
|
||||
|
||||
var _screen: Screen = Screen.PLAYING
|
||||
var _exit_to_levels: bool = false
|
||||
var _leaving: bool = false
|
||||
var _notice_seconds: float = 0.0
|
||||
var _next_level_path: String = ""
|
||||
|
||||
@onready var pause_button: Button = $Overlay/Pause
|
||||
@onready var scrim: ColorRect = $Overlay/Scrim
|
||||
@onready var dialog: CenterContainer = $Overlay/Dialog
|
||||
@onready var heading: Label = $Overlay/Dialog/Panel/Margin/Options/Heading
|
||||
@onready var description: Label = $Overlay/Dialog/Panel/Margin/Options/Description
|
||||
@onready var resume_button: Button = $Overlay/Dialog/Panel/Margin/Options/Resume
|
||||
@onready var restart_button: Button = $Overlay/Dialog/Panel/Margin/Options/Restart
|
||||
@onready var next_button: Button = $Overlay/Dialog/Panel/Margin/Options/Next
|
||||
@onready var levels_button: Button = $Overlay/Dialog/Panel/Margin/Options/Levels
|
||||
@onready var title_button: Button = $Overlay/Dialog/Panel/Margin/Options/Title
|
||||
@onready var confirm_button: Button = $Overlay/Dialog/Panel/Margin/Options/Confirm
|
||||
@onready var cancel_button: Button = $Overlay/Dialog/Panel/Margin/Options/Cancel
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
$Overlay/Menu.pressed.connect(return_to_menu)
|
||||
# No referencia LevelRoot por tipo: esta escena se precarga desde esa clase.
|
||||
pause_button.pressed.connect(pause_game)
|
||||
resume_button.pressed.connect(resume_game)
|
||||
restart_button.pressed.connect(_restart_level)
|
||||
next_button.pressed.connect(_load_next_level)
|
||||
levels_button.pressed.connect(_select_levels)
|
||||
title_button.pressed.connect(_select_title)
|
||||
confirm_button.pressed.connect(_confirm_exit)
|
||||
cancel_button.pressed.connect(_cancel_exit)
|
||||
var level: Node = get_parent()
|
||||
if level.has_signal("progress_notice"):
|
||||
level.connect("progress_notice", _show_notice)
|
||||
if level.has_signal("rare_items_changed"):
|
||||
level.connect("rare_items_changed", _refresh_pending)
|
||||
if level.has_signal("level_failed"):
|
||||
level.connect("level_failed", show_defeat)
|
||||
if level.has_signal("level_completed"):
|
||||
level.connect("level_completed", show_victory)
|
||||
_refresh_pending()
|
||||
_update_screen()
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
return_to_menu()
|
||||
if event.is_action_pressed("ui_cancel") and not event.is_echo():
|
||||
_handle_back()
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
|
||||
func _notification(what: int) -> void:
|
||||
if what == NOTIFICATION_WM_GO_BACK_REQUEST and is_node_ready():
|
||||
return_to_menu()
|
||||
_handle_back()
|
||||
|
||||
|
||||
func return_to_menu() -> void:
|
||||
func _exit_tree() -> void:
|
||||
# No deja el SceneTree pausado si otro sistema descarga el nivel.
|
||||
if not Engine.is_editor_hint():
|
||||
get_tree().paused = false
|
||||
|
||||
|
||||
func _handle_back() -> void:
|
||||
match _screen:
|
||||
Screen.PLAYING:
|
||||
pause_game()
|
||||
Screen.PAUSED:
|
||||
resume_game()
|
||||
Screen.CONFIRM_EXIT:
|
||||
_cancel_exit()
|
||||
# No es posible cerrar una pantalla de resultado sin elegir destino.
|
||||
Screen.DEFEAT, Screen.VICTORY:
|
||||
pass
|
||||
|
||||
|
||||
func pause_game() -> void:
|
||||
if _leaving or _screen != Screen.PLAYING:
|
||||
return
|
||||
_release_virtual_actions()
|
||||
_screen = Screen.PAUSED
|
||||
_update_screen()
|
||||
get_tree().paused = true
|
||||
resume_button.grab_focus()
|
||||
|
||||
|
||||
func resume_game() -> void:
|
||||
if _leaving or _screen != Screen.PAUSED:
|
||||
return
|
||||
_screen = Screen.PLAYING
|
||||
get_tree().paused = false
|
||||
_update_screen()
|
||||
pause_button.grab_focus()
|
||||
|
||||
|
||||
func show_defeat() -> void:
|
||||
if _leaving or _screen == Screen.DEFEAT or _screen == Screen.VICTORY:
|
||||
return
|
||||
_release_virtual_actions()
|
||||
_screen = Screen.DEFEAT
|
||||
_update_screen()
|
||||
get_tree().paused = true
|
||||
restart_button.grab_focus()
|
||||
|
||||
|
||||
func show_victory() -> void:
|
||||
if _leaving or _screen == Screen.VICTORY or _screen == Screen.DEFEAT:
|
||||
return
|
||||
_release_virtual_actions()
|
||||
_next_level_path = _get_next_level_path()
|
||||
_screen = Screen.VICTORY
|
||||
_update_screen()
|
||||
get_tree().paused = true
|
||||
(next_button if not _next_level_path.is_empty() else levels_button).grab_focus()
|
||||
|
||||
|
||||
func _get_next_level_path() -> String:
|
||||
var level: Node = get_parent()
|
||||
var current: String = level.scene_file_path
|
||||
if current.is_empty():
|
||||
return ""
|
||||
var paths: PackedStringArray = MENU_SCRIPT.discover_level_paths()
|
||||
var index: int = paths.find(current)
|
||||
if index < 0 or index >= paths.size() - 1:
|
||||
return ""
|
||||
return paths[index + 1]
|
||||
|
||||
|
||||
func _update_screen() -> void:
|
||||
var playing: bool = _screen == Screen.PLAYING
|
||||
pause_button.visible = playing
|
||||
scrim.visible = not playing
|
||||
dialog.visible = not playing
|
||||
$Overlay/Pending.visible = playing and int(get_parent().call("get_pending_rare_count")) > 0
|
||||
$Overlay/Notice.visible = playing and _notice_seconds > 0.0
|
||||
if playing:
|
||||
return
|
||||
resume_button.visible = _screen == Screen.PAUSED
|
||||
restart_button.visible = _screen == Screen.DEFEAT
|
||||
next_button.visible = _screen == Screen.VICTORY
|
||||
levels_button.visible = _screen != Screen.CONFIRM_EXIT
|
||||
title_button.visible = _screen != Screen.CONFIRM_EXIT
|
||||
confirm_button.visible = _screen == Screen.CONFIRM_EXIT
|
||||
cancel_button.visible = _screen == Screen.CONFIRM_EXIT
|
||||
match _screen:
|
||||
Screen.PAUSED:
|
||||
heading.add_theme_color_override("font_color", Color(0.9, 0.96, 0.61))
|
||||
heading.text = "PAUSA"
|
||||
description.text = "Partida en pausa. Puedes continuar o abandonar el intento."
|
||||
Screen.CONFIRM_EXIT:
|
||||
heading.add_theme_color_override("font_color", Color(1.0, 0.78, 0.48))
|
||||
heading.text = "¿ABANDONAR NIVEL?"
|
||||
description.text = "Perderás el avance de esta pantalla y los objetos raros aún no confirmados."
|
||||
confirm_button.text = "SI, IR AL SELECTOR" if _exit_to_levels else "SI, IR AL TITULO"
|
||||
Screen.DEFEAT:
|
||||
heading.add_theme_color_override("font_color", Color(1.0, 0.52, 0.49))
|
||||
heading.text = "HAS MUERTO..."
|
||||
description.text = "El intento ha terminado. Puedes volver a empezar o elegir otro nivel."
|
||||
Screen.VICTORY:
|
||||
heading.add_theme_color_override("font_color", Color(0.82, 0.97, 0.57))
|
||||
heading.text = "¡VICTORIA!"
|
||||
if _next_level_path.is_empty():
|
||||
description.text = "¡Nivel completado! No quedan mas niveles disponibles por ahora."
|
||||
else:
|
||||
description.text = "¡Nivel completado! Continúa la aventura o vuelve al menú."
|
||||
next_button.disabled = _next_level_path.is_empty()
|
||||
next_button.text = "NO HAY MAS NIVELES" if _next_level_path.is_empty() else "SIGUIENTE NIVEL"
|
||||
|
||||
|
||||
func _select_levels() -> void:
|
||||
_request_exit(true)
|
||||
|
||||
|
||||
func _select_title() -> void:
|
||||
_request_exit(false)
|
||||
|
||||
|
||||
func _request_exit(to_levels: bool) -> void:
|
||||
if _leaving:
|
||||
return
|
||||
_exit_to_levels = to_levels
|
||||
if _screen == Screen.PAUSED:
|
||||
_screen = Screen.CONFIRM_EXIT
|
||||
_update_screen()
|
||||
cancel_button.grab_focus()
|
||||
else:
|
||||
# Los resultados ya han concluido el intento; no hay progreso que perder.
|
||||
_confirm_exit()
|
||||
|
||||
|
||||
func _cancel_exit() -> void:
|
||||
if _screen != Screen.CONFIRM_EXIT:
|
||||
return
|
||||
_screen = Screen.PAUSED
|
||||
_update_screen()
|
||||
resume_button.grab_focus()
|
||||
|
||||
|
||||
func _confirm_exit() -> void:
|
||||
if _leaving:
|
||||
return
|
||||
var session: RunSessionState = get_node_or_null("/root/RunSession") as RunSessionState
|
||||
if session != null:
|
||||
session.show_levels_on_menu_entry = _exit_to_levels
|
||||
_change_scene(MENU_PATH)
|
||||
|
||||
|
||||
func _restart_level() -> void:
|
||||
if _screen != Screen.DEFEAT or _leaving:
|
||||
return
|
||||
_leaving = true
|
||||
get_tree().paused = false
|
||||
_release_virtual_actions()
|
||||
call_deferred("_reload_scene")
|
||||
|
||||
|
||||
func _reload_scene() -> void:
|
||||
var error: Error = get_tree().reload_current_scene()
|
||||
if error != OK:
|
||||
_leaving = false
|
||||
push_error("No se pudo reiniciar el nivel: " + error_string(error))
|
||||
get_tree().paused = true
|
||||
restart_button.grab_focus()
|
||||
|
||||
|
||||
func _load_next_level() -> void:
|
||||
if _screen != Screen.VICTORY or _leaving or _next_level_path.is_empty():
|
||||
return
|
||||
var session: RunSessionState = get_node_or_null("/root/RunSession") as RunSessionState
|
||||
var level: Node = get_parent()
|
||||
var player: Node = level.get_node_or_null("Player")
|
||||
if session != null and player != null:
|
||||
var character: CharacterData = player.get("character_data") as CharacterData
|
||||
if character != null:
|
||||
session.begin_level(_next_level_path, character)
|
||||
_change_scene(_next_level_path)
|
||||
|
||||
|
||||
func _change_scene(path: String) -> void:
|
||||
if _leaving:
|
||||
return
|
||||
_leaving = true
|
||||
# Tambien es seguro si se solicita desde el callback de un area de fisica.
|
||||
call_deferred("_change_scene")
|
||||
get_tree().paused = false
|
||||
_release_virtual_actions()
|
||||
call_deferred("_change_scene_deferred", path)
|
||||
|
||||
|
||||
func _change_scene() -> void:
|
||||
var error: Error = get_tree().change_scene_to_file(MENU_PATH)
|
||||
func _change_scene_deferred(path: String) -> void:
|
||||
var error: Error = get_tree().change_scene_to_file(path)
|
||||
if error != OK:
|
||||
_leaving = false
|
||||
push_error("No se pudo volver al menu: " + error_string(error))
|
||||
push_error("No se pudo cambiar de escena: " + error_string(error))
|
||||
get_tree().paused = true
|
||||
_update_screen()
|
||||
|
||||
|
||||
## Alias util para escenas existentes y pruebas antiguas: ahora confirma antes de salir.
|
||||
func return_to_menu() -> void:
|
||||
_select_title()
|
||||
|
||||
|
||||
func _release_virtual_actions() -> void:
|
||||
for action: StringName in [&"move_left", &"move_right", &"jump", &"attack", &"ground_pound", &"special_attack"]:
|
||||
Input.action_release(action)
|
||||
|
||||
|
||||
func _refresh_pending() -> void:
|
||||
var level: Node = get_parent()
|
||||
var count: int = int(level.call("get_pending_rare_count")) if level.has_method("get_pending_rare_count") else 0
|
||||
$Overlay/Pending.text = "RAROS PENDIENTES: %d\nCompleta el nivel para guardarlos" % count
|
||||
$Overlay/Pending.visible = count > 0
|
||||
$Overlay/Pending.visible = count > 0 and _screen == Screen.PLAYING
|
||||
|
||||
|
||||
func _show_notice(message: String) -> void:
|
||||
$Overlay/Notice.text = message
|
||||
$Overlay/Notice.show()
|
||||
_notice_seconds = 8.0
|
||||
$Overlay/Notice.visible = _screen == Screen.PLAYING
|
||||
|
||||
|
||||
func _process(delta: float) -> void:
|
||||
|
||||
@@ -1,10 +1,29 @@
|
||||
[gd_scene load_steps=4 format=3]
|
||||
[gd_scene load_steps=5 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://ui/menu/level_navigation.gd" id="script"]
|
||||
[ext_resource type="Script" path="res://ui/editor_ui_visibility.gd" id="editor_ui_visibility"]
|
||||
[ext_resource type="Theme" path="res://ui/menu/menu_theme.tres" id="theme"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="ResultPanel"]
|
||||
content_margin_left = 0.0
|
||||
content_margin_top = 0.0
|
||||
content_margin_right = 0.0
|
||||
content_margin_bottom = 0.0
|
||||
bg_color = Color(0.095, 0.115, 0.145, 0.98)
|
||||
border_width_left = 3
|
||||
border_width_top = 3
|
||||
border_width_right = 3
|
||||
border_width_bottom = 3
|
||||
border_color = Color(0.56, 0.67, 0.49, 1)
|
||||
corner_radius_top_left = 12
|
||||
corner_radius_top_right = 12
|
||||
corner_radius_bottom_left = 12
|
||||
corner_radius_bottom_right = 12
|
||||
shadow_color = Color(0, 0, 0, 0.55)
|
||||
shadow_size = 12
|
||||
|
||||
[node name="LevelNavigation" type="CanvasLayer"]
|
||||
process_mode = 3
|
||||
layer = 110
|
||||
script = ExtResource("script")
|
||||
|
||||
@@ -19,7 +38,8 @@ anchor_bottom = 1.0
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("theme")
|
||||
|
||||
[node name="Menu" type="Button" parent="Overlay"]
|
||||
[node name="Pause" type="Button" parent="Overlay"]
|
||||
custom_minimum_size = Vector2(148, 60)
|
||||
layout_mode = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
@@ -28,9 +48,7 @@ offset_top = 16.0
|
||||
offset_right = -16.0
|
||||
offset_bottom = 76.0
|
||||
grow_horizontal = 0
|
||||
focus_mode = 0
|
||||
text = "MENU"
|
||||
|
||||
text = "II PAUSA"
|
||||
|
||||
[node name="Pending" type="Label" parent="Overlay"]
|
||||
visible = false
|
||||
@@ -68,3 +86,97 @@ theme_override_constants/shadow_offset_y = 2
|
||||
theme_override_font_sizes/font_size = 20
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="Scrim" type="ColorRect" parent="Overlay"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
mouse_filter = 0
|
||||
color = Color(0.015, 0.02, 0.028, 0.85)
|
||||
|
||||
[node name="Dialog" type="CenterContainer" parent="Overlay"]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 20.0
|
||||
offset_top = 12.0
|
||||
offset_right = -20.0
|
||||
offset_bottom = -12.0
|
||||
mouse_filter = 2
|
||||
|
||||
[node name="Panel" type="PanelContainer" parent="Overlay/Dialog"]
|
||||
custom_minimum_size = Vector2(540, 0)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 4
|
||||
theme_override_styles/panel = SubResource("ResultPanel")
|
||||
|
||||
[node name="Margin" type="MarginContainer" parent="Overlay/Dialog/Panel"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/margin_left = 28
|
||||
theme_override_constants/margin_top = 24
|
||||
theme_override_constants/margin_right = 28
|
||||
theme_override_constants/margin_bottom = 24
|
||||
|
||||
[node name="Options" type="VBoxContainer" parent="Overlay/Dialog/Panel/Margin"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 10
|
||||
|
||||
[node name="Heading" type="Label" parent="Overlay/Dialog/Panel/Margin/Options"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 34
|
||||
theme_override_colors/font_color = Color(0.9, 0.96, 0.61, 1)
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 3
|
||||
text = "PAUSA"
|
||||
|
||||
[node name="Description" type="Label" parent="Overlay/Dialog/Panel/Margin/Options"]
|
||||
layout_mode = 2
|
||||
custom_minimum_size = Vector2(0, 70)
|
||||
theme_override_font_sizes/font_size = 17
|
||||
horizontal_alignment = 1
|
||||
vertical_alignment = 1
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="Resume" type="Button" parent="Overlay/Dialog/Panel/Margin/Options"]
|
||||
custom_minimum_size = Vector2(0, 58)
|
||||
layout_mode = 2
|
||||
text = "REANUDAR"
|
||||
|
||||
[node name="Restart" type="Button" parent="Overlay/Dialog/Panel/Margin/Options"]
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(0, 58)
|
||||
layout_mode = 2
|
||||
text = "REINICIAR NIVEL"
|
||||
|
||||
[node name="Next" type="Button" parent="Overlay/Dialog/Panel/Margin/Options"]
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(0, 58)
|
||||
layout_mode = 2
|
||||
text = "SIGUIENTE NIVEL"
|
||||
|
||||
[node name="Levels" type="Button" parent="Overlay/Dialog/Panel/Margin/Options"]
|
||||
custom_minimum_size = Vector2(0, 58)
|
||||
layout_mode = 2
|
||||
text = "SELECTOR DE NIVELES"
|
||||
|
||||
[node name="Title" type="Button" parent="Overlay/Dialog/Panel/Margin/Options"]
|
||||
custom_minimum_size = Vector2(0, 58)
|
||||
layout_mode = 2
|
||||
text = "TITULO PRINCIPAL"
|
||||
|
||||
[node name="Confirm" type="Button" parent="Overlay/Dialog/Panel/Margin/Options"]
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(0, 58)
|
||||
layout_mode = 2
|
||||
text = "SI, ABANDONAR"
|
||||
|
||||
[node name="Cancel" type="Button" parent="Overlay/Dialog/Panel/Margin/Options"]
|
||||
visible = false
|
||||
custom_minimum_size = Vector2(0, 58)
|
||||
layout_mode = 2
|
||||
text = "CANCELAR"
|
||||
@@ -28,6 +28,7 @@ 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
|
||||
var open_levels: bool = session != null and session.show_levels_on_menu_entry
|
||||
if session != null:
|
||||
session.clear()
|
||||
characters_panel.connect("back_requested", _show_levels)
|
||||
@@ -39,7 +40,10 @@ func _ready() -> void:
|
||||
quit_button.pressed.connect(_quit_game)
|
||||
# En web no se puede cerrar la pestana desde el juego.
|
||||
quit_button.visible = not OS.has_feature("web")
|
||||
_show_home()
|
||||
if open_levels:
|
||||
_show_levels()
|
||||
else:
|
||||
_show_home()
|
||||
|
||||
|
||||
## ResourceLoader conserva los nombres originales tambien dentro del paquete exportado.
|
||||
|
||||
Reference in new issue
Block a user