fix: Use button component in StartScreen
This commit is contained in:
@@ -24,6 +24,7 @@ fn setup(mut commands: Commands) {
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
flex_direction: FlexDirection::Column,
|
||||
row_gap: px(10),
|
||||
..default()
|
||||
},
|
||||
children![
|
||||
@@ -32,57 +33,45 @@ fn setup(mut commands: Commands) {
|
||||
TextFont::from_font_size(64.0),
|
||||
TextColor(Color::srgb(0.9, 0.9, 0.9))
|
||||
),
|
||||
(
|
||||
Button,
|
||||
button(
|
||||
ButtonType::LoadGame,
|
||||
ButtonVariant::Primary,
|
||||
Node {
|
||||
width: px(300),
|
||||
height: px(65),
|
||||
width: px(280),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
padding: UiRect::all(px(10)),
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(NORMAL_BUTTON),
|
||||
children![(
|
||||
Text::new("Spiel laden"),
|
||||
TextFont::from_font_size(33.0),
|
||||
TextColor(Color::srgb(0.9, 0.9, 0.9))
|
||||
)]
|
||||
"Spiel laden",
|
||||
33.0
|
||||
),
|
||||
(
|
||||
Button,
|
||||
button(
|
||||
ButtonType::NewGame,
|
||||
ButtonVariant::Primary,
|
||||
Node {
|
||||
width: px(300),
|
||||
height: px(65),
|
||||
width: px(280),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
padding: UiRect::all(px(10)),
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(NORMAL_BUTTON),
|
||||
children![(
|
||||
Text::new("Neues Spiel"),
|
||||
TextFont::from_font_size(33.0),
|
||||
TextColor(Color::srgb(0.9, 0.9, 0.9))
|
||||
)]
|
||||
"Neues Spiel",
|
||||
33.0,
|
||||
),
|
||||
(
|
||||
Button,
|
||||
button(
|
||||
ButtonType::Settings,
|
||||
ButtonVariant::Secondary,
|
||||
Node {
|
||||
width: px(300),
|
||||
height: px(65),
|
||||
width: px(280),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
padding: UiRect::all(px(10)),
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(NORMAL_BUTTON),
|
||||
children![(
|
||||
Text::new("Einstellungen"),
|
||||
TextFont::from_font_size(33.0),
|
||||
TextColor(Color::srgb(0.9, 0.9, 0.9))
|
||||
)]
|
||||
)
|
||||
"Einstellungen",
|
||||
33.0
|
||||
),
|
||||
],
|
||||
));
|
||||
}
|
||||
@@ -90,18 +79,13 @@ fn setup(mut commands: Commands) {
|
||||
fn menu(
|
||||
mut commands: Commands,
|
||||
mut next_state: ResMut<NextState<AppState>>,
|
||||
mut interaction_query: Query<
|
||||
(&Interaction, &ButtonType, &mut BackgroundColor),
|
||||
(Changed<Interaction>, With<Button>),
|
||||
>,
|
||||
mut interaction_query: Query<(&Interaction, &ButtonType), (Changed<Interaction>, With<Button>)>,
|
||||
root_query: Query<(Entity, &RootMarker)>,
|
||||
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 {
|
||||
Interaction::Pressed => {
|
||||
*color = PRESSED_BUTTON.into();
|
||||
|
||||
match button_type {
|
||||
ButtonType::LoadGame => {
|
||||
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();
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user