show dashboard icon when flashlight is active

This commit is contained in:
yuni 2024-05-07 20:54:24 +02:00
parent b4441f6715
commit 7d31a95a7c
3 changed files with 59 additions and 0 deletions

View file

@ -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;
}
}
}

View file

@ -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<Image> = 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<Image> = 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<DashboardFlashlight>>,
settings: Res<var::Settings>,
) {
for mut vis in &mut q_flashlight {
*vis = bool2vis(settings.flashlight_active);
}
}
fn update_speedometer(
q_camera: Query<&LinearVelocity, With<actor::PlayerCamera>>,
q_target: Query<&LinearVelocity, With<IsTargeted>>,
@ -961,3 +1008,11 @@ fn update_overlay_visibility(
AMBIENT_LIGHT
};
}
fn bool2vis(parameter: bool) -> Visibility {
if parameter {
Visibility::Inherited
} else {
Visibility::Hidden
}
}

View file

@ -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,