I have the tooltip component added so thats a start

main
Elijah Voigt 3 months ago
parent 4f6e054630
commit 7100fc1cb1

@ -224,7 +224,7 @@ fn update_batch(
mut root: Query<(&mut Transform, &Batch), With<Children>>,
) {
if let Ok((mut t, Batch(idx))) = root.get_mut(trigger.target()) {
info!("Updating batch {:?}", idx);
debug!("Updating batch {:?}", idx);
t.translation.x = 500.0 * (*idx) as f32;
}
// todo!("Adjust pipe positions");
@ -239,7 +239,7 @@ fn populate_ground(
mut commands: Commands,
) {
let Ground(idx) = grounds.get(trigger.target()).unwrap();
info!("populating ground {:?}", idx);
debug!("populating ground {:?}", idx);
commands.entity(trigger.target()).insert((
ground_assets.material.clone(),
ground_assets.mesh.clone(),

@ -1,4 +1,6 @@
use std::collections::VecDeque;
use std::{cmp::Ordering, collections::VecDeque};
use bevy::picking::{backend::HitData, hover::HoverMap};
use super::*;
@ -25,6 +27,7 @@ impl Plugin for DebuggingPlugin {
.run_if(on_event::<Pointer<Over>>.or(on_event::<Pointer<Out>>)),
tooltip_follow.run_if(any_component_changed::<Window>),
sync_resource_to_ui::<ToolTip>.run_if(resource_changed::<ToolTip>),
lock_tooltip.run_if(input_just_pressed(KeyCode::KeyL)),
track_fps,
sync_resource_to_ui::<Fps>.run_if(resource_changed::<Fps>),
track_entity_count,
@ -231,6 +234,37 @@ fn tooltip_follow(
}
}
/// Lok tooltip to entity by inserting the Tooltip component on it
fn lock_tooltip(
q: Query<Option<&ToolTip>>,
hover_map: Res<HoverMap>,
mut commands: Commands,
) {
hover_map.0.iter().for_each(|(_, hit_data_map)| {
if let Some((e, _)) = hit_data_map.iter().min_by(|(_, a), (_, b)| {
if a.depth > b.depth {
Ordering::Greater
} else if a.depth < b.depth {
Ordering::Less
} else {
Ordering::Equal
}
}) {
match q.get(*e) {
Ok(None) => {
info!("Adding tooltip to {:?}", e);
commands.entity(*e).insert(ToolTip::default());
}
Ok(Some(_)) => {
info!("Removing tooltip from {:?}", e);
commands.entity(*e).remove::<ToolTip>();
}
_ => ()
}
}
});
}
/// When you hover over a mesh, update the tooltip with some info
fn hover_mesh(
mut over_events: EventReader<Pointer<Over>>,

Loading…
Cancel
Save