feat: Add StartScreen title and buttons (#11)

This commit is contained in:
demenik
2025-11-21 15:27:53 +01:00
parent 0f5712afa8
commit 81c8590612

View File

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