#[cfg(feature = "extended-framework")]
use crate::component::ExtendedComponentPlugin;
#[cfg(feature = "extended-dialog")]
use crate::dialog::ExtendedDialogPlugin;
#[cfg(feature = "extended-framework")]
use crate::framework::ExtendedFrameworkPlugin;
use crate::html::ExtendedUiHtmlPlugin;
use crate::io::ExtendedIoPlugin;
#[cfg(not(feature = "extended-framework"))]
use crate::old::registry::ExtendedRegistryPlugin;
#[cfg(feature = "providers")]
use crate::providers::ExtendedUiProviderPlugin;
use crate::routing::ExtendedRoutingPlugin;
use crate::services::ExtendedServicePlugin;
use crate::styles::ExtendedStylingPlugin;
use crate::widgets::ExtendedWidgetPlugin;
use bevy::camera::Hdr;
use bevy::camera::visibility::RenderLayers;
use bevy::prelude::*;
use std::collections::HashMap;
#[cfg(feature = "extended-framework")]
pub mod component;
#[cfg(feature = "extended-dialog")]
pub mod dialog;
pub mod example_utils;
pub mod framework;
pub mod html;
pub mod io;
pub mod lang;
pub mod old;
#[cfg(feature = "providers")]
pub mod providers;
#[deprecated(note = "Legacy module moved to `old::registry`. Use the new component framework.")]
pub mod registry;
pub mod routing;
pub mod services;
pub mod styles;
pub mod utils;
pub mod widgets;
pub use bevy_extended_ui_macros::BeuStore;
pub use lang::{UILang, UiLangVariables, UiSharedValues};
#[derive(Resource, Default)]
pub struct ImageCache {
pub map: HashMap<String, Handle<Image>>,
}
#[derive(Resource, Debug, Clone)]
pub struct ExtendedUiConfiguration {
pub order: isize,
pub hdr_support: bool,
pub camera: ExtendedCam,
pub render_layers: Vec<usize>,
pub framework_components_path: String,
pub assets_path: String,
pub language_path: String,
pub themes_path: String,
pub theme_names: Vec<String>,
}
impl Default for ExtendedUiConfiguration {
fn default() -> Self {
Self {
order: 2,
hdr_support: false,
camera: ExtendedCam::default(),
render_layers: vec![1, 2],
framework_components_path: String::from("components"),
assets_path: String::from("assets/extended_ui/"),
language_path: String::from("assets/lang"),
themes_path: String::from("assets/themes"),
theme_names: Vec::new(),
}
}
}
#[derive(Debug, Clone, Default)]
pub enum ExtendedCam {
#[default]
Default,
Simple,
None,
}
#[derive(Resource, Debug, Clone)]
pub struct CurrentWidgetState {
pub widget_id: usize,
}
impl Default for CurrentWidgetState {
fn default() -> Self {
Self { widget_id: 0 }
}
}
#[derive(Component)]
pub struct UiCamera;
pub struct ExtendedUiPlugin;
impl Plugin for ExtendedUiPlugin {
fn build(&self, app: &mut App) {
app.init_resource::<ExtendedUiConfiguration>();
app.init_resource::<ImageCache>();
app.init_resource::<CurrentWidgetState>();
app.init_resource::<UILang>();
app.init_resource::<UiLangVariables>();
app.register_type::<Camera>();
#[cfg(not(feature = "extended-framework"))]
app.add_plugins(ExtendedRegistryPlugin);
#[cfg(feature = "extended-framework")]
app.add_plugins(ExtendedComponentPlugin);
app.add_plugins((
ExtendedRoutingPlugin,
ExtendedWidgetPlugin,
ExtendedServicePlugin,
ExtendedStylingPlugin,
ExtendedIoPlugin,
ExtendedUiHtmlPlugin,
));
#[cfg(feature = "extended-dialog")]
app.add_plugins(ExtendedDialogPlugin);
#[cfg(feature = "extended-framework")]
app.add_plugins(ExtendedFrameworkPlugin);
#[cfg(feature = "providers")]
app.add_plugins(ExtendedUiProviderPlugin);
app.add_systems(
Update,
load_ui_camera_system.run_if(resource_changed::<ExtendedUiConfiguration>),
);
}
}
pub fn load_ui_camera_system(
mut commands: Commands,
configuration: Res<ExtendedUiConfiguration>,
mut query: Query<(Entity, &mut Camera, &mut RenderLayers), With<UiCamera>>,
) {
match configuration.camera {
ExtendedCam::Default => {
if let Some((cam_entity, mut camera, mut layers)) = query.iter_mut().next() {
camera.order = configuration.order;
*layers = RenderLayers::from_layers(configuration.render_layers.as_slice());
if configuration.hdr_support {
commands.entity(cam_entity).insert(Hdr::default());
} else {
commands.entity(cam_entity).remove::<Hdr>();
}
debug!("Ui Camera updated (Default)!");
} else {
let cam_entity = commands
.spawn((
Name::new("Extended Ui Camera"),
Camera2d,
Camera {
order: configuration.order,
clear_color: ClearColorConfig::None,
..default()
},
Msaa::Sample4,
RenderLayers::from_layers(configuration.render_layers.as_slice()),
UiCamera,
IsDefaultUiCamera,
))
.id();
if configuration.hdr_support {
commands.entity(cam_entity).insert(Hdr::default());
}
debug!("Ui Camera created (Default)!");
}
}
ExtendedCam::Simple => {
for (entity, _, _) in query.iter() {
commands.entity(entity).despawn();
}
commands.spawn((
Name::new("Extended UI Camera"),
Camera2d,
Camera {
order: configuration.order,
clear_color: ClearColorConfig::None,
..default()
},
UiCamera,
));
debug!("Ui Camera created (Simple)!");
}
ExtendedCam::None => {
for (entity, _, _) in query.iter() {
commands.entity(entity).despawn();
debug!("Ui Camera removed!");
}
}
}
}