diff --git a/src/bin/flappy/main.rs b/src/bin/flappy/main.rs index cd3340b..a3f959a 100644 --- a/src/bin/flappy/main.rs +++ b/src/bin/flappy/main.rs @@ -224,7 +224,7 @@ fn update_batch( mut root: Query<(&mut Transform, &Batch), With>, ) { 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(), diff --git a/src/debug.rs b/src/debug.rs index 8733597..0b0faa0 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -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::>.or(on_event::>)), tooltip_follow.run_if(any_component_changed::), sync_resource_to_ui::.run_if(resource_changed::), + lock_tooltip.run_if(input_just_pressed(KeyCode::KeyL)), track_fps, sync_resource_to_ui::.run_if(resource_changed::), 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>, + hover_map: Res, + 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::(); + } + _ => () + } + } + }); +} + /// When you hover over a mesh, update the tooltip with some info fn hover_mesh( mut over_events: EventReader>,