Skip to content

Commit

Permalink
Merge pull request #74 from bytestring-net/dev
Browse files Browse the repository at this point in the history
Changed UiPlugin to UiDefaultPlugins
  • Loading branch information
IDEDARY authored Sep 8, 2024
2 parents 73a4302 + 70fc769 commit 5ed60d8
Show file tree
Hide file tree
Showing 18 changed files with 122 additions and 48 deletions.
6 changes: 3 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
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",
"multi_threaded",
"bevy_gizmos",
] }

bevy_kira_audio = { version = "^0.20.0" }
bevy_mod_picking = { version = "^0.20.0", default-features = false, features = ["selection", "backend_raycast"] }
bevy_kira_audio = { version = "^0.20" }
bevy_mod_picking = { version = "^0.20", default-features = false, features = ["selection", "backend_raycast"] }
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div align="center">
<a href="https://crates.io/crates/bevy_lunex"><img src="https://img.shields.io/crates/v/bevy_lunex?label=version&color=d69039"></a>
<a href="https://crates.io/crates/bevy"><img src="https://img.shields.io/badge/v0.14.0-white.svg?label=bevy&color=bb86a5"></a>
<a href="https://crates.io/crates/bevy"><img src="https://img.shields.io/badge/v0.14.2-white.svg?label=bevy&color=bb86a5"></a>
<a href="./LICENSE-MIT"><img src="https://img.shields.io/badge/License-Apache/MIT-white.svg?label=license&color=9fcec4"></a>
<a href="https://deps.rs/crate/bevy_lunex"><img src="https://img.shields.io/badge/check-white.svg?label=deps&color=a0f6b9"></a>
<a href="https://docs.rs/bevy_lunex"><img src="https://img.shields.io/docsrs/bevy_lunex/latest?color=8df7cb"></a>
Expand Down Expand Up @@ -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 |
Expand Down
4 changes: 2 additions & 2 deletions crates/bevy_lunex/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div align="center">
<a href="https://crates.io/crates/bevy_lunex"><img src="https://img.shields.io/crates/v/bevy_lunex?label=version&color=d69039"></a>
<a href="https://crates.io/crates/bevy"><img src="https://img.shields.io/badge/v0.14.0-white.svg?label=bevy&color=bb86a5"></a>
<a href="https://crates.io/crates/bevy"><img src="https://img.shields.io/badge/v0.14.2-white.svg?label=bevy&color=bb86a5"></a>
<a href="./LICENSE-MIT"><img src="https://img.shields.io/badge/License-Apache/MIT-white.svg?label=license&color=9fcec4"></a>
<a href="https://deps.rs/crate/bevy_lunex"><img src="https://img.shields.io/badge/check-white.svg?label=deps&color=a0f6b9"></a>
<a href="https://docs.rs/bevy_lunex"><img src="https://img.shields.io/docsrs/bevy_lunex/latest?color=8df7cb"></a>
Expand Down Expand Up @@ -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 |
Expand Down
79 changes: 68 additions & 11 deletions crates/bevy_lunex/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::*;
Expand All @@ -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 <T:Component = MainUi, N:Default + Component = NoData>(PhantomData<T>, PhantomData<N>);
impl <T:Component, N:Default + Component> UiGenericPlugins<T, N> {
pub fn new() -> Self {
UiGenericPlugins::<T, N>(PhantomData, PhantomData)
}
}
impl <T:Component, N:Default + Component> PluginGroup for UiGenericPlugins<T, N> {
fn build(self) -> PluginGroupBuilder {
let mut builder = PluginGroupBuilder::start::<Self>();

// Add core logic
builder = builder.add(UiCorePlugin::<T, N>::new());

// Add functionality logic
builder = builder.add(UiStateLogicPlugin::<T, N>::new());

// Add debug logic
#[cfg(feature = "debug")]
app.add_plugins(UiDebugPlugin::<MainUi>::new());
{builder = builder.add(UiDebugPlugin::<T, N>::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::<Self>();

// Add core logic
builder = builder.add(UiCorePlugin::<MainUi>::new());

// Add debug logic
#[cfg(feature = "debug")]
{builder = builder.add(UiDebugPlugin::<MainUi>::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::<Self>();

// Add default MainUi plugins
builder = builder.add_group(UiGenericPlugins::<MainUi>::new());

// Add non generic state logic
builder = builder.add(UiLogicPlugin);

// Add picking
builder = builder.add(UiLunexPickingPlugin);
builder = builder.add_group(DefaultPickingPlugins.build().disable::<InputPlugin>());

app
.add_plugins(UiGenericPlugin::<MainUi>::new())
.add_plugins(LunexBackend)
.add_plugins(LogicPlugin);
// Return the plugin group
builder
}
}

Expand Down Expand Up @@ -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;
Expand Down
25 changes: 23 additions & 2 deletions crates/bevy_lunex/src/logic/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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 <T:Component = MainUi, N:Default + Component = NoData>(PhantomData<T>, PhantomData<N>);
impl <T:Component, N:Default + Component> UiStateLogicPlugin<T, N> {
pub fn new() -> Self {
UiStateLogicPlugin::<T, N>(PhantomData, PhantomData)
}
}
impl <T:Component, N:Default + Component> Plugin for UiStateLogicPlugin<T, N> {
fn build(&self, app: &mut App) {
app
//.add_plugins(StatePlugin::<T, N, Base>::new())
.add_plugins(StatePlugin::<T, N, Hover>::new())
.add_plugins(StatePlugin::<T, N, Clicked>::new())
.add_plugins(StatePlugin::<T, N, Selected>::new())
.add_plugins(StatePlugin::<T, N, Intro>::new())
.add_plugins(StatePlugin::<T, N, Outro>::new());
}
}
5 changes: 2 additions & 3 deletions crates/bevy_lunex/src/picking.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<InputPlugin>())
.add_systems(PreUpdate, lunex_picking.in_set(PickSet::Backend))
.add_systems(Update, rendered_texture_picking);
}
Expand Down
19 changes: 6 additions & 13 deletions crates/bevy_lunex/src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -533,7 +533,7 @@ pub enum UiSystems {
/// ```
/// App::new()
/// .add_plugins(DefaultPlugins)
/// .add_plugins(UiGenericPlugin::<MyUiWidget, MyNodeData>::new())
/// .add_plugins(UiCorePlugin::<MyUiWidget, MyNodeData>::new())
/// .run();
/// ```
/// *3. Use the [`UiTree`] freely*
Expand All @@ -545,13 +545,13 @@ pub enum UiSystems {
///# }
/// ```
#[derive(Debug, Default, Clone)]
pub struct UiGenericPlugin <T:Component = MainUi, N:Default + Component = NoData>(PhantomData<T>, PhantomData<N>);
impl <T:Component, N:Default + Component> UiGenericPlugin<T, N> {
pub struct UiCorePlugin <T:Component = MainUi, N:Default + Component = NoData>(PhantomData<T>, PhantomData<N>);
impl <T:Component, N:Default + Component> UiCorePlugin<T, N> {
pub fn new() -> Self {
UiGenericPlugin::<T, N>(PhantomData, PhantomData)
UiCorePlugin::<T, N>(PhantomData, PhantomData)
}
}
impl <T:Component, N:Default + Component> Plugin for UiGenericPlugin<T, N> {
impl <T:Component, N:Default + Component> Plugin for UiCorePlugin<T, N> {
fn build(&self, app: &mut App) {
app
.add_systems(Update, (
Expand All @@ -562,13 +562,6 @@ impl <T:Component, N:Default + Component> Plugin for UiGenericPlugin<T, N> {
fetch_transform_from_camera::<T, N>.after(touch_camera_if_uitree_added::<T, N>),
).in_set(UiSystems::Modify).before(UiSystems::Send))

//.add_plugins(StatePlugin::<T, N, Base>::new())
.add_plugins(StatePlugin::<T, N, Hover>::new())
.add_plugins(StatePlugin::<T, N, Clicked>::new())
.add_plugins(StatePlugin::<T, N, Selected>::new())
.add_plugins(StatePlugin::<T, N, Intro>::new())
.add_plugins(StatePlugin::<T, N, Outro>::new())

.add_systems(Update, (
send_layout_to_node::<T, N, Base>,
send_content_size_to_node::<T, N>,
Expand Down Expand Up @@ -616,7 +609,7 @@ impl <T:Component, N:Default + Component> Plugin for UiGenericPlugin<T, N> {
/// ```
/// App::new()
/// .add_plugins(DefaultPlugins)
/// .add_plugins(UiGenericPlugin::<MyUiWidget, MyNodeData>::new())
/// .add_plugins(UiCorePlugin::<MyUiWidget, MyNodeData>::new())
/// .add_plugins(UiDebugPlugin::<MyUiWidget, MyNodeData>::new())
/// .run();
/// ```
Expand Down
2 changes: 1 addition & 1 deletion docs/src/advanced/abstraction/components.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::<CustomButtonUi>::new())
.add_plugins(UiGenericPlugins::<CustomButtonUi>::new())

// NOTE! Systems changing the UI need to run before UiSystems::Compute
// or they will not get picked up by change detection.
Expand Down
6 changes: 5 additions & 1 deletion docs/src/advanced/interactivity.md
Original file line number Diff line number Diff line change
Expand Up @@ -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::<InputPlugin>()` version of picking plugins must also be added (Part of `UiDefaultPlugins` but not part of `UiMinimalPlugins`)

### Getting started

Expand Down
4 changes: 2 additions & 2 deletions docs/src/quick_start.md
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
```
Expand Down
2 changes: 1 addition & 1 deletion examples/mesh2d/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/mesh2d/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/minimal/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
2 changes: 1 addition & 1 deletion examples/worldspace/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/worldspace/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion examples/worldspace_text/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion examples/worldspace_text/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 5ed60d8

Please sign in to comment.