diff --git a/assets/sprites/speedometer_white.png b/assets/sprites/speedometer_white.png new file mode 100644 index 0000000..7f89686 Binary files /dev/null and b/assets/sprites/speedometer_white.png differ diff --git a/media/speedometer2.svg b/media/speedometer2.svg index 2655e94..a2e4203 100644 --- a/media/speedometer2.svg +++ b/media/speedometer2.svg @@ -2,9 +2,9 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/hud.rs b/src/hud.rs index 1aa4bfe..3b0a20f 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -25,6 +25,8 @@ pub const LOG_MAX_TIME_S: f64 = 30.0; pub const LOG_MAX_ROWS: usize = 30; pub const LOG_MAX: usize = LOG_MAX_ROWS; pub const MAX_CHOICES: usize = 10; +pub const SPEEDOMETER_WIDTH: f32 = 40.0; +pub const SPEEDOMETER_HEIGHT: f32 = 10.0; pub const AMBIENT_LIGHT: f32 = 0.0; // Space is DARK pub const AMBIENT_LIGHT_AR: f32 = 30.0; //pub const REPLY_NUMBERS: [char; 10] = ['❶', '❷', '❸', '❹', '❺', '❻', '❼', '❽', '❾', '⓿']; @@ -37,6 +39,7 @@ impl Plugin for HudPlugin { app.add_systems(Startup, setup); app.add_systems(Update, ( update_hud, + update_speedometer, handle_input, handle_target_event, )); @@ -75,6 +78,7 @@ impl Plugin for HudPlugin { #[derive(Component)] struct NodeCurrentChatLine; #[derive(Component)] struct Reticule; #[derive(Component)] struct Speedometer; +#[derive(Component)] struct Speedometer2; #[derive(Component)] pub struct ToggleableHudElement; #[derive(Component)] pub struct ToggleableHudMapElement; #[derive(Component)] struct Selectagon; @@ -321,11 +325,12 @@ fn setup( }); // Add Speedometer - let reticule_handle: Handle = asset_server.load("sprites/speedometer.png"); + let speedometer_height = 10.0; + let speedometer_handle: Handle = asset_server.load("sprites/speedometer.png"); commands.spawn(( NodeBundle { style: Style { - width: Val::VMin(10.0), + width: Val::VMin(0.0), height: Val::Percent(100.0), align_items: AlignItems::End, overflow: Overflow::clip(), @@ -339,10 +344,38 @@ fn setup( )).with_children(|builder| { builder.spawn(( ImageBundle { - image: UiImage::new(reticule_handle), + image: UiImage::new(speedometer_handle), style: Style { - width: Val::VMin(50.0), - height: Val::VMin(10.0), + width: Val::VMin(SPEEDOMETER_WIDTH), + height: Val::VMin(SPEEDOMETER_HEIGHT), + ..Default::default() + }, + ..Default::default() + }, + )); + }); + let speedometer_handle: Handle = asset_server.load("sprites/speedometer_white.png"); + commands.spawn(( + NodeBundle { + style: Style { + width: Val::VMin(0.0), + height: Val::Percent(100.0), + align_items: AlignItems::End, + overflow: Overflow::clip(), + ..default() + }, + visibility, + ..default() + }, + Speedometer2, + ToggleableHudElement, + )).with_children(|builder| { + builder.spawn(( + ImageBundle { + image: UiImage::new(speedometer_handle), + style: Style { + width: Val::VMin(SPEEDOMETER_WIDTH), + height: Val::VMin(SPEEDOMETER_HEIGHT), ..Default::default() }, ..Default::default() @@ -411,6 +444,30 @@ fn setup( ew_updateoverlays.send(UpdateOverlayVisibility); } +fn update_speedometer( + q_camera: Query<&LinearVelocity, With>, + mut q_speedometer: Query<&mut Style, (With, Without)>, + mut q_speedometer2: Query<&mut Style, (With, Without)>, +) { + if let Ok(cam_v) = q_camera.get_single() { + let speed = cam_v.length(); + + let speedometer_split = 5_000.0; + if let Ok(mut speedometer) = q_speedometer.get_single_mut() { + let custom_c = speedometer_split; + let fraction = nature::lorenz_factor_custom_c((custom_c - speed).clamp(0.0, custom_c), custom_c).clamp(0.0, 1.0) as f32; + let wid = (fraction * SPEEDOMETER_WIDTH).clamp(0.0, 100.0); + speedometer.width = Val::VMin(wid); + } + if let Ok(mut speedometer2) = q_speedometer2.get_single_mut() { + let custom_c = nature::C - speedometer_split; + let fraction = nature::lorenz_factor_custom_c((custom_c - speed + speedometer_split).clamp(0.0, custom_c), custom_c).clamp(0.0, 1.0) as f32; + let wid = (fraction * SPEEDOMETER_WIDTH).clamp(0.0, 100.0); + speedometer2.width = Val::VMin(wid); + } + } +} + fn update_hud( diagnostics: Res, time: Res