mirror of
https://github.com/kristoferssolo/maze-ascension.git
synced 2025-10-21 19:20:34 +00:00
feat(sceen): add pause screen
This commit is contained in:
parent
c8e968e76e
commit
e7bdb37093
@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -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
43
src/screens/pause.rs
Normal 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);
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user