From 9f442fa339371869dda44a32a9e0ec2f763d830c Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 19:05:52 +0400 Subject: feat(ui): connect the bunker list to the strategic camera Show clan bunkers with the original compound controls and map selection. The strategic command button switches the camera anchor and preserves a view already bound to that bunker. Check the stock Two Fortresses window with Vulkan validation and exercise retargeting and the ownership guard with the licensed runtime test. --- crates/fparkan-assets/src/strategic_buildings.rs | 86 +++++++++++++++++++----- crates/fparkan-assets/src/strategy_toolbar.rs | 3 + 2 files changed, 71 insertions(+), 18 deletions(-) (limited to 'crates/fparkan-assets/src') diff --git a/crates/fparkan-assets/src/strategic_buildings.rs b/crates/fparkan-assets/src/strategic_buildings.rs index 53deabdf..0ed6d140 100644 --- a/crates/fparkan-assets/src/strategic_buildings.rs +++ b/crates/fparkan-assets/src/strategic_buildings.rs @@ -1,4 +1,4 @@ -//! Compound controls of the strategic «Другие здания» section. +//! Shared compound controls of the strategic building sections. use crate::{ game_font::{load_layout_font, BitmapFont}, @@ -15,16 +15,19 @@ 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; +const COMMAND_LEFT: u32 = 34; +const BUTTON_WIDTH: u32 = 35; +pub const COMMAND_TOOLTIP: u32 = 0x5ed; pub const VISIBLE_ROWS: usize = (EXTENT[1] / ROW_PITCH - 1) as usize; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Hit { Close, Row(usize), + Command(usize), } -pub fn hit_test([x, y]: [f32; 2], rows: usize) -> Option { +pub fn hit_test([x, y]: [f32; 2], rows: usize, command_buttons: bool) -> Option { 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) { @@ -35,7 +38,15 @@ pub fn hit_test([x, y]: [f32; 2], rows: usize) -> Option { } 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)) + if row >= rows.min(VISIBLE_ROWS) || y % ROW_PITCH >= ROW_HEIGHT { + return None; + } + let command = COMMAND_LEFT as f32..(COMMAND_LEFT + BUTTON_WIDTH) as f32; + if command_buttons && command.contains(&x) { + Some(Hit::Command(row)) + } else { + Some(Hit::Row(row)) + } } pub struct Row<'a> { @@ -56,10 +67,12 @@ pub struct Images { ray: RgbaImage, end: RgbaImage, atlas: RgbaImage, + command_frame: [RgbaImage; 2], + command_icon: RgbaImage, } impl Images { - pub fn load(vfs: &dyn Vfs, title: &str) -> Result { + pub fn load(vfs: &dyn Vfs) -> Result { let [title_cap, frame, close, cap_off, cap_on, separator, emitter_off, emitter_on, ray, end] = load_ui_sprites( vfs, @@ -77,7 +90,16 @@ impl Images { "ccres_ray_ending", ], )?; - let [exit] = load_ui_sprites(vfs, "ui/hq.cfg", ["exit_icon"])?; + let [exit, command_off, command_on, command_icon] = load_ui_sprites( + vfs, + "ui/hq.cfg", + [ + "exit_icon", + "buildscreen_button1", + "buildscreen_button2", + "buildscreen_direct_icon", + ], + )?; let font = load_layout_font(vfs)?; let [width, height] = EXTENT; let mut header = RgbaImage { @@ -93,7 +115,6 @@ impl Images { ] { stamp(&mut header, sprite, rect, [255; 3]); } - text(&font, &mut header, title, [5, 0, 283, 19], [255; 3])?; Ok(Self { header, font, @@ -104,25 +125,50 @@ impl Images { ray, end, atlas: load_ui_page(vfs, "ui_menu")?, + command_frame: [command_off, command_on], + command_icon, }) } - pub fn paint<'a>(&self, rows: impl Iterator>) -> Result { + pub fn paint<'a>( + &self, + title: &str, + command_buttons: bool, + rows: impl Iterator>, + ) -> Result { let mut image = self.header.clone(); + text(&self.font, &mut image, title, [5, 0, 283, 19], [255; 3])?; 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); + // The original bunker layout measures the label after two 35-unit controls. + let emitter = COMMAND_LEFT + if command_buttons { 2 * BUTTON_WIDTH } else { 0 }; + let text_left = emitter + (TEXT_LEFT - COMMAND_LEFT); 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.emitter[selected], emitter, emitter + 11), + (&self.ray, text_left, TEXT_RIGHT + 1), (&self.end, TEXT_RIGHT, EXTENT[0]), ] { stamp(&mut image, sprite, [left, y, right, bottom], [255; 3]); } + if command_buttons { + stamp( + &mut image, + &self.command_frame[selected], + [COMMAND_LEFT, y, COMMAND_LEFT + BUTTON_WIDTH + 1, bottom], + [255; 3], + ); + stamp( + &mut image, + &self.command_icon, + [COMMAND_LEFT + 10, y + 2, COMMAND_LEFT + 25, y + 17], + [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")?; @@ -135,7 +181,7 @@ impl Images { } if let Some((width, rgba)) = row .durability_percent - .and_then(|percent| durability_fill(percent, TEXT_RIGHT - TEXT_LEFT)) + .and_then(|percent| durability_fill(percent, TEXT_RIGHT - text_left)) { let fill = RgbaImage { width: 1, @@ -145,7 +191,7 @@ impl Images { stamp( &mut image, &fill, - [TEXT_LEFT + 2, y + 3, TEXT_LEFT + width, bottom - 3], + [text_left + 2, y + 3, text_left + width, bottom - 3], [255; 3], ); } @@ -153,7 +199,7 @@ impl Images { &self.font, &mut image, row.label, - [TEXT_LEFT, y, TEXT_RIGHT, bottom], + [text_left, y, TEXT_RIGHT, bottom], if row.selected { [255; 3] } else { [128; 3] }, )?; } @@ -167,10 +213,14 @@ mod tests { #[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); + assert_eq!(hit_test([350.0, 9.0], 4, false), Some(Hit::Close)); + assert_eq!(hit_test([68.0, 39.0], 4, false), None); + assert_eq!(hit_test([68.0, 40.0], 4, false), Some(Hit::Row(1))); + assert_eq!(hit_test([340.0, 49.0], 4, false), Some(Hit::Row(1))); + assert_eq!(hit_test([340.0, 49.0], 1, false), None); + assert_eq!(hit_test([102.0, 25.0], 1, true), Some(Hit::Command(0))); + assert_eq!(hit_test([102.0, 25.0], 1, false), Some(Hit::Row(0))); + assert_eq!(hit_test([119.0, 25.0], 1, true), Some(Hit::Command(0))); + assert_eq!(hit_test([120.0, 25.0], 1, true), Some(Hit::Row(0))); } } diff --git a/crates/fparkan-assets/src/strategy_toolbar.rs b/crates/fparkan-assets/src/strategy_toolbar.rs index 29737335..e7c5ca11 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 bunkers. + Bunkers, /// Toggle the clan's other buildings. OtherBuildings, /// Toggle the satellite map. @@ -44,6 +46,7 @@ pub fn command_button_at([x, y]: [f32; 2]) -> Option { 0 => Some(ToolbarAction::Hero), 1 => Some(ToolbarAction::Warbots), 5 => Some(ToolbarAction::Factories), + 7 => Some(ToolbarAction::Bunkers), 8 => Some(ToolbarAction::OtherBuildings), 10 => Some(ToolbarAction::Map), _ => None, -- cgit v1.2.3