targeting now only works in AR

This commit is contained in:
yuni 2024-04-05 22:43:14 +02:00
parent 9c5a61767a
commit dc077ca141

View file

@ -48,6 +48,7 @@ impl Plugin for HudPlugin {
#[derive(Component)] struct ChatText;
#[derive(Component)] struct Reticule;
#[derive(Component)] struct ToggleableHudElement;
#[derive(Component)] struct OnlyHideWhenTogglingHud;
#[derive(Component)] struct Selectagon;
#[derive(Component)] pub struct IsClickable;
#[derive(Component)] pub struct IsTargeted;
@ -442,8 +443,11 @@ fn setup(
// Selectagon
commands.spawn((
Selectagon,
ToggleableHudElement,
OnlyHideWhenTogglingHud,
SceneBundle {
scene: asset_server.load(world::asset_name_to_path("selectagon")),
visibility: Visibility::Hidden,
..default()
},
));
@ -593,7 +597,7 @@ fn handle_input(
keyboard_input: Res<ButtonInput<KeyCode>>,
mouse_input: Res<ButtonInput<MouseButton>>,
mut settings: ResMut<settings::Settings>,
mut q_hud: Query<&mut Visibility, With<ToggleableHudElement>>,
mut q_hud: Query<(&mut Visibility, Option<&OnlyHideWhenTogglingHud>), With<ToggleableHudElement>>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
mut ew_togglemusic: EventWriter<audio::ToggleMusicEvent>,
mut ew_target: EventWriter<TargetEvent>,
@ -603,15 +607,17 @@ fn handle_input(
) {
if keyboard_input.just_pressed(settings.key_togglehud) {
if settings.hud_active {
for mut hudelement_visibility in q_hud.iter_mut() {
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 in q_hud.iter_mut() {
*hudelement_visibility = Visibility::Inherited;
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;
@ -619,7 +625,7 @@ fn handle_input(
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Switch));
ew_togglemusic.send(audio::ToggleMusicEvent());
}
if mouse_input.just_pressed(settings.key_selectobject) {
if settings.hud_active && mouse_input.just_pressed(settings.key_selectobject) {
if let Ok(camtrans) = q_camera.get_single() {
let objects: Vec<(Entity, &Transform)> = q_objects.iter().collect();
if let (Some(new_target), _dist) = camera::find_closest_target::<Entity>(objects, camtrans) {
@ -658,11 +664,12 @@ fn handle_target_event(
}
fn update_target_selectagon(
settings: Res<settings::Settings>,
mut q_selectagon: Query<(&mut Transform, &mut Visibility), (With<Selectagon>, Without<IsTargeted>, Without<Camera>)>,
q_target: Query<&Transform, (With<IsTargeted>, Without<Camera>, Without<Selectagon>)>,
q_camera: Query<&Transform, (With<Camera>, Without<IsTargeted>, Without<Selectagon>)>,
) {
if q_camera.is_empty() {
if !settings.hud_active || q_camera.is_empty() {
return;
}
let camera_trans = q_camera.get_single().unwrap();