From 7d31a95a7c87e11e95840426f9255320613cfea6 Mon Sep 17 00:00:00 2001 From: hut Date: Tue, 7 May 2024 20:54:24 +0200 Subject: [PATCH] show dashboard icon when flashlight is active --- src/actor.rs | 2 ++ src/hud.rs | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/var.rs | 2 ++ 3 files changed, 59 insertions(+) diff --git a/src/actor.rs b/src/actor.rs index 3fd444d..f74a01f 100644 --- a/src/actor.rs +++ b/src/actor.rs @@ -329,8 +329,10 @@ pub fn handle_input( ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click)); if *flashlight_vis == Visibility::Hidden { *flashlight_vis = Visibility::Visible; + settings.flashlight_active = true; } else { *flashlight_vis = Visibility::Hidden; + settings.flashlight_active = false; } } } diff --git a/src/hud.rs b/src/hud.rs index 15b225d..bf9ddf7 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -39,6 +39,7 @@ impl Plugin for HudPlugin { app.add_systems(Startup, setup); app.add_systems(Update, ( update_hud, + update_dashboard, update_speedometer, handle_input, handle_target_event, @@ -80,6 +81,8 @@ impl Plugin for HudPlugin { #[derive(Component)] struct Reticule; #[derive(Component)] struct Speedometer; #[derive(Component)] struct Speedometer2; +#[derive(Component)] struct Dashboard; +#[derive(Component)] struct DashboardFlashlight; #[derive(Component)] pub struct ToggleableHudElement; #[derive(Component)] pub struct ToggleableHudMapElement; #[derive(Component)] struct Selectagon; @@ -331,6 +334,41 @@ fn setup( )); }); + // Car-Dashboard-Style icons + let flashlight_visibility = bool2vis(visibility == Visibility::Visible && settings.flashlight_active); + let dashboard_flashlight_handle: Handle = asset_server.load("sprites/dashboard_highbeams.png"); + commands.spawn(( + NodeBundle { + style: Style { + width: Val::Percent(30.0), + height: Val::Percent(100.0), + bottom: Val::VMin(SPEEDOMETER_HEIGHT + 3.0), + left: Val::VMin(4.0), + align_items: AlignItems::End, + overflow: Overflow::clip(), + ..default() + }, + visibility, + ..default() + }, + Dashboard, + ToggleableHudElement, + )).with_children(|builder| { + builder.spawn(( + ImageBundle { + image: UiImage::new(dashboard_flashlight_handle), + style: Style { + width: Val::VMin(6.0), + height: Val::VMin(6.0), + ..Default::default() + }, + visibility: flashlight_visibility, + ..Default::default() + }, + DashboardFlashlight, + )); + }); + // Add Speedometer let speedometer_handle: Handle = asset_server.load("sprites/speedometer.png"); commands.spawn(( @@ -465,6 +503,15 @@ fn setup( ew_updateoverlays.send(UpdateOverlayVisibility); } +fn update_dashboard( + mut q_flashlight: Query<&mut Visibility, With>, + settings: Res, +) { + for mut vis in &mut q_flashlight { + *vis = bool2vis(settings.flashlight_active); + } +} + fn update_speedometer( q_camera: Query<&LinearVelocity, With>, q_target: Query<&LinearVelocity, With>, @@ -961,3 +1008,11 @@ fn update_overlay_visibility( AMBIENT_LIGHT }; } + +fn bool2vis(parameter: bool) -> Visibility { + if parameter { + Visibility::Inherited + } else { + Visibility::Hidden + } +} diff --git a/src/var.rs b/src/var.rs index 6788ed6..105dc6c 100644 --- a/src/var.rs +++ b/src/var.rs @@ -59,6 +59,7 @@ pub struct Settings { pub hud_color_choices: Color, pub hud_color_speedometer: Color, pub chat_speed: f32, + pub flashlight_active: bool, pub hud_active: bool, pub map_active: bool, pub is_zooming: bool, @@ -165,6 +166,7 @@ impl Default for Settings { hud_color_choices: Color::hex("#727272").unwrap(), hud_color_speedometer: Color::hex("#BE1251").unwrap(), chat_speed: DEFAULT_CHAT_SPEED * if dev_mode { 2.5 } else { 1.0 }, + flashlight_active: false, hud_active: true, map_active: false, is_zooming: false,