add toggleable reticule to HUD
This commit is contained in:
parent
99fd2ec750
commit
2eb00d025d
51
src/hud.rs
51
src/hud.rs
|
@ -1,7 +1,7 @@
|
||||||
use crate::{settings, actor, audio, nature};
|
use crate::{settings, actor, audio, nature};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
|
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::collections::VecDeque;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
|
@ -33,6 +33,8 @@ impl Plugin for HudPlugin {
|
||||||
|
|
||||||
#[derive(Component)] struct GaugesText;
|
#[derive(Component)] struct GaugesText;
|
||||||
#[derive(Component)] struct ChatText;
|
#[derive(Component)] struct ChatText;
|
||||||
|
#[derive(Component)] struct Reticule;
|
||||||
|
#[derive(Component)] struct ToggleableHudElement;
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
struct FPSUpdateTimer(Timer);
|
struct FPSUpdateTimer(Timer);
|
||||||
|
@ -262,8 +264,9 @@ fn setup(
|
||||||
});
|
});
|
||||||
bundle_fps.visibility = visibility;
|
bundle_fps.visibility = visibility;
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
bundle_fps,
|
|
||||||
GaugesText,
|
GaugesText,
|
||||||
|
ToggleableHudElement,
|
||||||
|
bundle_fps,
|
||||||
));
|
));
|
||||||
|
|
||||||
// Add Chat Box
|
// 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
|
// AR-related things
|
||||||
ambient_light.brightness = if settings.hud_active {
|
ambient_light.brightness = if settings.hud_active {
|
||||||
AMBIENT_LIGHT_AR
|
AMBIENT_LIGHT_AR
|
||||||
|
@ -423,8 +444,8 @@ fn update(
|
||||||
fn handle_input(
|
fn handle_input(
|
||||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mut settings: ResMut<settings::Settings>,
|
mut settings: ResMut<settings::Settings>,
|
||||||
mut q_gauges: Query<&mut Visibility, With<GaugesText>>,
|
mut q_hud: Query<&mut Visibility, With<ToggleableHudElement>>,
|
||||||
mut q_bloomsettings: Query<&mut BloomSettings>,
|
//mut q_bloomsettings: Query<&mut BloomSettings>,
|
||||||
q_choices: Query<&ChoiceAvailable>,
|
q_choices: Query<&ChoiceAvailable>,
|
||||||
mut evwriter_sendmsg: EventWriter<actor::SendMessageEvent>,
|
mut evwriter_sendmsg: EventWriter<actor::SendMessageEvent>,
|
||||||
mut evwriter_sfx: EventWriter<audio::PlaySfxEvent>,
|
mut evwriter_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||||
|
@ -432,25 +453,27 @@ fn handle_input(
|
||||||
mut ambient_light: ResMut<AmbientLight>,
|
mut ambient_light: ResMut<AmbientLight>,
|
||||||
) {
|
) {
|
||||||
if keyboard_input.just_pressed(settings.key_togglehud) {
|
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 let Ok(mut bloomsettings) = q_bloomsettings.get_single_mut() {
|
if settings.hud_active {
|
||||||
if *vis == Visibility::Inherited {
|
for mut hudelement_visibility in q_hud.iter_mut() {
|
||||||
*vis = Visibility::Hidden;
|
*hudelement_visibility = Visibility::Hidden;
|
||||||
|
}
|
||||||
settings.hud_active = false;
|
settings.hud_active = false;
|
||||||
ambient_light.brightness = AMBIENT_LIGHT;
|
ambient_light.brightness = AMBIENT_LIGHT;
|
||||||
bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
//bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
||||||
} else {
|
}
|
||||||
*vis = Visibility::Inherited;
|
else {
|
||||||
|
for mut hudelement_visibility in q_hud.iter_mut() {
|
||||||
|
*hudelement_visibility = Visibility::Inherited;
|
||||||
|
}
|
||||||
settings.hud_active = true;
|
settings.hud_active = true;
|
||||||
ambient_light.brightness = AMBIENT_LIGHT_AR;
|
ambient_light.brightness = AMBIENT_LIGHT_AR;
|
||||||
bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
//bloomsettings.composite_mode = BloomCompositeMode::EnergyConserving;
|
||||||
//bloomsettings.composite_mode = BloomCompositeMode::Additive;
|
//bloomsettings.composite_mode = BloomCompositeMode::Additive;
|
||||||
}
|
}
|
||||||
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
evwriter_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
||||||
evwriter_togglemusic.send(audio::ToggleMusicEvent());
|
evwriter_togglemusic.send(audio::ToggleMusicEvent());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
let mut selected_choice = 1;
|
let mut selected_choice = 1;
|
||||||
'outer: for key in settings.get_reply_keys() {
|
'outer: for key in settings.get_reply_keys() {
|
||||||
|
|
Loading…
Reference in a new issue