diff options
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 2 | ||||
| -rw-r--r-- | apps/fparkan-game/src/mission_overlay.rs | 28 | ||||
| -rw-r--r-- | apps/fparkan-game/src/satellite_map.rs | 3 | ||||
| -rw-r--r-- | apps/fparkan-game/src/strategic_buildings_hud.rs | 92 | ||||
| -rw-r--r-- | apps/fparkan-game/src/strategic_toolbar_hud.rs | 4 | ||||
| -rw-r--r-- | apps/fparkan-game/src/strategic_view.rs | 152 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/satellite_map_chrome.rs | 40 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/strategic_buildings.rs | 176 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/strategic_factory.rs | 4 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/strategy_toolbar.rs | 3 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/satellite_contacts.rs | 24 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/strategic_buildings.rs | 112 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/strategic_toolbar.rs | 2 | ||||
| -rw-r--r-- | docs/appendices/ui-shell.md | 24 |
16 files changed, 642 insertions, 26 deletions
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<StrategicFactoryHud>, #[cfg(windows)] + pub(super) strategic_buildings: Option<StrategicBuildingsHud>, + #[cfg(windows)] strategic_tooltip: Option<StrategicTooltipHud>, dial: Option<CockpitDial>, pub(super) factory_projects: Option<FactoryProjectPanel>, @@ -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<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(()) + } +} 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<FactorySelection>, + #[cfg(windows)] + other_buildings_open: bool, + #[cfg(windows)] + selected_building: Option<ObjectHandle>, pub(super) selected_warbot: Option<ObjectHandle>, order_input: Option<OrderInput>, } @@ -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<ObjectHandle> { + #[cfg(windows)] + return self.selected_building; + #[cfg(not(windows))] + None + } + + #[cfg(windows)] + fn select_building(&mut self, row: BuildingRow) -> Option<BuildingRow> { + 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<BuildingRow> { + 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,13 +568,61 @@ 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 .as_mut() @@ -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<super::strategic_buildings_hud::BuildingsFrame> { + 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, 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, } diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 83aac64c..ad030b00 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -73,6 +73,7 @@ mod node_stage; mod projectile_capacity; pub mod satellite_contacts; pub mod strategic_balance; +pub mod strategic_buildings; pub mod strategic_map_readout; pub mod strategic_orders; pub mod strategic_roster; diff --git a/crates/fparkan-runtime/src/satellite_contacts.rs b/crates/fparkan-runtime/src/satellite_contacts.rs index 31181bc1..13c918a4 100644 --- a/crates/fparkan-runtime/src/satellite_contacts.rs +++ b/crates/fparkan-runtime/src/satellite_contacts.rs @@ -73,12 +73,26 @@ pub fn visible_buildings( engine: &Engine, cockpit: StartingCockpit, extent: f32, + selected: Option<ObjectHandle>, ) -> impl Iterator<Item = BuildingContact> + '_ { + let selected = selected.filter(|&target| { + identity_metadata(&engine.world, target) + .ok() + .and_then(|identity| identity.owner_id) + .is_some_and(|owner| { + identity_metadata(&engine.world, cockpit.handle) + .is_ok_and(|identity| identity.owner_id == Some(owner)) + }) + }); visible_contacts(engine, cockpit, extent, |_, class| icon_x(class)).map( - |(pixel, _, _, tint, icon_x)| BuildingContact { + move |(pixel, handle, _, tint, icon_x)| BuildingContact { pixel, icon_x, - tint, + tint: if Some(handle) == selected { + [255; 3] + } else { + tint + }, }, ) } @@ -460,14 +474,14 @@ mod tests { icon_x: 72, tint: super::OWN_TINT, }; - assert!(!visible_buildings(&engine, cockpit, extent).any(|contact| contact == marker)); + assert!(!visible_buildings(&engine, cockpit, extent, None).any(|contact| contact == marker)); let owner = identity_metadata(&engine.world, cockpit.handle) .unwrap() .owner_id; assert!(owner.is_some()); set_owner(&mut engine.world, handle, owner).unwrap(); - assert!(visible_buildings(&engine, cockpit, extent).any(|contact| contact == marker)); + assert!(visible_buildings(&engine, cockpit, extent, None).any(|contact| contact == marker)); let table = loaded_mission_control_device_tables(&engine) .unwrap() @@ -488,6 +502,6 @@ mod tests { assert!(registration_sequence(&engine.world, handle) .unwrap() .is_some()); - assert!(!visible_buildings(&engine, cockpit, extent).any(|contact| contact == marker)); + assert!(!visible_buildings(&engine, cockpit, extent, None).any(|contact| contact == marker)); } } diff --git a/crates/fparkan-runtime/src/strategic_buildings.rs b/crates/fparkan-runtime/src/strategic_buildings.rs new file mode 100644 index 00000000..91024136 --- /dev/null +++ b/crates/fparkan-runtime/src/strategic_buildings.rs @@ -0,0 +1,112 @@ +//! Live rows of the strategic «Другие здания» section. + +use crate::{strategic_map_readout::building_label, Engine, StartingCockpit}; +use fparkan_world::{identity_metadata, registration_sequence, ObjectHandle}; +use std::cmp::Reverse; + +pub(super) const OTHER_BUILDINGS: u32 = 0x8000_044e; + +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub struct BuildingRow { + pub handle: ObjectHandle, + pub class: u32, + pub size: u32, + pub label: u32, + pub durability_percent: Option<i32>, +} + +/// Buildings of the operator's clan, most recently registered first. +pub fn other_buildings(engine: &Engine, cockpit: StartingCockpit) -> Vec<BuildingRow> { + let Some((mission, owner)) = engine.loaded.as_ref().zip( + identity_metadata(&engine.world, cockpit.handle) + .ok() + .and_then(|identity| identity.owner_id), + ) else { + return Vec::new(); + }; + let mut rows: Vec<_> = mission + .control_device_tables + .iter() + .filter_map(|table| { + let handle = table.handle; + let draft = mission.object_drafts.get(table.original_id?.0 as usize)?; + let class = draft.unit_dat_header_flags?; + if class == 0 + || class & OTHER_BUILDINGS != class + || table.node_provider_depletion_marked + || identity_metadata(&engine.world, handle).ok()?.owner_id != Some(owner) + { + return None; + } + let sequence = registration_sequence(&engine.world, handle).ok()??; + let size = + crate::unit_size_class::classify(3, &draft.unit_components.first()?.resource_raw); + let row = BuildingRow { + handle, + class, + size, + label: building_label(class, size), + durability_percent: crate::warbot_stats::durability_percent(table), + }; + Some((sequence, row)) + }) + .collect(); + rows.sort_unstable_by_key(|(sequence, _)| Reverse(*sequence)); + rows.into_iter().map(|(_, row)| row).collect() +} + +#[cfg(test)] +mod tests { + use super::*; + use crate::{ + create, frame, load_gameplay_mission, satellite_contacts, starting_cockpit, EngineServices, + MissionMode, MissionRequest, MissionStartupInput, + }; + use fparkan_vfs::DirectoryVfs; + use std::sync::Arc; + + #[test] + #[ignore = "requires licensed mission resources"] + fn two_fortresses_lists_owned_buildings_and_whitens_only_the_selected_map_icon() { + let root = std::env::var_os("FPARKAN_CORPUS_PART1_ROOT").expect("licensed corpus"); + let mut engine = create(EngineServices::new(Arc::new(DirectoryVfs::new(root)))).unwrap(); + load_gameplay_mission( + &mut engine, + MissionRequest { + key: "MISSIONS/Single.01/data.tma".into(), + mode: MissionMode::SingleMission, + }, + MissionStartupInput { + queue_time_ms: 0, + research_creation_gate: false, + }, + None, + ) + .unwrap(); + frame(&mut engine, 1).unwrap(); + let cockpit = starting_cockpit(&engine).unwrap(); + let rows = other_buildings(&engine, cockpit); + assert_eq!( + rows.iter().map(|row| row.label).collect::<Vec<_>>(), + [0x179e, 0x178f, 0x1794, 0x1799] + ); + let extent = satellite_contacts::landscape_extent(&engine).unwrap(); + let before: Vec<_> = + satellite_contacts::visible_buildings(&engine, cockpit, extent, None).collect(); + let after: Vec<_> = + satellite_contacts::visible_buildings(&engine, cockpit, extent, Some(rows[1].handle)) + .collect(); + assert_eq!(before.len(), after.len()); + let changed: Vec<_> = before.iter().zip(&after).filter(|(a, b)| a != b).collect(); + assert_eq!(changed.len(), 1); + let (normal, selected) = changed[0]; + assert_eq!(normal.tint, satellite_contacts::OWN_TINT); + assert_eq!( + *selected, + satellite_contacts::BuildingContact { + tint: [255; 3], + ..*normal + } + ); + } +} diff --git a/crates/fparkan-runtime/src/strategic_toolbar.rs b/crates/fparkan-runtime/src/strategic_toolbar.rs index e35c19b0..de35f695 100644 --- a/crates/fparkan-runtime/src/strategic_toolbar.rs +++ b/crates/fparkan-runtime/src/strategic_toolbar.rs @@ -12,7 +12,7 @@ const SECTION_MASKS: [u32; 8] = [ 0x8000_0010, 0x8030_0000, 0x8007_0000, - 0x8000_044e, + crate::strategic_buildings::OTHER_BUILDINGS, ]; /// Availability for warbots, builders, transports, labs, factories, towers, diff --git a/docs/appendices/ui-shell.md b/docs/appendices/ui-shell.md index ce04f047..86f73402 100644 --- a/docs/appendices/ui-shell.md +++ b/docs/appendices/ui-shell.md @@ -543,6 +543,30 @@ RVA `0x97fe0` передаёт признак серии в заявку `0x205` бесплатной сборки у выбранного завода. Строки подсказок задаёт RVA `0x965f0`. [Хеши GOG-сборок](../reference/original-binaries.md) +### Другие здания + +Кнопка «Другие здания» выбирает группу `0x8000044e` +(`iron3d.dll`, RVA `0x85160`). В неё входят генераторы, шахты, +склады, ангары и лаборатории. Обход реестра в RVA `0x7e310` +идёт от последних зарегистрированных зданий к первым, проверяет клан и пропускает объекты +с признаком истощения Control `0xfffe`. В «Двух крепостях» первыми +видны малая лаборатория, малая шахта, малый склад и малый генератор. + +Рамки строк и лампы выбора берутся из `ui/compaund.cfg`. +Строки начинаются под заголовком и идут с шагом 20 в системе 640×480. +RVA `0x96190` строит строку из нескольких частей и передаёт выбор +лампам и подписи. Длина и цвет полосы под названием показывают +текущую прочность здания (RVA `0x7eda0`, `0x9a320`). +Значок класса берётся из `ui_menu` по той же таблице, +что и в карточке контакта на карте (RVA `0x346a0`). + +Щелчок по строке выбирает здание и выделяет его белым на карте. +Щелчок по своему зданию на карте меняет ту же строку. Кнопка выхода в +заголовке закрывает список, сохраняя выбор. При первом открытии выбирается первая +строка, если среди объектов раздела ещё нет выбранного здания +(RVA `0x85240` и `0x86480`). +[Хеши GOG-сборок](../reference/original-binaries.md) + ### Приказы варботу Панель начинается на X = 100 сразу под списком. `iron3d.dll` по RVA |
