-
Notifications
You must be signed in to change notification settings - Fork 54
Add pause menu #419
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add pause menu #419
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,88 @@ | ||
// Disable console on Windows for non-dev builds. | ||
#![cfg_attr(not(feature = "dev"), windows_subsystem = "windows")] | ||
// Support configuring Bevy lints within code. | ||
#![cfg_attr(bevy_lint, feature(register_tool), register_tool(bevy))] | ||
// Disable console on Windows for non-dev builds. | ||
#![cfg_attr(not(feature = "dev"), windows_subsystem = "windows")] | ||
|
||
use bevy::prelude::*; | ||
use {{crate_name}}::AppPlugin; | ||
mod asset_tracking; | ||
mod audio; | ||
mod demo; | ||
#[cfg(feature = "dev")] | ||
mod dev_tools; | ||
mod menus; | ||
mod screens; | ||
mod theme; | ||
|
||
use bevy::{asset::AssetMetaCheck, prelude::*}; | ||
|
||
fn main() -> AppExit { | ||
App::new().add_plugins(AppPlugin).run() | ||
} | ||
|
||
pub struct AppPlugin; | ||
|
||
impl Plugin for AppPlugin { | ||
fn build(&self, app: &mut App) { | ||
// Order new `AppSystems` variants by adding them here: | ||
app.configure_sets( | ||
Update, | ||
( | ||
AppSystems::TickTimers, | ||
AppSystems::RecordInput, | ||
AppSystems::Update, | ||
) | ||
.chain(), | ||
); | ||
|
||
// Spawn the main camera. | ||
app.add_systems(Startup, spawn_camera); | ||
|
||
// Add Bevy plugins. | ||
app.add_plugins( | ||
DefaultPlugins | ||
.set(AssetPlugin { | ||
// Wasm builds will check for meta files (that don't exist) if this isn't set. | ||
// This causes errors and even panics on web build on itch. | ||
// See https://github.com/bevyengine/bevy_github_ci_template/issues/48. | ||
meta_check: AssetMetaCheck::Never, | ||
..default() | ||
}) | ||
.set(WindowPlugin { | ||
primary_window: Window { | ||
title: "{{project-name | title_case}}".to_string(), | ||
fit_canvas_to_parent: true, | ||
..default() | ||
} | ||
.into(), | ||
..default() | ||
}), | ||
); | ||
|
||
// Add other plugins. | ||
app.add_plugins(( | ||
asset_tracking::plugin, | ||
demo::plugin, | ||
#[cfg(feature = "dev")] | ||
dev_tools::plugin, | ||
menus::plugin, | ||
screens::plugin, | ||
theme::plugin, | ||
)); | ||
} | ||
} | ||
|
||
/// High-level groupings of systems for the app in the `Update` schedule. | ||
/// When adding a new variant, make sure to order it in the `configure_sets` | ||
/// call above. | ||
#[derive(SystemSet, Debug, Clone, Copy, Eq, PartialEq, Hash, PartialOrd, Ord)] | ||
enum AppSystems { | ||
/// Tick timers. | ||
TickTimers, | ||
/// Record player input. | ||
RecordInput, | ||
/// Do everything else (consider splitting this into further variants). | ||
Update, | ||
} | ||
|
||
fn spawn_camera(mut commands: Commands) { | ||
commands.spawn((Name::new("Camera"), Camera2d)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
//! The main menu (seen on the title screen). | ||
|
||
use bevy::prelude::*; | ||
|
||
use crate::{asset_tracking::ResourceHandles, menus::Menu, screens::Screen, theme::widget}; | ||
|
||
pub(super) fn plugin(app: &mut App) { | ||
app.add_systems(OnEnter(Menu::Main), spawn_main_menu); | ||
} | ||
|
||
fn spawn_main_menu(mut commands: Commands) { | ||
commands.spawn(( | ||
widget::ui_root("Main Menu"), | ||
StateScoped(Menu::Main), | ||
#[cfg(not(target_family = "wasm"))] | ||
children![ | ||
widget::button("Play", enter_loading_or_gameplay_screen), | ||
widget::button("Settings", open_settings_menu), | ||
widget::button("Credits", open_credits_menu), | ||
widget::button("Exit", exit_app), | ||
], | ||
#[cfg(target_family = "wasm")] | ||
children![ | ||
widget::button("Play", enter_loading_or_gameplay_screen), | ||
widget::button("Settings", open_settings_menu), | ||
widget::button("Credits", open_credits_menu), | ||
], | ||
)); | ||
} | ||
|
||
fn enter_loading_or_gameplay_screen( | ||
_: Trigger<Pointer<Click>>, | ||
resource_handles: Res<ResourceHandles>, | ||
mut next_screen: ResMut<NextState<Screen>>, | ||
) { | ||
if resource_handles.is_all_done() { | ||
next_screen.set(Screen::Gameplay); | ||
} else { | ||
next_screen.set(Screen::Loading); | ||
} | ||
} | ||
|
||
fn open_settings_menu(_: Trigger<Pointer<Click>>, mut next_menu: ResMut<NextState<Menu>>) { | ||
next_menu.set(Menu::Settings); | ||
} | ||
|
||
fn open_credits_menu(_: Trigger<Pointer<Click>>, mut next_menu: ResMut<NextState<Menu>>) { | ||
next_menu.set(Menu::Credits); | ||
} | ||
|
||
#[cfg(not(target_family = "wasm"))] | ||
fn exit_app(_: Trigger<Pointer<Click>>, mut app_exit: EventWriter<AppExit>) { | ||
app_exit.write(AppExit::Success); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.