targeting now only works in AR
This commit is contained in:
parent
9c5a61767a
commit
dc077ca141
19
src/hud.rs
19
src/hud.rs
|
@ -48,6 +48,7 @@ impl Plugin for HudPlugin {
|
||||||
#[derive(Component)] struct ChatText;
|
#[derive(Component)] struct ChatText;
|
||||||
#[derive(Component)] struct Reticule;
|
#[derive(Component)] struct Reticule;
|
||||||
#[derive(Component)] struct ToggleableHudElement;
|
#[derive(Component)] struct ToggleableHudElement;
|
||||||
|
#[derive(Component)] struct OnlyHideWhenTogglingHud;
|
||||||
#[derive(Component)] struct Selectagon;
|
#[derive(Component)] struct Selectagon;
|
||||||
#[derive(Component)] pub struct IsClickable;
|
#[derive(Component)] pub struct IsClickable;
|
||||||
#[derive(Component)] pub struct IsTargeted;
|
#[derive(Component)] pub struct IsTargeted;
|
||||||
|
@ -442,8 +443,11 @@ fn setup(
|
||||||
// Selectagon
|
// Selectagon
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Selectagon,
|
Selectagon,
|
||||||
|
ToggleableHudElement,
|
||||||
|
OnlyHideWhenTogglingHud,
|
||||||
SceneBundle {
|
SceneBundle {
|
||||||
scene: asset_server.load(world::asset_name_to_path("selectagon")),
|
scene: asset_server.load(world::asset_name_to_path("selectagon")),
|
||||||
|
visibility: Visibility::Hidden,
|
||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
));
|
));
|
||||||
|
@ -593,7 +597,7 @@ fn handle_input(
|
||||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||||
mouse_input: Res<ButtonInput<MouseButton>>,
|
mouse_input: Res<ButtonInput<MouseButton>>,
|
||||||
mut settings: ResMut<settings::Settings>,
|
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_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>,
|
||||||
|
@ -603,15 +607,17 @@ fn handle_input(
|
||||||
) {
|
) {
|
||||||
if keyboard_input.just_pressed(settings.key_togglehud) {
|
if keyboard_input.just_pressed(settings.key_togglehud) {
|
||||||
if settings.hud_active {
|
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;
|
*hudelement_visibility = Visibility::Hidden;
|
||||||
}
|
}
|
||||||
settings.hud_active = false;
|
settings.hud_active = false;
|
||||||
ambient_light.brightness = AMBIENT_LIGHT;
|
ambient_light.brightness = AMBIENT_LIGHT;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
for mut hudelement_visibility in q_hud.iter_mut() {
|
for (mut hudelement_visibility, only_hide) in q_hud.iter_mut() {
|
||||||
*hudelement_visibility = Visibility::Inherited;
|
if only_hide.is_none() {
|
||||||
|
*hudelement_visibility = Visibility::Inherited;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
settings.hud_active = true;
|
settings.hud_active = true;
|
||||||
ambient_light.brightness = AMBIENT_LIGHT_AR;
|
ambient_light.brightness = AMBIENT_LIGHT_AR;
|
||||||
|
@ -619,7 +625,7 @@ fn handle_input(
|
||||||
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());
|
||||||
}
|
}
|
||||||
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() {
|
if let Ok(camtrans) = q_camera.get_single() {
|
||||||
let objects: Vec<(Entity, &Transform)> = q_objects.iter().collect();
|
let objects: Vec<(Entity, &Transform)> = q_objects.iter().collect();
|
||||||
if let (Some(new_target), _dist) = camera::find_closest_target::<Entity>(objects, camtrans) {
|
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(
|
fn update_target_selectagon(
|
||||||
|
settings: Res<settings::Settings>,
|
||||||
mut q_selectagon: Query<(&mut Transform, &mut Visibility), (With<Selectagon>, Without<IsTargeted>, Without<Camera>)>,
|
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_target: Query<&Transform, (With<IsTargeted>, Without<Camera>, Without<Selectagon>)>,
|
||||||
q_camera: Query<&Transform, (With<Camera>, Without<IsTargeted>, 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;
|
return;
|
||||||
}
|
}
|
||||||
let camera_trans = q_camera.get_single().unwrap();
|
let camera_trans = q_camera.get_single().unwrap();
|
||||||
|
|
Loading…
Reference in a new issue