feat(sceen): add pause screen

This commit is contained in:
Kristofers Solo 2025-01-17 12:50:46 +02:00
parent c8e968e76e
commit e7bdb37093
3 changed files with 49 additions and 4 deletions

View File

@ -21,11 +21,10 @@ pub(super) fn plugin(app: &mut App) {
app.add_systems( app.add_systems(
Update, Update,
return_to_title_screen pause_game.run_if(in_state(Screen::Gameplay).and(input_just_pressed(KeyCode::Escape))),
.run_if(in_state(Screen::Gameplay).and(input_just_pressed(KeyCode::Escape))),
); );
} }
fn return_to_title_screen(mut next_screen: ResMut<NextState<Screen>>) { fn pause_game(mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Title); next_screen.set(Screen::Pause);
} }

View File

@ -2,6 +2,7 @@
mod gameplay; mod gameplay;
mod loading; mod loading;
mod pause;
mod splash; mod splash;
mod title; mod title;
@ -16,6 +17,7 @@ pub(super) fn plugin(app: &mut App) {
loading::plugin, loading::plugin,
splash::plugin, splash::plugin,
title::plugin, title::plugin,
pause::plugin,
)); ));
} }
@ -28,4 +30,5 @@ pub enum Screen {
Loading, Loading,
Title, Title,
Gameplay, Gameplay,
Pause,
} }

43
src/screens/pause.rs Normal file
View File

@ -0,0 +1,43 @@
use bevy::{input::common_conditions::input_just_pressed, prelude::*};
use crate::theme::{
events::OnPress,
widgets::{Containers, Widgets},
};
use super::Screen;
pub(super) fn plugin(app: &mut App) {
app.add_systems(OnEnter(Screen::Pause), spawn_title_screen);
app.add_systems(
Update,
return_to_game.run_if(in_state(Screen::Pause).and(input_just_pressed(KeyCode::Escape))),
);
}
fn spawn_title_screen(mut commands: Commands) {
commands
.ui_root()
.insert(StateScoped(Screen::Pause))
.with_children(|parent| {
parent.button("Continue").observe(return_to_game_trigger);
parent
.button("Exit")
.observe(return_to_title_screen_trigger);
});
}
fn return_to_game_trigger(_trigger: Trigger<OnPress>, mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Gameplay);
}
fn return_to_title_screen_trigger(
_trigger: Trigger<OnPress>,
mut next_screen: ResMut<NextState<Screen>>,
) {
next_screen.set(Screen::Title);
}
fn return_to_game(mut next_screen: ResMut<NextState<Screen>>) {
next_screen.set(Screen::Gameplay);
}