show point of interest marker only if HUD + map are active
This commit is contained in:
parent
00e4fb4957
commit
556f097193
|
@ -264,6 +264,7 @@ pub fn handle_input(
|
||||||
mut settings: ResMut<var::Settings>,
|
mut settings: ResMut<var::Settings>,
|
||||||
mut mapcam: ResMut<MapCam>,
|
mut mapcam: ResMut<MapCam>,
|
||||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||||
|
mut ew_updateoverlays: EventWriter<hud::UpdateOverlayVisibility>,
|
||||||
) {
|
) {
|
||||||
if keyboard_input.just_pressed(settings.key_camera) {
|
if keyboard_input.just_pressed(settings.key_camera) {
|
||||||
settings.third_person ^= true;
|
settings.third_person ^= true;
|
||||||
|
@ -271,6 +272,7 @@ pub fn handle_input(
|
||||||
if keyboard_input.just_pressed(settings.key_map) {
|
if keyboard_input.just_pressed(settings.key_map) {
|
||||||
settings.map_active ^= true;
|
settings.map_active ^= true;
|
||||||
*mapcam = MapCam::default();
|
*mapcam = MapCam::default();
|
||||||
|
ew_updateoverlays.send(hud::UpdateOverlayVisibility);
|
||||||
}
|
}
|
||||||
if keyboard_input.just_pressed(settings.key_rotation_stabilizer) {
|
if keyboard_input.just_pressed(settings.key_rotation_stabilizer) {
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Click));
|
||||||
|
|
|
@ -694,7 +694,7 @@ fn spawn_entities(
|
||||||
|
|
||||||
if state.is_point_of_interest {
|
if state.is_point_of_interest {
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
hud::IsPointOfInterestMarker(actor_entity),
|
hud::PointOfInterestMarker(actor_entity),
|
||||||
world::DespawnOnPlayerDeath,
|
world::DespawnOnPlayerDeath,
|
||||||
hud::ToggleableHudElement,
|
hud::ToggleableHudElement,
|
||||||
SceneBundle {
|
SceneBundle {
|
||||||
|
|
54
src/hud.rs
54
src/hud.rs
|
@ -39,6 +39,7 @@ impl Plugin for HudPlugin {
|
||||||
handle_target_event,
|
handle_target_event,
|
||||||
));
|
));
|
||||||
app.add_systems(PostUpdate, (
|
app.add_systems(PostUpdate, (
|
||||||
|
update_overlay_visibility,
|
||||||
update_ar_overlays
|
update_ar_overlays
|
||||||
.after(world::position_to_transform)
|
.after(world::position_to_transform)
|
||||||
.in_set(sync::SyncSet::PositionToTransform),
|
.in_set(sync::SyncSet::PositionToTransform),
|
||||||
|
@ -60,20 +61,23 @@ impl Plugin for HudPlugin {
|
||||||
app.insert_resource(FPSUpdateTimer(
|
app.insert_resource(FPSUpdateTimer(
|
||||||
Timer::from_seconds(HUD_REFRESH_TIME, TimerMode::Repeating)));
|
Timer::from_seconds(HUD_REFRESH_TIME, TimerMode::Repeating)));
|
||||||
app.add_event::<TargetEvent>();
|
app.add_event::<TargetEvent>();
|
||||||
|
app.add_event::<UpdateOverlayVisibility>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Event)] pub struct TargetEvent(pub Option<Entity>);
|
#[derive(Event)] pub struct TargetEvent(pub Option<Entity>);
|
||||||
|
#[derive(Event)] pub struct UpdateOverlayVisibility;
|
||||||
#[derive(Component)] struct NodeHud;
|
#[derive(Component)] struct NodeHud;
|
||||||
#[derive(Component)] struct NodeConsole;
|
#[derive(Component)] struct NodeConsole;
|
||||||
#[derive(Component)] struct NodeChoiceText;
|
#[derive(Component)] struct NodeChoiceText;
|
||||||
#[derive(Component)] struct NodeCurrentChatLine;
|
#[derive(Component)] struct NodeCurrentChatLine;
|
||||||
#[derive(Component)] struct Reticule;
|
#[derive(Component)] struct Reticule;
|
||||||
#[derive(Component)] pub struct ToggleableHudElement;
|
#[derive(Component)] pub struct ToggleableHudElement;
|
||||||
|
#[derive(Component)] pub struct ToggleableHudMapElement;
|
||||||
#[derive(Component)] struct OnlyHideWhenTogglingHud;
|
#[derive(Component)] struct OnlyHideWhenTogglingHud;
|
||||||
#[derive(Component)] struct Selectagon;
|
#[derive(Component)] struct Selectagon;
|
||||||
#[derive(Component)] pub struct IsTargeted;
|
#[derive(Component)] pub struct IsTargeted;
|
||||||
#[derive(Component)] pub struct IsPointOfInterestMarker(pub Entity);
|
#[derive(Component)] pub struct PointOfInterestMarker(pub Entity);
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct AugmentedRealityState {
|
pub struct AugmentedRealityState {
|
||||||
|
@ -644,6 +648,7 @@ fn handle_input(
|
||||||
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
|
||||||
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
|
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
|
||||||
mut ew_target: EventWriter<TargetEvent>,
|
mut ew_target: EventWriter<TargetEvent>,
|
||||||
|
mut ew_updateoverlays: EventWriter<UpdateOverlayVisibility>,
|
||||||
mut ambient_light: ResMut<AmbientLight>,
|
mut ambient_light: ResMut<AmbientLight>,
|
||||||
q_objects: Query<(Entity, &Transform), (With<IsClickable>, Without<IsTargeted>, Without<actor::PlayerDrivesThis>, Without<actor::Player>)>,
|
q_objects: Query<(Entity, &Transform), (With<IsClickable>, Without<IsTargeted>, Without<actor::PlayerDrivesThis>, Without<actor::Player>)>,
|
||||||
q_camera: Query<&Transform, With<Camera>>,
|
q_camera: Query<&Transform, With<Camera>>,
|
||||||
|
@ -654,21 +659,12 @@ fn handle_input(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if keyboard_input.just_pressed(settings.key_togglehud) {
|
if keyboard_input.just_pressed(settings.key_togglehud) {
|
||||||
|
ew_updateoverlays.send(UpdateOverlayVisibility);
|
||||||
|
settings.hud_active ^= true;
|
||||||
if settings.hud_active {
|
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;
|
ambient_light.brightness = AMBIENT_LIGHT_AR;
|
||||||
|
} else {
|
||||||
|
ambient_light.brightness = AMBIENT_LIGHT;
|
||||||
}
|
}
|
||||||
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
|
||||||
ew_togglemusic.send(audio::ToggleMusicEvent());
|
ew_togglemusic.send(audio::ToggleMusicEvent());
|
||||||
|
@ -786,12 +782,12 @@ fn update_ar_overlays (
|
||||||
}
|
}
|
||||||
|
|
||||||
fn update_poi_overlays (
|
fn update_poi_overlays (
|
||||||
mut q_marker: Query<(&mut Transform, &IsPointOfInterestMarker)>,
|
mut q_marker: Query<(&mut Transform, &PointOfInterestMarker)>,
|
||||||
q_parent: Query<&Transform, Without<IsPointOfInterestMarker>>,
|
q_parent: Query<&Transform, Without<PointOfInterestMarker>>,
|
||||||
q_camera: Query<&Transform, (With<Camera>, Without<IsPointOfInterestMarker>)>,
|
q_camera: Query<&Transform, (With<Camera>, Without<PointOfInterestMarker>)>,
|
||||||
settings: ResMut<var::Settings>,
|
settings: ResMut<var::Settings>,
|
||||||
) {
|
) {
|
||||||
if !settings.hud_active || q_camera.is_empty() {
|
if !settings.hud_active || !settings.map_active || q_camera.is_empty() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let camera_trans = q_camera.get_single().unwrap();
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue