From ca1828fc869aaeb72df00c642f918a7723c84df4 Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 06:38:48 +0400 Subject: feat(ui): save and reopen warbot projects Use original designer art and names for named Unit DAT files. Restore researched designs onto the prepared mounts of a compatible factory scheme. Verified saving, restoring and ordering from the Field Camp window, and production after decoding the saved design in the Constructor. --- crates/fparkan-assets/src/designer_screen.rs | 83 ++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) (limited to 'crates/fparkan-assets/src/designer_screen.rs') diff --git a/crates/fparkan-assets/src/designer_screen.rs b/crates/fparkan-assets/src/designer_screen.rs index 133eaef0..3b9399f6 100644 --- a/crates/fparkan-assets/src/designer_screen.rs +++ b/crates/fparkan-assets/src/designer_screen.rs @@ -14,6 +14,9 @@ use fparkan_vfs::Vfs; 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]; @@ -23,6 +26,8 @@ pub const EXTENT: [u32; 2] = [800, 600]; 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; +/// Number of visible projects in the original file picker. +pub const FILE_ROWS: usize = 4; /// Controls in logical 640×480 coordinates. #[derive(Clone, Copy, Debug, Eq, PartialEq)] @@ -35,6 +40,10 @@ pub enum DesignerAction { Variant(usize), /// Assign the currently open project to the factory. Send, + /// Open the save name field. + Save, + /// Open the list of saved projects. + Load, /// Return to the factory panel. Exit, } @@ -47,6 +56,12 @@ pub struct DesignerLabels { pub recent: String, /// Transfer to the connected factory. pub send: String, + /// Save project command. + pub save: String, + /// Load project command. + pub load: String, + /// Prompt next to the save name field. + pub filename: String, /// Close the designer. pub exit: String, } @@ -59,6 +74,9 @@ pub struct DesignerScreen { recent: RgbaImage, send: RgbaImage, send_frame: RgbaImage, + save: RgbaImage, + load: RgbaImage, + load_frame: RgbaImage, exit: RgbaImage, exit_frame: RgbaImage, labels: DesignerLabels, @@ -76,6 +94,18 @@ pub struct DesignerPicture<'a> { pub variants: Option<(usize, &'a [String])>, /// Action whose original tooltip is shown. pub hover: Option, + /// Active project file control. + pub file_dialog: Option>, + /// Result of the last file operation. + pub file_status: Option<&'a str>, +} + +/// View of the name editor or the current page of saved projects. +pub enum DesignerFileView<'a> { + /// Project name typed by the player. + Save(&'a str), + /// Project names in the four visible rows. + Load(&'a [&'a str]), } impl DesignerScreen { @@ -94,6 +124,9 @@ impl DesignerScreen { recent: sprite(&icons, [216, 96, 24, 24])?, send: sprite(&icons, [176, 231, 24, 24])?, send_frame: sprite(&frames, [84, 169, 35, 43])?, + save: sprite(&icons, [152, 231, 24, 24])?, + load: sprite(&icons, [128, 231, 24, 24])?, + load_frame: sprite(&frames, [119, 169, 35, 43])?, exit: sprite(&icons, [192, 72, 24, 24])?, exit_frame: sprite(&frames, [141, 213, 41, 43])?, labels, @@ -170,11 +203,42 @@ impl DesignerScreen { } sprite(&mut image, &self.send_frame, SEND, [255; 3]); sprite(&mut image, &self.send, [201, 450, 225, 474], [255; 3]); + sprite(&mut image, &self.send_frame, SAVE, [255; 3]); + sprite(&mut image, &self.save, [278, 450, 302, 474], [255; 3]); } + sprite(&mut image, &self.load_frame, LOAD, [255; 3]); + sprite(&mut image, &self.load, [308, 450, 332, 474], [255; 3]); sprite(&mut image, &self.exit_frame, EXIT, [255; 3]); sprite(&mut image, &self.exit, [413, 450, 437, 474], [255; 3]); + if let Some(message) = view.file_status { + self.text(&mut image, message, [194, 365, 446, 386], [255, 255, 100])?; + } + if let Some(dialog) = view.file_dialog { + match dialog { + DesignerFileView::Save(name) => { + self.text( + &mut image, + &self.labels.filename, + [194, 389, 446, 407], + [255; 3], + )?; + self.frame.paint(&mut image, NAME_BOX, [0, 24, 0, 255]); + self.text(&mut image, &format!("{name}_"), NAME_BOX, [255; 3])?; + } + DesignerFileView::Load(files) => { + self.frame + .paint(&mut image, [262, 352, 378, 432], [0, 24, 0, 255]); + for (row, filename) in files.iter().take(FILE_ROWS).enumerate() { + self.text(&mut image, filename, file_row(row), [255; 3])?; + } + } + } + return Ok(image); + } let hint = match view.hover { Some(DesignerAction::Send) => &self.labels.send, + Some(DesignerAction::Save) => &self.labels.save, + Some(DesignerAction::Load) => &self.labels.load, Some(DesignerAction::Exit) => &self.labels.exit, _ => return Ok(image), }; @@ -277,11 +341,30 @@ pub fn hit_test([x, y]: [f32; 2], count: usize, has_project: bool) -> Option [u32; 4] { + let top = 354 + 18 * row as u32; + [270, top, 370, top + 18] +} + +/// Converts a pointer position to a populated file row. +pub fn project_file_hit([x, y]: [f32; 2], visible: usize) -> Option { + (0..visible.min(FILE_ROWS)).find(|&row| { + let [l, t, r, b] = file_row(row).map(|coordinate| coordinate as f32); + (l..r).contains(&x) && (t..b).contains(&y) + }) +} + /// Hits a populated mount or variant row using the coordinates used to paint it. pub fn equipment_hit( [x, y]: [f32; 2], -- cgit v1.2.3