From 62bb029084f068c027b44619a4e7482999ebf433 Mon Sep 17 00:00:00 2001 From: demenik Date: Thu, 27 Nov 2025 13:56:30 +0100 Subject: [PATCH] feat: Add savegame deletion (#37) --- src/features/start_screen/components.rs | 1 + src/features/start_screen/mod.rs | 86 ++++++++++++++++++------- 2 files changed, 62 insertions(+), 25 deletions(-) diff --git a/src/features/start_screen/components.rs b/src/features/start_screen/components.rs index abf57d5..ac6f436 100644 --- a/src/features/start_screen/components.rs +++ b/src/features/start_screen/components.rs @@ -12,5 +12,6 @@ pub enum ButtonType { NewGame, Settings, PopupSavegameLoad { savegame_path: SavegamePath }, + PopupSavegameDelete { savegame_path: SavegamePath }, PopupClose, } diff --git a/src/features/start_screen/mod.rs b/src/features/start_screen/mod.rs index da4c7ac..19d788c 100644 --- a/src/features/start_screen/mod.rs +++ b/src/features/start_screen/mod.rs @@ -172,36 +172,60 @@ fn spawn_load_popup(commands: &mut Commands) { height: px(80), justify_content: JustifyContent::Center, align_items: AlignItems::Center, + flex_direction: FlexDirection::Row, + column_gap: px(10.0), + padding: UiRect::horizontal(px(10.0)), ..default() }, BackgroundColor(NORMAL_BUTTON), - children![( - Node { - width: percent(100), - height: percent(100), - flex_direction: FlexDirection::Column, - ..default() - }, - children![ - ( - Text::new(format!( - "Spielstand {}", - savegame.index + 1 - )), + children![ + ( + Node { + width: percent(100), + height: percent(100), + flex_direction: FlexDirection::Column, + justify_content: JustifyContent::Center, + ..default() + }, + children![ + ( + Text::new(format!( + "Spielstand {}", + savegame.index + 1 + )), + TextFont::from_font_size(24.0), + TextColor(Color::srgb(0.9, 0.9, 0.9)) + ), + ( + Text::new(format!( + "Beeren: {}, Fokusphasen abgeschlossen: {}", + savegame.total_berries, + savegame.completed_focus + )), + TextFont::from_font_size(18.0), + TextColor(Color::srgb(0.9, 0.9, 0.9)) + ) + ] + ), + ( + Button, + ButtonType::PopupSavegameDelete { + savegame_path: savegame.path.clone() + }, + Node { + width: px(40.0), + height: px(40.0), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + ..default() + }, + children![( + Text::new("X"), TextFont::from_font_size(24.0), TextColor(Color::srgb(0.9, 0.9, 0.9)) - ), - ( - Text::new(format!( - "Beeren: {}, Fokusphasen abgeschlossen: {}", - savegame.total_berries, - savegame.completed_focus - )), - TextFont::from_font_size(18.0), - TextColor(Color::srgb(0.9, 0.9, 0.9)) - ) - ] - )], + )] + ) + ], )); } }); @@ -245,6 +269,18 @@ fn menu( next_state.set(AppState::GameScreen); savegame_messages.write(SavegameLoadMessage); } + ButtonType::PopupSavegameDelete { savegame_path } => { + if let Err(e) = std::fs::remove_file(savegame_path.clone().0) { + println!("Error while deleting savegame: {:?}", e); + } + + for (entity, root) in root_query.iter() { + match *root { + RootMarker::PopupSavegameLoad => commands.entity(entity).despawn(), + _ => {} + } + } + } _ => (), }; }