From fd42fb7e4fa27d2fe03ee8b6532949b7c1b13ace Mon Sep 17 00:00:00 2001 From: Valentin Popov Date: Wed, 2 Dec 2026 16:42:10 +0400 Subject: feat(ui): transfer designer projects to strategic factories --- apps/fparkan-game/src/factory_menu.rs | 75 +++++++++++++++++++++++++---------- 1 file changed, 54 insertions(+), 21 deletions(-) (limited to 'apps/fparkan-game/src/factory_menu.rs') diff --git a/apps/fparkan-game/src/factory_menu.rs b/apps/fparkan-game/src/factory_menu.rs index 1ce2f683..05c29ab7 100644 --- a/apps/fparkan-game/src/factory_menu.rs +++ b/apps/fparkan-game/src/factory_menu.rs @@ -35,6 +35,9 @@ use winit::{ keyboard::{KeyCode, PhysicalKey}, }; +#[cfg(windows)] +mod strategic; + #[derive(Clone)] pub(super) struct FactoryChoice { pub(super) factory: Option, @@ -49,6 +52,7 @@ pub(super) struct FactoryMenu { cursor: [f32; 2], pressed: Option, pub(super) designer: Option, + strategy_plant: Option, } pub(super) struct DesignerSession { @@ -164,13 +168,13 @@ impl DesignerSession { impl FactoryMenu { pub(super) fn new(choices: Vec) -> Self { - debug_assert!(!choices.is_empty()); Self { choices, selected: 0, cursor: [f32::NAN; 2], pressed: None, designer: None, + strategy_plant: None, } } @@ -178,6 +182,11 @@ impl FactoryMenu { &self.choices[self.selected] } + fn factory(&self) -> Option { + self.strategy_plant + .or_else(|| self.choices.get(self.selected)?.factory) + } + fn navigate(&mut self, backwards: bool) { let len = self.choices.len(); let offset = if backwards { len - 1 } else { 1 }; @@ -185,7 +194,11 @@ impl FactoryMenu { } fn visible_slots(&self) -> Range { - self.slots_for(self.selected) + if self.choices.is_empty() { + 0..0 + } else { + self.slots_for(self.selected) + } } fn slots_for(&self, index: usize) -> Range { @@ -207,12 +220,10 @@ impl FactoryMenu { let chassis = engine .zip(cockpit) .map_or_else(Vec::new, |(engine, cockpit)| { - factory_chassis_choices(engine, cockpit, self.selected().factory).unwrap_or_else( - |error| { - eprintln!("designer_chassis_catalogue_failed {error}"); - Vec::new() - }, - ) + factory_chassis_choices(engine, cockpit, self.factory()).unwrap_or_else(|error| { + eprintln!("designer_chassis_catalogue_failed {error}"); + Vec::new() + }) }); let mut designer = DesignerSession { slots: self.visible_slots(), @@ -491,7 +502,7 @@ impl FactoryMenu { resource: String, clock_ms: u32, ) { - let result = prepare_factory_chassis(engine, cockpit, self.selected().factory, &resource) + let result = prepare_factory_chassis(engine, cockpit, self.factory(), &resource) .and_then(|project| edit_factory_project(&project, &[]).map(|bytes| (project, bytes))) .map_err(|error| error.to_string()) .and_then(|(project, bytes)| PreparedProjectModel::prepare(engine, project, bytes)); @@ -599,6 +610,9 @@ impl FactoryMenu { } pub(super) fn title(&self) -> String { + if self.strategy_plant.is_some() { + return "Конструктор варботов".into(); + } let choice = self.selected(); let factory = choice.factory.map_or_else( || "Завод".to_owned(), @@ -634,12 +648,12 @@ struct ProjectPicture { impl FactoryProjectPanel { #[cfg(windows)] pub(super) fn draw_strategic_model( - &self, + &mut self, renderer: &mut VulkanSmokeRenderer, active: (usize, u32), viewport: [f32; 2], ) -> Result<(), String> { - if let Some(designer) = &self.designer { + if let Some(designer) = &mut self.designer { designer.draw_factory_model(renderer, active, viewport)?; } Ok(()) @@ -756,6 +770,15 @@ impl FactoryProjectPanel { impl StaticVulkanApp { fn send_designer_project(&mut self) { + #[cfg(windows)] + if let Some(plant) = self + .factory_menu + .as_ref() + .and_then(|menu| menu.strategy_plant) + { + self.send_strategic_project(plant); + return; + } let (Some(menu), Some(engine), Some(cockpit)) = (&self.factory_menu, &mut self.mission_engine, self.cockpit) else { @@ -823,6 +846,16 @@ impl StaticVulkanApp { menu.designer_action(DesignerAction::Send, self.simulation_time_ms); } + fn leave_designer(&mut self) { + if let Some(menu) = &mut self.factory_menu { + if menu.strategy_plant.is_some() { + self.factory_menu = None; + } else { + menu.designer_action(DesignerAction::Exit, self.simulation_time_ms); + } + } + } + pub(super) fn handle_designer_project_key( &mut self, key: PhysicalKey, @@ -926,9 +959,7 @@ impl StaticVulkanApp { if state == ElementState::Pressed && !repeat && !self.mission_paused { if menu.designer.is_some() { match code { - KeyCode::Escape => { - menu.designer_action(DesignerAction::Exit, self.simulation_time_ms) - } + KeyCode::Escape => self.leave_designer(), KeyCode::Enter | KeyCode::NumpadEnter => self.send_designer_project(), _ => {} } @@ -1032,7 +1063,7 @@ impl StaticVulkanApp { return true; } Some(DesignerAction::Load) => { - let factory = menu.selected().factory; + let factory = menu.factory(); let choices: Vec<_> = menu .choices .iter() @@ -1087,12 +1118,14 @@ impl StaticVulkanApp { return true; } if let Some(action) = hover { - if action == DesignerAction::Send { - self.send_designer_project(); - } else { - menu.designer_action(action, self.simulation_time_ms); - if matches!(action, DesignerAction::Project(_)) { - menu.refresh_sockets(self.mission_engine.as_ref()); + match action { + DesignerAction::Send => self.send_designer_project(), + DesignerAction::Exit => self.leave_designer(), + _ => { + menu.designer_action(action, self.simulation_time_ms); + if matches!(action, DesignerAction::Project(_)) { + menu.refresh_sockets(self.mission_engine.as_ref()); + } } } self.update_mission_title(); -- cgit v1.2.3