aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-assets/src/designer_screen.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 05:38:48 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 05:38:48 +0300
commitca1828fc869aaeb72df00c642f918a7723c84df4 (patch)
tree1a16cb74faad26cc652dec2dce2efc64bda3f2ad /crates/fparkan-assets/src/designer_screen.rs
parent6fde1faa1dfed89007566b3373114a89139390b9 (diff)
downloadfparkan-ca1828fc869aaeb72df00c642f918a7723c84df4.tar.xz
fparkan-ca1828fc869aaeb72df00c642f918a7723c84df4.zip
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.
Diffstat (limited to 'crates/fparkan-assets/src/designer_screen.rs')
-rw-r--r--crates/fparkan-assets/src/designer_screen.rs83
1 files changed, 83 insertions, 0 deletions
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<DesignerAction>,
+ /// Active project file control.
+ pub file_dialog: Option<DesignerFileView<'a>>,
+ /// 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<Des
if has_project && hit(SEND) {
return Some(DesignerAction::Send);
}
+ if has_project && hit(SAVE) {
+ return Some(DesignerAction::Save);
+ }
+ if hit(LOAD) {
+ return Some(DesignerAction::Load);
+ }
(0..count.min(PROJECT_SLOTS))
.find(|&index| hit(recent_slot(index)))
.map(DesignerAction::Project)
}
+fn file_row(row: usize) -> [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<usize> {
+ (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],