|
|
|
@ -9,8 +9,9 @@ impl Plugin for MenuPlugin {
|
|
|
|
app.add_state::<MenuState>()
|
|
|
|
app.add_state::<MenuState>()
|
|
|
|
// Initialize menus
|
|
|
|
// Initialize menus
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
|
|
|
|
// TODO: move this to game.rs or display3d.rs
|
|
|
|
OnExit(GameState::Loading),
|
|
|
|
OnExit(GameState::Loading),
|
|
|
|
(init_play_menu, init_tutorial_menu, init_endgame_menu),
|
|
|
|
init_play_menu,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
// Manage visible/hidden states
|
|
|
|
// Manage visible/hidden states
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
@ -26,7 +27,7 @@ impl Plugin for MenuPlugin {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.run_if(any_component_changed::<Interaction>()),
|
|
|
|
.run_if(any_component_changed::<Interaction>()),
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.add_systems(Update, set_menu_state.run_if(just_pressed(KeyCode::Escape)));
|
|
|
|
.add_systems(Update, handle_escape.run_if(just_pressed(KeyCode::Escape)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -180,165 +181,44 @@ fn init_play_menu(mut commands: Commands) {
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
fn init_tutorial_menu(mut commands: Commands) {
|
|
|
|
fn handle_escape(
|
|
|
|
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((
|
|
|
|
|
|
|
|
ButtonAction(GameState::Play),
|
|
|
|
|
|
|
|
ButtonAction(MenuState::None),
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
|
|
|
"Continue Game",
|
|
|
|
|
|
|
|
TextStyle {
|
|
|
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
|
|
|
font_size: 32.0,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Quit button
|
|
|
|
|
|
|
|
parent
|
|
|
|
|
|
|
|
.spawn((
|
|
|
|
|
|
|
|
ButtonAction(GameState::Restart),
|
|
|
|
|
|
|
|
ButtonAction(MenuState::None),
|
|
|
|
|
|
|
|
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(
|
|
|
|
|
|
|
|
"Restart",
|
|
|
|
|
|
|
|
TextStyle {
|
|
|
|
|
|
|
|
color: Color::BLACK,
|
|
|
|
|
|
|
|
font_size: 32.0,
|
|
|
|
|
|
|
|
..default()
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
),));
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn init_endgame_menu(mut commands: Commands) {
|
|
|
|
|
|
|
|
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| {
|
|
|
|
|
|
|
|
// New Game button
|
|
|
|
|
|
|
|
parent
|
|
|
|
|
|
|
|
.spawn((
|
|
|
|
|
|
|
|
ButtonAction(GameState::Restart),
|
|
|
|
|
|
|
|
ButtonAction(MenuState::None),
|
|
|
|
|
|
|
|
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(MenuState::None),
|
|
|
|
|
|
|
|
ButtonAction(GameState::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>>,
|
|
|
|
game_state: Res<State<GameState>>,
|
|
|
|
|
|
|
|
tutorial_state: Res<State<TutorialState>>,
|
|
|
|
|
|
|
|
mut next_game_state: ResMut<NextState<GameState>>,
|
|
|
|
mut next_menu_state: ResMut<NextState<MenuState>>,
|
|
|
|
mut next_menu_state: ResMut<NextState<MenuState>>,
|
|
|
|
|
|
|
|
mut next_tutorial_state: ResMut<NextState<TutorialState>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
match game_state.get() {
|
|
|
|
match game_state.get() {
|
|
|
|
GameState::Loading => error!("No menu while loading!"),
|
|
|
|
GameState::Loading => error!("No menu while loading!"),
|
|
|
|
GameState::Play => next_menu_state.set(MenuState::Play),
|
|
|
|
// State(Play): ...
|
|
|
|
GameState::Endgame => next_menu_state.set(MenuState::Endgame),
|
|
|
|
GameState::Play => {
|
|
|
|
GameState::Intro => error!("Should skip to GameState::Play"),
|
|
|
|
match tutorial_state.get() {
|
|
|
|
GameState::Credits => error!("Should pop back to GameState::Play"),
|
|
|
|
// State(Tutorial::None): Escape -> Play Menu
|
|
|
|
GameState::Restart | GameState::Quit => panic!("This shouldn't be possible!"),
|
|
|
|
TutorialState::None => {
|
|
|
|
|
|
|
|
next_menu_state.set(MenuState::Play);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// State(Tutorial::*): Escape -> Quit Tutorial
|
|
|
|
|
|
|
|
_ => {
|
|
|
|
|
|
|
|
next_tutorial_state.set(TutorialState::None);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// State(Endgame): Escape -> Quit game
|
|
|
|
|
|
|
|
GameState::Endgame => {
|
|
|
|
|
|
|
|
next_game_state.set(GameState::Quit);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// State(Credits): Escape -> Play + Menu
|
|
|
|
|
|
|
|
GameState::Credits => {
|
|
|
|
|
|
|
|
next_game_state.set(GameState::Play);
|
|
|
|
|
|
|
|
next_menu_state.set(MenuState::Play);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// State(Intro): Escape -> Play
|
|
|
|
|
|
|
|
GameState::Intro => {
|
|
|
|
|
|
|
|
next_game_state.set(GameState::Play);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
GameState::Restart | GameState::Quit => {
|
|
|
|
|
|
|
|
panic!("This shouldn't be possible!");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|