Skip to content

Commit

Permalink
Update to bevy 0.12
Browse files Browse the repository at this point in the history
  • Loading branch information
nicopap committed Nov 10, 2023
1 parent 391dc5e commit 77d94a2
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 114 deletions.
24 changes: 15 additions & 9 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ repository = "https://github.com/nicopap/ui-navigation"
homepage = "https://github.com/nicopap/ui-navigation"
exclude = ["assets", ".github"]
version = "0.32.0"
rust-version = "1.70"
rust-version = "1.73"
edition = "2021"

[features]
Expand All @@ -21,18 +21,24 @@ pointer_focus = ["bevy_mod_picking"]
cuicui_chirp = ["cuicui_dsl", "dep:cuicui_chirp"]

[dependencies]
bevy = { version = "0.11", default-features = false, features = ["bevy_asset"] }
bevy_mod_picking = { version = "0.15.0", optional = true, default-features = false }
cuicui_chirp = { version = "0.10.0", optional = true, default-features = false, features = ["macros"] }
cuicui_dsl = { version = "0.10.0", optional = true }
bevy = { version = "0.12", default-features = false, features = ["bevy_asset"] }
bevy_mod_picking = { version = "0.17.0", optional = true, default-features = false }
cuicui_chirp = { version = "0.12.0", optional = true, default-features = false, features = ["macros"] }
cuicui_dsl = { version = "0.12.0", optional = true }
non-empty-vec = { version = "0.2.2", default-features = false }

[dev-dependencies]
fastrand = "1.7"
cuicui_layout_bevy_ui = { version = "0.10.0", default-features = false }
cuicui_layout = { version = "0.10.0", default-features = false }
bevy = { version = "0.11", default-features = false, features = ["bevy_asset", "png", "x11", "default_font"] }
cuicui_layout_bevy_ui = { version = "0.12.0", default-features = false }
cuicui_layout = { version = "0.12.0", default-features = false }
bevy = { version = "0.12", default-features = false, features = ["bevy_asset", "png", "x11", "default_font", "bevy_gilrs"] }

[package.metadata.release]
pre-release-replacements = [
{search="\\| 0.12 \\| [0-9.]* \\|",replace="| 0.12 | {{version}} |",file="Readme.md"},
{search="bevy-ui-navigation = \"[0-9.]*\"",replace="bevy-ui-navigation = \"{{version}}\"",file="Readme.md"},
]

[[example]]
name = "ultimate_menu_navigation"
required-features = ["cuicui_chirp", "bevy/filesystem_watcher", "cuicui_layout_bevy_ui/chirp", "cuicui_layout/reflect"]
required-features = ["cuicui_chirp", "cuicui_layout_bevy_ui/chirp"]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ check:
cargo clippy --examples

run:
cargo run --example ultimate_menu_navigation --features cuicui_dsl
cargo run --example ultimate_menu_navigation --features="cuicui_chirp cuicui_layout_bevy_ui/chirp"

pre-hook:
cargo fmt --all -- --check
cargo clippy --no-default-features -- --deny clippy::all -D warnings
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps --all-features
cargo clippy --all-features -- --deny clippy::all -D warnings
cargo test --all-features
cargo clippy --all-features --features="cuicui_chirp bevy/filesystem_watcher cuicui_layout_bevy_ui/chirp cuicui_layout/reflect" --example ultimate_menu_navigation
cargo clippy --all-features --features="cuicui_chirp cuicui_layout_bevy_ui/chirp" --example ultimate_menu_navigation
25 changes: 4 additions & 21 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,9 @@ fn return_trigger_action(mut requests: EventWriter<NavRequest>, input: Res<Input
* Upgrade to `cuicui_dsl v0.10.0`
* Add `cuicui_chirp` support
* Add `ParseDsl` impl for `NavigationDsl`
* `0.33.0`: **BREAKING**:
* Upgrade to `cuicui v0.12.0`
* Upgrade to `bevy v0.12.0`

[the RFC PR]: https://github.com/bevyengine/bevy/pull/5378
[diff-18-19]: https://github.com/nicopap/ui-navigation/compare/v0.18.0...v0.19.0
Expand Down Expand Up @@ -629,37 +632,17 @@ fn return_trigger_action(mut requests: EventWriter<NavRequest>, input: Res<Input

| bevy | latest supporting version |
|------|--------|
| 0.12 | 0.32.0 |
| 0.11 | 0.32.0 |
| 0.10 | 0.24.1 |
| 0.9 | 0.23.1 |
| 0.8 | 0.21.0 |
| 0.7 | 0.18.0 |
| 0.6 | 0.14.0 |

### Notes on API Stability

In the 4th week of January, there has been 5 breaking version changes. `0.13.0`
marks the end of this wave of API changes. And things should go much slower in
the future.

The new `NavMenu` construction system helps adding orthogonal features to the
library without breaking API changes. However, since bevy is still in `0.*`
territory, it doesn't make sense for this library to leave the `0.*` range.

Also, the way cargo handles versioning for `0.*` crates is in infraction of
the semver specification. Meaning that additional features without breakages
requires bumping the minor version rather than the patch version (as should
pre-`1.` versions do).


# License

Copyright © 2022 Nicola Papale

This software is licensed under either MIT or Apache 2.0 at your leisure. See
licenses directory for details.

### Font

The font in `font.ttf` is derived from Adobe SourceSans, licensed
under the SIL OFL. see file at `licenses/SIL Open Font License.txt`.
Binary file removed assets/font.ttf
Binary file not shown.
23 changes: 6 additions & 17 deletions examples/infinite_upgrades.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ fn main() {
.add_systems(PostUpdate, mark_buttons)
.add_systems(Startup, setup)
// Our systems.
.init_resource::<MenuFont>()
.init_resource::<MenuMap>()
.run();
}
Expand Down Expand Up @@ -134,15 +133,6 @@ impl MenuMap {
}
}

#[derive(Resource)]
struct MenuFont(Handle<Font>);
impl FromWorld for MenuFont {
fn from_world(world: &mut World) -> Self {
let assets = world.get_resource::<AssetServer>().unwrap();
MenuFont(assets.load("font.ttf"))
}
}

/// Animate anything. Used to move the camera smoothly.
///
/// See the `animate_system` for how this is used.
Expand Down Expand Up @@ -380,7 +370,7 @@ const QUALIFICATIVES: &[&str] = &[
//
// === === ===

fn setup(mut commands: Commands, font: Res<MenuFont>, mut menus: ResMut<MenuMap>) {
fn setup(mut commands: Commands, mut menus: ResMut<MenuMap>) {
let name = NAMES[fastrand::usize(0..NAMES.len())];
let upgrade = if fastrand::bool() {
Upgrade::Roman(1)
Expand All @@ -390,7 +380,7 @@ fn setup(mut commands: Commands, font: Res<MenuFont>, mut menus: ResMut<MenuMap>
let weapon = Weapon::new(name, upgrade);
commands.spawn((Camera2dBundle::default(), Animate::default()));
let at = IVec2::ZERO;
let menu = spawn_weapon_upgrade_menu(&mut commands, at, &weapon, &font, None);
let menu = spawn_weapon_upgrade_menu(&mut commands, at, &weapon, None);
menus.grid.insert(at, menu);
}

Expand Down Expand Up @@ -452,7 +442,7 @@ fn handle_menu_change(
menu_position: Query<&GlobalTransform, With<Menu>>,
menu_query: Query<&ParentMenu>,
) {
for event in nav_events.iter() {
for event in nav_events.read() {
if let NavEvent::FocusChanged { to, from } = event {
let menu_query = (menu_query.get(*from.first()), menu_query.get(*to.first()));
if let (Ok(from), Ok(to)) = menu_query {
Expand Down Expand Up @@ -481,7 +471,7 @@ fn upgrade_weapon(
mut commands: Commands,
mut events: EventReader<NavEvent>,
mut requests: EventWriter<NavRequest>,
(mut menus, time, font): (ResMut<MenuMap>, Res<Time>, Res<MenuFont>),
(mut menus, time): (ResMut<MenuMap>, Res<Time>),
mut cam: Query<&mut Animate, With<Camera2d>>,
query: Query<(&ParentMenu, &WeaponUpgrade, &SpawnDirection, Entity)>,
menu_data: Query<&Menu>,
Expand All @@ -502,7 +492,7 @@ fn upgrade_weapon(
// `Menu.weapon`, but instead reads the `WeaponUpgrade` component of all
// focusable in the `from` field of `NavEvent::NoChanges` to generate
// the current weapon upgrade.
let menu = spawn_weapon_upgrade_menu(&mut commands, at, &weapon, &font, Some(entity));
let menu = spawn_weapon_upgrade_menu(&mut commands, at, &weapon, Some(entity));
menus.grid.insert(at, menu);
requests.send(NavRequest::Action);
} else {
Expand Down Expand Up @@ -558,7 +548,6 @@ fn spawn_weapon_upgrade_menu(
commands: &mut Commands,
position: IVec2,
weapon: &Weapon,
font: &MenuFont,
parent: Option<Entity>,
) -> Entity {
let quals = QUALIFICATIVES.len();
Expand All @@ -568,9 +557,9 @@ fn spawn_weapon_upgrade_menu(
let menu_grid_offset = Vec2::new(MENU_WIDTH, MENU_HEIGHT) + MENU_GAP;
let at = position.as_vec2() * menu_grid_offset;
let text_style = || TextStyle {
font: font.0.clone_weak(),
color: Color::WHITE,
font_size: FONT_SIZE,
..default()
};
let item_position = |at: Vec2| Transform::from_translation(at.extend(0.1));
// Rectangle
Expand Down
2 changes: 1 addition & 1 deletion examples/locking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ fn main() {
}

fn print_nav_events(mut events: EventReader<NavEvent>) {
for event in events.iter() {
for event in events.read() {
println!("{:?}", event);
}
}
Expand Down
2 changes: 1 addition & 1 deletion examples/menu_navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ fn handle_nav_events(
game: Res<Gameui>,
) {
use NavRequest::Action;
for event in events.iter() {
for event in events.read() {
if let NavEvent::FocusChanged { from, to } = &event {
println!("----------\nfrom: {:?}\n to: {:?}", from, to);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ fn button_system(
}
}
fn print_nav_events(mut events: EventReader<NavEvent>) {
for event in events.iter() {
for event in events.read() {
println!("{:?}", event);
}
}
Expand Down
17 changes: 9 additions & 8 deletions examples/ultimate_menu_navigation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ struct UltimateMenuDsl {
#[parse_dsl_impl(delegate = inner)]
impl UltimateMenuDsl {}
impl DslBundle for UltimateMenuDsl {
fn insert(&mut self, cmds: &mut EntityCommands) -> Entity {
self.inner.insert(cmds)
fn insert(&mut self, cmds: &mut EntityCommands) {
self.inner.insert(cmds);
}
}

Expand All @@ -37,14 +37,15 @@ impl DslBundle for UltimateMenuDsl {
///
/// Navigation also works with controller
fn main() {
let primary_window = Some(Window {
resolution: (1280., 720.).into(),
..default()
});
App::new()
.add_plugins((
DefaultPlugins.set({
let delay = std::time::Duration::from_millis(200);
AssetPlugin {
watch_for_changes: bevy::asset::ChangeWatcher::with_delay(delay),
..default()
}
DefaultPlugins.set(WindowPlugin {
primary_window,
..default()
}),
DefaultNavigationPlugins,
cuicui_chirp::loader::Plugin::new::<UltimateMenuDsl>(),
Expand Down
43 changes: 0 additions & 43 deletions licenses/SIL Open Font License.txt

This file was deleted.

3 changes: 1 addition & 2 deletions src/dsl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl<C> NavigationDsl<C> {
}
}
impl<C: DslBundle> DslBundle for NavigationDsl<C> {
fn insert(&mut self, cmds: &mut EntityCommands) -> Entity {
fn insert(&mut self, cmds: &mut EntityCommands) {
self.inner.insert(cmds);
if let Some(menu) = self.menu.take() {
let builder = match menu.reachable_from {
Expand All @@ -110,6 +110,5 @@ impl<C: DslBundle> DslBundle for NavigationDsl<C> {
};
cmds.insert(focusable);
}
cmds.id()
}
}
4 changes: 2 additions & 2 deletions src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ impl<'w, 's, 'a> NavEventReader<'w, 's, 'a> {
/// triggered by `request` type requests.
pub fn with_request(&mut self, request: NavRequest) -> impl Iterator<Item = Entity> + '_ {
self.event_reader
.iter()
.read()
.filter_map(move |nav_event| match nav_event {
NavEvent::NoChanges {
from,
Expand All @@ -254,7 +254,7 @@ impl<'w, 's, 'a> NavEventReader<'w, 's, 'a> {
/// with the "relevant" entity of the event.
pub fn types(&mut self) -> impl Iterator<Item = (&NavEvent, Entity)> + '_ {
use NavEvent::{FocusChanged, InitiallyFocused, Locked, NoChanges, Unlocked};
self.event_reader.iter().filter_map(|event| {
self.event_reader.read().filter_map(|event| {
let entity = match event {
NoChanges { from, .. } => Some(*from.first()),
InitiallyFocused(initial) => Some(*initial),
Expand Down
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ impl<T: 'static + Sync + Send + Component + Clone> Plugin for NavMarkerPropagati
/// # fn button_system() {}
/// fn main() {
/// App::new()
/// .add_plugin(GenericNavigationPlugin::<MoveCursor3d>::new())
/// .add_plugins(GenericNavigationPlugin::<MoveCursor3d>::new())
/// // ...
/// // Add the button color update system after the focus update system
/// .add_system(button_system.after(NavRequestSystem))
/// .add_systems(Update, button_system.after(NavRequestSystem))
/// // ...
/// .run();
/// }
Expand All @@ -165,7 +165,7 @@ pub struct NavRequestSystem;

/// The navigation plugin.
///
/// Add it to your app with `.add_plugin(NavigationPlugin::new())` and send
/// Add it to your app with `.add_plugins(NavigationPlugin::new())` and send
/// [`NavRequest`]s to move focus within declared [`Focusable`] entities.
///
/// You should prefer `bevy_ui` provided defaults
Expand Down Expand Up @@ -250,7 +250,7 @@ impl PluginGroup for DefaultNavigationPlugins {
mod test {
use crate::prelude::*;
use bevy::{
ecs::{event::Event, world::EntityMut},
ecs::{event::Event, world::EntityWorldMut},
prelude::*,
};

Expand Down Expand Up @@ -297,7 +297,7 @@ mod test {
}

impl SpawnFocusable {
fn spawn(self, mut entity: EntityMut) {
fn spawn(self, mut entity: EntityWorldMut) {
let SpawnFocusable {
name,
prioritized,
Expand All @@ -324,7 +324,7 @@ mod test {
children: Vec<SpawnFocusable>,
}
impl SpawnMenu {
fn spawn(self, entity: &mut EntityMut) {
fn spawn(self, entity: &mut EntityWorldMut) {
let SpawnMenu { name, children } = self;
let parent_focusable = name.strip_suffix(" Menu");
let menu_builder = match parent_focusable {
Expand Down
2 changes: 1 addition & 1 deletion src/resolve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -907,7 +907,7 @@ pub(crate) fn listen_nav_requests<STGY: SystemParam>(

// Cache focus result from previous iteration to avoid re-running costly `pick_first_focused`
let mut computed_focused = None;
for request in requests.iter() {
for request in requests.read() {
if lock.is_locked() && *request != NavRequest::Unlock {
continue;
}
Expand Down

0 comments on commit 77d94a2

Please sign in to comment.