Skip to content

Commit

Permalink
feat: make debug UI appears on the left of the screen and closed by d…
Browse files Browse the repository at this point in the history
…efault
  • Loading branch information
AudranTourneur committed Jan 28, 2025
1 parent 2ad7e4e commit e871624
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
12 changes: 9 additions & 3 deletions client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,18 @@ use bevy::{
},
window::PresentMode,
};
use bevy_inspector_egui::quick::WorldInspectorPlugin;
use bevy_inspector_egui::{bevy_egui::EguiPlugin, DefaultInspectorConfigPlugin};
use clap::Parser;
use constants::{TEXTURE_PATH_BASE, TEXTURE_PATH_CUSTOM};
use input::{data::GameAction, keyboard::get_bindings};
use menus::solo::SelectedWorld;
use serde::{Deserialize, Serialize};
use shared::{GameFolderPaths, SpecialFlag};
use std::collections::BTreeMap;
use ui::menus::{self, splash};
use ui::{
hud::debug::inspector::inspector_ui,
menus::{self, splash},
};

#[derive(Parser, Debug)]
#[command(version, about, long_about = None)]
Expand Down Expand Up @@ -158,7 +161,10 @@ fn main() {
..default()
}),
);
app.add_plugins(WorldInspectorPlugin::new());

app.add_plugins(EguiPlugin)
.add_plugins(DefaultInspectorConfigPlugin)
.add_systems(Update, inspector_ui);

app.add_event::<LoadWorldEvent>();
network::add_base_netcode(&mut app);
Expand Down
38 changes: 38 additions & 0 deletions client/src/ui/hud/debug/inspector.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
use bevy::{prelude::*, window::PrimaryWindow};
use bevy_inspector_egui::bevy_egui::EguiContext;

pub fn inspector_ui(world: &mut World) {
let Ok(egui_context) = world
.query_filtered::<&mut EguiContext, With<PrimaryWindow>>()
.get_single(world)
else {
return;
};
let mut egui_context = egui_context.clone();

let window = world.query::<&Window>().get_single(world).unwrap();
let width = window.width();

info!("Inspector UI width: {}", width);

let time = world.get_resource::<Time>().unwrap();

let mut res = egui::Window::new("Debug UI").default_open(false);

// This is kinda ridiculous, but it's the only way I found to make the window properly appears at the left side of the screen
// Using .default_pos(w, h) doesn't fully work for some reason on a dual-monitor setup
// A better way might be to resize this proportionally to the window width on window resize
if time.elapsed_secs() < 1.0 {
res = res.current_pos((width - 200.0, 0.0));
}

res.show(egui_context.get_mut(), |ui| {
egui::ScrollArea::vertical().show(ui, |ui| {
bevy_inspector_egui::bevy_inspector::ui_for_world(world, ui);

egui::CollapsingHeader::new("Materials").show(ui, |ui| {
bevy_inspector_egui::bevy_inspector::ui_for_assets::<StandardMaterial>(world, ui);
});
});
});
}
1 change: 1 addition & 0 deletions client/src/ui/hud/debug/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub mod blocks;
pub mod chunks;
pub mod coords;
pub mod fps;
pub mod inspector;
mod loaded_stats;
pub mod setup;
pub mod targeted_block;
Expand Down

0 comments on commit e871624

Please sign in to comment.