aboutsummaryrefslogtreecommitdiff
path: root/crates/fparkan-assets
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 17:50:37 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 17:50:37 +0300
commit3b5a8aa4e6465ca56763cb96b4100bb1ff1c0ccf (patch)
tree7ccd3b6b20a2211d3c2f72f0707f2d28f9faaf2c /crates/fparkan-assets
parentbd7811533a348e56d2be9c7281d0533fc8c46024 (diff)
downloadfparkan-3b5a8aa4e6465ca56763cb96b4100bb1ff1c0ccf.tar.xz
fparkan-3b5a8aa4e6465ca56763cb96b4100bb1ff1c0ccf.zip
feat(ui): link the other buildings panel to the satellite map
Use the installed compound controls, font, and class glyphs for live clan buildings and their durability. Compare the stock Two Fortresses list order, first selection, two-way map selection, and close behavior in the original and in FParkan with Vulkan validation.
Diffstat (limited to 'crates/fparkan-assets')
-rw-r--r--crates/fparkan-assets/src/lib.rs1
-rw-r--r--crates/fparkan-assets/src/satellite_map_chrome.rs40
-rw-r--r--crates/fparkan-assets/src/strategic_buildings.rs176
-rw-r--r--crates/fparkan-assets/src/strategic_factory.rs4
-rw-r--r--crates/fparkan-assets/src/strategy_toolbar.rs3
5 files changed, 209 insertions, 15 deletions
diff --git a/crates/fparkan-assets/src/lib.rs b/crates/fparkan-assets/src/lib.rs
index 5d4973ef..295ed772 100644
--- a/crates/fparkan-assets/src/lib.rs
+++ b/crates/fparkan-assets/src/lib.rs
@@ -48,6 +48,7 @@ pub mod object_descriptions;
pub mod satellite_map;
pub mod satellite_map_chrome;
pub mod strategic_balance;
+pub mod strategic_buildings;
pub mod strategic_factory;
pub mod strategic_roster;
pub mod strategy_cursor;
diff --git a/crates/fparkan-assets/src/satellite_map_chrome.rs b/crates/fparkan-assets/src/satellite_map_chrome.rs
index 30b41e06..5ae81bea 100644
--- a/crates/fparkan-assets/src/satellite_map_chrome.rs
+++ b/crates/fparkan-assets/src/satellite_map_chrome.rs
@@ -172,9 +172,7 @@ impl MapChrome {
(false, 2) => [255, 128, 128],
(false, 3) => [128, 255, 128],
(false, 4) => [128, 128, 255],
- (true, 2) => [255, 0, 0],
- (true, 3) => [0, 255, 0],
- (true, 4 | 5) => [0, 0, 255],
+ (true, size) => building_glyph_tint(size),
_ => [255; 3],
};
let atlas = if contact.class == 0x8000_0200 {
@@ -186,16 +184,7 @@ impl MapChrome {
0x0100_2000 => Some([81, 110]),
0x0100_4000 => Some([65, 110]),
0x0100_8000 | 0x0101_0000 | 0x0102_0000 => Some([49, 110]),
- 0x8000_0002 => Some([113, 126]),
- 0x8000_0004 => Some([129, 126]),
- 0x8000_0008 => Some([81, 110]),
- 0x8000_0010 => Some([129, 94]),
- 0x8000_0040 => Some([97, 126]),
- 0x8000_0200 => Some([148, 27]),
- 0x8000_0400 => Some([49, 126]),
- 0x8001_0000 | 0x8002_0000 | 0x8004_0000 => Some([65, 126]),
- 0x8010_0000 | 0x8020_0000 => Some([81, 126]),
- _ => None,
+ class => building_glyph(class),
};
if let Some(glyph) = class.and_then(|[x, y]| atlas_region(atlas, [x, y, 15, 15])) {
stamp(image, &glyph, [26, 2, 41, 17], tint);
@@ -215,6 +204,31 @@ impl MapChrome {
}
}
+// The list and map readout both call iron3d+0x346a0 for building glyphs.
+pub(crate) fn building_glyph(class: u32) -> Option<[u32; 2]> {
+ Some(match class {
+ 0x8000_0002 => [113, 126],
+ 0x8000_0004 => [129, 126],
+ 0x8000_0008 => [81, 110],
+ 0x8000_0010 => [129, 94],
+ 0x8000_0040 => [97, 126],
+ 0x8000_0200 => [148, 27],
+ 0x8000_0400 => [49, 126],
+ 0x8001_0000 | 0x8002_0000 | 0x8004_0000 => [65, 126],
+ 0x8010_0000 | 0x8020_0000 => [81, 126],
+ _ => return None,
+ })
+}
+
+pub(crate) fn building_glyph_tint(size: u32) -> [u8; 3] {
+ match size {
+ 2 => [255, 0, 0],
+ 3 => [0, 255, 0],
+ 4 | 5 => [0, 0, 255],
+ _ => [255; 3],
+ }
+}
+
fn empty_strip() -> RgbaImage {
RgbaImage {
width: WIDTH,
diff --git a/crates/fparkan-assets/src/strategic_buildings.rs b/crates/fparkan-assets/src/strategic_buildings.rs
new file mode 100644
index 00000000..53deabdf
--- /dev/null
+++ b/crates/fparkan-assets/src/strategic_buildings.rs
@@ -0,0 +1,176 @@
+//! Compound controls of the strategic «Другие здания» section.
+
+use crate::{
+ game_font::{load_layout_font, BitmapFont},
+ satellite_map_chrome::{building_glyph, building_glyph_tint},
+ strategic_factory::{stamp, text},
+ strategic_roster::durability_fill,
+ ui_sprite::{atlas_region, load_ui_page, load_ui_sprites},
+ RgbaImage,
+};
+use fparkan_vfs::Vfs;
+
+pub use crate::strategic_factory::{EXTENT, ORIGIN};
+const ROW_PITCH: u32 = 20;
+const ROW_HEIGHT: u32 = 19;
+const TEXT_LEFT: u32 = 44;
+const TEXT_RIGHT: u32 = 313;
+pub const TITLE: u32 = 0x64a;
+pub const VISIBLE_ROWS: usize = (EXTENT[1] / ROW_PITCH - 1) as usize;
+
+#[derive(Clone, Copy, Debug, PartialEq, Eq)]
+pub enum Hit {
+ Close,
+ Row(usize),
+}
+
+pub fn hit_test([x, y]: [f32; 2], rows: usize) -> Option<Hit> {
+ let x = x.round_ties_even() - ORIGIN[0] as f32;
+ let y = y.round_ties_even();
+ if (283.0..318.0).contains(&x) && (0.0..19.0).contains(&y) {
+ return Some(Hit::Close);
+ }
+ if !(0.0..(EXTENT[0] - 1) as f32).contains(&x) || !(20.0..480.0).contains(&y) {
+ return None;
+ }
+ let y = y as u32 - ROW_PITCH;
+ let row = (y / ROW_PITCH) as usize;
+ (row < rows.min(VISIBLE_ROWS) && y % ROW_PITCH < ROW_HEIGHT).then_some(Hit::Row(row))
+}
+
+pub struct Row<'a> {
+ pub label: &'a str,
+ pub class: u32,
+ pub size: u32,
+ pub selected: bool,
+ pub durability_percent: Option<i32>,
+}
+
+pub struct Images {
+ header: RgbaImage,
+ font: BitmapFont,
+ cap: [RgbaImage; 2],
+ frame: RgbaImage,
+ separator: RgbaImage,
+ emitter: [RgbaImage; 2],
+ ray: RgbaImage,
+ end: RgbaImage,
+ atlas: RgbaImage,
+}
+
+impl Images {
+ pub fn load(vfs: &dyn Vfs, title: &str) -> Result<Self, String> {
+ let [title_cap, frame, close, cap_off, cap_on, separator, emitter_off, emitter_on, ray, end] =
+ load_ui_sprites(
+ vfs,
+ "ui/compaund.cfg",
+ [
+ "ccres_ending_text",
+ "ccres_body_text",
+ "ccres_exit_button_pressed",
+ "ccres_lamp_stub_ending_off",
+ "ccres_lamp_stub_ending_normal",
+ "ccres_separator_left_text",
+ "ccres_ray_emitter_off",
+ "ccres_ray_emitter_normal",
+ "ccres_ray_body",
+ "ccres_ray_ending",
+ ],
+ )?;
+ let [exit] = load_ui_sprites(vfs, "ui/hq.cfg", ["exit_icon"])?;
+ let font = load_layout_font(vfs)?;
+ let [width, height] = EXTENT;
+ let mut header = RgbaImage {
+ width,
+ height,
+ rgba8: vec![0; (width * height * 4) as usize],
+ };
+ for (sprite, rect) in [
+ (&title_cap, [0, 0, 6, 19]),
+ (&frame, [5, 0, 284, 19]),
+ (&close, [283, 0, 318, 19]),
+ (&exit, [298, 3, 311, 16]),
+ ] {
+ stamp(&mut header, sprite, rect, [255; 3]);
+ }
+ text(&font, &mut header, title, [5, 0, 283, 19], [255; 3])?;
+ Ok(Self {
+ header,
+ font,
+ cap: [cap_off, cap_on],
+ frame,
+ separator,
+ emitter: [emitter_off, emitter_on],
+ ray,
+ end,
+ atlas: load_ui_page(vfs, "ui_menu")?,
+ })
+ }
+
+ pub fn paint<'a>(&self, rows: impl Iterator<Item = Row<'a>>) -> Result<RgbaImage, String> {
+ let mut image = self.header.clone();
+ for (index, row) in rows.take(VISIBLE_ROWS).enumerate() {
+ let y = (index as u32 + 1) * ROW_PITCH;
+ let bottom = y + ROW_HEIGHT;
+ let selected = usize::from(row.selected);
+ for (sprite, left, right) in [
+ (&self.cap[selected], 0, 11),
+ (&self.frame, 10, 30),
+ (&self.separator, 29, 35),
+ (&self.emitter[selected], 34, 45),
+ (&self.ray, TEXT_LEFT, TEXT_RIGHT + 1),
+ (&self.end, TEXT_RIGHT, EXTENT[0]),
+ ] {
+ stamp(&mut image, sprite, [left, y, right, bottom], [255; 3]);
+ }
+ if let Some([x, atlas_y]) = building_glyph(row.class) {
+ let glyph = atlas_region(&self.atlas, [x, atlas_y, 15, 15])
+ .ok_or("building glyph outside ui_menu")?;
+ stamp(
+ &mut image,
+ &glyph,
+ [12, y + 2, 27, y + 17],
+ building_glyph_tint(row.size),
+ );
+ }
+ if let Some((width, rgba)) = row
+ .durability_percent
+ .and_then(|percent| durability_fill(percent, TEXT_RIGHT - TEXT_LEFT))
+ {
+ let fill = RgbaImage {
+ width: 1,
+ height: 1,
+ rgba8: rgba.to_vec(),
+ };
+ stamp(
+ &mut image,
+ &fill,
+ [TEXT_LEFT + 2, y + 3, TEXT_LEFT + width, bottom - 3],
+ [255; 3],
+ );
+ }
+ text(
+ &self.font,
+ &mut image,
+ row.label,
+ [TEXT_LEFT, y, TEXT_RIGHT, bottom],
+ if row.selected { [255; 3] } else { [128; 3] },
+ )?;
+ }
+ Ok(image)
+ }
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn building_list_hits_labels_icons_and_close_with_native_row_gaps() {
+ assert_eq!(hit_test([350.0, 9.0], 4), Some(Hit::Close));
+ assert_eq!(hit_test([68.0, 39.0], 4), None);
+ assert_eq!(hit_test([68.0, 40.0], 4), Some(Hit::Row(1)));
+ assert_eq!(hit_test([340.0, 49.0], 4), Some(Hit::Row(1)));
+ assert_eq!(hit_test([340.0, 49.0], 1), None);
+ }
+}
diff --git a/crates/fparkan-assets/src/strategic_factory.rs b/crates/fparkan-assets/src/strategic_factory.rs
index 1cf6d8a4..cc4eb491 100644
--- a/crates/fparkan-assets/src/strategic_factory.rs
+++ b/crates/fparkan-assets/src/strategic_factory.rs
@@ -373,11 +373,11 @@ impl FactoryImages {
}
}
-fn stamp(image: &mut RgbaImage, sprite: &RgbaImage, rect: [u32; 4], tint: [u8; 3]) {
+pub(crate) fn stamp(image: &mut RgbaImage, sprite: &RgbaImage, rect: [u32; 4], tint: [u8; 3]) {
copy_sprite(image, sprite, rect, [false; 2], tint);
}
-fn text(
+pub(crate) fn text(
font: &BitmapFont,
image: &mut RgbaImage,
label: &str,
diff --git a/crates/fparkan-assets/src/strategy_toolbar.rs b/crates/fparkan-assets/src/strategy_toolbar.rs
index a50520c2..29737335 100644
--- a/crates/fparkan-assets/src/strategy_toolbar.rs
+++ b/crates/fparkan-assets/src/strategy_toolbar.rs
@@ -31,6 +31,8 @@ pub enum ToolbarAction {
Warbots,
/// Toggle the clan's factory panel.
Factories,
+ /// Toggle the clan's other buildings.
+ OtherBuildings,
/// Toggle the satellite map.
Map,
}
@@ -42,6 +44,7 @@ pub fn command_button_at([x, y]: [f32; 2]) -> Option<ToolbarAction> {
0 => Some(ToolbarAction::Hero),
1 => Some(ToolbarAction::Warbots),
5 => Some(ToolbarAction::Factories),
+ 8 => Some(ToolbarAction::OtherBuildings),
10 => Some(ToolbarAction::Map),
_ => None,
}