Tooltip in world space works, need to populate with data

main
Elijah Voigt 3 months ago
parent 7100fc1cb1
commit 079b5aa787

@ -36,7 +36,9 @@ impl Plugin for DebuggingPlugin {
) )
.run_if(in_state(DebuggingState::On)), .run_if(in_state(DebuggingState::On)),
), ),
); )
.add_observer(add_tooltip_text)
.add_observer(remove_tooltip_text);
// WebGL2-incompatible systems // WebGL2-incompatible systems
#[cfg(not(target_arch = "wasm32"))] #[cfg(not(target_arch = "wasm32"))]
@ -265,6 +267,37 @@ fn lock_tooltip(
}); });
} }
/// when a tooltip is added to an entity, insert the text component
fn add_tooltip_text(
trigger: Trigger<OnAdd, ToolTip>,
mut commands: Commands,
) {
info!("Adding text2d to {:?}", trigger.target());
commands.entity(trigger.target()).with_children(|parent| {
parent.spawn((
TextColor(GREEN.into()),
Text2d("Placeholder".into()),
Transform::from_xyz(1.5, 0.0, 1.0).with_scale(Vec3::splat(0.01)),
));
});
}
/// when a tooltip is removed to an entity, remove the text components
fn remove_tooltip_text(
trigger: Trigger<OnRemove, ToolTip>,
mut commands: Commands,
parents: Query<&Children>,
text_2d: Query<Entity, With<Text2d>>,
) {
// Get lis of children for this entity
let children = parents.get(trigger.target()).unwrap();
// Find the tooltip text child
if let Some(child) = children.iter().find_map(|child| text_2d.get(child).ok()) {
// Remove it from the world
commands.entity(child).despawn();
}
}
/// When you hover over a mesh, update the tooltip with some info /// When you hover over a mesh, update the tooltip with some info
fn hover_mesh( fn hover_mesh(
mut over_events: EventReader<Pointer<Over>>, mut over_events: EventReader<Pointer<Over>>,

Loading…
Cancel
Save