diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 6b1c09b60..4429a88cb 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -3643,7 +3643,7 @@ impl Game<'_> { } /// `Minecraft.pause`: a single-player game with a pausing screen open. fn pauses_game(&self) -> bool { - (self.remote.is_none() || self.integrated.is_some()) + self.has_singleplayer_server() && self.lan.is_none() && self.title.is_none() && (matches!( diff --git a/crates/horizon-client/src/game/debug_keys.rs b/crates/horizon-client/src/game/debug_keys.rs index 3aac02ae7..4008c33d9 100644 --- a/crates/horizon-client/src/game/debug_keys.rs +++ b/crates/horizon-client/src/game/debug_keys.rs @@ -38,7 +38,7 @@ impl DebugHost for Host<'_, '_> { // the menu as it always has (key_pressed). let g = &mut *self.game; if without_menu && g.screen == Screen::Playing { - g.pause_menu = !(g.remote.is_none() && g.lan.is_none()); + g.pause_menu = !(g.has_singleplayer_server() && g.lan.is_none()); g.screen = Screen::Paused; g.capture(false); g.mining = None; diff --git a/crates/horizon-client/src/game/integrated.rs b/crates/horizon-client/src/game/integrated.rs index 30b9ff23f..0366627e3 100644 --- a/crates/horizon-client/src/game/integrated.rs +++ b/crates/horizon-client/src/game/integrated.rs @@ -45,6 +45,8 @@ struct Flags { pub(super) struct Integrated { flags: Arc, thread: Option>, + /// The world's name (`level.dat`'s `LevelName`), for the pause menu. + pub world_name: String, } impl Integrated { /// `IntegratedServer.tickServer` skips the world while the game is paused. @@ -68,6 +70,10 @@ impl Drop for Integrated { } } +/// What the server thread hands the window once the world is open: its end +/// of the connection and the world's name, or why it failed. +type Ready = std::result::Result<(Pipe, String), String>; + /// The world to open and the player who owns it. struct Launch { folder: String, @@ -88,6 +94,11 @@ pub(super) fn wanted(options: &Options, world: &Path) -> bool { } impl Game<'_> { + /// `Minecraft.hasSingleplayerServer`: a world of this window's own, run + /// in the frame or on its server thread. + pub(super) fn has_singleplayer_server(&self) -> bool { + self.remote.is_none() || self.integrated.is_some() + } /// `Minecraft.doWorldLoad`: start the server thread on the world, wait /// until it can be joined, then join it through memory. pub(super) fn open_integrated( @@ -145,12 +156,16 @@ impl Game<'_> { let _ = ready_tx.send(Err(e.to_string())); } })?; - let handle = Integrated { + let mut handle = Integrated { flags, thread: Some(thread), + world_name: String::new(), }; let pipe = match ready.recv() { - Ok(Ok(pipe)) => pipe, + Ok(Ok((pipe, world_name))) => { + handle.world_name = world_name; + pipe + } Ok(Err(e)) => return Err(e.into()), Err(_) => return Err("the integrated server stopped".into()), }; @@ -165,7 +180,7 @@ impl Game<'_> { &mut self, launch: Launch, flags: &Flags, - ready: &Sender>, + ready: &Sender, ) -> Result<()> { self.open_world( &launch.folder, @@ -223,7 +238,7 @@ impl Game<'_> { }); host.hub.lan.connect_local()? }; - let _ = ready.send(Ok(pipe)); + let _ = ready.send(Ok((pipe, self.level.name.clone()))); self.settle_spawn()?; let mut next = Instant::now(); while !flags.stop.load(Ordering::Relaxed) { @@ -280,7 +295,7 @@ fn serve( settings: Settings, launch: Launch, flags: &Flags, - ready: &Sender>, + ready: &Sender, ) -> Result<()> { // It draws nothing: only the font, which books and chat measure with. let atlas = HudAtlas::fonts(&options.resources)?; diff --git a/crates/horizon-client/src/game/screens.rs b/crates/horizon-client/src/game/screens.rs index ac4d16274..0e0d63c23 100644 --- a/crates/horizon-client/src/game/screens.rs +++ b/crates/horizon-client/src/game/screens.rs @@ -60,17 +60,14 @@ impl Game<'_> { && horizon_client::ui_theme::horizon() } fn pause_labels(&self) -> (String, &'static str) { - let world = if self.remote.is_some() { - "Multiplayer".to_owned() + if let Some(server) = &self.integrated { + return (server.world_name.clone(), "Save and quit"); + } + if self.remote.is_some() { + ("Multiplayer".to_owned(), "Disconnect") } else { - self.level.name.clone() - }; - let quit = if self.remote.is_some() { - "Disconnect" - } else { - "Save and quit" - }; - (world, quit) + (self.level.name.clone(), "Save and quit") + } } pub(super) fn draw_pause_menu(&mut self, batch: &mut HudBatch) { if horizon_client::ui_theme::horizon() {