diff --git a/src/bin/trees/main.rs b/src/bin/trees/main.rs index a13b3a8..b5a6c33 100644 --- a/src/bin/trees/main.rs +++ b/src/bin/trees/main.rs @@ -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>, ) { 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); } diff --git a/src/debug.rs b/src/debug.rs index 399b05a..d60e05c 100644 --- a/src/debug.rs +++ b/src/debug.rs @@ -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::::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::::default(), + )); + parent.spawn(( + // Entity count + DebuggingState::On, + Name::new("Entity Count"), + GlobalZIndex(i32::MAX - 1), Text::new("Entities: ###"), SyncResource::::default(), )); @@ -344,3 +351,15 @@ impl Display for EntityCount { fn track_entity_count(query: Query, mut count: ResMut) { count.0 = query.iter().len(); } + +/// Toggle the debug state when a button is clicked +fn toggle_debug( + _trigger: Trigger>, + curr: Res>, + mut next: ResMut>, +) { + next.set(match curr.get() { + DebuggingState::On => DebuggingState::Off, + DebuggingState::Off => DebuggingState::On, + }); +}