aboutsummaryrefslogtreecommitdiff
path: root/apps/fparkan-game
diff options
context:
space:
mode:
authorValentin Popov <valentin@popov.link>2026-12-03 17:14:49 +0300
committerValentin Popov <valentin@popov.link>2026-12-03 17:14:49 +0300
commit1776dd8007169ef4f04969f0a5edcc423b6d67bc (patch)
treed6bf261f4ecf07ddb79026130448f5aa937d49a1 /apps/fparkan-game
parentca66e64b3995229ca7c8771b75ca26a60c3e344f (diff)
downloadfparkan-1776dd8007169ef4f04969f0a5edcc423b6d67bc.tar.xz
fparkan-1776dd8007169ef4f04969f0a5edcc423b6d67bc.zip
feat(ui): restore cockpit status indicators
Diffstat (limited to 'apps/fparkan-game')
-rw-r--r--apps/fparkan-game/src/cockpit_dial.rs7
-rw-r--r--apps/fparkan-game/src/cockpit_status_hud.rs202
-rw-r--r--apps/fparkan-game/src/main.rs8
-rw-r--r--apps/fparkan-game/src/mission_overlay.rs24
4 files changed, 236 insertions, 5 deletions
diff --git a/apps/fparkan-game/src/cockpit_dial.rs b/apps/fparkan-game/src/cockpit_dial.rs
index ff422dea..f9063313 100644
--- a/apps/fparkan-game/src/cockpit_dial.rs
+++ b/apps/fparkan-game/src/cockpit_dial.rs
@@ -177,7 +177,10 @@ fn vertex([x, y]: [f32; 2], uv: [f32; 2], color: [f32; 3]) -> VulkanStaticVertex
)
}
-fn atlas_material(preview: &mut StaticPreviewScene, page: RgbaImage) -> Result<usize, String> {
+pub(super) fn atlas_material(
+ preview: &mut StaticPreviewScene,
+ page: RgbaImage,
+) -> Result<usize, String> {
let material = append_environment_gradient_material(&mut preview.materials)?;
preview.materials[material].screen_tl = true;
preview.materials[material].sky_far_depth = false;
@@ -190,7 +193,7 @@ fn atlas_material(preview: &mut StaticPreviewScene, page: RgbaImage) -> Result<u
Ok(material)
}
-fn append_range(
+pub(super) fn append_range(
preview: &mut StaticPreviewScene,
material: usize,
vertex_count: usize,
diff --git a/apps/fparkan-game/src/cockpit_status_hud.rs b/apps/fparkan-game/src/cockpit_status_hud.rs
new file mode 100644
index 00000000..440622af
--- /dev/null
+++ b/apps/fparkan-game/src/cockpit_status_hud.rs
@@ -0,0 +1,202 @@
+use super::{
+ cockpit_dial::{append_range, atlas_material},
+ quad_indices, screen_tl_quad_vertices_pixels, DirectoryVfs, EnvironmentGpuRange,
+ StaticPreviewScene, VulkanSmokeRenderer, VulkanStaticMesh, VulkanStaticVertex,
+};
+use fparkan_assets::ui_sprite::load_ui_page;
+use fparkan_runtime::{cockpit_indicators::CockpitIndicators, RemoteWarbotControl};
+use std::path::Path;
+
+// iron3d+0x3f6xx: left edge of each frame in 640×480 coordinates.
+const FRAME_X: [u32; 8] = [222, 240, 258, 280, 344, 366, 384, 402];
+const FRAME_SRC_X: [u32; 3] = [202, 220, 238];
+// iron3d+0x3f0d0: the danger icon uses ui_menu3, the others use ui_menu.
+const ICON_SRC: [[u32; 2]; 8] = [
+ [97, 126],
+ [238, 222],
+ [239, 126],
+ [223, 142],
+ [180, 27],
+ [113, 94],
+ [113, 110],
+ [81, 94],
+];
+const DANGER_INDEX: usize = 4;
+const MAIN_ICON_INDICES: [usize; 7] = [0, 1, 2, 3, 5, 6, 7];
+
+#[derive(Clone, Copy, Debug, Eq, PartialEq)]
+enum Lamp {
+ Off,
+ On,
+ Red,
+}
+
+impl Lamp {
+ fn from_active(active: bool) -> Self {
+ if active {
+ Self::On
+ } else {
+ Self::Off
+ }
+ }
+
+ fn color(self) -> [f32; 3] {
+ match self {
+ Self::Off => [128.0 / 255.0; 3],
+ Self::On => [1.0; 3],
+ Self::Red => [1.0, 0.0, 0.0],
+ }
+ }
+}
+
+fn lamps(state: CockpitIndicators, risk_since: Option<u32>, clock_ms: u32) -> [Lamp; 8] {
+ let mut lamps = [Lamp::Off; 8];
+ lamps[0] = Lamp::from_active(state.self_repair);
+ // Slot 1 follows the infrared camera pass when that pass is available.
+ lamps[2] = Lamp::from_active(state.camouflage);
+ lamps[3] = Lamp::from_active(state.onsite);
+ if risk_since.is_some_and(|start| clock_ms.wrapping_sub(start) <= 3_000) {
+ lamps[DANGER_INDEX] = Lamp::Red;
+ }
+ let mode = match state.control {
+ RemoteWarbotControl::Manual => 5,
+ RemoteWarbotControl::AutoGunner => 6,
+ RemoteWarbotControl::Autopilot => 7,
+ };
+ lamps[mode] = Lamp::On;
+ lamps
+}
+
+pub(super) struct CockpitStatusHud {
+ frames: EnvironmentGpuRange,
+ main_icons: EnvironmentGpuRange,
+ danger_icon: EnvironmentGpuRange,
+ risk_since: Option<u32>,
+}
+
+impl CockpitStatusHud {
+ pub(super) fn load(root: &Path, preview: &mut StaticPreviewScene) -> Result<Self, String> {
+ let vfs = DirectoryVfs::new(root);
+ let frames = load_ui_page(&vfs, "page6")?;
+ let icons = load_ui_page(&vfs, "ui_menu")?;
+ let danger = load_ui_page(&vfs, "ui_menu3")?;
+ if [&frames, &icons, &danger]
+ .iter()
+ .any(|page| [page.width, page.height] != [256; 2])
+ {
+ return Err("unexpected cockpit indicator atlas dimensions".into());
+ }
+ let frames = atlas_material(preview, frames)?;
+ let icons = atlas_material(preview, icons)?;
+ let danger = atlas_material(preview, danger)?;
+ Ok(Self {
+ frames: append_range(preview, frames, 32, quad_indices(8)?)?,
+ main_icons: append_range(preview, icons, 28, quad_indices(7)?)?,
+ danger_icon: append_range(preview, danger, 4, quad_indices(1)?)?,
+ risk_since: None,
+ })
+ }
+
+ pub(super) fn note_exit_result(&mut self, clock_ms: u32, rejected: bool) {
+ self.risk_since = rejected.then_some(clock_ms);
+ }
+
+ pub(super) fn ranges(&self) -> [usize; 3] {
+ [
+ self.frames.range_index,
+ self.main_icons.range_index,
+ self.danger_icon.range_index,
+ ]
+ }
+
+ pub(super) fn draw(
+ &self,
+ renderer: &mut VulkanSmokeRenderer,
+ mesh: &mut VulkanStaticMesh,
+ state: Option<CockpitIndicators>,
+ clock_ms: u32,
+ ) -> Result<(), String> {
+ for (range, count) in self.ranges().into_iter().zip([48, 42, 6]) {
+ renderer
+ .set_draw_range_index_count(range, if state.is_some() { count } else { 0 })
+ .map_err(|error| error.to_string())?;
+ }
+ let Some(state) = state else { return Ok(()) };
+ let lamps = lamps(state, self.risk_since, clock_ms);
+ for (index, lamp) in lamps.into_iter().enumerate() {
+ let x = FRAME_X[index];
+ let start = self.frames.vertex_start + index * 4;
+ mesh.vertices[start..start + 4].copy_from_slice(&quad(
+ [x, 459, 18, 25],
+ [FRAME_SRC_X[lamp as usize], 154, 17, 20],
+ [1.0; 3],
+ ));
+ }
+ let icon = |index: usize| {
+ let [u, v] = ICON_SRC[index];
+ quad(
+ [FRAME_X[index] + 1, 463, 15, 15],
+ [u, v, 15, 15],
+ lamps[index].color(),
+ )
+ };
+ for (slot, index) in MAIN_ICON_INDICES.into_iter().enumerate() {
+ let start = self.main_icons.vertex_start + slot * 4;
+ mesh.vertices[start..start + 4].copy_from_slice(&icon(index));
+ }
+ let start = self.danger_icon.vertex_start;
+ mesh.vertices[start..start + 4].copy_from_slice(&icon(DANGER_INDEX));
+ Ok(())
+ }
+}
+
+fn quad(
+ [left, top, width, height]: [u32; 4],
+ [u, v, tex_width, tex_height]: [u32; 4],
+ color: [f32; 3],
+) -> [VulkanStaticVertex; 4] {
+ let [hw, hh] = [width as f32 * 0.5, height as f32 * 0.5];
+ let [u0, v0] = [(u as f32 + 0.5) / 256.0, (v as f32 + 0.5) / 256.0];
+ let [u1, v1] = [
+ (u + tex_width) as f32 / 256.0,
+ (v + tex_height) as f32 / 256.0,
+ ];
+ screen_tl_quad_vertices_pixels(
+ [left as f32 + hw, top as f32 + hh],
+ hw,
+ hh,
+ [640.0, 480.0],
+ color,
+ 1.0,
+ [[u0, v0], [u0, v1], [u1, v1], [u1, v0]],
+ )
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn marks_the_active_control_mode_and_expires_the_risk_warning() {
+ let state = CockpitIndicators {
+ self_repair: true,
+ camouflage: false,
+ onsite: false,
+ control: RemoteWarbotControl::AutoGunner,
+ };
+ assert_eq!(
+ lamps(state, Some(100), 3_100),
+ [
+ Lamp::On,
+ Lamp::Off,
+ Lamp::Off,
+ Lamp::Off,
+ Lamp::Red,
+ Lamp::Off,
+ Lamp::On,
+ Lamp::Off
+ ],
+ );
+ assert_eq!(lamps(state, Some(100), 3_101)[DANGER_INDEX], Lamp::Off);
+ }
+}
diff --git a/apps/fparkan-game/src/main.rs b/apps/fparkan-game/src/main.rs
index 35721de9..a38186ce 100644
--- a/apps/fparkan-game/src/main.rs
+++ b/apps/fparkan-game/src/main.rs
@@ -12,6 +12,7 @@ mod cockpit_geometry;
mod cockpit_instrument;
mod cockpit_radar_hud;
mod cockpit_reticle;
+mod cockpit_status_hud;
mod cockpit_vertical_gauge;
#[cfg(windows)]
mod control_effects;
@@ -9436,9 +9437,10 @@ impl StaticVulkanApp {
fparkan_world::OriginalObjectId(vehicle.object_index as u32),
) == Some(vehicle.handle);
if disembark || !live {
- if let Some(hero) =
- disembark_warbot(engine).map_err(|error| error.to_string())?
- {
+ let hero = disembark_warbot(engine).map_err(|error| error.to_string())?;
+ self.overlay
+ .note_exit_result(control_clock_ms, disembark && live && hero.is_none());
+ if let Some(hero) = hero {
self.cockpit = Some(hero);
self.boarded_hero_index = None;
self.selected_contact = None;
diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs
index fe646cc6..a2aafd4b 100644
--- a/apps/fparkan-game/src/mission_overlay.rs
+++ b/apps/fparkan-game/src/mission_overlay.rs
@@ -3,6 +3,7 @@ use super::{
cockpit_dial::CockpitDial,
cockpit_radar_hud::CockpitRadarHud,
cockpit_reticle::CockpitReticle,
+ cockpit_status_hud::CockpitStatusHud,
factory_menu::FactoryProjectPanel,
horizontal_fov, quad_indices,
satellite_map::SatelliteMap,
@@ -27,6 +28,7 @@ use super::{
use fparkan_assets::RgbaImage;
use fparkan_runtime::{
cockpit_altimeter::cockpit_altimeter,
+ cockpit_indicators::cockpit_indicators,
cockpit_speedometer::cockpit_speedometer,
radar::{cockpit_radar_period, cockpit_range_readout},
AutoDemoCamera, Engine, StartingCockpit,
@@ -51,6 +53,7 @@ pub(super) struct MissionOverlay {
#[cfg(windows)]
strategic_tooltip: Option<StrategicTooltipHud>,
dial: Option<CockpitDial>,
+ cockpit_status: Option<CockpitStatusHud>,
reticle: Option<CockpitReticle>,
#[cfg(windows)]
pub(super) instrument: Option<CockpitInstrument>,
@@ -94,6 +97,11 @@ impl MissionOverlay {
None
})
});
+ let cockpit_status = cockpit.and_then(|_| {
+ CockpitStatusHud::load(root, preview)
+ .inspect_err(|error| eprintln!("cockpit_status_unavailable reason={error}"))
+ .ok()
+ });
let reticle = cockpit.and_then(|_| {
CockpitReticle::load(root, preview)
.inspect_err(|error| eprintln!("cockpit_reticle_unavailable reason={error}"))
@@ -219,6 +227,7 @@ impl MissionOverlay {
#[cfg(windows)]
strategic_tooltip,
dial,
+ cockpit_status,
reticle,
#[cfg(windows)]
instrument,
@@ -233,6 +242,12 @@ impl MissionOverlay {
}
}
+ pub(super) fn note_exit_result(&mut self, clock_ms: u32, rejected: bool) {
+ if let Some(status) = &mut self.cockpit_status {
+ status.note_exit_result(clock_ms, rejected);
+ }
+ }
+
pub(super) fn remove_world_ranges(
&self,
ranges: &mut Vec<usize>,
@@ -268,6 +283,11 @@ impl MissionOverlay {
remove(range, ranges, counts);
}
}
+ if let Some(status) = &self.cockpit_status {
+ for range in status.ranges() {
+ remove(range, ranges, counts);
+ }
+ }
#[cfg(windows)]
if let Some(balance) = &self.strategy_balance {
remove(balance.range_index(), ranges, counts);
@@ -537,6 +557,10 @@ impl StaticVulkanApp {
speed,
)?;
}
+ if let Some(status) = &self.overlay.cockpit_status {
+ let state = occupant.and_then(|(engine, cockpit)| cockpit_indicators(engine, cockpit));
+ status.draw(renderer, &mut self.mesh, state, frame.clock.time_ms)?;
+ }
if let Some(radar) = &mut self.overlay.radar {
let period =
occupant.and_then(|(engine, cockpit)| cockpit_radar_period(engine, cockpit));