|
|
|
|
@ -1,7 +1,7 @@
|
|
|
|
|
use bevy::ecs::system::EntityCommands;
|
|
|
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
|
|
use self::tutorial::TutorialState;
|
|
|
|
|
|
|
|
|
|
pub(crate) struct MenuPlugin;
|
|
|
|
|
|
|
|
|
|
impl Plugin for MenuPlugin {
|
|
|
|
|
@ -16,6 +16,10 @@ impl Plugin for MenuPlugin {
|
|
|
|
|
.add_systems(
|
|
|
|
|
Update,
|
|
|
|
|
manage_state_entities::<MenuState>().run_if(state_changed::<MenuState>()),
|
|
|
|
|
)
|
|
|
|
|
.add_systems(
|
|
|
|
|
Update,
|
|
|
|
|
set_menu_state.run_if(just_pressed(KeyCode::Escape))
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -29,6 +33,15 @@ enum MenuState {
|
|
|
|
|
Endgame,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
|
enum ButtonAction {
|
|
|
|
|
GameState(GameState),
|
|
|
|
|
MenuState(MenuState),
|
|
|
|
|
TutorialState(tutorial::TutorialState),
|
|
|
|
|
Restart,
|
|
|
|
|
Quit,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
info!("Initializing Play menu");
|
|
|
|
|
|
|
|
|
|
@ -51,8 +64,8 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
},
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
// Title
|
|
|
|
|
parent.spawn((
|
|
|
|
|
MenuState::Play,
|
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
"M A R T I A N C H E S S",
|
|
|
|
|
TextStyle {
|
|
|
|
|
@ -62,10 +75,11 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
|
|
|
|
|
// Continue button
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
GameState::Play,
|
|
|
|
|
MenuState::None,
|
|
|
|
|
ButtonAction::MenuState(MenuState::None),
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
@ -78,8 +92,6 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
GameState::Play,
|
|
|
|
|
MenuState::None,
|
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
"Continue",
|
|
|
|
|
TextStyle {
|
|
|
|
|
@ -91,10 +103,37 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Tutorial button
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonAction::TutorialState(tutorial::TutorialState::Intro),
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
margin: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
"Tutorial",
|
|
|
|
|
TextStyle {
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
font_size: 32.0,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Credits button
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
GameState::Credits,
|
|
|
|
|
MenuState::None,
|
|
|
|
|
ButtonAction::GameState(GameState::Credits),
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
@ -107,8 +146,6 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
GameState::Credits,
|
|
|
|
|
MenuState::None,
|
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
"Credits",
|
|
|
|
|
TextStyle {
|
|
|
|
|
@ -120,8 +157,11 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Quit button
|
|
|
|
|
parent
|
|
|
|
|
.spawn((ButtonBundle {
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonAction::Quit,
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
margin: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
@ -140,32 +180,75 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
},
|
|
|
|
|
),));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn init_tutorial_menu(mut commands: Commands) {
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
MenuState::Tutorial,
|
|
|
|
|
NodeBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
width: Val::Percent(100.0),
|
|
|
|
|
height: Val::Percent(100.0),
|
|
|
|
|
justify_content: JustifyContent::Center,
|
|
|
|
|
align_items: AlignItems::Center,
|
|
|
|
|
flex_direction: FlexDirection::Column,
|
|
|
|
|
position_type: PositionType::Absolute,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: Color::NONE.into(),
|
|
|
|
|
visibility: Visibility::Hidden,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
// Continue button
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
tutorial::TutorialState::Intro, // Marks the button to start the tutorial
|
|
|
|
|
GameState::Play, // Marks the button to be ignored during tutorial step cleanup
|
|
|
|
|
MenuState::None,
|
|
|
|
|
ButtonAction::MenuState(MenuState::None),
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
margin: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
position_type: PositionType::Absolute,
|
|
|
|
|
top: Val::Px(0.0),
|
|
|
|
|
right: Val::Px(0.0),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
|
visibility: Visibility::Hidden,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
"Continue Game",
|
|
|
|
|
TextStyle {
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
font_size: 32.0,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Quit button
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonAction::Restart,
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
margin: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
|
..default()
|
|
|
|
|
},))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
|
"Tutorial",
|
|
|
|
|
"Restart",
|
|
|
|
|
TextStyle {
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
font_size: 16.0,
|
|
|
|
|
font_size: 32.0,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
),));
|
|
|
|
|
@ -173,10 +256,89 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn init_tutorial_menu(mut commands: Commands) {
|
|
|
|
|
error!("Tutorial Menu");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn init_endgame_menu(mut commands: Commands) {
|
|
|
|
|
error!("Endgame Menu");
|
|
|
|
|
commands
|
|
|
|
|
.spawn((
|
|
|
|
|
MenuState::Endgame,
|
|
|
|
|
NodeBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
width: Val::Percent(100.0),
|
|
|
|
|
height: Val::Percent(100.0),
|
|
|
|
|
justify_content: JustifyContent::Center,
|
|
|
|
|
align_items: AlignItems::Center,
|
|
|
|
|
flex_direction: FlexDirection::Column,
|
|
|
|
|
position_type: PositionType::Absolute,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: Color::NONE.into(),
|
|
|
|
|
visibility: Visibility::Hidden,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
// Continue button
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonAction::Restart,
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
margin: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
parent.spawn((
|
|
|
|
|
TextBundle::from_section(
|
|
|
|
|
"New Game",
|
|
|
|
|
TextStyle {
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
font_size: 32.0,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Quit button
|
|
|
|
|
parent
|
|
|
|
|
.spawn((
|
|
|
|
|
ButtonAction::Quit,
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
margin: UiRect::all(Val::Px(5.0)),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
background_color: Color::ORANGE.with_a(0.5).into(),
|
|
|
|
|
..default()
|
|
|
|
|
},))
|
|
|
|
|
.with_children(|parent| {
|
|
|
|
|
parent.spawn((TextBundle::from_section(
|
|
|
|
|
"Quit",
|
|
|
|
|
TextStyle {
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
font_size: 32.0,
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
),));
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn set_menu_state(
|
|
|
|
|
game_state: Res<State<GameState>>,
|
|
|
|
|
mut next_menu_state: ResMut<NextState<MenuState>>,
|
|
|
|
|
) {
|
|
|
|
|
match game_state.get() {
|
|
|
|
|
GameState::Loading => error!("No menu while loading!"),
|
|
|
|
|
GameState::Play => next_menu_state.set(MenuState::Play),
|
|
|
|
|
GameState::Endgame => next_menu_state.set(MenuState::Endgame),
|
|
|
|
|
GameState::Intro => error!("Should skip to GameState::Play"),
|
|
|
|
|
GameState::Credits => error!("Should pop back to GameState::Play")
|
|
|
|
|
}
|
|
|
|
|
}
|