2025-08-24 09:42:18 -04:00
|
|
|
//bevy system signatures often violate these rules
|
|
|
|
|
#![allow(clippy::type_complexity)]
|
|
|
|
|
#![allow(clippy::too_many_arguments)]
|
|
|
|
|
|
|
|
|
|
use bevy::prelude::*;
|
2025-08-31 12:08:44 -04:00
|
|
|
use bevy_egui::{
|
|
|
|
|
EguiContexts, EguiPrimaryContextPass,
|
|
|
|
|
egui::{self, Align2, RichText},
|
|
|
|
|
};
|
|
|
|
|
use input::{Cancellable, actions::InputAction, conditions::action_just_pressed};
|
2025-08-30 23:39:18 -04:00
|
|
|
use state::GameState;
|
2025-08-24 09:42:18 -04:00
|
|
|
|
|
|
|
|
pub struct UiPausePlugin;
|
|
|
|
|
|
|
|
|
|
impl Plugin for UiPausePlugin {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
app.add_systems(
|
|
|
|
|
Update,
|
2025-08-30 23:39:18 -04:00
|
|
|
toggle_pause.run_if(action_just_pressed::<Update>(InputAction::TogglePause)),
|
2025-08-31 12:08:44 -04:00
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
EguiPrimaryContextPass,
|
|
|
|
|
pause_screen.run_if(in_state(GameState::Paused)),
|
2025-08-24 09:42:18 -04:00
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-08-31 12:08:44 -04:00
|
|
|
fn pause_screen(mut contexts: EguiContexts) {
|
|
|
|
|
let ctx = contexts.ctx_mut().unwrap();
|
|
|
|
|
egui::Window::new("Pause")
|
|
|
|
|
.resizable(false)
|
|
|
|
|
.collapsible(false)
|
|
|
|
|
.title_bar(false)
|
|
|
|
|
.anchor(Align2::CENTER_CENTER, [0., 0.])
|
|
|
|
|
.show(ctx, |ui| {
|
|
|
|
|
ui.label(RichText::new(format!("Paused")).size(64.));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn toggle_pause(
|
|
|
|
|
state: Res<State<GameState>>,
|
|
|
|
|
mut next_state: ResMut<NextState<GameState>>,
|
|
|
|
|
query: Query<(), With<Cancellable>>,
|
|
|
|
|
) {
|
|
|
|
|
if !query.is_empty() {
|
|
|
|
|
// cancelling takes priority over pausing
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-08-24 09:42:18 -04:00
|
|
|
let next = match state.get() {
|
|
|
|
|
GameState::Loading => GameState::Loading,
|
|
|
|
|
GameState::Running => GameState::Paused,
|
|
|
|
|
GameState::Paused => GameState::Running,
|
|
|
|
|
};
|
|
|
|
|
info!("toggle pause, changing to {:?}", next);
|
|
|
|
|
next_state.set(next);
|
|
|
|
|
}
|