From 3b5a8aa4e6465ca56763cb96b4100bb1ff1c0ccf Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 18:50:37 +0400 Subject: 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. --- apps/fparkan-game/src/strategic_buildings_hud.rs | 92 ++++++++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 apps/fparkan-game/src/strategic_buildings_hud.rs (limited to 'apps/fparkan-game/src/strategic_buildings_hud.rs') diff --git a/apps/fparkan-game/src/strategic_buildings_hud.rs b/apps/fparkan-game/src/strategic_buildings_hud.rs new file mode 100644 index 00000000..b0b6b4ae --- /dev/null +++ b/apps/fparkan-game/src/strategic_buildings_hud.rs @@ -0,0 +1,92 @@ +use super::{ + mission_overlay::{add_overlay_sprite, overlay_texture}, + DirectoryVfs, EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer, +}; +use fparkan_assets::{ + strategic_buildings::{Images, Row, EXTENT, ORIGIN, TITLE}, + RgbaImage, +}; +use fparkan_platform_winit::text::StringResources; +use fparkan_runtime::strategic_buildings::BuildingRow; +use fparkan_world::ObjectHandle; +use std::path::Path; + +#[derive(PartialEq, Eq)] +pub(super) struct BuildingsFrame { + pub rows: Vec, + pub selected: Option, +} + +pub(super) struct StrategicBuildingsHud { + range: EnvironmentGpuRange, + images: Images, + strings: StringResources, + displayed: Option, +} + +impl StrategicBuildingsHud { + pub(super) fn load(root: &Path, preview: &mut StaticPreviewScene) -> Result { + let strings = StringResources::open(&root.join("iron3d.dll"))?; + let title = strings + .get(TITLE) + .ok_or("missing strategic buildings title")?; + let images = Images::load(&DirectoryVfs::new(root), &title)?; + let [width, height] = EXTENT; + let [x, y] = ORIGIN.map(|axis| axis as f32); + let range = add_overlay_sprite( + preview, + RgbaImage { + width, + height, + rgba8: vec![0; (width * height * 4) as usize], + }, + [x, y, x + width as f32, y + height as f32], + [1.0; 3], + 1.0, + )?; + Ok(Self { + range, + images, + strings, + displayed: None, + }) + } + + pub(super) fn range_index(&self) -> usize { + self.range.range_index + } + + pub(super) fn draw( + &mut self, + renderer: &mut VulkanSmokeRenderer, + frame: Option, + ) -> Result<(), String> { + renderer + .set_draw_range_index_count(self.range_index(), if frame.is_some() { 6 } else { 0 }) + .map_err(|error| error.to_string())?; + if frame == self.displayed { + return Ok(()); + } + if let Some(frame) = &frame { + let labels: Vec<_> = frame + .rows + .iter() + .map(|row| self.strings.get(row.label).unwrap_or_default()) + .collect(); + let image = self + .images + .paint(frame.rows.iter().zip(&labels).map(|(row, label)| Row { + label, + class: row.class, + size: row.size, + selected: frame.selected == Some(row.handle), + durability_percent: row.durability_percent, + }))?; + renderer + .update_material_texture(self.range.material_index, 0, &overlay_texture(image)) + .map_err(|error| error.to_string())?; + } + self.displayed = frame; + Ok(()) + } +} -- cgit v1.2.3