diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 11:28:48 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 11:28:48 +0300 |
| commit | 0b0764de47a0a1fef30464fb5e4be496e101b083 (patch) | |
| tree | 91d129a508a0e2fdbedfdeadf7b9fa5bbd0f1a2e /crates/fparkan-assets/src | |
| parent | 733f9d92e0d4e40ed40db42fa6cd11294e49eb7b (diff) | |
| download | fparkan-0b0764de47a0a1fef30464fb5e4be496e101b083.tar.xz fparkan-0b0764de47a0a1fef30464fb5e4be496e101b083.zip | |
feat(ui): assign patrols from the strategic warbot panel
Use the installed order string and GUARD cursor. A single valid click assigns a 300-unit patrol around a terrain point or a live object. Checked the terrain and satellite paths, rejected terrain, and cancellation in the stock Two Fortresses window.
Diffstat (limited to 'crates/fparkan-assets/src')
| -rw-r--r-- | crates/fparkan-assets/src/strategic_roster.rs | 2 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/strategic_roster/orders.rs | 32 | ||||
| -rw-r--r-- | crates/fparkan-assets/src/strategy_cursor.rs | 9 |
3 files changed, 32 insertions, 11 deletions
diff --git a/crates/fparkan-assets/src/strategic_roster.rs b/crates/fparkan-assets/src/strategic_roster.rs index 64c819a1..6c755300 100644 --- a/crates/fparkan-assets/src/strategic_roster.rs +++ b/crates/fparkan-assets/src/strategic_roster.rs @@ -173,7 +173,7 @@ impl RosterImages { &self, rows: &[Row<'_>], card: &[Option<CardLine<'_>>], - orders: Option<([&str; 3], Option<RosterOrder>)>, + orders: Option<([&str; 4], Option<RosterOrder>)>, ) -> Result<RgbaImage, String> { let mut panel = self.background.clone(); if let Some(row) = rows.iter().find(|row| row.selected) { diff --git a/crates/fparkan-assets/src/strategic_roster/orders.rs b/crates/fparkan-assets/src/strategic_roster/orders.rs index 4ea7d8d8..6e6e1e22 100644 --- a/crates/fparkan-assets/src/strategic_roster/orders.rs +++ b/crates/fparkan-assets/src/strategic_roster/orders.rs @@ -12,9 +12,25 @@ pub enum RosterOrder { Stand, /// Draw a route and send it to the unit. FollowRoute, + /// Patrol a point or a live object. + Patrol, } -const ORDERS: [RosterOrder; 2] = [RosterOrder::Stand, RosterOrder::FollowRoute]; +const ORDERS: [RosterOrder; 3] = [ + RosterOrder::Stand, + RosterOrder::FollowRoute, + RosterOrder::Patrol, +]; + +impl RosterOrder { + fn slot(self) -> u32 { + match self { + Self::Stand => 0, + Self::FollowRoute => 1, + Self::Patrol => 3, + } + } +} /// Returns the visible command at the pointer, excluding borders and row gaps. pub fn order_at([x, y]: [f32; 2], count: usize) -> Option<RosterOrder> { @@ -24,8 +40,8 @@ pub fn order_at([x, y]: [f32; 2], count: usize) -> Option<RosterOrder> { } let y = (y as u32).checked_sub(panel_top(count) + ROW_PITCH)?; ORDERS - .get((y / ROW_PITCH) as usize) - .copied() + .into_iter() + .find(|order| order.slot() == y / ROW_PITCH) .filter(|_| y % ROW_PITCH < ROW_HEIGHT) } @@ -35,7 +51,7 @@ fn panel_top(count: usize) -> u32 { pub(super) fn covers_pointer([x, y]: [f32; 2], count: usize) -> bool { let y_top = panel_top(count); - let y_bottom = (y_top + (ORDERS.len() as u32 + 1) * ROW_PITCH).min(480); + let y_bottom = (y_top + (RosterOrder::Patrol.slot() + 2) * ROW_PITCH).min(480); (LEFT as f32..RIGHT as f32).contains(&x) && (y_top as f32..y_bottom as f32).contains(&y) } @@ -65,7 +81,7 @@ impl OrderImages { roster: &RosterImages, panel: &mut RgbaImage, count: usize, - [title, stand, follow]: [&str; 3], + [title, stand, follow, patrol]: [&str; 4], hovered: Option<RosterOrder>, ) -> Result<(), String> { let x = LEFT - ORIGIN[0]; @@ -105,8 +121,8 @@ impl OrderImages { [128; 3], ); } - for (index, (order, label)) in ORDERS.into_iter().zip([stand, follow]).enumerate() { - let y = y + (index as u32 + 1) * ROW_PITCH; + for (order, label) in ORDERS.into_iter().zip([stand, follow, patrol]) { + let y = y + (order.slot() + 1) * ROW_PITCH; let bottom = y + ROW_HEIGHT; let label = roster.font.centered_line(label, 247, ROW_HEIGHT as u16)?; for (sprite, left, right) in [ @@ -146,5 +162,7 @@ mod tests { assert_eq!(order_at([250.0, 217.0], 3), None); assert_eq!(order_at([250.0, 218.0], 3), Some(RosterOrder::FollowRoute)); assert_eq!(order_at([250.0, 218.0], 4), Some(RosterOrder::Stand)); + assert_eq!(order_at([250.0, 238.0], 3), None); + assert_eq!(order_at([250.0, 258.0], 3), Some(RosterOrder::Patrol)); } } diff --git a/crates/fparkan-assets/src/strategy_cursor.rs b/crates/fparkan-assets/src/strategy_cursor.rs index 392fa894..c38a5bc9 100644 --- a/crates/fparkan-assets/src/strategy_cursor.rs +++ b/crates/fparkan-assets/src/strategy_cursor.rs @@ -15,17 +15,20 @@ pub enum StrategyCursor { Place, /// An invalid order waypoint. WrongPlace, + /// An eligible patrol point or object. + Guard, } impl StrategyCursor { /// Modes in draw-range order. - pub const ALL: [Self; 3] = [Self::Arrow, Self::Place, Self::WrongPlace]; + pub const ALL: [Self; 4] = [Self::Arrow, Self::Place, Self::WrongPlace, Self::Guard]; fn key(self) -> &'static str { match self { Self::Arrow => "ARROW", Self::Place => "PLACE", Self::WrongPlace => "WRONG_PLACE", + Self::Guard => "GUARD", } } } @@ -38,7 +41,7 @@ pub struct CursorStrip { } /// Loads the route cursor strips from the installed UI archive. -pub fn load(vfs: &dyn Vfs) -> Result<[CursorStrip; 3], String> { +pub fn load(vfs: &dyn Vfs) -> Result<[CursorStrip; StrategyCursor::ALL.len()], String> { let config = ui_configuration::read(vfs, "ui/cursor.cfg")?; let config = String::from_utf8_lossy(&config); let region = |kind: StrategyCursor| { @@ -85,7 +88,7 @@ mod tests { let strips = load(&DirectoryVfs::new(root)).unwrap(); assert_eq!( strips.each_ref().map(|strip| strip.hotspot), - [[0, 0], [8, 8], [8, 8]] + [[0, 0], [8, 8], [8, 8], [8, 8]] ); for strip in strips { assert_eq!([strip.image.width, strip.image.height], [64, 16]); |
