editor update
This commit is contained in:
@@ -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<EntityHandle>,
|
||||
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()
|
||||
{
|
||||
|
||||
@@ -15,6 +15,7 @@ pub struct EditorState
|
||||
pub active: bool,
|
||||
pub right_mouse_held: bool,
|
||||
pub selected_entity: Option<EntityHandle>,
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user