tutorial menu works

main
Elijah C. Voigt 2 years ago
parent 3091a15dea
commit aef8c719f2

@ -31,29 +31,31 @@ fn init_credits_ui(mut commands: Commands) {
}, },
)) ))
.with_children(|parent| { .with_children(|parent| {
parent.spawn(( parent
Credits, .spawn((
NodeBundle {
style: Style {
padding: UiRect::all(Val::Px(25.0)),
..default()
},
background_color: Color::BLACK.with_a(0.5).into(),
..default()
}
)).with_children(|parent| {
parent.spawn((
Credits, Credits,
TextBundle { NodeBundle {
text: Text { style: Style {
alignment: TextAlignment::Center, padding: UiRect::all(Val::Px(25.0)),
sections: vec![],
..default() ..default()
}, },
background_color: Color::BLACK.with_a(0.5).into(),
..default() ..default()
}, },
)); ))
}); .with_children(|parent| {
parent.spawn((
Credits,
TextBundle {
text: Text {
alignment: TextAlignment::Center,
sections: vec![],
..default()
},
..default()
},
));
});
parent parent
.spawn(( .spawn((
@ -85,7 +87,6 @@ fn init_credits_ui(mut commands: Commands) {
..default() ..default()
}); });
}); });
}); });
} }

@ -46,6 +46,7 @@ impl Plugin for GamePlugin {
PostUpdate, PostUpdate,
(debug_board.run_if(resource_exists::<debug::DebugEnabled>()),), (debug_board.run_if(resource_exists::<debug::DebugEnabled>()),),
) )
.add_systems(OnEnter(GameState::Restart), handle_restart)
.add_systems(OnEnter(GameState::Quit), handle_quit); .add_systems(OnEnter(GameState::Quit), handle_quit);
} }
} }
@ -845,10 +846,11 @@ fn reset_game(
}); });
} }
/// Very simple system to handle the "Quit" state (shutdown the game) /// Very simple system to handle the "Quit" state (shutdown the game)
fn handle_quit( fn handle_quit(mut app_exit_events: EventWriter<AppExit>) {
mut app_exit_events: EventWriter<AppExit>,
) {
app_exit_events.send(AppExit); app_exit_events.send(AppExit);
} }
fn handle_restart() {
todo!("Restart is not implemented yet!");
}

@ -17,11 +17,15 @@ impl Plugin for MenuPlugin {
Update, Update,
manage_state_entities::<MenuState>().run_if(state_changed::<MenuState>()), manage_state_entities::<MenuState>().run_if(state_changed::<MenuState>()),
) )
.add_systems(Update, ( .add_systems(
handle_button_press::<GameState>, Update,
handle_button_press::<MenuState>, (
handle_button_press::<TutorialState>, handle_button_press::<GameState>,
).run_if(any_component_changed::<Interaction>())) handle_button_press::<MenuState>,
handle_button_press::<TutorialState>,
)
.run_if(any_component_changed::<Interaction>()),
)
.add_systems(Update, set_menu_state.run_if(just_pressed(KeyCode::Escape))); .add_systems(Update, set_menu_state.run_if(just_pressed(KeyCode::Escape)));
} }
} }
@ -347,7 +351,5 @@ fn handle_button_press<S: States + Clone + Component>(
.filter_map(|(interaction, button_action)| { .filter_map(|(interaction, button_action)| {
(*interaction == Interaction::Pressed).then_some(button_action) (*interaction == Interaction::Pressed).then_some(button_action)
}) })
.for_each(|ButtonAction(ba)| { .for_each(|ButtonAction(ba)| next_state.set(ba.clone()));
next_state.set(ba.clone())
});
} }

@ -182,6 +182,7 @@ fn initialize_tutorial(
width: Val::Percent(33.0), width: Val::Percent(33.0),
max_height: Val::Percent(100.0), max_height: Val::Percent(100.0),
padding: UiRect::all(Val::Px(25.0)), padding: UiRect::all(Val::Px(25.0)),
flex_direction: FlexDirection::Column,
..default() ..default()
}, },
background_color: Color::hex(&background_hex).unwrap().into(), background_color: Color::hex(&background_hex).unwrap().into(),
@ -210,6 +211,69 @@ fn initialize_tutorial(
..default() ..default()
}, },
)); ));
if *step == TutorialState::Outro {
parent
.spawn(NodeBundle {
style: Style {
flex_direction: FlexDirection::Row,
..default()
},
..default()
})
.with_children(|parent| {
parent
.spawn((
menu::ButtonAction(tutorial::TutorialState::None),
menu::ButtonAction(GameState::Restart),
menu::ButtonAction(menu::MenuState::None),
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Start Over",
TextStyle {
color: Color::BLACK,
font_size: 16.0,
..default()
},
),));
});
parent
.spawn((
menu::ButtonAction(tutorial::TutorialState::None),
menu::ButtonAction(GameState::Play),
menu::ButtonAction(menu::MenuState::None),
ButtonBundle {
style: Style {
padding: UiRect::all(Val::Px(5.0)),
margin: UiRect::all(Val::Px(5.0)),
..default()
},
background_color: Color::ORANGE.with_a(0.5).into(),
..default()
},
))
.with_children(|parent| {
parent.spawn((TextBundle::from_section(
"Continue Game",
TextStyle {
color: Color::BLACK,
font_size: 16.0,
..default()
},
),));
});
});
}
}); });
}); });
}) })
@ -305,7 +369,7 @@ fn step(
next_state.set(next); next_state.set(next);
} }
// After the outro, we exit the tutorial // After the outro, we exit the tutorial
TutorialState::Outro => next_state.set(TutorialState::None), TutorialState::Outro => error!("Press a button!"),
TutorialState::_Promotions => todo!("Not implemented yet!"), TutorialState::_Promotions => todo!("Not implemented yet!"),
} }
} }

Loading…
Cancel
Save