diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 17:50:37 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 17:50:37 +0300 |
| commit | 3b5a8aa4e6465ca56763cb96b4100bb1ff1c0ccf (patch) | |
| tree | 7ccd3b6b20a2211d3c2f72f0707f2d28f9faaf2c /apps/fparkan-game/src/strategic_buildings_hud.rs | |
| parent | bd7811533a348e56d2be9c7281d0533fc8c46024 (diff) | |
| download | fparkan-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 'apps/fparkan-game/src/strategic_buildings_hud.rs')
| -rw-r--r-- | apps/fparkan-game/src/strategic_buildings_hud.rs | 92 |
1 files changed, 92 insertions, 0 deletions
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<BuildingRow>, + pub selected: Option<ObjectHandle>, +} + +pub(super) struct StrategicBuildingsHud { + range: EnvironmentGpuRange, + images: Images, + strings: StringResources, + displayed: Option<BuildingsFrame>, +} + +impl StrategicBuildingsHud { + pub(super) fn load(root: &Path, preview: &mut StaticPreviewScene) -> Result<Self, String> { + 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<BuildingsFrame>, + ) -> 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(()) + } +} |
