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/main.rs | 2 + apps/fparkan-game/src/mission_overlay.rs | 28 ++++- apps/fparkan-game/src/satellite_map.rs | 3 +- apps/fparkan-game/src/strategic_buildings_hud.rs | 92 ++++++++++++++ apps/fparkan-game/src/strategic_toolbar_hud.rs | 4 + apps/fparkan-game/src/strategic_view.rs | 152 ++++++++++++++++++++++- 6 files changed, 276 insertions(+), 5 deletions(-) create mode 100644 apps/fparkan-game/src/strategic_buildings_hud.rs (limited to 'apps/fparkan-game/src') diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index da0d9b30..a95b4879 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -41,6 +41,8 @@ mod satellite_map_chrome; #[cfg(windows)] mod strategic_balance_hud; #[cfg(windows)] +mod strategic_buildings_hud; +#[cfg(windows)] mod strategic_factory_hud; #[cfg(windows)] mod strategic_roster_hud; diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs index 406cf92c..43177b6a 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -14,9 +14,9 @@ use super::{ #[cfg(windows)] use super::{ mission_help::MissionHelp, mission_hints::MissionHints, - strategic_balance_hud::StrategicBalanceHud, strategic_factory_hud::StrategicFactoryHud, - strategic_roster_hud::StrategicRosterHud, strategic_tooltip_hud::StrategicTooltipHud, - weapon_hud::WeaponHud, + strategic_balance_hud::StrategicBalanceHud, strategic_buildings_hud::StrategicBuildingsHud, + strategic_factory_hud::StrategicFactoryHud, strategic_roster_hud::StrategicRosterHud, + strategic_tooltip_hud::StrategicTooltipHud, weapon_hud::WeaponHud, }; use fparkan_assets::RgbaImage; use fparkan_runtime::{ @@ -40,6 +40,8 @@ pub(super) struct MissionOverlay { #[cfg(windows)] pub(super) strategic_factory: Option, #[cfg(windows)] + pub(super) strategic_buildings: Option, + #[cfg(windows)] strategic_tooltip: Option, dial: Option, pub(super) factory_projects: Option, @@ -130,6 +132,12 @@ impl MissionOverlay { .ok() }); #[cfg(windows)] + let strategic_buildings = cockpit.and_then(|_| { + StrategicBuildingsHud::load(root, preview) + .inspect_err(|error| eprintln!("strategic_buildings_unavailable reason={error}")) + .ok() + }); + #[cfg(windows)] let weapons = cockpit.and_then(|cockpit| { WeaponHud::load(root, cockpit.handle, preview) .map(Some) @@ -186,6 +194,8 @@ impl MissionOverlay { #[cfg(windows)] strategic_factory, #[cfg(windows)] + strategic_buildings, + #[cfg(windows)] strategic_tooltip, dial, factory_projects, @@ -236,6 +246,10 @@ impl MissionOverlay { remove(factory.range_index(), ranges, counts); } #[cfg(windows)] + if let Some(buildings) = &self.strategic_buildings { + remove(buildings.range_index(), ranges, counts); + } + #[cfg(windows)] if let Some(tooltip) = &self.strategic_tooltip { remove(tooltip.range_index(), ranges, counts); } @@ -289,6 +303,8 @@ impl StaticVulkanApp { #[cfg(windows)] let warbot_rows = self.strategic_warbot_rows(); #[cfg(windows)] + let buildings_frame = self.strategic_buildings_frame(); + #[cfg(windows)] let row_count = warbot_rows.len(); #[cfg(windows)] let cursor = self.strategy_cursor(row_count); @@ -312,6 +328,7 @@ impl StaticVulkanApp { sections: fparkan_runtime::strategic_toolbar::available_sections(engine, cockpit), warbots_open: view.warbots_open, factories_open: view.factories_open(), + other_buildings_open: view.other_buildings_open(), map_open: self .overlay .satellite_map @@ -338,6 +355,10 @@ impl StaticVulkanApp { .as_ref() .and_then(|view| view.selected_warbot); #[cfg(windows)] + if let Some(buildings) = &mut self.overlay.strategic_buildings { + buildings.draw(renderer, buildings_frame)?; + } + #[cfg(windows)] if let Some(roster) = &mut self.overlay.strategic_roster { let card = selected_warbot .zip(self.mission_engine.as_ref()) @@ -387,6 +408,7 @@ impl StaticVulkanApp { demo_target .map(|target| target.handle) .or(selected_warbot) + .or_else(|| self.command_view.as_ref()?.selected_building()) .or_else(|| { fparkan_runtime::player_vehicle(engine) .map(|vehicle| vehicle.handle) diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs index 0be40008..26db6c3d 100644 --- a/apps/fparkan-game/src/satellite_map.rs +++ b/apps/fparkan-game/src/satellite_map.rs @@ -230,7 +230,8 @@ impl SatelliteMap { || (Vec::new(), Vec::new()), |((engine, cockpit, selected), extent)| { ( - satellite_contacts::visible_buildings(engine, cockpit, extent).collect(), + satellite_contacts::visible_buildings(engine, cockpit, extent, selected) + .collect(), satellite_contacts::visible_units(engine, cockpit, extent, selected) .map(|mut unit| { if let Some(points) = draft 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(()) + } +} diff --git a/apps/fparkan-game/src/strategic_toolbar_hud.rs b/apps/fparkan-game/src/strategic_toolbar_hud.rs index 7bd71cfe..2ad93a59 100644 --- a/apps/fparkan-game/src/strategic_toolbar_hud.rs +++ b/apps/fparkan-game/src/strategic_toolbar_hud.rs @@ -69,6 +69,9 @@ impl StrategicToolbarHud { if frame.factories_open && frame.sections[4] { visuals[5] = ButtonVisual::Lit; } + if frame.other_buildings_open && frame.sections[7] { + visuals[8] = ButtonVisual::Lit; + } // The chat button is disabled in a local mission. visuals[9] = ButtonVisual::Disabled; if frame.map_open { @@ -98,6 +101,7 @@ pub(super) struct ToolbarFrame { pub sections: [bool; 8], pub warbots_open: bool, pub factories_open: bool, + pub other_buildings_open: bool, pub map_open: bool, pub pointer: Option<[f32; 2]>, pub now_ms: u32, diff --git a/apps/fparkan-game/src/strategic_view.rs b/apps/fparkan-game/src/strategic_view.rs index ffb806ab..a7da38da 100644 --- a/apps/fparkan-game/src/strategic_view.rs +++ b/apps/fparkan-game/src/strategic_view.rs @@ -3,6 +3,8 @@ use super::{ PreviewCameraFrame, StaticVulkanApp, }; #[cfg(windows)] +use fparkan_assets::strategic_buildings::{self, Hit as BuildingHit}; +#[cfg(windows)] use fparkan_assets::strategic_factory::FactoryAction; use fparkan_assets::strategic_roster::{ covers_pointer, hit_test, order_at, CockpitControl, ListHit, RosterOrder, @@ -11,6 +13,8 @@ use fparkan_assets::strategy_cursor::StrategyCursor; use fparkan_assets::strategy_toolbar::{ command_button_at, ToolbarAction, ToolbarFold, ToolbarLayout, }; +#[cfg(windows)] +use fparkan_runtime::strategic_buildings::{other_buildings, BuildingRow}; use fparkan_runtime::strategic_roster::{warbot_rows, WarbotRow}; use fparkan_runtime::strategic_view::{ command_post, mobile_command_post, CommandCamera, CommandCameraInput, COMMAND_FOV, @@ -43,6 +47,10 @@ pub(super) struct ActiveCommandView { pub(super) warbots_open: bool, #[cfg(windows)] factory: Option, + #[cfg(windows)] + other_buildings_open: bool, + #[cfg(windows)] + selected_building: Option, pub(super) selected_warbot: Option, order_input: Option, } @@ -103,6 +111,45 @@ impl FactorySelection { } impl ActiveCommandView { + pub(super) fn other_buildings_open(&self) -> bool { + #[cfg(windows)] + return self.other_buildings_open; + #[cfg(not(windows))] + false + } + + pub(super) fn selected_building(&self) -> Option { + #[cfg(windows)] + return self.selected_building; + #[cfg(not(windows))] + None + } + + #[cfg(windows)] + fn select_building(&mut self, row: BuildingRow) -> Option { + if self.selected_building == Some(row.handle) { + return None; + } + self.selected_building = Some(row.handle); + self.selected_warbot = None; + Some(row) + } + + #[cfg(windows)] + fn refresh_building_selection(&mut self, rows: &[BuildingRow]) -> Option { + if rows + .iter() + .any(|row| Some(row.handle) == self.selected_building) + { + return None; + } + if let Some(&row) = rows.first() { + return self.select_building(row); + } + self.selected_building = None; + None + } + pub(super) fn factories_open(&self) -> bool { #[cfg(windows)] { @@ -221,6 +268,10 @@ impl StaticVulkanApp { warbots_open: false, #[cfg(windows)] factory: None, + #[cfg(windows)] + other_buildings_open: false, + #[cfg(windows)] + selected_building: None, selected_warbot: None, order_input: None, }); @@ -338,7 +389,9 @@ impl StaticVulkanApp { self.command_view.as_mut().filter(|view| view.warbots_open) { view.warbots_open = false; - } else if self.close_strategic_factory_panel() { + } else if self.close_strategic_buildings() + || self.close_strategic_factory_panel() + { return true; } else { self.close_strategy(); @@ -490,6 +543,8 @@ impl StaticVulkanApp { #[cfg(windows)] { view.factory = None; + view.other_buildings_open = false; + view.selected_building = None; } if let Some(row) = view.refresh_warbots(&warbot_rows(engine, cockpit)) { self.play_warbot_selection(row); @@ -513,12 +568,60 @@ impl StaticVulkanApp { { view.factory = Some(factory); view.warbots_open = false; + view.other_buildings_open = false; + view.selected_building = None; view.selected_warbot = None; view.order_input = None; } } } + Some(ToolbarAction::OtherBuildings) => + { + #[cfg(windows)] + if view.other_buildings_open { + view.other_buildings_open = false; + } else if self.overlay.strategic_buildings.is_some() { + let rows = other_buildings(engine, cockpit); + if !rows.is_empty() { + view.other_buildings_open = true; + view.factory = None; + view.warbots_open = false; + view.selected_warbot = None; + view.order_input = None; + if let Some(row) = view.refresh_building_selection(&rows) { + self.play_building_selection(row); + } + } + } + } None => { + #[cfg(windows)] + if !view.warbots_open && view.factory.is_none() && view.order_input.is_none() { + let map_hit = map + .as_deref() + .and_then(|map| map.command_destination(xy)) + .and_then(|point| satellite_contacts::pick_contact(engine, cockpit, point)); + let list_visible = + view.other_buildings_open && view.toolbar_layout().sections_visible(); + if list_visible || map_hit.is_some() { + let rows = other_buildings(engine, cockpit); + let row = match list_visible + .then(|| strategic_buildings::hit_test(xy, rows.len())) + .flatten() + { + Some(BuildingHit::Close) => { + view.other_buildings_open = false; + return; + } + Some(BuildingHit::Row(index)) => rows.get(index).copied(), + None => rows.into_iter().find(|row| Some(row.handle) == map_hit), + }; + if let Some(row) = row.and_then(|row| view.select_building(row)) { + self.play_building_selection(row); + } + return; + } + } #[cfg(windows)] if let Some(factory) = view .factory @@ -751,6 +854,20 @@ impl StaticVulkanApp { } } + #[cfg(windows)] + fn play_building_selection(&mut self, row: BuildingRow) { + if let Some(audio) = self.audio.as_mut() { + let voice = match row.size { + 1 | 2 => "VOICE_SELECTED_S", + 4 | 5 => "VOICE_SELECTED_B", + _ => "VOICE_SELECTED", + }; + if let Err(error) = audio.queue_game_voice(voice) { + eprintln!("sim_coverage mission_voice_unavailable=1 notice={voice} reason={error}"); + } + } + } + pub(super) fn advance_strategy_toolbar(&mut self, now_ms: u32) { let Some(view) = self .command_view @@ -786,6 +903,39 @@ impl StaticVulkanApp { } } + fn close_strategic_buildings(&mut self) -> bool { + #[cfg(windows)] + return self + .command_view + .as_mut() + .is_some_and(|view| std::mem::take(&mut view.other_buildings_open)); + #[cfg(not(windows))] + false + } + + #[cfg(windows)] + pub(super) fn strategic_buildings_frame( + &mut self, + ) -> Option { + let view = self + .command_view + .as_mut() + .filter(|view| view.other_buildings_open)?; + let (engine, cockpit) = self.mission_engine.as_ref().zip(self.cockpit)?; + let rows = other_buildings(engine, cockpit); + let changed = view.refresh_building_selection(&rows); + let frame = view.toolbar_layout().sections_visible().then_some( + super::strategic_buildings_hud::BuildingsFrame { + rows, + selected: view.selected_building, + }, + ); + if let Some(row) = changed { + self.play_building_selection(row); + } + frame + } + #[cfg(windows)] pub(super) fn strategic_factory_frame( &mut self, -- cgit v1.2.3