add selectagon around target
This commit is contained in:
parent
f682f1d6c0
commit
36eb5a000e
BIN
assets/models/selectagon.glb
Normal file
BIN
assets/models/selectagon.glb
Normal file
Binary file not shown.
|
@ -141,7 +141,7 @@ fn manage_player_actor(
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn apply_input_to_player(
|
||||
pub fn apply_input_to_player(
|
||||
time: Res<Time>,
|
||||
settings: Res<settings::Settings>,
|
||||
mut windows: Query<&mut Window, With<PrimaryWindow>>,
|
||||
|
|
46
src/hud.rs
46
src/hud.rs
|
@ -1,6 +1,7 @@
|
|||
use crate::{actor, audio, camera, chat, nature, settings};
|
||||
use crate::{actor, audio, camera, chat, nature, settings, world};
|
||||
use bevy::prelude::*;
|
||||
use bevy::diagnostic::{DiagnosticsStore, FrameTimeDiagnosticsPlugin};
|
||||
use bevy::transform::TransformSystem;
|
||||
use bevy_xpbd_3d::prelude::*;
|
||||
use bevy::math::DVec3;
|
||||
use std::collections::VecDeque;
|
||||
|
@ -25,7 +26,12 @@ impl Plugin for HudPlugin {
|
|||
update,
|
||||
handle_input,
|
||||
handle_target_event,
|
||||
update_target_selectagon,
|
||||
));
|
||||
app.add_systems(PostUpdate, (
|
||||
update_target_selectagon
|
||||
.after(PhysicsSet::Sync)
|
||||
.after(camera::apply_input_to_player)
|
||||
.before(TransformSystem::TransformPropagate),
|
||||
));
|
||||
app.insert_resource(Log {
|
||||
logs: VecDeque::with_capacity(LOG_MAX),
|
||||
|
@ -42,6 +48,7 @@ impl Plugin for HudPlugin {
|
|||
#[derive(Component)] struct ChatText;
|
||||
#[derive(Component)] struct Reticule;
|
||||
#[derive(Component)] struct ToggleableHudElement;
|
||||
#[derive(Component)] struct Selectagon;
|
||||
#[derive(Component)] pub struct IsClickable;
|
||||
#[derive(Component)] pub struct IsTargeted;
|
||||
|
||||
|
@ -432,6 +439,15 @@ fn setup(
|
|||
},
|
||||
));
|
||||
|
||||
// Selectagon
|
||||
commands.spawn((
|
||||
Selectagon,
|
||||
SceneBundle {
|
||||
scene: asset_server.load(world::asset_name_to_path("selectagon")),
|
||||
..default()
|
||||
},
|
||||
));
|
||||
|
||||
// AR-related things
|
||||
ambient_light.brightness = if settings.hud_active {
|
||||
AMBIENT_LIGHT_AR
|
||||
|
@ -574,7 +590,6 @@ fn update(
|
|||
}
|
||||
|
||||
fn handle_input(
|
||||
mut commands: Commands,
|
||||
keyboard_input: Res<ButtonInput<KeyCode>>,
|
||||
mouse_input: Res<ButtonInput<MouseButton>>,
|
||||
mut settings: ResMut<settings::Settings>,
|
||||
|
@ -643,5 +658,30 @@ fn handle_target_event(
|
|||
}
|
||||
|
||||
fn update_target_selectagon(
|
||||
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() {
|
||||
return;
|
||||
}
|
||||
let camera_trans = q_camera.get_single().unwrap();
|
||||
|
||||
if let Ok((mut selectagon_trans, mut selectagon_vis)) = q_selectagon.get_single_mut() {
|
||||
if let Ok(target_trans) = q_target.get_single() {
|
||||
match *selectagon_vis {
|
||||
Visibility::Hidden => { *selectagon_vis = Visibility::Visible; },
|
||||
_ => {}
|
||||
}
|
||||
selectagon_trans.translation = target_trans.translation;
|
||||
selectagon_trans.scale = target_trans.scale;
|
||||
selectagon_trans.rotation = camera_trans.rotation;
|
||||
}
|
||||
else {
|
||||
match *selectagon_vis {
|
||||
Visibility::Hidden => {},
|
||||
_ => { *selectagon_vis = Visibility::Hidden; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,6 +33,7 @@ pub fn asset_name_to_path(name: &str) -> &'static str {
|
|||
"satellite" => "models/satellite.glb#Scene0",
|
||||
"pizzeria" => "models/pizzeria2.glb#Scene0",
|
||||
"pizzasign" => "models/pizzasign.glb#Scene0",
|
||||
"selectagon" => "models/selectagon.glb#Scene0",
|
||||
_ => "models/error.glb#Scene0",
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue