diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 07:20:34 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 07:20:34 +0300 |
| commit | 2f5791c59692beda3c948d3f9efd6557a32f4913 (patch) | |
| tree | e723ceccbd0e7b2aa8a71233de5fd577cd097339 /crates/fparkan-assets/src/designer_screen.rs | |
| parent | dcba82d1cdf4a70ab879d8af0a623a10deecb544 (diff) | |
| download | fparkan-2f5791c59692beda3c948d3f9efd6557a32f4913.tar.xz fparkan-2f5791c59692beda3c948d3f9efd6557a32f4913.zip | |
feat(ui): show original designer equipment categories
Use the original atlas, resource captions, and list geometry from iron3d.dll. Group Unit DAT records by their stored part roles while keeping the record index for each installed mount.
Checked the stock start of mission 4 in the Vulkan window. Scrolling the systems list and changing one ammunition mount leaves the other mount intact, and the factory accepts the edited project.
Diffstat (limited to 'crates/fparkan-assets/src/designer_screen.rs')
| -rw-r--r-- | crates/fparkan-assets/src/designer_screen.rs | 335 |
1 files changed, 260 insertions, 75 deletions
diff --git a/crates/fparkan-assets/src/designer_screen.rs b/crates/fparkan-assets/src/designer_screen.rs index 2a6fd7f1..bdbdeda2 100644 --- a/crates/fparkan-assets/src/designer_screen.rs +++ b/crates/fparkan-assets/src/designer_screen.rs @@ -1,6 +1,7 @@ //! Project selection and the installed parts of the selected Unit DAT. use crate::{ + designer_categories::contains, factory_projects::PROJECT_SLOTS, game_font::{load_game_font, BitmapFont}, mission_pager::{copy_sprite, scale, UiFrame}, @@ -9,23 +10,22 @@ use crate::{ RgbaImage, }; use encoding_rs::WINDOWS_1251; -use fparkan_prototype::{unit_component_tree, UnitComponentRecord}; +use fparkan_prototype::UnitComponentRecord; use fparkan_vfs::Vfs; +pub use crate::designer_categories::{DesignerCategory, DesignerPartsPane}; + const SEND: [u32; 4] = [194, 437, 229, 480]; const EXIT: [u32; 4] = [405, 437, 446, 480]; const SAVE: [u32; 4] = [269, 437, 304, 480]; const LOAD: [u32; 4] = [304, 437, 339, 480]; const NAME_BOX: [u32; 4] = [270, 410, 370, 430]; -const PART_TOP: u32 = 46; -const ROW_HEIGHT: u32 = 10; -const VARIANT_PANE: [u32; 4] = [2, 2, 177, 265]; /// Extent of the designer's original font profile. pub const EXTENT: [u32; 2] = [800, 600]; /// Native inset used to frame the assembled robot, in 640×480 coordinates. pub const MODEL_VIEWPORT: [f32; 4] = [195.0, 10.0, 445.0, 300.0]; /// Number of part rows in the project viewport. -pub const PART_ROWS: usize = 18; +pub const PART_ROWS: usize = crate::designer_categories::DESIGNER_PARTS_ROWS; /// Number of visible projects in the original file picker. pub const FILE_ROWS: usize = 4; @@ -34,10 +34,14 @@ pub const FILE_ROWS: usize = 4; pub enum DesignerAction { /// Restore a recent project in the designer. Project(usize), + /// Show the selected installed-part category. + Category(DesignerCategory), /// Choose the installed mount to inspect. Part(usize), /// Install a researched variant at the inspected mount. Variant(usize), + /// Move a list by one row. + Scroll(DesignerPartsPane, bool), /// Assign the currently open project to the factory. Send, /// Open the save name field. @@ -64,6 +68,22 @@ pub struct DesignerLabels { pub filename: String, /// Close the designer. pub exit: String, + /// Original category titles in screen order. + pub categories: [String; 6], + /// Caption for the parts catalogue. + pub parts_panel: String, + /// Caption for the assembled model. + pub model_panel: String, +} + +struct EquipmentSprites { + tab: [RgbaImage; 2], + icons: [RgbaImage; 6], + row: RgbaImage, + row_marker: [RgbaImage; 2], + scroll_bar: RgbaImage, + scroll_button: [RgbaImage; 2], + scroll_icon: [RgbaImage; 2], } /// Original UI resources required by the project view of the designer. @@ -79,6 +99,7 @@ pub struct DesignerScreen { load_frame: RgbaImage, exit: RgbaImage, exit_frame: RgbaImage, + equipment: EquipmentSprites, labels: DesignerLabels, } @@ -90,6 +111,10 @@ pub struct DesignerPicture<'a> { pub project: Option<(usize, &'a str, &'a [UnitComponentRecord])>, /// First component row in the pane. pub first_part: usize, + /// First available replacement shown in the opposite pane. + pub first_variant: usize, + /// Installed part category displayed in the model pane. + pub category: DesignerCategory, /// Selected record and the available equipment for it. pub variants: Option<(usize, &'a [String])>, /// Action whose original tooltip is shown. @@ -115,10 +140,17 @@ impl DesignerScreen { pub fn load(vfs: &dyn Vfs, labels: DesignerLabels) -> Result<Self, String> { let icons = load_ui_page(vfs, "icons")?; let frames = load_ui_page(vfs, "page4")?; + let controls = load_ui_page(vfs, "page1")?; let sprite = |page: &RgbaImage, [x, y, width, height]: [u32; 4]| { atlas_region(page, [x, y, width, height]) .ok_or_else(|| format!("designer sprite outside its page at {x},{y}")) }; + let category_icons = DesignerCategory::ALL + .iter() + .map(|category| sprite(&icons, category.tab().2)) + .collect::<Result<Vec<_>, _>>()? + .try_into() + .map_err(|_| "designer category icon count mismatch")?; Ok(Self { font: load_game_font(vfs)?, frame: UiFrame::load(vfs)?, @@ -131,6 +163,27 @@ impl DesignerScreen { load_frame: sprite(&frames, [119, 169, 35, 43])?, exit: sprite(&icons, [192, 72, 24, 24])?, exit_frame: sprite(&frames, [141, 213, 41, 43])?, + equipment: EquipmentSprites { + tab: [ + sprite(&frames, [0, 106, 26, 37])?, + sprite(&frames, [27, 106, 26, 37])?, + ], + icons: category_icons, + row: sprite(&frames, [0, 22, 180, 21])?, + row_marker: [ + sprite(&controls, [178, 141, 17, 21])?, + sprite(&controls, [195, 141, 17, 21])?, + ], + scroll_bar: sprite(&frames, [0, 0, 130, 21])?, + scroll_button: [ + sprite(&controls, [216, 78, 15, 21])?, + sprite(&controls, [231, 78, 18, 21])?, + ], + scroll_icon: [ + sprite(&icons, [154, 0, 11, 11])?, + sprite(&icons, [154, 11, 11, 11])?, + ], + }, labels, }) } @@ -161,7 +214,12 @@ impl DesignerScreen { height, rgba8: vec![0; (width * height * 4) as usize], }; - self.text(&mut image, &self.labels.title, [469, 10, 630, 26], [255; 3])?; + self.text( + &mut image, + &self.labels.title, + [194, 319, 446, 335], + [255; 3], + )?; self.text( &mut image, &self.labels.recent, @@ -177,32 +235,9 @@ impl DesignerScreen { }; sprite(&mut image, &self.recent, recent_slot(index), tint); } - if let Some((_, name, records)) = view.project { - self.text(&mut image, name, [469, 27, 630, 42], [255, 255, 100])?; - self.paint_parts( - &mut image, - records, - view.first_part, - view.variants.map(|v| v.0), - )?; - if let Some((record, variants)) = view.variants.and_then(|(mount, variants)| { - records - .get(mount) - .filter(|_| !variants.is_empty()) - .map(|record| (record, variants)) - }) { - self.frame.paint(&mut image, VARIANT_PANE, [0, 48, 0, 255]); - let active = field(&record.resource_raw); - for (row, resource) in variants.iter().take(PART_ROWS).enumerate() { - let label = self.part_label(resource.as_bytes(), resource.as_bytes()); - let tint = if active.eq_ignore_ascii_case(resource.as_bytes()) { - [255, 255, 100] - } else { - [255; 3] - }; - self.paint_row(&mut image, label, 9, 170, row, tint)?; - } - } + self.paint_equipment(&mut image, &view)?; + if let Some((_, name, _)) = view.project { + self.text(&mut image, name, [194, 300, 446, 316], [255, 255, 100])?; if view.buildable { sprite(&mut image, &self.send_frame, SEND, [255; 3]); sprite(&mut image, &self.send, [201, 450, 225, 474], [255; 3]); @@ -244,34 +279,125 @@ impl DesignerScreen { Some(DesignerAction::Save) => &self.labels.save, Some(DesignerAction::Load) => &self.labels.load, Some(DesignerAction::Exit) => &self.labels.exit, + Some(DesignerAction::Category(category)) => self.category_title(category), _ => return Ok(image), }; self.text(&mut image, hint, [194, 418, 446, 436], [255; 3])?; Ok(image) } - fn paint_parts( + fn category_title(&self, category: DesignerCategory) -> &str { + &self.labels.categories[category as usize] + } + + fn paint_equipment( &self, image: &mut RgbaImage, - records: &[UnitComponentRecord], - first: usize, - active: Option<usize>, + view: &DesignerPicture<'_>, ) -> Result<(), String> { - let tree = unit_component_tree(records).map_err(|error| error.to_string())?; - let mut depth = Vec::with_capacity(tree.len()); - for node in tree { - depth.push(node.parent_index.map_or(0_u32, |parent| depth[parent] + 1)); + use DesignerPartsPane::{Model, Parts}; + let records = view.project.map_or(&[][..], |(_, _, records)| records); + let variants = view.variants.map_or(&[][..], |(_, names)| names); + for pane in [Parts, Model] { + let x = pane.left(); + let title = match pane { + Parts => &self.labels.parts_panel, + Model => &self.labels.model_panel, + }; + self.text(image, title, [x + 10, 2, x + 180, 15], [255, 255, 0])?; + for (index, category) in DesignerCategory::ALL.into_iter().enumerate() { + let enabled = match pane { + Parts => category == view.category && !variants.is_empty(), + Model => category.mounts(records).next().is_some(), + }; + let selected = enabled && category == view.category; + let (frame, icon, _) = category.tab(); + let frame = x + frame; + let icon = x + icon; + sprite( + image, + &self.equipment.tab[usize::from(selected)], + [frame, 16, frame + 26, 53], + [255; 3], + ); + let top = if pane == Model && category == DesignerCategory::Armour { + 26 + } else { + 25 + }; + sprite( + image, + &self.equipment.icons[index], + [icon, top, icon + 24, top + 24], + category.tint(enabled, selected), + ); + } } - for (row, record) in records.iter().skip(first).take(PART_ROWS).enumerate() { + let mounts = view.category.mounts(records).collect::<Vec<_>>(); + for (row, index) in mounts + .iter() + .skip(view.first_part) + .take(PART_ROWS) + .enumerate() + { + let record = &records[*index]; let key = field(&record.resource_raw); let label = self.part_label(key, field(&record.description_raw)); - let left = 471 + depth[first + row].min(8) * 6; - let tint = if active == Some(first + row) { - [255, 255, 100] - } else { - [255; 3] - }; - self.paint_row(image, label, left, 630, row, tint)?; + self.paint_row( + image, + label, + Model, + row, + view.variants.is_some_and(|(mount, _)| mount == *index), + )?; + } + let installed = view + .variants + .and_then(|(mount, _)| records.get(mount)) + .map(|part| field(&part.resource_raw)); + for (row, name) in variants + .iter() + .skip(view.first_variant) + .take(PART_ROWS) + .enumerate() + { + let resource = name.as_bytes(); + self.paint_row( + image, + self.part_label(resource, resource), + Parts, + row, + installed.is_some_and(|part| part.eq_ignore_ascii_case(resource)), + )?; + } + for (pane, count) in [(Model, mounts.len()), (Parts, variants.len())] { + if count <= PART_ROWS { + continue; + } + let x = pane.left(); + sprite( + image, + &self.equipment.scroll_bar, + [x + 5, 203, x + 147, 224], + [255; 3], + ); + for (index, forward) in [false, true].into_iter().enumerate() { + let bounds = pane.arrow(forward); + sprite( + image, + &self.equipment.scroll_button[index], + bounds, + [255; 3], + ); + let left = bounds[0] + u32::from(!forward); + let top = if forward { 206 } else { 207 }; + sprite( + image, + &self.equipment.scroll_icon[index], + [left, top, left + 13, top + 13], + [255; 3], + ); + } } Ok(()) } @@ -291,14 +417,26 @@ impl DesignerScreen { &self, image: &mut RgbaImage, text: &[u8], - left: u32, - right: u32, + pane: DesignerPartsPane, row: usize, - tint: [u8; 3], + selected: bool, ) -> Result<(), String> { + let [left, top, right, bottom] = pane.row(row); + sprite( + image, + &self.equipment.row, + [left, top, right, bottom], + [255; 3], + ); + sprite( + image, + &self.equipment.row_marker[usize::from(selected)], + [left, top, left + 17, bottom], + [255; 3], + ); let [width, glyph_height] = self.font.line_metrics_bytes(text)?; - let left = scale(left); - let top = scale(PART_TOP + ROW_HEIGHT * row as u32); + let left = scale(left + 10); + let top = scale(top + 7); let width = width.min((scale(right) - left) as u16); if width != 0 { let glyphs = self.font.centered_line_bytes(text, width, glyph_height)?; @@ -312,7 +450,7 @@ impl DesignerScreen { top + u32::from(glyph_height), ], [false; 2], - tint, + if selected { [255, 255, 100] } else { [255; 3] }, ); } Ok(()) @@ -371,25 +509,56 @@ pub fn project_file_hit([x, y]: [f32; 2], visible: usize) -> Option<usize> { /// Hits a populated mount or variant row using the coordinates used to paint it. pub fn equipment_hit( - [x, y]: [f32; 2], - first: usize, - parts: usize, + cursor: [f32; 2], + category: DesignerCategory, + first_part: usize, + records: &[UnitComponentRecord], + first_variant: usize, variants: usize, ) -> Option<DesignerAction> { - let top = PART_TOP as f32; - if !(top..top + (ROW_HEIGHT as usize * PART_ROWS) as f32).contains(&y) { - return None; + use DesignerPartsPane::{Model, Parts}; + if let Some(category) = category_hit(cursor, records) { + return Some(DesignerAction::Category(category)); + } + let pane = DesignerPartsPane::at(cursor)?; + let count = match pane { + Parts => variants, + Model => category.mounts(records).count(), + }; + if count > PART_ROWS { + for forward in [false, true] { + if contains(pane.arrow(forward), cursor) { + return Some(DesignerAction::Scroll(pane, forward)); + } + } } - let row = ((y - top) / ROW_HEIGHT as f32) as usize; - if (VARIANT_PANE[0] as f32..VARIANT_PANE[2] as f32).contains(&x) && row < variants { - Some(DesignerAction::Variant(row)) - } else if (462.0..637.0).contains(&x) && first.saturating_add(row) < parts { - Some(DesignerAction::Part(first + row)) - } else { - None + let row = (0..PART_ROWS).find(|&row| contains(pane.row(row), cursor))?; + match pane { + Parts => { + (first_variant + row < variants).then_some(DesignerAction::Variant(first_variant + row)) + } + Model => category + .mounts(records) + .nth(first_part + row) + .map(DesignerAction::Part), } } +/// Finds an enabled category tab in the model panel. +pub fn category_hit(cursor: [f32; 2], records: &[UnitComponentRecord]) -> Option<DesignerCategory> { + DesignerCategory::ALL.into_iter().find(|&category| { + let (left, _, _) = category.tab(); + let left = left + DesignerPartsPane::Model.left(); + let hit_width = 26 + + u32::from(matches!( + category, + DesignerCategory::Chassis | DesignerCategory::Armour + )); + contains([left, 16, left + hit_width, 53], cursor) + && category.mounts(records).next().is_some() + }) +} + fn recent_slot(index: usize) -> [u32; 4] { let left = 200 + 30 * index as u32; [left, 270, left + 24, 294] @@ -427,19 +596,35 @@ mod tests { #[test] fn equipment_click_addresses_the_scrolled_mount_or_a_populated_variant() { + let make_part = |role| UnitComponentRecord { + archive_raw: [0; 32], + resource_raw: [0; 32], + kind: 1, + parent_or_link: -1, + description_raw: [0; 32], + tail0: role, + immediate_child_count: 0, + }; + let records = [0, 3, 4, 3, 4, 3, 3, 3, 3, 3].map(make_part); + let action = |cursor| equipment_hit(cursor, DesignerCategory::Systems, 1, &records, 2, 8); assert_eq!( - equipment_hit([500.0, 46.0], 7, 9, 1), - Some(DesignerAction::Part(7)) + action([491.0, 24.0]), + Some(DesignerAction::Category(DesignerCategory::Chassis)) ); + assert_eq!(action([494.0, 24.0]), None, "the turret category is empty"); + assert_eq!(action([500.0, 65.0]), Some(DesignerAction::Part(3))); + assert_eq!(action([500.0, 88.0]), Some(DesignerAction::Part(5))); + assert_eq!(action([500.0, 86.0]), None, "gap between original rows"); + assert_eq!(action([30.0, 65.0]), Some(DesignerAction::Variant(2))); assert_eq!( - equipment_hit([500.0, 56.0], 7, 9, 1), - Some(DesignerAction::Part(8)) + action([629.0, 210.0]), + Some(DesignerAction::Scroll(DesignerPartsPane::Model, true)) ); - assert_eq!(equipment_hit([500.0, 66.0], 7, 9, 1), None); assert_eq!( - equipment_hit([30.0, 46.0], 7, 9, 1), - Some(DesignerAction::Variant(0)) + DesignerCategory::Weapon + .mounts(&records) + .collect::<Vec<_>>(), + [2, 4] ); - assert_eq!(equipment_hit([30.0, 56.0], 7, 9, 1), None); } } |
