Default to Classic menus while preserving explicit preferences
This commit is contained in:
@@ -2942,6 +2942,8 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn classic_video_settings_lead_back_to_horizon_menus() {
|
||||
let previous_style = style();
|
||||
set_style(MenuStyle::Horizon);
|
||||
let s = Settings::default();
|
||||
let mut ui = OptionsUi::default();
|
||||
ui.push(Page::Video);
|
||||
@@ -2963,5 +2965,6 @@ mod tests {
|
||||
crate::options_horizon::SECTIONS[ui.section].name,
|
||||
"Interface"
|
||||
);
|
||||
set_style(previous_style);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,7 +38,7 @@ pub enum MenuStyle {
|
||||
/// Vanilla's screens, exactly as the parity harnesses expect them.
|
||||
Classic,
|
||||
}
|
||||
static STYLE: AtomicU8 = AtomicU8::new(0);
|
||||
static STYLE: AtomicU8 = AtomicU8::new(1);
|
||||
pub fn style() -> MenuStyle {
|
||||
if STYLE.load(Ordering::Relaxed) == 1 {
|
||||
MenuStyle::Classic
|
||||
@@ -55,16 +55,18 @@ pub fn set_style(s: MenuStyle) {
|
||||
/// Horizon-only preferences live in `horizon.txt` beside `options.txt`, so
|
||||
/// vanilla's options file stays exactly as vanilla writes it.
|
||||
pub fn load_preferences(dir: &Path) {
|
||||
let text = std::fs::read_to_string(dir.join("horizon.txt")).unwrap_or_default();
|
||||
let classic = text.lines().any(|l| l.trim() == "menuStyle:classic");
|
||||
let saved = preference(dir, "menuStyle");
|
||||
// HORIZON_MENU_STYLE=classic forces vanilla's screens (tests, harnesses).
|
||||
let forced = std::env::var("HORIZON_MENU_STYLE").ok();
|
||||
set_style(match forced.as_deref() {
|
||||
set_style(preferred_style(saved.as_deref(), forced.as_deref()));
|
||||
}
|
||||
fn preferred_style(saved: Option<&str>, forced: Option<&str>) -> MenuStyle {
|
||||
match forced {
|
||||
Some("classic") => MenuStyle::Classic,
|
||||
Some("horizon") => MenuStyle::Horizon,
|
||||
_ if classic => MenuStyle::Classic,
|
||||
_ => MenuStyle::Horizon,
|
||||
});
|
||||
_ if saved == Some("horizon") => MenuStyle::Horizon,
|
||||
_ => MenuStyle::Classic,
|
||||
}
|
||||
}
|
||||
pub fn save_preferences(dir: &Path) {
|
||||
let value = match style() {
|
||||
@@ -1366,3 +1368,29 @@ pub const fn id(name: &str, index: u64) -> u64 {
|
||||
}
|
||||
h ^ index.wrapping_mul(0x9e37_79b9_7f4a_7c15)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn classic_is_the_default_and_explicit_menu_preferences_are_preserved() {
|
||||
for saved in [None, Some("classic"), Some("invalid")] {
|
||||
assert_eq!(preferred_style(saved, None), MenuStyle::Classic);
|
||||
}
|
||||
assert_eq!(preferred_style(Some("horizon"), None), MenuStyle::Horizon);
|
||||
assert_eq!(preferred_style(None, Some("horizon")), MenuStyle::Horizon);
|
||||
assert_eq!(
|
||||
preferred_style(Some("classic"), Some("horizon")),
|
||||
MenuStyle::Horizon
|
||||
);
|
||||
assert_eq!(
|
||||
preferred_style(Some("horizon"), Some("classic")),
|
||||
MenuStyle::Classic
|
||||
);
|
||||
assert_eq!(
|
||||
preferred_style(Some("horizon"), Some("invalid")),
|
||||
MenuStyle::Horizon
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user