diff options
Diffstat (limited to 'apps/fparkan-game/src/strategic_view.rs')
| -rw-r--r-- | apps/fparkan-game/src/strategic_view.rs | 138 |
1 files changed, 100 insertions, 38 deletions
diff --git a/apps/fparkan-game/src/strategic_view.rs b/apps/fparkan-game/src/strategic_view.rs index a7da38da..a6719c84 100644 --- a/apps/fparkan-game/src/strategic_view.rs +++ b/apps/fparkan-game/src/strategic_view.rs @@ -13,11 +13,12 @@ use fparkan_assets::strategy_cursor::StrategyCursor; use fparkan_assets::strategy_toolbar::{ command_button_at, ToolbarAction, ToolbarFold, ToolbarLayout, }; +use fparkan_runtime::strategic_buildings::BuildingSection; #[cfg(windows)] -use fparkan_runtime::strategic_buildings::{other_buildings, BuildingRow}; +use fparkan_runtime::strategic_buildings::{building_rows, BuildingRow}; use fparkan_runtime::strategic_roster::{warbot_rows, WarbotRow}; use fparkan_runtime::strategic_view::{ - command_post, mobile_command_post, CommandCamera, CommandCameraInput, COMMAND_FOV, + command_post, mobile_command_post, CommandCamera, CommandCameraInput, CommandPost, COMMAND_FOV, }; use fparkan_runtime::{ projectile_unit_hit, satellite_contacts, @@ -42,13 +43,14 @@ pub(super) fn captured_command_target( pub(super) struct ActiveCommandView { camera: CommandCamera, + command_posts: Vec<CommandPost>, pointer: Option<[f32; 2]>, toolbar: ToolbarFold, pub(super) warbots_open: bool, #[cfg(windows)] factory: Option<FactorySelection>, #[cfg(windows)] - other_buildings_open: bool, + building_section: Option<BuildingSection>, #[cfg(windows)] selected_building: Option<ObjectHandle>, pub(super) selected_warbot: Option<ObjectHandle>, @@ -111,11 +113,11 @@ impl FactorySelection { } impl ActiveCommandView { - pub(super) fn other_buildings_open(&self) -> bool { + pub(super) fn building_section(&self) -> Option<BuildingSection> { #[cfg(windows)] - return self.other_buildings_open; + return self.building_section; #[cfg(not(windows))] - false + None } pub(super) fn selected_building(&self) -> Option<ObjectHandle> { @@ -150,6 +152,24 @@ impl ActiveCommandView { None } + #[cfg(windows)] + fn focus_bunker( + &mut self, + engine: &super::Engine, + cockpit: super::StartingCockpit, + target: ObjectHandle, + ) { + let Some(previous) = self.camera.focus_bunker(engine, cockpit, target) else { + return; + }; + let post = CommandPost::Bunker(target); + if let Some(index) = self.command_posts.iter().position(|&entry| entry == post) { + self.command_posts.truncate(index); + } else { + self.command_posts.push(previous); + } + } + pub(super) fn factories_open(&self) -> bool { #[cfg(windows)] { @@ -263,13 +283,14 @@ impl StaticVulkanApp { }; self.command_view = Some(ActiveCommandView { camera, + command_posts: Vec::new(), pointer: None, toolbar: ToolbarFold::default(), warbots_open: false, #[cfg(windows)] factory: None, #[cfg(windows)] - other_buildings_open: false, + building_section: None, #[cfg(windows)] selected_building: None, selected_warbot: None, @@ -391,6 +412,7 @@ impl StaticVulkanApp { view.warbots_open = false; } else if self.close_strategic_buildings() || self.close_strategic_factory_panel() + || self.back_to_previous_command_post() { return true; } else { @@ -543,7 +565,7 @@ impl StaticVulkanApp { #[cfg(windows)] { view.factory = None; - view.other_buildings_open = false; + view.building_section = None; view.selected_building = None; } if let Some(row) = view.refresh_warbots(&warbot_rows(engine, cockpit)) { @@ -568,28 +590,34 @@ impl StaticVulkanApp { { view.factory = Some(factory); view.warbots_open = false; - view.other_buildings_open = false; + view.building_section = None; view.selected_building = None; view.selected_warbot = None; view.order_input = None; } } } - Some(ToolbarAction::OtherBuildings) => - { + Some(action @ (ToolbarAction::Bunkers | ToolbarAction::OtherBuildings)) => { #[cfg(windows)] - if view.other_buildings_open { - view.other_buildings_open = false; - } else if self.overlay.strategic_buildings.is_some() { - let rows = other_buildings(engine, cockpit); - if !rows.is_empty() { - view.other_buildings_open = true; - view.factory = None; - view.warbots_open = false; - view.selected_warbot = None; - view.order_input = None; - if let Some(row) = view.refresh_building_selection(&rows) { - self.play_building_selection(row); + { + let section = if action == ToolbarAction::Bunkers { + BuildingSection::Bunkers + } else { + BuildingSection::Other + }; + if view.building_section == Some(section) { + view.building_section = None; + } else if self.overlay.strategic_buildings.is_some() { + let rows = building_rows(engine, cockpit, section); + if !rows.is_empty() { + view.building_section = Some(section); + view.factory = None; + view.warbots_open = false; + view.selected_warbot = None; + view.order_input = None; + if let Some(row) = view.refresh_building_selection(&rows) { + self.play_building_selection(row); + } } } } @@ -601,18 +629,29 @@ impl StaticVulkanApp { .as_deref() .and_then(|map| map.command_destination(xy)) .and_then(|point| satellite_contacts::pick_contact(engine, cockpit, point)); - let list_visible = - view.other_buildings_open && view.toolbar_layout().sections_visible(); - if list_visible || map_hit.is_some() { - let rows = other_buildings(engine, cockpit); - let row = match list_visible - .then(|| strategic_buildings::hit_test(xy, rows.len())) - .flatten() - { + if let Some(section) = view.building_section { + let rows = building_rows(engine, cockpit, section); + let hit = view + .toolbar_layout() + .sections_visible() + .then(|| { + strategic_buildings::hit_test( + xy, + rows.len(), + section == BuildingSection::Bunkers, + ) + }) + .flatten(); + let row = match hit { Some(BuildingHit::Close) => { - view.other_buildings_open = false; + view.building_section = None; return; } + Some(BuildingHit::Command(index)) => { + let row = rows[index]; + view.focus_bunker(engine, cockpit, row.handle); + Some(row) + } Some(BuildingHit::Row(index)) => rows.get(index).copied(), None => rows.into_iter().find(|row| Some(row.handle) == map_hit), }; @@ -621,6 +660,16 @@ impl StaticVulkanApp { } return; } + if let Some(target) = map_hit { + let row = [BuildingSection::Other, BuildingSection::Bunkers] + .into_iter() + .flat_map(|section| building_rows(engine, cockpit, section)) + .find(|row| row.handle == target); + if let Some(row) = row.and_then(|row| view.select_building(row)) { + self.play_building_selection(row); + } + return; + } } #[cfg(windows)] if let Some(factory) = view @@ -908,24 +957,37 @@ impl StaticVulkanApp { return self .command_view .as_mut() - .is_some_and(|view| std::mem::take(&mut view.other_buildings_open)); + .is_some_and(|view| view.building_section.take().is_some()); #[cfg(not(windows))] false } + fn back_to_previous_command_post(&mut self) -> bool { + let Some((view, engine)) = self.command_view.as_mut().zip(self.mission_engine.as_ref()) + else { + return false; + }; + while let Some(post) = view.command_posts.pop() { + if let Some(camera) = CommandCamera::new(engine, post) { + view.camera = camera; + return true; + } + } + false + } + #[cfg(windows)] pub(super) fn strategic_buildings_frame( &mut self, ) -> Option<super::strategic_buildings_hud::BuildingsFrame> { - let view = self - .command_view - .as_mut() - .filter(|view| view.other_buildings_open)?; + let view = self.command_view.as_mut()?; + let section = view.building_section?; let (engine, cockpit) = self.mission_engine.as_ref().zip(self.cockpit)?; - let rows = other_buildings(engine, cockpit); + let rows = building_rows(engine, cockpit, section); let changed = view.refresh_building_selection(&rows); let frame = view.toolbar_layout().sections_visible().then_some( super::strategic_buildings_hud::BuildingsFrame { + section, rows, selected: view.selected_building, }, |
