62 lines
1.7 KiB
Rust
62 lines
1.7 KiB
Rust
use crate::lobby::LobbyUiState;
|
|
use bevy::prelude::*;
|
|
use bevy_inspector_egui::{
|
|
bevy_egui::EguiPlugin,
|
|
quick::{ResourceInspectorPlugin, WorldInspectorPlugin},
|
|
};
|
|
|
|
// TODO: compile these in only if debug build
|
|
|
|
/// Whether the debug inspector is currently shown.
|
|
#[derive(Resource, Debug, Default)]
|
|
pub struct InspectorEnabled(bool);
|
|
|
|
pub struct DebugInspectorPlugin;
|
|
|
|
impl Plugin for DebugInspectorPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.init_resource::<InspectorEnabled>()
|
|
.add_plugins(EguiPlugin::default())
|
|
.add_plugins(WorldInspectorPlugin::new())
|
|
.add_plugins(
|
|
ResourceInspectorPlugin::<LobbyUiState>::new()
|
|
.run_if(|enabled: Res<InspectorEnabled>| enabled.0),
|
|
)
|
|
.add_systems(Update, (toggle_inspector, toggle_ui_layout_debug));
|
|
}
|
|
}
|
|
|
|
fn toggle_inspector(keys: Res<ButtonInput<KeyCode>>, mut enabled: ResMut<InspectorEnabled>) {
|
|
if !keys.just_pressed(KeyCode::F1) {
|
|
return;
|
|
}
|
|
|
|
enabled.0 = !enabled.0;
|
|
info!(
|
|
"lobby ui inspector toggled {}",
|
|
if enabled.0 { "on" } else { "off" }
|
|
);
|
|
}
|
|
|
|
fn toggle_ui_layout_debug(
|
|
keys: Res<ButtonInput<KeyCode>>,
|
|
mut debug_options: ResMut<GlobalUiDebugOptions>,
|
|
) {
|
|
if !keys.just_pressed(KeyCode::F2) {
|
|
return;
|
|
}
|
|
|
|
if debug_options.enabled {
|
|
debug_options.enabled = false;
|
|
} else {
|
|
debug_options.enabled = true;
|
|
debug_options.outline_border_box = true;
|
|
debug_options.outline_padding_box = true;
|
|
debug_options.outline_content_box = true;
|
|
}
|
|
info!(
|
|
"ui layout debug toggled {}",
|
|
if debug_options.enabled { "on" } else { "off" }
|
|
);
|
|
}
|