diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-02 11:12:06 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-02 11:12:06 +0300 |
| commit | 733f9d92e0d4e40ed40db42fa6cd11294e49eb7b (patch) | |
| tree | 824dde369c5fbb7b3180c42899c4f0555929ca4b /apps/fparkan-game | |
| parent | 61208d874cb3d9bf93e9f7c60aceebc287454b62 (diff) | |
| download | fparkan-733f9d92e0d4e40ed40db42fa6cd11294e49eb7b.tar.xz fparkan-733f9d92e0d4e40ed40db42fa6cd11294e49eb7b.zip | |
feat(ui): show native strategic waypoint cursors
Read the animated cursor strips and their hotspots from the installed UI atlas. Use the native Land.map areal flag and chassis selector for both the preview cursor and waypoint input. In stock Two Fortresses, compared one accepted and one rejected map point against the original and checked the return to the cockpit with Vulkan validation.
Diffstat (limited to 'apps/fparkan-game')
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 3 | ||||
| -rw-r--r-- | apps/fparkan-game/src/mission_overlay.rs | 27 | ||||
| -rw-r--r-- | apps/fparkan-game/src/strategic_view.rs | 92 | ||||
| -rw-r--r-- | apps/fparkan-game/src/strategy_cursor_hud.rs | 107 |
4 files changed, 206 insertions, 23 deletions
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs index 347bdc1b..02727c17 100644 --- a/apps/fparkan-game/src/main.rs +++ b/apps/fparkan-game/src/main.rs @@ -39,6 +39,7 @@ mod strategic_balance_hud; #[cfg(windows)] mod strategic_roster_hud; mod strategic_view; +mod strategy_cursor_hud; #[cfg(windows)] mod weapon_hud; #[cfg(test)] @@ -11466,7 +11467,7 @@ impl StaticVulkanApp { } else { let _ = window.set_cursor_grab(CursorGrabMode::None); } - window.set_cursor_visible(!active); + window.set_cursor_visible(!active && !self.shows_strategy_cursor()); } } diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs index 8825094b..66a40697 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -2,8 +2,9 @@ use super::{ append_environment_gradient_material, append_environment_range, cockpit_dial::CockpitDial, cockpit_radar_hud::CockpitRadarHud, factory_menu::FactoryProjectPanel, horizontal_fov, quad_indices, satellite_map::SatelliteMap, screen_tl_quad_vertices_pixels, - world_pipeline_state, DirectoryVfs, EnvironmentGpuRange, LegacyBlendMode, LegacyDepthMode, - StaticPreviewScene, StaticVulkanApp, VulkanStaticTexture, + strategy_cursor_hud::StrategyCursorHud, world_pipeline_state, DirectoryVfs, + EnvironmentGpuRange, LegacyBlendMode, LegacyDepthMode, StaticPreviewScene, StaticVulkanApp, + VulkanStaticTexture, }; #[cfg(windows)] use super::{ @@ -25,6 +26,7 @@ pub(super) use fparkan_assets::ui_sprite::source_over; pub(super) struct MissionOverlay { pub(super) satellite_map: Option<SatelliteMap>, strategy_toolbar: Option<EnvironmentGpuRange>, + pub(super) strategy_cursor: Option<StrategyCursorHud>, #[cfg(windows)] strategy_balance: Option<StrategicBalanceHud>, #[cfg(windows)] @@ -146,9 +148,15 @@ impl MissionOverlay { None }) }); + let strategy_cursor = cockpit.and_then(|_| { + StrategyCursorHud::load(root, preview) + .inspect_err(|error| eprintln!("strategy_cursor_unavailable reason={error}")) + .ok() + }); Self { satellite_map, strategy_toolbar, + strategy_cursor, #[cfg(windows)] strategy_balance, #[cfg(windows)] @@ -184,6 +192,11 @@ impl MissionOverlay { if let Some(toolbar) = self.strategy_toolbar { remove(toolbar.range_index, ranges, counts); } + if let Some(cursor) = &self.strategy_cursor { + for range in cursor.ranges() { + remove(range, ranges, counts); + } + } #[cfg(windows)] if let Some(balance) = &self.strategy_balance { remove(balance.range_index(), ranges, counts); @@ -226,6 +239,10 @@ impl StaticVulkanApp { pub(super) fn draw_mission_overlay(&mut self) -> Result<(), String> { #[cfg(windows)] let warbot_rows = self.strategic_warbot_rows(); + #[cfg(windows)] + let cursor = self.strategy_cursor(warbot_rows.len()); + #[cfg(not(windows))] + let cursor = self.strategy_cursor(0); let (Some(renderer), Some(frame)) = (&mut self.renderer, &self.pending_scene_update) else { return Ok(()); }; @@ -372,6 +389,12 @@ impl StaticVulkanApp { frame.clock.time_ms, )?; } + if let Some(hud) = &mut self.overlay.strategy_cursor { + if let Some(window) = &self.window { + hud.sync_visibility(window, cursor.is_some(), self.mouse_look); + } + hud.draw(renderer, &mut self.mesh, frame.clock.time_ms, cursor)?; + } Ok(()) } } diff --git a/apps/fparkan-game/src/strategic_view.rs b/apps/fparkan-game/src/strategic_view.rs index 762e9fbd..de24e8fa 100644 --- a/apps/fparkan-game/src/strategic_view.rs +++ b/apps/fparkan-game/src/strategic_view.rs @@ -2,7 +2,8 @@ use super::{ player_movement_key, screen_ray_from_pixels, LegacyD3d7Projection, PreviewCameraFrame, StaticVulkanApp, }; -use fparkan_assets::strategic_roster::{hit_test, order_at, ListHit, RosterOrder}; +use fparkan_assets::strategic_roster::{covers_pointer, hit_test, order_at, ListHit, RosterOrder}; +use fparkan_assets::strategy_cursor::StrategyCursor; use fparkan_assets::strategy_toolbar::{command_button_at, ToolbarAction}; use fparkan_runtime::strategic_orders; use fparkan_runtime::strategic_roster::{warbot_rows, WarbotRow}; @@ -49,6 +50,32 @@ impl ActiveCommandView { } impl StaticVulkanApp { + pub(super) fn shows_strategy_cursor(&self) -> bool { + self.overlay.strategy_cursor.is_some() + && self.window_focused + && !self.mission_paused + && self + .command_view + .as_ref() + .is_some_and(|view| view.pointer.is_some()) + } + + pub(super) fn strategy_cursor(&self, rows: usize) -> Option<([f32; 2], StrategyCursor)> { + let view = self + .command_view + .as_ref() + .filter(|_| self.shows_strategy_cursor())?; + let xy = view.pointer?; + let kind = if view.route_draft.is_none() || over_strategy_controls(xy, rows) { + StrategyCursor::Arrow + } else if self.pick_route_point(xy, view.selected_warbot).is_some() { + StrategyCursor::Place + } else { + StrategyCursor::WrongPlace + }; + Some((xy, kind)) + } + pub(super) fn open_strategy(&mut self) -> bool { if self.factory_menu.is_some() || self.demo_camera.is_some() || self.mission_paused { return false; @@ -225,12 +252,27 @@ impl StaticVulkanApp { } fn click_strategy(&mut self, button: MouseButton) { - let Some(view) = self.command_view.as_mut() else { + let Some(view) = self.command_view.as_ref() else { return; }; let Some(xy) = view.pointer else { return; }; + let rows = self + .mission_engine + .as_ref() + .zip(self.cockpit) + .filter(|_| button == MouseButton::Left && view.warbots_open) + .map_or_else(Vec::new, |(engine, cockpit)| warbot_rows(engine, cockpit)); + let point = (button == MouseButton::Left + && view.route_draft.is_some() + && !over_strategy_controls(xy, rows.len())) + .then(|| self.pick_route_point(xy, view.selected_warbot)) + .flatten(); + let view = self + .command_view + .as_mut() + .expect("active command view above"); let map = self.overlay.satellite_map.as_mut(); let Some((engine, cockpit)) = self.mission_engine.as_mut().zip(self.cockpit) else { return; @@ -263,7 +305,6 @@ impl StaticVulkanApp { Some(ToolbarAction::Warbots) => view.refresh_warbots(&warbot_rows(engine, cockpit)), None => { if view.warbots_open { - let rows = warbot_rows(engine, cockpit); match hit_test(xy, rows.len()) { Some(ListHit::Close) => { view.warbots_open = false; @@ -298,29 +339,35 @@ impl StaticVulkanApp { None => {} } } - let Some(draft) = &mut view.route_draft else { - return; - }; - let point = if let Some(map) = map.filter(|map| map.covers_command_point(xy)) { - map.command_destination(xy) - } else { - self.window.as_ref().and_then(|window| { - let size = window.inner_size(); - terrain_destination( - &self.terrain, - &self.view_camera, - [size.width as f32, size.height as f32], - xy, - ) - }) - }; - if let Some(point) = point { + if let Some((draft, point)) = view.route_draft.as_mut().zip(point) { draft.push(point); } } } } + fn pick_route_point(&self, xy: [f32; 2], actor: Option<ObjectHandle>) -> Option<[f32; 2]> { + let engine = self.mission_engine.as_ref()?; + let actor = actor?; + let point = if let Some(map) = self + .overlay + .satellite_map + .as_ref() + .filter(|map| map.covers_command_point(xy)) + { + map.command_destination(xy) + } else { + let size = self.window.as_ref()?.inner_size(); + terrain_destination( + &self.terrain, + &self.view_camera, + [size.width as f32, size.height as f32], + xy, + ) + }?; + strategic_orders::accepts_waypoint(engine, actor, point).then_some(point) + } + #[cfg(windows)] pub(super) fn strategic_warbot_rows(&mut self) -> Vec<WarbotRow> { let Some(view) = self.command_view.as_mut().filter(|view| view.warbots_open) else { @@ -336,6 +383,11 @@ impl StaticVulkanApp { } } +fn over_strategy_controls(xy: [f32; 2], rows: usize) -> bool { + (0.0..fparkan_assets::strategy_toolbar::EXTENT[0] as f32).contains(&xy[0]) + || covers_pointer(xy, rows) +} + fn terrain_destination( terrain: &TerrainWorld, camera: &PreviewCameraFrame, diff --git a/apps/fparkan-game/src/strategy_cursor_hud.rs b/apps/fparkan-game/src/strategy_cursor_hud.rs new file mode 100644 index 00000000..d64217a5 --- /dev/null +++ b/apps/fparkan-game/src/strategy_cursor_hud.rs @@ -0,0 +1,107 @@ +use super::{ + mission_overlay::add_overlay_sprite, screen_tl_quad_vertices_pixels, DirectoryVfs, + EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer, VulkanStaticMesh, +}; +use fparkan_assets::strategy_cursor::{self, CursorStrip, StrategyCursor, PHASES}; +use std::path::Path; +use winit::window::Window; + +pub(super) struct StrategyCursorHud { + strips: [CursorDraw; 3], + visible: bool, +} + +struct CursorDraw { + range: EnvironmentGpuRange, + size: [f32; 2], + hotspot: [f32; 2], + delay_ms: u32, + phase: u32, + last_change_ms: u32, +} + +impl StrategyCursorHud { + pub(super) fn load(root: &Path, preview: &mut StaticPreviewScene) -> Result<Self, String> { + let [arrow, place, wrong_place] = strategy_cursor::load(&DirectoryVfs::new(root))?; + let mut load = |strip: CursorStrip| { + let size = [ + (strip.image.width / PHASES) as f32, + strip.image.height as f32, + ]; + Ok::<_, String>(CursorDraw { + range: add_overlay_sprite( + preview, + strip.image, + [0.0, 0.0, size[0], size[1]], + [1.0; 3], + 1.0, + )?, + size, + hotspot: strip.hotspot.map(|axis| axis as f32), + delay_ms: strip.phase_delay_ms, + phase: 0, + last_change_ms: 0, + }) + }; + Ok(Self { + strips: [load(arrow)?, load(place)?, load(wrong_place)?], + visible: false, + }) + } + + pub(super) fn ranges(&self) -> [usize; 3] { + std::array::from_fn(|i| self.strips[i].range.range_index) + } + + pub(super) fn sync_visibility(&mut self, window: &Window, visible: bool, mouse_look: bool) { + if self.visible != visible { + self.visible = visible; + window.set_cursor_visible(!visible && !mouse_look); + } + } + + pub(super) fn draw( + &mut self, + renderer: &mut VulkanSmokeRenderer, + mesh: &mut VulkanStaticMesh, + now_ms: u32, + cursor: Option<([f32; 2], StrategyCursor)>, + ) -> Result<(), String> { + for (kind, strip) in StrategyCursor::ALL.into_iter().zip(&mut self.strips) { + let position = cursor + .filter(|(_, current)| kind == *current) + .map(|(xy, _)| xy); + renderer + .set_draw_range_index_count( + strip.range.range_index, + if position.is_some() { 6 } else { 0 }, + ) + .map_err(|error| error.to_string())?; + let Some(position) = position else { + continue; + }; + let half = strip.size.map(|axis| axis * 0.5); + let center = + std::array::from_fn(|i| position[i].round_ties_even() - strip.hotspot[i] + half[i]); + let left = strip.phase as f32 / PHASES as f32; + let right = (strip.phase + 1) as f32 / PHASES as f32; + let vertices = screen_tl_quad_vertices_pixels( + center, + half[0], + half[1], + [640.0, 480.0], + [1.0; 3], + 1.0, + [[left, 0.0], [left, 1.0], [right, 1.0], [right, 0.0]], + ); + let start = strip.range.vertex_start; + mesh.vertices[start..start + vertices.len()].copy_from_slice(&vertices); + // iron3d+0x57500 draws the current phase, then advances one frame if due. + if now_ms.saturating_sub(strip.last_change_ms) > strip.delay_ms { + strip.phase = (strip.phase + 1) % PHASES; + strip.last_change_ms = now_ms; + } + } + Ok(()) + } +} |
