2025-04-17 00:00:16 +00:00
|
|
|
extends Control
|
|
|
|
|
|
|
|
|
|
@onready var login_popup = $Window
|
|
|
|
|
@onready var email_input = $Window/VBoxContainer/EmailInput
|
|
|
|
|
@onready var password_input = $Window/VBoxContainer/PasswordInput
|
|
|
|
|
|
2025-04-26 20:13:48 +00:00
|
|
|
@onready var players_menu = $MarginContainer/VBoxContainer/MenuButton
|
|
|
|
|
@onready var seleccionados_container = $MarginContainer/VBoxContainer/FlowContainer
|
|
|
|
|
@onready var play_button = $MarginContainer/VBoxContainer/PlayButton
|
2025-04-17 00:00:16 +00:00
|
|
|
|
|
|
|
|
var todos_los_jugadores = []
|
|
|
|
|
var jugadores_disponibles = []
|
|
|
|
|
var jugadores_seleccionados = []
|
|
|
|
|
|
|
|
|
|
func _ready():
|
2025-04-26 20:13:48 +00:00
|
|
|
RenderingServer.set_default_clear_color("#CCCCCC")
|
|
|
|
|
|
2025-04-17 00:00:16 +00:00
|
|
|
await get_tree().process_frame # Esperar a que todo esté listo
|
|
|
|
|
if GameData.id_user == -1:
|
|
|
|
|
login_popup.show()
|
|
|
|
|
$Bloqueador.visible = true
|
|
|
|
|
|
|
|
|
|
todos_los_jugadores = await GameData.get_residents_loaded()
|
|
|
|
|
jugadores_disponibles = todos_los_jugadores.duplicate()
|
|
|
|
|
_actualizar_menu()
|
|
|
|
|
players_menu.get_popup().connect("id_pressed", Callable(self, "_on_jugador_seleccionado"))
|
|
|
|
|
|
|
|
|
|
func _on_log_in_button_pressed():
|
|
|
|
|
var users = await GameData.get_users_loaded()
|
|
|
|
|
var username = email_input.text.strip_edges()
|
|
|
|
|
var password = password_input.text.strip_edges()
|
|
|
|
|
|
|
|
|
|
for user in users:
|
|
|
|
|
if user.email == username:
|
|
|
|
|
GameData.id_user = int(user.id)
|
|
|
|
|
login_popup.hide()
|
|
|
|
|
$Bloqueador.visible = false
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
if GameData.id_user == -1:
|
|
|
|
|
email_input.clear()
|
|
|
|
|
password_input.clear()
|
|
|
|
|
|
2025-04-26 20:13:48 +00:00
|
|
|
var stylebox_email = email_input.get_theme_stylebox("normal") as StyleBoxFlat
|
|
|
|
|
var stylebox_password = password_input.get_theme_stylebox("normal") as StyleBoxFlat
|
|
|
|
|
if stylebox_email and stylebox_password:
|
|
|
|
|
stylebox_email.bg_color = Color(1, 0.8, 0.8)
|
|
|
|
|
stylebox_password.bg_color = Color(1, 0.8, 0.8)
|
2025-04-17 00:00:16 +00:00
|
|
|
|
|
|
|
|
func _actualizar_menu():
|
|
|
|
|
var popup = players_menu.get_popup()
|
|
|
|
|
popup.clear()
|
|
|
|
|
for i in jugadores_disponibles.size():
|
|
|
|
|
popup.add_item(jugadores_disponibles[i].nombre, i)
|
|
|
|
|
|
|
|
|
|
func _on_jugador_seleccionado(index: int):
|
|
|
|
|
var jugador = jugadores_disponibles[index]
|
|
|
|
|
jugadores_seleccionados.append(jugador)
|
|
|
|
|
jugadores_disponibles.erase(jugador)
|
|
|
|
|
_actualizar_menu()
|
|
|
|
|
_agregar_jugador_visual(jugador.nombre)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _agregar_jugador_visual(nombre: String):
|
|
|
|
|
var boton = Button.new()
|
|
|
|
|
boton.text = nombre + " ❌"
|
|
|
|
|
boton.name = nombre
|
|
|
|
|
boton.pressed.connect(Callable(self, "_quitar_jugador").bind(nombre))
|
|
|
|
|
seleccionados_container.add_child(boton)
|
|
|
|
|
|
|
|
|
|
func _quitar_jugador(nombre: String):
|
|
|
|
|
# Quitar de la vista
|
|
|
|
|
var boton = seleccionados_container.get_node(nombre)
|
|
|
|
|
if boton:
|
|
|
|
|
seleccionados_container.remove_child(boton)
|
|
|
|
|
boton.queue_free()
|
|
|
|
|
|
|
|
|
|
# Buscar el jugador por nombre
|
|
|
|
|
for jugador in jugadores_seleccionados:
|
|
|
|
|
if jugador.nombre == nombre:
|
|
|
|
|
jugadores_seleccionados.erase(jugador)
|
|
|
|
|
jugadores_disponibles.append(jugador)
|
|
|
|
|
break
|
|
|
|
|
|
|
|
|
|
jugadores_disponibles.sort_custom(func(a, b): return a.nombre < b.nombre)
|
|
|
|
|
_actualizar_menu()
|
|
|
|
|
|
|
|
|
|
func _on_play_button_pressed():
|
2025-04-26 20:13:48 +00:00
|
|
|
for child in $Warning/Panel.get_children():
|
|
|
|
|
child.queue_free()
|
|
|
|
|
|
|
|
|
|
var warning = Label.new()
|
|
|
|
|
warning.text = ""
|
|
|
|
|
warning.add_theme_color_override("font_color","#324f5e")
|
|
|
|
|
if jugadores_seleccionados.is_empty():
|
|
|
|
|
warning.text = " - Debes seleccionar un jugador"
|
|
|
|
|
|
|
|
|
|
if warning.text != "":
|
|
|
|
|
$Warning/Panel.add_child(warning)
|
|
|
|
|
$Warning.popup_centered(Vector2(400, 200))
|
|
|
|
|
return
|
|
|
|
|
|
|
|
|
|
|
2025-04-17 00:00:16 +00:00
|
|
|
var game_scene = preload("res://scenes/game.tscn").instantiate()
|
|
|
|
|
game_scene.jugadores_seleccionados = jugadores_seleccionados
|
|
|
|
|
|
|
|
|
|
for jugador in jugadores_seleccionados:
|
|
|
|
|
GameData.start_game(jugador.id, null)
|
|
|
|
|
ScreenManager.change_scene(game_scene, self)
|