Created
October 7, 2023 11:01
-
-
Save jan-tennert/ac216e5b9642d96482cf2380f629c99d to your computer and use it in GitHub Desktop.
rust
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub fn system_ui( | |
mut egui_context: EguiContexts, | |
mut star_query: Query<( | |
&Name, | |
&Children, | |
&mut Selectable, | |
&mut Visibility, | |
With<Star>, | |
Without<Planet>, | |
Without<Planet> | |
)>, | |
mut planet_query: Query<( | |
&Name, | |
&Children, | |
&mut Selectable, | |
&mut Visibility, | |
With<Planet>, | |
Without<Star>, | |
Without<Moon> | |
)>, | |
mut moon_query: Query<( | |
&Name, | |
&mut Selectable, | |
&mut Visibility, | |
With<Moon>, | |
Without<Planet>, | |
Without<Star> | |
)>, | |
mut camera: Query<&mut Camera>, | |
mut light: Query<&mut PointLight>, | |
mut state: ResMut<NextState<SimState>> | |
) { | |
let mut new_selected: Option<&Name> = None; | |
egui::SidePanel::left("system_panel") | |
.default_width(400.0) | |
.resizable(true) | |
.show(egui_context.ctx_mut(), |ui| { | |
ui.heading("Bodies"); | |
for (s_name, s_children, s_selectable, _, _, _, _) in &star_query { | |
ui.horizontal(|ui| { | |
// ui.checkbox(&mut visibility.is_visible, ""); | |
if ui.button(s_name.as_str()).clicked() && !s_selectable.0 { | |
new_selected = Some(s_name); | |
} | |
}); | |
for planet_child in s_children { | |
if let Ok((p_name, p_children, p_selectable, _, _, _, _)) = planet_query.get(*planet_child) { | |
ui.horizontal(|ui| { | |
// ui.checkbox(&mut visibility.is_visible, ""); | |
ui.add_space(5.0); | |
if ui.button(p_name.as_str()).clicked() && !p_selectable.0 { | |
new_selected = Some(p_name); | |
} | |
}); | |
for moon_child in p_children { | |
if let Ok((m_name, m_selectable, _, _, _, _)) = moon_query.get(*moon_child) { | |
ui.horizontal(|ui| { | |
// ui.checkbox(&mut visibility.is_visible, ""); | |
ui.add_space(10.0); | |
if ui.button(m_name.as_str()).clicked() && !m_selectable.0 { | |
new_selected = Some(m_name); | |
} | |
}); | |
} | |
} | |
} | |
} | |
} | |
ui.heading("Options"); | |
if let Ok(mut camera) = camera.get_single_mut() { | |
ui.checkbox(&mut camera.hdr, "HDR/Bloom"); | |
} | |
if let Ok(mut light) = light.get_single_mut() { | |
ui.checkbox(&mut light.shadows_enabled, "Shadows"); | |
} | |
ui.with_layout(egui::Layout::bottom_up(egui::Align::LEFT), |ui| { | |
if ui.button("Back to Menu").clicked() { | |
let _ = state.set(SimState::ExitToMainMenu); | |
} | |
}); | |
}); | |
/*if let Some(new_name) = new_selected { | |
for (name, _, ref mut selectable, _, _, _, _) in &mut planet_query { | |
if name.clone() == new_name.clone() && !selectable.0 { | |
selectable.0 = true; | |
} else if name.clone() != new_name.clone() && selectable.0 { | |
selectable.0 = false; | |
} | |
} | |
}*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment