From e2887b0d24a751632cc6e9cc7cc77b50b8a35149 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 15:12:28 +0400 Subject: feat(ui): arm warbot self-destruction from the strategic card --- crates/fparkan-assets/src/strategic_roster.rs | 45 +++++++++++++++++++++++++-- 1 file changed, 43 insertions(+), 2 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 cc4741ee..53f14f2f 100644 --- a/crates/fparkan-assets/src/strategic_roster.rs +++ b/crates/fparkan-assets/src/strategic_roster.rs @@ -43,6 +43,7 @@ const COCKPIT_CONTROLS: [CockpitControl; 3] = [ pub enum ListHit { Close, Cockpit(CockpitControl), + SelfDestruct, Row(usize), } @@ -65,6 +66,9 @@ pub fn hit_test([x, y]: [f32; 2], row_count: usize) -> Option { } } } + if row_count != 0 && (275.0..303.0).contains(&x) && (90.0..107.0).contains(&y) { + return Some(ListHit::SelfDestruct); + } let y = (y as u32).checked_sub(ROW_TOP)?; let row = (y / ROW_PITCH) as usize; (row < row_count && y % ROW_PITCH < ROW_HEIGHT).then_some(ListHit::Row(row)) @@ -89,6 +93,13 @@ pub struct Row<'a> { pub durability_percent: Option, } +/// The selected warbot's button states for the card. +#[derive(Clone, Copy, Debug, Default, Eq, PartialEq)] +pub struct CardControls { + pub cockpit_enabled: bool, + pub self_destruct_armed: bool, +} + /// Resident art for the header, selected-unit frame, and rows. pub struct RosterImages { background: RgbaImage, @@ -102,6 +113,7 @@ pub struct RosterImages { class_icon: RgbaImage, chassis_icons: [RgbaImage; 4], cockpit_controls: [RgbaImage; 4], + self_destruct: [RgbaImage; 3], orders: OrderImages, } @@ -199,6 +211,15 @@ impl RosterImages { "botscreen_autodriver_icon", ], )?, + self_destruct: load_ui_sprites( + vfs, + "ui/hq.cfg", + [ + "long_button_frame_off", + "long_button_frame_on", + "self_destruction_icon", + ], + )?, orders: OrderImages::load(vfs)?, }) } @@ -208,7 +229,7 @@ impl RosterImages { &self, rows: &[Row<'_>], card: &[Option>], - cockpit_controls_enabled: bool, + controls: CardControls, orders: Option<([&str; 6], Option)>, ) -> Result { let mut panel = self.background.clone(); @@ -218,7 +239,7 @@ impl RosterImages { let name = self.font.centered_line(row.label, width as u16, 16)?; stamp(&mut panel, &name, [49, 25, 49 + width, 41], [255, 255, 0]); warbot_card::paint(&self.font, &mut panel, card)?; - let tint = if cockpit_controls_enabled { + let tint = if controls.cockpit_enabled { [255; 3] } else { [128; 3] @@ -229,6 +250,16 @@ impl RosterImages { stamp(&mut panel, frame, [x, 88, x + 21, 109], tint); stamp(&mut panel, icon, [x + 3, 91, x + 18, 106], tint); } + let armed = controls.self_destruct_armed; + let frame = &self.self_destruct[usize::from(armed)]; + stamp(&mut panel, frame, [273, 88, 305, 109], [255; 3]); + let tint = if armed { [128; 3] } else { [255; 3] }; + stamp( + &mut panel, + &self.self_destruct[2], + [275, 90, 303, 107], + tint, + ); } for (index, row) in rows.iter().take(19).enumerate() { let y = ROW_TOP + index as u32 * ROW_PITCH; @@ -354,6 +385,16 @@ mod tests { } } + #[test] + fn self_destruct_hit_box_uses_the_glyph_and_excludes_the_frame() { + assert_eq!(hit_test([326.0, 90.0], 3), Some(ListHit::SelfDestruct)); + assert_eq!(hit_test([353.0, 106.0], 3), Some(ListHit::SelfDestruct)); + assert_eq!(hit_test([325.0, 90.0], 3), None); + assert_eq!(hit_test([354.0, 106.0], 3), None); + assert_eq!(hit_test([326.0, 107.0], 3), None); + assert_eq!(hit_test([326.0, 90.0], 0), None); + } + #[test] fn original_durability_colours_follow_the_rounded_health_percentage() { let durability_fill = |percent| super::durability_fill(percent, TEXT_WIDTH); -- cgit v1.2.3