show dashboard icon when flashlight is active
This commit is contained in:
parent
b4441f6715
commit
7d31a95a7c
|
@ -329,8 +329,10 @@ pub fn handle_input(
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
||||||
if *flashlight_vis == Visibility::Hidden {
|
if *flashlight_vis == Visibility::Hidden {
|
||||||
*flashlight_vis = Visibility::Visible;
|
*flashlight_vis = Visibility::Visible;
|
||||||
|
settings.flashlight_active = true;
|
||||||
} else {
|
} else {
|
||||||
*flashlight_vis = Visibility::Hidden;
|
*flashlight_vis = Visibility::Hidden;
|
||||||
|
settings.flashlight_active = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
55
src/hud.rs
55
src/hud.rs
|
@ -39,6 +39,7 @@ impl Plugin for HudPlugin {
|
||||||
app.add_systems(Startup, setup);
|
app.add_systems(Startup, setup);
|
||||||
app.add_systems(Update, (
|
app.add_systems(Update, (
|
||||||
update_hud,
|
update_hud,
|
||||||
|
update_dashboard,
|
||||||
update_speedometer,
|
update_speedometer,
|
||||||
handle_input,
|
handle_input,
|
||||||
handle_target_event,
|
handle_target_event,
|
||||||
|
@ -80,6 +81,8 @@ impl Plugin for HudPlugin {
|
||||||
#[derive(Component)] struct Reticule;
|
#[derive(Component)] struct Reticule;
|
||||||
#[derive(Component)] struct Speedometer;
|
#[derive(Component)] struct Speedometer;
|
||||||
#[derive(Component)] struct Speedometer2;
|
#[derive(Component)] struct Speedometer2;
|
||||||
|
#[derive(Component)] struct Dashboard;
|
||||||
|
#[derive(Component)] struct DashboardFlashlight;
|
||||||
#[derive(Component)] pub struct ToggleableHudElement;
|
#[derive(Component)] pub struct ToggleableHudElement;
|
||||||
#[derive(Component)] pub struct ToggleableHudMapElement;
|
#[derive(Component)] pub struct ToggleableHudMapElement;
|
||||||
#[derive(Component)] struct Selectagon;
|
#[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
|
// Add Speedometer
|
||||||
let speedometer_handle: Handle<Image> = asset_server.load("sprites/speedometer.png");
|
let speedometer_handle: Handle<Image> = asset_server.load("sprites/speedometer.png");
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
|
@ -465,6 +503,15 @@ fn setup(
|
||||||
ew_updateoverlays.send(UpdateOverlayVisibility);
|
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(
|
fn update_speedometer(
|
||||||
q_camera: Query<&LinearVelocity, With<actor::PlayerCamera>>,
|
q_camera: Query<&LinearVelocity, With<actor::PlayerCamera>>,
|
||||||
q_target: Query<&LinearVelocity, With<IsTargeted>>,
|
q_target: Query<&LinearVelocity, With<IsTargeted>>,
|
||||||
|
@ -961,3 +1008,11 @@ fn update_overlay_visibility(
|
||||||
AMBIENT_LIGHT
|
AMBIENT_LIGHT
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bool2vis(parameter: bool) -> Visibility {
|
||||||
|
if parameter {
|
||||||
|
Visibility::Inherited
|
||||||
|
} else {
|
||||||
|
Visibility::Hidden
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -59,6 +59,7 @@ pub struct Settings {
|
||||||
pub hud_color_choices: Color,
|
pub hud_color_choices: Color,
|
||||||
pub hud_color_speedometer: Color,
|
pub hud_color_speedometer: Color,
|
||||||
pub chat_speed: f32,
|
pub chat_speed: f32,
|
||||||
|
pub flashlight_active: bool,
|
||||||
pub hud_active: bool,
|
pub hud_active: bool,
|
||||||
pub map_active: bool,
|
pub map_active: bool,
|
||||||
pub is_zooming: bool,
|
pub is_zooming: bool,
|
||||||
|
@ -165,6 +166,7 @@ impl Default for Settings {
|
||||||
hud_color_choices: Color::hex("#727272").unwrap(),
|
hud_color_choices: Color::hex("#727272").unwrap(),
|
||||||
hud_color_speedometer: Color::hex("#BE1251").unwrap(),
|
hud_color_speedometer: Color::hex("#BE1251").unwrap(),
|
||||||
chat_speed: DEFAULT_CHAT_SPEED * if dev_mode { 2.5 } else { 1.0 },
|
chat_speed: DEFAULT_CHAT_SPEED * if dev_mode { 2.5 } else { 1.0 },
|
||||||
|
flashlight_active: false,
|
||||||
hud_active: true,
|
hud_active: true,
|
||||||
map_active: false,
|
map_active: false,
|
||||||
is_zooming: false,
|
is_zooming: false,
|
||||||
|
|
Loading…
Reference in a new issue