Integrated server: single-player pause menu labels
On its server thread a single-player world is joined like a server, so the Horizon pause menu named it "Multiplayer" with a "Disconnect" button, and F3+Escape opened the full menu as on a server. The server thread now hands the window the world's name with its connection, the pause menu shows that name and "Save and quit", and `has_singleplayer_server` (Minecraft.hasSingleplayerServer) covers both ways of running a world for the pause checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -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!(
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -45,6 +45,8 @@ struct Flags {
|
||||
pub(super) struct Integrated {
|
||||
flags: Arc<Flags>,
|
||||
thread: Option<JoinHandle<()>>,
|
||||
/// 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<std::result::Result<Pipe, String>>,
|
||||
ready: &Sender<Ready>,
|
||||
) -> 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<std::result::Result<Pipe, String>>,
|
||||
ready: &Sender<Ready>,
|
||||
) -> Result<()> {
|
||||
// It draws nothing: only the font, which books and chat measure with.
|
||||
let atlas = HudAtlas::fonts(&options.resources)?;
|
||||
|
||||
@@ -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() {
|
||||
|
||||
Reference in New Issue
Block a user