can now change colors!

This commit is contained in:
RustyStriker 2022-08-15 23:25:47 +03:00
parent a6452fcfbf
commit 91e31fed7e

View file

@ -116,8 +116,9 @@ pub fn items_tree_sys(
mut selected: ResMut<SelectedItem>, mut selected: ResMut<SelectedItem>,
mut egui_ctx: ResMut<EguiContext>, mut egui_ctx: ResMut<EguiContext>,
shapes:Query<(Entity, &ShapeData)>, shapes:Query<(Entity, &ShapeData)>,
mut visible: Query<&mut Visibility, Or<(With<Path>, With<Sprite>)>>,
images: Query<(Entity, &ImageName), With<Sprite>>, images: Query<(Entity, &ImageName), With<Sprite>>,
mut draw_modes: Query<&mut DrawMode, With<ShapeData>>,
mut visible: Query<&mut Visibility, Or<(With<Path>, With<Sprite>)>>,
) { ) {
egui::Window::new("Items") egui::Window::new("Items")
.default_pos((10.0,100.0)) .default_pos((10.0,100.0))
@ -125,11 +126,12 @@ pub fn items_tree_sys(
.resizable(false) .resizable(false)
.show(egui_ctx.ctx_mut(), |ui| { .show(egui_ctx.ctx_mut(), |ui| {
for (e, sd) in shapes.iter() { for (e, sd) in shapes.iter() {
let entity_selected = if let Some(se) = **selected && se == e { true } else { false };
ui.horizontal(|hui| { ui.horizontal(|hui| {
let color = if let Some(se) = **selected && se == e { egui::Color32::GOLD } else { egui::Color32::WHITE }; let color = if entity_selected { egui::Color32::GOLD } else { egui::Color32::WHITE };
let label = egui::Label::new(egui::RichText::new(&sd.name).color(color)).sense(egui::Sense::click()); let label = egui::Label::new(egui::RichText::new(&sd.name).color(color)).sense(egui::Sense::click());
if hui.add(label).clicked() { if hui.add(label).clicked() {
if color == egui::Color32::GOLD { if entity_selected {
**selected = None; **selected = None;
} }
else { else {
@ -144,13 +146,21 @@ pub fn items_tree_sys(
} }
} }
}); });
if let Ok(mut dm) = draw_modes.get_mut(e) {
if let DrawMode::Outlined { fill_mode: _ , outline_mode: o } = &mut *dm {
o.color = if entity_selected { Color::GOLD } else { Color::rgba(0.0, 0.5, 0.5, 0.6) };
}
}
} }
for (e, n) in images.iter() { for (e, n) in images.iter() {
let entity_selected = if let Some(se) = **selected && se == e { true } else { false };
ui.horizontal(|hui| { ui.horizontal(|hui| {
let color = if let Some(se) = **selected && se == e { egui::Color32::GOLD } else { egui::Color32::WHITE }; let color = if entity_selected { egui::Color32::GOLD } else { egui::Color32::WHITE };
let label = egui::Label::new(egui::RichText::new(&**n).color(color)).sense(egui::Sense::click()); let label = egui::Label::new(egui::RichText::new(&**n).color(color)).sense(egui::Sense::click());
if hui.add(label).clicked() { if hui.add(label).clicked() {
if color == egui::Color32::GOLD { if entity_selected {
**selected = None; **selected = None;
} }
else { else {
@ -254,6 +264,19 @@ pub fn inspector_sys(
if let Ok(mut v) = visible.get_mut(e) { if let Ok(mut v) = visible.get_mut(e) {
ui.checkbox(&mut v.is_visible, "Visible"); ui.checkbox(&mut v.is_visible, "Visible");
} }
if let Ok(mut dm) = draw_modes.get_mut(e) {
ui.separator();
if let DrawMode::Outlined { fill_mode: f, outline_mode: _ } = &mut *dm {
ui.horizontal(|hui| {
hui.label("Color: ");
let mut color = [f.color.r(), f.color.g(), f.color.b(), f.color.a()];
if hui.color_edit_button_rgba_unmultiplied(&mut color).changed() {
f.color = Color::from(color);
}
});
}
}
ui.separator(); ui.separator();
if ui.button("Delete").clicked() { if ui.button("Delete").clicked() {