|
|
|
|
@ -34,10 +34,8 @@ impl Plugin for MenuPlugin {
|
|
|
|
|
#[derive(Debug, States, Hash, Default, PartialEq, Eq, Clone, Component)]
|
|
|
|
|
pub(crate) enum MenuState {
|
|
|
|
|
#[default]
|
|
|
|
|
None,
|
|
|
|
|
Play,
|
|
|
|
|
Tutorial,
|
|
|
|
|
Endgame,
|
|
|
|
|
Off,
|
|
|
|
|
On,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
@ -48,7 +46,7 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
MenuState::Play,
|
|
|
|
|
MenuState::On,
|
|
|
|
|
NodeBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
width: Val::Percent(100.0),
|
|
|
|
|
@ -79,7 +77,7 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonAction(GameState::Play),
|
|
|
|
|
ButtonAction(MenuState::None),
|
|
|
|
|
ButtonAction(MenuState::Off),
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
@ -105,7 +103,7 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonAction(tutorial::TutorialState::Intro),
|
|
|
|
|
ButtonAction(MenuState::None),
|
|
|
|
|
ButtonAction(MenuState::Off),
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
@ -131,7 +129,7 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonAction(GameState::Credits),
|
|
|
|
|
ButtonAction(MenuState::None),
|
|
|
|
|
ButtonAction(MenuState::Off),
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
@ -157,7 +155,7 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonAction(GameState::Quit),
|
|
|
|
|
ButtonAction(MenuState::None),
|
|
|
|
|
ButtonAction(MenuState::Off),
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
@ -184,6 +182,7 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
fn handle_escape(
|
|
|
|
|
game_state: Res<State<GameState>>,
|
|
|
|
|
tutorial_state: Res<State<TutorialState>>,
|
|
|
|
|
menu_state: Res<State<MenuState>>,
|
|
|
|
|
mut next_game_state: ResMut<NextState<GameState>>,
|
|
|
|
|
mut next_menu_state: ResMut<NextState<MenuState>>,
|
|
|
|
|
mut next_tutorial_state: ResMut<NextState<TutorialState>>,
|
|
|
|
|
@ -195,7 +194,12 @@ fn handle_escape(
|
|
|
|
|
match tutorial_state.get() {
|
|
|
|
|
// State(Tutorial::None): Escape -> Play Menu
|
|
|
|
|
TutorialState::None => {
|
|
|
|
|
next_menu_state.set(MenuState::Play);
|
|
|
|
|
match menu_state.get() {
|
|
|
|
|
// State(Menu::None): Escape -> Show Menu
|
|
|
|
|
MenuState::Off => next_menu_state.set(MenuState::On),
|
|
|
|
|
// State(Menu::Play): Escape -> Hide menu
|
|
|
|
|
MenuState::On => next_menu_state.set(MenuState::Off),
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// State(Tutorial::*): Escape -> Quit Tutorial
|
|
|
|
|
_ => {
|
|
|
|
|
@ -210,7 +214,7 @@ fn handle_escape(
|
|
|
|
|
// State(Credits): Escape -> Play + Menu
|
|
|
|
|
GameState::Credits => {
|
|
|
|
|
next_game_state.set(GameState::Play);
|
|
|
|
|
next_menu_state.set(MenuState::Play);
|
|
|
|
|
next_menu_state.set(MenuState::On);
|
|
|
|
|
}
|
|
|
|
|
// State(Intro): Escape -> Play
|
|
|
|
|
GameState::Intro => {
|
|
|
|
|
|