From 9f7c1c3ce545903a063c1b9d33e141ee464d5388 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Fri, 16 Oct 2026 02:46:19 +0200 Subject: [PATCH 1/2] World Options: vanilla layout, headings, port box, lock, game rules and restrictions WorldOptionsScreen in a HeaderAndFooterLayout: the title in the 33 pixel header, the content in a ScrollableLayout over the in-world list background between the separators, the footer buttons at h - 27. Bold underlined category headings (FocusableTextWidget), the difficulty button 130 wide beside its lock, Edit Game Rules... and Restrictions..., the port EditBox always shown with its hint and error colour, and the buttons' active states from updateButton and the update*Button methods. Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game.rs | 3 + crates/horizon-client/src/game/lan_screen.rs | 267 +++++++++++++------ crates/horizon-client/src/game/options.rs | 2 +- 3 files changed, 191 insertions(+), 81 deletions(-) diff --git a/crates/horizon-client/src/game.rs b/crates/horizon-client/src/game.rs index b4787eb0b..04968c1df 100644 --- a/crates/horizon-client/src/game.rs +++ b/crates/horizon-client/src/game.rs @@ -9181,6 +9181,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 f0eb57b3e..a46efacc7 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"]; +/// 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, 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