diff --git a/src/hud.rs b/src/hud.rs index 3c8aec4..0ec0901 100644 --- a/src/hud.rs +++ b/src/hud.rs @@ -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, +) { + 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, time: Res