From ea9051e68a9de762a3d6f79c2e8d26bd1ce4310c Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 09:12:48 +0400 Subject: feat(ui): show the original framed map in AutoDemo --- crates/fparkan-assets/src/satellite_map.rs | 27 ++++++++++++++++++++++++++- crates/fparkan-runtime/src/autodemo.rs | 22 ++++++++++++++++++++++ 2 files changed, 48 insertions(+), 1 deletion(-) (limited to 'crates') diff --git a/crates/fparkan-assets/src/satellite_map.rs b/crates/fparkan-assets/src/satellite_map.rs index 39af61bf..d1d11ce3 100644 --- a/crates/fparkan-assets/src/satellite_map.rs +++ b/crates/fparkan-assets/src/satellite_map.rs @@ -1,6 +1,9 @@ //! Resources used by the satellite map overlay. -use crate::ui_configuration::{field, number, object, read}; +use crate::{ + mission_pager::{scale, UiFrame}, + ui_configuration::{field, number, object, read}, +}; use fparkan_nres::{decode, EntryId, ReadProfile}; use fparkan_path::{normalize_relative, PathPolicy}; use fparkan_resource::{resource_name, CachedResourceRepository, ResourceRepository}; @@ -8,8 +11,14 @@ use fparkan_texm::{decode_mip_rgba8, decode_texm, RgbaImage}; use fparkan_vfs::Vfs; use std::sync::Arc; +/// Framed map bounds in the original 640×480 coordinates (iron3d+0x733e0). +pub const MAP_RECT: [u32; 4] = [374, 0, 640, 266]; +/// Inset between the frame and the mission image (iron3d+0x74cf0). +pub const MAP_INSET: u32 = 5; + /// The mission map, compass and contact atlas from the installed game. pub struct SatelliteMapAssets { + pub frame: RgbaImage, pub background: RgbaImage, pub compass: RgbaImage, pub icons: RgbaImage, @@ -71,7 +80,17 @@ pub fn load_satellite_map( if icons.width != 256 || icons.height != 256 { return Err("unexpected satellite icon atlas dimensions".into()); } + let [left, top, right, bottom] = MAP_RECT; + let bounds = [0, 0, right - left, bottom - top]; + let [_, _, width, height] = bounds.map(scale); + let mut frame = RgbaImage { + width, + height, + rgba8: vec![0; (width * height * 4) as usize], + }; + UiFrame::load(vfs.as_ref())?.paint(&mut frame, bounds, [0; 4]); Ok(Some(SatelliteMapAssets { + frame, background, compass, icons, @@ -134,6 +153,12 @@ mod tests { [256, 256] ); assert_eq!([range.compass.width, range.compass.height], [21, 42]); + assert_eq!([range.frame.width, range.frame.height], [332, 332]); + assert_eq!(range.frame, fortresses.frame); + assert!(range.frame.rgba8[..332 * 4] + .chunks_exact(4) + .any(|pixel| pixel[3] != 0)); + assert_eq!(range.frame.rgba8[(166 * 332 + 166) * 4 + 3], 0); assert_ne!(range.background.rgba8, fortresses.background.rgba8); assert_eq!(range.compass, fortresses.compass); assert!(range diff --git a/crates/fparkan-runtime/src/autodemo.rs b/crates/fparkan-runtime/src/autodemo.rs index fe0bfd19..ab793fb2 100644 --- a/crates/fparkan-runtime/src/autodemo.rs +++ b/crates/fparkan-runtime/src/autodemo.rs @@ -431,6 +431,22 @@ fn read_setting(bytes: &[u8], key: &str) -> Option { } impl AutoDemoCamera { + /// Unit selected while the automatic camera shows the strategic map. + pub fn strategy_map_target(&self, snapshot: &WorldSnapshot) -> Option { + if self.phase != 0 || self.last_clock_ms.is_none() { + return None; + } + self.targets + .get(self.target_index) + .copied() + .filter(|target| { + snapshot + .transforms + .iter() + .any(|(handle, _)| *handle == target.handle) + }) + } + /// Replaces the camera target for a reused model slot, or adds a new target. pub fn register_target(&mut self, cockpit: StartingCockpit) { if let Some(target) = self @@ -595,6 +611,11 @@ mod tests { demo.sample_with_height(0, &snapshot, terrain).unwrap(), AutoDemoView::Exterior { bird: false, .. } )); + assert_eq!( + demo.strategy_map_target(&snapshot) + .map(|target| target.handle), + Some(cockpit(0).handle) + ); assert!(matches!( demo.sample_with_height(5_000, &snapshot, terrain).unwrap(), AutoDemoView::Exterior { bird: false, .. } @@ -603,6 +624,7 @@ mod tests { demo.sample_with_height(5_001, &snapshot, terrain).unwrap(), AutoDemoView::Exterior { bird: true, .. } )); + assert!(demo.strategy_map_target(&snapshot).is_none()); assert!(matches!( demo.sample_with_height(15_001, &snapshot, terrain).unwrap(), AutoDemoView::Exterior { bird: true, .. } -- cgit v1.2.3