diff --git a/src/features/start_screen/components.rs b/src/features/start_screen/components.rs index eea6455..cc077d0 100644 --- a/src/features/start_screen/components.rs +++ b/src/features/start_screen/components.rs @@ -1,9 +1,11 @@ +use crate::features::phase::components::TimerSettings; use crate::prelude::*; /// Markers for main menu UI. #[derive(Component)] pub enum RootMarker { MainMenu, + Settings, } /// Buttons in the main menu. @@ -13,3 +15,6 @@ pub enum ButtonType { NewGame, Settings, } + +#[derive(Resource, Default, Debug)] +pub struct StartScreenTimerSettings(pub Option); diff --git a/src/features/start_screen/mod.rs b/src/features/start_screen/mod.rs index bed89e7..81a833d 100644 --- a/src/features/start_screen/mod.rs +++ b/src/features/start_screen/mod.rs @@ -1,17 +1,30 @@ +use crate::features::hud::components::{SettingsTimerInput, TimerType}; +use crate::features::phase::components::TimerSettings; use crate::features::savegame::ui::spawn_load_popup; use crate::prelude::*; use components::*; +use ui::settings::open_settings_menu; pub mod components; +pub mod ui; /// Plugin for the main menu screen. pub struct StartScreenPlugin; impl Plugin for StartScreenPlugin { fn build(&self, app: &mut App) { + app.init_resource::(); app.add_systems(OnEnter(AppState::StartScreen), setup); app.add_systems(OnExit(AppState::StartScreen), cleanup); - app.add_systems(Update, menu.run_if(in_state(AppState::StartScreen))); + app.add_systems( + Update, + (menu, handle_settings_buttons, update_timer_settings_display) + .run_if(in_state(AppState::StartScreen)), + ); + app.add_systems( + PostUpdate, + apply_start_screen_settings.run_if(in_state(AppState::GameScreen)), + ); } } @@ -70,18 +83,18 @@ fn menu( ) { for (interaction, button_type) in &mut interaction_query { match *interaction { - Interaction::Pressed => { - match button_type { - ButtonType::LoadGame => { - spawn_load_popup(&mut commands); - } - ButtonType::NewGame => { - commands.insert_resource(SavegamePath::next()); - next_state.set(AppState::GameScreen); - } - ButtonType::Settings => todo!(), - }; - } + Interaction::Pressed => match button_type { + ButtonType::LoadGame => { + spawn_load_popup(&mut commands); + } + ButtonType::NewGame => { + commands.insert_resource(SavegamePath::next()); + next_state.set(AppState::GameScreen); + } + ButtonType::Settings => { + open_settings_menu(&mut commands); + } + }, _ => (), } } @@ -93,3 +106,79 @@ fn cleanup(mut commands: Commands, query: Query>) { commands.entity(entity).despawn(); } } + +/// Handles button interactions within the settings menu. +fn handle_settings_buttons( + mut interaction_query: Query< + (&Interaction, &crate::features::hud::components::ButtonType), + (Changed, With