refactor: Move load savegame popup to ui folder

This commit is contained in:
demenik
2025-11-27 17:31:41 +01:00
parent 8c04f0e484
commit 3e04c71e9d
3 changed files with 153 additions and 146 deletions

View File

@@ -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<NextState<AppState>>,

View File

@@ -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))
)]
)
],
));
}
});
});
});
}

View File

@@ -0,0 +1,3 @@
pub mod load;
pub use load::*;