From 53061388bfdeabfca2321a322f0af09dbe652779 Mon Sep 17 00:00:00 2001 From: IDEDARY Date: Sat, 7 Sep 2024 19:53:36 +0200 Subject: [PATCH 1/2] Bumped Bevy version --- Cargo.toml | 6 +++--- README.md | 4 ++-- crates/bevy_lunex/README.md | 4 ++-- examples/mesh2d/Cargo.toml | 2 +- examples/minimal/Cargo.toml | 2 +- examples/worldspace/Cargo.toml | 2 +- examples/worldspace_text/Cargo.toml | 2 +- 7 files changed, 11 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d09b146..21d312b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -33,7 +33,7 @@ indexmap = { version = "^2.1" } thiserror = { version = "^1.0" } - bevy = { version = "^0.14.0", default-features = false, features = [ + bevy = { version = "^0.14", default-features = false, features = [ "bevy_pbr", "bevy_sprite", "bevy_text", @@ -41,5 +41,5 @@ "bevy_gizmos", ] } - bevy_kira_audio = { version = "^0.20.0" } - bevy_mod_picking = { version = "^0.20.0", default-features = false, features = ["selection", "backend_raycast"] } \ No newline at end of file + bevy_kira_audio = { version = "^0.20" } + bevy_mod_picking = { version = "^0.20", default-features = false, features = ["selection", "backend_raycast"] } \ No newline at end of file diff --git a/README.md b/README.md index 637c9ed..13abdcb 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@
- + @@ -89,7 +89,7 @@ For production ready example/template check out [`Bevypunk source code`](https:/ | Bevy | Bevy Lunex | |--------|-----------------| -| 0.14.0 | 0.2.0 - 0.2.3 | +| ^ 0.14 | 0.2.0 - 0.2.3 | | 0.13.2 | 0.1.0 | | 0.12.1 | 0.0.10 - 0.0.11 | | 0.12.0 | 0.0.7 - 0.0.9 | diff --git a/crates/bevy_lunex/README.md b/crates/bevy_lunex/README.md index 637c9ed..13abdcb 100644 --- a/crates/bevy_lunex/README.md +++ b/crates/bevy_lunex/README.md @@ -2,7 +2,7 @@
- + @@ -89,7 +89,7 @@ For production ready example/template check out [`Bevypunk source code`](https:/ | Bevy | Bevy Lunex | |--------|-----------------| -| 0.14.0 | 0.2.0 - 0.2.3 | +| ^ 0.14 | 0.2.0 - 0.2.3 | | 0.13.2 | 0.1.0 | | 0.12.1 | 0.0.10 - 0.0.11 | | 0.12.0 | 0.0.7 - 0.0.9 | diff --git a/examples/mesh2d/Cargo.toml b/examples/mesh2d/Cargo.toml index 1f28e10..0479e70 100644 --- a/examples/mesh2d/Cargo.toml +++ b/examples/mesh2d/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] - bevy = { version = "^0.14.0", default-features = false, features = [ + bevy = { version = "^0.14", default-features = false, features = [ "bevy_asset", "bevy_gilrs", "bevy_winit", diff --git a/examples/minimal/Cargo.toml b/examples/minimal/Cargo.toml index 0f299af..3ac8501 100644 --- a/examples/minimal/Cargo.toml +++ b/examples/minimal/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] - bevy = { version = "^0.14.0", default-features = false, features = [ + bevy = { version = "^0.14", default-features = false, features = [ "bevy_asset", "bevy_gilrs", "bevy_winit", diff --git a/examples/worldspace/Cargo.toml b/examples/worldspace/Cargo.toml index 8352820..20cf949 100644 --- a/examples/worldspace/Cargo.toml +++ b/examples/worldspace/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] - bevy = { version = "^0.14.0", default-features = false, features = [ + bevy = { version = "^0.14", default-features = false, features = [ "bevy_asset", "bevy_winit", "bevy_core_pipeline", diff --git a/examples/worldspace_text/Cargo.toml b/examples/worldspace_text/Cargo.toml index ee3acb4..507983a 100644 --- a/examples/worldspace_text/Cargo.toml +++ b/examples/worldspace_text/Cargo.toml @@ -6,7 +6,7 @@ publish = false [dependencies] - bevy = { version = "^0.14.0", default-features = false, features = [ + bevy = { version = "^0.14", default-features = false, features = [ "bevy_asset", "bevy_winit", "bevy_core_pipeline", From 70fc7698d45407d9d42cb2c921b329124954b7f2 Mon Sep 17 00:00:00 2001 From: IDEDARY Date: Sun, 8 Sep 2024 19:37:37 +0200 Subject: [PATCH 2/2] Changed UiPlugin to UiDefaultPlugins --- crates/bevy_lunex/src/lib.rs | 79 ++++++++++++++++++--- crates/bevy_lunex/src/logic/mod.rs | 25 ++++++- crates/bevy_lunex/src/picking.rs | 5 +- crates/bevy_lunex/src/systems.rs | 19 ++--- docs/src/advanced/abstraction/components.md | 2 +- docs/src/advanced/interactivity.md | 6 +- docs/src/quick_start.md | 4 +- examples/mesh2d/src/main.rs | 2 +- examples/minimal/src/main.rs | 2 +- examples/worldspace/src/main.rs | 2 +- examples/worldspace_text/src/main.rs | 2 +- 11 files changed, 111 insertions(+), 37 deletions(-) diff --git a/crates/bevy_lunex/src/lib.rs b/crates/bevy_lunex/src/lib.rs index 54d2b47..3d84ea9 100644 --- a/crates/bevy_lunex/src/lib.rs +++ b/crates/bevy_lunex/src/lib.rs @@ -6,6 +6,7 @@ // #=== IMPORTS FOR THIS CRATE ===# pub (crate) use std::{borrow::Borrow, marker::PhantomData}; +use bevy::app::PluginGroupBuilder; pub (crate) use bevy::prelude::*; pub (crate) use lunex_engine::prelude::*; pub (crate) use bevy_mod_picking::prelude::*; @@ -18,17 +19,71 @@ pub (crate) use colored::Colorize; // #======================# // #=== GENERAL PLUGIN ===# -/// Plugin implementing general logic. -pub struct UiPlugin; -impl Plugin for UiPlugin { - fn build(&self, app: &mut App) { +/// Plugin group implementing generic logic for given marker. +#[derive(Debug, Default, Clone)] +pub struct UiGenericPlugins (PhantomData, PhantomData); +impl UiGenericPlugins { + pub fn new() -> Self { + UiGenericPlugins::(PhantomData, PhantomData) + } +} +impl PluginGroup for UiGenericPlugins { + fn build(self) -> PluginGroupBuilder { + let mut builder = PluginGroupBuilder::start::(); + + // Add core logic + builder = builder.add(UiCorePlugin::::new()); + + // Add functionality logic + builder = builder.add(UiStateLogicPlugin::::new()); + + // Add debug logic #[cfg(feature = "debug")] - app.add_plugins(UiDebugPlugin::::new()); + {builder = builder.add(UiDebugPlugin::::new());} + + // Return the plugin group + builder + } +} + + +/// Plugin group implementing minimal default logic. +pub struct UiMinimalPlugins; +impl PluginGroup for UiMinimalPlugins { + fn build(self) -> PluginGroupBuilder { + let mut builder = PluginGroupBuilder::start::(); + + // Add core logic + builder = builder.add(UiCorePlugin::::new()); + + // Add debug logic + #[cfg(feature = "debug")] + {builder = builder.add(UiDebugPlugin::::new());} + + // Return the plugin group + builder + } +} + + +/// Plugin group implementing all UI logic + required plugins for other functionality to work, including picking. +pub struct UiDefaultPlugins; +impl PluginGroup for UiDefaultPlugins { + fn build(self) -> PluginGroupBuilder { + let mut builder = PluginGroupBuilder::start::(); + + // Add default MainUi plugins + builder = builder.add_group(UiGenericPlugins::::new()); + + // Add non generic state logic + builder = builder.add(UiLogicPlugin); + + // Add picking + builder = builder.add(UiLunexPickingPlugin); + builder = builder.add_group(DefaultPickingPlugins.build().disable::()); - app - .add_plugins(UiGenericPlugin::::new()) - .add_plugins(LunexBackend) - .add_plugins(LogicPlugin); + // Return the plugin group + builder } } @@ -57,8 +112,10 @@ pub mod prelude { pub use super::logic::*; // BEVY-LUNEX SPECIFIC - pub use super::UiPlugin; - pub use super::systems::{UiSystems, UiGenericPlugin, UiDebugPlugin}; + pub use super::UiGenericPlugins; + pub use super::UiMinimalPlugins; + pub use super::UiDefaultPlugins; + pub use super::systems::{UiSystems, UiDebugPlugin}; pub use super::structs::*; pub use super::PickingPortal; diff --git a/crates/bevy_lunex/src/logic/mod.rs b/crates/bevy_lunex/src/logic/mod.rs index 7838ea0..dd6a8e2 100644 --- a/crates/bevy_lunex/src/logic/mod.rs +++ b/crates/bevy_lunex/src/logic/mod.rs @@ -18,10 +18,11 @@ pub use style::*; // #=== LOGIC PLUGIN ===# use bevy::prelude::*; +use crate::*; /// Plugin adding all our route logic -pub struct LogicPlugin; -impl Plugin for LogicPlugin { +pub struct UiLogicPlugin; +impl Plugin for UiLogicPlugin { fn build(&self, app: &mut App) { app .add_plugins(ActionsPlugin) @@ -30,4 +31,24 @@ impl Plugin for LogicPlugin { .add_plugins(DefaultStatesPlugin) .add_plugins(StylePlugin); } +} + +/// Plugin adding all our route logic +#[derive(Debug, Default, Clone)] +pub struct UiStateLogicPlugin (PhantomData, PhantomData); +impl UiStateLogicPlugin { + pub fn new() -> Self { + UiStateLogicPlugin::(PhantomData, PhantomData) + } +} +impl Plugin for UiStateLogicPlugin { + fn build(&self, app: &mut App) { + app + //.add_plugins(StatePlugin::::new()) + .add_plugins(StatePlugin::::new()) + .add_plugins(StatePlugin::::new()) + .add_plugins(StatePlugin::::new()) + .add_plugins(StatePlugin::::new()) + .add_plugins(StatePlugin::::new()); + } } \ No newline at end of file diff --git a/crates/bevy_lunex/src/picking.rs b/crates/bevy_lunex/src/picking.rs index 621611c..3cbb396 100644 --- a/crates/bevy_lunex/src/picking.rs +++ b/crates/bevy_lunex/src/picking.rs @@ -13,11 +13,10 @@ use crate::{Dimension, Element}; /// Adds picking support for [`bevy_lunex`]. #[derive(Clone)] -pub struct LunexBackend; -impl Plugin for LunexBackend { +pub struct UiLunexPickingPlugin; +impl Plugin for UiLunexPickingPlugin { fn build(&self, app: &mut App) { app - .add_plugins(DefaultPickingPlugins.build().disable::()) .add_systems(PreUpdate, lunex_picking.in_set(PickSet::Backend)) .add_systems(Update, rendered_texture_picking); } diff --git a/crates/bevy_lunex/src/systems.rs b/crates/bevy_lunex/src/systems.rs index c8b50dc..fdc8bd3 100644 --- a/crates/bevy_lunex/src/systems.rs +++ b/crates/bevy_lunex/src/systems.rs @@ -533,7 +533,7 @@ pub enum UiSystems { /// ``` /// App::new() /// .add_plugins(DefaultPlugins) -/// .add_plugins(UiGenericPlugin::::new()) +/// .add_plugins(UiCorePlugin::::new()) /// .run(); /// ``` /// *3. Use the [`UiTree`] freely* @@ -545,13 +545,13 @@ pub enum UiSystems { ///# } /// ``` #[derive(Debug, Default, Clone)] -pub struct UiGenericPlugin (PhantomData, PhantomData); -impl UiGenericPlugin { +pub struct UiCorePlugin (PhantomData, PhantomData); +impl UiCorePlugin { pub fn new() -> Self { - UiGenericPlugin::(PhantomData, PhantomData) + UiCorePlugin::(PhantomData, PhantomData) } } -impl Plugin for UiGenericPlugin { +impl Plugin for UiCorePlugin { fn build(&self, app: &mut App) { app .add_systems(Update, ( @@ -562,13 +562,6 @@ impl Plugin for UiGenericPlugin { fetch_transform_from_camera::.after(touch_camera_if_uitree_added::), ).in_set(UiSystems::Modify).before(UiSystems::Send)) - //.add_plugins(StatePlugin::::new()) - .add_plugins(StatePlugin::::new()) - .add_plugins(StatePlugin::::new()) - .add_plugins(StatePlugin::::new()) - .add_plugins(StatePlugin::::new()) - .add_plugins(StatePlugin::::new()) - .add_systems(Update, ( send_layout_to_node::, send_content_size_to_node::, @@ -616,7 +609,7 @@ impl Plugin for UiGenericPlugin { /// ``` /// App::new() /// .add_plugins(DefaultPlugins) -/// .add_plugins(UiGenericPlugin::::new()) +/// .add_plugins(UiCorePlugin::::new()) /// .add_plugins(UiDebugPlugin::::new()) /// .run(); /// ``` diff --git a/docs/src/advanced/abstraction/components.md b/docs/src/advanced/abstraction/components.md index 9269a3d..15436be 100644 --- a/docs/src/advanced/abstraction/components.md +++ b/docs/src/advanced/abstraction/components.md @@ -77,7 +77,7 @@ impl Plugin for CustomButtonPlugin { fn build(&self, app: &mut App) { app // Add Lunex plugins for our sandboxed UI - .add_plugins(UiGenericPlugin::::new()) + .add_plugins(UiGenericPlugins::::new()) // NOTE! Systems changing the UI need to run before UiSystems::Compute // or they will not get picked up by change detection. diff --git a/docs/src/advanced/interactivity.md b/docs/src/advanced/interactivity.md index 3d421bb..2c48f27 100644 --- a/docs/src/advanced/interactivity.md +++ b/docs/src/advanced/interactivity.md @@ -6,7 +6,11 @@ This crate allows us to detect mouse clicks, hovers, drags, etc. ### Requirements -Please note that `Cursor2d` **MUST** be spawned for any picking to work. +* Please note that `Cursor2d` **MUST** be spawned for any picking to work. + +* `UiLunexPickingPlugin` must be added (Part of `UiDefaultPlugins` but not part of `UiMinimalPlugins`) + +* `DefaultPickingPlugins.build().disable::()` version of picking plugins must also be added (Part of `UiDefaultPlugins` but not part of `UiMinimalPlugins`) ### Getting started diff --git a/docs/src/quick_start.md b/docs/src/quick_start.md index e1b8deb..6f8bdaf 100644 --- a/docs/src/quick_start.md +++ b/docs/src/quick_start.md @@ -14,12 +14,12 @@ First import Lunex library use bevy_lunex::prelude::*; ``` -Then we add `UiPlugin` to our app. +Then we add `UiDefaultPlugins` to our app. ```rust fn main() { App::new() - .add_plugins((DefaultPlugins, UiPlugin)) + .add_plugins((DefaultPlugins, UiDefaultPlugins)) .run(); } ``` diff --git a/examples/mesh2d/src/main.rs b/examples/mesh2d/src/main.rs index 7870ade..472636c 100644 --- a/examples/mesh2d/src/main.rs +++ b/examples/mesh2d/src/main.rs @@ -4,7 +4,7 @@ use bevy_lunex::prelude::*; fn main() { App::new() - .add_plugins((DefaultPlugins, UiPlugin)) + .add_plugins((DefaultPlugins, UiMinimalPlugins)) .add_systems(Startup, setup) .run(); } diff --git a/examples/minimal/src/main.rs b/examples/minimal/src/main.rs index 77a2102..36baab2 100644 --- a/examples/minimal/src/main.rs +++ b/examples/minimal/src/main.rs @@ -4,7 +4,7 @@ use bevy_lunex::prelude::*; fn main() { App::new() - .add_plugins((DefaultPlugins, UiPlugin)) + .add_plugins((DefaultPlugins, UiMinimalPlugins)) .add_systems(Startup, setup) .run(); } diff --git a/examples/worldspace/src/main.rs b/examples/worldspace/src/main.rs index 6b0ed55..7bb7be7 100644 --- a/examples/worldspace/src/main.rs +++ b/examples/worldspace/src/main.rs @@ -7,7 +7,7 @@ use boilerplate::*; fn main() { App::new() - .add_plugins((default_plugins(), UiPlugin)) + .add_plugins((default_plugins(), UiDefaultPlugins)) .add_systems(Startup, setup) .add_systems(Update, (rotate_playercam, zoom_playercam)) .run(); diff --git a/examples/worldspace_text/src/main.rs b/examples/worldspace_text/src/main.rs index b620dd3..a0bc7bf 100644 --- a/examples/worldspace_text/src/main.rs +++ b/examples/worldspace_text/src/main.rs @@ -15,7 +15,7 @@ use boilerplate::*; fn main() { App::new() - .add_plugins((default_plugins(), UiPlugin, BillboardPlugin)) + .add_plugins((default_plugins(), UiDefaultPlugins, BillboardPlugin)) .add_systems(Startup, setup) .add_systems(Update, (rotate_playercam, zoom_playercam)) .run();