diff options
-rw-r--r-- | client/game.gd | 10 | ||||
-rw-r--r-- | client/menu/ingame.gd | 23 | ||||
-rw-r--r-- | client/menu/ingame.tscn | 15 | ||||
-rw-r--r-- | client/menu/lobby.gd | 15 | ||||
-rw-r--r-- | client/multiplayer.gd | 5 |
5 files changed, 60 insertions, 8 deletions
diff --git a/client/game.gd b/client/game.gd index e760186b..4e0bfe52 100644 --- a/client/game.gd +++ b/client/game.gd @@ -22,6 +22,7 @@ signal update_players(players: Dictionary) signal data_updated() signal player_set_input_enabled(b: bool) signal joined() +signal left() var player_id: int = -1 var item_names: Array = [] @@ -32,6 +33,8 @@ var tile_collide: Array = [] var tile_interact: Array = [] var map_names: Array = [] var in_lobby := false +var is_joined := false +var join_sent := false var marker_target = Vector3(0,0,0) var players := {} @@ -90,6 +93,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) + is_joined = true joined.emit() else: player_instance = Player.new(player, player_name, pos, character, self) @@ -109,7 +113,10 @@ func _ready(): mp.remove_player.connect(func(id: int): var player: Player = players.get(id) if id == player_id: - camera.target = self + is_joined = false + join_sent = false + left.emit() + camera.target = $Center if player != null: if player.hand != null: player.hand.queue_free() @@ -235,6 +242,7 @@ func _ready(): ) func join(): + join_sent = true mp.send_join(Global.profile["username"], Global.profile["character"]) func _process(delta): diff --git a/client/menu/ingame.gd b/client/menu/ingame.gd index 659528aa..f8653411 100644 --- a/client/menu/ingame.gd +++ b/client/menu/ingame.gd @@ -20,11 +20,14 @@ extends Menu @onready var options = $Side/Margin/Options @onready var game: Game = $"../Game" @onready var lobby_button: Button = $Side/Margin/Options/Lobby +@onready var leave_button: Button = $Side/Margin/Options/Leave var opened func _ready(): opened = Time.get_ticks_msec() lobby_button.disabled = game.in_lobby + game.joined.connect(_on_game_joined) + game.left.connect(_on_game_left) super() func anim_setup(): pass @@ -57,3 +60,23 @@ func _on_quit_pressed(): func _on_lobby_pressed(): game.mp.send_chat("/end") exit() + +func _on_leave_pressed(): + if game.is_joined: + game.mp.send_leave() + elif not game.join_sent: + leave_button.disabled = true + game.join() + +func _on_game_joined(): + leave_button.disabled = false + update_button_text() + +func _on_game_left(): + update_button_text() + +func update_button_text(): + if game.is_joined: + leave_button.text = tr("Leave Game") + else: + leave_button.text = tr("Join Game") diff --git a/client/menu/ingame.tscn b/client/menu/ingame.tscn index 029a4d6a..75710d41 100644 --- a/client/menu/ingame.tscn +++ b/client/menu/ingame.tscn @@ -72,6 +72,7 @@ anchors_preset = 9 anchor_bottom = 1.0 offset_left = -400.0 offset_right = -90.0 +offset_bottom = 648.0 grow_vertical = 2 [node name="Margin" type="MarginContainer" parent="Side"] @@ -102,6 +103,11 @@ layout_mode = 2 text = "Resume" alignment = 0 +[node name="Leave" type="Button" parent="Side/Margin/Options"] +layout_mode = 2 +text = "Join Game" +alignment = 0 + [node name="Lobby" type="Button" parent="Side/Margin/Options"] layout_mode = 2 text = "Cancel game" @@ -112,11 +118,19 @@ layout_mode = 2 text = "Reconnect" alignment = 0 +[node name="Spacer2" type="Control" parent="Side/Margin/Options"] +custom_minimum_size = Vector2(0, 10) +layout_mode = 2 + [node name="Settings" type="Button" parent="Side/Margin/Options"] layout_mode = 2 text = "Settings" alignment = 0 +[node name="Spacer3" type="Control" parent="Side/Margin/Options"] +custom_minimum_size = Vector2(0, 10) +layout_mode = 2 + [node name="MainMenu" type="Button" parent="Side/Margin/Options"] layout_mode = 2 text = "Main menu" @@ -128,6 +142,7 @@ text = "Quit game" alignment = 0 [connection signal="pressed" from="Side/Margin/Options/Resume" to="." method="_on_resume_pressed"] +[connection signal="pressed" from="Side/Margin/Options/Leave" to="." method="_on_leave_pressed"] [connection signal="pressed" from="Side/Margin/Options/Lobby" to="." method="_on_lobby_pressed"] [connection signal="pressed" from="Side/Margin/Options/Reconnect" to="." method="_on_reconnect_pressed"] [connection signal="pressed" from="Side/Margin/Options/Settings" to="." method="_on_settings_pressed"] diff --git a/client/menu/lobby.gd b/client/menu/lobby.gd index 6e315a19..a31b38e9 100644 --- a/client/menu/lobby.gd +++ b/client/menu/lobby.gd @@ -20,8 +20,6 @@ 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() @@ -38,6 +36,7 @@ func _ready(): 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() @@ -60,7 +59,7 @@ func update_players(player_list: Dictionary): player_container.add_child(p) p.setup(player_list[i].username) -func _input(event): +func _input(_event): if not visible: return @@ -73,7 +72,10 @@ func _on_game_joined(): map_selector.show() start_button.text = tr("Start Game") start_button.disabled = false - joined = true + +func _on_game_left(): + map_selector.hide() + start_button.text = tr("Join Game") func _on_left_pressed(): selected_map = (selected_map - 1) % map_count @@ -84,10 +86,9 @@ func _on_right_pressed(): select_map(selected_map) func _on_controller_button_pressed(): - if joined: + if game.is_joined: if selected_map_name != null: game.mp.send_chat("/start %s" % selected_map_name) - elif not join_sent: - join_sent = true + elif not game.join_sent: start_button.disabled = true game.join() diff --git a/client/multiplayer.gd b/client/multiplayer.gd index 4d071933..8df00034 100644 --- a/client/multiplayer.gd +++ b/client/multiplayer.gd @@ -279,6 +279,11 @@ func send_chat(message: String): } }) +func send_leave(): + send_packet({ + "type": "leave", + }) + func send_packet(packet): var json = JSON.stringify(packet) socket.send_text(json) |