diff options
Diffstat (limited to 'apps')
| -rw-r--r-- | apps/fparkan-game/src/mission_overlay.rs | 75 | ||||
| -rw-r--r-- | apps/fparkan-game/src/satellite_map.rs | 59 |
2 files changed, 82 insertions, 52 deletions
diff --git a/apps/fparkan-game/src/mission_overlay.rs b/apps/fparkan-game/src/mission_overlay.rs index 167c5562..3edf0970 100644 --- a/apps/fparkan-game/src/mission_overlay.rs +++ b/apps/fparkan-game/src/mission_overlay.rs @@ -1,14 +1,17 @@ use super::{ - cockpit_dial::CockpitDial, cockpit_radar_hud::CockpitRadarHud, - factory_menu::FactoryProjectPanel, horizontal_fov, satellite_map::SatelliteMap, - StaticPreviewScene, StaticVulkanApp, + 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, }; #[cfg(windows)] use super::{mission_help::MissionHelp, mission_hints::MissionHints, weapon_hud::WeaponHud}; +use fparkan_assets::{strategy_toolbar, RgbaImage}; use fparkan_runtime::{ cockpit_altimeter::cockpit_altimeter, radar::{cockpit_radar_period, cockpit_range_readout}, - Engine, StartingCockpit, + AutoDemoCamera, Engine, StartingCockpit, }; use std::path::Path; @@ -17,6 +20,7 @@ pub(super) use fparkan_assets::ui_sprite::source_over; #[derive(Default)] pub(super) struct MissionOverlay { pub(super) satellite_map: Option<SatelliteMap>, + strategy_toolbar: Option<EnvironmentGpuRange>, dial: Option<CockpitDial>, pub(super) factory_projects: Option<FactoryProjectPanel>, pub(super) radar: Option<CockpitRadarHud>, @@ -64,8 +68,20 @@ impl MissionOverlay { None }); if autodemo { + let strategy_toolbar = + strategy_toolbar::load_expanded_toolbar(&DirectoryVfs::new(root)) + .and_then(|image| { + let [width, height] = strategy_toolbar::EXTENT.map(|axis| axis as f32); + add_overlay_sprite(preview, image, [0.0, 0.0, width, height], [1.0; 3], 1.0) + }) + .map(Some) + .unwrap_or_else(|error| { + eprintln!("strategy_toolbar_unavailable reason={error}"); + None + }); return Self { satellite_map, + strategy_toolbar, ..Self::default() }; } @@ -104,6 +120,7 @@ impl MissionOverlay { }); Self { satellite_map, + strategy_toolbar: None, dial, factory_projects, radar, @@ -132,6 +149,9 @@ impl MissionOverlay { remove(range, ranges, counts); } } + if let Some(toolbar) = self.strategy_toolbar { + remove(toolbar.range_index, ranges, counts); + } if let Some(radar) = &self.radar { for range in radar.ranges() { remove(range, ranges, counts); @@ -167,6 +187,15 @@ impl StaticVulkanApp { let (Some(renderer), Some(frame)) = (&mut self.renderer, &self.pending_scene_update) else { return Ok(()); }; + if let Some(toolbar) = self.overlay.strategy_toolbar { + let visible = self + .demo_camera + .as_ref() + .is_some_and(AutoDemoCamera::shows_strategy_toolbar); + renderer + .set_draw_range_index_count(toolbar.range_index, if visible { 6 } else { 0 }) + .map_err(|error| error.to_string())?; + } if let Some(map) = &mut self.overlay.satellite_map { let demo_target = self .demo_camera @@ -261,3 +290,41 @@ impl StaticVulkanApp { Ok(()) } } + +pub(super) fn overlay_texture(image: RgbaImage) -> VulkanStaticTexture { + VulkanStaticTexture { + width: image.width, + height: image.height, + rgba8: image.rgba8, + mip_levels: Vec::new(), + } +} + +pub(super) fn add_overlay_sprite( + preview: &mut StaticPreviewScene, + image: RgbaImage, + [left, top, right, bottom]: [f32; 4], + color: [f32; 3], + alpha: f32, +) -> Result<EnvironmentGpuRange, String> { + let material = append_environment_gradient_material(&mut preview.materials)?; + preview.materials[material].screen_tl = true; + preview.materials[material].sky_far_depth = false; + preview.materials[material].texture = overlay_texture(image); + append_environment_range( + &mut preview.mesh, + material, + screen_tl_quad_vertices_pixels( + [(left + right) * 0.5, (top + bottom) * 0.5], + (right - left) * 0.5, + (bottom - top) * 0.5, + [640.0, 480.0], + color, + alpha, + [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]], + ) + .to_vec(), + quad_indices(1)?, + world_pipeline_state(LegacyBlendMode::SourceAlpha, LegacyDepthMode::Disabled), + ) +} diff --git a/apps/fparkan-game/src/satellite_map.rs b/apps/fparkan-game/src/satellite_map.rs index 6eef249b..d2a240eb 100644 --- a/apps/fparkan-game/src/satellite_map.rs +++ b/apps/fparkan-game/src/satellite_map.rs @@ -1,7 +1,6 @@ use super::{ - append_environment_gradient_material, append_environment_range, quad_indices, - screen_tl_quad_vertices_pixels, world_pipeline_state, EnvironmentGpuRange, LegacyBlendMode, - LegacyDepthMode, StaticPreviewScene, VulkanSmokeRenderer, VulkanStaticTexture, + mission_overlay::{add_overlay_sprite, overlay_texture}, + EnvironmentGpuRange, StaticPreviewScene, VulkanSmokeRenderer, }; use fparkan_assets::{ satellite_map::{load_satellite_map, MAP_INSET, MAP_RECT}, @@ -12,12 +11,10 @@ use fparkan_vfs::DirectoryVfs; use fparkan_world::ObjectHandle; use std::{path::Path, sync::Arc}; -const UV: [[f32; 2]; 4] = [[0.0, 0.0], [0.0, 1.0], [1.0, 1.0], [1.0, 0.0]]; // Native initial background colour, iron3d+0x74cf0. const MAP_TINT: [f32; 3] = [55.0 / 255.0, 1.0, 55.0 / 255.0]; const MAP_ALPHA: f32 = 128.0 / 255.0; const MAP_SIZE: usize = 256; -const UI_VIEWPORT: [f32; 2] = [640.0, 480.0]; pub(super) struct SatelliteMap { frame: EnvironmentGpuRange, @@ -53,10 +50,10 @@ impl SatelliteMap { compass_bottom, ]; Ok(Some(Self { - frame: add_sprite(preview, assets.frame, bounds, [1.0; 3], 1.0)?, - background: add_sprite(preview, assets.background, image, MAP_TINT, MAP_ALPHA)?, - compass: add_sprite(preview, assets.compass, compass, [1.0; 3], 1.0)?, - contact_layer: add_sprite(preview, empty_layer(), image, [1.0; 3], 1.0)?, + frame: add_overlay_sprite(preview, assets.frame, bounds, [1.0; 3], 1.0)?, + background: add_overlay_sprite(preview, assets.background, image, MAP_TINT, MAP_ALPHA)?, + compass: add_overlay_sprite(preview, assets.compass, compass, [1.0; 3], 1.0)?, + contact_layer: add_overlay_sprite(preview, empty_layer(), image, [1.0; 3], 1.0)?, icons: assets.icons, extent: satellite_contacts::landscape_extent(engine), buildings: Vec::new(), @@ -121,7 +118,11 @@ impl SatelliteMap { paint_unit(&mut layer, unit); } renderer - .update_material_texture(self.contact_layer.material_index, 0, &texture(layer)) + .update_material_texture( + self.contact_layer.material_index, + 0, + &overlay_texture(layer), + ) .map_err(|error| error.to_string())?; self.buildings = buildings; self.units = units; @@ -250,41 +251,3 @@ fn paint_building( } } } - -fn texture(image: RgbaImage) -> VulkanStaticTexture { - VulkanStaticTexture { - width: image.width, - height: image.height, - rgba8: image.rgba8, - mip_levels: Vec::new(), - } -} - -fn add_sprite( - preview: &mut StaticPreviewScene, - image: RgbaImage, - [left, top, right, bottom]: [f32; 4], - color: [f32; 3], - alpha: f32, -) -> Result<EnvironmentGpuRange, String> { - let material = append_environment_gradient_material(&mut preview.materials)?; - preview.materials[material].screen_tl = true; - preview.materials[material].sky_far_depth = false; - preview.materials[material].texture = texture(image); - append_environment_range( - &mut preview.mesh, - material, - screen_tl_quad_vertices_pixels( - [(left + right) * 0.5, (top + bottom) * 0.5], - (right - left) * 0.5, - (bottom - top) * 0.5, - UI_VIEWPORT, - color, - alpha, - UV, - ) - .to_vec(), - quad_indices(1)?, - world_pipeline_state(LegacyBlendMode::SourceAlpha, LegacyDepthMode::Disabled), - ) -} |
