From 98569dc5e8ee01b19ee82852a807f6a2b911dae4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 14:59:29 +0400 Subject: feat(ui): watch a warbot on autopilot from its cockpit --- crates/fparkan-assets/src/strategic_roster.rs | 72 ++++++++++++++++----------- 1 file changed, 44 insertions(+), 28 deletions(-) (limited to 'crates/fparkan-assets/src') diff --git a/crates/fparkan-assets/src/strategic_roster.rs b/crates/fparkan-assets/src/strategic_roster.rs index 15ccf018..cc4741ee 100644 --- a/crates/fparkan-assets/src/strategic_roster.rs +++ b/crates/fparkan-assets/src/strategic_roster.rs @@ -24,12 +24,25 @@ const CLOSE_LEFT: u32 = 5 + TITLE_WIDTH; const TEXT_WIDTH: u32 = 248; const TEXT_LEFT: u32 = 10 + 19 * 2 + 5 + 10; +/// A cockpit control button in its left-to-right card position. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum CockpitControl { + Manual, + AutoGunner, + Autopilot, +} + +const COCKPIT_CONTROLS: [CockpitControl; 3] = [ + CockpitControl::Manual, + CockpitControl::AutoGunner, + CockpitControl::Autopilot, +]; + /// The visible interactive area of the original list. #[derive(Clone, Copy, Debug, Eq, PartialEq)] pub enum ListHit { Close, - ManualControl, - AutoGunner, + Cockpit(CockpitControl), Row(usize), } @@ -44,11 +57,13 @@ pub fn hit_test([x, y]: [f32; 2], row_count: usize) -> Option { return Some(ListHit::Close); } // iron3d+0x85c70 expands the icon rectangle by two logical pixels. - if row_count != 0 && (10.0..29.0).contains(&x) && (89.0..108.0).contains(&y) { - return Some(ListHit::ManualControl); - } - if row_count != 0 && (34.0..53.0).contains(&x) && (89.0..108.0).contains(&y) { - return Some(ListHit::AutoGunner); + if row_count != 0 && (89.0..108.0).contains(&y) { + for (index, control) in COCKPIT_CONTROLS.into_iter().enumerate() { + let left = 10.0 + 24.0 * index as f32; + if (left..left + 19.0).contains(&x) { + return Some(ListHit::Cockpit(control)); + } + } } let y = (y as u32).checked_sub(ROW_TOP)?; let row = (y / ROW_PITCH) as usize; @@ -86,7 +101,7 @@ pub struct RosterImages { end: RgbaImage, class_icon: RgbaImage, chassis_icons: [RgbaImage; 4], - cockpit_controls: [RgbaImage; 3], + cockpit_controls: [RgbaImage; 4], orders: OrderImages, } @@ -181,6 +196,7 @@ impl RosterImages { "short_button_frame_off", "buildscreen_hq_icon", "botscreen_autogunner_icon", + "botscreen_autodriver_icon", ], )?, orders: OrderImages::load(vfs)?, @@ -207,11 +223,12 @@ impl RosterImages { } else { [128; 3] }; - let [frame, manual, gunner] = &self.cockpit_controls; - stamp(&mut panel, frame, [9, 88, 30, 109], tint); - stamp(&mut panel, manual, [12, 91, 27, 106], tint); - stamp(&mut panel, frame, [33, 88, 54, 109], tint); - stamp(&mut panel, gunner, [36, 91, 51, 106], tint); + let [frame, icons @ ..] = &self.cockpit_controls; + for (index, icon) in icons.iter().enumerate() { + let x = 9 + 24 * index as u32; + stamp(&mut panel, frame, [x, 88, x + 21, 109], tint); + stamp(&mut panel, icon, [x + 3, 91, x + 18, 106], tint); + } } for (index, row) in rows.iter().take(19).enumerate() { let y = ROW_TOP + index as u32 * ROW_PITCH; @@ -321,21 +338,20 @@ mod tests { } #[test] - fn manual_control_uses_the_enlarged_native_hit_box() { - assert_eq!(hit_test([61.0, 89.0], 3), Some(ListHit::ManualControl)); - assert_eq!(hit_test([79.0, 107.0], 3), Some(ListHit::ManualControl)); - assert_eq!(hit_test([80.0, 107.0], 3), None); - assert_eq!(hit_test([61.0, 108.0], 3), None); - assert_eq!(hit_test([61.0, 89.0], 0), None); - } - - #[test] - fn auto_gunner_uses_its_own_native_hit_box() { - assert_eq!(hit_test([84.0, 89.0], 3), None); - assert_eq!(hit_test([85.0, 89.0], 3), Some(ListHit::AutoGunner)); - assert_eq!(hit_test([103.0, 107.0], 3), Some(ListHit::AutoGunner)); - assert_eq!(hit_test([104.0, 107.0], 3), None); - assert_eq!(hit_test([85.0, 108.0], 3), None); + fn cockpit_buttons_use_enlarged_hit_boxes_with_gaps() { + for (x, button) in [ + (61.0, super::CockpitControl::Manual), + (85.0, super::CockpitControl::AutoGunner), + (109.0, super::CockpitControl::Autopilot), + ] { + let hit = Some(ListHit::Cockpit(button)); + assert_eq!(hit_test([x, 89.0], 3), hit); + assert_eq!(hit_test([x + 18.0, 107.0], 3), hit); + assert_eq!(hit_test([x - 1.0, 89.0], 3), None); + assert_eq!(hit_test([x + 19.0, 107.0], 3), None); + assert_eq!(hit_test([x, 108.0], 3), None); + assert_eq!(hit_test([x, 89.0], 0), None); + } } #[test] -- cgit v1.2.3