fix: Use button component in StartScreen

This commit is contained in:
demenik
2025-11-28 12:26:34 +01:00
parent 63dae75761
commit cdcb8c08d4

View File

@@ -24,6 +24,7 @@ fn setup(mut commands: Commands) {
justify_content: JustifyContent::Center, justify_content: JustifyContent::Center,
align_items: AlignItems::Center, align_items: AlignItems::Center,
flex_direction: FlexDirection::Column, flex_direction: FlexDirection::Column,
row_gap: px(10),
..default() ..default()
}, },
children![ children![
@@ -32,57 +33,45 @@ fn setup(mut commands: Commands) {
TextFont::from_font_size(64.0), TextFont::from_font_size(64.0),
TextColor(Color::srgb(0.9, 0.9, 0.9)) TextColor(Color::srgb(0.9, 0.9, 0.9))
), ),
( button(
Button,
ButtonType::LoadGame, ButtonType::LoadGame,
ButtonVariant::Primary,
Node { Node {
width: px(300), width: px(280),
height: px(65),
justify_content: JustifyContent::Center, justify_content: JustifyContent::Center,
align_items: AlignItems::Center, align_items: AlignItems::Center,
padding: UiRect::all(px(10)),
..default() ..default()
}, },
BackgroundColor(NORMAL_BUTTON), "Spiel laden",
children![( 33.0
Text::new("Spiel laden"),
TextFont::from_font_size(33.0),
TextColor(Color::srgb(0.9, 0.9, 0.9))
)]
), ),
( button(
Button,
ButtonType::NewGame, ButtonType::NewGame,
ButtonVariant::Primary,
Node { Node {
width: px(300), width: px(280),
height: px(65),
justify_content: JustifyContent::Center, justify_content: JustifyContent::Center,
align_items: AlignItems::Center, align_items: AlignItems::Center,
padding: UiRect::all(px(10)),
..default() ..default()
}, },
BackgroundColor(NORMAL_BUTTON), "Neues Spiel",
children![( 33.0,
Text::new("Neues Spiel"),
TextFont::from_font_size(33.0),
TextColor(Color::srgb(0.9, 0.9, 0.9))
)]
), ),
( button(
Button,
ButtonType::Settings, ButtonType::Settings,
ButtonVariant::Secondary,
Node { Node {
width: px(300), width: px(280),
height: px(65),
justify_content: JustifyContent::Center, justify_content: JustifyContent::Center,
align_items: AlignItems::Center, align_items: AlignItems::Center,
padding: UiRect::all(px(10)),
..default() ..default()
}, },
BackgroundColor(NORMAL_BUTTON), "Einstellungen",
children![( 33.0
Text::new("Einstellungen"), ),
TextFont::from_font_size(33.0),
TextColor(Color::srgb(0.9, 0.9, 0.9))
)]
)
], ],
)); ));
} }
@@ -90,18 +79,13 @@ fn setup(mut commands: Commands) {
fn menu( fn menu(
mut commands: Commands, mut commands: Commands,
mut next_state: ResMut<NextState<AppState>>, mut next_state: ResMut<NextState<AppState>>,
mut interaction_query: Query< mut interaction_query: Query<(&Interaction, &ButtonType), (Changed<Interaction>, With<Button>)>,
(&Interaction, &ButtonType, &mut BackgroundColor),
(Changed<Interaction>, With<Button>),
>,
root_query: Query<(Entity, &RootMarker)>, root_query: Query<(Entity, &RootMarker)>,
mut savegame_messages: MessageWriter<SavegameLoadMessage>, mut savegame_messages: MessageWriter<SavegameLoadMessage>,
) { ) {
for (interaction, button_type, mut color) in &mut interaction_query { for (interaction, button_type) in &mut interaction_query {
match *interaction { match *interaction {
Interaction::Pressed => { Interaction::Pressed => {
*color = PRESSED_BUTTON.into();
match button_type { match button_type {
ButtonType::LoadGame => { ButtonType::LoadGame => {
spawn_load_popup(&mut commands); spawn_load_popup(&mut commands);
@@ -135,15 +119,10 @@ fn menu(
} }
} }
} }
_ => (), ButtonType::Settings => todo!(),
}; };
} }
Interaction::Hovered => { _ => (),
*color = HOVERED_BUTTON.into();
}
Interaction::None => {
*color = NORMAL_BUTTON.into();
}
} }
} }
} }