From e8efd36e5be8202abf8617f4e127de10e1652fc1 Mon Sep 17 00:00:00 2001 From: rdbtCVS <87152661+rdbtCVS@users.noreply.github.com> Date: Wed, 14 Oct 2026 22:20:20 +0100 Subject: [PATCH] Integrate world management with Classic button click sounds --- crates/horizon-client/src/front.rs | 2 +- crates/horizon-client/src/title.rs | 59 ------------ crates/horizon-client/src/title/tests.rs | 112 +++++++++++++++++++++++ 3 files changed, 113 insertions(+), 60 deletions(-) diff --git a/crates/horizon-client/src/front.rs b/crates/horizon-client/src/front.rs index fef4f7220..3361f94f4 100644 --- a/crates/horizon-client/src/front.rs +++ b/crates/horizon-client/src/front.rs @@ -323,7 +323,7 @@ impl Title { self.mode, Mode::Edit { .. } | Mode::Backup { .. } | Mode::Delete { .. } | Mode::Error { .. } ) { - return self.click(x, y, (batch.width, batch.height)); + return self.click(x, y, (batch.width, batch.height)).0; } let hit = { let mut ui = Ui::dry(atlas, batch, (x, y)); diff --git a/crates/horizon-client/src/title.rs b/crates/horizon-client/src/title.rs index f491eaffb..c526d7905 100644 --- a/crates/horizon-client/src/title.rs +++ b/crates/horizon-client/src/title.rs @@ -1433,62 +1433,3 @@ 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 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")); - 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_world_selection_is_silent_until_the_entry_launches() { - let mut title = Title::new(PathBuf::from("/nonexistent/horizon-test-saves")); - 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 - ) - ); - } -} diff --git a/crates/horizon-client/src/title/tests.rs b/crates/horizon-client/src/title/tests.rs index 6805496c7..c0f515f1d 100644 --- a/crates/horizon-client/src/title/tests.rs +++ b/crates/horizon-client/src/title/tests.rs @@ -50,6 +50,9 @@ impl Fixture { .unwrap(); } fn click(&mut self, label: &str) -> Action { + self.click_with_sound(label).0 + } + fn click_with_sound(&mut self, label: &str) -> (Action, bool) { let button = self .title .buttons(480.0, 262.0) @@ -421,3 +424,112 @@ fn recreate_uses_existing_name_seed_and_mode_and_scroll_reaches_later_rows() { matches!(&f.title.mode,Mode::Select { worlds,selected:Some(i) } if worlds[*i].folder == last) ); } + +#[test] +fn classic_navigation_buttons_sound_even_without_a_game_action() { + let mut f = Fixture::new(); + f.world("World", "World"); + assert_eq!( + f.title.click(0.0, 0.0, (480.0, 262.0)), + (Action::None, false) + ); + assert_eq!( + f.click_with_sound("Minecraft Realms"), + (Action::None, false) + ); + assert_eq!(f.click_with_sound("Singleplayer"), (Action::None, true)); + assert_eq!( + f.click_with_sound("Play Selected World"), + (Action::None, false) + ); + assert_eq!(f.click_with_sound("Create New World"), (Action::None, true)); + assert_eq!( + f.title.click(240.0, 55.0, (480.0, 262.0)), + (Action::None, false) + ); + assert_eq!( + f.click_with_sound("Game Mode: Survival"), + (Action::None, true) + ); + assert_eq!(f.click_with_sound("Cancel"), (Action::None, true)); + assert_eq!(f.click_with_sound("Back"), (Action::None, true)); + assert_eq!(f.click_with_sound("Options..."), (Action::Options, true)); +} + +#[test] +fn classic_world_selection_is_silent_until_the_entry_launches() { + let mut f = Fixture::new(); + f.world("World", "World"); + f.title.enter_singleplayer(); + assert_eq!( + f.title.click(240.0, 60.0, (480.0, 262.0)), + (Action::None, false) + ); + assert_eq!( + f.title.click(240.0, 60.0, (480.0, 262.0)), + ( + Action::Play { + folder: "World".into() + }, + true + ) + ); +} + +#[test] +fn world_management_buttons_sound_when_enabled() { + let mut f = Fixture::new(); + f.world("World", "World"); + f.select(); + assert_eq!(f.click_with_sound("Edit"), (Action::None, true)); + assert_eq!(f.click_with_sound("Reset Icon"), (Action::None, false)); + assert_eq!(f.click_with_sound("Optimize World"), (Action::None, false)); + fs::write(f.title.saves.join("World/icon.png"), b"icon").unwrap(); + assert_eq!(f.click_with_sound("Reset Icon"), (Action::None, true)); + let Mode::Edit { name, .. } = &mut f.title.mode else { + panic!("edit screen") + }; + name.clear(); + assert_eq!(f.click_with_sound("Save"), (Action::None, false)); + let Mode::Edit { name, .. } = &mut f.title.mode else { + panic!("edit screen") + }; + *name = "Renamed".into(); + assert_eq!(f.click_with_sound("Save"), (Action::None, true)); + assert_eq!(f.click_with_sound("Edit"), (Action::None, true)); + assert_eq!(f.click_with_sound("Cancel"), (Action::None, true)); + assert_eq!(f.click_with_sound("Delete"), (Action::None, true)); + assert_eq!(f.click_with_sound("Cancel"), (Action::None, true)); + assert_eq!(f.click_with_sound("Delete"), (Action::None, true)); + assert_eq!(f.click_with_sound("Delete"), (Action::None, true)); + assert!(matches!(f.title.mode, Mode::Select { .. })); +} + +#[test] +fn backup_button_sounds_and_the_progress_screen_is_silent() { + let mut f = Fixture::new(); + f.world("World", "World"); + f.select(); + f.click("Edit"); + assert_eq!(f.click_with_sound("Make Backup"), (Action::None, true)); + assert_eq!( + f.title.click(240.0, 120.0, (480.0, 262.0)), + (Action::None, false) + ); + assert!(matches!(f.title.mode, Mode::Backup { .. })); + f.finish_backup(); + assert!(matches!(f.title.mode, Mode::Select { .. })); +} + +#[test] +fn failed_world_operation_back_button_plays_the_click_sound() { + let mut f = Fixture::new(); + f.world("World", "World"); + f.select(); + f.click("Edit"); + fs::remove_file(f.title.saves.join("World/level.dat")).unwrap(); + assert_eq!(f.click_with_sound("Save"), (Action::None, true)); + assert!(matches!(f.title.mode, Mode::Error { .. })); + assert_eq!(f.click_with_sound("Back"), (Action::None, true)); + assert!(matches!(f.title.mode, Mode::Edit { .. })); +}