From dd62c2970f063052cafeaf47201c59398bbca067 Mon Sep 17 00:00:00 2001 From: Mateusz Wachowiak Date: Mon, 11 Mar 2024 23:10:23 +0100 Subject: [PATCH] change visibility based on state of the dev tool --- crates/bevy_dev_tools/src/fps_overlay.rs | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/crates/bevy_dev_tools/src/fps_overlay.rs b/crates/bevy_dev_tools/src/fps_overlay.rs index 070df97e316c8..5b1e264b035a5 100644 --- a/crates/bevy_dev_tools/src/fps_overlay.rs +++ b/crates/bevy_dev_tools/src/fps_overlay.rs @@ -10,10 +10,11 @@ use bevy_ecs::{ schedule::{common_conditions::resource_changed, IntoSystemConfigs}, system::{Commands, Query, Res, Resource}, }; +use bevy_render::view::Visibility; use bevy_text::{Font, Text, TextSection, TextStyle}; use bevy_ui::node_bundles::TextBundle; -use crate::{DevTool, DevToolId, RegisterDevTool}; +use crate::{DevTool, DevToolId, DevToolsStore, RegisterDevTool}; /// A plugin that adds an FPS overlay to the Bevy application. /// @@ -47,7 +48,12 @@ impl Plugin for FpsOverlayPlugin { Update, ( customize_text.run_if(resource_changed::), - update_text, + change_visibility.run_if(resource_changed::), + update_text.run_if(|dev_tools: Res| { + dev_tools + .get(&Self::FPS_OVERLAY_ID) + .is_some_and(|dev_tool| dev_tool.is_enabled) + }), ), ); } @@ -105,3 +111,21 @@ fn customize_text( } } } + +fn change_visibility( + mut query: Query<&mut Visibility, With>, + dev_tools: Res, +) { + if dev_tools + .get(&FpsOverlayPlugin::FPS_OVERLAY_ID) + .is_some_and(|dev_tool| dev_tool.is_enabled) + { + for mut visibility in query.iter_mut() { + *visibility = Visibility::Visible; + } + } else { + for mut visibility in query.iter_mut() { + *visibility = Visibility::Hidden; + } + } +}