diff --git a/src/widgets.rs b/src/widgets.rs index 06aeb75..baee080 100644 --- a/src/widgets.rs +++ b/src/widgets.rs @@ -1,11 +1,11 @@ use crate::{ GameState, - config::UI_BUTTON_NORMAL, + config::{UI_BUTTON_HOVERED, UI_BUTTON_NORMAL, UI_BUTTON_PRESSED}, resources::{Lives, Score}, }; use bevy::{ - color::palettes::css::{BLACK, GREEN, LIGHT_BLUE, RED}, + color::palettes::css::{BLACK, GREEN, LIGHT_BLUE, RED, WHITE}, prelude::*, }; @@ -44,7 +44,11 @@ pub struct PluginGameOver; impl Plugin for PluginGameOver { fn build(&self, app: &mut App) { app.add_systems(OnEnter(GameState::GameOver), spawn_gameover_ui) - .add_systems(OnExit(GameState::GameOver), despawn::); + .add_systems(OnExit(GameState::GameOver), despawn::) + .add_systems( + Update, + operate_gameover_ui.run_if(in_state(GameState::GameOver)), + ); } } @@ -56,6 +60,16 @@ struct OnReadySetGo; #[derive(Component)] struct MarkerGameOver; +/// Action specifier for the game-over menu's buttons. +/// +/// Attach this component to a button and [`PluginGameOver`] will use it to +/// decide what to do when that button is pressed. +#[derive(Component)] +enum GameOverMenuAction { + ToMainMenu, + Quit, +} + /// Newtype wrapper for `Timer`. Used to count down during the "get ready" phase. #[derive(Deref, DerefMut, Resource)] struct ReadySetGoTimer(Timer); @@ -194,13 +208,37 @@ fn animate_get_ready_widget( } } -/// Handles interaction and performs updates to the game over UI. +/// Handles interaction and performs updates to the game-over UI. /// /// Used by [`PluginGameOver`] while in the [`GameState::GameOver`] state. /// /// Mostly a button input handler, but it also makes for a convenient single /// place to keep all system logic for this plugin. -fn operate_gameover_ui() {} +fn operate_gameover_ui( + mut interactions: Query< + (&Interaction, &mut BackgroundColor, &mut BorderColor), + (Changed, With