From 3e04c71e9dc6e4bcec8c2b8cfcfd0757d158165c Mon Sep 17 00:00:00 2001 From: demenik Date: Thu, 27 Nov 2025 17:31:41 +0100 Subject: [PATCH 1/4] refactor: Move load savegame popup to ui folder --- src/features/start_screen/mod.rs | 148 +-------------------------- src/features/start_screen/ui/load.rs | 148 +++++++++++++++++++++++++++ src/features/start_screen/ui/mod.rs | 3 + 3 files changed, 153 insertions(+), 146 deletions(-) create mode 100644 src/features/start_screen/ui/load.rs create mode 100644 src/features/start_screen/ui/mod.rs diff --git a/src/features/start_screen/mod.rs b/src/features/start_screen/mod.rs index 19d788c..cc69c82 100644 --- a/src/features/start_screen/mod.rs +++ b/src/features/start_screen/mod.rs @@ -1,9 +1,11 @@ use crate::{features::savegame::messages::SavegameLoadMessage, prelude::*}; use components::*; use consts::*; +use ui::*; pub mod components; pub mod consts; +pub mod ui; pub struct StartScreenPlugin; @@ -87,152 +89,6 @@ fn setup(mut commands: Commands) { )); } -fn spawn_load_popup(commands: &mut Commands) { - commands - .spawn(( - RootMarker::PopupSavegameLoad, - Node { - position_type: PositionType::Absolute, - width: percent(100), - height: percent(100), - justify_content: JustifyContent::Center, - align_items: AlignItems::Center, - ..default() - }, - ZIndex(1), - BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)), - )) - .with_children(|parent| { - parent - .spawn(( - Node { - width: px(600.0), - height: px(500.0), - flex_direction: FlexDirection::Column, - align_items: AlignItems::Center, - padding: UiRect::all(px(20.0)), - ..default() - }, - BackgroundColor(Color::srgb(0.2, 0.2, 0.2)), - BorderRadius::all(Val::Px(10.0)), - )) - .with_children(|parent| { - parent.spawn(( - Node { - width: percent(100.0), - justify_content: JustifyContent::SpaceBetween, - align_items: AlignItems::Center, - margin: UiRect::bottom(px(20.0)), - ..default() - }, - children![ - ( - Text::new("Spielstand Auswahl"), - TextFont::from_font_size(40.0), - TextColor(Color::WHITE), - ), - ( - Button, - ButtonType::PopupClose, - Node { - width: px(40.0), - height: px(40.0), - justify_content: JustifyContent::Center, - align_items: AlignItems::Center, - ..default() - }, - BackgroundColor(Color::srgb(0.8, 0.2, 0.2)), - children![( - Text::new("X"), - TextFont::from_font_size(24.0), - TextColor(Color::WHITE), - )] - ) - ], - )); - - parent - .spawn(Node { - width: percent(100), - flex_direction: FlexDirection::Column, - overflow: Overflow::scroll_y(), - margin: UiRect::all(px(20.0)), - row_gap: px(10.0), - ..default() - }) - .with_children(|parent| { - for savegame in SavegamePath::list() { - parent.spawn(( - Button, - ButtonType::PopupSavegameLoad { - savegame_path: savegame.path.clone(), - }, - Node { - width: percent(100), - 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, - 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)) - )] - ) - ], - )); - } - }); - }); - }); -} - fn menu( mut commands: Commands, mut next_state: ResMut>, diff --git a/src/features/start_screen/ui/load.rs b/src/features/start_screen/ui/load.rs new file mode 100644 index 0000000..b0baf91 --- /dev/null +++ b/src/features/start_screen/ui/load.rs @@ -0,0 +1,148 @@ +use super::super::{components::*, consts::*}; +use crate::prelude::*; + +pub fn spawn_load_popup(commands: &mut Commands) { + commands + .spawn(( + RootMarker::PopupSavegameLoad, + Node { + position_type: PositionType::Absolute, + width: percent(100), + height: percent(100), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + ..default() + }, + ZIndex(1), + BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)), + )) + .with_children(|parent| { + parent + .spawn(( + Node { + width: px(600.0), + height: px(500.0), + flex_direction: FlexDirection::Column, + align_items: AlignItems::Center, + padding: UiRect::all(px(20.0)), + ..default() + }, + BackgroundColor(Color::srgb(0.2, 0.2, 0.2)), + BorderRadius::all(Val::Px(10.0)), + )) + .with_children(|parent| { + parent.spawn(( + Node { + width: percent(100.0), + justify_content: JustifyContent::SpaceBetween, + align_items: AlignItems::Center, + margin: UiRect::bottom(px(20.0)), + ..default() + }, + children![ + ( + Text::new("Spielstand Auswahl"), + TextFont::from_font_size(40.0), + TextColor(Color::WHITE), + ), + ( + Button, + ButtonType::PopupClose, + Node { + width: px(40.0), + height: px(40.0), + justify_content: JustifyContent::Center, + align_items: AlignItems::Center, + ..default() + }, + BackgroundColor(Color::srgb(0.8, 0.2, 0.2)), + children![( + Text::new("X"), + TextFont::from_font_size(24.0), + TextColor(Color::WHITE), + )] + ) + ], + )); + + parent + .spawn(Node { + width: percent(100), + flex_direction: FlexDirection::Column, + overflow: Overflow::scroll_y(), + margin: UiRect::all(px(20.0)), + row_gap: px(10.0), + ..default() + }) + .with_children(|parent| { + for savegame in SavegamePath::list() { + parent.spawn(( + Button, + ButtonType::PopupSavegameLoad { + savegame_path: savegame.path.clone(), + }, + Node { + width: percent(100), + 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, + 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)) + )] + ) + ], + )); + } + }); + }); + }); +} diff --git a/src/features/start_screen/ui/mod.rs b/src/features/start_screen/ui/mod.rs new file mode 100644 index 0000000..1e3623f --- /dev/null +++ b/src/features/start_screen/ui/mod.rs @@ -0,0 +1,3 @@ +pub mod load; + +pub use load::*; From 2a17d161f3bcbbacb721c2e50707675aee9887d8 Mon Sep 17 00:00:00 2001 From: demenik Date: Thu, 27 Nov 2025 17:33:37 +0100 Subject: [PATCH 2/4] refactor: Move status to hud --- src/features/hud/components.rs | 20 +++++++++++++ src/features/{status => hud}/mod.rs | 44 +++++++++++++---------------- src/features/hud/ui/mod.rs | 1 + src/features/hud/ui/settings.rs | 3 ++ src/features/mod.rs | 4 +-- src/features/ui/components.rs | 14 --------- src/main.rs | 2 +- src/prelude.rs | 5 +--- 8 files changed, 48 insertions(+), 45 deletions(-) create mode 100644 src/features/hud/components.rs rename src/features/{status => hud}/mod.rs (66%) create mode 100644 src/features/hud/ui/mod.rs create mode 100644 src/features/hud/ui/settings.rs diff --git a/src/features/hud/components.rs b/src/features/hud/components.rs new file mode 100644 index 0000000..ea70282 --- /dev/null +++ b/src/features/hud/components.rs @@ -0,0 +1,20 @@ +use crate::prelude::*; + +#[derive(Component)] +pub enum RootMarker { + Status, + Settings, +} + +#[derive(Component)] +pub enum TextType { + Phase, + Timer, +} + +#[derive(Component)] +pub enum ButtonType { + SavegameDump, + SettingsOpen, + SettingsClose, +} diff --git a/src/features/status/mod.rs b/src/features/hud/mod.rs similarity index 66% rename from src/features/status/mod.rs rename to src/features/hud/mod.rs index 79e123c..663158c 100644 --- a/src/features/status/mod.rs +++ b/src/features/hud/mod.rs @@ -1,23 +1,24 @@ use crate::features::savegame::messages::SavegameDumpMessage; use crate::prelude::*; +use components::*; -pub struct StatusPlugin; +pub mod components; +pub mod ui; -impl Plugin for StatusPlugin { +pub struct HudPlugin; + +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, - status_buttons.run_if(in_state(AppState::GameScreen)), - ); + app.add_systems(Update, buttons.run_if(in_state(AppState::GameScreen))); } } fn setup(mut commands: Commands) { commands.spawn(( - UiStatusRootContainer, + RootMarker::Status, Node { position_type: PositionType::Absolute, bottom: px(0), @@ -34,23 +35,23 @@ fn setup(mut commands: Commands) { BackgroundColor(Color::srgba(0.0, 0.0, 0.0, 0.8)), children![ ( - UiStatusText::Phase, + TextType::Phase, Text::new("..."), TextFont::from_font_size(16.0), TextColor(Color::WHITE) ), ( - UiStatusText::Timer, + TextType::Timer, Text::new("--:--"), TextFont::from_font_size(16.0), TextColor(Color::WHITE) ), ( Button, - UiStatusButton::SavegameDump, + ButtonType::SettingsOpen, Node::default(), children![ - Text::new("Save"), + Text::new("Einstellungen"), TextFont::from_font_size(16.0), TextColor(Color::WHITE) ] @@ -59,7 +60,7 @@ fn setup(mut commands: Commands) { )); } -fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, &UiStatusText)>) { +fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, &TextType)>) { if !phase_res.is_changed() { return; } @@ -67,32 +68,27 @@ fn update_status(phase_res: Res, mut text_query: Query<(&mut Text, for (mut text, status_type) in text_query.iter_mut() { text.0 = match status_type { - UiStatusText::Phase => current_phase.display_name().into(), - UiStatusText::Timer => current_phase.format_duration(), + TextType::Phase => current_phase.display_name().into(), + TextType::Timer => current_phase.format_duration(), }; } } -fn status_buttons( - mut interaction_query: Query< - (&Interaction, &UiStatusButton), - (Changed, With