toggle AR/hud with TAB key
This commit is contained in:
parent
d58e9ebb1e
commit
68d19c3a6a
2 changed files with 55 additions and 26 deletions
33
src/hud.rs
33
src/hud.rs
|
@ -1,3 +1,4 @@
|
||||||
|
use crate::settings;
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
|
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
|
||||||
|
|
||||||
|
@ -5,7 +6,7 @@ pub struct OutFlyHudPlugin;
|
||||||
impl Plugin for OutFlyHudPlugin {
|
impl Plugin for OutFlyHudPlugin {
|
||||||
fn build(&self, app: &mut App) {
|
fn build(&self, app: &mut App) {
|
||||||
app.add_systems(Startup, setup);
|
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)));
|
app.insert_resource(FPSUpdateTimer(Timer::from_seconds(0.25, TimerMode::Repeating)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -18,9 +19,14 @@ struct FPSUpdateTimer(Timer);
|
||||||
|
|
||||||
fn setup(
|
fn setup(
|
||||||
mut commands: Commands,
|
mut commands: Commands,
|
||||||
|
settings: Res<settings::Settings>,
|
||||||
) {
|
) {
|
||||||
commands.spawn((
|
let visibility = if settings.ar_active {
|
||||||
TextBundle::from_sections([
|
Visibility::Inherited
|
||||||
|
} else {
|
||||||
|
Visibility::Hidden
|
||||||
|
};
|
||||||
|
let mut bundle_fps = TextBundle::from_sections([
|
||||||
TextSection::new(
|
TextSection::new(
|
||||||
"FPS: ",
|
"FPS: ",
|
||||||
TextStyle {
|
TextStyle {
|
||||||
|
@ -44,7 +50,10 @@ fn setup(
|
||||||
..default()
|
..default()
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
]),
|
]);
|
||||||
|
bundle_fps.visibility = visibility;
|
||||||
|
commands.spawn((
|
||||||
|
bundle_fps,
|
||||||
FpsText,
|
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 mute_music: bool,
|
||||||
pub volume_sfx: u8,
|
pub volume_sfx: u8,
|
||||||
pub volume_music: u8,
|
pub volume_music: u8,
|
||||||
|
pub key_togglehud: KeyCode,
|
||||||
|
pub ar_active: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for Settings {
|
impl Default for Settings {
|
||||||
|
@ -15,6 +17,8 @@ impl Default for Settings {
|
||||||
mute_music: false,
|
mute_music: false,
|
||||||
volume_sfx: 100,
|
volume_sfx: 100,
|
||||||
volume_music: 100,
|
volume_music: 100,
|
||||||
|
key_togglehud: KeyCode::Tab,
|
||||||
|
ar_active: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue