add update_gauges system (dummy data for now)

This commit is contained in:
yuni 2024-05-08 00:24:36 +02:00
parent 32e5c2258c
commit dc0d4be8ea

View file

@ -42,6 +42,7 @@ impl Plugin for HudPlugin {
update_hud,
update_dashboard,
update_speedometer,
update_gauges,
handle_input,
handle_target_event,
));
@ -84,6 +85,7 @@ impl Plugin for HudPlugin {
#[derive(Component)] struct Speedometer2;
#[derive(Component)] struct Dashboard;
#[derive(Component)] struct DashboardFlashlight;
#[derive(Component)] struct GaugeLength(f32);
#[derive(Component)] pub struct ToggleableHudElement;
#[derive(Component)] pub struct ToggleableHudMapElement;
#[derive(Component)] struct Selectagon;
@ -386,6 +388,7 @@ fn setup(
..Default::default()
},
gauge.clone(),
GaugeLength(bar_length),
));
});
@ -662,6 +665,27 @@ fn update_speedometer(
}
}
fn update_gauges(
mut q_gauges: Query<(&mut Style, &mut BackgroundColor, &Gauge, &GaugeLength)>,
settings: Res<var::Settings>,
) {
for (mut style, mut bg, gauge, len) in &mut q_gauges {
let value = match gauge {
Gauge::Health => 0.9,
Gauge::Oxygen => 0.1,
Gauge::Fuel => 0.3,
Gauge::Power => 1.0,
};
if value < 0.5 {
*bg = settings.hud_color_alert.into();
}
else {
*bg = settings.hud_color.into();
}
style.width = Val::Px(len.0 * value);
}
}
fn update_hud(
diagnostics: Res<DiagnosticsStore>,
time: Res<Time>,