diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 15:56:29 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 15:56:29 +0300 |
| commit | 2918dbe5c591ab6b1d4a76512b7fc8f258997558 (patch) | |
| tree | eba8d582a1357a72ed3895c2ef285ef28b7d59cb /crates/fparkan-assets | |
| parent | fd42fb7e4fa27d2fe03ee8b6532949b7c1b13ace (diff) | |
| download | fparkan-2918dbe5c591ab6b1d4a76512b7fc8f258997558.tar.xz fparkan-2918dbe5c591ab6b1d4a76512b7fc8f258997558.zip | |
feat(ui): run repeating strategic factory orders
Diffstat (limited to 'crates/fparkan-assets')
| -rw-r--r-- | crates/fparkan-assets/src/strategic_factory.rs | 135 |
1 files changed, 83 insertions, 52 deletions
diff --git a/crates/fparkan-assets/src/strategic_factory.rs b/crates/fparkan-assets/src/strategic_factory.rs index 9eac9721..aaa590c6 100644 --- a/crates/fparkan-assets/src/strategic_factory.rs +++ b/crates/fparkan-assets/src/strategic_factory.rs @@ -18,6 +18,7 @@ const ROW_PITCH: u32 = 20; const ROW_HEIGHT: u32 = 19; pub const VISIBLE_PLANTS: usize = ((EXTENT[1] - ROW_TOP) / ROW_PITCH) as usize; const BUILD: [u32; 4] = [263, 150, 313, 169]; +const BATCH: [u32; 4] = [211, 150, 261, 169]; const CONSTRUCTOR: [u32; 4] = [5, 150, 55, 169]; #[derive(Clone, Copy, Debug, PartialEq, Eq)] @@ -25,26 +26,30 @@ pub enum FactoryAction { Close, Project(usize), Build, + Batch, Cancel, Designer, Plant(usize), } #[derive(Clone, Copy, Debug, PartialEq, Eq)] -pub enum FactoryOrderButton { - Start, - Stop, - Hidden, +pub enum FactoryOrders { + Ready, + Unavailable, + Single, + Batch, } -impl FactoryOrderButton { - pub fn for_plant(active: bool, project_selected: bool, free_minds: u32) -> Self { - if active { - Self::Stop +impl FactoryOrders { + pub fn for_plant(batch: bool, active: bool, project_selected: bool, free_minds: u32) -> Self { + if batch { + Self::Batch + } else if active { + Self::Single } else if project_selected && free_minds > 0 { - Self::Start + Self::Ready } else { - Self::Hidden + Self::Unavailable } } } @@ -58,7 +63,7 @@ pub fn hit_test( [x, y]: [f32; 2], plants: usize, projects: usize, - order_button: FactoryOrderButton, + orders: FactoryOrders, designer_available: bool, ) -> Option<FactoryAction> { let [x, y] = [x.round_ties_even() - ORIGIN[0] as f32, y.round_ties_even()]; @@ -69,10 +74,17 @@ pub fn hit_test( return Some(FactoryAction::Close); } if hit(BUILD) { - return match order_button { - FactoryOrderButton::Start => Some(FactoryAction::Build), - FactoryOrderButton::Stop => Some(FactoryAction::Cancel), - FactoryOrderButton::Hidden => None, + return match orders { + FactoryOrders::Ready => Some(FactoryAction::Build), + FactoryOrders::Single => Some(FactoryAction::Cancel), + _ => None, + }; + } + if hit(BATCH) { + return match orders { + FactoryOrders::Ready => Some(FactoryAction::Batch), + FactoryOrders::Batch => Some(FactoryAction::Cancel), + _ => None, }; } if designer_available && hit(CONSTRUCTOR) { @@ -102,7 +114,7 @@ pub struct FactoryPicture<'a> { pub selected_project: Option<usize>, pub progress: Option<u8>, pub free_minds: u32, - pub order_button: FactoryOrderButton, + pub orders: FactoryOrders, pub designer_available: bool, } @@ -113,6 +125,7 @@ pub struct FactoryImages { row_body: RgbaImage, ray: RgbaImage, icons: [RgbaImage; 7], + batch_icons: [RgbaImage; 2], } impl FactoryImages { @@ -135,19 +148,22 @@ impl FactoryImages { "ccres_frame_edge_v", ], )?; - let [exit, project, project_frame, build, stop, constructor, free] = load_ui_sprites( - vfs, - "ui/hq.cfg", - [ - "exit_icon", - "project_icon", - "short_button_frame_off", - "build_icon", - "stop_build_icon", - "constructor_icon", - "brain_icon", - ], - )?; + let [exit, project, project_frame, build, stop, constructor, free, batch, stop_batch] = + load_ui_sprites( + vfs, + "ui/hq.cfg", + [ + "exit_icon", + "project_icon", + "short_button_frame_off", + "build_icon", + "stop_build_icon", + "constructor_icon", + "brain_icon", + "batch_build_icon", + "batch_stop_build_icon", + ], + )?; let atlas = load_ui_page(vfs, "ui_menu")?; let plant = atlas_region(&atlas, [129, 94, 15, 15]).ok_or("factory glyph outside ui_menu")?; @@ -195,6 +211,7 @@ impl FactoryImages { constructor, free, ], + batch_icons: [batch, stop_batch], }) } @@ -235,32 +252,35 @@ impl FactoryImages { [289, 125, 306, 144], [128, 255, 128], )?; - stamp(&mut image, &self.row_body, [55, 150, 263, 169], [255; 3]); + let progress_rect = [55, 150, BATCH[0], 169]; + stamp(&mut image, &self.row_body, progress_rect, [255; 3]); if let Some(progress) = picture.progress { text( &self.font, &mut image, &format!("{progress}%"), - [55, 150, 263, 169], + progress_rect, [255; 3], )?; } - let order_icon = match picture.order_button { - FactoryOrderButton::Start => Some(build), - FactoryOrderButton::Stop => Some(stop), - FactoryOrderButton::Hidden => None, - }; - for (rect, icon) in [ + let busy = matches!(picture.orders, FactoryOrders::Single | FactoryOrders::Batch); + for (rect, icon, enabled) in [ + (CONSTRUCTOR, constructor, picture.designer_available), ( - CONSTRUCTOR, - picture.designer_available.then_some(constructor), + BATCH, + &self.batch_icons[usize::from(busy)], + matches!(picture.orders, FactoryOrders::Ready | FactoryOrders::Batch), + ), + ( + BUILD, + if busy { stop } else { build }, + matches!(picture.orders, FactoryOrders::Ready | FactoryOrders::Single), ), - (BUILD, order_icon), ] { - let Some(icon) = icon else { continue }; + let tint = if enabled { [255; 3] } else { [104; 3] }; let [x, y, _, _] = rect; stamp(&mut image, &self.row_body, rect, [255; 3]); - stamp(&mut image, icon, [x + 10, y + 2, x + 40, y + 17], [255; 3]); + stamp(&mut image, icon, [x + 10, y + 2, x + 40, y + 17], tint); } for (index, row) in picture.rows.iter().take(VISIBLE_PLANTS).enumerate() { let y = ROW_TOP + index as u32 * ROW_PITCH; @@ -309,31 +329,42 @@ mod tests { #[test] fn factory_actions_follow_project_and_row_extents() { - use FactoryOrderButton::{Hidden, Start, Stop}; + use FactoryOrders::{Batch, Ready, Single, Unavailable}; assert_eq!( - hit_test([95.0, 132.0], 1, 2, Start, true), + hit_test([95.0, 132.0], 1, 2, Ready, true), Some(FactoryAction::Project(1)) ); - assert_eq!(hit_test([95.0, 132.0], 1, 1, Start, true), None); + assert_eq!(hit_test([95.0, 132.0], 1, 1, Ready, true), None); assert_eq!( - hit_test([340.0, 160.0], 1, 2, Start, true), + hit_test([340.0, 160.0], 1, 2, Ready, true), Some(FactoryAction::Build) ); - assert_eq!(hit_test([340.0, 160.0], 1, 2, Hidden, true), None); - assert_eq!(FactoryOrderButton::for_plant(true, false, 0), Stop); + assert_eq!(hit_test([340.0, 160.0], 1, 2, Unavailable, true), None); + assert_eq!(FactoryOrders::for_plant(false, true, false, 0), Single); assert_eq!( - hit_test([340.0, 160.0], 1, 0, Stop, true), + hit_test([340.0, 160.0], 1, 0, Single, true), Some(FactoryAction::Cancel) ); assert_eq!( - hit_test([200.0, 172.0], 1, 2, Start, true), + hit_test([200.0, 172.0], 1, 2, Ready, true), Some(FactoryAction::Plant(0)) ); - assert_eq!(hit_test([80.0, 160.0], 1, 0, Hidden, false), None); + assert_eq!(hit_test([80.0, 160.0], 1, 0, Unavailable, false), None); assert_eq!( - hit_test([80.0, 160.0], 1, 0, Hidden, true), + hit_test([80.0, 160.0], 1, 0, Unavailable, true), Some(FactoryAction::Designer) ); + assert_eq!(FactoryOrders::for_plant(true, false, true, 0), Batch); + assert_eq!(hit_test([340.0, 160.0], 1, 2, Batch, true), None); + assert_eq!(hit_test([289.0, 160.0], 1, 2, Single, true), None); + assert_eq!( + hit_test([289.0, 160.0], 1, 2, Ready, true), + Some(FactoryAction::Batch) + ); + assert_eq!( + hit_test([289.0, 160.0], 1, 2, Batch, true), + Some(FactoryAction::Cancel) + ); } } |
