diff options
Diffstat (limited to 'client/menu/lobby.gd')
| -rw-r--r-- | client/menu/lobby.gd | 76 | 
1 files changed, 76 insertions, 0 deletions
| diff --git a/client/menu/lobby.gd b/client/menu/lobby.gd new file mode 100644 index 00000000..e96e11c4 --- /dev/null +++ b/client/menu/lobby.gd @@ -0,0 +1,76 @@ +# Undercooked - a game about cooking +# Copyright 2024 tpart +# +# 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 <https://www.gnu.org/licenses/>. +# +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 prev_map = $VBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/Left +@onready var next_map = $VBoxContainer/Bottom/MarginContainer/VBoxContainer/HBoxContainer/Right + +func _ready(): +	game.update_players.connect(update_players) +	initialize() +	game.data_updated.connect(initialize) + +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].name) + +func _input(event): +	if not visible: +		return +	 +	if Input.is_action_just_pressed("previous"): +		prev_map.emit_signal("pressed") +	elif Input.is_action_just_pressed("next"): +		next_map.emit_signal("pressed") + +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("/start %s" % selected_map_name) | 
