diff --git a/src/features/savegame/components.rs b/src/features/savegame/components.rs index c8690ae..c167311 100644 --- a/src/features/savegame/components.rs +++ b/src/features/savegame/components.rs @@ -92,3 +92,15 @@ impl SavegamePath { Self::new(next_index) } } + +#[derive(Component)] +pub enum RootMarker { + PopupSavegameLoad, +} + +#[derive(Component)] +pub enum ButtonType { + SavegameLoad { savegame_path: SavegamePath }, + SavegameDelete { savegame_path: SavegamePath }, + PopupClose, +} diff --git a/src/features/savegame/mod.rs b/src/features/savegame/mod.rs index a492b1c..eb6d0e3 100644 --- a/src/features/savegame/mod.rs +++ b/src/features/savegame/mod.rs @@ -1,4 +1,5 @@ use crate::features::phase::components::{SessionTracker, TimerSettings}; +use crate::features::savegame::ui::load_popup_handler; use crate::prelude::*; use messages::*; use std::fs::File; @@ -6,6 +7,7 @@ use std::io::{Read, Write}; pub mod components; pub mod messages; +pub mod ui; pub struct SavegamePlugin; @@ -16,6 +18,8 @@ impl Plugin for SavegamePlugin { app.add_systems(Update, dump_savegame.run_if(in_state(AppState::GameScreen))); app.add_systems(Update, load_savegame.run_if(in_state(AppState::GameScreen))); + + app.add_systems(Update, load_popup_handler); } } diff --git a/src/features/start_screen/ui/load.rs b/src/features/savegame/ui/load.rs similarity index 81% rename from src/features/start_screen/ui/load.rs rename to src/features/savegame/ui/load.rs index d820591..e5131c6 100644 --- a/src/features/start_screen/ui/load.rs +++ b/src/features/savegame/ui/load.rs @@ -1,5 +1,5 @@ -use super::super::components::*; -use crate::prelude::*; +use super::super::components::{ButtonType, RootMarker}; +use crate::{features::savegame::messages::SavegameLoadMessage, prelude::*}; pub fn spawn_load_popup(commands: &mut Commands) { commands @@ -78,7 +78,7 @@ pub fn spawn_load_popup(commands: &mut Commands) { for savegame in SavegamePath::list() { parent.spawn(( Button, - ButtonType::PopupSavegameLoad { + ButtonType::SavegameLoad { savegame_path: savegame.path.clone(), }, Node { @@ -123,7 +123,7 @@ pub fn spawn_load_popup(commands: &mut Commands) { ), ( Button, - ButtonType::PopupSavegameDelete { + ButtonType::SavegameDelete { savegame_path: savegame.path.clone() }, Node { @@ -146,3 +146,38 @@ pub fn spawn_load_popup(commands: &mut Commands) { }); }); } + +pub fn load_popup_handler( + mut commands: Commands, + mut next_state: ResMut>, + mut interaction_query: Query<(&Interaction, &ButtonType), (Changed, With