diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 10:09:58 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 10:09:58 +0300 |
| commit | 5f0b8c076b40f8eca67e2745367c731f803914f4 (patch) | |
| tree | 95bf85609d44cebfaabb86dede135c728d994cdb /crates/fparkan-assets | |
| parent | 7dfbf534267011ad629c11c7140d0f9c0fe9cd3b (diff) | |
| download | fparkan-5f0b8c076b40f8eca67e2745367c731f803914f4.tar.xz fparkan-5f0b8c076b40f8eca67e2745367c731f803914f4.zip | |
feat(ui): select units from the strategic warbot roster
Diffstat (limited to 'crates/fparkan-assets')
| -rw-r--r-- | crates/fparkan-assets/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/strategic_roster.rs | 237 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/strategy_toolbar.rs | 22 |
3 files changed, 254 insertions, 6 deletions
diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs index d64425ef..090c6c78 100644 --- a/crates/fparkan-assets/src/lib.rs +++ b/crates/fparkan-assets/src/lib.rs @@ -47,6 +47,7 @@ pub mod mission_pager; pub mod object_descriptions; pub mod satellite_map; pub mod strategic_balance; +pub mod strategic_roster; pub mod strategy_toolbar; mod turret_elevation; mod ui_configuration; diff --git a/crates/fparkan-assets/src/strategic_roster.rs b/crates/fparkan-assets/src/strategic_roster.rs new file mode 100644 index 00000000..3a28ac2a --- /dev/null +++ b/crates/fparkan-assets/src/strategic_roster.rs @@ -0,0 +1,237 @@ +//! The strategic warbot list assembled from installed compound controls. + +use crate::{ + game_font::{load_layout_font, BitmapFont}, + mission_pager::copy_sprite, + ui_sprite::{atlas_region, load_ui_page, load_ui_sprites}, + RgbaImage, +}; +use fparkan_vfs::Vfs; + +/// List origin and size in the original logical screen coordinates. +pub const ORIGIN: [u32; 2] = [51, 0]; +pub const EXTENT: [u32; 2] = [319, 480]; +const ROW_TOP: u32 = 118; +const ROW_PITCH: u32 = 20; +const ROW_HEIGHT: u32 = 19; +const TITLE_WIDTH: u32 = 278; +const CLOSE_LEFT: u32 = 5 + TITLE_WIDTH; +const TEXT_WIDTH: u32 = 248; +const TEXT_LEFT: u32 = 10 + 19 * 2 + 5 + 10; + +/// The visible interactive area of the original list. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub enum ListHit { + Close, + Row(usize), +} + +/// Locates a title close control or a list row, preserving the gap between rows. +pub fn hit_test([x, y]: [f32; 2], row_count: usize) -> Option<ListHit> { + let x = x.round_ties_even() - ORIGIN[0] as f32; + let y = y.round_ties_even(); + if !(0.0..(EXTENT[0] - 1) as f32).contains(&x) || !(0.0..480.0).contains(&y) { + return None; + } + if x >= CLOSE_LEFT as f32 && y < 20.0 { + return Some(ListHit::Close); + } + 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)) +} + +/// A localized row with the native icon selectors. +pub struct Row<'a> { + pub label: &'a str, + pub size: u32, + pub chassis: u32, + pub selected: bool, +} + +/// Resident art for the header, selected-unit frame, and rows. +pub struct RosterImages { + background: RgbaImage, + font: BitmapFont, + cap: [RgbaImage; 2], + icon_frame: RgbaImage, + separator: RgbaImage, + emitter: [RgbaImage; 2], + ray: RgbaImage, + end: RgbaImage, + class_icon: RgbaImage, + chassis_icons: [RgbaImage; 4], +} + +impl RosterImages { + /// Loads the same atlas crops used by the original compound controls. + pub fn load(vfs: &dyn Vfs, title: &str) -> Result<Self, String> { + let [title_cap, title_body, close, cap_off, cap_on, separator, emitter_off, emitter_on, ray, end, tl, tr, br, bl, horizontal, vertical] = + load_ui_sprites( + vfs, + "ui/compaund.cfg", + [ + "ccres_ending_text", + "ccres_body_text", + "ccres_exit_button_pressed", + "ccres_lamp_text_ending_off", + "ccres_lamp_text_ending_normal", + "ccres_separator_left_text", + "ccres_ray_emitter_off", + "ccres_ray_emitter_normal", + "ccres_ray_body", + "ccres_ray_ending", + "ccres_frame_corner_1", + "ccres_frame_corner_2", + "ccres_frame_corner_3", + "ccres_frame_corner_4", + "ccres_frame_edge_h", + "ccres_frame_edge_v", + ], + )?; + let [exit_icon] = load_ui_sprites(vfs, "ui/hq.cfg", ["exit_icon"])?; + let [width, height] = EXTENT; + let mut background = RgbaImage { + width, + height, + rgba8: vec![0; (width * height * 4) as usize], + }; + let font = load_layout_font(vfs)?; + let caption = font.centered_line(title, TITLE_WIDTH as u16, ROW_HEIGHT as u16)?; + stamp(&mut background, &title_cap, [0, 0, 6, 19], [255; 3]); + stamp( + &mut background, + &title_body, + [5, 0, CLOSE_LEFT + 1, 19], + [255; 3], + ); + stamp(&mut background, &caption, [5, 0, CLOSE_LEFT, 19], [255; 3]); + stamp(&mut background, &close, [CLOSE_LEFT, 0, 318, 19], [255; 3]); + stamp( + &mut background, + &exit_icon, + [CLOSE_LEFT + 15, 3, CLOSE_LEFT + 28, 16], + [255; 3], + ); + + // iron3d+0x85910 supplies the frame rectangle and its ARGB fill. + let fill = RgbaImage { + width: 1, + height: 1, + rgba8: vec![0, 128, 0, 128], + }; + for (sprite, bounds) in [ + (&fill, [5, 25, 313, 112]), + (&horizontal, [8, 20, 310, 25]), + (&horizontal, [8, 112, 310, 117]), + (&vertical, [0, 28, 5, 109]), + (&vertical, [313, 28, 318, 109]), + (&tl, [0, 20, 8, 28]), + (&tr, [310, 20, 318, 28]), + (&br, [310, 109, 318, 117]), + (&bl, [0, 109, 8, 117]), + ] { + stamp(&mut background, sprite, bounds, [255; 3]); + } + let atlas = load_ui_page(vfs, "ui_menu")?; + let icon = + |x, y| atlas_region(&atlas, [x, y, 15, 15]).ok_or("warbot glyph outside ui_menu"); + Ok(Self { + background, + font, + cap: [cap_off, cap_on], + icon_frame: title_body, + separator, + emitter: [emitter_off, emitter_on], + ray, + end, + class_icon: icon(49, 110)?, + chassis_icons: [icon(97, 94)?, icon(49, 94)?, icon(65, 94)?, icon(81, 94)?], + }) + } + + /// Renders the visible rows and the identity of the selected unit. + pub fn paint(&self, rows: &[Row<'_>]) -> Result<RgbaImage, String> { + let mut panel = self.background.clone(); + if let Some(row) = rows.iter().find(|row| row.selected) { + self.icons(&mut panel, row, [9, 27]); + let width = u32::from(self.font.line_metrics(row.label)?[0]).min(263); + let name = self.font.centered_line(row.label, width as u16, 16)?; + stamp(&mut panel, &name, [49, 25, 49 + width, 41], [255, 255, 0]); + } + for (index, row) in rows.iter().take(19).enumerate() { + let y = ROW_TOP + index as u32 * ROW_PITCH; + let bottom = y + ROW_HEIGHT; + for (sprite, left, width) in [ + (&self.cap[usize::from(row.selected)], 0, 11), + (&self.icon_frame, 10, 20), + (&self.icon_frame, 29, 20), + (&self.separator, 48, 6), + (&self.emitter[usize::from(row.selected)], 53, 11), + (&self.ray, TEXT_LEFT, TEXT_WIDTH + 1), + (&self.end, TEXT_LEFT + TEXT_WIDTH, 7), + ] { + stamp( + &mut panel, + sprite, + [left, y, left + width, bottom], + [255; 3], + ); + } + self.icons(&mut panel, row, [12, y + 2]); + let name = self + .font + .centered_line(row.label, TEXT_WIDTH as u16, ROW_HEIGHT as u16)?; + let tint = if row.selected { [255; 3] } else { [128; 3] }; + stamp( + &mut panel, + &name, + [TEXT_LEFT, y, TEXT_LEFT + TEXT_WIDTH, bottom], + tint, + ); + } + Ok(panel) + } + + fn icons(&self, panel: &mut RgbaImage, row: &Row<'_>, [left, top]: [u32; 2]) { + let tint = match row.size { + 1 => [255, 231, 255], + 2 => [255, 128, 128], + 3 => [128, 255, 128], + 4 => [128, 128, 255], + _ => [255; 3], + }; + stamp( + panel, + &self.class_icon, + [left, top, left + 15, top + 15], + tint, + ); + if let Some(icon) = row + .chassis + .checked_sub(1) + .and_then(|index| self.chassis_icons.get(index as usize)) + { + stamp(panel, icon, [left + 19, top, left + 34, top + 15], tint); + } + } +} + +fn stamp(panel: &mut RgbaImage, sprite: &RgbaImage, bounds: [u32; 4], tint: [u8; 3]) { + copy_sprite(panel, sprite, bounds, [false; 2], tint); +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn hit_testing_matches_visible_rows_and_the_close_button() { + assert_eq!(hit_test([350.0, 7.0], 3), Some(ListHit::Close)); + assert_eq!(hit_test([200.0, 118.0], 3), Some(ListHit::Row(0))); + assert_eq!(hit_test([200.0, 137.0], 3), None); + assert_eq!(hit_test([200.0, 138.0], 3), Some(ListHit::Row(1))); + assert_eq!(hit_test([200.0, 158.0], 2), None); + assert_eq!(hit_test([200.0, 480.0], 20), None); + } +} diff --git a/crates/fparkan-assets/src/strategy_toolbar.rs b/crates/fparkan-assets/src/strategy_toolbar.rs index 4c49e7f0..ac06e26e 100644 --- a/crates/fparkan-assets/src/strategy_toolbar.rs +++ b/crates/fparkan-assets/src/strategy_toolbar.rs @@ -21,6 +21,8 @@ const ENABLED_GLYPH: [u8; 3] = [128, 255, 128]; pub enum ToolbarAction { /// Return to the hero in the suit. Hero, + /// Toggle the clan's warbot list. + Warbots, /// Toggle the satellite map. Map, } @@ -32,12 +34,16 @@ pub fn command_button_at([x, y]: [f32; 2]) -> Option<ToolbarAction> { return None; } let y = y.round_ties_even(); - [(0, ToolbarAction::Hero), (10, ToolbarAction::Map)] - .into_iter() - .find_map(|(index, action)| { - let top = BUTTON_TOPS[index] as f32; - (top..top + 29.0).contains(&y).then_some(action) - }) + [ + (0, ToolbarAction::Hero), + (1, ToolbarAction::Warbots), + (10, ToolbarAction::Map), + ] + .into_iter() + .find_map(|(index, action)| { + let top = BUTTON_TOPS[index] as f32; + (top..top + 29.0).contains(&y).then_some(action) + }) } /// Composes the fully expanded toolbar in its resting state. @@ -112,6 +118,10 @@ mod tests { #[test] fn command_buttons_use_their_original_row_bounds() { assert_eq!(command_button_at([16.0, 12.0]), Some(ToolbarAction::Hero)); + assert_eq!( + command_button_at([16.0, 65.0]), + Some(ToolbarAction::Warbots) + ); assert_eq!(command_button_at([45.0, 427.0]), Some(ToolbarAction::Map)); assert_eq!(command_button_at([46.0, 400.0]), None); assert_eq!(command_button_at([25.0, 428.0]), None); |
