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] 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:
|
||||
|
||||
## 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
|
||||
|
|
|
@ -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<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)")
|
||||
.pick_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);
|
||||
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<Path>>,
|
||||
mut visible: Query<&mut Visibility, Or<(With<Path>, With<Sprite>)>>,
|
||||
mut images: Query<(Entity, &mut ImageName), With<Sprite>>,
|
||||
) {
|
||||
if !shapes.is_empty() {
|
||||
egui::Window::new("Shape Tree")
|
||||
|
@ -162,17 +166,28 @@ 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() {
|
||||
if collapse.fully_closed() {
|
||||
if hui.button("E").clicked() {
|
||||
*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(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)),
|
||||
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