/// Handles user interactions with the menu
///
/// Starts the new game (changes to [GameState::Playing]) when a user selects
/// a difficulty level.
/// Handles hovering logic: the label text will increas by 20% if hovered
/// over.
Handles user interactions with the menu
Starts the new game (changes to [GameState::Playing]) when a user selects
a difficulty level.
Handles hovering logic: the label text will increas by 20% if hovered
over.
Handles user interactions with the menu Starts the new game ( changes to [ GameState :: Playing ] ) when a user selects a difficulty level . Handles hovering logic : the label text will increas by 20% if hovered over .
fn handle_menu(
    mut commands: Commands,
    mut state: ResMut<State<GameState>>,
    mut interaction_query: Query<
        (&Interaction, &DifficultyLevel, &Children),
        (Changed<Interaction>, With<Button>),
    >,
    mut text_query: Query<&mut Text>,
) {
    for (interaction, level, children) in interaction_query.iter_mut() {
        match *interaction {
            Interaction::Hovered => {
                if let Ok(mut text) = text_query.get_mut(children[0]) {
                    text.sections[0].style.font_size *= 1.2;
                }
            }
            Interaction::Clicked => {
                let game = match level {
                    DifficultyLevel::Easy => game::Game::new(5, 5),
                    DifficultyLevel::Medium => game::Game::new(10, 10),
                    DifficultyLevel::Hard => game::Game::new(15, 15),
                };
                info!("\n{}", game);
                commands.remove_resource::<game::Game>();
                commands.insert_resource(game);
                state
                    .set(GameState::Playing)
                    .expect("Failed to change the state");
            }
            Interaction::None => {
                if let Ok(mut text) = text_query.get_mut(children[0]) {
                    text.sections[0].style.font_size /= 1.2;
                }
            }
        }
    }
}
fn handle_menu ( mut commands : Commands , mut state : ResMut < State < GameState > > , mut interaction_query : Query < ( & Interaction , & DifficultyLevel , & Children ) , ( Changed < Interaction > , With < Button > ) , > , mut text_query : Query < & mut Text > , ) { for ( interaction , level , children ) in interaction_query . iter_mut ( ) { match * interaction { Interaction :: Hovered => { if let Ok ( mut text ) = text_query . get_mut ( children [ 0 ] ) { text . sections [ 0 ] . style . font_size *= 1.2 ; } } Interaction :: Clicked => { let game = match level { DifficultyLevel :: Easy => game :: Game :: new ( 5 , 5 ) , DifficultyLevel :: Medium => game :: Game :: new ( 10 , 10 ) , DifficultyLevel :: Hard => game :: Game :: new ( 15 , 15 ) , } ; info ! ( " \n " game ) ; commands . remove_resource :: < game :: Game > ( ) ; commands . insert_resource ( game ) ; state . set ( GameState :: Playing ) . expect ( " " ) ; } Interaction :: None => { if let Ok ( mut text ) = text_query . get_mut ( children [ 0 ] ) { text . sections [ 0 ] . style . font_size /= 1.2 ; } } } } }
Handles user interactions with the menu
Starts the new game (changes to [GameState::Playing]) when a user selects
a difficulty level.
Handles user interactions with the menu Starts the new game ( changes to [ GameState :: Playing ] ) when a user selects a difficulty level .
commands
Commands
state
ResMut<State<GameState>>
interaction_query
Query<
        (&Interaction, &DifficultyLevel, &Children),
        (Changed<Interaction>, With<Button>),
    >
text_query
Query<&mut Text>