diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index 6758111c2..88a8f688a 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -9130,6 +9130,9 @@ impl ApplicationHandler for Game<'_> { if self.screen == Screen::Stats && d != 0.0 { self.stats_scroll(d); } + if self.screen == Screen::WorldOptions && d != 0.0 { + self.world_options_scroll(d); + } if self.screen == Screen::Advancements { self.advancements_scroll(scaled(raw_x) as f32, d); } diff --git a/crates/horizon-client/src/game/lan_screen.rs b/crates/horizon-client/src/game/lan_screen.rs index b9ba56c5e..2c767a3fd 100644 --- a/crates/horizon-client/src/game/lan_screen.rs +++ b/crates/horizon-client/src/game/lan_screen.rs @@ -22,7 +22,10 @@ pub(super) struct WorldOptions { hint: u16, guest_commands: bool, force: bool, + hardcore: bool, initial: Snapshot, + /// ScrollableLayout's scroll amount. + scroll: f32, } #[derive(Clone, PartialEq)] struct Snapshot { @@ -39,12 +42,28 @@ struct Snapshot { const MODES: [&str; 4] = ["survival", "creative", "adventure", "spectator"]; const DIFFICULTIES: [&str; 4] = ["peaceful", "easy", "normal", "hard"]; -#[derive(Clone, Copy, PartialEq)] +/// HeaderAndFooterLayout's header and footer heights. +const HEADER: f32 = 33.0; +const FOOTER: f32 = 33.0; +/// The scrolled content: both grids, each padded by 8 and 8 apart. +const CONTENT: f32 = 218.0; +/// The category headings' tops (FocusableTextWidget, padding 4). +const GENERAL_TOP: f32 = 8.0; +const MULTIPLAYER_TOP: f32 = 145.0; +/// The port box's top beside the LAN button. +const PORT_TOP: f32 = 166.0; + +#[derive(Clone, Copy, Debug, PartialEq)] enum Button { DefaultMode, PersonalMode, Cheats, Difficulty, + /// LockIconButton: Horizon can't lock a world's difficulty yet. + Lock, + /// InWorldGameRulesScreen and RestrictionsScreen are not in Horizon yet. + GameRules, + Restrictions, Lan, CommandAccess, Force, @@ -86,26 +105,56 @@ impl WorldOptions { let valid = !self.lan || self.parsed_port().is_some(); valid && self.snapshot() != self.initial } - fn buttons(w: f32) -> Vec<(Button, f32, f32, f32)> { - let x = (w / 2.0 - 154.0).floor(); + /// The scrolled content's top: under the header, less the scroll. + fn top(&self) -> f32 { + HEADER - self.scroll.trunc() + } + /// The grids' left edge: the content (308 wide, padded by 8) centred + /// in a ScrollableLayout reserving 10 pixels for the scrollbar each side. + fn left(w: f32) -> f32 { + (w / 2.0).floor() - 154.0 + } + /// The scrolled widgets: each grid's rows 4 apart, columns 8 apart. + fn buttons(w: f32, top: f32) -> Vec<(Button, f32, f32, f32)> { + let x = Self::left(w); let right = x + 158.0; vec![ - (Button::DefaultMode, x, 38.0, 308.0), - (Button::PersonalMode, x, 62.0, 308.0), - (Button::Cheats, x, 86.0, 150.0), - (Button::Difficulty, right, 86.0, 150.0), - (Button::Lan, x, 126.0, 150.0), - (Button::CommandAccess, x, 150.0, 150.0), - (Button::Force, right, 150.0, 150.0), + (Button::DefaultMode, x, top + 29.0, 308.0), + (Button::PersonalMode, x, top + 53.0, 308.0), + (Button::Cheats, x, top + 77.0, 150.0), + // DifficultyButtons: the cycle button gives the lock its 20 pixels. + (Button::Difficulty, right, top + 77.0, 130.0), + (Button::Lock, right + 130.0, top + 77.0, 20.0), + (Button::GameRules, x, top + 101.0, 150.0), + (Button::Restrictions, right, top + 101.0, 150.0), + (Button::Lan, x, top + 166.0, 150.0), + (Button::CommandAccess, x, top + 190.0, 150.0), + (Button::Force, right, top + 190.0, 150.0), ] } + /// The footer's two buttons, centred in its 33 pixels (FrameLayout + /// truncates the 6.5 pixel offset). fn footer(w: f32, h: f32) -> [(Button, f32, f32, f32); 2] { - let x = (w / 2.0 - 154.0).floor(); + let x = Self::left(w); [ - (Button::Apply, x, h - 28.0, 150.0), - (Button::Cancel, x + 158.0, h - 28.0, 150.0), + (Button::Apply, x, h - FOOTER + 6.0, 150.0), + (Button::Cancel, x + 158.0, h - FOOTER + 6.0, 150.0), ] } + /// The widgets under the pointer's row: scrolled ones only inside the + /// scroll area. + fn hit(&self, (x, y): (f32, f32), (w, h): (f32, f32)) -> Option