From 4384f60478cf53cae38abdd62e087f7eb47867c8 Mon Sep 17 00:00:00 2001 From: MiniaczQ Date: Thu, 11 Jul 2024 14:52:33 +0200 Subject: [PATCH] Add exit button, but not for wasm (#109) Partially: #92 --- src/screen/title.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/screen/title.rs b/src/screen/title.rs index 2c4841fb..76a3772e 100644 --- a/src/screen/title.rs +++ b/src/screen/title.rs @@ -17,6 +17,9 @@ pub(super) fn plugin(app: &mut App) { enum TitleAction { Play, Credits, + /// Exit doesn't work well with embedded applications. + #[cfg(not(target = "wasm"))] + Exit, } fn enter_title(mut commands: Commands) { @@ -26,18 +29,27 @@ fn enter_title(mut commands: Commands) { .with_children(|children| { children.button("Play").insert(TitleAction::Play); children.button("Credits").insert(TitleAction::Credits); + + #[cfg(not(target = "wasm"))] + children.button("Exit").insert(TitleAction::Exit); }); } fn handle_title_action( mut next_screen: ResMut>, mut button_query: InteractionQuery<&TitleAction>, + mut app_exit: EventWriter, ) { for (interaction, action) in &mut button_query { if matches!(interaction, Interaction::Pressed) { match action { TitleAction::Play => next_screen.set(Screen::Playing), TitleAction::Credits => next_screen.set(Screen::Credits), + + #[cfg(not(target = "wasm"))] + TitleAction::Exit => { + app_exit.send(AppExit::Success); + } } } }