You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
Rust
43 lines
1.2 KiB
Rust
use crate::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_ui);
|
|
app.add_systems(
|
|
Update,
|
|
manage_visibility::<MenuState>.run_if(state_changed::<MenuState>),
|
|
);
|
|
app.add_systems(
|
|
Update,
|
|
button_state_action::<MenuState>.run_if(any_component_changed::<Interaction>),
|
|
);
|
|
}
|
|
}
|
|
|
|
/// State tracking if the menu is open or closed
|
|
#[derive(States, Debug, Clone, PartialEq, Eq, Hash, Default, Component)]
|
|
pub(crate) enum MenuState {
|
|
#[default]
|
|
Open,
|
|
Closed,
|
|
}
|
|
|
|
/// Initialize menu UI nodes at startup
|
|
fn init_menu_ui(mut commands: Commands) {
|
|
commands
|
|
.spawn((MenuState::Open, GameChoice::None, Pickable::IGNORE))
|
|
.add(UiContainer)
|
|
.with_children(|parent| {
|
|
parent.spawn_empty().add(UiTitle {
|
|
text: "Game Jam Casino",
|
|
});
|
|
parent
|
|
.spawn(SetState(GameChoice::Dice))
|
|
.add(UiButton { label: "Dice" });
|
|
});
|
|
}
|