simplify dashboard definition
This commit is contained in:
parent
b012a2d51e
commit
fa8c21203f
76
src/hud.rs
76
src/hud.rs
|
@ -19,6 +19,7 @@ use bevy_xpbd_3d::prelude::*;
|
|||
use std::collections::VecDeque;
|
||||
use std::time::SystemTime;
|
||||
|
||||
pub const DASHBOARD_ICON_SIZE: f32 = 64.0;
|
||||
pub const HUD_REFRESH_TIME: f32 = 0.1;
|
||||
pub const LOG_MAX_TIME_S: f64 = 30.0;
|
||||
pub const LOG_MAX_ROWS: usize = 30;
|
||||
|
@ -32,6 +33,14 @@ pub const AMBIENT_LIGHT_AR: f32 = 20.0;
|
|||
//pub const REPLY_NUMBERS: [char; 10] = ['①', '②', '③', '④', '⑤', '⑥', '⑦', '⑧', '⑨', '⑩'];
|
||||
pub const REPLY_NUMBERS: [char; 10] = ['➀', '➁', '➂', '➃', '➄', '➅', '➆', '➇', '➈', '➉'];
|
||||
|
||||
pub const DASHBOARD_DEF: &[(Dashboard, &str)] = &[
|
||||
(Dashboard::Flashlight, "highbeams"),
|
||||
(Dashboard::Leak, "leak"),
|
||||
(Dashboard::RotationStabiliser, "rotation_stabiliser"),
|
||||
(Dashboard::CruiseControl, "cruise_control"),
|
||||
(Dashboard::Radioactivity, "radioactivity"),
|
||||
];
|
||||
|
||||
pub struct HudPlugin;
|
||||
impl Plugin for HudPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
|
@ -89,7 +98,7 @@ impl Plugin for HudPlugin {
|
|||
#[derive(Component)] pub struct PointOfInterestMarker(pub Entity);
|
||||
|
||||
#[derive(Component, Debug, Copy, Clone)]
|
||||
enum Dashboard {
|
||||
pub enum Dashboard {
|
||||
Leak,
|
||||
Flashlight,
|
||||
RotationStabiliser,
|
||||
|
@ -434,13 +443,9 @@ pub fn setup(
|
|||
|
||||
|
||||
// Car-Dashboard-Style icons
|
||||
let dashboard_icon_size = 64.0;
|
||||
let flashlight_visibility = bool2vis(visibility == Visibility::Visible && settings.flashlight_active);
|
||||
let rotation_stabiliser_visibility = bool2vis(visibility == Visibility::Visible && !settings.rotation_stabilizer_active);
|
||||
let cruise_control_visibility = bool2vis(visibility == Visibility::Visible && settings.cruise_control_active);
|
||||
let style_dashboard = Style {
|
||||
width: Val::Px(dashboard_icon_size),
|
||||
height: Val::Px(dashboard_icon_size),
|
||||
width: Val::Px(DASHBOARD_ICON_SIZE),
|
||||
height: Val::Px(DASHBOARD_ICON_SIZE),
|
||||
..Default::default()
|
||||
};
|
||||
commands.spawn((
|
||||
|
@ -459,51 +464,18 @@ pub fn setup(
|
|||
},
|
||||
ToggleableHudElement,
|
||||
)).with_children(|builder| {
|
||||
builder.spawn((
|
||||
ImageBundle {
|
||||
image: UiImage::new(asset_server.load("sprites/dashboard_highbeams.png")),
|
||||
style: style_dashboard.clone(),
|
||||
visibility: flashlight_visibility,
|
||||
..Default::default()
|
||||
},
|
||||
Dashboard::Flashlight,
|
||||
));
|
||||
builder.spawn((
|
||||
ImageBundle {
|
||||
image: UiImage::new(asset_server.load("sprites/dashboard_leak.png")),
|
||||
style: style_dashboard.clone(),
|
||||
visibility: flashlight_visibility,
|
||||
..Default::default()
|
||||
},
|
||||
Dashboard::Leak,
|
||||
));
|
||||
builder.spawn((
|
||||
ImageBundle {
|
||||
image: UiImage::new(asset_server.load("sprites/dashboard_rotation_stabiliser.png")),
|
||||
style: style_dashboard.clone(),
|
||||
visibility: rotation_stabiliser_visibility,
|
||||
..Default::default()
|
||||
},
|
||||
Dashboard::RotationStabiliser,
|
||||
));
|
||||
builder.spawn((
|
||||
ImageBundle {
|
||||
image: UiImage::new(asset_server.load("sprites/dashboard_cruise_control.png")),
|
||||
style: style_dashboard.clone(),
|
||||
visibility: cruise_control_visibility,
|
||||
..Default::default()
|
||||
},
|
||||
Dashboard::CruiseControl,
|
||||
));
|
||||
builder.spawn((
|
||||
ImageBundle {
|
||||
image: UiImage::new(asset_server.load("sprites/dashboard_radioactivity.png")),
|
||||
style: style_dashboard.clone(),
|
||||
visibility: Visibility::Hidden,
|
||||
..Default::default()
|
||||
},
|
||||
Dashboard::Radioactivity,
|
||||
));
|
||||
for (component, filename) in DASHBOARD_DEF {
|
||||
builder.spawn((
|
||||
*component,
|
||||
ImageBundle {
|
||||
image: UiImage::new(asset_server.load(
|
||||
format!("sprites/dashboard_{}.png", filename))),
|
||||
style: style_dashboard.clone(),
|
||||
visibility: Visibility::Hidden,
|
||||
..Default::default()
|
||||
},
|
||||
));
|
||||
}
|
||||
});
|
||||
|
||||
// Add Speedometer
|
||||
|
|
Loading…
Reference in a new issue