From 10b120512f55a1906eeea68084ff2035335b1411 Mon Sep 17 00:00:00 2001 From: RustyStriker Date: Wed, 3 Aug 2022 18:31:57 +0300 Subject: [PATCH] show/hide images/shapes and images visible in tree view --- README.md | 21 +++++++++++++------- src/lib.rs | 3 +++ src/ui.rs | 57 ++++++++++++++++++++++++++++++++++++++++++++++-------- 3 files changed, 66 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 732457a..061c08e 100644 --- a/README.md +++ b/README.md @@ -11,21 +11,28 @@ Eventually, this will be a level editor... But until then, I guess it's just fun - [x] Drag camera around - [x] Zome in/out - [ ] Import images: - - [ ] Insert images - - [ ] Show images in tree view - - [ ] Show/Hide images + - [x] Insert images + - [x] Show images in tree view + - [x] Show/Hide images - [ ] Move/Drag images around - [ ] Control images Z value(so we could reorder them) - [ ] Delete images - [ ] Name images - [ ] Duplicate images(and also shapes maybe?)? -- [ ] Show hide shapes +- [x] Show hide shapes +- [ ] Control shape Z value - [ ] Snap to grid - [ ] Change grid size - [ ] Show/Hide grid(also make a visible grid in the first place) -- [ ] Grab shapes instead of center points - [ ] Save? (maybe just import and export directly?) - [ ] Export - [ ] Import -- Quality of life todo: - - [ ] Double click on shape in tree view will center the relevant shape + +## Quality of life todo + +- [ ] Double click on shape in tree view will center the relevant shape +- [ ] Grab shapes instead of center points + +## Maybe, just maybe todo + +- [ ] Group shapes/images under an empty/another object diff --git a/src/lib.rs b/src/lib.rs index 3265d0f..cd7093c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,6 +16,9 @@ pub use helpers::*; #[derive(Clone, Debug)] pub struct PointSize(pub f32); +#[derive(Component, Debug, Deref, DerefMut)] +pub struct ImageName(pub String); + #[derive(Component, Debug)] pub struct ShapeData { pub name: Option, diff --git a/src/ui.rs b/src/ui.rs index 8520de9..99fc16c 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -36,11 +36,13 @@ pub fn action_bar_sys( .set_title("Please dont try to pick a cat instead of an image(although you can pick a cat image)") .pick_file(); if let Some(file) = file { + let name = String::from(file.file_name().unwrap().to_str().unwrap_or("Image")); let image: Handle = assets.load(file); coms.spawn_bundle(SpriteBundle { texture: image, ..Default::default() - }); + }) + .insert(ImageName(name)); } } @@ -83,6 +85,8 @@ pub fn shape_tree_sys( global_transforms: Query<&GlobalTransform>, mut paths: Query<&mut Path>, mut draw_modes: Query<&mut DrawMode, With>, + mut visible: Query<&mut Visibility, Or<(With, With)>>, + mut images: Query<(Entity, &mut ImageName), With>, ) { if !shapes.is_empty() { egui::Window::new("Shape Tree") @@ -162,16 +166,27 @@ pub fn shape_tree_sys( coms.entity(sd.main_shape).despawn_recursive(); coms.entity(e).despawn(); } + let mut v = visible.get_mut(sd.main_shape).unwrap(); + let text = if v.is_visible { egui::RichText::new("V") } else { egui::RichText::new("V").strikethrough() }; + if hui.button(text).clicked() { + v.is_visible ^= true; + } }); ui_func(ui); }); - let closed = collapse.fully_closed(); - if closed && hui.button("E").clicked() { - *name_change = Some((e, default_name)); - } - if closed && hui.button("D").clicked() { - coms.entity(sd.main_shape).despawn_recursive(); - coms.entity(e).despawn(); + if collapse.fully_closed() { + if hui.button("E").clicked() { + *name_change = Some((e, default_name)); + } + if hui.button("D").clicked() { + coms.entity(sd.main_shape).despawn_recursive(); + coms.entity(e).despawn(); + } + let mut v = visible.get_mut(sd.main_shape).unwrap(); + let text = if v.is_visible { egui::RichText::new("V") } else { egui::RichText::new("V").strikethrough() }; + if hui.button(text).clicked() { + v.is_visible ^= true; + } } let d_normal = DrawMode::Outlined { fill_mode: FillMode::color(Color::rgba(0.0, 0.5, 0.5, 0.4)), @@ -192,6 +207,32 @@ pub fn shape_tree_sys( } }); } + for (e, mut n) in images.iter_mut() { + if let Some((ne, name)) = &mut *name_change && *ne == e { + let te = egui::TextEdit::singleline(name); + + if ui.add(te).lost_focus() { + let (_, name) = name_change.take().unwrap(); + **n = name; + } + } + else { + ui.horizontal(|hui| { + hui.label(&**n); + if hui.button("E").clicked() { + *name_change = Some((e, n.clone())); + } + if hui.button("D").clicked() { + coms.entity(e).despawn(); + } + let mut v = visible.get_mut(e).unwrap(); + let text = if v.is_visible { egui::RichText::new("V") } else { egui::RichText::new("V").strikethrough() }; + if hui.button(text).clicked() { + v.is_visible ^= true; + } + }); + } + } }); } } \ No newline at end of file