toggle AR/hud with TAB key

This commit is contained in:
yuni 2024-03-17 19:03:02 +01:00
parent d58e9ebb1e
commit 68d19c3a6a
2 changed files with 55 additions and 26 deletions

View file

@ -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,9 +19,14 @@ struct FPSUpdateTimer(Timer);
fn setup(
mut commands: Commands,
settings: Res<settings::Settings>,
) {
commands.spawn((
TextBundle::from_sections([
let visibility = if settings.ar_active {
Visibility::Inherited
} else {
Visibility::Hidden
};
let mut bundle_fps = TextBundle::from_sections([
TextSection::new(
"FPS: ",
TextStyle {
@ -44,7 +50,10 @@ fn setup(
..default()
}
}),
]),
]);
bundle_fps.visibility = visibility;
commands.spawn((
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;
}
}
}
}

View file

@ -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,
}
}
}