2022-08-21 17:17:55 +00:00
|
|
|
use crate::AppState;
|
|
|
|
|
|
|
|
use bevy::{
|
|
|
|
input::{keyboard::KeyCode, Input},
|
|
|
|
prelude::*,
|
|
|
|
};
|
|
|
|
|
|
|
|
pub struct MenuPlugin;
|
|
|
|
|
2022-08-21 17:53:08 +00:00
|
|
|
#[derive(Component)]
|
2022-08-23 10:42:56 +00:00
|
|
|
struct Menu;
|
2022-08-21 17:53:08 +00:00
|
|
|
|
2022-08-21 17:17:55 +00:00
|
|
|
impl Plugin for MenuPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_system_set(SystemSet::on_enter(AppState::Menu).with_system(setup))
|
2022-08-21 17:53:08 +00:00
|
|
|
.add_system_set(SystemSet::on_update(AppState::Menu).with_system(keyboard_input_system))
|
|
|
|
.add_system_set(SystemSet::on_exit(AppState::Menu).with_system(despawn));
|
2022-08-21 17:17:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn setup(mut commands: Commands, asset_server: Res<AssetServer>) {
|
2022-08-23 10:42:56 +00:00
|
|
|
let font = asset_server.get_handle("UacariLegacy-Thin.ttf");
|
2022-08-21 21:46:07 +00:00
|
|
|
commands
|
|
|
|
.spawn_bundle(Text2dBundle {
|
|
|
|
text: Text::from_section(
|
|
|
|
"BEVYJAM",
|
|
|
|
TextStyle {
|
|
|
|
font: font.clone(),
|
2022-08-25 13:39:16 +00:00
|
|
|
font_size: 96.0,
|
2022-08-21 21:46:07 +00:00
|
|
|
color: Color::WHITE,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.with_alignment(TextAlignment::CENTER),
|
2022-08-23 10:42:56 +00:00
|
|
|
transform: Transform::from_xyz(0., 128.0, 0.),
|
2022-08-21 21:46:07 +00:00
|
|
|
..Default::default()
|
|
|
|
})
|
2022-08-23 10:42:56 +00:00
|
|
|
.insert(Menu);
|
2022-08-21 17:53:08 +00:00
|
|
|
commands
|
|
|
|
.spawn_bundle(Text2dBundle {
|
|
|
|
text: Text::from_section(
|
|
|
|
"Press ENTER",
|
|
|
|
TextStyle {
|
2022-08-21 21:46:07 +00:00
|
|
|
font,
|
|
|
|
font_size: 32.0,
|
2022-08-21 17:53:08 +00:00
|
|
|
color: Color::WHITE,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.with_alignment(TextAlignment::CENTER),
|
|
|
|
..Default::default()
|
|
|
|
})
|
2022-08-23 10:42:56 +00:00
|
|
|
.insert(Menu);
|
2022-08-21 17:53:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn despawn(mut commands: Commands, menu_query: Query<Entity, With<Menu>>) {
|
|
|
|
for entity in menu_query.iter() {
|
|
|
|
commands.entity(entity).despawn_recursive();
|
|
|
|
}
|
2022-08-21 17:17:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fn keyboard_input_system(
|
|
|
|
keyboard_input: Res<Input<KeyCode>>,
|
|
|
|
mut app_state: ResMut<State<AppState>>,
|
|
|
|
) {
|
|
|
|
if keyboard_input.just_pressed(KeyCode::Return) {
|
|
|
|
app_state.replace(AppState::Game).unwrap()
|
|
|
|
}
|
|
|
|
}
|