feat: Add StartScreen title and buttons (#11)
This commit is contained in:
@@ -16,6 +16,13 @@ struct MenuData {
|
||||
button_entity: Entity,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
enum ButtonType {
|
||||
LoadGame,
|
||||
NewGame,
|
||||
Settings,
|
||||
}
|
||||
|
||||
const NORMAL_BUTTON: Color = Color::srgb(0.15, 0.15, 0.15);
|
||||
const HOVERED_BUTTON: Color = Color::srgb(0.25, 0.25, 0.25);
|
||||
const PRESSED_BUTTON: Color = Color::srgb(0.35, 0.75, 0.35);
|
||||
@@ -28,27 +35,79 @@ fn setup(mut commands: Commands) {
|
||||
height: percent(100),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
flex_direction: FlexDirection::Column,
|
||||
..default()
|
||||
},
|
||||
children![(
|
||||
Button,
|
||||
Node {
|
||||
width: px(150),
|
||||
height: px(65),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(NORMAL_BUTTON),
|
||||
children![(
|
||||
Text::new("Play"),
|
||||
children![
|
||||
(
|
||||
Text::new("Pomonon Garten"),
|
||||
TextFont {
|
||||
font_size: 33.0,
|
||||
font_size: 64.0,
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::srgb(0.9, 0.9, 0.9))
|
||||
)]
|
||||
)],
|
||||
),
|
||||
(
|
||||
Button,
|
||||
ButtonType::LoadGame,
|
||||
Node {
|
||||
width: px(300),
|
||||
height: px(65),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(NORMAL_BUTTON),
|
||||
children![(
|
||||
Text::new("Spiel laden"),
|
||||
TextFont {
|
||||
font_size: 33.0,
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::srgb(0.9, 0.9, 0.9))
|
||||
)]
|
||||
),
|
||||
(
|
||||
Button,
|
||||
ButtonType::NewGame,
|
||||
Node {
|
||||
width: px(300),
|
||||
height: px(65),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(NORMAL_BUTTON),
|
||||
children![(
|
||||
Text::new("Neues Spiel"),
|
||||
TextFont {
|
||||
font_size: 33.0,
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::srgb(0.9, 0.9, 0.9))
|
||||
)]
|
||||
),
|
||||
(
|
||||
Button,
|
||||
ButtonType::Settings,
|
||||
Node {
|
||||
width: px(300),
|
||||
height: px(65),
|
||||
justify_content: JustifyContent::Center,
|
||||
align_items: AlignItems::Center,
|
||||
..default()
|
||||
},
|
||||
BackgroundColor(NORMAL_BUTTON),
|
||||
children![(
|
||||
Text::new("Einstellungen"),
|
||||
TextFont {
|
||||
font_size: 33.0,
|
||||
..default()
|
||||
},
|
||||
TextColor(Color::srgb(0.9, 0.9, 0.9))
|
||||
)]
|
||||
)
|
||||
],
|
||||
))
|
||||
.id();
|
||||
|
||||
@@ -58,15 +117,19 @@ fn setup(mut commands: Commands) {
|
||||
fn menu(
|
||||
mut next_state: ResMut<NextState<AppState>>,
|
||||
mut interaction_query: Query<
|
||||
(&Interaction, &mut BackgroundColor),
|
||||
(&Interaction, &ButtonType, &mut BackgroundColor),
|
||||
(Changed<Interaction>, With<Button>),
|
||||
>,
|
||||
) {
|
||||
for (interaction, mut color) in &mut interaction_query {
|
||||
for (interaction, button_type, mut color) in &mut interaction_query {
|
||||
match *interaction {
|
||||
Interaction::Pressed => {
|
||||
*color = PRESSED_BUTTON.into();
|
||||
next_state.set(AppState::GameScreen);
|
||||
|
||||
match button_type {
|
||||
ButtonType::NewGame => next_state.set(AppState::GameScreen),
|
||||
_ => (),
|
||||
};
|
||||
}
|
||||
Interaction::Hovered => {
|
||||
*color = HOVERED_BUTTON.into();
|
||||
|
||||
Reference in New Issue
Block a user