diff --git a/crates/horizon-client/src/extras.rs b/crates/horizon-client/src/extras.rs index ee142486c..adbc6e23a 100644 --- a/crates/horizon-client/src/extras.rs +++ b/crates/horizon-client/src/extras.rs @@ -505,7 +505,7 @@ impl Item { Item::ZoomKey => "Zoom key", Item::ZoomLevel => "Starting zoom", Item::ZoomSmooth => "Smooth zoom", - Item::ZoomSensitivity => "Lower sensitivity while zoomed", + Item::ZoomSensitivity => "Slower turning", Item::Fps => "FPS counter", Item::FpsCorner | Item::KeystrokesCorner | Item::MinimapCorner => "Corner", Item::Minimap => "Minimap", @@ -523,6 +523,21 @@ impl Item { Item::KeystrokesCps => "Clicks per second", } } + /// The switch this setting belongs to: it does nothing while that is off. + pub fn parent(self) -> Option { + use Item::*; + Some(match self { + ZoomKey | ZoomLevel | ZoomSmooth | ZoomSensitivity => Zoom, + MinimapCorner | MinimapSize | MinimapShape | MinimapZoom | MinimapRotate => Minimap, + FpsCorner | FpsLows => Fps, + KeystrokesCorner | KeystrokesCps => Keystrokes, + MouseTweaksWheel => MouseTweaks, + SortKey => Sort, + Fullbright | Zoom | Minimap | Fps | Keystrokes | MouseTweaks | Sort | AutoReconnect => { + return None; + } + }) + } /// What the row says under its caption. pub fn description(self) -> &'static str { match self { diff --git a/crates/horizon-client/src/options_horizon.rs b/crates/horizon-client/src/options_horizon.rs index dd065d120..75458ae40 100644 --- a/crates/horizon-client/src/options_horizon.rs +++ b/crates/horizon-client/src/options_horizon.rs @@ -185,9 +185,17 @@ pub const SECTIONS: &[Section] = &[ Section { name: "Extras", blurb: "Optional additions, all off by default: the game stays vanilla until you turn one on.", - rows: |_| { + // A switch's own settings nest under it and show while it is on, so + // the page stays one row per extra until one is turned on. + rows: |s| { extras::rows() .into_iter() + .filter(|r| { + r.map_or(true, |item| { + item.parent() + .is_none_or(|parent| parent.switch(&s.extras) == Some(true)) + }) + }) .map(|r| r.map_or_else(HRow::Header, HRow::Extra)) .collect() }, @@ -872,6 +880,41 @@ mod tests { (point.0 * gui_per_dp, point.1 * gui_per_dp) } + #[test] + fn extras_settings_nest_under_their_switch() { + let mut s = Settings::default(); + let section = SECTIONS.iter().find(|s| s.name == "Extras").unwrap(); + let items = |s: &Settings| -> Vec { + (section.rows)(s) + .iter() + .filter_map(|row| match row { + HRow::Extra(item) => Some(*item), + _ => None, + }) + .collect() + }; + // Everything off: one row per extra. + assert!(items(&s).iter().all(|item| item.parent().is_none())); + s.extras.zoom = true; + let zoom_on = items(&s); + assert!(zoom_on.contains(&extras::Item::ZoomKey)); + assert!(zoom_on.contains(&extras::Item::ZoomSensitivity)); + assert!(!zoom_on.contains(&extras::Item::MinimapSize)); + // Every setting shows once its switch is on. + for item in extras::rows().into_iter().flatten() { + if let Some(on) = item.switch(&s.extras) + && item.parent().is_none() + && !on + { + item.cycle(&mut s.extras, false); + } + } + assert_eq!( + items(&s).len(), + extras::rows().into_iter().flatten().count() + ); + } + #[test] fn accessibility_section_only_shows_available_options() { let s = Settings::default(); diff --git a/crates/horizon-client/src/options_ui.rs b/crates/horizon-client/src/options_ui.rs index 4440d0a82..0ea49cb72 100644 --- a/crates/horizon-client/src/options_ui.rs +++ b/crates/horizon-client/src/options_ui.rs @@ -1209,22 +1209,41 @@ impl OptionsUi { fn list_rows(&self, s: &Settings) -> Vec { match self.page() { - Page::Extras => crate::extras::rows() - .into_iter() - .map(|row| match row { - Err(header) => Row::Header(header), - Ok(item) => { - let value = format!("{}: {}", item.caption(), item.value(&s.extras)); - let label = - if item.key_name().is_some() && self.selected_key == item.key_name() { - Text::literal(format!("> {value} <")).with_color(text::YELLOW) - } else { - Text::literal(value) - }; - Row::Buttons(button(0.0, 0.0, 310.0, label, Act::Extra(item)), None) + Page::Extras => { + // Each section's switches two to a row, as vanilla's + // OptionsList.addSmall lays out an options screen. + let extra = |item: crate::extras::Item| { + let value = format!("{}: {}", item.caption(), item.value(&s.extras)); + let label = if item.key_name().is_some() && self.selected_key == item.key_name() + { + Text::literal(format!("> {value} <")).with_color(text::YELLOW) + } else { + Text::literal(value) + }; + button(0.0, 0.0, 150.0, label, Act::Extra(item)) + }; + let mut rows = Vec::new(); + let mut section = Vec::new(); + let flush = |rows: &mut Vec, section: &mut Vec| { + rows.extend( + section + .chunks(2) + .map(|c| Row::Buttons(extra(c[0]), c.get(1).map(|&b| extra(b)))), + ); + section.clear(); + }; + for row in crate::extras::rows() { + match row { + Err(header) => { + flush(&mut rows, &mut section); + rows.push(Row::Header(header)); + } + Ok(item) => section.push(item), } - }) - .collect(), + } + flush(&mut rows, &mut section); + rows + } Page::Video => { // Horizon's graphics screens, Simple and Advanced. let mut rows = vec![Row::Buttons( diff --git a/docs/extras.md b/docs/extras.md index 3c952d5ac..b88910e6d 100644 --- a/docs/extras.md +++ b/docs/extras.md @@ -20,6 +20,10 @@ again restores vanilla's behaviour completely. | Sort order and its clicks | `crates/horizon-client/src/inv_sort.rs` (pure, unit tested) | | The settings page | `options_horizon.rs`: the **Extras** section of Horizon's Options | +The settings are grouped by extra. On Horizon's page an extra's own settings +(its key, corner, size...) show under its switch while it is on (`Item::parent`); +Classic's Horizon Extras screen lists them all, two buttons to a row. + `game.rs` only gets one-line hooks (key, wheel, mouse, frame, HUD), so the extras stay out of the way of other input and options work. @@ -58,7 +62,7 @@ Horizon category in Controls, and adding one would put a non-vanilla mapping int Off applies the zoom to the final FOV with no easing. - While scoping with a spyglass the zoom does nothing: the spyglass view and its overlay stay exactly vanilla's. -- **Lower sensitivity** (default on) divides mouse turning by the zoom factor. +- **Slower turning** (default on) divides mouse turning by the zoom factor. - With zoom off (or the key up) the FOV target and mouse are vanilla's, bit for bit; the FOV harness covers this.