show point of interest marker only if HUD + map are active

This commit is contained in:
yuni 2024-04-21 21:38:21 +02:00
parent 00e4fb4957
commit 556f097193
3 changed files with 39 additions and 19 deletions

View file

@ -264,6 +264,7 @@ pub fn handle_input(
mut settings: ResMut<var::Settings>,
mut mapcam: ResMut<MapCam>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>,
) {
if keyboard_input.just_pressed(settings.key_camera) {
settings.third_person ^= true;
@ -271,6 +272,7 @@ pub fn handle_input(
if keyboard_input.just_pressed(settings.key_map) {
settings.map_active ^= true;
*mapcam = MapCam::default();
ew_updateoverlays.send(hud::UpdateOverlayVisibility);
}
if keyboard_input.just_pressed(settings.key_rotation_stabilizer) {
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));

View file

@ -694,7 +694,7 @@ fn spawn_entities(
if state.is_point_of_interest {
commands.spawn((
hud::IsPointOfInterestMarker(actor_entity),
hud::PointOfInterestMarker(actor_entity),
world::DespawnOnPlayerDeath,
hud::ToggleableHudElement,
SceneBundle {

View file

@ -39,6 +39,7 @@ impl Plugin for HudPlugin {
handle_target_event,
));
app.add_systems(PostUpdate, (
update_overlay_visibility,
update_ar_overlays
.after(world::position_to_transform)
.in_set(sync::SyncSet::PositionToTransform),
@ -60,20 +61,23 @@ impl Plugin for HudPlugin {
app.insert_resource(FPSUpdateTimer(
Timer::from_seconds(HUD_REFRESH_TIME, TimerMode::Repeating)));
app.add_event::<TargetEvent>();
app.add_event::<UpdateOverlayVisibility>();
}
}
#[derive(Event)] pub struct TargetEvent(pub Option<Entity>);
#[derive(Event)] pub struct UpdateOverlayVisibility;
#[derive(Component)] struct NodeHud;
#[derive(Component)] struct NodeConsole;
#[derive(Component)] struct NodeChoiceText;
#[derive(Component)] struct NodeCurrentChatLine;
#[derive(Component)] struct Reticule;
#[derive(Component)] pub struct ToggleableHudElement;
#[derive(Component)] pub struct ToggleableHudMapElement;
#[derive(Component)] struct OnlyHideWhenTogglingHud;
#[derive(Component)] struct Selectagon;
#[derive(Component)] pub struct IsTargeted;
#[derive(Component)] pub struct IsPointOfInterestMarker(pub Entity);
#[derive(Component)] pub struct PointOfInterestMarker(pub Entity);
#[derive(Resource)]
pub struct AugmentedRealityState {
@ -644,6 +648,7 @@ fn handle_input(
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
mut ew_target: EventWriter<TargetEvent>,
mut ew_updateoverlays: EventWriter<UpdateOverlayVisibility>,
mut ambient_light: ResMut<AmbientLight>,
q_objects: Query<(Entity, &Transform), (With<IsClickable>, Without<IsTargeted>, Without<actor::PlayerDrivesThis>, Without<actor::Player>)>,
q_camera: Query<&Transform, With<Camera>>,
@ -654,21 +659,12 @@ fn handle_input(
}
}
if keyboard_input.just_pressed(settings.key_togglehud) {
ew_updateoverlays.send(UpdateOverlayVisibility);
settings.hud_active ^= true;
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;
}
else {
for (mut hudelement_visibility, only_hide) in q_hud.iter_mut() {
if only_hide.is_none() {
*hudelement_visibility = Visibility::Inherited;
}
}
settings.hud_active = true;
ambient_light.brightness = AMBIENT_LIGHT_AR;
} else {
ambient_light.brightness = AMBIENT_LIGHT;
}
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
ew_togglemusic.send(audio::ToggleMusicEvent());
@ -786,12 +782,12 @@ fn update_ar_overlays (
}
fn update_poi_overlays (
mut q_marker: Query<(&mut Transform, &IsPointOfInterestMarker)>,
q_parent: Query<&Transform, Without<IsPointOfInterestMarker>>,
q_camera: Query<&Transform, (With<Camera>, Without<IsPointOfInterestMarker>)>,
mut q_marker: Query<(&mut Transform, &PointOfInterestMarker)>,
q_parent: Query<&Transform, Without<PointOfInterestMarker>>,
q_camera: Query<&Transform, (With<Camera>, Without<PointOfInterestMarker>)>,
settings: ResMut<var::Settings>,
) {
if !settings.hud_active || q_camera.is_empty() {
if !settings.hud_active || !settings.map_active || q_camera.is_empty() {
return;
}
let camera_trans = q_camera.get_single().unwrap();
@ -810,3 +806,25 @@ fn update_poi_overlays (
}
}
}
fn update_overlay_visibility(
mut q_marker: Query<&mut Visibility, With<PointOfInterestMarker>>,
mut q_hudelement: Query<&mut Visibility, (With<ToggleableHudElement>, Without<PointOfInterestMarker>)>,
er_target: EventReader<UpdateOverlayVisibility>,
settings: Res<var::Settings>,
) {
if er_target.is_empty() {
return;
}
let check = {|check: bool|
if check { Visibility::Inherited } else { Visibility::Hidden }
};
let show_poi = check(settings.hud_active && settings.map_active);
let show_hud = check(settings.hud_active);
for mut vis in &mut q_marker {
*vis = show_poi;
}
for mut vis in &mut q_hudelement {
*vis = show_hud;
}
}