2022-01-12 08:18:13 +00:00
|
|
|
use bevy::prelude::*;
|
2022-02-08 21:27:57 +00:00
|
|
|
use bevy_rapier3d::prelude::*;
|
2022-01-12 08:18:13 +00:00
|
|
|
|
2022-03-13 00:06:36 +00:00
|
|
|
use crate::bike::CyberBikeBody;
|
2022-01-12 08:18:13 +00:00
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
struct UpText;
|
|
|
|
|
|
|
|
fn setup_ui(mut commands: Commands, asset_server: Res<AssetServer>) {
|
2022-08-13 22:30:37 +00:00
|
|
|
//commands.spawn_bundle(UiCameraBundle::default());
|
2022-01-12 08:18:13 +00:00
|
|
|
|
|
|
|
commands
|
|
|
|
.spawn_bundle(TextBundle {
|
|
|
|
style: Style {
|
|
|
|
align_self: AlignSelf::FlexEnd,
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
// Use `Text` directly
|
|
|
|
text: Text {
|
|
|
|
// Construct a `Vec` of `TextSection`s
|
|
|
|
sections: vec![TextSection {
|
|
|
|
value: "".to_string(),
|
|
|
|
style: TextStyle {
|
|
|
|
font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
|
|
|
font_size: 40.0,
|
|
|
|
color: Color::GOLD,
|
|
|
|
},
|
|
|
|
}],
|
|
|
|
..Default::default()
|
|
|
|
},
|
|
|
|
..Default::default()
|
|
|
|
})
|
|
|
|
.insert(UpText);
|
|
|
|
}
|
|
|
|
|
2022-02-08 21:27:57 +00:00
|
|
|
fn update_ui(
|
2022-05-08 17:58:48 +00:00
|
|
|
state_query: Query<&Velocity, With<CyberBikeBody>>,
|
2022-02-08 21:27:57 +00:00
|
|
|
mut text_query: Query<&mut Text, With<UpText>>,
|
|
|
|
) {
|
2022-01-12 08:18:13 +00:00
|
|
|
let mut text = text_query.single_mut();
|
2022-01-14 00:14:08 +00:00
|
|
|
let state = state_query.single();
|
2022-05-08 17:58:48 +00:00
|
|
|
text.sections[0].value = format!("spd: {:.2}", state.linvel.length());
|
2022-01-12 08:18:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub struct CyberUIPlugin;
|
|
|
|
|
|
|
|
impl Plugin for CyberUIPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_startup_system(setup_ui).add_system(update_ui);
|
|
|
|
}
|
|
|
|
}
|