170 lines
5.6 KiB
GDScript3
170 lines
5.6 KiB
GDScript3
|
|
extends Control
|
||
|
|
|
||
|
|
@onready var login_popup = $Window
|
||
|
|
@onready var email_input = $Window/VBoxContainer/EmailInput
|
||
|
|
@onready var password_input = $Window/VBoxContainer/PasswordInput
|
||
|
|
|
||
|
|
@onready var menu_button: MenuButton = $MarginContainer/VBoxContainer/MenuButton
|
||
|
|
@onready var seleccionados_container: FlowContainer = $MarginContainer/VBoxContainer/FlowContainer
|
||
|
|
@onready var warning_label: Label = $MarginContainer/VBoxContainer/FlowContainer/WarningLabel
|
||
|
|
@onready var seconds_input: LineEdit = $MarginContainer/VBoxContainer/Seconds
|
||
|
|
|
||
|
|
@onready var button_2_directions = $MarginContainer/VBoxContainer/HBoxContainer/Button2Directions
|
||
|
|
@onready var button_4_directions = $MarginContainer/VBoxContainer/HBoxContainer/Button4Directions
|
||
|
|
@onready var button_8_directions = $MarginContainer/VBoxContainer/HBoxContainer/Button8Directions
|
||
|
|
|
||
|
|
@onready var repeats_per_direction_input = $MarginContainer/VBoxContainer/RepeatsPerDirection
|
||
|
|
|
||
|
|
@onready var bg_color_picker: ColorPickerButton = $MarginContainer/VBoxContainer/BackgroundColorPickerButton
|
||
|
|
@onready var arrow_color_picker: ColorPickerButton = $MarginContainer/VBoxContainer/ArrowColorPickerButton
|
||
|
|
|
||
|
|
var todos_los_jugadores = []
|
||
|
|
var jugadores_disponibles = []
|
||
|
|
var jugadores_seleccionados = []
|
||
|
|
|
||
|
|
var directions = 0
|
||
|
|
var level = -1
|
||
|
|
|
||
|
|
func _ready():
|
||
|
|
RenderingServer.set_default_clear_color("#CCCCCC")
|
||
|
|
|
||
|
|
await get_tree().process_frame # Esperar a que todo esté listo
|
||
|
|
|
||
|
|
if GameData.id_user == -1:
|
||
|
|
login_popup.show()
|
||
|
|
$Blocker.visible = true
|
||
|
|
|
||
|
|
todos_los_jugadores = await GameData.get_residents_loaded()
|
||
|
|
jugadores_disponibles = todos_los_jugadores.duplicate()
|
||
|
|
_actualizar_menu()
|
||
|
|
|
||
|
|
# Conectar señal de selección
|
||
|
|
menu_button.get_popup().connect("id_pressed", Callable(self, "_on_jugador_seleccionado"))
|
||
|
|
|
||
|
|
button_2_directions.pressed.connect(Callable(self, "_on_directions_pressed").bind(button_2_directions))
|
||
|
|
button_4_directions.pressed.connect(Callable(self, "_on_directions_pressed").bind(button_4_directions))
|
||
|
|
button_8_directions.pressed.connect(Callable(self, "_on_directions_pressed").bind(button_8_directions))
|
||
|
|
|
||
|
|
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()
|
||
|
|
$Blocker.visible = false
|
||
|
|
break
|
||
|
|
|
||
|
|
if GameData.id_user == -1:
|
||
|
|
email_input.clear()
|
||
|
|
password_input.clear()
|
||
|
|
|
||
|
|
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)
|
||
|
|
|
||
|
|
func _actualizar_menu():
|
||
|
|
var popup = menu_button.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)
|
||
|
|
|
||
|
|
if warning_label.visible:
|
||
|
|
warning_label.visible = false
|
||
|
|
|
||
|
|
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()
|
||
|
|
|
||
|
|
if jugadores_seleccionados.is_empty():
|
||
|
|
warning_label.visible = true
|
||
|
|
|
||
|
|
|
||
|
|
func _on_directions_pressed(button : Button):
|
||
|
|
# Desmarcar todos los botones
|
||
|
|
button_2_directions.button_pressed = false
|
||
|
|
button_4_directions.button_pressed = false
|
||
|
|
button_8_directions.button_pressed = false
|
||
|
|
|
||
|
|
# Marcar el botón seleccionado
|
||
|
|
button.button_pressed = true
|
||
|
|
|
||
|
|
# Actualizar el valor de directions
|
||
|
|
match button:
|
||
|
|
button_2_directions:
|
||
|
|
directions = 2
|
||
|
|
level = 0
|
||
|
|
button_4_directions:
|
||
|
|
directions = 4
|
||
|
|
level = 1
|
||
|
|
button_8_directions:
|
||
|
|
directions = 8
|
||
|
|
level = 2
|
||
|
|
|
||
|
|
func _on_play_button_pressed():
|
||
|
|
for child in $Warning/Panel.get_children():
|
||
|
|
$Warning/Panel.remove_child(child)
|
||
|
|
child.queue_free()
|
||
|
|
|
||
|
|
var warning_text = Label.new()
|
||
|
|
warning_text.text = ""
|
||
|
|
if jugadores_seleccionados.is_empty() :
|
||
|
|
warning_text.text = " - Debe seleccionar al menos un jugador\n"
|
||
|
|
if seconds_input.text.is_empty():
|
||
|
|
warning_text.text += " - Debe insertar un numero de segundos\n"
|
||
|
|
if directions == 0:
|
||
|
|
warning_text.text += " - Debe selecionar las direcciones\n"
|
||
|
|
if repeats_per_direction_input.text.is_empty():
|
||
|
|
warning_text.text += " - Debe insertar numero de obejtos por direccion"
|
||
|
|
|
||
|
|
if warning_text.text != "":
|
||
|
|
$Warning/Panel.add_child(warning_text)
|
||
|
|
$Warning.popup_centered(Vector2(500, 200))
|
||
|
|
return
|
||
|
|
|
||
|
|
var game_scene = preload("res://scenes/game.tscn").instantiate()
|
||
|
|
|
||
|
|
game_scene.bg_color = bg_color_picker.color
|
||
|
|
game_scene.arrow_color = arrow_color_picker.color
|
||
|
|
|
||
|
|
game_scene.interval = int(seconds_input.text)
|
||
|
|
game_scene.direction_count = directions
|
||
|
|
game_scene.max_repeats_per_direction = repeats_per_direction_input.text
|
||
|
|
game_scene.selected_players = jugadores_seleccionados
|
||
|
|
|
||
|
|
for jugador in jugadores_seleccionados:
|
||
|
|
GameData.start_game(int(jugador.id), level)
|
||
|
|
|
||
|
|
ScreenManager.change_scene(game_scene, self)
|