|
|
|
|
@ -1,6 +1,6 @@
|
|
|
|
|
use std::{cmp::Ordering, collections::VecDeque};
|
|
|
|
|
|
|
|
|
|
use bevy::picking::{backend::HitData, hover::HoverMap};
|
|
|
|
|
use bevy::{picking::{backend::HitData, hover::HoverMap}, sprite::Anchor};
|
|
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
|
|
@ -18,7 +18,9 @@ impl Plugin for DebuggingPlugin {
|
|
|
|
|
.add_systems(
|
|
|
|
|
Update,
|
|
|
|
|
(
|
|
|
|
|
(toggle_state_visibility::<DebuggingState>,)
|
|
|
|
|
(
|
|
|
|
|
toggle_state_visibility::<DebuggingState>,
|
|
|
|
|
)
|
|
|
|
|
.run_if(state_changed::<DebuggingState>),
|
|
|
|
|
toggle_debug_state.run_if(input_just_pressed(KeyCode::F12)),
|
|
|
|
|
(toggle_light_gizmo, toggle_aabb_gizmo).run_if(state_changed::<DebuggingState>),
|
|
|
|
|
@ -26,6 +28,8 @@ impl Plugin for DebuggingPlugin {
|
|
|
|
|
(hover_mesh, hover_ui)
|
|
|
|
|
.run_if(on_event::<Pointer<Over>>.or(on_event::<Pointer<Out>>)),
|
|
|
|
|
tooltip_follow.run_if(any_component_changed::<Window>),
|
|
|
|
|
tooltip_update_transform.run_if(any_component_changed::<Transform>),
|
|
|
|
|
tooltip_draw.run_if(any_component_changed::<ToolTip>),
|
|
|
|
|
sync_resource_to_ui::<ToolTip>.run_if(resource_changed::<ToolTip>),
|
|
|
|
|
lock_tooltip.run_if(input_just_pressed(KeyCode::KeyL)),
|
|
|
|
|
track_fps,
|
|
|
|
|
@ -38,6 +42,7 @@ impl Plugin for DebuggingPlugin {
|
|
|
|
|
),
|
|
|
|
|
)
|
|
|
|
|
.add_observer(add_tooltip_text)
|
|
|
|
|
.add_observer(populate_tooltip_info)
|
|
|
|
|
.add_observer(remove_tooltip_text);
|
|
|
|
|
|
|
|
|
|
// WebGL2-incompatible systems
|
|
|
|
|
@ -275,13 +280,34 @@ fn add_tooltip_text(
|
|
|
|
|
info!("Adding text2d to {:?}", trigger.target());
|
|
|
|
|
commands.entity(trigger.target()).with_children(|parent| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
TextColor(GREEN.into()),
|
|
|
|
|
TextColor(BLACK.into()),
|
|
|
|
|
Text2d("Placeholder".into()),
|
|
|
|
|
Transform::from_xyz(1.5, 0.0, 1.0).with_scale(Vec3::splat(0.01)),
|
|
|
|
|
Transform::from_xyz(0.5, 0.0, 1.0).with_scale(Vec3::splat(0.01)),
|
|
|
|
|
Anchor::CenterLeft,
|
|
|
|
|
DebuggingState::On,
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn populate_tooltip_info(
|
|
|
|
|
trigger: Trigger<OnAdd, ToolTip>,
|
|
|
|
|
mut tooltips: Query<(&mut ToolTip, Entity, &Transform, &Name)>,
|
|
|
|
|
) {
|
|
|
|
|
if let Ok((mut tt, e, t, n)) = tooltips.get_mut(trigger.target()) {
|
|
|
|
|
tt.insert("ID", format!("{e}"));
|
|
|
|
|
tt.insert("Name", n.into());
|
|
|
|
|
tt.insert("Pos", format!("{:.2?} {:.2?} {:.2?}", t.translation.x, t.translation.y, t.translation.z));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn tooltip_update_transform(
|
|
|
|
|
mut events: Query<(&mut ToolTip, &Transform), Changed<Transform>>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter_mut().for_each(|(mut tt, t)| {
|
|
|
|
|
tt.insert("Pos", format!("{:.2?} {:.2?} {:.2?}", t.translation.x, t.translation.y, t.translation.z));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// when a tooltip is removed to an entity, remove the text components
|
|
|
|
|
fn remove_tooltip_text(
|
|
|
|
|
trigger: Trigger<OnRemove, ToolTip>,
|
|
|
|
|
@ -298,6 +324,21 @@ fn remove_tooltip_text(
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// When tooltip is updated, re-draw it
|
|
|
|
|
fn tooltip_draw(
|
|
|
|
|
events: Query<(&ToolTip, &Children), Changed<ToolTip>>,
|
|
|
|
|
mut text_2d: Query<&mut Text2d>,
|
|
|
|
|
) {
|
|
|
|
|
events.iter().for_each(|(tt, children)| {
|
|
|
|
|
// Find the tooltip text child
|
|
|
|
|
children.iter().for_each(|child| {
|
|
|
|
|
if let Ok(mut text) = text_2d.get_mut(child) {
|
|
|
|
|
text.0 = format!("{}", tt);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// When you hover over a mesh, update the tooltip with some info
|
|
|
|
|
fn hover_mesh(
|
|
|
|
|
mut over_events: EventReader<Pointer<Over>>,
|
|
|
|
|
|