From 6cdcf6c85a3d2ef4bc56c826249029c99530d42d Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Wed, 14 Oct 2026 23:47:04 +0100 Subject: [PATCH 1/5] Fix classic title menu layout and accessibility shortcut --- crates/horizon-client/src/game.rs | 12 +- crates/horizon-client/src/game/options.rs | 5 +- crates/horizon-client/src/game/remote.rs | 2 +- crates/horizon-client/src/options_ui.rs | 20 +- crates/horizon-client/src/title.rs | 283 +++++++++++++++++++--- 5 files changed, 283 insertions(+), 39 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 9abc6c74a..6cc3c47c9 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -6245,7 +6245,10 @@ impl Game<'_> { if let Some(r) = self.renderer.as_mut() { r.clear_sections(); } - self.title = Some(Title::new(std::env::current_dir()?.join("saves"))); + self.title = Some(Title::new( + std::env::current_dir()?.join("saves"), + &self.options.resources, + )); self.capture(false); Ok(()) } @@ -8686,6 +8689,8 @@ impl ApplicationHandler for Game<'_> { match action { Action::Quit => event_loop.exit(), Action::Options => self.open_options(true), + Action::Accessibility => self + .open_options_at(true, horizon_client::options_ui::Page::Accessibility), Action::Play { folder } => self.open_world(&folder, None, None, false)?, Action::Create { folder, @@ -9564,7 +9569,10 @@ pub fn run() -> Result<()> { game.open_world(&folder, None, Some(seed), creative)?; } None => { - let title = Title::new(std::env::current_dir()?.join("saves")); + let title = Title::new( + std::env::current_dir()?.join("saves"), + &game.options.resources, + ); // The launcher's opening, once per session and only in Horizon's style. if horizon_client::ui_theme::horizon() && game.options.frames.is_none() { title diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rs index fa631e114..69c73c07c 100644 --- a/crates/horizon-client/src/game/options.rs +++ b/crates/horizon-client/src/game/options.rs @@ -26,13 +26,16 @@ impl Game<'_> { } /// Open the options screens (OptionsScreen) from the title or pause menu. pub(super) fn open_options(&mut self, from_title: bool) { + self.open_options_at(from_title, Page::Main); + } + pub(super) fn open_options_at(&mut self, from_title: bool, page: Page) { // Gameplay keys must not stay held behind the options screen, where // bindings can also change before the physical key is released. self.keys.clear(); self.screen = Screen::Options; self.options_from_title = from_title; let ui = &mut self.ui.options; - ui.open(!from_title && self.title.is_none()); + ui.open_at(!from_title && self.title.is_none(), page); let root = self.options.resources.clone(); ui.languages = lang::available(&[&root]); self.refresh_pack_lists(); diff --git a/crates/horizon-client/src/game/remote.rs b/crates/horizon-client/src/game/remote.rs index 19e7092a2..a626107ea 100644 --- a/crates/horizon-client/src/game/remote.rs +++ b/crates/horizon-client/src/game/remote.rs @@ -291,7 +291,7 @@ impl Game<'_> { r.clear_sections(); } let saves = std::env::current_dir()?.join("saves"); - let mut title = horizon_client::title::Title::new(saves.clone()); + let mut title = horizon_client::title::Title::new(saves.clone(), &self.options.resources); title.mode = horizon_client::title::Mode::Multiplayer(match reason { Some(reason) => horizon_client::multiplayer::Screen::Disconnected { reason, diff --git a/crates/horizon-client/src/options_ui.rs b/crates/horizon-client/src/options_ui.rs index e52de9976..ea3fde9d7 100644 --- a/crates/horizon-client/src/options_ui.rs +++ b/crates/horizon-client/src/options_ui.rs @@ -809,7 +809,11 @@ impl OptionsUi { } } pub fn open(&mut self, in_world: bool) { - self.stack = vec![Page::Main]; + self.open_at(in_world, Page::Main); + } + /// Open a page whose Done/Escape returns directly to the calling screen. + pub fn open_at(&mut self, in_world: bool, page: Page) { + self.stack = vec![page]; self.scroll = 0.0; self.scrollbar_drag_y = None; self.in_world = in_world; @@ -2456,6 +2460,20 @@ mod tests { assert_eq!(widgets.iter().find(|w| w.list).unwrap().y, top + 2.0); } + #[test] + fn title_accessibility_done_returns_directly_to_the_title() { + let mut ui = OptionsUi::default(); + let mut s = Settings::default(); + ui.open_at(false, Page::Accessibility); + assert_eq!(ui.page(), Page::Accessibility); + assert!(!ui.in_world); + assert!(ui.back(&mut s).contains(&Event::Close)); + ui.open(false); + ui.show(Page::Accessibility); + assert!(!ui.back(&mut s).contains(&Event::Close)); + assert_eq!(ui.page(), Page::Main); + } + #[test] fn classic_video_settings_lead_back_to_horizon_menus() { let s = Settings::default(); diff --git a/crates/horizon-client/src/title.rs b/crates/horizon-client/src/title.rs index 5247e08cb..b503ca7d4 100644 --- a/crates/horizon-client/src/title.rs +++ b/crates/horizon-client/src/title.rs @@ -103,6 +103,7 @@ pub enum Action { None, Quit, Options, + Accessibility, Play { folder: String, }, @@ -129,6 +130,7 @@ pub struct Title { backup_shown: Cell, toast: Option<(std::time::Instant, BackupToast)>, icons: RefCell>)>>, + splash: String, /// The mode last drawn and when it appeared (Horizon's screen fades). shown: std::cell::Cell<(std::mem::Discriminant, std::time::Instant)>, /// The launcher-style opening (Horizon style, first title of the session). @@ -143,6 +145,7 @@ struct Button { label: String, enabled: bool, id: u8, + icon: Option<(&'static str, f32)>, } /// Java String.hashCode for text seeds (WorldOptions.parseSeed). pub fn parse_seed(text: &str) -> Option { @@ -189,8 +192,20 @@ pub fn list_worlds(saves: &Path) -> Vec { worlds.sort_by_key(|w| std::cmp::Reverse(w.modified)); worlds } +fn choose_splash(text: &str, index: usize) -> String { + let splashes: Vec<_> = text + .lines() + .map(str::trim) + .filter(|s| !s.is_empty()) + .collect(); + splashes + .get(index % splashes.len().max(1)) + .copied() + .unwrap_or("Made in Rust!") + .to_owned() +} impl Title { - pub fn new(saves: PathBuf) -> Self { + pub fn new(saves: PathBuf, resources: &Path) -> Self { let mode = Mode::Main; let now = std::time::Instant::now(); Self { @@ -207,6 +222,14 @@ impl Title { backup_shown: Cell::new(false), toast: None, icons: RefCell::new(std::collections::HashMap::new()), + splash: choose_splash( + &std::fs::read_to_string(resources.join("assets/minecraft/texts/splashes.txt")) + .unwrap_or_default(), + std::time::SystemTime::now() + .duration_since(std::time::UNIX_EPOCH) + .unwrap_or_default() + .subsec_nanos() as usize, + ), opening: std::cell::Cell::new(None), recent: std::cell::RefCell::new(None), } @@ -459,45 +482,45 @@ impl Title { label: label.into(), enabled, id, + icon: None, }; match &self.mode { Mode::Main => { - let y = h / 4.0 + 48.0; - vec![ - b((w / 2.0).floor() - 100.0, y, 200.0, "Singleplayer", true, 1), - b( - (w / 2.0).floor() - 100.0, - y + 24.0, - 200.0, - "Multiplayer", + let cx = (w / 2.0).floor(); + let y = (h / 4.0).floor() + 48.0; + let mut buttons = vec![ + b(cx - 100.0, y, 200.0, "Singleplayer", true, 1), + b(cx - 100.0, y + 24.0, 200.0, "Multiplayer", true, 4), + b(cx - 100.0, y + 48.0, 200.0, "Minecraft Realms", false, 0), + b(cx - 100.0, y + 96.0, 98.0, "Options...", true, 3), + b(cx + 2.0, y + 96.0, 98.0, "Quit Game", true, 2), + ]; + for (i, (label, enabled, id, icon, size)) in [ + ("Friends", false, 5, "friends/friends", 15.0), + ("Language", false, 6, "icon/language", 15.0), + ( + "Accessibility Settings", true, - 4, - ), - b( - (w / 2.0).floor() - 100.0, - y + 48.0, - 200.0, - "Minecraft Realms", - false, - 0, - ), - b( - (w / 2.0).floor() - 100.0, - y + 84.0, - 98.0, - "Options...", - true, - 3, - ), - b( - (w / 2.0).floor() + 2.0, - y + 84.0, - 98.0, - "Quit Game", - true, - 2, + 7, + "icon/accessibility", + 15.0, ), ] + .into_iter() + .enumerate() + { + let mut button = b( + cx - 34.0 + i as f32 * 24.0, + y + 72.0, + 20.0, + label, + enabled, + id, + ); + button.icon = Some((icon, size)); + buttons.push(button); + } + buttons } Mode::Select { selected, .. } => vec![ b( @@ -688,6 +711,31 @@ impl Title { 128.0, 16.0, ); + let tw = HudBatch::text_width(atlas, &self.splash); + let start = batch.vertices.len(); + batch.text( + atlas, + &self.splash, + -(tw / 2.0).floor(), + -8.0, + rgba(255, 255, 0, 255), + true, + ); + let scale = (1.8 + - (self.started.elapsed().as_secs_f32() * std::f32::consts::TAU) + .sin() + .abs() + * 0.1) + * 100.0 + / (tw + 32.0); + let (sin, cos) = (-20.0f32).to_radians().sin_cos(); + for v in &mut batch.vertices[start..] { + let [x, y] = v.pos; + v.pos = [ + w / 2.0 + 123.0 + scale * (x * cos - y * sin), + 69.0 + scale * (x * sin + y * cos), + ]; + } let version = "Horizon 26.3 (Rust)"; batch.text(atlas, version, 2.0, h - 10.0, u32::MAX, true); let notice = "Not affiliated with Mojang or Microsoft"; @@ -1019,6 +1067,22 @@ impl Title { } else { rgba(160, 160, 160, 255) }; + if let Some((icon, size)) = b.icon { + batch.sprite_scaled( + atlas, + &format!("gui/sprites/{icon}"), + b.x + ((b.w - size) / 2.0).floor(), + b.y + ((20.0 - size) / 2.0).floor(), + size, + size, + if b.enabled { + u32::MAX + } else { + rgba(255, 255, 255, 128) + }, + ); + continue; + } let tw = HudBatch::text_width(atlas, &b.label); batch.text( atlas, @@ -1086,6 +1150,7 @@ impl Title { } } (Mode::Main, Some(3)) => Action::Options, + (Mode::Main, Some(7)) => Action::Accessibility, (Mode::Select { worlds, selected }, Some(10)) => { match selected.and_then(|i| worlds.get(i)) { Some(world) => Action::Play { @@ -1446,3 +1511,153 @@ fn date_string(secs: u64) -> String { let y = if mo <= 2 { y + 1 } else { y }; format!("{y}-{mo:02}-{d:02} {h:02}:{m:02}") } + +#[cfg(test)] +mod classic_tests { + use super::*; + + fn click_button(title: &mut Title, id: u8) -> (Action, bool) { + let b = title + .buttons(480.0, 320.0) + .into_iter() + .find(|b| b.id == id) + .unwrap(); + title.click(b.x + 1.0, b.y + 1.0, (480.0, 320.0)) + } + + #[test] + fn classic_navigation_buttons_sound_even_without_a_game_action() { + let mut title = Title::new( + PathBuf::from("/nonexistent/horizon-test-saves"), + Path::new("/nonexistent/horizon-test-resources"), + ); + assert_eq!(title.click(0.0, 0.0, (480.0, 320.0)), (Action::None, false)); + assert_eq!(click_button(&mut title, 0), (Action::None, false)); // Disabled Realms. + assert_eq!(click_button(&mut title, 1), (Action::None, true)); // Singleplayer. + assert_eq!(click_button(&mut title, 10), (Action::None, false)); // No selected world. + assert_eq!(click_button(&mut title, 11), (Action::None, true)); // Create screen. + assert_eq!( + title.click(240.0, 55.0, (480.0, 320.0)), + (Action::None, false) + ); + assert_eq!(click_button(&mut title, 20), (Action::None, true)); // Game mode. + assert_eq!(click_button(&mut title, 22), (Action::None, true)); // Cancel. + assert_eq!(click_button(&mut title, 12), (Action::None, true)); // Back. + assert_eq!(click_button(&mut title, 3), (Action::Options, true)); + } + + #[test] + fn classic_main_menu_icon_row_matches_reference_and_routes_accessibility() { + let mut title = Title::new( + PathBuf::new(), + Path::new("/nonexistent/horizon-test-resources"), + ); + for (w, h) in [(960.0, 523.0), (480.0, 320.0), (427.0, 240.0)] { + let buttons = title.buttons(w, h); + let cx = (w / 2.0).floor(); + let y = (h / 4.0).floor() + 48.0; + for (id, x, enabled, icon) in [ + (5, cx - 34.0, false, "friends/friends"), + (6, cx - 10.0, false, "icon/language"), + (7, cx + 14.0, true, "icon/accessibility"), + ] { + let b = buttons.iter().find(|b| b.id == id).unwrap(); + assert_eq!( + (b.x, b.y, b.w, b.enabled, b.icon), + (x, y + 72.0, 20.0, enabled, Some((icon, 15.0))) + ); + assert_eq!( + title.click(x + 10.0, y + 82.0, (w, h)), + if enabled { + (Action::Accessibility, true) + } else { + (Action::None, false) + } + ); + } + for id in [2, 3] { + assert_eq!(buttons.iter().find(|b| b.id == id).unwrap().y, y + 96.0); + } + // The four-pixel gaps around icons must not activate a button. + assert_eq!( + title.click(cx + 12.0, y + 82.0, (w, h)), + (Action::None, false) + ); + assert_eq!( + title.click(cx + 24.0, y + 92.0, (w, h)), + (Action::None, false) + ); + } + } + + #[test] + fn splash_selection_uses_resource_lines_and_survives_missing_resources() { + assert_eq!(choose_splash("\n First! \r\n\r\nSecond!\n", 0), "First!"); + assert_eq!(choose_splash("First!\nSecond!", 3), "Second!"); + assert_eq!(choose_splash(" \r\n", 42), "Made in Rust!"); + } + + #[test] + fn classic_logo_crops_transparent_padding_and_overlaps_edition() { + let root = Path::new("/nonexistent/horizon-test-resources"); + let mut atlas = HudAtlas::build(root).unwrap(); + let r = crate::hud::Rect { + u0: 0.0, + v0: 0.0, + u1: 1.0, + v1: 1.0, + w: 1024, + h: 256, + }; + atlas.sprites.insert("gui/title/minecraft".into(), r); + atlas.sprites.insert( + "gui/title/edition".into(), + crate::hud::Rect { w: 128, h: 16, ..r }, + ); + let title = Title::new(PathBuf::new(), root); + let mut batch = HudBatch::new([1920, 1080]); + title.draw(&atlas, &mut batch, (0.0, 0.0)); + let cx = (batch.width / 2.0).floor(); + assert_eq!(batch.vertices[0].pos, [cx - 128.0, 30.0]); + assert_eq!(batch.vertices[2].pos, [cx + 128.0, 74.0]); + assert_eq!(batch.vertices[2].uv, [1.0, 44.0 / 64.0]); + assert_eq!(batch.vertices[6].pos, [cx - 64.0, 67.0]); + assert_eq!(batch.vertices[8].pos, [cx + 64.0, 81.0]); + assert_eq!(batch.vertices[8].uv, [1.0, 14.0 / 16.0]); + assert!( + batch.vertices[12..] + .iter() + .any(|v| v.color == rgba(255, 255, 0, 255)) + ); + } + + #[test] + fn classic_world_selection_is_silent_until_the_entry_launches() { + let mut title = Title::new( + PathBuf::from("/nonexistent/horizon-test-saves"), + Path::new("/nonexistent/horizon-test-resources"), + ); + title.mode = Mode::Select { + worlds: vec![WorldEntry { + folder: "world".into(), + name: "World".into(), + creative: false, + modified: std::time::SystemTime::UNIX_EPOCH, + }], + selected: None, + }; + assert_eq!( + title.click(240.0, 40.0, (480.0, 320.0)), + (Action::None, false) + ); + assert_eq!( + title.click(240.0, 40.0, (480.0, 320.0)), + ( + Action::Play { + folder: "world".into() + }, + true + ) + ); + } +} From cccb5bff9668ffcea6b516be73291fcf4764d0eb Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Wed, 14 Oct 2026 23:53:12 +0100 Subject: [PATCH 2/5] Match Minecraft integer centering for title menu icons --- crates/horizon-client/src/title.rs | 35 +++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/title.rs b/crates/horizon-client/src/title.rs index b503ca7d4..b6a5b7751 100644 --- a/crates/horizon-client/src/title.rs +++ b/crates/horizon-client/src/title.rs @@ -1068,11 +1068,13 @@ impl Title { rgba(160, 160, 160, 255) }; if let Some((icon, size)) = b.icon { + // CenteredIcon divides the button and sprite sizes separately: + // a 15px icon in a 20px button starts at 10 - 7 = 3, not 2. batch.sprite_scaled( atlas, &format!("gui/sprites/{icon}"), - b.x + ((b.w - size) / 2.0).floor(), - b.y + ((20.0 - size) / 2.0).floor(), + b.x + (b.w / 2.0).floor() - (size / 2.0).floor(), + b.y + 10.0 - (size / 2.0).floor(), size, size, if b.enabled { @@ -1598,7 +1600,7 @@ mod classic_tests { } #[test] - fn classic_logo_crops_transparent_padding_and_overlaps_edition() { + fn classic_logo_and_icon_geometry_matches_minecraft() { let root = Path::new("/nonexistent/horizon-test-resources"); let mut atlas = HudAtlas::build(root).unwrap(); let r = crate::hud::Rect { @@ -1614,6 +1616,20 @@ mod classic_tests { "gui/title/edition".into(), crate::hud::Rect { w: 128, h: 16, ..r }, ); + for (i, icon) in ["friends/friends", "icon/language", "icon/accessibility"] + .into_iter() + .enumerate() + { + atlas.sprites.insert( + format!("gui/sprites/{icon}"), + crate::hud::Rect { + u0: 0.25 + i as f32 * 0.125, + w: 15, + h: 15, + ..r + }, + ); + } let title = Title::new(PathBuf::new(), root); let mut batch = HudBatch::new([1920, 1080]); title.draw(&atlas, &mut batch, (0.0, 0.0)); @@ -1624,6 +1640,19 @@ mod classic_tests { assert_eq!(batch.vertices[6].pos, [cx - 64.0, 67.0]); assert_eq!(batch.vertices[8].pos, [cx + 64.0, 81.0]); assert_eq!(batch.vertices[8].uv, [1.0, 14.0 / 16.0]); + for i in 0..3 { + let quad = batch + .vertices + .as_chunks::<6>() + .0 + .iter() + .find(|quad| quad[0].uv == [0.25 + i as f32 * 0.125, 0.0]) + .unwrap(); + let x = cx - 34.0 + i as f32 * 24.0 + 3.0; + let y = (batch.height / 4.0).floor() + 48.0 + 72.0 + 3.0; + assert_eq!(quad[0].pos, [x, y]); + assert_eq!(quad[2].pos, [x + 15.0, y + 15.0]); + } assert!( batch.vertices[12..] .iter() From a0f3315a79966edc87dbaf2363b4f4a45241e865 Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Thu, 15 Oct 2026 00:12:42 +0100 Subject: [PATCH 3/5] Address title menu review: language, icon opacity, and splash behavior --- crates/horizon-client/src/front.rs | 2 +- crates/horizon-client/src/game.rs | 10 +- crates/horizon-client/src/options_ui.rs | 39 ++-- crates/horizon-client/src/title.rs | 223 ++++++++++++----------- crates/horizon-client/src/title/tests.rs | 2 +- 5 files changed, 152 insertions(+), 124 deletions(-) diff --git a/crates/horizon-client/src/front.rs b/crates/horizon-client/src/front.rs index 64a27d5ac..c4a40eac6 100644 --- a/crates/horizon-client/src/front.rs +++ b/crates/horizon-client/src/front.rs @@ -108,7 +108,7 @@ impl Title { /// live backdrop is visible (0 shows the plain cold background). pub fn draw_horizon(&self, ui: &mut Ui, backdrop: f32) { if classic(&self.mode) { - self.draw(ui.atlas, ui.batch, ui.cursor); + self.draw(ui.atlas, ui.batch, ui.cursor, false); return; } let reveal = self.opening_phase(backdrop >= 1.0); diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 6cc3c47c9..11bf6ef49 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -3428,7 +3428,12 @@ impl Game<'_> { title.draw_horizon(&mut ui, fade); ui.finish(); } else { - title.draw(&self.res.atlas, &mut batch, self.cursor); + title.draw( + &self.res.atlas, + &mut batch, + self.cursor, + self.settings.file.bool("hideSplashTexts"), + ); } return batch; } @@ -8691,6 +8696,9 @@ impl ApplicationHandler for Game<'_> { Action::Options => self.open_options(true), Action::Accessibility => self .open_options_at(true, horizon_client::options_ui::Page::Accessibility), + Action::Language => { + self.open_options_at(true, horizon_client::options_ui::Page::Language) + } Action::Play { folder } => self.open_world(&folder, None, None, false)?, Action::Create { folder, diff --git a/crates/horizon-client/src/options_ui.rs b/crates/horizon-client/src/options_ui.rs index ea3fde9d7..99d1286b6 100644 --- a/crates/horizon-client/src/options_ui.rs +++ b/crates/horizon-client/src/options_ui.rs @@ -813,9 +813,8 @@ impl OptionsUi { } /// Open a page whose Done/Escape returns directly to the calling screen. pub fn open_at(&mut self, in_world: bool, page: Page) { - self.stack = vec![page]; - self.scroll = 0.0; - self.scrollbar_drag_y = None; + self.stack.clear(); + self.push(page); self.in_world = in_world; self.selected_key = None; } @@ -2461,17 +2460,33 @@ mod tests { } #[test] - fn title_accessibility_done_returns_directly_to_the_title() { + fn title_shortcuts_initialize_pages_and_return_directly_to_the_title() { let mut ui = OptionsUi::default(); let mut s = Settings::default(); - ui.open_at(false, Page::Accessibility); - assert_eq!(ui.page(), Page::Accessibility); - assert!(!ui.in_world); - assert!(ui.back(&mut s).contains(&Event::Close)); - ui.open(false); - ui.show(Page::Accessibility); - assert!(!ui.back(&mut s).contains(&Event::Close)); - assert_eq!(ui.page(), Page::Main); + for page in [Page::Accessibility, Page::Language] { + ui.language_choice = Some("de_de".into()); + ui.language_search.set_value("old query"); + ui.open_at(false, page); + assert_eq!(ui.page(), page); + assert!(!ui.in_world); + if page == Page::Language { + assert_eq!(ui.language_choice, None); + assert!(ui.language_search.value.is_empty()); + assert!(ui.center_language); + } + assert!(ui.back(&mut s).contains(&Event::Close)); + assert_eq!(s.language, "en_us"); + ui.open(false); + ui.show(page); + assert!(!ui.back(&mut s).contains(&Event::Close)); + assert_eq!(ui.page(), Page::Main); + } + ui.open_at(false, Page::Language); + ui.language_choice = Some("de_de".into()); + let events = ui.back(&mut s); + assert!(events.contains(&Event::Language("de_de".into()))); + assert!(events.contains(&Event::Close)); + assert_eq!(s.language, "de_de"); } #[test] diff --git a/crates/horizon-client/src/title.rs b/crates/horizon-client/src/title.rs index b6a5b7751..9f667a39b 100644 --- a/crates/horizon-client/src/title.rs +++ b/crates/horizon-client/src/title.rs @@ -104,6 +104,7 @@ pub enum Action { Quit, Options, Accessibility, + Language, Play { folder: String, }, @@ -130,7 +131,7 @@ pub struct Title { backup_shown: Cell, toast: Option<(std::time::Instant, BackupToast)>, icons: RefCell>)>>, - splash: String, + splash: Option, /// The mode last drawn and when it appeared (Horizon's screen fades). shown: std::cell::Cell<(std::mem::Discriminant, std::time::Instant)>, /// The launcher-style opening (Horizon style, first title of the session). @@ -192,20 +193,33 @@ pub fn list_worlds(saves: &Path) -> Vec { worlds.sort_by_key(|w| std::cmp::Reverse(w.modified)); worlds } -fn choose_splash(text: &str, index: usize) -> String { +fn choose_splash(text: &str, index: usize, date: (u32, u32)) -> Option { + // SplashManager checks SpecialDates before the resource list (local date). + let special = match date { + (12, 24) => Some("Merry X-mas!"), + (1, 1) => Some("Happy new year!"), + (10, 31) => Some("OOoooOOOoooo! Spooky!"), + _ => None, + }; + if let Some(special) = special { + return Some(special.to_owned()); + } let splashes: Vec<_> = text .lines() .map(str::trim) - .filter(|s| !s.is_empty()) + .filter(|s| { + !s.is_empty() && horizon_core::random::java_string_hash(s.encode_utf16()) != 125780783 + }) .collect(); splashes - .get(index % splashes.len().max(1)) - .copied() - .unwrap_or("Made in Rust!") - .to_owned() + .get(index.checked_rem(splashes.len())?) + .map(|s| (*s).to_owned()) } + impl Title { pub fn new(saves: PathBuf, resources: &Path) -> Self { + use chrono::Datelike; + let today = chrono::Local::now(); let mode = Mode::Main; let now = std::time::Instant::now(); Self { @@ -229,6 +243,7 @@ impl Title { .duration_since(std::time::UNIX_EPOCH) .unwrap_or_default() .subsec_nanos() as usize, + (today.month(), today.day()), ), opening: std::cell::Cell::new(None), recent: std::cell::RefCell::new(None), @@ -497,7 +512,7 @@ impl Title { ]; for (i, (label, enabled, id, icon, size)) in [ ("Friends", false, 5, "friends/friends", 15.0), - ("Language", false, 6, "icon/language", 15.0), + ("Language", true, 6, "icon/language", 15.0), ( "Accessibility Settings", true, @@ -691,7 +706,13 @@ impl Title { .collect(), } } - pub fn draw(&self, atlas: &HudAtlas, batch: &mut HudBatch, cursor: (f32, f32)) { + pub fn draw( + &self, + atlas: &HudAtlas, + batch: &mut HudBatch, + cursor: (f32, f32), + hide_splash: bool, + ) { let (w, h) = (batch.width.ceil(), batch.height.ceil()); match &self.mode { Mode::Main => { @@ -711,30 +732,32 @@ impl Title { 128.0, 16.0, ); - let tw = HudBatch::text_width(atlas, &self.splash); - let start = batch.vertices.len(); - batch.text( - atlas, - &self.splash, - -(tw / 2.0).floor(), - -8.0, - rgba(255, 255, 0, 255), - true, - ); - let scale = (1.8 - - (self.started.elapsed().as_secs_f32() * std::f32::consts::TAU) - .sin() - .abs() - * 0.1) - * 100.0 - / (tw + 32.0); - let (sin, cos) = (-20.0f32).to_radians().sin_cos(); - for v in &mut batch.vertices[start..] { - let [x, y] = v.pos; - v.pos = [ - w / 2.0 + 123.0 + scale * (x * cos - y * sin), - 69.0 + scale * (x * sin + y * cos), - ]; + if !hide_splash && let Some(splash) = self.splash.as_deref() { + let tw = HudBatch::text_width(atlas, splash); + let start = batch.vertices.len(); + batch.text( + atlas, + splash, + -(tw / 2.0).floor(), + -8.0, + rgba(255, 255, 0, 255), + true, + ); + let scale = (1.8 + - (self.started.elapsed().as_secs_f32() * std::f32::consts::TAU) + .sin() + .abs() + * 0.1) + * 100.0 + / (tw + 32.0); + let (sin, cos) = (-20.0f32).to_radians().sin_cos(); + for v in &mut batch.vertices[start..] { + let [x, y] = v.pos; + v.pos = [ + w / 2.0 + 123.0 + scale * (x * cos - y * sin), + 69.0 + scale * (x * sin + y * cos), + ]; + } } let version = "Horizon 26.3 (Rust)"; batch.text(atlas, version, 2.0, h - 10.0, u32::MAX, true); @@ -1077,11 +1100,7 @@ impl Title { b.y + 10.0 - (size / 2.0).floor(), size, size, - if b.enabled { - u32::MAX - } else { - rgba(255, 255, 255, 128) - }, + u32::MAX, ); continue; } @@ -1153,6 +1172,7 @@ impl Title { } (Mode::Main, Some(3)) => Action::Options, (Mode::Main, Some(7)) => Action::Accessibility, + (Mode::Main, Some(6)) => Action::Language, (Mode::Select { worlds, selected }, Some(10)) => { match selected.and_then(|i| worlds.get(i)) { Some(world) => Action::Play { @@ -1518,38 +1538,8 @@ fn date_string(secs: u64) -> String { mod classic_tests { use super::*; - fn click_button(title: &mut Title, id: u8) -> (Action, bool) { - let b = title - .buttons(480.0, 320.0) - .into_iter() - .find(|b| b.id == id) - .unwrap(); - title.click(b.x + 1.0, b.y + 1.0, (480.0, 320.0)) - } - #[test] - fn classic_navigation_buttons_sound_even_without_a_game_action() { - let mut title = Title::new( - PathBuf::from("/nonexistent/horizon-test-saves"), - Path::new("/nonexistent/horizon-test-resources"), - ); - assert_eq!(title.click(0.0, 0.0, (480.0, 320.0)), (Action::None, false)); - assert_eq!(click_button(&mut title, 0), (Action::None, false)); // Disabled Realms. - assert_eq!(click_button(&mut title, 1), (Action::None, true)); // Singleplayer. - assert_eq!(click_button(&mut title, 10), (Action::None, false)); // No selected world. - assert_eq!(click_button(&mut title, 11), (Action::None, true)); // Create screen. - assert_eq!( - title.click(240.0, 55.0, (480.0, 320.0)), - (Action::None, false) - ); - assert_eq!(click_button(&mut title, 20), (Action::None, true)); // Game mode. - assert_eq!(click_button(&mut title, 22), (Action::None, true)); // Cancel. - assert_eq!(click_button(&mut title, 12), (Action::None, true)); // Back. - assert_eq!(click_button(&mut title, 3), (Action::Options, true)); - } - - #[test] - fn classic_main_menu_icon_row_matches_reference_and_routes_accessibility() { + fn classic_main_menu_icons_route_language_and_accessibility() { let mut title = Title::new( PathBuf::new(), Path::new("/nonexistent/horizon-test-resources"), @@ -1560,7 +1550,7 @@ mod classic_tests { let y = (h / 4.0).floor() + 48.0; for (id, x, enabled, icon) in [ (5, cx - 34.0, false, "friends/friends"), - (6, cx - 10.0, false, "icon/language"), + (6, cx - 10.0, true, "icon/language"), (7, cx + 14.0, true, "icon/accessibility"), ] { let b = buttons.iter().find(|b| b.id == id).unwrap(); @@ -1570,10 +1560,10 @@ mod classic_tests { ); assert_eq!( title.click(x + 10.0, y + 82.0, (w, h)), - if enabled { - (Action::Accessibility, true) - } else { - (Action::None, false) + match id { + 6 => (Action::Language, true), + 7 => (Action::Accessibility, true), + _ => (Action::None, false), } ); } @@ -1593,10 +1583,35 @@ mod classic_tests { } #[test] - fn splash_selection_uses_resource_lines_and_survives_missing_resources() { - assert_eq!(choose_splash("\n First! \r\n\r\nSecond!\n", 0), "First!"); - assert_eq!(choose_splash("First!\nSecond!", 3), "Second!"); - assert_eq!(choose_splash(" \r\n", 42), "Made in Rust!"); + fn splash_selection_filters_the_forbidden_hash_and_has_no_fallback() { + let hidden = "This message will never appear on the splash screen, isn't that weird?"; + assert_eq!( + horizon_core::random::java_string_hash(hidden.encode_utf16()), + 125780783 + ); + let text = format!("\n First! \r\n{hidden}\nSecond!\n"); + for index in 0..6 { + assert_eq!( + choose_splash(&text, index, (10, 15)).as_deref(), + Some(if index % 2 == 0 { "First!" } else { "Second!" }) + ); + } + for text in ["", " \r\n", hidden] { + assert_eq!(choose_splash(text, 42, (10, 15)), None); + } + } + + #[test] + fn special_date_splashes_override_resources_even_when_the_list_is_empty() { + for (date, expected) in [ + ((12, 24), "Merry X-mas!"), + ((1, 1), "Happy new year!"), + ((10, 31), "OOoooOOOoooo! Spooky!"), + ] { + for text in ["", "Ordinary splash!"] { + assert_eq!(choose_splash(text, 0, date).as_deref(), Some(expected)); + } + } } #[test] @@ -1630,9 +1645,10 @@ mod classic_tests { }, ); } - let title = Title::new(PathBuf::new(), root); + let mut title = Title::new(PathBuf::new(), root); + title.splash = Some("Visible splash!".into()); let mut batch = HudBatch::new([1920, 1080]); - title.draw(&atlas, &mut batch, (0.0, 0.0)); + title.draw(&atlas, &mut batch, (0.0, 0.0), false); let cx = (batch.width / 2.0).floor(); assert_eq!(batch.vertices[0].pos, [cx - 128.0, 30.0]); assert_eq!(batch.vertices[2].pos, [cx + 128.0, 74.0]); @@ -1652,41 +1668,30 @@ mod classic_tests { let y = (batch.height / 4.0).floor() + 48.0 + 72.0 + 3.0; assert_eq!(quad[0].pos, [x, y]); assert_eq!(quad[2].pos, [x + 15.0, y + 15.0]); + assert!(quad.iter().all(|v| v.color == u32::MAX)); } assert!( batch.vertices[12..] .iter() .any(|v| v.color == rgba(255, 255, 0, 255)) ); - } - - #[test] - fn classic_world_selection_is_silent_until_the_entry_launches() { - let mut title = Title::new( - PathBuf::from("/nonexistent/horizon-test-saves"), - Path::new("/nonexistent/horizon-test-resources"), - ); - title.mode = Mode::Select { - worlds: vec![WorldEntry { - folder: "world".into(), - name: "World".into(), - creative: false, - modified: std::time::SystemTime::UNIX_EPOCH, - }], - selected: None, - }; - assert_eq!( - title.click(240.0, 40.0, (480.0, 320.0)), - (Action::None, false) - ); - assert_eq!( - title.click(240.0, 40.0, (480.0, 320.0)), + let settings = crate::settings::Settings::parse("hideSplashTexts:true\n"); + for (hide_splash, splash) in [ ( - Action::Play { - folder: "world".into() - }, - true - ) - ); + settings.file.bool("hideSplashTexts"), + Some("Hidden splash!".into()), + ), + (false, None), + ] { + title.splash = splash; + let mut hidden = HudBatch::new([1920, 1080]); + title.draw(&atlas, &mut hidden, (0.0, 0.0), hide_splash); + assert!( + !hidden + .vertices + .iter() + .any(|v| v.color == rgba(255, 255, 0, 255)) + ); + } } } diff --git a/crates/horizon-client/src/title/tests.rs b/crates/horizon-client/src/title/tests.rs index 15d0f4d5b..f1148a7b7 100644 --- a/crates/horizon-client/src/title/tests.rs +++ b/crates/horizon-client/src/title/tests.rs @@ -19,7 +19,7 @@ impl Fixture { )); fs::create_dir_all(root.join("saves")).unwrap(); Self { - title: Title::new(root.join("saves")), + title: Title::new(root.join("saves"), &root), root, } } From bd4101e9d19468cf57a3816bfca29e5195e92060 Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Thu, 15 Oct 2026 00:21:35 +0100 Subject: [PATCH 4/5] Update merged world-menu test for title resource loading --- crates/horizon-client/src/front.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/horizon-client/src/front.rs b/crates/horizon-client/src/front.rs index c4a40eac6..00c29a833 100644 --- a/crates/horizon-client/src/front.rs +++ b/crates/horizon-client/src/front.rs @@ -1173,7 +1173,7 @@ mod tests { for (i, folder) in ["C", "B", "A"].iter().enumerate() { world(&saves, folder, 1000 * (i as i64 + 1)); } - let mut title = Title::new(saves.clone()); + let mut title = Title::new(saves.clone(), &saves); title.mode = Mode::Select { worlds: list_worlds(&saves), selected: None, From 75a30185a540d00701a207506ec56ca47104f814 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Thu, 15 Oct 2026 02:18:24 +0200 Subject: [PATCH 5/5] Keep blank splash lines like SplashManager.prepare Vanilla trims each line and drops only the hidden splash (hash 125780783); a blank line stays a (blank) splash. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/title.rs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/crates/horizon-client/src/title.rs b/crates/horizon-client/src/title.rs index 9f667a39b..a6e7d3f23 100644 --- a/crates/horizon-client/src/title.rs +++ b/crates/horizon-client/src/title.rs @@ -207,9 +207,8 @@ fn choose_splash(text: &str, index: usize, date: (u32, u32)) -> Option { let splashes: Vec<_> = text .lines() .map(str::trim) - .filter(|s| { - !s.is_empty() && horizon_core::random::java_string_hash(s.encode_utf16()) != 125780783 - }) + // SplashManager.prepare keeps blank lines: only the hidden splash is dropped. + .filter(|s| horizon_core::random::java_string_hash(s.encode_utf16()) != 125780783) .collect(); splashes .get(index.checked_rem(splashes.len())?) @@ -1593,10 +1592,11 @@ mod classic_tests { for index in 0..6 { assert_eq!( choose_splash(&text, index, (10, 15)).as_deref(), - Some(if index % 2 == 0 { "First!" } else { "Second!" }) + Some(["", "First!", "Second!"][index % 3]) ); } - for text in ["", " \r\n", hidden] { + assert_eq!(choose_splash(" \r\n", 42, (10, 15)).as_deref(), Some("")); + for text in ["", hidden] { assert_eq!(choose_splash(text, 42, (10, 15)), None); } }