tree view update + highlihgt hovered dot

This commit is contained in:
RustyStriker 2022-07-31 18:28:44 +03:00
parent db8657bb96
commit c59621e43d
6 changed files with 184 additions and 32 deletions

View file

@ -1,4 +1,5 @@
use bevy::ecs::schedule::ShouldRun;
use bevy::math::Vec3Swizzles;
use bevy::{prelude::*, window::PresentMode, winit::WinitSettings};
use bevy_egui::{egui, EguiContext, EguiPlugin};
use bevy_prototype_lyon::prelude::*;
@ -20,7 +21,7 @@ fn main() {
})
.insert_resource(ButtonsColors::default())
.insert_resource(UiState::default())
.insert_resource(PointSize(5.0))
.insert_resource(PointSize(6.0))
;
app
@ -28,6 +29,7 @@ fn main() {
.add_plugin(EguiPlugin)
.add_plugin(ShapePlugin)
;
app
.add_startup_system(configure_visuals)
.add_startup_system(basic_setup_sys)
@ -42,6 +44,8 @@ fn main() {
))
.add_system(action_bar_sys)
.add_system(shape_tree_sys)
.add_system(show_hide_points)
.add_system(color_points)
;
app.run();
@ -59,4 +63,96 @@ fn configure_visuals(mut egui_ctx: ResMut<EguiContext>) {
window_rounding: 0.0.into(),
..Default::default()
});
}
fn show_hide_points(
state: Res<UiState>,
shapes: Query<&ShapeData>,
mut dots: Query<&mut Visibility, (With<Transform>, With<Path>)>,
) {
let (center, edge) = match state.current_action {
Action::Create => (false, false),
Action::Modify => (true, true),
Action::Rotate => (true, true),
};
for sd in shapes.iter() {
// center
if let Ok(mut v) = dots.get_mut(sd.center.unwrap()) {
if v.is_visible != center {
v.is_visible = center;
}
}
for e in sd.edges.iter() {
if let Ok(mut v) = dots.get_mut(*e) {
if v.is_visible != edge {
v.is_visible = edge;
}
}
}
}
}
fn color_points(
mut current: Local<Option<Entity>>,
wnds: Res<Windows>,
p_size: Res<PointSize>,
q_cam: Query<(&Camera, &GlobalTransform), With<MainCamera>>,
shapes: Query<&ShapeData>,
global_transforms: Query<&GlobalTransform, With<Path>>,
mut dots: Query<&mut DrawMode, With<Path>>,
) {
let normal = DrawMode::Outlined { fill_mode: FillMode::color(Color::RED), outline_mode: StrokeMode::new(Color::rgb(0.9,0.0,0.0), 1.0) };
let hover = DrawMode::Outlined { fill_mode: FillMode::color(Color::RED), outline_mode: StrokeMode::new(Color::ORANGE, 3.0) };
let mouse_pos = get_mouse_pos(&q_cam, &wnds);
if let Some(mpos) = mouse_pos {
let mut hovering = false;
'shapes: for sd in shapes.iter() {
let e = sd.center.unwrap();
let p = global_transforms.get(e).unwrap().translation.xy();
if (mpos - p).length_squared() < p_size.0.powi(2) {
if Some(e) != *current {
if let Some(c) = &*current {
if let Ok(mut md) = dots.get_mut(*c) {
*md = normal;
}
}
*current = Some(e);
if let Ok(mut md) = dots.get_mut(e) {
*md = hover;
}
}
hovering = true;
break;
}
for edge in sd.edges.iter() {
let p = global_transforms.get(*edge).unwrap().translation.xy();
if (mpos - p).length_squared() < p_size.0.powi(2) {
if Some(*edge) != *current {
if let Some(c) = &*current {
if let Ok(mut md) = dots.get_mut(*c) {
*md = normal;
}
}
*current = Some(*edge);
if let Ok(mut md) = dots.get_mut(*edge) {
*md = hover;
}
}
hovering = true;
break 'shapes;
}
}
}
if !hovering {
if let Some(c) = &*current {
if let Ok(mut md) = dots.get_mut(*c) {
*md = normal;
}
*current = None;
}
}
}
}