toggle AR/hud with TAB key
This commit is contained in:
parent
d58e9ebb1e
commit
68d19c3a6a
77
src/hud.rs
77
src/hud.rs
|
@ -1,3 +1,4 @@
|
|||
use crate::settings;
|
||||
use bevy::prelude::*;
|
||||
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
|
||||
|
||||
|
@ -5,7 +6,7 @@ pub struct OutFlyHudPlugin;
|
|||
impl Plugin for OutFlyHudPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(Startup, setup);
|
||||
app.add_systems(Update, update);
|
||||
app.add_systems(Update, (update, handle_input));
|
||||
app.insert_resource(FPSUpdateTimer(Timer::from_seconds(0.25, TimerMode::Repeating)));
|
||||
}
|
||||
}
|
||||
|
@ -18,33 +19,41 @@ struct FPSUpdateTimer(Timer);
|
|||
|
||||
fn setup(
|
||||
mut commands: Commands,
|
||||
settings: Res<settings::Settings>,
|
||||
) {
|
||||
let visibility = if settings.ar_active {
|
||||
Visibility::Inherited
|
||||
} else {
|
||||
Visibility::Hidden
|
||||
};
|
||||
let mut bundle_fps = TextBundle::from_sections([
|
||||
TextSection::new(
|
||||
"FPS: ",
|
||||
TextStyle {
|
||||
//font: asset_server.load("fonts/FiraSans-Bold.ttf"),
|
||||
font_size: 30.0,
|
||||
..default()
|
||||
},
|
||||
),
|
||||
TextSection::from_style(if cfg!(feature = "default_font") {
|
||||
TextStyle {
|
||||
font_size: 30.0,
|
||||
color: Color::GOLD,
|
||||
..default()
|
||||
}
|
||||
} else {
|
||||
// "default_font" feature is unavailable, load a font to use instead.
|
||||
TextStyle {
|
||||
//font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
||||
font_size: 30.0,
|
||||
color: Color::GOLD,
|
||||
..default()
|
||||
}
|
||||
}),
|
||||
]);
|
||||
bundle_fps.visibility = visibility;
|
||||
commands.spawn((
|
||||
TextBundle::from_sections([
|
||||
TextSection::new(
|
||||
"FPS: ",
|
||||
TextStyle {
|
||||
//font: asset_server.load("fonts/FiraSans-Bold.ttf"),
|
||||
font_size: 30.0,
|
||||
..default()
|
||||
},
|
||||
),
|
||||
TextSection::from_style(if cfg!(feature = "default_font") {
|
||||
TextStyle {
|
||||
font_size: 30.0,
|
||||
color: Color::GOLD,
|
||||
..default()
|
||||
}
|
||||
} else {
|
||||
// "default_font" feature is unavailable, load a font to use instead.
|
||||
TextStyle {
|
||||
//font: asset_server.load("fonts/FiraMono-Medium.ttf"),
|
||||
font_size: 30.0,
|
||||
color: Color::GOLD,
|
||||
..default()
|
||||
}
|
||||
}),
|
||||
]),
|
||||
bundle_fps,
|
||||
FpsText,
|
||||
));
|
||||
}
|
||||
|
@ -66,3 +75,19 @@ fn update(
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handle_input(
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
settings: Res<settings::Settings>,
|
||||
mut query: Query<&mut Visibility, With<FpsText>>,
|
||||
) {
|
||||
if keyboard_input.just_pressed(settings.key_togglehud) {
|
||||
for mut vis in &mut query {
|
||||
if *vis == Visibility::Inherited {
|
||||
*vis = Visibility::Hidden;
|
||||
} else {
|
||||
*vis = Visibility::Inherited;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ pub struct Settings {
|
|||
pub mute_music: bool,
|
||||
pub volume_sfx: u8,
|
||||
pub volume_music: u8,
|
||||
pub key_togglehud: KeyCode,
|
||||
pub ar_active: bool,
|
||||
}
|
||||
|
||||
impl Default for Settings {
|
||||
|
@ -15,6 +17,8 @@ impl Default for Settings {
|
|||
mute_music: false,
|
||||
volume_sfx: 100,
|
||||
volume_music: 100,
|
||||
key_togglehud: KeyCode::Tab,
|
||||
ar_active: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue