# 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 const PLAYER = preload("res://menu/lobby/player.tscn") var selected_map := 0 var selected_map_name: String @onready var game: Game = $"../Game" @onready var map_count = game.map_names.size() @onready var player_container = $VBoxContainer/Top/MarginContainer/VBoxContainer/Players @onready var map_name_label = $VBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/MapSelection @onready var map_selector = $VBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer @onready var prev_map = $VBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/Left @onready var next_map = $VBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/Right @onready var start_button = $VBoxContainer/Bottom/MarginContainer/VBoxContainer/CenterContainer/ControllerButton 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) func initialize(): map_count = game.map_names.size() select_map(0) func select_map(i: int): if i >= game.map_names.size(): return selected_map = i var map_name: String = game.map_names[i] map_name_label.text = map_name selected_map_name = map_name 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.text = tr("Start Game") start_button.disabled = false func _on_game_left(): map_selector.hide() start_button.text = tr("Join Game") 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 game.is_joined: if selected_map_name != null: game.mp.send_chat("/start %s" % selected_map_name) elif not game.join_sent: start_button.disabled = true game.join()