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, interaction_query: Query<(Entity, &Interaction, &mut Button), Changed>, ) { 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>) { for entity in query { commands.get_entity(entity).unwrap().despawn(); } }