use actual data for gauges
This commit is contained in:
parent
c38fcaa8dd
commit
99c32ce516
21
src/hud.rs
21
src/hud.rs
|
@ -97,7 +97,7 @@ enum Gauge {
|
||||||
Health,
|
Health,
|
||||||
Power,
|
Power,
|
||||||
Oxygen,
|
Oxygen,
|
||||||
Fuel,
|
Integrity,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
|
@ -345,13 +345,13 @@ fn setup(
|
||||||
));
|
));
|
||||||
});
|
});
|
||||||
|
|
||||||
// HP/O2/Fuel/Power Gauges
|
// HP/O2/Suit Integrity/Power Gauges
|
||||||
let gauges_handle: Handle<Image> = asset_server.load("sprites/gauge_horizontal.png");
|
let gauges_handle: Handle<Image> = asset_server.load("sprites/gauge_horizontal.png");
|
||||||
let gauges = [
|
let gauges = [
|
||||||
("sprites/dashboard_highbeams.png", Gauge::Health),
|
("sprites/dashboard_highbeams.png", Gauge::Health),
|
||||||
("sprites/dashboard_highbeams.png", Gauge::Power),
|
("sprites/dashboard_highbeams.png", Gauge::Power),
|
||||||
("sprites/dashboard_highbeams.png", Gauge::Oxygen),
|
("sprites/dashboard_highbeams.png", Gauge::Oxygen),
|
||||||
("sprites/dashboard_highbeams.png", Gauge::Fuel),
|
("sprites/dashboard_highbeams.png", Gauge::Integrity),
|
||||||
];
|
];
|
||||||
for (i, (sprite, gauge)) in gauges.iter().enumerate() {
|
for (i, (sprite, gauge)) in gauges.iter().enumerate() {
|
||||||
let bar_length = if i == 0 { 196.0 } else { 128.0 };
|
let bar_length = if i == 0 { 196.0 } else { 128.0 };
|
||||||
|
@ -666,15 +666,20 @@ fn update_speedometer(
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_gauges(
|
fn update_gauges(
|
||||||
|
q_player: Query<(&actor::HitPoints, &actor::Suit), With<actor::Player>>,
|
||||||
mut q_gauges: Query<(&mut Style, &mut BackgroundColor, &Gauge, &GaugeLength)>,
|
mut q_gauges: Query<(&mut Style, &mut BackgroundColor, &Gauge, &GaugeLength)>,
|
||||||
settings: Res<var::Settings>,
|
settings: Res<var::Settings>,
|
||||||
) {
|
) {
|
||||||
|
let player = q_player.get_single();
|
||||||
|
if player.is_err() { return; }
|
||||||
|
let (hp, suit) = player.unwrap();
|
||||||
|
|
||||||
for (mut style, mut bg, gauge, len) in &mut q_gauges {
|
for (mut style, mut bg, gauge, len) in &mut q_gauges {
|
||||||
let value = match gauge {
|
let value: f32 = match gauge {
|
||||||
Gauge::Health => 0.9,
|
Gauge::Health => hp.current / hp.max,
|
||||||
Gauge::Oxygen => 0.1,
|
Gauge::Oxygen => suit.oxygen / suit.oxygen_max,
|
||||||
Gauge::Fuel => 0.3,
|
Gauge::Integrity => suit.integrity,
|
||||||
Gauge::Power => 1.0,
|
Gauge::Power => suit.power / suit.power_max,
|
||||||
};
|
};
|
||||||
if value < 0.5 {
|
if value < 0.5 {
|
||||||
*bg = settings.hud_color_alert.into();
|
*bg = settings.hud_color_alert.into();
|
||||||
|
|
Loading…
Reference in a new issue