aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-assets
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 05:25:19 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 05:25:19 +0300
commit6fde1faa1dfed89007566b3373114a89139390b9 (patch)
tree05fff10a3442ba6304086defcb109c61a5a3410c /crates/fparkan-assets
parent0ad190894afd8e9592ef182e36e16ee7a61483f6 (diff)
downloadfparkan-6fde1faa1dfed89007566b3373114a89139390b9.tar.xz
fparkan-6fde1faa1dfed89007566b3373114a89139390b9.zip
feat(ui): edit installed warbot equipment
Choose researched internal equipment per mount and build the resulting Unit DAT with the projected Control devices. Verified pointer selection and order in Field Camp with Vulkan validation, and produced the edited two-gun design at the Constructor factory.
Diffstat (limited to 'crates/fparkan-assets')
-rw-r--r--crates/fparkan-assets/src/designer_screen.rs124
1 files changed, 108 insertions, 16 deletions
diff --git a/crates/fparkan-assets/src/designer_screen.rs b/crates/fparkan-assets/src/designer_screen.rs
index 58af85c8..133eaef0 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 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.
@@ -26,6 +29,10 @@ pub const PART_ROWS: usize = 18;
pub enum DesignerAction {
/// Restore a recent project in the designer.
Project(usize),
+ /// Choose the installed mount to inspect.
+ Part(usize),
+ /// Install a researched variant at the inspected mount.
+ Variant(usize),
/// Assign the currently open project to the factory.
Send,
/// Return to the factory panel.
@@ -65,6 +72,8 @@ pub struct DesignerPicture<'a> {
pub project: Option<(usize, &'a str, &'a [UnitComponentRecord])>,
/// First component row in the pane.
pub first_part: usize,
+ /// Selected record and the available equipment for it.
+ pub variants: Option<(usize, &'a [String])>,
/// Action whose original tooltip is shown.
pub hover: Option<DesignerAction>,
}
@@ -135,7 +144,30 @@ impl DesignerScreen {
}
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)?;
+ 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)?;
+ }
+ }
sprite(&mut image, &self.send_frame, SEND, [255; 3]);
sprite(&mut image, &self.send, [201, 450, 225, 474], [255; 3]);
}
@@ -155,6 +187,7 @@ impl DesignerScreen {
image: &mut RgbaImage,
records: &[UnitComponentRecord],
first: usize,
+ active: Option<usize>,
) -> Result<(), String> {
let tree = unit_component_tree(records).map_err(|error| error.to_string())?;
let mut depth = Vec::with_capacity(tree.len());
@@ -163,23 +196,43 @@ impl DesignerScreen {
}
for (row, record) in records.iter().skip(first).take(PART_ROWS).enumerate() {
let key = field(&record.resource_raw);
- let description = self
- .descriptions
- .short_name(key)
- .filter(|name| !name.is_empty())
- .unwrap_or_else(|| field(&record.description_raw));
- let text = if description.is_empty() {
+ 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)?;
+ }
+ Ok(())
+ }
+
+ fn part_label<'a>(&'a self, key: &'a [u8], description: &'a [u8]) -> &'a [u8] {
+ self.descriptions
+ .short_name(key)
+ .filter(|name| !name.is_empty())
+ .unwrap_or(if description.is_empty() {
key
} else {
description
- };
- let [width, glyph_height] = self.font.line_metrics_bytes(text)?;
- if width == 0 {
- continue;
- }
- let left = scale(471 + depth[first + row].min(8) * 6);
- let top = scale(46 + 10 * row as u32);
- let width = width.min((scale(630) - left) as u16);
+ })
+ }
+
+ fn paint_row(
+ &self,
+ image: &mut RgbaImage,
+ text: &[u8],
+ left: u32,
+ right: u32,
+ row: usize,
+ tint: [u8; 3],
+ ) -> Result<(), String> {
+ 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 width = width.min((scale(right) - left) as u16);
+ if width != 0 {
let glyphs = self.font.centered_line_bytes(text, width, glyph_height)?;
copy_sprite(
image,
@@ -191,7 +244,7 @@ impl DesignerScreen {
top + u32::from(glyph_height),
],
[false; 2],
- [255; 3],
+ tint,
);
}
Ok(())
@@ -229,6 +282,27 @@ pub fn hit_test([x, y]: [f32; 2], count: usize, has_project: bool) -> Option<Des
.map(DesignerAction::Project)
}
+/// 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,
+ 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;
+ }
+ 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
+ }
+}
+
fn recent_slot(index: usize) -> [u32; 4] {
let left = 200 + 30 * index as u32;
[left, 270, left + 24, 294]
@@ -263,4 +337,22 @@ mod tests {
Some(DesignerAction::Exit)
);
}
+
+ #[test]
+ fn equipment_click_addresses_the_scrolled_mount_or_a_populated_variant() {
+ assert_eq!(
+ equipment_hit([500.0, 46.0], 7, 9, 1),
+ Some(DesignerAction::Part(7))
+ );
+ assert_eq!(
+ equipment_hit([500.0, 56.0], 7, 9, 1),
+ Some(DesignerAction::Part(8))
+ );
+ 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))
+ );
+ assert_eq!(equipment_hit([30.0, 56.0], 7, 9, 1), None);
+ }
}