use bevy::prelude::*;
use bevy::text::Justify;
use crate::pause::PauseState;
#[derive(Component, Debug)]
pub struct PauseOverlay;
pub fn spawn_pause_overlay(
mut commands: Commands,
pause_state: Res<PauseState>,
overlay_query: Query<(), With<PauseOverlay>>,
) {
if matches!(*pause_state, PauseState::Paused { .. }) && overlay_query.is_empty() {
commands.spawn((
Text::new("PAUSED\nClick to Resume"),
TextFont {
font_size: 60.0,
..default()
},
TextColor(Color::WHITE),
TextLayout::new_with_justify(Justify::Center),
Node {
position_type: PositionType::Absolute,
width: Val::Percent(100.0),
height: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
PauseOverlay,
));
}
}
pub fn despawn_pause_overlay(
mut commands: Commands,
pause_state: Res<PauseState>,
overlay_query: Query<Entity, With<PauseOverlay>>,
) {
if matches!(*pause_state, PauseState::Active) {
for entity in overlay_query.iter() {
commands.entity(entity).despawn();
}
}
}