From 2eb00d025d51922fd5ee446d1a09deb66932e453 Mon Sep 17 00:00:00 2001 From: hut Date: Thu, 28 Mar 2024 20:47:18 +0100 Subject: [PATCH] add toggleable reticule to HUD --- src/hud.rs | 63 +++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 43 insertions(+), 20 deletions(-) diff --git a/src/hud.rs b/src/hud.rs index e1cebde..c809b82 100644 --- a/src/hud.rs +++ b/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>, mut settings: ResMut, - mut q_gauges: Query<&mut Visibility, With>, - mut q_bloomsettings: Query<&mut BloomSettings>, + mut q_hud: Query<&mut Visibility, With>, + //mut q_bloomsettings: Query<&mut BloomSettings>, q_choices: Query<&ChoiceAvailable>, mut evwriter_sendmsg: EventWriter, mut evwriter_sfx: EventWriter, @@ -432,24 +453,26 @@ fn handle_input( mut ambient_light: ResMut, ) { 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;