|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
use bevy::app::AppExit;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
|
|
|
|
use self::tutorial::TutorialState;
|
|
|
|
use self::tutorial::TutorialState;
|
|
|
|
@ -19,8 +21,9 @@ impl Plugin for MenuPlugin {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
Update,
|
|
|
|
Update,
|
|
|
|
set_menu_state.run_if(just_pressed(KeyCode::Escape))
|
|
|
|
handle_button_press.run_if(any_component_changed::<Interaction>()),
|
|
|
|
);
|
|
|
|
)
|
|
|
|
|
|
|
|
.add_systems(Update, set_menu_state.run_if(just_pressed(KeyCode::Escape)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -65,16 +68,14 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
// Title
|
|
|
|
// Title
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
|
|
|
"M A R T I A N C H E S S",
|
|
|
|
"M A R T I A N C H E S S",
|
|
|
|
TextStyle {
|
|
|
|
TextStyle {
|
|
|
|
font_size: 48.0,
|
|
|
|
font_size: 48.0,
|
|
|
|
color: Color::ORANGE_RED,
|
|
|
|
color: Color::ORANGE_RED,
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),));
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Continue button
|
|
|
|
// Continue button
|
|
|
|
parent
|
|
|
|
parent
|
|
|
|
@ -91,16 +92,14 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
|
|
|
"Continue",
|
|
|
|
"Continue",
|
|
|
|
TextStyle {
|
|
|
|
TextStyle {
|
|
|
|
color: Color::BLACK,
|
|
|
|
color: Color::BLACK,
|
|
|
|
font_size: 32.0,
|
|
|
|
font_size: 32.0,
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),));
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Tutorial button
|
|
|
|
// Tutorial button
|
|
|
|
@ -118,16 +117,14 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
|
|
|
"Tutorial",
|
|
|
|
"Tutorial",
|
|
|
|
TextStyle {
|
|
|
|
TextStyle {
|
|
|
|
color: Color::BLACK,
|
|
|
|
color: Color::BLACK,
|
|
|
|
font_size: 32.0,
|
|
|
|
font_size: 32.0,
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),));
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Credits button
|
|
|
|
// Credits button
|
|
|
|
@ -145,16 +142,14 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
|
|
|
"Credits",
|
|
|
|
"Credits",
|
|
|
|
TextStyle {
|
|
|
|
TextStyle {
|
|
|
|
color: Color::BLACK,
|
|
|
|
color: Color::BLACK,
|
|
|
|
font_size: 32.0,
|
|
|
|
font_size: 32.0,
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),));
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Quit button
|
|
|
|
// Quit button
|
|
|
|
@ -169,7 +164,8 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},))
|
|
|
|
},
|
|
|
|
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
"Quit",
|
|
|
|
"Quit",
|
|
|
|
@ -218,16 +214,14 @@ fn init_tutorial_menu(mut commands: Commands) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
|
|
|
"Continue Game",
|
|
|
|
"Continue Game",
|
|
|
|
TextStyle {
|
|
|
|
TextStyle {
|
|
|
|
color: Color::BLACK,
|
|
|
|
color: Color::BLACK,
|
|
|
|
font_size: 32.0,
|
|
|
|
font_size: 32.0,
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),));
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Quit button
|
|
|
|
// Quit button
|
|
|
|
@ -242,7 +236,8 @@ fn init_tutorial_menu(mut commands: Commands) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},))
|
|
|
|
},
|
|
|
|
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
"Restart",
|
|
|
|
"Restart",
|
|
|
|
@ -291,16 +286,14 @@ fn init_endgame_menu(mut commands: Commands) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
|
|
|
"New Game",
|
|
|
|
"New Game",
|
|
|
|
TextStyle {
|
|
|
|
TextStyle {
|
|
|
|
color: Color::BLACK,
|
|
|
|
color: Color::BLACK,
|
|
|
|
font_size: 32.0,
|
|
|
|
font_size: 32.0,
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),));
|
|
|
|
));
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// Quit button
|
|
|
|
// Quit button
|
|
|
|
@ -315,7 +308,8 @@ fn init_endgame_menu(mut commands: Commands) {
|
|
|
|
},
|
|
|
|
},
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},))
|
|
|
|
},
|
|
|
|
|
|
|
|
))
|
|
|
|
.with_children(|parent| {
|
|
|
|
.with_children(|parent| {
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
"Quit",
|
|
|
|
"Quit",
|
|
|
|
@ -329,7 +323,6 @@ fn init_endgame_menu(mut commands: Commands) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn set_menu_state(
|
|
|
|
fn set_menu_state(
|
|
|
|
game_state: Res<State<GameState>>,
|
|
|
|
game_state: Res<State<GameState>>,
|
|
|
|
mut next_menu_state: ResMut<NextState<MenuState>>,
|
|
|
|
mut next_menu_state: ResMut<NextState<MenuState>>,
|
|
|
|
@ -339,6 +332,27 @@ fn set_menu_state(
|
|
|
|
GameState::Play => next_menu_state.set(MenuState::Play),
|
|
|
|
GameState::Play => next_menu_state.set(MenuState::Play),
|
|
|
|
GameState::Endgame => next_menu_state.set(MenuState::Endgame),
|
|
|
|
GameState::Endgame => next_menu_state.set(MenuState::Endgame),
|
|
|
|
GameState::Intro => error!("Should skip to GameState::Play"),
|
|
|
|
GameState::Intro => error!("Should skip to GameState::Play"),
|
|
|
|
GameState::Credits => error!("Should pop back to GameState::Play")
|
|
|
|
GameState::Credits => error!("Should pop back to GameState::Play"),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_button_press(
|
|
|
|
|
|
|
|
events: Query<(&Interaction, &ButtonAction), Changed<Interaction>>,
|
|
|
|
|
|
|
|
mut next_game_state: ResMut<NextState<GameState>>,
|
|
|
|
|
|
|
|
mut next_tutorial_state: ResMut<NextState<TutorialState>>,
|
|
|
|
|
|
|
|
mut next_menu_state: ResMut<NextState<MenuState>>,
|
|
|
|
|
|
|
|
mut app_exit_events: EventWriter<AppExit>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
events
|
|
|
|
|
|
|
|
.iter()
|
|
|
|
|
|
|
|
.filter_map(|(interaction, button_action)| {
|
|
|
|
|
|
|
|
(*interaction == Interaction::Pressed).then_some(button_action)
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.for_each(|button_action| match button_action {
|
|
|
|
|
|
|
|
ButtonAction::GameState(gs) => next_game_state.set(gs.clone()),
|
|
|
|
|
|
|
|
ButtonAction::MenuState(ms) => next_menu_state.set(ms.clone()),
|
|
|
|
|
|
|
|
ButtonAction::TutorialState(ts) => next_tutorial_state.set(ts.clone()),
|
|
|
|
|
|
|
|
ButtonAction::Quit => app_exit_events.send(AppExit),
|
|
|
|
|
|
|
|
ButtonAction::Restart => panic!("TODO: Restart game!"),
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|