# Hurry Curry! - a game about cooking # Copyright 2024 tpart # Copyright 2024 nokoe # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as published by # the Free Software Foundation, version 3 of the License only. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU Affero General Public License for more details. # # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # extends Control class_name Lobby const PLAYER = preload("res://menu/lobby/player.tscn") var map_count var selected_map := 0 var selected_map_name: String var difficulty_names = [tr("Easy"), tr("Moderate"), tr("Hard"), tr("Very hard"), tr("Unplayable")] @onready var game: Game = $"../Game" @onready var player_container = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/Players @onready var map_name_label = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/Map/Name @onready var map_player_label = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/Map/Players @onready var map_difficulty_label = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/Map/Difficulty @onready var map_list = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/MapList/VBoxContainer @onready var map_selector = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer @onready var prev_map = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer/Left @onready var next_map = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/VBoxContainer2/Right @onready var join_spectate = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/VBoxContainer/JoinSpectate @onready var start_button = $HBoxContainer/Bottom/MarginContainer/VBoxContainer/VBoxContainer/Start func _ready(): game.update_players.connect(update_players) initialize() game.data_updated.connect(initialize) game.joined.connect(_on_game_joined) game.left.connect(_on_game_left) check_for_music() func initialize(): map_count = game.maps.size() for c in map_list.get_children(): c.queue_free() var i := 0 for m in game.maps.keys(): var b = Button.new() b.name = m b.text = "%s (%d)" % [game.maps[m]["name"], game.maps[m]["players"]] b.pressed.connect(select_map.bind(i)) b.focus_entered.connect(select_map.bind(i)) map_list.add_child(b) i += 1 select_map(0) func select_map(i: int): if i >= map_count: return selected_map = i var k = game.maps.keys()[i] var map_data: Dictionary = game.maps[k] map_name_label.text = map_data["name"] map_player_label.text = tr("%d players recommended") % map_data["players"] map_difficulty_label.text = difficulty_names[map_data["difficulty"] - 1] selected_map_name = k map_list.get_child(i).grab_focus() func update_players(player_list: Dictionary): for i in player_container.get_children(): i.queue_free() for i in player_list.keys(): var p: PlayerTag = PLAYER.instantiate() player_container.add_child(p) p.setup(player_list[i].username) func _input(_event): if not visible: return if Input.is_action_just_pressed("previous") and not prev_map.disabled: prev_map.emit_signal("pressed") elif Input.is_action_just_pressed("next") and not next_map.disabled: next_map.emit_signal("pressed") func _on_game_joined(): map_selector.show() start_button.disabled = false func _on_game_left(): map_selector.hide() start_button.disabled = true func _on_left_pressed(): selected_map = (selected_map - 1) % map_count select_map(selected_map) func _on_right_pressed(): selected_map = (selected_map + 1) % map_count select_map(selected_map) func _on_controller_button_pressed(): if selected_map_name != null: game.mp.send_chat(game.player_id, "/start %s" % selected_map_name) Sound.play_music("stop") # TODO: Game music enter func _on_join_spectate_pressed(): if game.is_joined: game.leave() join_spectate.text = tr("Join game") elif not game.join_sent: game.join() join_spectate.text = tr("Spectate") func check_for_music(): if visible: Sound.play_music("Lobby") else: Sound.play_music("stop") # TODO: Game music enter