make stars clickable
This commit is contained in:
parent
36859f6bb6
commit
81187b4fe6
|
@ -660,7 +660,10 @@ fn spawn_entities(
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
if state.is_clickable {
|
if state.is_clickable {
|
||||||
actor.insert(hud::IsClickable);
|
actor.insert(hud::IsClickable {
|
||||||
|
name: state.name.clone(),
|
||||||
|
..default()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
if let Some(value) = state.wants_maxrotation {
|
if let Some(value) = state.wants_maxrotation {
|
||||||
actor.insert(actor::WantsMaxRotation(value));
|
actor.insert(actor::WantsMaxRotation(value));
|
||||||
|
|
37
src/hud.rs
37
src/hud.rs
|
@ -50,7 +50,6 @@ impl Plugin for HudPlugin {
|
||||||
#[derive(Component)] struct ToggleableHudElement;
|
#[derive(Component)] struct ToggleableHudElement;
|
||||||
#[derive(Component)] struct OnlyHideWhenTogglingHud;
|
#[derive(Component)] struct OnlyHideWhenTogglingHud;
|
||||||
#[derive(Component)] struct Selectagon;
|
#[derive(Component)] struct Selectagon;
|
||||||
#[derive(Component)] pub struct IsClickable;
|
|
||||||
#[derive(Component)] pub struct IsTargeted;
|
#[derive(Component)] pub struct IsTargeted;
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
|
@ -73,6 +72,16 @@ struct Message {
|
||||||
time: u64,
|
time: u64,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct IsClickable {
|
||||||
|
pub name: Option<String>,
|
||||||
|
pub distance: Option<f64>,
|
||||||
|
}
|
||||||
|
impl Default for IsClickable { fn default() -> Self { Self {
|
||||||
|
name: None,
|
||||||
|
distance: None,
|
||||||
|
}}}
|
||||||
|
|
||||||
#[derive(Resource)]
|
#[derive(Resource)]
|
||||||
pub struct Log {
|
pub struct Log {
|
||||||
logs: VecDeque<Message>,
|
logs: VecDeque<Message>,
|
||||||
|
@ -472,7 +481,7 @@ fn update_hud(
|
||||||
mut query_chat: Query<&mut Text, (With<ChatText>, Without<GaugesText>)>,
|
mut query_chat: Query<&mut Text, (With<ChatText>, Without<GaugesText>)>,
|
||||||
query_all_actors: Query<&actor::Actor>,
|
query_all_actors: Query<&actor::Actor>,
|
||||||
settings: Res<settings::Settings>,
|
settings: Res<settings::Settings>,
|
||||||
q_target: Query<(&Position, &actor::Actor), With<IsTargeted>>,
|
q_target: Query<(Option<&Position>, &IsClickable), With<IsTargeted>>,
|
||||||
) {
|
) {
|
||||||
// TODO only when hud is actually on
|
// TODO only when hud is actually on
|
||||||
if timer.0.tick(time.delta()).just_finished() || log.needs_rerendering {
|
if timer.0.tick(time.delta()).just_finished() || log.needs_rerendering {
|
||||||
|
@ -516,8 +525,14 @@ fn update_hud(
|
||||||
text.sections[19].value = format!("{speed:.0}m/s | {kmh:.0}km/h");
|
text.sections[19].value = format!("{speed:.0}m/s | {kmh:.0}km/h");
|
||||||
|
|
||||||
// Target display
|
// Target display
|
||||||
|
let (x, y, z, dist_scalar) : (f64, f64, f64, f64);
|
||||||
|
if let Ok((_, IsClickable { distance: Some(dist), .. })) = q_target.get_single() {
|
||||||
|
dist_scalar = *dist;
|
||||||
|
(x, y, z) = (0.0, 0.0, 0.0);
|
||||||
|
}
|
||||||
|
else {
|
||||||
let target: Option<DVec3>;
|
let target: Option<DVec3>;
|
||||||
if let Ok((targetpos, _actr)) = q_target.get_single() {
|
if let Ok((Some(targetpos), _)) = q_target.get_single() {
|
||||||
target = Some(targetpos.0);
|
target = Some(targetpos.0);
|
||||||
}
|
}
|
||||||
else if q_target.is_empty() {
|
else if q_target.is_empty() {
|
||||||
|
@ -528,12 +543,20 @@ fn update_hud(
|
||||||
}
|
}
|
||||||
if let Some(target_pos) = target {
|
if let Some(target_pos) = target {
|
||||||
let dist = pos.0 - target_pos;
|
let dist = pos.0 - target_pos;
|
||||||
let (x, y, z) = (dist.x, dist.y, dist.z);
|
(x, y, z) = (dist.x, dist.y, dist.z);
|
||||||
let dist_scalar = dist.length();
|
dist_scalar = dist.length();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
(x, y, z) = (0.0, 0.0, 0.0);
|
||||||
|
dist_scalar = 0.0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if dist_scalar != 0.0 {
|
||||||
text.sections[7].value = format!("{x:.0}m / {z:.0}m / {y:.0}m / distance: {dist_scalar:.0}m");
|
text.sections[7].value = format!("{x:.0}m / {z:.0}m / {y:.0}m / distance: {dist_scalar:.0}m");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
text.sections[7].value = format!("ERROR: MULTIPLE TARGETS");
|
text.sections[7].value = format!("TARGET ERROR");
|
||||||
}
|
}
|
||||||
if q_target.is_empty() {
|
if q_target.is_empty() {
|
||||||
text.sections[21].value = "Jupiter".to_string();
|
text.sections[21].value = "Jupiter".to_string();
|
||||||
|
@ -541,7 +564,7 @@ fn update_hud(
|
||||||
else {
|
else {
|
||||||
let targets: Vec<String> = q_target
|
let targets: Vec<String> = q_target
|
||||||
.iter()
|
.iter()
|
||||||
.map(|(_pos, act)| act.name.clone().unwrap_or("<unnamed>".to_string()))
|
.map(|(_, clickable)| clickable.name.clone().unwrap_or("<unnamed>".to_string()))
|
||||||
.collect();
|
.collect();
|
||||||
text.sections[21].value = targets.join(", ");
|
text.sections[21].value = targets.join(", ");
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use crate::{actor, nature, settings};
|
use crate::{actor, hud, nature, settings};
|
||||||
use bevy::prelude::*;
|
use bevy::prelude::*;
|
||||||
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
use bevy::render::render_resource::{AsBindGroup, ShaderRef};
|
||||||
use bevy::math::{DVec3, I64Vec3};
|
use bevy::math::{DVec3, I64Vec3};
|
||||||
|
@ -151,6 +151,10 @@ pub fn setup(
|
||||||
let dist = 1e9;
|
let dist = 1e9;
|
||||||
commands.spawn((
|
commands.spawn((
|
||||||
Star,
|
Star,
|
||||||
|
hud::IsClickable {
|
||||||
|
name: Some("Star".to_string()),
|
||||||
|
distance: Some(10000000000.0),
|
||||||
|
},
|
||||||
PbrBundle {
|
PbrBundle {
|
||||||
mesh: sphere_handle.clone(),
|
mesh: sphere_handle.clone(),
|
||||||
material: star_color_handle,
|
material: star_color_handle,
|
||||||
|
|
Loading…
Reference in a new issue