use egui::{Color32, Stroke, Ui, epaint::CircleShape}; use crate::{ Camera, Config, Diagnostics, Input, content::materials::MaterialId, sim::{rb_manager::DebugRenderMode, sim_manager::SimManager}, }; const DEBUG_RENDER_MODES: [(&str, DebugRenderMode); 6] = [ ("Collider shapes", DebugRenderMode::COLLIDER_SHAPES), ("Collider AABBs", DebugRenderMode::COLLIDER_AABBS), ("Rigid body axes", DebugRenderMode::RIGID_BODY_AXES), ("Joints", DebugRenderMode::JOINTS), ("Contacts", DebugRenderMode::CONTACTS), ("Solver contacts", DebugRenderMode::SOLVER_CONTACTS), ]; pub fn draw_egui<'a>( ui: &mut Ui, config: &mut Config, camera: &mut Camera, diagnostics: &Diagnostics, input: &Input, sim: &SimManager, ) { puffin::profile_function!(); ui.heading("Config"); ui.add(egui::Slider::new(&mut config.brush_radius, 1.0..=100.0).text("Brush radius")); let material = config.brush_material.def(); // material combobox egui::ComboBox::from_label("Select a brush material") .selected_text(format!( "Material: [{}, d={}]", material.name, material.density, )) .icon(move |ui, rect, _, _| { ui.painter().add(egui::Shape::Circle(CircleShape { center: rect.center(), radius: rect.height() / 2.0, stroke: Stroke::NONE, fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2), })); }) .show_ui(ui, |ui| { for material_id in MaterialId::ALL { ui.selectable_value( &mut config.brush_material, material_id, material_id.def().name, ); } }); let dropper_material = config.dropper_material.def(); egui::ComboBox::from_label("Select a dropper material") .selected_text(format!( "Material: [{}, d={}]", dropper_material.name, dropper_material.density, )) .icon(move |ui, rect, _, _| { ui.painter().add(egui::Shape::Circle(CircleShape { center: rect.center(), radius: rect.height() / 2.0, stroke: Stroke::NONE, fill: Color32::from_rgb( dropper_material.color.0, dropper_material.color.1, dropper_material.color.2, ), })); }) .show_ui(ui, |ui| { for material_id in MaterialId::ALL { ui.selectable_value( &mut config.dropper_material, material_id, material_id.def().name, ); } }); ui.checkbox(&mut config.use_threading, "Use multithreading"); ui.checkbox(&mut config.cells_render, "Draw cells"); ui.checkbox(&mut config.debug_render, "Draw physics debug lines"); if config.debug_render { ui.indent("debug_render_modes", |ui| { for (name, flag) in DEBUG_RENDER_MODES { let mut enabled = config.debug_render_mode.contains(flag); if ui.checkbox(&mut enabled, name).changed() { config.debug_render_mode.set(flag, enabled); } } }); } ui.label(format!("Real FPS: {}", diagnostics.fps)); ui.heading("Camera"); ui.add(egui::Slider::new(&mut camera.zoom, 0.0..=10.0).text("Zoom")); ui.heading("Input"); input .last_mouse_world_pos .map(|p| ui.label(format!("Mouse (world): x,y=({x}, {y})", x = p.0, y = p.1,))); if let Some(p) = input.last_mouse_chunk_pos { ui.label(format!("Mouse (chunk): x,y=({x}, {y})", x = p.0, y = p.1,)); if let Some(&chunk) = sim.cell_manager.chunk_position_to_chunk_idx.get(&p) { ui.label(format!( "Sleeping={}", sim.cell_manager.chunks[chunk].sleeping )); } } input .last_mouse_local_pos .map(|p| ui.label(format!("Mouse (local): x,y=({x}, {y})", x = p.0, y = p.1,))); if let Some((x, y)) = input.last_mouse_world_pos { ui.heading("Entity"); if let Some(cell) = sim .cell_manager .get_cell_from_game_position(x.round() as i32, y.round() as i32) { let material = cell.material.def(); let cell_label = ui.label( egui::RichText::new(format!("Cell: {}", material.name)).color(Color32::LIGHT_BLUE), ); ui.painter().add(egui::Shape::Circle(CircleShape { center: cell_label.rect.right_center() + egui::vec2(10.0, 0.0), radius: cell_label.rect.height() / 2.5, stroke: Stroke::NONE, fill: Color32::from_rgb(material.color.0, material.color.1, material.color.2), })); ui.label( egui::RichText::new(format!("Flags: {:b}", cell.flags)).color(Color32::YELLOW), ); } } }