simplify dashboard definition

This commit is contained in:
yuni 2024-05-15 05:34:10 +02:00
parent b012a2d51e
commit fa8c21203f

View file

@ -19,6 +19,7 @@ use bevy_xpbd_3d::prelude::*;
use std::collections::VecDeque; use std::collections::VecDeque;
use std::time::SystemTime; use std::time::SystemTime;
pub const DASHBOARD_ICON_SIZE: f32 = 64.0;
pub const HUD_REFRESH_TIME: f32 = 0.1; pub const HUD_REFRESH_TIME: f32 = 0.1;
pub const LOG_MAX_TIME_S: f64 = 30.0; pub const LOG_MAX_TIME_S: f64 = 30.0;
pub const LOG_MAX_ROWS: usize = 30; 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 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; pub struct HudPlugin;
impl Plugin for HudPlugin { impl Plugin for HudPlugin {
fn build(&self, app: &mut App) { fn build(&self, app: &mut App) {
@ -89,7 +98,7 @@ impl Plugin for HudPlugin {
#[derive(Component)] pub struct PointOfInterestMarker(pub Entity); #[derive(Component)] pub struct PointOfInterestMarker(pub Entity);
#[derive(Component, Debug, Copy, Clone)] #[derive(Component, Debug, Copy, Clone)]
enum Dashboard { pub enum Dashboard {
Leak, Leak,
Flashlight, Flashlight,
RotationStabiliser, RotationStabiliser,
@ -434,13 +443,9 @@ pub fn setup(
// Car-Dashboard-Style icons // 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 { let style_dashboard = Style {
width: Val::Px(dashboard_icon_size), width: Val::Px(DASHBOARD_ICON_SIZE),
height: Val::Px(dashboard_icon_size), height: Val::Px(DASHBOARD_ICON_SIZE),
..Default::default() ..Default::default()
}; };
commands.spawn(( commands.spawn((
@ -459,51 +464,18 @@ pub fn setup(
}, },
ToggleableHudElement, ToggleableHudElement,
)).with_children(|builder| { )).with_children(|builder| {
for (component, filename) in DASHBOARD_DEF {
builder.spawn(( builder.spawn((
*component,
ImageBundle { ImageBundle {
image: UiImage::new(asset_server.load("sprites/dashboard_highbeams.png")), image: UiImage::new(asset_server.load(
style: style_dashboard.clone(), format!("sprites/dashboard_{}.png", filename))),
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(), style: style_dashboard.clone(),
visibility: Visibility::Hidden, visibility: Visibility::Hidden,
..Default::default() ..Default::default()
}, },
Dashboard::Radioactivity,
)); ));
}
}); });
// Add Speedometer // Add Speedometer