diff --git a/godot/scenes/player/local_player.tscn b/godot/scenes/player/local_player.tscn index 252da90..83c4222 100644 --- a/godot/scenes/player/local_player.tscn +++ b/godot/scenes/player/local_player.tscn @@ -107,3 +107,6 @@ text = "Exit to Lobby" [node name="exit" type="Button" parent="pause_menu/v_box_container" unique_id=641638697] layout_mode = 2 text = "Exit" + +[connection signal="pressed" from="pause_menu/v_box_container/exit_to_lobby" to="." method="exit_to_lobby"] +[connection signal="pressed" from="pause_menu/v_box_container/exit" to="." method="exit"] diff --git a/rust/src/game_manager.rs b/rust/src/game_manager.rs index 1c0e955..289fcf6 100644 --- a/rust/src/game_manager.rs +++ b/rust/src/game_manager.rs @@ -96,11 +96,13 @@ impl GameManager { pub fn exit_game(&mut self) { self.exiting = true; - if let Some(mut game) = self.game.take() { - game.bind_mut().finish_game(); - game.queue_free(); - self.go_to_main_menu(); - } + self.run_deferred(|s| { + if let Some(mut game) = s.game.take() { + game.bind_mut().finish_game(); + game.queue_free(); + s.go_to_main_menu(); + } + }); } pub fn go_to_finish_screen(&self) { diff --git a/rust/src/player.rs b/rust/src/player.rs index ab8a5d6..274cca5 100644 --- a/rust/src/player.rs +++ b/rust/src/player.rs @@ -11,7 +11,7 @@ use godot::{ use serde::{Deserialize, Serialize}; use crate::{ - game_manager::{Game, GameOption}, + game_manager::{Game, GameManager, GameOption}, net::{ network_manager::{ NetworkManager, @@ -483,7 +483,6 @@ impl ICharacterBody3D for LocalPlayer { fn input(&mut self, event: Gd) { if event.is_action_pressed("pause") { - godot_print!("pause"); if let Some(pause_panel) = &mut self.pause_panel { let is_visible = pause_panel.is_visible(); pause_panel.set_visible(!is_visible); @@ -599,6 +598,19 @@ impl LocalPlayer { self.weapon = Some(weapon); } } + + #[func] + pub fn exit_to_lobby(&mut self) { + if let Some(game) = &mut Game::singleton() { + game.bind_mut().finish_game(); + } + } + + #[func] + pub fn exit(&mut self) { + GameManager::singleton().bind_mut().exit_game(); + NetworkManager::singleton().bind_mut().disconnect(); + } } #[derive(GodotClass)]