aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game/src/strategic_view.rs
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-02 11:12:06 +0300
committerValentin Popov <valentin@popov.link>2026-12-02 11:12:06 +0300
commit733f9d92e0d4e40ed40db42fa6cd11294e49eb7b (patch)
tree824dde369c5fbb7b3180c42899c4f0555929ca4b /apps/fparkan-game/src/strategic_view.rs
parent61208d874cb3d9bf93e9f7c60aceebc287454b62 (diff)
downloadfparkan-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/src/strategic_view.rs')
-rw-r--r--apps/fparkan-game/src/strategic_view.rs92
1 files changed, 72 insertions, 20 deletions
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,