Merge pull request #2388 from kacpherek/fix/death-screen-quit-confirm

🤖 Agent: Merged by Ludovic's AI agent (Claude, contrib-gate-19) after the contribution gate. Checked against vanilla 26.3 and proven in union/cg19-r2 (all round-2 PRs together: clippy, 1722 tests, 135 harnesses, lan_e2e in-frame and on the server thread) and union/cg19-r3 (the same PRs merged with today's main: 96/96 harnesses). Thanks @kacpherek.
This commit is contained in:
Ludovic Marie
2026-10-27 17:43:52 +01:00
committed by GitHub
5 changed files with 95 additions and 2 deletions
+13 -2
View File
@@ -63,13 +63,24 @@ impl Confirm {
atlas: &HudAtlas,
cursor: (f32, f32),
labels: [&Text; 2],
) {
self.draw_active(batch, atlas, cursor, labels, true);
}
/// `draw` with the buttons greyed out while `setDelay` runs (`active` false).
pub fn draw_active(
&self,
batch: &mut HudBatch,
atlas: &HudAtlas,
cursor: (f32, f32),
labels: [&Text; 2],
active: bool,
) {
for (line, x, y) in &self.lines {
batch.text_styled(atlas, line, *x, *y, u32::MAX, true);
}
for ((bx, by), label) in self.buttons.into_iter().zip(labels) {
let hover = ui::hovered(cursor, bx, by, 150.0, 20.0);
ui::button(batch, atlas, bx, by, 150.0, 20.0, label, true, hover);
let hover = active && ui::hovered(cursor, bx, by, 150.0, 20.0);
ui::button(batch, atlas, bx, by, 150.0, 20.0, label, active, hover);
}
}
}
+15
View File
@@ -4904,6 +4904,7 @@ impl Game<'_> {
self.screen = Screen::Dead;
self.ui.died_at = Some(Instant::now());
self.ui.death_text = None;
self.ui.death_confirm = None;
self.capture(false);
}
self.previous_position = feet;
@@ -12915,6 +12916,20 @@ impl ApplicationHandler for Game<'_> {
_ => {}
}
}
// ConfirmScreen.keyPressed: Escape answers no, once its delay is over.
WindowEvent::KeyboardInput { event, .. }
if self.screen == Screen::Dead && self.ui.death_confirm.is_some() =>
{
if event.state == ElementState::Pressed
&& event.physical_key == PhysicalKey::Code(KeyCode::Escape)
&& self
.ui
.death_confirm
.is_some_and(|t| t.elapsed().as_millis() >= 1000)
{
self.death_confirm_answer(false)?;
}
}
// ConfirmScreen.keyPressed: Escape answers no.
WindowEvent::KeyboardInput { event, .. } if self.link_prompt.is_some() => {
if event.state == ElementState::Pressed
+4
View File
@@ -104,6 +104,9 @@ pub struct UiState {
/// Death screen cause and when the player died (buttons wait 20 ticks).
pub death_text: Option<Text>,
pub died_at: Option<std::time::Instant>,
/// `DeathScreen.TitleConfirmScreen` and when it opened (its buttons wait
/// 20 ticks, `setDelay`).
pub death_confirm: Option<std::time::Instant>,
/// `LivingEntity.deathTime` of the window's player: ticks since it died.
pub death_time: u32,
}
@@ -1046,6 +1049,7 @@ impl Game<'_> {
let cause = self.ui.death_cause.take();
self.ui.died_at = Some(std::time::Instant::now());
self.ui.death_text = None;
self.ui.death_confirm = None;
if !self.ui.rules.bool("show_death_messages") {
return;
}
+2
View File
@@ -2441,6 +2441,7 @@ impl Game<'_> {
{
self.screen = Screen::Dead;
self.ui.death_time = 0;
self.ui.death_confirm = None;
self.capture(false);
}
}
@@ -2460,6 +2461,7 @@ impl Game<'_> {
if self.remote.as_ref().is_none_or(|r| r.show_death_screen) {
self.screen = Screen::Dead;
self.ui.death_time = 0;
self.ui.death_confirm = None;
self.capture(false);
} else {
self.respawn_player()?;
+61
View File
@@ -3,6 +3,7 @@ use super::{Game, Screen};
use horizon_client::{
Result,
command::args::GameMode,
confirm_screen::Confirm,
hud::{HudBatch, rgba},
text::{self, Text},
ui,
@@ -103,6 +104,14 @@ fn pause_icons(w: f32, h: f32, links: bool) -> [(f32, f32, &'static str); 4] {
]
}
/// DeathScreen.init: a hardcore player can only spectate.
/// `DeathScreen.TitleConfirmScreen`: its title and the yes and no labels.
fn death_confirm_texts() -> (Text, [Text; 2]) {
let t = |key: &str| Text::translate(key, &[]);
(
t("deathScreen.quit.confirm"),
[t("deathScreen.titleScreen"), t("deathScreen.respawn")],
)
}
fn death_buttons(w: f32, h: f32, hardcore: bool) -> [(f32, f32, &'static str, u8); 2] {
let respawn = if hardcore {
"deathScreen.spectate"
@@ -267,6 +276,20 @@ impl Game<'_> {
),
);
}
// DeathScreen.handleExitToTitleScreen: the TitleConfirmScreen takes the
// screen over, on the same background.
if let Some(opened) = self.ui.death_confirm {
let (title, labels) = death_confirm_texts();
let size = self.gui_size();
Confirm::new(&atlas.font, size, &title, &Text::literal("")).draw_active(
batch,
atlas,
self.cursor,
[&labels[0], &labels[1]],
opened.elapsed().as_millis() >= 1000,
);
return;
}
let title = if self.level.hardcore {
"deathScreen.title.hardcore"
} else {
@@ -382,6 +405,23 @@ impl Game<'_> {
{
return Ok(());
}
if let Some(opened) = self.ui.death_confirm {
// ConfirmScreen.setDelay: both buttons wait 20 ticks.
if opened.elapsed().as_millis() < 1000 {
return Ok(());
}
let (title, _) = death_confirm_texts();
let confirm = Confirm::new(
&self.gui.atlas.font,
self.gui_size(),
&title,
&Text::literal(""),
);
if let Some(yes) = confirm.answer_at(self.cursor) {
self.death_confirm_answer(yes)?;
}
return Ok(());
}
let size = self
.renderer
.as_ref()
@@ -391,6 +431,27 @@ impl Game<'_> {
.into_iter()
.find(|d| ui::hovered(self.cursor, d.0, d.1, 200.0, 20.0))
.map(|d| d.3);
// handleExitToTitleScreen: outside hardcore, Title Screen asks first.
if hit == Some(1) && !self.level.hardcore {
self.ui.death_confirm = Some(std::time::Instant::now());
self.audio.play_button_click();
return Ok(());
}
self.death_action(hit)
}
/// The confirm screen's answer: yes leaves the world, no respawns
/// (`DeathScreen.handleExitToTitleScreen`'s callback).
pub(super) fn death_confirm_answer(&mut self, yes: bool) -> Result<()> {
self.ui.death_confirm = None;
if yes {
self.audio.play_button_click();
self.close_world()
} else {
self.death_action(Some(0))
}
}
/// A death screen button: 0 respawns (or spectates in hardcore), 1 leaves.
fn death_action(&mut self, hit: Option<u8>) -> Result<()> {
match hit {
Some(0) => self.respawn_player()?,
Some(1) => self.close_world()?,