diff options
Diffstat (limited to 'src/renderer/ui.rs')
| -rw-r--r-- | src/renderer/ui.rs | 81 |
1 files changed, 44 insertions, 37 deletions
diff --git a/src/renderer/ui.rs b/src/renderer/ui.rs index a7395a0..46fb853 100644 --- a/src/renderer/ui.rs +++ b/src/renderer/ui.rs @@ -1,8 +1,9 @@ use egui::{Color32, Stroke, Ui, epaint::CircleShape}; use crate::{ - Camera, Config, Diagnostics, Input, + Camera, Config, Diagnostics, content::materials::MaterialId, + input::InputManager, sim::{rb_manager::DebugRenderMode, sim_manager::SimManager}, }; @@ -20,7 +21,7 @@ pub fn draw_egui<'a>( config: &mut Config, camera: &mut Camera, diagnostics: &Diagnostics, - input: &Input, + input_manager: &InputManager, sim: &SimManager, ) { puffin::profile_function!(); @@ -104,44 +105,50 @@ pub fn draw_egui<'a>( 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,))); + ui.label(format!( + "Mouse (world): x,y=({x}, {y})", + x = input_manager.world_mouse_pos.x, + y = input_manager.world_mouse_pos.y + )); - 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 - )); - } + ui.label(format!( + "Mouse (chunk): x,y=({x}, {y})", + x = input_manager.chunk_mouse_pos.x, + y = input_manager.chunk_mouse_pos.y + )); + + if let Some(&chunk) = sim.cell_manager.chunk_position_to_chunk_idx.get(&( + input_manager.chunk_mouse_pos.x, + input_manager.chunk_mouse_pos.y, + )) { + 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,))); + ui.label(format!( + "Mouse (local): x,y=({x}, {y})", + x = input_manager.local_mouse_pos.x, + y = input_manager.local_mouse_pos.y + )); - 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), - ); - ui.label(egui::RichText::new(format!("Data: {:b}", cell.data)).color(Color32::RED)); - } + ui.heading("Entity"); + if let Some(cell) = sim.cell_manager.get_cell_from_game_position( + input_manager.world_mouse_pos.x.round() as i32, + input_manager.world_mouse_pos.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)); + ui.label(egui::RichText::new(format!("Data: {:b}", cell.data)).color(Color32::RED)); } } |
