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,36 @@
|
||||
extends CanvasLayer
|
||||
|
||||
## Salida minima de los escenarios de prueba. No es un menu de pausa ni guardado.
|
||||
## Se usa una escena compartida para que el boton se pueda editar visualmente.
|
||||
const MENU_PATH: String = "res://ui/menu/main_menu.tscn"
|
||||
var _leaving: bool = false
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
$Overlay/Menu.pressed.connect(return_to_menu)
|
||||
|
||||
|
||||
func _unhandled_input(event: InputEvent) -> void:
|
||||
if event.is_action_pressed("ui_cancel"):
|
||||
return_to_menu()
|
||||
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()
|
||||
|
||||
|
||||
func return_to_menu() -> void:
|
||||
if _leaving:
|
||||
return
|
||||
_leaving = true
|
||||
# Tambien es seguro si se solicita desde el callback de un area de fisica.
|
||||
call_deferred("_change_scene")
|
||||
|
||||
|
||||
func _change_scene() -> void:
|
||||
var error: Error = get_tree().change_scene_to_file(MENU_PATH)
|
||||
if error != OK:
|
||||
_leaving = false
|
||||
push_error("No se pudo volver al menu: " + error_string(error))
|
||||
@@ -0,0 +1,32 @@
|
||||
[gd_scene load_steps=4 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"]
|
||||
|
||||
[node name="LevelNavigation" type="CanvasLayer"]
|
||||
layer = 110
|
||||
script = ExtResource("script")
|
||||
|
||||
[node name="EditorVisibility" type="Node" parent="."]
|
||||
script = ExtResource("editor_ui_visibility")
|
||||
|
||||
[node name="Overlay" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
mouse_filter = 2
|
||||
theme = ExtResource("theme")
|
||||
|
||||
[node name="Menu" type="Button" parent="Overlay"]
|
||||
layout_mode = 1
|
||||
anchor_left = 1.0
|
||||
anchor_right = 1.0
|
||||
offset_left = -164.0
|
||||
offset_top = 16.0
|
||||
offset_right = -16.0
|
||||
offset_bottom = 76.0
|
||||
grow_horizontal = 0
|
||||
focus_mode = 0
|
||||
text = "MENU"
|
||||
@@ -0,0 +1,159 @@
|
||||
extends Control
|
||||
|
||||
## Menu provisional sin seleccion de personaje, progreso ni lista manual de niveles.
|
||||
## Solo descubre escenas directamente dentro de levels, nunca sus subcarpetas.
|
||||
const LEVEL_DIRECTORY: String = "res://levels"
|
||||
|
||||
@onready var title_label: Label = $Margin/Layout/Title
|
||||
@onready var home_panel: VBoxContainer = $Margin/Layout/Home
|
||||
@onready var levels_panel: VBoxContainer = $Margin/Layout/Levels
|
||||
@onready var level_list: VBoxContainer = $Margin/Layout/Levels/Scroll/LevelList
|
||||
@onready var empty_label: Label = $Margin/Layout/Levels/Empty
|
||||
@onready var play_button: Button = $Margin/Layout/Home/Play
|
||||
@onready var quit_button: Button = $Margin/Layout/Home/Quit
|
||||
@onready var back_button: Button = $Margin/Layout/Levels/Back
|
||||
@onready var error_label: Label = $Margin/Layout/Error
|
||||
@onready var loading_panel: ColorRect = $Loading
|
||||
@onready var loading_label: Label = $Loading/Content/Status
|
||||
@onready var loading_progress: ProgressBar = $Loading/Content/Progress
|
||||
|
||||
var _loading_path: String = ""
|
||||
|
||||
|
||||
func _ready() -> void:
|
||||
set_process(false)
|
||||
play_button.pressed.connect(_show_levels)
|
||||
back_button.pressed.connect(_show_home)
|
||||
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()
|
||||
|
||||
|
||||
## ResourceLoader conserva los nombres originales tambien dentro del paquete exportado.
|
||||
## El filtro no es recursivo y ordenar evita diferencias entre plataformas.
|
||||
static func discover_level_paths() -> PackedStringArray:
|
||||
var paths: Array[String] = []
|
||||
for entry: String in ResourceLoader.list_directory(LEVEL_DIRECTORY):
|
||||
if entry.ends_with("/") or entry.get_extension().to_lower() not in ["tscn", "scn"]:
|
||||
continue
|
||||
paths.append(LEVEL_DIRECTORY.path_join(entry))
|
||||
paths.sort_custom(func(a: String, b: String) -> bool: return a.naturalnocasecmp_to(b) < 0)
|
||||
return PackedStringArray(paths)
|
||||
|
||||
|
||||
static func level_label(path: String) -> String:
|
||||
var filename: String = path.get_file().get_basename()
|
||||
if filename == "level_00":
|
||||
return "NIVEL 00 - BETA / PRUEBAS"
|
||||
if filename == "level_01":
|
||||
return "NIVEL 01 - PASAJES DEL FEEDBACK"
|
||||
return filename.replace("level_", "nivel_").replace("_", " ").to_upper()
|
||||
|
||||
|
||||
func _show_home() -> void:
|
||||
if not _loading_path.is_empty():
|
||||
return
|
||||
home_panel.show()
|
||||
levels_panel.hide()
|
||||
loading_panel.hide()
|
||||
error_label.hide()
|
||||
title_label.text = "INICIO"
|
||||
play_button.grab_focus()
|
||||
|
||||
|
||||
## Reconstruye al abrir el submenu; no carga ni instancia los niveles para enumerarlos.
|
||||
func _show_levels() -> void:
|
||||
if not _loading_path.is_empty():
|
||||
return
|
||||
for child: Node in level_list.get_children():
|
||||
level_list.remove_child(child)
|
||||
child.queue_free()
|
||||
var paths: PackedStringArray = discover_level_paths()
|
||||
for path: String in paths:
|
||||
var button := Button.new()
|
||||
button.text = level_label(path)
|
||||
button.tooltip_text = path.get_file()
|
||||
button.custom_minimum_size.y = 64.0
|
||||
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))
|
||||
level_list.add_child(button)
|
||||
empty_label.visible = paths.is_empty()
|
||||
home_panel.hide()
|
||||
levels_panel.show()
|
||||
error_label.hide()
|
||||
title_label.text = "ELEGIR NIVEL"
|
||||
if level_list.get_child_count() > 0:
|
||||
(level_list.get_child(0) as Button).grab_focus()
|
||||
else:
|
||||
back_button.grab_focus()
|
||||
|
||||
|
||||
## La pantalla de carga real no introduce otros diez segundos artificiales.
|
||||
func _load_level(path: String) -> void:
|
||||
if not _loading_path.is_empty():
|
||||
return
|
||||
if not ResourceLoader.exists(path, "PackedScene"):
|
||||
_show_load_error("No se encuentra el nivel: " + path.get_file())
|
||||
return
|
||||
var error: Error = ResourceLoader.load_threaded_request(path, "PackedScene")
|
||||
if error != OK:
|
||||
_show_load_error("No se pudo iniciar la carga: " + error_string(error))
|
||||
return
|
||||
_loading_path = path
|
||||
# Ocultar el panel tambien evita activaciones por teclado mientras se carga.
|
||||
levels_panel.hide()
|
||||
loading_panel.show()
|
||||
loading_label.text = "Cargando " + level_label(path).to_lower() + "..."
|
||||
loading_progress.value = 0.0
|
||||
set_process(true)
|
||||
|
||||
|
||||
func _process(_delta: float) -> void:
|
||||
if _loading_path.is_empty():
|
||||
return
|
||||
var progress: Array = []
|
||||
var status: ResourceLoader.ThreadLoadStatus = ResourceLoader.load_threaded_get_status(_loading_path, progress)
|
||||
if not progress.is_empty():
|
||||
loading_progress.value = float(progress[0]) * 100.0
|
||||
match status:
|
||||
ResourceLoader.THREAD_LOAD_LOADED:
|
||||
var level: PackedScene = ResourceLoader.load_threaded_get(_loading_path) as PackedScene
|
||||
if level == null:
|
||||
_show_load_error("El recurso no es una escena de nivel.")
|
||||
return
|
||||
set_process(false)
|
||||
var error: Error = get_tree().change_scene_to_packed(level)
|
||||
if error != OK:
|
||||
_show_load_error("No se pudo abrir el nivel: " + error_string(error))
|
||||
ResourceLoader.THREAD_LOAD_FAILED, ResourceLoader.THREAD_LOAD_INVALID_RESOURCE:
|
||||
_show_load_error("Fallo al cargar " + _loading_path.get_file())
|
||||
|
||||
|
||||
func _show_load_error(message: String) -> void:
|
||||
_loading_path = ""
|
||||
set_process(false)
|
||||
loading_panel.hide()
|
||||
_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:
|
||||
_show_home()
|
||||
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:
|
||||
_show_home()
|
||||
else:
|
||||
_quit_game()
|
||||
|
||||
|
||||
func _quit_game() -> void:
|
||||
get_tree().quit()
|
||||
@@ -0,0 +1,131 @@
|
||||
[gd_scene load_steps=3 format=3]
|
||||
|
||||
[ext_resource type="Script" path="res://ui/menu/main_menu.gd" id="script"]
|
||||
[ext_resource type="Theme" path="res://ui/menu/menu_theme.tres" id="theme"]
|
||||
|
||||
[node name="MainMenu" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
theme = ExtResource("theme")
|
||||
script = ExtResource("script")
|
||||
|
||||
[node name="Background" type="ColorRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
mouse_filter = 2
|
||||
color = Color(0.035, 0.045, 0.055, 1)
|
||||
|
||||
[node name="Margin" type="MarginContainer" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
theme_override_constants/margin_left = 32
|
||||
theme_override_constants/margin_top = 24
|
||||
theme_override_constants/margin_right = 32
|
||||
theme_override_constants/margin_bottom = 24
|
||||
|
||||
[node name="Layout" type="VBoxContainer" parent="Margin"]
|
||||
layout_mode = 2
|
||||
theme_override_constants/separation = 16
|
||||
|
||||
[node name="Title" type="Label" parent="Margin/Layout"]
|
||||
layout_mode = 2
|
||||
theme_override_font_sizes/font_size = 30
|
||||
text = "INICIO"
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Home" type="VBoxContainer" parent="Margin/Layout"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/separation = 18
|
||||
alignment = 1
|
||||
|
||||
[node name="Hint" type="Label" parent="Margin/Layout/Home"]
|
||||
layout_mode = 2
|
||||
text = "Elige un escenario y entra a probar."
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="Play" type="Button" parent="Margin/Layout/Home"]
|
||||
custom_minimum_size = Vector2(0, 64)
|
||||
layout_mode = 2
|
||||
text = "JUGAR"
|
||||
|
||||
[node name="Quit" type="Button" parent="Margin/Layout/Home"]
|
||||
custom_minimum_size = Vector2(0, 64)
|
||||
layout_mode = 2
|
||||
text = "SALIR"
|
||||
|
||||
[node name="Levels" type="VBoxContainer" parent="Margin/Layout"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/separation = 16
|
||||
|
||||
[node name="Scroll" type="ScrollContainer" parent="Margin/Layout/Levels"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
follow_focus = true
|
||||
horizontal_scroll_mode = 0
|
||||
|
||||
[node name="LevelList" type="VBoxContainer" parent="Margin/Layout/Levels/Scroll"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
theme_override_constants/separation = 14
|
||||
|
||||
[node name="Empty" type="Label" parent="Margin/Layout/Levels"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
text = "No hay escenas en la raiz de levels."
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="Back" type="Button" parent="Margin/Layout/Levels"]
|
||||
custom_minimum_size = Vector2(0, 64)
|
||||
layout_mode = 2
|
||||
text = "VOLVER"
|
||||
|
||||
[node name="Error" type="Label" parent="Margin/Layout"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(1, 0.65, 0.48, 1)
|
||||
autowrap_mode = 3
|
||||
horizontal_alignment = 1
|
||||
|
||||
[node name="Loading" type="ColorRect" parent="."]
|
||||
visible = false
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
color = Color(0.035, 0.045, 0.055, 1)
|
||||
|
||||
[node name="Content" type="VBoxContainer" parent="Loading"]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
offset_left = 32.0
|
||||
offset_top = 24.0
|
||||
offset_right = -32.0
|
||||
offset_bottom = -24.0
|
||||
theme_override_constants/separation = 24
|
||||
alignment = 1
|
||||
|
||||
[node name="Status" type="Label" parent="Loading/Content"]
|
||||
layout_mode = 2
|
||||
text = "Cargando nivel..."
|
||||
horizontal_alignment = 1
|
||||
autowrap_mode = 3
|
||||
|
||||
[node name="Progress" type="ProgressBar" parent="Loading/Content"]
|
||||
custom_minimum_size = Vector2(0, 24)
|
||||
layout_mode = 2
|
||||
show_percentage = false
|
||||
@@ -0,0 +1,63 @@
|
||||
[gd_resource type="Theme" load_steps=6 format=3]
|
||||
|
||||
[ext_resource type="FontFile" path="res://assets/fonts/PixelOperator8.ttf" id="font"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="Normal"]
|
||||
content_margin_left = 22.0
|
||||
content_margin_top = 16.0
|
||||
content_margin_right = 22.0
|
||||
content_margin_bottom = 16.0
|
||||
bg_color = Color(0.12, 0.15, 0.18, 1)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.35, 0.4, 0.43, 1)
|
||||
corner_radius_top_left = 4
|
||||
corner_radius_top_right = 4
|
||||
corner_radius_bottom_left = 4
|
||||
corner_radius_bottom_right = 4
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="Hover"]
|
||||
content_margin_left = 22.0
|
||||
content_margin_top = 16.0
|
||||
content_margin_right = 22.0
|
||||
content_margin_bottom = 16.0
|
||||
bg_color = Color(0.20, 0.25, 0.26, 1)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.7, 0.83, 0.32, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="Pressed"]
|
||||
content_margin_left = 22.0
|
||||
content_margin_top = 16.0
|
||||
content_margin_right = 22.0
|
||||
content_margin_bottom = 16.0
|
||||
bg_color = Color(0.25, 0.32, 0.15, 1)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.8, 0.94, 0.4, 1)
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="Focus"]
|
||||
bg_color = Color(0, 0, 0, 0)
|
||||
border_width_left = 2
|
||||
border_width_top = 2
|
||||
border_width_right = 2
|
||||
border_width_bottom = 2
|
||||
border_color = Color(0.85, 0.95, 0.55, 1)
|
||||
|
||||
[resource]
|
||||
default_font = ExtResource("font")
|
||||
default_font_size = 20
|
||||
Button/styles/normal = SubResource("Normal")
|
||||
Button/styles/hover = SubResource("Hover")
|
||||
Button/styles/pressed = SubResource("Pressed")
|
||||
Button/styles/focus = SubResource("Focus")
|
||||
Button/styles/disabled = SubResource("Normal")
|
||||
Button/colors/font_color = Color(0.94, 0.95, 0.90, 1)
|
||||
Button/colors/font_disabled_color = Color(0.48, 0.52, 0.54, 1)
|
||||
Label/colors/font_color = Color(0.88, 0.91, 0.88, 1)
|
||||
Reference in new issue
Block a user