show/hide images/shapes and images visible in tree view
This commit is contained in:
parent
374fce86e1
commit
10b120512f
3 changed files with 66 additions and 15 deletions
19
README.md
19
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] Drag camera around
|
||||||
- [x] Zome in/out
|
- [x] Zome in/out
|
||||||
- [ ] Import images:
|
- [ ] Import images:
|
||||||
- [ ] Insert images
|
- [x] Insert images
|
||||||
- [ ] Show images in tree view
|
- [x] Show images in tree view
|
||||||
- [ ] Show/Hide images
|
- [x] Show/Hide images
|
||||||
- [ ] Move/Drag images around
|
- [ ] Move/Drag images around
|
||||||
- [ ] Control images Z value(so we could reorder them)
|
- [ ] Control images Z value(so we could reorder them)
|
||||||
- [ ] Delete images
|
- [ ] Delete images
|
||||||
- [ ] Name images
|
- [ ] Name images
|
||||||
- [ ] Duplicate images(and also shapes maybe?)?
|
- [ ] Duplicate images(and also shapes maybe?)?
|
||||||
- [ ] Show hide shapes
|
- [x] Show hide shapes
|
||||||
|
- [ ] Control shape Z value
|
||||||
- [ ] Snap to grid
|
- [ ] Snap to grid
|
||||||
- [ ] Change grid size
|
- [ ] Change grid size
|
||||||
- [ ] Show/Hide grid(also make a visible grid in the first place)
|
- [ ] 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?)
|
- [ ] Save? (maybe just import and export directly?)
|
||||||
- [ ] Export
|
- [ ] Export
|
||||||
- [ ] Import
|
- [ ] Import
|
||||||
- Quality of life todo:
|
|
||||||
|
## Quality of life todo
|
||||||
|
|
||||||
- [ ] Double click on shape in tree view will center the relevant shape
|
- [ ] 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
|
||||||
|
|
|
@ -16,6 +16,9 @@ pub use helpers::*;
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct PointSize(pub f32);
|
pub struct PointSize(pub f32);
|
||||||
|
|
||||||
|
#[derive(Component, Debug, Deref, DerefMut)]
|
||||||
|
pub struct ImageName(pub String);
|
||||||
|
|
||||||
#[derive(Component, Debug)]
|
#[derive(Component, Debug)]
|
||||||
pub struct ShapeData {
|
pub struct ShapeData {
|
||||||
pub name: Option<String>,
|
pub name: Option<String>,
|
||||||
|
|
49
src/ui.rs
49
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)")
|
.set_title("Please dont try to pick a cat instead of an image(although you can pick a cat image)")
|
||||||
.pick_file();
|
.pick_file();
|
||||||
if let Some(file) = file {
|
if let Some(file) = file {
|
||||||
|
let name = String::from(file.file_name().unwrap().to_str().unwrap_or("Image"));
|
||||||
let image: Handle<Image> = assets.load(file);
|
let image: Handle<Image> = assets.load(file);
|
||||||
coms.spawn_bundle(SpriteBundle {
|
coms.spawn_bundle(SpriteBundle {
|
||||||
texture: image,
|
texture: image,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
});
|
})
|
||||||
|
.insert(ImageName(name));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -83,6 +85,8 @@ pub fn shape_tree_sys(
|
||||||
global_transforms: Query<&GlobalTransform>,
|
global_transforms: Query<&GlobalTransform>,
|
||||||
mut paths: Query<&mut Path>,
|
mut paths: Query<&mut Path>,
|
||||||
mut draw_modes: Query<&mut DrawMode, With<Path>>,
|
mut draw_modes: Query<&mut DrawMode, With<Path>>,
|
||||||
|
mut visible: Query<&mut Visibility, Or<(With<Path>, With<Sprite>)>>,
|
||||||
|
mut images: Query<(Entity, &mut ImageName), With<Sprite>>,
|
||||||
) {
|
) {
|
||||||
if !shapes.is_empty() {
|
if !shapes.is_empty() {
|
||||||
egui::Window::new("Shape Tree")
|
egui::Window::new("Shape Tree")
|
||||||
|
@ -162,17 +166,28 @@ pub fn shape_tree_sys(
|
||||||
coms.entity(sd.main_shape).despawn_recursive();
|
coms.entity(sd.main_shape).despawn_recursive();
|
||||||
coms.entity(e).despawn();
|
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);
|
ui_func(ui);
|
||||||
});
|
});
|
||||||
let closed = collapse.fully_closed();
|
if collapse.fully_closed() {
|
||||||
if closed && hui.button("E").clicked() {
|
if hui.button("E").clicked() {
|
||||||
*name_change = Some((e, default_name));
|
*name_change = Some((e, default_name));
|
||||||
}
|
}
|
||||||
if closed && hui.button("D").clicked() {
|
if hui.button("D").clicked() {
|
||||||
coms.entity(sd.main_shape).despawn_recursive();
|
coms.entity(sd.main_shape).despawn_recursive();
|
||||||
coms.entity(e).despawn();
|
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 {
|
let d_normal = DrawMode::Outlined {
|
||||||
fill_mode: FillMode::color(Color::rgba(0.0, 0.5, 0.5, 0.4)),
|
fill_mode: FillMode::color(Color::rgba(0.0, 0.5, 0.5, 0.4)),
|
||||||
outline_mode: StrokeMode::new(Color::rgba(0.0, 0.5, 0.5, 0.6), 3.0),
|
outline_mode: StrokeMode::new(Color::rgba(0.0, 0.5, 0.5, 0.6), 3.0),
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue