Add pause menu

This commit is contained in:
Sofia 2026-07-23 20:17:37 +03:00
parent a98c9d2e55
commit 6cf5828d43
3 changed files with 24 additions and 7 deletions

View File

@ -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"]

View File

@ -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) {

View File

@ -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<InputEvent>) {
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)]