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
fn init_debug_ui(mut commands: Commands) {
let mut monologue_button = None;
commands
.spawn((
Name::new("Tree Planter"),
children![
Text::new("+Tree"),
],
Node {
top: Val::Px(0.0),
left: Val::Px(0.0),
min_width: Val::Px(25.0),
min_height: Val::Px(25.0),
flex_direction: FlexDirection::Row,
..default()
},
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
.spawn((
NavParent(monologue_button),
NavParent(monologue_button.unwrap()),
NavState::default(),
Name::new("Container"),
Node {
flex_direction: FlexDirection::Row,
top: Val::Px(50.0),
top: Val::Px(25.0),
height: Val::Percent(90.0),
width: Val::Percent(80.0),
..default()
@ -188,7 +196,7 @@ fn init_debug_ui(mut commands: Commands) {
parent.spawn((
Name::new("Preview"),
MonologuePreview,
NavParent(monologue_button),
NavParent(monologue_button.unwrap()),
NavState::default(),
Node {
flex_direction: FlexDirection::Column,
@ -280,9 +288,9 @@ fn start_dialog(
query: Query<&TreeMonologue, With<Tree>>,
) {
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) {
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::NextBatch);
}

@ -67,19 +67,6 @@ pub enum DebuggingState {
/// Create the Debugging UI
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
commands.spawn((
DebuggingState::On,
@ -94,37 +81,57 @@ fn init_debug_ui(mut commands: Commands) {
},
));
// Version string for troubleshooting
// "Turn on Debugging" button
commands
.spawn((
DebuggingState::On,
Name::new("FPS"),
GlobalZIndex(i32::MAX - 1),
Node {
width: Val::Auto,
align_self: AlignSelf::Start,
justify_self: JustifySelf::End,
flex_direction: FlexDirection::Column,
..default()
},
DebuggingState::Off,
Name::new("Debug Indicator"),
GlobalZIndex(i32::MAX - 1),
children![Text("Debug: OFF".into()),],
Button,
))
.with_children(|parent| {
parent.spawn((Text::new("FPS: ##.#"), SyncResource::<Fps>::default()));
});
.observe(toggle_debug);
commands
.spawn((
DebuggingState::On,
Name::new("Entity Count"),
GlobalZIndex(i32::MAX - 1),
Node {
width: Val::Auto,
align_self: AlignSelf::Start,
justify_self: JustifySelf::Center,
justify_self: JustifySelf::End,
flex_direction: FlexDirection::Column,
..default()
},
))
.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((
// 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: ###"),
SyncResource::<EntityCount>::default(),
));
@ -344,3 +351,15 @@ impl Display for EntityCount {
fn track_entity_count(query: Query<Entity>, mut count: ResMut<EntityCount>) {
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