From 2c965c1237b6dc1c6b6e5843489c48ce9b3c2e01 Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Fri, 9 Aug 2024 15:39:31 -0700 Subject: [PATCH 1/2] Add debug UI toggle --- src/dev_tools.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/dev_tools.rs b/src/dev_tools.rs index d5814310..7f387dbb 100644 --- a/src/dev_tools.rs +++ b/src/dev_tools.rs @@ -1,10 +1,30 @@ //! Development tools for the game. This plugin is only enabled in dev builds. -use bevy::{dev_tools::states::log_transitions, prelude::*}; +use bevy::{ + dev_tools::{ + states::log_transitions, + ui_debug_overlay::{DebugUiPlugin, UiDebugOptions}, + }, + input::common_conditions::input_just_pressed, + prelude::*, +}; use crate::screens::Screen; pub(super) fn plugin(app: &mut App) { - // Print state transitions in dev builds + // Log `Screen` state transitions. app.add_systems(Update, log_transitions::); + + // Toggle the debug overlay for UI. + app.add_plugins(DebugUiPlugin); + app.add_systems( + Update, + toggle_debug_ui.run_if(input_just_pressed(TOGGLE_KEY)), + ); +} + +const TOGGLE_KEY: KeyCode = KeyCode::Backquote; + +fn toggle_debug_ui(mut options: ResMut) { + options.toggle(); } From 0fd894502347eb66413f808af6481cce6c25b9ec Mon Sep 17 00:00:00 2001 From: Ben Frankel Date: Fri, 9 Aug 2024 15:43:41 -0700 Subject: [PATCH 2/2] Mention toggle key in README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 4ef8689a..e318ef5d 100644 --- a/README.md +++ b/README.md @@ -52,7 +52,7 @@ This template comes with a basic project structure that you may find useful: | [`src/assets.rs`](./src/assets.rs) | Definition of assets that will be preloaded before the game starts | | [`src/audio/`](./src/audio) | Commands for playing SFX and music | | [`src/demo/`](./src/demo) | Example game mechanics & content (replace with your own code) | -| [`src/dev_tools.rs`](./src/dev_tools.rs) | Dev tools for dev builds | +| [`src/dev_tools.rs`](./src/dev_tools.rs) | Dev tools for dev builds (press \` aka backtick to toggle) | | [`src/screens/`](./src/screens) | Splash screen, title screen, playing screen, etc. | | [`src/theme/`](./src/theme) | Reusable UI widgets & theming |