diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 14:12:28 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 14:12:28 +0300 |
| commit | e2887b0d24a751632cc6e9cc7cc77b50b8a35149 (patch) | |
| tree | 82690c136dee0dea0e26bc5e27f45305de52a8ac /crates/fparkan-assets | |
| parent | 98569dc5e8ee01b19ee82852a807f6a2b911dae4 (diff) | |
| download | fparkan-e2887b0d24a751632cc6e9cc7cc77b50b8a35149.tar.xz fparkan-e2887b0d24a751632cc6e9cc7cc77b50b8a35149.zip | |
feat(ui): arm warbot self-destruction from the strategic card
Diffstat (limited to 'crates/fparkan-assets')
| -rw-r--r-- | crates/fparkan-assets/src/strategic_roster.rs | 45 |
1 files changed, 43 insertions, 2 deletions
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<ListHit> { } } } + 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<i32>, } +/// 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<CardLine<'_>>], - cockpit_controls_enabled: bool, + controls: CardControls, orders: Option<([&str; 6], Option<RosterOrder>)>, ) -> Result<RgbaImage, String> { 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; @@ -355,6 +386,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); assert_eq!(durability_fill(0), None); |
