Add debug mode toggle & move some debug elements around

main
Elijah Voigt 3 months ago
parent 2a1d7fe8c2
commit 4f1c634ed2

@ -120,50 +120,58 @@ struct MonologuePreview;
/// Panel for selecting which monologue tree to spawn /// Panel for selecting which monologue tree to spawn
fn init_debug_ui(mut commands: Commands) { fn init_debug_ui(mut commands: Commands) {
let mut monologue_button = None;
commands commands
.spawn(( .spawn((
Name::new("Tree Planter"),
children![
Text::new("+Tree"),
],
Node { Node {
top: Val::Px(0.0), top: Val::Px(0.0),
left: Val::Px(0.0), left: Val::Px(0.0),
min_width: Val::Px(25.0), flex_direction: FlexDirection::Row,
min_height: Val::Px(25.0),
..default() ..default()
}, },
DebuggingState::On, DebuggingState::On,
MonologuesContainer,
Button,
)) ))
.observe(spawn_tree); .with_children(|parent| {
monologue_button = Some(
parent
.spawn((
Name::new("Monologue Assignment Menu"),
children![Text::new("+Monologue"),],
Button,
Node {
min_width: Val::Px(25.0),
min_height: Val::Px(25.0),
..default()
},
DebuggingState::On,
MonologuesContainer,
))
.id(),
);
parent
.spawn((
Name::new("Tree Planter"),
children![Text::new("+Tree"),],
Node {
min_width: Val::Px(25.0),
min_height: Val::Px(25.0),
..default()
},
DebuggingState::On,
MonologuesContainer,
Button,
))
.observe(spawn_tree);
});
let monologue_button = commands
.spawn((
Name::new("Monologue Assignment Menu"),
children![
Text::new("+Monologue"),
],
Node {
top: Val::Px(25.0),
left: Val::Px(0.0),
min_width: Val::Px(25.0),
min_height: Val::Px(25.0),
..default()
},
DebuggingState::On,
MonologuesContainer,
))
.id();
commands commands
.spawn(( .spawn((
NavParent(monologue_button), NavParent(monologue_button.unwrap()),
NavState::default(), NavState::default(),
Name::new("Container"), Name::new("Container"),
Node { Node {
flex_direction: FlexDirection::Row, flex_direction: FlexDirection::Row,
top: Val::Px(50.0), top: Val::Px(25.0),
height: Val::Percent(90.0), height: Val::Percent(90.0),
width: Val::Percent(80.0), width: Val::Percent(80.0),
..default() ..default()
@ -188,7 +196,7 @@ fn init_debug_ui(mut commands: Commands) {
parent.spawn(( parent.spawn((
Name::new("Preview"), Name::new("Preview"),
MonologuePreview, MonologuePreview,
NavParent(monologue_button), NavParent(monologue_button.unwrap()),
NavState::default(), NavState::default(),
Node { Node {
flex_direction: FlexDirection::Column, flex_direction: FlexDirection::Column,
@ -280,9 +288,9 @@ fn start_dialog(
query: Query<&TreeMonologue, With<Tree>>, query: Query<&TreeMonologue, With<Tree>>,
) { ) {
click_events.read().for_each(|event| { click_events.read().for_each(|event| {
info!("Click event detected in start dialog systme"); debug!("Click event detected in start dialog systme");
if let Ok(TreeMonologue(handle)) = query.get(event.target) { if let Ok(TreeMonologue(handle)) = query.get(event.target) {
info!("Tree Monologue received, sending start dialog event"); debug!("Tree Monologue received, sending start dialog event");
dialog_events.write(DialogEvent::Start(event.target, handle.clone())); dialog_events.write(DialogEvent::Start(event.target, handle.clone()));
dialog_events.write(DialogEvent::NextBatch); dialog_events.write(DialogEvent::NextBatch);
} }

@ -67,19 +67,6 @@ pub enum DebuggingState {
/// Create the Debugging UI /// Create the Debugging UI
fn init_debug_ui(mut commands: Commands) { fn init_debug_ui(mut commands: Commands) {
// "Debugging On" Indicator
commands.spawn((
DebuggingState::On,
Name::new("Debug Indicator"),
GlobalZIndex(i32::MAX - 1),
children![Text(" Debug: ON ".into()),],
Node {
align_self: AlignSelf::Center,
justify_self: JustifySelf::End,
..default()
},
));
// Version string for troubleshooting // Version string for troubleshooting
commands.spawn(( commands.spawn((
DebuggingState::On, DebuggingState::On,
@ -94,37 +81,57 @@ fn init_debug_ui(mut commands: Commands) {
}, },
)); ));
// Version string for troubleshooting // "Turn on Debugging" button
commands commands
.spawn(( .spawn((
DebuggingState::On,
Name::new("FPS"),
GlobalZIndex(i32::MAX - 1),
Node { Node {
width: Val::Auto,
align_self: AlignSelf::Start, align_self: AlignSelf::Start,
justify_self: JustifySelf::End, justify_self: JustifySelf::End,
flex_direction: FlexDirection::Column,
..default() ..default()
}, },
DebuggingState::Off,
Name::new("Debug Indicator"),
GlobalZIndex(i32::MAX - 1),
children![Text("Debug: OFF".into()),],
Button,
)) ))
.with_children(|parent| { .observe(toggle_debug);
parent.spawn((Text::new("FPS: ##.#"), SyncResource::<Fps>::default()));
});
commands commands
.spawn(( .spawn((
DebuggingState::On, DebuggingState::On,
Name::new("Entity Count"),
GlobalZIndex(i32::MAX - 1),
Node { Node {
width: Val::Auto,
align_self: AlignSelf::Start, align_self: AlignSelf::Start,
justify_self: JustifySelf::Center, justify_self: JustifySelf::End,
flex_direction: FlexDirection::Column,
..default() ..default()
}, },
)) ))
.with_children(|parent| { .with_children(|parent| {
parent
.spawn((
// Debug is active & button to toggle
DebuggingState::On,
Name::new("Debug Indicator"),
GlobalZIndex(i32::MAX - 1),
children![Text("Debug: ON".into()),],
Button,
))
.observe(toggle_debug);
parent.spawn(( parent.spawn((
// FPS Counter for troubleshooting
DebuggingState::On,
Name::new("FPS"),
GlobalZIndex(i32::MAX - 1),
Text::new("FPS: ##.#"),
SyncResource::<Fps>::default(),
));
parent.spawn((
// Entity count
DebuggingState::On,
Name::new("Entity Count"),
GlobalZIndex(i32::MAX - 1),
Text::new("Entities: ###"), Text::new("Entities: ###"),
SyncResource::<EntityCount>::default(), SyncResource::<EntityCount>::default(),
)); ));
@ -344,3 +351,15 @@ impl Display for EntityCount {
fn track_entity_count(query: Query<Entity>, mut count: ResMut<EntityCount>) { fn track_entity_count(query: Query<Entity>, mut count: ResMut<EntityCount>) {
count.0 = query.iter().len(); count.0 = query.iter().len();
} }
/// Toggle the debug state when a button is clicked
fn toggle_debug(
_trigger: Trigger<Pointer<Click>>,
curr: Res<State<DebuggingState>>,
mut next: ResMut<NextState<DebuggingState>>,
) {
next.set(match curr.get() {
DebuggingState::On => DebuggingState::Off,
DebuggingState::Off => DebuggingState::On,
});
}

Loading…
Cancel
Save