diff options
| author | Valentin Popov <valentin@popov.link> | 2026-12-03 17:14:49 +0300 |
|---|---|---|
| committer | Valentin Popov <valentin@popov.link> | 2026-12-03 17:14:49 +0300 |
| commit | 1776dd8007169ef4f04969f0a5edcc423b6d67bc (patch) | |
| tree | d6bf261f4ecf07ddb79026130448f5aa937d49a1 | |
| parent | ca66e64b3995229ca7c8771b75ca26a60c3e344f (diff) | |
| download | fparkan-1776dd8007169ef4f04969f0a5edcc423b6d67bc.tar.xz fparkan-1776dd8007169ef4f04969f0a5edcc423b6d67bc.zip | |
feat(ui): restore cockpit status indicators
| -rw-r--r-- | apps/fparkan-game/src/cockpit_dial.rs | 7 | ||||
| -rw-r--r-- | apps/fparkan-game/src/cockpit_status_hud.rs | 202 | ||||
| -rw-r--r-- | apps/fparkan-game/src/main.rs | 8 | ||||
| -rw-r--r-- | apps/fparkan-game/src/mission_overlay.rs | 24 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/cockpit_indicators.rs | 51 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/lib.rs | 1 | ||||
| -rw-r--r-- | crates/fparkan-runtime/src/repair_system.rs | 12 | ||||
| -rw-r--r-- | docs/appendices/knowledge-boundaries.md | 6 | ||||
| -rw-r--r-- | docs/appendices/ui-shell.md | 15 |
9 files changed, 315 insertions, 11 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)); diff --git a/crates/fparkan-runtime/src/cockpit_indicators.rs b/crates/fparkan-runtime/src/cockpit_indicators.rs new file mode 100644 index 00000000..e51e00bb --- /dev/null +++ b/crates/fparkan-runtime/src/cockpit_indicators.rs @@ -0,0 +1,51 @@ +//! Control device flags and control mode shown at the base of the cockpit dial. + +use crate::{ + repair_system::is_self_repair_device, Engine, MissionControlDeviceTableStatus, + RemoteWarbotControl, StartingCockpit, +}; + +/// The live device flags and control mode of an active cockpit. +#[derive(Clone, Copy, Debug, Eq, PartialEq)] +pub struct CockpitIndicators { + pub self_repair: bool, + pub camouflage: bool, + pub onsite: bool, + pub control: RemoteWarbotControl, +} + +/// Reads the occupied cockpit instead of the hero left at a remote console. +pub fn cockpit_indicators(engine: &Engine, cockpit: StartingCockpit) -> Option<CockpitIndicators> { + let mission = engine.loaded.as_ref()?; + let (onsite, control) = match mission.boarding { + Some(board) if board.cockpit.handle == cockpit.handle => ( + board.remote.is_none(), + board.remote.unwrap_or(RemoteWarbotControl::Manual), + ), + None if mission.local_hero == Some(cockpit.handle) => (true, RemoteWarbotControl::Manual), + _ => return None, + }; + let devices = mission + .control_device_tables + .iter() + .find(|table| table.handle == cockpit.handle) + .and_then(|table| match &table.status { + MissionControlDeviceTableStatus::Available(devices) => Some(devices.as_slice()), + _ => None, + }) + .unwrap_or_default(); + let self_repair = devices + .iter() + .find(|device| is_self_repair_device(device)) + .is_some_and(|device| device.native_word_50_bits == Some(0x20)); + let camouflage = devices + .iter() + .find(|device| device.key == 0 && device.descriptor.tag == 10 && device.factory_tag == 10) + .is_some_and(|device| device.native_word_50_bits == Some(0x1000)); + Some(CockpitIndicators { + self_repair, + camouflage, + onsite, + control, + }) +} diff --git a/crates/fparkan-runtime/src/lib.rs b/crates/fparkan-runtime/src/lib.rs index 6081fe98..7170b78f 100644 --- a/crates/fparkan-runtime/src/lib.rs +++ b/crates/fparkan-runtime/src/lib.rs @@ -112,6 +112,7 @@ pub use destruction::{ unit_destruction_effect_sources, DestroyedMesh, UnitDestructionEffect, }; pub mod cockpit_altimeter; +pub mod cockpit_indicators; pub mod cockpit_instruments; pub mod cockpit_speedometer; mod flight_altitude; diff --git a/crates/fparkan-runtime/src/repair_system.rs b/crates/fparkan-runtime/src/repair_system.rs index 8fa6c09a..6d94a093 100644 --- a/crates/fparkan-runtime/src/repair_system.rs +++ b/crates/fparkan-runtime/src/repair_system.rs @@ -1,6 +1,10 @@ //! State switch for the controlled unit's Control repair device. -use crate::{Engine, MissionControlDeviceTableStatus, StartingCockpit}; +use crate::{EffectiveControlDevice, Engine, MissionControlDeviceTableStatus, StartingCockpit}; + +pub(super) fn is_self_repair_device(device: &EffectiveControlDevice) -> bool { + device.key == 0 && device.descriptor.tag == 15 && device.factory_tag == 15 +} /// Switches the selected unit's self-repair device when it is present. pub fn toggle_self_repair(engine: &mut Engine, cockpit: StartingCockpit) -> Option<bool> { @@ -12,9 +16,9 @@ pub fn toggle_self_repair(engine: &mut Engine, cockpit: StartingCockpit) -> Opti let MissionControlDeviceTableStatus::Available(devices) = &mut table.status else { return None; }; - let device = devices.iter_mut().find(|device| { - device.key == 0 && device.descriptor.tag == 15 && device.factory_tag == 15 - })?; + let device = devices + .iter_mut() + .find(|device| is_self_repair_device(device))?; // Control+0x22c90 handles the inverse switch command 0x40. let enabled = device.native_word_50_bits? != 0x20; device.native_word_50_bits = Some(if enabled { 0x20 } else { 0 }); diff --git a/docs/appendices/knowledge-boundaries.md b/docs/appendices/knowledge-boundaries.md index 28892141..0819e995 100644 --- a/docs/appendices/knowledge-boundaries.md +++ b/docs/appendices/knowledge-boundaries.md @@ -1463,8 +1463,10 @@ layout или glyph drawing. `menu_resources.cfg` и шесть варианто на фактическом дисплее `1280x1024`, widget tree, layout rules, sprite command semantics, focus/navigation и HUD state machine. -В нижнем радаре ещё открыты захват цели правой кнопкой, отметки группы -и кнопки на рамке прибора. Порядок объектов при одинаковой дальности +В нижнем радаре ещё открыты захват цели правой кнопкой и отметки группы. +В кабине остаются ночное видение (`N`), переключение маскировки (`H`) +и смена режима управления (`A`). Для красного индикатора ещё нужно сверить +условия отказа в высадке. Порядок объектов радара при одинаковой дальности и при смене режима ручного управления требует проверки. Для боковых приборов открыт пересчёт сферы при смене состава креплений. Если сферы узлов недоступны, используется сфера заголовка корневого MSH. diff --git a/docs/appendices/ui-shell.md b/docs/appendices/ui-shell.md index 045e04f3..56c5dc53 100644 --- a/docs/appendices/ui-shell.md +++ b/docs/appendices/ui-shell.md @@ -898,6 +898,21 @@ Control. Оружейный цикл в `Control.dll` по RVA `0x29ca0` разÐ координаты масштабируются независимо по ширине и высоте. [Хеш сборки iron3d.dll](../reference/original-binaries.md). +## Нижняя строка индикаторов кабины + +`iron3d.dll` по RVA `0x3f4b0` рисует восемь индикаторов. Слева показаны +саморемонт, ночное видение, маскировка и присутствие Капитана в кабине. +Справа идут предупреждение о высадке, ручное управление, автострелок +и автопилот. Рамки выбираются из `page6`, значки из `ui_menu` и `ui_menu3`. +Вызов RVA `0x3f5d0` подтвердил расположение рамок и три цвета значка. + +Индикатор саморемонта белеет после включения устройства клавишей `R`. +В дистанционной кабине справа отмечается выбранный режим варбота. +При отказе в высадке оригинал ставит флаг в RVA `0x639a0`. RVA `0x62df0` +убирает сигнал после трёх секунд. FParkan зажигает красный значок при отказе +текущей проверки высадки. +[Хеш сборки iron3d.dll](../reference/original-binaries.md). + ## Контакты на радаре кабины Круг в кабине читает результаты собственного скана занятой машины. |
