Got web to work
parent
b2ca08ce3f
commit
520df6405e
@ -1,7 +1,16 @@
|
||||
extern crate wee_alloc;
|
||||
|
||||
// Use `wee_alloc` as the global allocator.
|
||||
#[global_allocator]
|
||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
|
||||
use bevy::prelude::*;
|
||||
|
||||
mod menu;
|
||||
|
||||
fn main() {
|
||||
App::new()
|
||||
.add_plugins(DefaultPlugins)
|
||||
.run();
|
||||
let mut app = App::new();
|
||||
app.add_plugins(DefaultPlugins);
|
||||
app.add_plugins(menu::MenuPlugin);
|
||||
app.run();
|
||||
}
|
||||
|
||||
@ -0,0 +1,67 @@
|
||||
use bevy::prelude::*;
|
||||
|
||||
/// Menu Plugin; empty struct for Plugin impl
|
||||
pub(crate) struct MenuPlugin;
|
||||
|
||||
impl Plugin for MenuPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.init_state::<MenuState>();
|
||||
app.add_systems(Startup, init_menu);
|
||||
app.add_systems(OnEnter(MenuState::Open), open_menu);
|
||||
app.add_systems(OnExit(MenuState::Open), close_menu);
|
||||
}
|
||||
}
|
||||
|
||||
/// State tracking if the menu is open or closed
|
||||
#[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default)]
|
||||
enum MenuState {
|
||||
#[default]
|
||||
Closed,
|
||||
Open,
|
||||
}
|
||||
|
||||
#[derive(Component)]
|
||||
struct MenuUi;
|
||||
|
||||
/// Initialize menu UI nodes at startup
|
||||
fn init_menu(
|
||||
mut commands: Commands,
|
||||
) {
|
||||
commands.spawn(Camera2dBundle { ..default() });
|
||||
|
||||
commands.spawn((
|
||||
MenuUi,
|
||||
NodeBundle {
|
||||
..default()
|
||||
}
|
||||
)).with_children(|parent| {
|
||||
parent.spawn(
|
||||
ButtonBundle {
|
||||
..default()
|
||||
}
|
||||
).with_children(|parent| {
|
||||
parent.spawn(TextBundle {
|
||||
text: Text::from_section("START", TextStyle { color: Color::BLACK, ..default() }),
|
||||
..default()
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/// Make menu UI visible
|
||||
fn open_menu(
|
||||
mut query: Query<&mut Visibility, With<MenuUi>>,
|
||||
) {
|
||||
query.iter_mut().for_each(|mut v| {
|
||||
*v = Visibility::Hidden
|
||||
})
|
||||
}
|
||||
|
||||
/// Hide menu UI
|
||||
fn close_menu(
|
||||
mut query: Query<&mut Visibility, With<MenuUi>>,
|
||||
) {
|
||||
query.iter_mut().for_each(|mut v| {
|
||||
*v = Visibility::Inherited
|
||||
})
|
||||
}
|
||||
Loading…
Reference in New Issue