diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 15:28:59 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 15:28:59 +0300 |
| commit | aafdd0c398923f51625b632789ff0c7948b006e8 (patch) | |
| tree | 34717d5b9750e5d0ccf7e11ff91de66b09cb762c /crates/fparkan-assets/src | |
| parent | cc6bbdfa4aebf844ec7be2e8eb01b7fd1c69d24b (diff) | |
| download | fparkan-aafdd0c398923f51625b632789ff0c7948b006e8.tar.xz fparkan-aafdd0c398923f51625b632789ff0c7948b006e8.zip | |
feat(ui): stop an active strategic factory order
Diffstat (limited to 'crates/fparkan-assets/src')
| -rw-r--r-- | crates/fparkan-assets/src/strategic_factory.rs | 67 |
1 files changed, 53 insertions, 14 deletions
diff --git a/crates/fparkan-assets/src/strategic_factory.rs b/crates/fparkan-assets/src/strategic_factory.rs index e9d1a387..8120c8cd 100644 --- a/crates/fparkan-assets/src/strategic_factory.rs +++ b/crates/fparkan-assets/src/strategic_factory.rs @@ -24,9 +24,29 @@ pub enum FactoryAction { Close, Project(usize), Build, + Cancel, Plant(usize), } +#[derive(Clone, Copy, Debug, PartialEq, Eq)] +pub enum FactoryOrderButton { + Start, + Stop, + Hidden, +} + +impl FactoryOrderButton { + pub fn for_plant(active: bool, project_selected: bool, free_minds: u32) -> Self { + if active { + Self::Stop + } else if project_selected && free_minds > 0 { + Self::Start + } else { + Self::Hidden + } + } +} + fn project_rect(index: usize) -> [u32; 4] { let left = 10 + index as u32 * 23; [left, 125, left + 19, 142] @@ -36,7 +56,7 @@ pub fn hit_test( [x, y]: [f32; 2], plants: usize, projects: usize, - idle: bool, + order_button: FactoryOrderButton, ) -> Option<FactoryAction> { let [x, y] = [x.round_ties_even() - ORIGIN[0] as f32, y.round_ties_even()]; let hit = |[left, top, right, bottom]: [u32; 4]| { @@ -45,8 +65,12 @@ pub fn hit_test( if hit([283, 0, 318, 19]) { return Some(FactoryAction::Close); } - if idle && projects != 0 && hit(BUILD) { - return Some(FactoryAction::Build); + if hit(BUILD) { + return match order_button { + FactoryOrderButton::Start => Some(FactoryAction::Build), + FactoryOrderButton::Stop => Some(FactoryAction::Cancel), + FactoryOrderButton::Hidden => None, + }; } if let Some(index) = (0..projects).find(|&index| hit(project_rect(index))) { return Some(FactoryAction::Project(index)); @@ -72,6 +96,7 @@ pub struct FactoryPicture<'a> { pub selected_project: Option<usize>, pub progress: Option<u8>, pub free_minds: u32, + pub order_button: FactoryOrderButton, } pub struct FactoryImages { @@ -80,7 +105,7 @@ pub struct FactoryImages { row_cap: [RgbaImage; 2], row_body: RgbaImage, ray: RgbaImage, - icons: [RgbaImage; 5], + icons: [RgbaImage; 6], } impl FactoryImages { @@ -103,7 +128,7 @@ impl FactoryImages { "ccres_frame_edge_v", ], )?; - let [exit, project, project_frame, build, free] = load_ui_sprites( + let [exit, project, project_frame, build, stop, free] = load_ui_sprites( vfs, "ui/hq.cfg", [ @@ -111,6 +136,7 @@ impl FactoryImages { "project_icon", "short_button_frame_off", "build_icon", + "stop_build_icon", "brain_icon", ], )?; @@ -152,13 +178,13 @@ impl FactoryImages { row_cap: [row_off, row_on], row_body: body, ray, - icons: [project, project_frame, plant, build, free], + icons: [project, project_frame, plant, build, stop, free], }) } pub fn paint(&self, picture: FactoryPicture<'_>) -> Result<RgbaImage, String> { let mut image = self.base.clone(); - let [project, frame, plant, build, free] = &self.icons; + let [project, frame, plant, build, stop, free] = &self.icons; if let Some(name) = picture.project_name { let width = u32::from(self.font.line_metrics(name)?[0]).min(170); text( @@ -202,11 +228,17 @@ impl FactoryImages { [5, 150, 263, 169], [255; 3], )?; - } else if picture.selected_project.is_some() && picture.free_minds > 0 { + } + let order_icon = match picture.order_button { + FactoryOrderButton::Start => Some(build), + FactoryOrderButton::Stop => Some(stop), + FactoryOrderButton::Hidden => None, + }; + if let Some(icon) = order_icon { stamp(&mut image, &self.row_body, BUILD, [255; 3]); stamp( &mut image, - build, + icon, [BUILD[0] + 10, BUILD[1] + 2, BUILD[0] + 40, BUILD[1] + 17], [255; 3], ); @@ -258,18 +290,25 @@ mod tests { #[test] fn factory_actions_follow_project_and_row_extents() { + use FactoryOrderButton::{Hidden, Start, Stop}; + assert_eq!( - hit_test([95.0, 132.0], 1, 2, true), + hit_test([95.0, 132.0], 1, 2, Start), Some(FactoryAction::Project(1)) ); - assert_eq!(hit_test([95.0, 132.0], 1, 1, true), None); + assert_eq!(hit_test([95.0, 132.0], 1, 1, Start), None); assert_eq!( - hit_test([340.0, 160.0], 1, 2, true), + hit_test([340.0, 160.0], 1, 2, Start), Some(FactoryAction::Build) ); - assert_eq!(hit_test([340.0, 160.0], 1, 2, false), None); + assert_eq!(hit_test([340.0, 160.0], 1, 2, Hidden), None); + assert_eq!(FactoryOrderButton::for_plant(true, false, 0), Stop); + assert_eq!( + hit_test([340.0, 160.0], 1, 0, Stop), + Some(FactoryAction::Cancel) + ); assert_eq!( - hit_test([200.0, 172.0], 1, 2, true), + hit_test([200.0, 172.0], 1, 2, Start), Some(FactoryAction::Plant(0)) ); } |
