Added quit and resume buttons toESC menu. With functionality

This commit is contained in:
Franklin 2023-11-07 13:47:06 -04:00
parent 331fb31c40
commit 20c37e1439
2 changed files with 76 additions and 3 deletions

View File

@ -15,6 +15,8 @@ impl Plugin for MainGameUIPlugin {
fps_counter::setup_fps_counter));
app.add_systems(Update, (
settings_screen::toggle_settings_screen,
fps_counter::tick_fps_counter));
settings_screen::handle_settings_button_click,
fps_counter::tick_fps_counter,
));
}
}

View File

@ -1,10 +1,16 @@
use bevy::{prelude::*, ui::FocusPolicy};
use bevy::{prelude::*, ui::FocusPolicy, app::AppExit};
use super::settings::SettingsScreenUIConfiguration;
#[derive(Component)]
pub struct SettingsScreenMarker;
#[derive(Component)]
pub enum SettingsScreenActions {
Resume,
Quit,
}
pub fn setup_settings_screen(mut commands: Commands) {
commands.spawn(
NodeBundle {
@ -14,6 +20,7 @@ pub fn setup_settings_screen(mut commands: Commands) {
height: Val::Percent(100.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
flex_direction: FlexDirection::Column,
..Default::default()
},
visibility: Visibility::Hidden,
@ -21,7 +28,47 @@ pub fn setup_settings_screen(mut commands: Commands) {
focus_policy: FocusPolicy::Block,
..Default::default()
}
).insert(SettingsScreenMarker);
)
.insert(SettingsScreenMarker)
.with_children(|parent| {
// RESUME BUTTON
parent.spawn(
ButtonBundle {
style: Style {
..Default::default()
},
background_color: BackgroundColor(Color::NONE),
//focus_policy: FocusPolicy::Block,
..Default::default()
}
)
.insert(SettingsScreenActions::Resume)
.with_children(|parent| {
parent.spawn(TextBundle {
text: Text::from_section("Resume", TextStyle { font_size: 32.0, ..Default::default() }),
..Default::default()
});
});
// QUIT BUTTON
parent.spawn(
ButtonBundle {
style: Style {
..Default::default()
},
background_color: BackgroundColor(Color::NONE),
//focus_policy: FocusPolicy::Block,
..Default::default()
}
)
.insert(SettingsScreenActions::Quit)
.with_children(|parent| {
parent.spawn(TextBundle {
text: Text::from_section("Quit", TextStyle { font_size: 32.0, ..Default::default() }),
..Default::default()
});
});
// END BUTTONS
});
}
pub fn toggle_settings_screen(
@ -40,3 +87,27 @@ pub fn toggle_settings_screen(
}
}
}
pub fn handle_settings_button_click(
query: Query<(&Interaction, &SettingsScreenActions), Changed<Interaction>>,
mut exit: EventWriter<AppExit>,
mut settings: ResMut<SettingsScreenUIConfiguration>,
) {
for (interaction, action) in query.iter() {
match interaction {
Interaction::Pressed => {
match action {
SettingsScreenActions::Quit => {
// QUIT GAME
exit.send(AppExit);
},
SettingsScreenActions::Resume => {
// RESUME GAME
settings.settings_menu_shown = false;
}
}
},
_ => {}
}
}
}