diff --git a/src/hud.rs b/src/hud.rs index 2d1f037..7c811d2 100644 --- a/src/hud.rs +++ b/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, ) { + 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>, + settings: Res, + mut query: Query<&mut Visibility, With>, +) { + 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; + } + } + } +} diff --git a/src/settings.rs b/src/settings.rs index 0308c77..9a7f5f1 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -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, } } }