Skip to content

Commit

Permalink
dev: made button component enum
Browse files Browse the repository at this point in the history
  • Loading branch information
roboteng committed Oct 13, 2023
1 parent 47240a2 commit a3c3528
Showing 1 changed file with 16 additions and 12 deletions.
28 changes: 16 additions & 12 deletions game/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ fn c_title_test(_: &AssetServer, a: &mut TextStyle) {
}

#[derive(Component)]
struct QuitButton;

#[derive(Component)]
struct MyButton;
enum MyButton {
SinglePlayer,
MultiPlayer,
Settings,
Quit,
}

fn draw_main_menu(mut commands: Commands, assets: Res<AssetServer>) {
commands.spawn(Camera2dBundle::default());
Expand All @@ -61,16 +63,16 @@ fn draw_main_menu(mut commands: Commands, assets: Res<AssetServer>) {
node(c_main_menu, p, |p| {
text("The Tales our\nAncestors Told", (), c_title_test, p);

buttoni(c_button, MyButton, p, |p| {
buttoni(c_button, MyButton::SinglePlayer, p, |p| {
text("Single Player", (), c_button_text, p);
});
buttoni(c_button, MyButton, p, |p| {
buttoni(c_button, MyButton::MultiPlayer, p, |p| {
text("Multi Player", (), c_button_text, p);
});
buttoni(c_button, MyButton, p, |p| {
buttoni(c_button, MyButton::Settings, p, |p| {
text("Settings", (), c_button_text, p);
});
buttoni(c_button, (QuitButton, MyButton), p, |p| {
buttoni(c_button, MyButton::Quit, p, |p| {
text("Quit", (), c_button_text, p);
});
});
Expand All @@ -93,12 +95,14 @@ fn button_interaction(
}

fn quit_interaction(
query: Query<&Interaction, (Changed<Interaction>, With<QuitButton>)>,
query: Query<(&Interaction, &MyButton), Changed<Interaction>>,
mut exit_event: ResMut<Events<AppExit>>,
) {
for interaction in &query {
if let Interaction::Pressed = interaction {
exit_event.send(AppExit)
for (interaction, button) in &query {
if let MyButton::Quit = button {
if let Interaction::Pressed = interaction {
exit_event.send(AppExit)
}
}
}
}
Expand Down

0 comments on commit a3c3528

Please sign in to comment.