aboutsummaryrefslogtreecommitdiff
path: root/client
diff options
context:
space:
mode:
authornokoe <nokoe@mailbox.org>2024-07-08 14:24:34 +0200
committernokoe <nokoe@mailbox.org>2024-07-08 14:24:34 +0200
commit535db64a8fc2ed95393eb5ca7facedcf179b8f63 (patch)
tree33860ace7c4f90b69de58f0d91cd522944b43bea /client
parent3eb17b6d3e5a95e997d1dfd38eaac56cbf169177 (diff)
downloadhurrycurry-535db64a8fc2ed95393eb5ca7facedcf179b8f63.tar
hurrycurry-535db64a8fc2ed95393eb5ca7facedcf179b8f63.tar.bz2
hurrycurry-535db64a8fc2ed95393eb5ca7facedcf179b8f63.tar.zst
add join button
Diffstat (limited to 'client')
-rw-r--r--client/game.gd8
-rw-r--r--client/menu/lobby.gd25
-rw-r--r--client/menu/lobby.tscn3
3 files changed, 28 insertions, 8 deletions
diff --git a/client/game.gd b/client/game.gd
index ac0fff9e..397a2b73 100644
--- a/client/game.gd
+++ b/client/game.gd
@@ -21,6 +21,7 @@ extends Node3D
signal update_players(players: Dictionary)
signal data_updated()
signal player_set_input_enabled(b: bool)
+signal joined()
var player_id: int = -1
var item_names: Array = []
@@ -89,6 +90,7 @@ func _ready():
player_instance = ControllablePlayer.new(player, player_name, pos, character, self)
camera.target = player_instance
player_set_input_enabled.connect(player_instance.set_input_enabled)
+ joined.emit()
else:
player_instance = Player.new(player, player_name, pos, character, self)
players[player] = player_instance
@@ -207,9 +209,6 @@ func _ready():
p.clear_message()
)
-
- mp.send_join(Global.profile["username"], Global.profile["character"])
-
mp.set_ingame.connect(func (state, in_lobby_):
in_lobby = in_lobby_
if state:
@@ -235,6 +234,9 @@ func _ready():
lobby.visible = lobby_state
)
+func join():
+ mp.send_join(Global.profile["username"], Global.profile["character"])
+
func _process(delta):
marker.position = Global.interpolate(marker.position, marker_target, delta * 30.)
diff --git a/client/menu/lobby.gd b/client/menu/lobby.gd
index 976cefb6..a905e670 100644
--- a/client/menu/lobby.gd
+++ b/client/menu/lobby.gd
@@ -1,5 +1,6 @@
# Undercooked - 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
@@ -19,19 +20,24 @@ const PLAYER = preload("res://menu/lobby/player.tscn")
var selected_map := 0
var selected_map_name: String
+var joined := false
+var join_sent := false
@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)
func initialize():
map_count = game.map_names.size()
@@ -48,7 +54,7 @@ func select_map(i: int):
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)
@@ -57,12 +63,18 @@ func update_players(player_list: Dictionary):
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
+ joined = true
+
func _on_left_pressed():
selected_map = (selected_map - 1) % map_count
select_map(selected_map)
@@ -72,5 +84,10 @@ func _on_right_pressed():
select_map(selected_map)
func _on_controller_button_pressed():
- if selected_map_name != null:
- game.mp.send_chat("/start %s" % selected_map_name)
+ if joined:
+ if selected_map_name != null:
+ game.mp.send_chat("/start %s" % selected_map_name)
+ elif not join_sent:
+ join_sent = true
+ start_button.disabled = true
+ game.join()
diff --git a/client/menu/lobby.tscn b/client/menu/lobby.tscn
index df58915c..8510b995 100644
--- a/client/menu/lobby.tscn
+++ b/client/menu/lobby.tscn
@@ -60,6 +60,7 @@ layout_mode = 2
theme_override_constants/separation = 24
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Bottom/MarginContainer/VBoxContainer"]
+visible = false
layout_mode = 2
alignment = 1
@@ -99,7 +100,7 @@ layout_mode = 2
[node name="ControllerButton" parent="VBoxContainer/Bottom/MarginContainer/VBoxContainer/CenterContainer" instance=ExtResource("7_t6mox")]
custom_minimum_size = Vector2(148, 0)
layout_mode = 2
-text = "Start Game"
+text = "Join Game"
expand_icon = true
controller_texture = ExtResource("9_q14bw")
press_action = "start_game"