Finish main-menu button handling
All checks were successful
Basic checks / Basic build-and-test supertask (push) Successful in 7m8s
All checks were successful
Basic checks / Basic build-and-test supertask (push) Successful in 7m8s
This commit is contained in:
@@ -18,7 +18,7 @@ impl Plugin for PluginGameMenu {
|
|||||||
.add_systems(OnExit(GameState::TitleScreen), despawn::<MarkerMainMenu>)
|
.add_systems(OnExit(GameState::TitleScreen), despawn::<MarkerMainMenu>)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
handle_spacebar.run_if(in_state(GameState::TitleScreen)),
|
(handle_spacebar, operate_buttons).run_if(in_state(GameState::TitleScreen)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -38,7 +38,7 @@ impl Plugin for PluginGetReady {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Plugin for the game-over screen (TODO)
|
/// Plugin for the game-over screen
|
||||||
pub struct PluginGameOver;
|
pub struct PluginGameOver;
|
||||||
|
|
||||||
impl Plugin for PluginGameOver {
|
impl Plugin for PluginGameOver {
|
||||||
@@ -47,7 +47,7 @@ impl Plugin for PluginGameOver {
|
|||||||
.add_systems(OnExit(GameState::GameOver), despawn::<MarkerGameOver>)
|
.add_systems(OnExit(GameState::GameOver), despawn::<MarkerGameOver>)
|
||||||
.add_systems(
|
.add_systems(
|
||||||
Update,
|
Update,
|
||||||
operate_gameover_ui //.run_if(in_state(GameState::GameOver)),
|
operate_buttons.run_if(in_state(GameState::GameOver)),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,7 @@ struct MarkerGameOver;
|
|||||||
/// Attach this component to a button and [`PluginGameOver`] will use it to
|
/// Attach this component to a button and [`PluginGameOver`] will use it to
|
||||||
/// decide what to do when that button is pressed.
|
/// decide what to do when that button is pressed.
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
enum GameOverMenuAction {
|
enum ButtonMenuAction {
|
||||||
ToMainMenu,
|
ToMainMenu,
|
||||||
StartGame,
|
StartGame,
|
||||||
Quit,
|
Quit,
|
||||||
@@ -147,12 +147,8 @@ fn spawn_menu(mut commands: Commands) {
|
|||||||
TextColor(Color::srgb(0.7, 0.7, 0.7)),
|
TextColor(Color::srgb(0.7, 0.7, 0.7)),
|
||||||
TextShadow::default(),
|
TextShadow::default(),
|
||||||
));
|
));
|
||||||
cmds.spawn((
|
cmds.spawn((button_bundle("Start Game"), ButtonMenuAction::StartGame));
|
||||||
button_bundle("Start Game"), GameOverMenuAction::StartGame
|
cmds.spawn((button_bundle("Quit"), ButtonMenuAction::Quit));
|
||||||
));
|
|
||||||
cmds.spawn((
|
|
||||||
button_bundle("Quit"), GameOverMenuAction::Quit
|
|
||||||
));
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -205,8 +201,8 @@ fn spawn_gameover_ui(mut commands: Commands) {
|
|||||||
..default()
|
..default()
|
||||||
},
|
},
|
||||||
children![
|
children![
|
||||||
(button_bundle("Main Menu"), GameOverMenuAction::ToMainMenu,),
|
(button_bundle("Main Menu"), ButtonMenuAction::ToMainMenu,),
|
||||||
(button_bundle("Quit"), GameOverMenuAction::Quit),
|
(button_bundle("Quit"), ButtonMenuAction::Quit),
|
||||||
],
|
],
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -236,19 +232,24 @@ fn animate_get_ready_widget(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Handles interaction and performs updates to the game-over UI.
|
/// Handles interactions with the menu buttons.
|
||||||
///
|
///
|
||||||
/// Used by [`PluginGameOver`] while in the [`GameState::GameOver`] state.
|
/// The buttons are used by the main menu and the game-over menu to change
|
||||||
|
/// between game states.
|
||||||
///
|
///
|
||||||
/// Mostly a button input handler, but it also makes for a convenient single
|
/// Button animation and action handling is done entirely within this system.
|
||||||
/// place to keep all system logic for this plugin.
|
///
|
||||||
fn operate_gameover_ui(
|
/// There are no checks for current state. If a "quit" button was put somewhere
|
||||||
|
/// on the HUD, this system would quit the game. The same will happen for
|
||||||
|
/// returning to the title screen. This should be useful for making a pause
|
||||||
|
/// menu, too.
|
||||||
|
fn operate_buttons(
|
||||||
mut interactions: Query<
|
mut interactions: Query<
|
||||||
(
|
(
|
||||||
&Interaction,
|
&Interaction,
|
||||||
&mut BackgroundColor,
|
&mut BackgroundColor,
|
||||||
&mut BorderColor,
|
&mut BorderColor,
|
||||||
&GameOverMenuAction,
|
&ButtonMenuAction,
|
||||||
),
|
),
|
||||||
(Changed<Interaction>, With<Button>),
|
(Changed<Interaction>, With<Button>),
|
||||||
>,
|
>,
|
||||||
@@ -262,13 +263,13 @@ fn operate_gameover_ui(
|
|||||||
*color = UI_BUTTON_PRESSED.into();
|
*color = UI_BUTTON_PRESSED.into();
|
||||||
border_color.0 = RED.into();
|
border_color.0 = RED.into();
|
||||||
match menu_action {
|
match menu_action {
|
||||||
GameOverMenuAction::ToMainMenu => {
|
ButtonMenuAction::ToMainMenu => {
|
||||||
game_state.set(GameState::TitleScreen);
|
game_state.set(GameState::TitleScreen);
|
||||||
}
|
}
|
||||||
GameOverMenuAction::StartGame => {
|
ButtonMenuAction::StartGame => {
|
||||||
game_state.set(GameState::Playing);
|
game_state.set(GameState::Playing);
|
||||||
}
|
}
|
||||||
GameOverMenuAction::Quit => {
|
ButtonMenuAction::Quit => {
|
||||||
app_exit_events.write(AppExit::Success);
|
app_exit_events.write(AppExit::Success);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user