From faeb22084ea59194036785d84b68396981dfcbae Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 17:09:19 +0400 Subject: feat(ui): inspect the current factory project --- apps/fparkan-game/src/mission_overlay.rs | 7 + apps/fparkan-game/src/strategic_factory_hud.rs | 45 +++-- apps/fparkan-game/src/strategic_tooltip_hud.rs | 14 +- apps/fparkan-game/src/strategic_view.rs | 27 ++- crates/fparkan-assets/src/strategic_factory.rs | 223 +++++++++++++++------ crates/fparkan-runtime/src/production.rs | 2 + crates/fparkan-runtime/src/production/batch.rs | 2 +- crates/fparkan-runtime/src/production/strategic.rs | 60 +++++- docs/appendices/knowledge-boundaries.md | 2 - docs/appendices/ui-shell.md | 6 + 10 files changed, 286 insertions(+), 102 deletions(-) diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs index c193e76f..406cf92c 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -281,6 +281,12 @@ impl StaticVulkanApp { .map(|frame| frame.clock.time_ms) .and_then(|now_ms| self.strategic_factory_frame(now_ms)); #[cfg(windows)] + let factory_tip = factory_frame.as_ref().and_then(|frame| { + frame + .controls() + .tooltip(self.command_view.as_ref()?.pointer()?) + }); + #[cfg(windows)] let warbot_rows = self.strategic_warbot_rows(); #[cfg(windows)] let row_count = warbot_rows.len(); @@ -518,6 +524,7 @@ impl StaticVulkanApp { .filter(|_| self.overlay.strategy_toolbar.is_some()) .map(|view| view.toolbar_layout()), card_rows, + factory_tip, )?; } Ok(()) diff --git a/apps/fparkan-game/src/strategic_factory_hud.rs b/apps/fparkan-game/src/strategic_factory_hud.rs index a71793f8..0e865c30 100644 --- a/apps/fparkan-game/src/strategic_factory_hud.rs +++ b/apps/fparkan-game/src/strategic_factory_hud.rs @@ -3,7 +3,9 @@ use super::{ DirectoryVfs, EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer, }; use fparkan_assets::{ - strategic_factory::{FactoryImages, FactoryOrders, FactoryPicture, FactoryRow, EXTENT, ORIGIN}, + strategic_factory::{ + FactoryControls, FactoryImages, FactoryOrders, FactoryPicture, FactoryRow, EXTENT, ORIGIN, + }, warbot_card::{CardLabels, RatingScale}, }; use fparkan_platform_winit::text::StringResources; @@ -15,24 +17,37 @@ pub(super) struct FactoryFrame { pub plants: Vec, pub active_plant: usize, pub selected: Option, + pub viewing_active: bool, pub model_started_ms: u32, pub designer_available: bool, } impl FactoryFrame { pub(super) fn scheme(&self) -> Option { - self.selected - .and_then(|slot| self.plants[self.active_plant].projects.get(slot).copied()) + let plant = &self.plants[self.active_plant]; + if self.viewing_active { + plant.active_project + } else { + self.selected + .and_then(|slot| plant.projects.get(slot).copied()) + } } - pub(super) fn orders(&self) -> FactoryOrders { + pub(super) fn controls(&self) -> FactoryControls { let plant = &self.plants[self.active_plant]; - FactoryOrders::for_plant( - plant.batch, - plant.progress.is_some(), - self.scheme().is_some(), - plant.free_minds, - ) + FactoryControls { + plants: self.plants.len(), + projects: plant.projects.len(), + orders: FactoryOrders::for_plant( + plant.batch, + plant.progress.is_some(), + self.scheme().is_some(), + plant.free_minds, + ), + designer_available: self.designer_available, + active_available: plant.active_project.is_some(), + free_build: plant.free_build, + } } } @@ -132,9 +147,11 @@ impl StrategicFactoryHud { selected: index == frame.active_plant, }) .collect::>(); + let plant = &frame.plants[frame.active_plant]; + let current_factory = frame.viewing_active.then_some(plant.handle); let project = engine .zip(frame.scheme()) - .and_then(|(engine, scheme)| factory_panel_project(engine, scheme)); + .and_then(|(engine, scheme)| factory_panel_project(engine, scheme, current_factory)); let name = project.as_ref().and_then(|project| { let prefix = project.prefix.iter().collect::(); Some(format!( @@ -153,17 +170,15 @@ impl StrategicFactoryHud { ) }, ); - let plant = &frame.plants[frame.active_plant]; let image = self.images.paint(FactoryPicture { rows: &rows, project_name: name.as_deref(), stats: &stats, - projects: plant.projects.len(), + controls: frame.controls(), selected_project: frame.selected, + viewing_active: frame.viewing_active, progress: plant.progress, free_minds: plant.free_minds, - orders: frame.orders(), - designer_available: frame.designer_available, })?; renderer .update_material_texture(self.range.material_index, 0, &overlay_texture(image)) diff --git a/apps/fparkan-game/src/strategic_tooltip_hud.rs b/apps/fparkan-game/src/strategic_tooltip_hud.rs index 2572ad61..0e8ee3af 100644 --- a/apps/fparkan-game/src/strategic_tooltip_hud.rs +++ b/apps/fparkan-game/src/strategic_tooltip_hud.rs @@ -4,6 +4,7 @@ use super::{ }; use fparkan_assets::{ game_font::{load_tool_font, TOOL_FONT_EXTENTS}, + strategic_factory, strategic_roster::{hit_test, CockpitControl, ListHit}, strategy_toolbar::{button_index_at, ToolbarLayout, TOOLTIP_IDS}, ui_tooltip::{self, TooltipHover}, @@ -14,7 +15,8 @@ use std::{path::Path, time::Instant}; // In the order in which iron3d+0x82930 assigns the original texts to the buttons. const CARD_LABELS: [u32; 4] = [0x05de, 0x05ef, 0x05ee, 0x1864]; -const LABEL_COUNT: usize = TOOLTIP_IDS.len() + CARD_LABELS.len(); +const FACTORY_OFFSET: usize = TOOLTIP_IDS.len() + CARD_LABELS.len(); +const LABEL_COUNT: usize = FACTORY_OFFSET + strategic_factory::TOOLTIP_IDS.len(); #[derive(Clone, Copy, Default)] struct Frame { @@ -35,6 +37,7 @@ impl StrategicTooltipHud { let labels = TOOLTIP_IDS .into_iter() .chain(CARD_LABELS) + .chain(strategic_factory::TOOLTIP_IDS) .map(|id| { strings .get(id) @@ -98,12 +101,19 @@ impl StrategicTooltipHud { pointer: Option<[f32; 2]>, toolbar_layout: Option, card_rows: usize, + factory_tip: Option, ) -> Result<(), String> { let tooltip = pointer.and_then(|xy| { let toolbar_label = toolbar_layout .filter(|layout| layout.button_visible(xy[1])) .and_then(|_| button_index_at(xy)); - let label = toolbar_label.or_else(|| { + let factory_label = factory_tip.and_then(|id| { + strategic_factory::TOOLTIP_IDS + .iter() + .position(|&known| id == known) + .map(|index| FACTORY_OFFSET + index) + }); + let label = toolbar_label.or(factory_label).or_else(|| { let card = match hit_test(xy, card_rows)? { ListHit::Cockpit(CockpitControl::Manual) => 0, ListHit::Cockpit(CockpitControl::AutoGunner) => 1, diff --git a/apps/fparkan-game/src/strategic_view.rs b/apps/fparkan-game/src/strategic_view.rs index fd790b1e..de854e54 100644 --- a/apps/fparkan-game/src/strategic_view.rs +++ b/apps/fparkan-game/src/strategic_view.rs @@ -3,7 +3,7 @@ use super::{ PreviewCameraFrame, StaticVulkanApp, }; #[cfg(windows)] -use fparkan_assets::strategic_factory::{self, FactoryAction}; +use fparkan_assets::strategic_factory::FactoryAction; use fparkan_assets::strategic_roster::{ covers_pointer, hit_test, order_at, CockpitControl, ListHit, RosterOrder, }; @@ -48,6 +48,7 @@ enum OrderInput { struct FactorySelection { plant: Option, scheme: Option, + viewing_active: bool, model_started_ms: u32, } @@ -64,13 +65,19 @@ impl FactorySelection { .position(|plant| Some(plant.handle) == self.plant) .unwrap_or(0); let plant = plants.get(active_plant)?; + let changed_plant = Some(plant.handle) != self.plant; + if changed_plant || (self.viewing_active && plant.active_project.is_none()) { + self.viewing_active = false; + self.scheme = None; + self.model_started_ms = now_ms; + } let selected = plant .projects .iter() .position(|&scheme| Some(scheme) == self.scheme) .or_else(|| (!plant.projects.is_empty()).then_some(0)); let scheme = selected.map(|slot| plant.projects[slot]); - if scheme != self.scheme || Some(plant.handle) != self.plant { + if scheme != self.scheme { self.model_started_ms = now_ms; } self.plant = Some(plant.handle); @@ -79,6 +86,7 @@ impl FactorySelection { plants, active_plant, selected, + viewing_active: self.viewing_active, model_started_ms: self.model_started_ms, designer_available, }) @@ -513,21 +521,21 @@ impl StaticVulkanApp { designer_available, ) { let plant = &frame.plants[frame.active_plant]; - match strategic_factory::hit_test( - xy, - frame.plants.len(), - plant.projects.len(), - frame.orders(), - frame.designer_available, - ) { + match frame.controls().hit_test(xy) { Some(FactoryAction::Close) => view.factory = None, Some(FactoryAction::Plant(index)) => { factory.plant = Some(frame.plants[index].handle); factory.scheme = frame.plants[index].projects.first().copied(); + factory.viewing_active = false; factory.model_started_ms = now; } Some(FactoryAction::Project(index)) => { factory.scheme = Some(plant.projects[index]); + factory.viewing_active = false; + factory.model_started_ms = now; + } + Some(FactoryAction::ActiveProject) => { + factory.viewing_active = true; factory.model_started_ms = now; } Some(action @ (FactoryAction::Build | FactoryAction::Batch)) => { @@ -809,6 +817,7 @@ impl StaticVulkanApp { { factory.plant = Some(plant); factory.scheme = Some(scheme); + factory.viewing_active = false; factory.model_started_ms = self.simulation_time_ms; } self.update_mission_title(); diff --git a/crates/fparkan-assets/src/strategic_factory.rs b/crates/fparkan-assets/src/strategic_factory.rs index aaa590c6..1cf6d8a4 100644 --- a/crates/fparkan-assets/src/strategic_factory.rs +++ b/crates/fparkan-assets/src/strategic_factory.rs @@ -20,11 +20,18 @@ 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]; +const ACTIVE: [u32; 4] = [135, 125, 165, 142]; +const FREE_BUILD: [u32; 4] = [228, 127, 258, 142]; +const MINDS: [u32; 4] = [274, 125, 307, 144]; +pub const TOOLTIP_IDS: [u32; 10] = [ + 0x611, 0xbfe, 0x185e, 0x185f, 0x5e7, 0xbfc, 0xbfd, 0xbfb, 0x1868, 0x1869, +]; #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum FactoryAction { Close, Project(usize), + ActiveProject, Build, Batch, Cancel, @@ -59,46 +66,80 @@ fn project_rect(index: usize) -> [u32; 4] { [left, 125, left + 19, 142] } -pub fn hit_test( - [x, y]: [f32; 2], - plants: usize, - projects: usize, - orders: FactoryOrders, - designer_available: bool, -) -> Option { - let [x, y] = [x.round_ties_even() - ORIGIN[0] as f32, y.round_ties_even()]; - let hit = |[left, top, right, bottom]: [u32; 4]| { - (left as f32..right as f32).contains(&x) && (top as f32..bottom as f32).contains(&y) - }; - if hit([283, 0, 318, 19]) { - return Some(FactoryAction::Close); - } - if hit(BUILD) { - 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) { - return Some(FactoryAction::Designer); +#[derive(Clone, Copy)] +pub struct FactoryControls { + pub plants: usize, + pub projects: usize, + pub orders: FactoryOrders, + pub designer_available: bool, + pub active_available: bool, + pub free_build: bool, +} + +impl FactoryControls { + pub fn hit_test(self, at: [f32; 2]) -> Option { + let hit = |rect| contains(at, rect); + if hit([283, 0, 318, 19]) { + return Some(FactoryAction::Close); + } + if hit(BUILD) { + return match self.orders { + FactoryOrders::Ready => Some(FactoryAction::Build), + FactoryOrders::Single => Some(FactoryAction::Cancel), + _ => None, + }; + } + if hit(BATCH) { + return match self.orders { + FactoryOrders::Ready => Some(FactoryAction::Batch), + FactoryOrders::Batch => Some(FactoryAction::Cancel), + _ => None, + }; + } + if self.designer_available && hit(CONSTRUCTOR) { + return Some(FactoryAction::Designer); + } + if self.active_available && hit(ACTIVE) { + return Some(FactoryAction::ActiveProject); + } + if let Some(index) = (0..self.projects).find(|&index| hit(project_rect(index))) { + return Some(FactoryAction::Project(index)); + } + (0..self.plants.min(VISIBLE_PLANTS)) + .find(|&index| { + let top = ROW_TOP + index as u32 * ROW_PITCH; + hit([0, top, 318, top + ROW_HEIGHT]) + }) + .map(FactoryAction::Plant) } - if let Some(index) = (0..projects).find(|&index| hit(project_rect(index))) { - return Some(FactoryAction::Project(index)); + + pub fn tooltip(self, at: [f32; 2]) -> Option { + let hit = |rect| contains(at, rect); + let busy = matches!(self.orders, FactoryOrders::Single | FactoryOrders::Batch); + if hit(BUILD) { + Some(if busy { 0xbfe } else { 0x611 }) + } else if hit(BATCH) { + Some(if busy { 0x185f } else { 0x185e }) + } else if hit(CONSTRUCTOR) { + Some(0x5e7) + } else if self.active_available && hit(ACTIVE) { + Some(0xbfd) + } else if (0..self.projects).any(|index| hit(project_rect(index))) { + Some(0xbfc) + } else if hit(FREE_BUILD) { + Some(if self.free_build { 0x1868 } else { 0x1869 }) + } else if hit(MINDS) { + Some(0xbfb) + } else { + None + } } - (0..plants.min(VISIBLE_PLANTS)) - .find(|&index| { - let top = ROW_TOP + index as u32 * ROW_PITCH; - hit([0, top, 318, top + ROW_HEIGHT]) - }) - .map(FactoryAction::Plant) +} + +fn contains([x, y]: [f32; 2], [left, top, right, bottom]: [u32; 4]) -> bool { + let x = x.round_ties_even() - ORIGIN[0] as f32; + let y = y.round_ties_even(); + (left as f32..right as f32).contains(&x) && (top as f32..bottom as f32).contains(&y) } pub struct FactoryRow<'a> { @@ -110,12 +151,11 @@ pub struct FactoryPicture<'a> { pub rows: &'a [FactoryRow<'a>], pub project_name: Option<&'a str>, pub stats: &'a [Option>], - pub projects: usize, + pub controls: FactoryControls, pub selected_project: Option, + pub viewing_active: bool, pub progress: Option, pub free_minds: u32, - pub orders: FactoryOrders, - pub designer_available: bool, } pub struct FactoryImages { @@ -126,6 +166,8 @@ pub struct FactoryImages { ray: RgbaImage, icons: [RgbaImage; 7], batch_icons: [RgbaImage; 2], + active_project: RgbaImage, + free_bots_icons: [RgbaImage; 2], } impl FactoryImages { @@ -148,7 +190,7 @@ impl FactoryImages { "ccres_frame_edge_v", ], )?; - let [exit, project, project_frame, build, stop, constructor, free, batch, stop_batch] = + let [exit, project, project_frame, build, stop, constructor, free, batch, stop_batch, active_project, free_bots, no_free_bots] = load_ui_sprites( vfs, "ui/hq.cfg", @@ -162,6 +204,9 @@ impl FactoryImages { "brain_icon", "batch_build_icon", "batch_stop_build_icon", + "active_project", + "free_bots_icon", + "no_free_bots_icon", ], )?; let atlas = load_ui_page(vfs, "ui_menu")?; @@ -212,6 +257,8 @@ impl FactoryImages { free, ], batch_icons: [batch, stop_batch], + active_project, + free_bots_icons: [no_free_bots, free_bots], }) } @@ -229,7 +276,7 @@ impl FactoryImages { )?; warbot_card::paint_at(&self.font, &mut image, picture.stats, [10, 144, 147], 43)?; } - for index in 0..picture.projects { + for index in 0..picture.controls.projects { let rect = project_rect(index); stamp( &mut image, @@ -237,13 +284,28 @@ impl FactoryImages { [rect[0] - 2, rect[1] - 2, rect[2] + 2, rect[3] + 2], [255; 3], ); - let tint = if picture.selected_project == Some(index) { + let tint = if !picture.viewing_active && picture.selected_project == Some(index) { [255; 3] } else { [128, 255, 128] }; stamp(&mut image, project, rect, tint); } + if picture.controls.active_available { + stamp(&mut image, frame, [133, 123, 167, 144], [255; 3]); + let tint = if picture.viewing_active { + [255; 3] + } else { + [128, 255, 128] + }; + stamp(&mut image, &self.active_project, ACTIVE, tint); + } + stamp( + &mut image, + &self.free_bots_icons[usize::from(picture.controls.free_build)], + FREE_BUILD, + [255; 3], + ); stamp(&mut image, free, [274, 127, 289, 142], [128, 255, 128]); text( &self.font, @@ -263,18 +325,23 @@ impl FactoryImages { [255; 3], )?; } - let busy = matches!(picture.orders, FactoryOrders::Single | FactoryOrders::Batch); + let orders = picture.controls.orders; + let busy = matches!(orders, FactoryOrders::Single | FactoryOrders::Batch); for (rect, icon, enabled) in [ - (CONSTRUCTOR, constructor, picture.designer_available), + ( + CONSTRUCTOR, + constructor, + picture.controls.designer_available, + ), ( BATCH, &self.batch_icons[usize::from(busy)], - matches!(picture.orders, FactoryOrders::Ready | FactoryOrders::Batch), + matches!(orders, FactoryOrders::Ready | FactoryOrders::Batch), ), ( BUILD, if busy { stop } else { build }, - matches!(picture.orders, FactoryOrders::Ready | FactoryOrders::Single), + matches!(orders, FactoryOrders::Ready | FactoryOrders::Single), ), ] { let tint = if enabled { [255; 3] } else { [104; 3] }; @@ -330,41 +397,67 @@ mod tests { #[test] fn factory_actions_follow_project_and_row_extents() { use FactoryOrders::{Batch, Ready, Single, Unavailable}; - + let mut controls = FactoryControls { + plants: 1, + projects: 2, + orders: Ready, + designer_available: true, + active_available: false, + free_build: true, + }; assert_eq!( - hit_test([95.0, 132.0], 1, 2, Ready, true), + controls.hit_test([95.0, 132.0]), Some(FactoryAction::Project(1)) ); - assert_eq!(hit_test([95.0, 132.0], 1, 1, Ready, true), None); assert_eq!( - hit_test([340.0, 160.0], 1, 2, Ready, true), + controls.hit_test([340.0, 160.0]), Some(FactoryAction::Build) ); - 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!(controls.tooltip([340.0, 160.0]), Some(0x611)); assert_eq!( - hit_test([340.0, 160.0], 1, 0, Single, true), - Some(FactoryAction::Cancel) + controls.hit_test([289.0, 160.0]), + Some(FactoryAction::Batch) ); assert_eq!( - hit_test([200.0, 172.0], 1, 2, Ready, true), + controls.hit_test([200.0, 172.0]), Some(FactoryAction::Plant(0)) ); - assert_eq!(hit_test([80.0, 160.0], 1, 0, Unavailable, false), None); assert_eq!( - hit_test([80.0, 160.0], 1, 0, Unavailable, true), + controls.hit_test([80.0, 160.0]), 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!(controls.hit_test([201.0, 132.0]), None); + assert_eq!(controls.tooltip([201.0, 132.0]), None); + assert_eq!(controls.tooltip([95.0, 132.0]), Some(0xbfc)); + assert_eq!(controls.tooltip([287.0, 132.0]), Some(0x1868)); + controls.orders = Single; + controls.active_available = true; + assert_eq!(controls.hit_test([289.0, 160.0]), None); assert_eq!( - hit_test([289.0, 160.0], 1, 2, Ready, true), - Some(FactoryAction::Batch) + controls.hit_test([340.0, 160.0]), + Some(FactoryAction::Cancel) ); assert_eq!( - hit_test([289.0, 160.0], 1, 2, Batch, true), + controls.hit_test([201.0, 132.0]), + Some(FactoryAction::ActiveProject) + ); + assert_eq!(controls.tooltip([201.0, 132.0]), Some(0xbfd)); + + controls.orders = Batch; + assert_eq!(controls.hit_test([340.0, 160.0]), None); + assert_eq!( + controls.hit_test([289.0, 160.0]), Some(FactoryAction::Cancel) ); + assert_eq!(controls.tooltip([289.0, 160.0]), Some(0x185f)); + + controls.orders = Unavailable; + controls.projects = 1; + controls.designer_available = false; + controls.free_build = false; + assert_eq!(controls.hit_test([95.0, 132.0]), None); + assert_eq!(controls.hit_test([340.0, 160.0]), None); + assert_eq!(controls.hit_test([80.0, 160.0]), None); + assert_eq!(controls.tooltip([287.0, 132.0]), Some(0x1869)); } } diff --git a/crates/fparkan-runtime/src/production.rs b/crates/fparkan-runtime/src/production.rs index 50acdd94..37246b8a 100644 --- a/crates/fparkan-runtime/src/production.rs +++ b/crates/fparkan-runtime/src/production.rs @@ -60,6 +60,7 @@ pub(super) struct Production { struct Order { slot: usize, + scheme: usize, plant: ObjectHandle, plant_index: usize, owner: OwnerId, @@ -745,6 +746,7 @@ fn order_owned_factory( }; let order = Order { slot, + scheme, plant, plant_index, owner, diff --git a/crates/fparkan-runtime/src/production/batch.rs b/crates/fparkan-runtime/src/production/batch.rs index c0fb2690..ed8dee9a 100644 --- a/crates/fparkan-runtime/src/production/batch.rs +++ b/crates/fparkan-runtime/src/production/batch.rs @@ -10,7 +10,7 @@ use fparkan_world::{identity_metadata, ObjectHandle, OwnerId}; pub(super) struct BatchOrder { pub(super) plant: ObjectHandle, pub(super) owner: OwnerId, - scheme: usize, + pub(super) scheme: usize, } /// Starts a repeating order at an idle factory and reserves one clan slot. diff --git a/crates/fparkan-runtime/src/production/strategic.rs b/crates/fparkan-runtime/src/production/strategic.rs index 5b4e08f9..83360548 100644 --- a/crates/fparkan-runtime/src/production/strategic.rs +++ b/crates/fparkan-runtime/src/production/strategic.rs @@ -82,6 +82,8 @@ pub struct FactoryPanelPlant { pub free_minds: u32, pub progress: Option, pub batch: bool, + pub active_project: Option, + pub free_build: bool, pub projects: Vec, } @@ -98,7 +100,7 @@ pub fn factory_panel_plants( }; let free_minds = production.free_minds(&engine.world, mission, owner); let mut plants: Vec<_> = owned_factories(&engine.world, mission, production, owner) - .filter_map(|(index, handle, _)| { + .filter_map(|(index, handle, free_build)| { if factory_depleted(mission, handle) { return None; } @@ -113,6 +115,14 @@ pub fn factory_panel_plants( .pending .iter() .find(|order| order.plant == handle && order.owner == owner); + let batch = production + .batches + .iter() + .find(|batch| batch.plant == handle && batch.owner == owner); + let active_project = order + .map(|order| order.scheme) + .or_else(|| batch.map(|batch| batch.scheme)) + .filter(|&scheme| production.player_project(scheme)); let progress = order.map(|order| { let time = ratio( now_ms.wrapping_sub(order.start_ms) as f32, @@ -135,10 +145,9 @@ pub fn factory_panel_plants( label_id: label, free_minds, progress, - batch: production - .batches - .iter() - .any(|batch| batch.plant == handle && batch.owner == owner), + batch: batch.is_some(), + active_project, + free_build, projects, }, )) @@ -162,7 +171,11 @@ pub struct FactoryPanelProject { pub stats: WarbotStats, } -pub fn factory_panel_project(engine: &Engine, scheme: usize) -> Option { +pub fn factory_panel_project( + engine: &Engine, + scheme: usize, + current_factory: Option, +) -> Option { let (mission, production) = loaded_production(engine).ok()?; let root = factory_project_root(engine, scheme)?; let draft = &mission.object_drafts[root]; @@ -180,7 +193,14 @@ pub fn factory_panel_project(engine: &Engine, scheme: usize) -> Option