Main Menu

This commit is contained in:
Rendo 2025-11-17 17:59:59 +05:00
commit 241078096f
5 changed files with 105 additions and 9 deletions

68
src/ui/main_menu.rs Normal file
View file

@ -0,0 +1,68 @@
use bevy::{input_focus::InputFocus, prelude::*};
use crate::GameState;
#[derive(Component)]
pub struct Menu;
pub fn setup_menu(mut commands: Commands) {
//setup menu text
commands.spawn((
Text::new("NOW IT'S YOUR CHANCE TO BE\nA\nBIG\nFELORONI"),
TextFont {
font_size: 32.,
..default()
},
TextLayout::new_with_justify(Justify::Center),
Menu,
Node {
position_type: PositionType::Absolute,
top: percent(25),
right: percent(33),
..default()
},
));
//setup button
commands.spawn((
Button,
Node {
width: px(150),
height: px(65),
border: UiRect::all(px(5)),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
Menu,
children![(Text::new("Igron"))],
));
}
pub fn button_system(
mut commands: Commands,
mut input_focus: ResMut<InputFocus>,
interaction_query: Query<(Entity, &Interaction, &mut Button), Changed<Interaction>>,
) {
for (entity, interaction, mut button) in interaction_query {
match interaction {
Interaction::Pressed => {
input_focus.set(entity);
button.set_changed();
commands.set_state(GameState::Game);
}
Interaction::Hovered => {
input_focus.set(entity);
button.set_changed();
}
Interaction::None => {
input_focus.clear();
}
}
}
}
pub fn cleanup_menu(mut commands: Commands, query: Query<Entity, With<Menu>>) {
for entity in query {
commands.get_entity(entity).unwrap().despawn();
}
}