From ce85fd98edaa437a55107ded24d9d1e5b9ff5457 Mon Sep 17 00:00:00 2001 From: Ludovic Marie <136255825+ludovic111@users.noreply.github.com> Date: Wed, 14 Oct 2026 18:40:30 +0200 Subject: [PATCH 1/3] Controllers: Controller options, button binds and glyphs Co-Authored-By: Claude Opus 5.5 --- crates/horizon-client/src/game/control.rs | 2 + crates/horizon-client/src/game/options.rs | 2 +- crates/horizon-client/src/game/pad.rs | 1 + crates/horizon-client/src/game/pad_menu.rs | 11 + crates/horizon-client/src/gamepad.rs | 102 +++++++++ crates/horizon-client/src/options_horizon.rs | 26 ++- crates/horizon-client/src/options_ui.rs | 213 ++++++++++++++++++- 7 files changed, 354 insertions(+), 3 deletions(-) diff --git a/crates/horizon-client/src/game/control.rs b/crates/horizon-client/src/game/control.rs index 2ab1245cf..495e40049 100644 --- a/crates/horizon-client/src/game/control.rs +++ b/crates/horizon-client/src/game/control.rs @@ -393,6 +393,8 @@ impl Game<'_> { "sound" => Page::Sound, "controls" => Page::Controls, "keybinds" => Page::KeyBinds, + "controller" => Page::Controller, + "controller-binds" => Page::PadBinds, "mouse" => Page::Mouse, "chat" => Page::Chat, "accessibility" => Page::Accessibility, diff --git a/crates/horizon-client/src/game/options.rs b/crates/horizon-client/src/game/options.rs index f9f7fc617..bdd6ba92c 100644 --- a/crates/horizon-client/src/game/options.rs +++ b/crates/horizon-client/src/game/options.rs @@ -106,7 +106,7 @@ impl Game<'_> { } Ok(()) } - fn handle_option_events(&mut self, events: Vec) -> Result<()> { + pub(super) fn handle_option_events(&mut self, events: Vec) -> Result<()> { for e in events { match e { Event::Changed => { diff --git a/crates/horizon-client/src/game/pad.rs b/crates/horizon-client/src/game/pad.rs index 698422134..1251eab25 100644 --- a/crates/horizon-client/src/game/pad.rs +++ b/crates/horizon-client/src/game/pad.rs @@ -168,6 +168,7 @@ impl Game<'_> { } self.pad.start(); let hardware = self.pad.read(); + self.ui.options.pad_style = self.settings.controller.glyphs.resolve(self.pad.style); let state = hardware.merge(&self.pad.injected); self.pad.virtual_input = self.pad.injected != PadState::default(); for button in std::mem::take(&mut self.pad.taps) { diff --git a/crates/horizon-client/src/game/pad_menu.rs b/crates/horizon-client/src/game/pad_menu.rs index 3e8895aa5..8047e889a 100644 --- a/crates/horizon-client/src/game/pad_menu.rs +++ b/crates/horizon-client/src/game/pad_menu.rs @@ -10,6 +10,7 @@ use horizon_client::{ creative::Creative, gamepad::{self, Button}, hud::{HudBatch, rgba}, + options_ui::{Event, Page}, widgets, }; use std::time::Instant; @@ -221,6 +222,16 @@ impl Game<'_> { } return Ok(()); } + // Controller Binds waiting for a button: this one (Start cancels). + if self.screen == Screen::Options + && self.ui.options.page() == Page::PadBinds + && let Some(action) = self.ui.options.selected_pad_action.take() + { + if button != Button::Start { + self.settings.controller.bind(action, Some(button)); + } + return self.handle_option_events(vec![Event::Changed]); + } match button { Button::East | Button::Start => return self.pad_back(), Button::South | Button::West => { diff --git a/crates/horizon-client/src/gamepad.rs b/crates/horizon-client/src/gamepad.rs index b7654aa90..ed93a62dc 100644 --- a/crates/horizon-client/src/gamepad.rs +++ b/crates/horizon-client/src/gamepad.rs @@ -76,6 +76,49 @@ impl Button { fn bit(self) -> u32 { 1 << self as u32 } + /// What is printed on the button for a pad family (`Auto` reads as Xbox). + pub fn label(self, style: GlyphStyle) -> &'static str { + let i = self as usize; + match style { + GlyphStyle::PlayStation => [ + "✕", "○", "□", "△", "L1", "R1", "L2", "R2", "Create", "Options", "L3", "R3", "↑", + "↓", "←", "→", + ][i], + GlyphStyle::Nintendo => [ + "B", "A", "Y", "X", "L", "R", "ZL", "ZR", "−", "+", "LS", "RS", "↑", "↓", "←", "→", + ][i], + GlyphStyle::Xbox | GlyphStyle::Auto => [ + "A", "B", "X", "Y", "LB", "RB", "LT", "RT", "View", "Menu", "LS", "RS", "↑", "↓", + "←", "→", + ][i], + } + } + /// The glyph's colour (RGB): face buttons in their family's colours, + /// the rest white. + pub fn color(self, style: GlyphStyle) -> [u8; 3] { + let face = match self { + Button::South => 0, + Button::East => 1, + Button::West => 2, + Button::North => 3, + _ => return [255, 255, 255], + }; + match style { + GlyphStyle::PlayStation => [ + [124, 178, 232], + [235, 110, 110], + [222, 145, 205], + [92, 205, 170], + ][face], + GlyphStyle::Nintendo => [255, 255, 255], + GlyphStyle::Xbox | GlyphStyle::Auto => [ + [110, 200, 90], + [235, 90, 80], + [80, 150, 240], + [240, 200, 60], + ][face], + } + } } /// A pad's inputs at one moment. Sticks are `[x, y]` with right and up @@ -205,6 +248,16 @@ pub const ACTIONS: &[(&str, Option