add toggleable reticule to HUD
This commit is contained in:
parent
99fd2ec750
commit
2eb00d025d
63
src/hud.rs
63
src/hud.rs
|
@ -1,7 +1,7 @@
|
|||
use crate::{settings, actor, audio, nature};
|
||||
use bevy::prelude::*;
|
||||
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
|
||||
use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings};
|
||||
//use bevy::core_pipeline::bloom::{BloomCompositeMode, BloomSettings};
|
||||
use std::collections::VecDeque;
|
||||
use std::time::SystemTime;
|
||||
|
||||
|
@ -33,6 +33,8 @@ impl Plugin for HudPlugin {
|
|||
|
||||
#[derive(Component)] struct GaugesText;
|
||||
#[derive(Component)] struct ChatText;
|
||||
#[derive(Component)] struct Reticule;
|
||||
#[derive(Component)] struct ToggleableHudElement;
|
||||
|
||||
#[derive(Resource)]
|
||||
struct FPSUpdateTimer(Timer);
|
||||
|
@ -262,8 +264,9 @@ fn setup(
|
|||
});
|
||||
bundle_fps.visibility = visibility;
|
||||
commands.spawn((
|
||||
bundle_fps,
|
||||
GaugesText,
|
||||
ToggleableHudElement,
|
||||
bundle_fps,
|
||||
));
|
||||
|
||||
// Add Chat Box
|
||||
|
@ -323,6 +326,24 @@ fn setup(
|
|||
));
|
||||
});
|
||||
|
||||
commands.spawn((
|
||||
Reticule,
|
||||
ToggleableHudElement,
|
||||
NodeBundle {
|
||||
style: Style {
|
||||
width: Val::Px(2.0),
|
||||
height: Val::Px(2.0),
|
||||
position_type: PositionType::Absolute,
|
||||
top: Val::Vh(50.0),
|
||||
left: Val::Vw(50.0),
|
||||
..default()
|
||||
},
|
||||
visibility: visibility,
|
||||
background_color: Color::rgb(0.4, 0.4, 0.6).into(),
|
||||
..default()
|
||||
},
|
||||
));
|
||||
|
||||
// AR-related things
|
||||
ambient_light.brightness = if settings.hud_active {
|
||||
AMBIENT_LIGHT_AR
|
||||
|
@ -423,8 +444,8 @@ fn update(
|
|||
fn handle_input(
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
mut settings: ResMut<settings::Settings>,
|
||||
mut q_gauges: Query<&mut Visibility, With<GaugesText>>,
|
||||
mut q_bloomsettings: Query<&mut BloomSettings>,
|
||||
mut q_hud: Query<&mut Visibility, With<ToggleableHudElement>>,
|
||||
//mut q_bloomsettings: Query<&mut BloomSettings>,
|
||||
q_choices: Query<&ChoiceAvailable>,
|
||||
mut evwriter_sendmsg: EventWriter<actor::SendMessageEvent>,
|
||||
mut evwriter_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||
|
@ -432,24 +453,26 @@ fn handle_input(
|
|||
mut ambient_light: ResMut<AmbientLight>,
|
||||
) {
|
||||
if keyboard_input.just_pressed(settings.key_togglehud) {
|
||||
if let Ok(mut vis) = q_gauges.get_single_mut() {
|
||||
if let Ok(mut bloomsettings) = q_bloomsettings.get_single_mut() {
|
||||
if *vis == Visibility::Inherited {
|
||||
*vis = Visibility::Hidden;
|
||||
settings.hud_active = false;
|
||||
ambient_light.brightness = AMBIENT_LIGHT;
|
||||
bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
||||
} else {
|
||||
*vis = Visibility::Inherited;
|
||||
settings.hud_active = true;
|
||||
ambient_light.brightness = AMBIENT_LIGHT_AR;
|
||||
bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
||||
//bloomsettings.composite_mode = BloomCompositeMode::Additive;
|
||||
}
|
||||
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
||||
evwriter_togglemusic.send(audio::ToggleMusicEvent());
|
||||
//if let Ok(mut bloomsettings) = q_bloomsettings.get_single_mut() {
|
||||
if settings.hud_active {
|
||||
for mut hudelement_visibility in q_hud.iter_mut() {
|
||||
*hudelement_visibility = Visibility::Hidden;
|
||||
}
|
||||
settings.hud_active = false;
|
||||
ambient_light.brightness = AMBIENT_LIGHT;
|
||||
//bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
||||
}
|
||||
else {
|
||||
for mut hudelement_visibility in q_hud.iter_mut() {
|
||||
*hudelement_visibility = Visibility::Inherited;
|
||||
}
|
||||
settings.hud_active = true;
|
||||
ambient_light.brightness = AMBIENT_LIGHT_AR;
|
||||
//bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
||||
//bloomsettings.composite_mode = BloomCompositeMode::Additive;
|
||||
}
|
||||
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
||||
evwriter_togglemusic.send(audio::ToggleMusicEvent());
|
||||
}
|
||||
|
||||
let mut selected_choice = 1;
|
||||
|
|
Loading…
Reference in a new issue