Main Menu
This commit is contained in:
parent
5ea5d9e2de
commit
241078096f
5 changed files with 105 additions and 9 deletions
68
src/ui/main_menu.rs
Normal file
68
src/ui/main_menu.rs
Normal 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();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue