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 /apps/fparkan-game/src | |
| 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 'apps/fparkan-game/src')
| -rw-r--r-- | apps/fparkan-game/src/factory_menu.rs | 230 | ||||
| -rw-r--r-- | apps/fparkan-game/src/robot_designer.rs | 14 |
2 files changed, 160 insertions, 84 deletions
diff --git a/apps/fparkan-game/src/factory_menu.rs b/apps/fparkan-game/src/factory_menu.rs index 48d39949..c1035fe2 100644 --- a/apps/fparkan-game/src/factory_menu.rs +++ b/apps/fparkan-game/src/factory_menu.rs @@ -10,14 +10,17 @@ use super::{ LegacyBlendMode, LegacyDepthMode, StaticPreviewScene, StaticVulkanApp, VulkanSmokeRenderer, VulkanStaticTexture, }; -use fparkan_assets::designer_screen::{self, DesignerAction, PART_ROWS}; +use fparkan_assets::designer_screen::{ + self, DesignerAction, DesignerCategory, DesignerPartsPane, PART_ROWS, +}; use fparkan_assets::factory_projects::{ hit_test, FactoryProjectAction, FactoryProjectImages, EXTENT, ORIGIN, PROJECT_SLOTS, }; +use fparkan_prototype::UnitComponentRecord; use fparkan_runtime::{ check_factory_design, factory_design_bytes, factory_part_variants, factory_project_components, factory_saved_schemes, prepare_saved_factory_preview, register_saved_factory_project, Engine, - FactoryPartChange, + FactoryPartChange, StartingCockpit, }; use fparkan_world::ObjectHandle; use std::{ @@ -50,6 +53,8 @@ pub(super) struct DesignerSession { pub(super) slots: Range<usize>, pub(super) selected: Option<usize>, pub(super) first_part: usize, + pub(super) first_variant: usize, + pub(super) category: DesignerCategory, pub(super) hover: Option<DesignerAction>, pub(super) dirty: bool, pub(super) model_started_ms: u32, @@ -70,18 +75,63 @@ impl DesignerSession { }) } - fn point(&mut self, cursor: [f32; 2]) { + fn project_parts<'a>( + &'a self, + engine: Option<&'a Engine>, + choices: &[FactoryChoice], + ) -> &'a [UnitComponentRecord] { + self.preview_project + .as_ref() + .map(|model| model.project.records.as_slice()) + .or_else(|| { + self.active_scheme(choices) + .and_then(|scheme| factory_project_components(engine?, scheme)) + }) + .unwrap_or_default() + } + + fn point(&mut self, cursor: [f32; 2], engine: Option<&Engine>, choices: &[FactoryChoice]) { let next = designer_screen::hit_test( cursor, self.slots.len(), self.selected.is_some() || self.imported_scheme.is_some() || self.preview_project.is_some(), - ); + ) + .or_else(|| { + designer_screen::category_hit(cursor, self.project_parts(engine, choices)) + .map(DesignerAction::Category) + }); self.dirty |= next != self.hover; self.hover = next; } + fn reset_equipment(&mut self) { + self.category = DesignerCategory::Chassis; + self.first_part = 0; + self.first_variant = 0; + self.variants = None; + } + + fn scroll_parts(&mut self, pane: DesignerPartsPane, lines: isize, count: usize) { + let first = match pane { + DesignerPartsPane::Model => &mut self.first_part, + DesignerPartsPane::Parts => &mut self.first_variant, + }; + let next = first + .saturating_add_signed(lines) + .min(count.saturating_sub(PART_ROWS)); + self.dirty |= next != *first; + *first = next; + } + + fn pane_len(&self, pane: DesignerPartsPane, records: &[UnitComponentRecord]) -> usize { + match pane { + DesignerPartsPane::Model => self.category.mounts(records).count(), + DesignerPartsPane::Parts => self.variants.as_ref().map_or(0, |(_, parts)| parts.len()), + } + } + fn scroll_files(&mut self, lines: isize) { if let Some(ProjectDialog::Load { projects, first }) = &mut self.file_dialog { let next = first @@ -139,6 +189,8 @@ impl FactoryMenu { slots: self.visible_slots(), selected: None, first_part: 0, + first_variant: 0, + category: DesignerCategory::Chassis, hover: None, dirty: true, model_started_ms: 0, @@ -150,7 +202,7 @@ impl FactoryMenu { preview_project: None, imported_scheme: None, }; - designer.point(self.cursor); + designer.point(self.cursor, None, &self.choices); self.designer = Some(designer); } @@ -161,13 +213,12 @@ impl FactoryMenu { match action { DesignerAction::Project(slot) if slot < designer.slots.len() => { designer.selected = Some(slot); - designer.first_part = 0; + designer.reset_equipment(); designer.dirty = true; designer.model_started_ms = clock_ms; designer .changes .clone_from(&self.choices[designer.slots.start + slot].changes); - designer.variants = None; designer.file_name = None; designer.imported_scheme = None; designer.preview_project = None; @@ -275,12 +326,84 @@ impl FactoryMenu { designer.file_name = Some(file.name); designer.file_dialog = None; designer.file_status = None; - designer.first_part = 0; - designer.variants = None; + designer.reset_equipment(); designer.model_started_ms = clock_ms; designer.dirty = true; } + fn choose_equipment( + &mut self, + engine: Option<&Engine>, + cockpit: Option<StartingCockpit>, + ) -> bool { + let Some(view) = &self.designer else { + return false; + }; + let records = view.project_parts(engine, &self.choices); + let Some(action) = designer_screen::equipment_hit( + self.cursor, + view.category, + view.first_part, + records, + view.first_variant, + view.pane_len(DesignerPartsPane::Parts, records), + ) else { + return false; + }; + match action { + DesignerAction::Category(category) => { + let view = self.designer.as_mut().expect("designer is open"); + if view.category != category { + view.reset_equipment(); + view.category = category; + } + } + DesignerAction::Part(component) => { + let variants = engine + .zip(cockpit) + .zip(view.active_scheme(&self.choices)) + .map(|((engine, cockpit), scheme)| { + factory_part_variants(engine, cockpit, scheme, component) + }) + .transpose() + .unwrap_or_else(|error| { + eprintln!("designer_equipment_unavailable {error}"); + None + }) + .unwrap_or_default(); + let view = self.designer.as_mut().expect("designer is open"); + view.first_variant = 0; + view.variants = Some((component, variants)); + } + DesignerAction::Variant(index) => { + let (component, variants) = view.variants.as_ref().expect("selected mount"); + let component = *component; + let resource = variants[index].clone(); + let base = &records[component].resource_raw; + let base = base.split(|&byte| byte == 0).next().unwrap_or_default(); + let replace = !base.eq_ignore_ascii_case(resource.as_bytes()); + let view = self.designer.as_mut().expect("designer is open"); + view.changes.retain(|change| change.component != component); + if replace { + view.changes.push(FactoryPartChange { + component, + resource, + }); + } + } + DesignerAction::Scroll(pane, forward) => { + let count = view.pane_len(pane, records); + self.designer + .as_mut() + .expect("designer is open") + .scroll_parts(pane, if forward { 1 } else { -1 }, count); + } + _ => return false, + } + self.designer.as_mut().expect("designer is open").dirty = true; + true + } + pub(super) fn title(&self) -> String { let choice = self.selected(); let factory = choice.factory.map_or_else( @@ -640,7 +763,11 @@ impl StaticVulkanApp { position.y as f32 * 480.0 / size.height as f32, ]; if let Some(designer) = &mut menu.designer { - designer.point(menu.cursor); + designer.point( + menu.cursor, + self.mission_engine.as_ref(), + &menu.choices, + ); } } } @@ -649,7 +776,7 @@ impl StaticVulkanApp { WindowEvent::CursorLeft { .. } | WindowEvent::Focused(false) => { menu.cursor = [f32::NAN; 2]; if let Some(designer) = &mut menu.designer { - designer.point(menu.cursor); + designer.point(menu.cursor, self.mission_engine.as_ref(), &menu.choices); } false } @@ -666,24 +793,10 @@ impl StaticVulkanApp { designer.scroll_files(-y.signum() as isize); return true; } - let parts = designer - .active_scheme(&menu.choices) - .and_then(|scheme| { - factory_project_components(self.mission_engine.as_ref()?, scheme) - }) - .or_else(|| { - designer - .preview_project - .as_ref() - .map(|model| model.project.records.as_slice()) - }); - if let Some(parts) = parts { - let first_part = designer - .first_part - .saturating_add_signed(-y.signum() as isize) - .min(parts.len().saturating_sub(PART_ROWS)); - designer.dirty |= designer.first_part != first_part; - designer.first_part = first_part; + if let Some(pane) = DesignerPartsPane::at(menu.cursor) { + let parts = designer.project_parts(self.mission_engine.as_ref(), &menu.choices); + let count = designer.pane_len(pane, parts); + designer.scroll_parts(pane, -y.signum() as isize, count); } true } @@ -757,60 +870,11 @@ impl StaticVulkanApp { } _ => {} } - let equipment = designer.active_scheme(&menu.choices).and_then(|scheme| { - let engine = self.mission_engine.as_ref()?; - let parts = factory_project_components(engine, scheme)?; - let variant_count = designer.variants.as_ref().map_or(0, |v| v.1.len()); - let action = designer_screen::equipment_hit( - menu.cursor, - designer.first_part, - parts.len(), - variant_count, - )?; - Some((engine, scheme, parts, action)) - }); - if let Some((engine, scheme, parts, action)) = equipment { - let designer = menu.designer.as_mut().expect("the designer is open"); - match action { - DesignerAction::Part(component) => { - designer.variants = None; - if let Some(cockpit) = self.cockpit { - match factory_part_variants( - engine, cockpit, scheme, component, - ) { - Ok(variants) if !variants.is_empty() => { - designer.variants = Some((component, variants)) - } - Ok(_) => {} - Err(error) => { - eprintln!("designer_equipment_unavailable {error}") - } - } - } - } - DesignerAction::Variant(index) => { - if let Some((component, variants)) = &designer.variants { - let resource = &variants[index]; - let base = &parts[*component].resource_raw; - let base = base - .split(|&byte| byte == 0) - .next() - .unwrap_or_default(); - designer - .changes - .retain(|change| change.component != *component); - if !base.eq_ignore_ascii_case(resource.as_bytes()) { - designer.changes.push(FactoryPartChange { - component: *component, - resource: resource.clone(), - }); - } - } - } - _ => {} - } - designer.dirty = true; - } else if let Some(action) = designer.hover { + let hover = designer.hover; + if menu.choose_equipment(self.mission_engine.as_ref(), self.cockpit) { + return true; + } + if let Some(action) = hover { if action == DesignerAction::Send { self.send_designer_project(); } else { diff --git a/apps/fparkan-game/src/robot_designer.rs b/apps/fparkan-game/src/robot_designer.rs index 2d1be0d0..0b4590cc 100644 --- a/apps/fparkan-game/src/robot_designer.rs +++ b/apps/fparkan-game/src/robot_designer.rs @@ -5,7 +5,8 @@ use super::{ DirectoryVfs, EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer, }; use fparkan_assets::designer_screen::{ - DesignerFileView, DesignerLabels, DesignerPicture, DesignerScreen, EXTENT, FILE_ROWS, + DesignerCategory, DesignerFileView, DesignerLabels, DesignerPicture, DesignerScreen, EXTENT, + FILE_ROWS, }; use fparkan_platform_winit::text::StringResources; use fparkan_runtime::{factory_design_parts, factory_project_components, Engine}; @@ -36,6 +37,12 @@ impl RobotDesignerPanel { .get(id) .ok_or_else(|| format!("missing designer label {id:#06x}")) }; + let categories = DesignerCategory::ALL + .into_iter() + .map(|category| read(u32::from(category.label_id()))) + .collect::<Result<Vec<_>, _>>()? + .try_into() + .map_err(|_| "designer category label count mismatch")?; let assets = DesignerScreen::load( &DirectoryVfs::new(root), DesignerLabels { @@ -46,6 +53,9 @@ impl RobotDesignerPanel { load: read(0x614)?, filename: read(0xbf0)?, exit: read(0x615)?, + categories, + parts_panel: read(0xbe9)?, + model_panel: read(0xbea)?, }, )?; let screen = [0.0, 0.0, 640.0, 480.0]; @@ -179,6 +189,8 @@ impl RobotDesignerPanel { (slot, name, modified.as_deref().unwrap_or(parts)) }), first_part: designer.first_part, + first_variant: designer.first_variant, + category: designer.category, variants: designer .variants .as_ref() |
