diff --git a/src/features/game_screen/mod.rs b/src/features/game_screen/mod.rs index 9f503b7..2a74417 100644 --- a/src/features/game_screen/mod.rs +++ b/src/features/game_screen/mod.rs @@ -9,10 +9,10 @@ impl Plugin for GameScreenPlugin { } } -fn setup(mut commands: Commands) { - commands.insert_resource(ClearColor(Color::srgb(0.294, 0.412, 0.184))); +fn setup(mut clear_color: ResMut) { + *clear_color = ClearColor(Color::srgb(0.294, 0.412, 0.184)); } -fn cleanup(mut commands: Commands) { - commands.remove_resource::(); +fn cleanup(mut clear_color: ResMut) { + *clear_color = ClearColor(Color::srgb(0.2, 0.2, 0.2)); } diff --git a/src/features/hud/components.rs b/src/features/hud/components.rs index ea70282..547dfae 100644 --- a/src/features/hud/components.rs +++ b/src/features/hud/components.rs @@ -1,4 +1,4 @@ -use crate::prelude::*; +use crate::{features::phase::components::TimerSettings, prelude::*}; #[derive(Component)] pub enum RootMarker { @@ -17,4 +17,51 @@ pub enum ButtonType { SavegameDump, SettingsOpen, SettingsClose, + SettingsExit, + SettingsSave, + SettingsTimerChange { + input: SettingsTimerInput, + amount: i32, + }, +} + +#[derive(Clone)] +pub enum TimerType { + Focus, + ShortBreak, + LongBreak, +} + +impl TimerSettings { + pub fn change(&mut self, timer_type: &TimerType, amount: i32) { + match timer_type { + TimerType::Focus => { + self.focus_duration = (self.focus_duration as i32 + amount) as u32; + if self.focus_duration > 7259 { + // 120:59 + self.focus_duration = 7259; + } + } + TimerType::LongBreak => { + self.long_break_duration = (self.long_break_duration as i32 + amount) as u32; + if self.long_break_duration > 7259 { + // 120:59 + self.long_break_duration = 7259; + } + } + TimerType::ShortBreak => { + self.short_break_duration = (self.short_break_duration as i32 + amount) as u32; + if self.short_break_duration > 7259 { + // 120:59 + self.short_break_duration = 7259; + } + } + } + } +} + +#[derive(Component, Clone)] +pub enum SettingsTimerInput { + Minutes(TimerType), + Seconds(TimerType), } diff --git a/src/features/hud/mod.rs b/src/features/hud/mod.rs index 3725a05..a248c1e 100644 --- a/src/features/hud/mod.rs +++ b/src/features/hud/mod.rs @@ -1,5 +1,8 @@ +use crate::features::phase::components::TimerSettings; +use crate::features::savegame::messages::SavegameDumpMessage; use crate::prelude::*; use components::*; +use ui::*; pub mod components; pub mod ui; @@ -10,8 +13,10 @@ impl Plugin for HudPlugin { fn build(&self, app: &mut App) { app.add_systems(OnEnter(AppState::GameScreen), setup); app.add_systems(OnExit(AppState::GameScreen), cleanup); - app.add_systems(Update, update_status.run_if(in_state(AppState::GameScreen))); - app.add_systems(Update, buttons.run_if(in_state(AppState::GameScreen))); + app.add_systems( + Update, + (update_status, buttons, update_timer_settings).run_if(in_state(AppState::GameScreen)), + ); } } @@ -74,12 +79,42 @@ fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, } fn buttons( + mut commands: Commands, mut interaction_query: Query<(&Interaction, &ButtonType), (Changed, With