diff --git a/src/editor/inspector.rs b/src/editor/inspector.rs index 2341499..f42aa92 100644 --- a/src/editor/inspector.rs +++ b/src/editor/inspector.rs @@ -1,4 +1,4 @@ -use dear_imgui_rs::{Condition, Context}; +use dear_imgui_rs::{Condition, Context, WindowFlags}; use dear_imgui_wgpu::{WgpuInitInfo, WgpuRenderer}; use glam::EulerRot; use sdl3_sys::events::SDL_Event; @@ -61,16 +61,53 @@ impl Inspector self.imgui.io().want_capture_mouse() } + pub fn build_minimal_ui(&mut self, world: &World) + { + let ui = self.imgui.frame(); + let state_name = world + .player_tags + .all() + .first() + .and_then(|e| world.state_machines.get(*e)) + .map(|sm| sm.get_current_state_name()) + .unwrap_or("—"); + ui.window("Player State") + .position([10.0, 10.0], Condition::FirstUseEver) + .flags(WindowFlags::ALWAYS_AUTO_RESIZE) + .build(|| { + ui.text(format!("State: {}", state_name)); + }); + } + pub fn build_ui( &mut self, stats: &FrameStats, world: &World, selected_entity: Option, + show_player_state: bool, ) { let ui = self.imgui.frame(); + + if show_player_state + { + let state_name = world + .player_tags + .all() + .first() + .and_then(|e| world.state_machines.get(*e)) + .map(|sm| sm.get_current_state_name()) + .unwrap_or("—"); + ui.window("Player State") + .position([10.0, 10.0], Condition::FirstUseEver) + .flags(WindowFlags::ALWAYS_AUTO_RESIZE) + .build(|| { + ui.text(format!("State: {}", state_name)); + }); + } + ui.window("Inspector") - .position([10.0, 10.0], Condition::FirstUseEver) + .position([10.0, 40.0], Condition::FirstUseEver) .build(|| { ui.text(format!("FPS: {:.1}", stats.fps)); ui.text(format!("Frame: {:.1} ms", stats.frame_ms)); @@ -128,10 +165,7 @@ impl Inspector } if let Some(m) = world.movements.get(entity) { - ui.text(format!( - " Movement (max_speed {:.1})", - m.max_walking_speed - )); + ui.text(format!(" Movement (max_speed {:.1})", m.max_walking_speed)); } if world.jumps.get(entity).is_some() { diff --git a/src/editor/mod.rs b/src/editor/mod.rs index 5928389..a4518ba 100644 --- a/src/editor/mod.rs +++ b/src/editor/mod.rs @@ -15,6 +15,7 @@ pub struct EditorState pub active: bool, pub right_mouse_held: bool, pub selected_entity: Option, + pub show_player_state: bool, inspector: Inspector, } @@ -30,6 +31,7 @@ impl EditorState active: false, right_mouse_held: false, selected_entity: None, + show_player_state: false, inspector: Inspector::new(device, queue, surface_format), } } @@ -60,6 +62,11 @@ impl EditorState self.inspector.wants_mouse() } + pub fn build_hud(&mut self, world: &World) + { + self.inspector.build_minimal_ui(world); + } + pub fn render(&mut self, encoder: &mut wgpu::CommandEncoder, view: &wgpu::TextureView) { self.inspector.render(encoder, view); @@ -79,5 +86,8 @@ pub fn editor_loop( camera_noclip_system(world, input_state, delta); } let selected = editor.selected_entity; - editor.inspector.build_ui(stats, world, selected); + let show_player_state = editor.show_player_state; + editor + .inspector + .build_ui(stats, world, selected, show_player_state); }