Skip to content

Commit

Permalink
change visibility based on state of the dev tool
Browse files Browse the repository at this point in the history
  • Loading branch information
matiqo15 committed Mar 11, 2024
1 parent 2b5cef5 commit dd62c29
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions crates/bevy_dev_tools/src/fps_overlay.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
///
Expand Down Expand Up @@ -47,7 +48,12 @@ impl Plugin for FpsOverlayPlugin {
Update,
(
customize_text.run_if(resource_changed::<FpsOverlayConfig>),
update_text,
change_visibility.run_if(resource_changed::<DevToolsStore>),
update_text.run_if(|dev_tools: Res<DevToolsStore>| {
dev_tools
.get(&Self::FPS_OVERLAY_ID)
.is_some_and(|dev_tool| dev_tool.is_enabled)
}),
),
);
}
Expand Down Expand Up @@ -105,3 +111,21 @@ fn customize_text(
}
}
}

fn change_visibility(
mut query: Query<&mut Visibility, With<FpsText>>,
dev_tools: Res<DevToolsStore>,
) {
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;
}
}
}

0 comments on commit dd62c29

Please sign in to comment.