Added quit and resume buttons toESC menu. With functionality
This commit is contained in:
parent
331fb31c40
commit
20c37e1439
@ -15,6 +15,8 @@ impl Plugin for MainGameUIPlugin {
|
|||||||
fps_counter::setup_fps_counter));
|
fps_counter::setup_fps_counter));
|
||||||
app.add_systems(Update, (
|
app.add_systems(Update, (
|
||||||
settings_screen::toggle_settings_screen,
|
settings_screen::toggle_settings_screen,
|
||||||
fps_counter::tick_fps_counter));
|
settings_screen::handle_settings_button_click,
|
||||||
|
fps_counter::tick_fps_counter,
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,10 +1,16 @@
|
|||||||
use bevy::{prelude::*, ui::FocusPolicy};
|
use bevy::{prelude::*, ui::FocusPolicy, app::AppExit};
|
||||||
|
|
||||||
use super::settings::SettingsScreenUIConfiguration;
|
use super::settings::SettingsScreenUIConfiguration;
|
||||||
|
|
||||||
#[derive(Component)]
|
#[derive(Component)]
|
||||||
pub struct SettingsScreenMarker;
|
pub struct SettingsScreenMarker;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub enum SettingsScreenActions {
|
||||||
|
Resume,
|
||||||
|
Quit,
|
||||||
|
}
|
||||||
|
|
||||||
pub fn setup_settings_screen(mut commands: Commands) {
|
pub fn setup_settings_screen(mut commands: Commands) {
|
||||||
commands.spawn(
|
commands.spawn(
|
||||||
NodeBundle {
|
NodeBundle {
|
||||||
@ -14,6 +20,7 @@ pub fn setup_settings_screen(mut commands: Commands) {
|
|||||||
height: Val::Percent(100.0),
|
height: Val::Percent(100.0),
|
||||||
justify_content: JustifyContent::Center,
|
justify_content: JustifyContent::Center,
|
||||||
align_items: AlignItems::Center,
|
align_items: AlignItems::Center,
|
||||||
|
flex_direction: FlexDirection::Column,
|
||||||
..Default::default()
|
..Default::default()
|
||||||
},
|
},
|
||||||
visibility: Visibility::Hidden,
|
visibility: Visibility::Hidden,
|
||||||
@ -21,7 +28,47 @@ pub fn setup_settings_screen(mut commands: Commands) {
|
|||||||
focus_policy: FocusPolicy::Block,
|
focus_policy: FocusPolicy::Block,
|
||||||
..Default::default()
|
..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(
|
pub fn toggle_settings_screen(
|
||||||
@ -39,4 +86,28 @@ 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => {}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user