scenes UI refactor fixed... need cameras too

main
Elijah Voigt 2 years ago
parent b3c225b1ad
commit f6384c036e

@ -142,14 +142,10 @@ pub fn sync_asset_buttons<T: Asset>(
buttons
.iter()
.find_map(|(entity, ui::TargetAsset { handle })| {
if handle == this_handle {
Some(entity)
} else {
None
}
(handle == this_handle).then_some(entity)
})
.iter()
.for_each(|&entity| {
.into_iter()
.for_each(|entity| {
commands.entity(entity).insert(ui::Active);
});
});
@ -166,20 +162,16 @@ pub fn sync_remove_asset_buttons<T: Asset>(
events
.iter()
.find_map(|this_asset_entity| asset_entities.get(this_asset_entity).ok())
.iter()
.into_iter()
.for_each(|this_handle| {
info!("Syncing removal of {:?}", this_handle);
buttons
.iter()
.find_map(|(entity, ui::TargetAsset { handle })| {
if handle == *this_handle {
Some(entity)
} else {
None
}
(handle == this_handle).then_some(entity)
})
.iter()
.for_each(|&entity| {
.into_iter()
.for_each(|entity| {
commands.entity(entity).remove::<ui::Active>();
});
});

@ -6,14 +6,14 @@ pub struct EditorAudioPlugin;
impl Plugin for EditorAudioPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, audio_ui)
app.register_type::<AudioRoot>()
.add_event::<ControlAudio>()
.add_systems(Update, audio_ui)
.add_systems(Update, ui_control_audio)
.add_systems(Update, ui_active::<AudioSource>)
.add_systems(Update, ui_inactive::<AudioSource>)
.add_systems(Update, control_audio)
.add_systems(Update, sync_asset_buttons::<AudioSource>)
.register_type::<AudioRoot>()
.add_event::<ControlAudio>()
.add_systems(Update, sync_remove_asset_buttons::<AudioSource>);
}
}

@ -1,79 +1,2 @@
use crate::editor::prelude::*;
#[derive(Debug, Default)]
pub struct EditorGltfPlugin;
impl Plugin for EditorGltfPlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, sync_asset_buttons::<Gltf>)
.add_systems(Update, sync_remove_asset_buttons::<Gltf>)
.add_systems(Update, gltf_ui);
}
}
#[derive(Debug, Component, Default)]
pub struct GltfWidget;
pub fn gltf_ui(
mut events: EventReader<AssetEvent<Gltf>>,
mut commands: Commands,
widget: Query<Entity, With<GltfWidget>>,
current: Query<(Entity, &ui::TargetAsset<Gltf>)>,
server: Res<AssetServer>,
) {
events.iter().for_each(|event| match event {
AssetEvent::Created { handle } => {
info!("Asset created! {:?}", event);
create_asset_button(
&widget,
&mut commands,
ui::TargetAsset {
handle: handle.clone(),
},
get_asset_name(&server, handle.clone()),
None,
);
}
AssetEvent::Removed { handle } => {
info!("Asset removed! {:?}", event);
destroy_asset_button(
&current,
&mut commands,
&ui::TargetAsset {
handle: handle.clone(),
},
);
}
AssetEvent::Modified { handle } => {
info!("Asset modified! {:?}", event);
destroy_asset_button(
&current,
&mut commands,
&ui::TargetAsset {
handle: handle.clone(),
},
);
create_asset_button(
&widget,
&mut commands,
ui::TargetAsset {
handle: handle.clone(),
},
get_asset_name(&server, handle.clone()),
None,
);
}
});
}
pub fn control_active_gltf(
events: Query<Entity, (With<ui::TargetAsset<Gltf>>, Added<ui::Active>)>,
root: Query<Entity, With<LevelRoot>>,
mut commands: Commands,
) {
events.iter().for_each(|_| {
root.iter().for_each(|entity| {
commands.entity(entity).despawn_descendants();
});
});
}

@ -3,7 +3,6 @@ pub mod assets;
pub mod audio;
pub mod camera;
pub mod font;
pub mod gltf;
pub mod level;
pub mod lighting;
pub mod monologue;
@ -26,15 +25,11 @@ pub fn ui_active<T: Asset>(
buttons
.iter()
.find_map(|(entity, ui::TargetAsset { handle })| {
if handle == this_handle {
Some(entity)
} else {
None
}
(handle == this_handle).then_some(entity)
})
.and_then(|entity| {
.into_iter()
.for_each(|entity| {
commands.entity(entity).insert(ui::Active);
Some(())
});
});
}
@ -51,9 +46,9 @@ pub fn ui_inactive<T: Asset>(
.find_map(|(entity, ui::TargetAsset { handle })| {
(!sources.iter().any(|this_handle| this_handle == handle)).then_some(entity)
})
.and_then(|entity| {
.into_iter()
.for_each(|entity| {
commands.entity(entity).remove::<ui::Active>();
Some(())
});
});
}
@ -156,8 +151,6 @@ fn initialize_ui(mut commands: Commands) {
.push(spawn_tab_container::<AudioWidget>("Audio", parent));
content_containers
.push(spawn_tab_container::<LevelWidget>("Level", parent));
content_containers
.push(spawn_tab_container::<GltfWidget>("Gltf", parent));
content_containers
.push(spawn_tab_container::<SceneWidget>("Scene", parent));
content_containers

@ -17,7 +17,6 @@ impl Plugin for EditorMonologuePlugin {
.add_event::<ControlMonologue>()
.add_systems(Update, sync_asset_buttons::<Monologue>)
.add_systems(Update, sync_remove_asset_buttons::<Monologue>)
.add_systems(Update, control_active_gltf)
.add_systems(Update, control_monologue)
.add_systems(Update, ui_control_monologue)
.add_systems(Update, ui_active::<Monologue>)
@ -62,7 +61,6 @@ impl AssetLoader for MonologueLoader {
let asset = Monologue {
text: String::from_utf8(bytes.to_vec())?,
};
info!("!!! Loading Monologue !!!");
load_context.set_default_asset(LoadedAsset::new(asset));
Ok(())
})

@ -10,7 +10,6 @@ impl Plugin for EditorPlugin {
.add_plugins(EditorAudioPlugin::default())
.add_plugins(EditorCameraPlugin::default())
.add_plugins(EditorFontPlugin::default())
.add_plugins(EditorGltfPlugin::default())
.add_plugins(EditorLevelPlugin::default())
.add_plugins(EditorLightingPlugin::default())
.add_plugins(EditorMonologuePlugin::default())

@ -1,7 +1,7 @@
pub use crate::{
editor::{
animation::*, assets::*, audio::*, camera::*, font::*, gltf::*, level::*, lighting::*,
monologue::*, quit::*, scene::*, timeline::*, *,
animation::*, assets::*, audio::*, camera::*, font::*, level::*, lighting::*, monologue::*,
quit::*, scene::*, timeline::*, *,
},
ui,
};

@ -5,25 +5,41 @@ pub struct EditorScenePlugin;
impl Plugin for EditorScenePlugin {
fn build(&self, app: &mut App) {
app.add_systems(Update, remove_scenes_ui)
.add_systems(Update, add_scenes_ui)
.add_systems(Update, control_active_scenes)
app.add_event::<ControlScene>()
.add_systems(Update, sync_asset_buttons::<Scene>)
.add_systems(Update, sync_remove_asset_buttons::<Scene>);
.add_systems(Update, sync_remove_asset_buttons::<Scene>)
.add_systems(Update, add_scenes_ui)
.add_systems(Update, remove_scenes_ui)
.add_systems(Update, sync_asset_buttons::<AudioSource>)
.add_systems(Update, sync_remove_asset_buttons::<AudioSource>)
.add_systems(Update, control_scene)
.add_systems(Update, ui_control_scene);
}
}
#[derive(Debug, Event)]
pub enum ControlScene {
Spawn(Handle<Scene>),
Despawn(Handle<Scene>),
}
#[derive(Debug, Component, Default)]
pub struct SceneWidget;
pub fn add_scenes_ui(
gltf_selected: Query<&ui::TargetAsset<Gltf>, Added<ui::TargetAsset<Gltf>>>,
mut events: EventReader<AssetEvent<Gltf>>,
mut commands: Commands,
gltfs: Res<Assets<Gltf>>,
widget: Query<Entity, With<SceneWidget>>,
server: Res<AssetServer>,
) {
gltf_selected.iter().for_each(|ui::TargetAsset { handle }| {
events
.iter()
.filter_map(|event| match event {
AssetEvent::Created { handle } => Some(handle),
_ => None,
})
.for_each(|handle| {
let gltf_name = get_asset_name(&server, handle.clone());
if let Some(gltf) = gltfs.get(&handle.clone()) {
gltf.named_scenes.iter().for_each(|(name, handle)| {
@ -65,44 +81,48 @@ pub fn remove_scenes_ui(
});
}
pub fn control_active_scenes(
added: Query<Entity, (With<Button>, Added<ui::Active>)>,
mut removed: RemovedComponents<ui::Active>,
scene_refs: Query<&ui::TargetAsset<Scene>>,
pub fn control_scene(
mut events: EventReader<ControlScene>,
root: Query<Entity, With<LevelRoot>>,
scenes: Query<(Entity, &Handle<Scene>)>,
level_root: Query<Entity, With<LevelRoot>>,
mut commands: Commands,
) {
// A scene button was marked inactive
removed.iter().for_each(|entity| {
// Get the handle associated with that button
scene_refs
.get(entity)
.iter()
.for_each(|ui::TargetAsset { handle }| {
scenes
.iter()
.find_map(|(entity, this_handle)| (this_handle == handle).then_some(entity))
.iter()
.for_each(|&entity| {
commands.entity(entity).despawn_recursive();
});
});
});
added.iter().for_each(|entity| {
scene_refs
.get(entity)
.iter()
.for_each(|ui::TargetAsset { handle }| {
info!("Spawning Scene {:?}", handle);
commands
.entity(level_root.single())
.with_children(|parent| {
events.iter().for_each(|event| match event {
ControlScene::Spawn(handle) => {
commands.entity(root.single()).with_children(|parent| {
parent.spawn(SceneBundle {
scene: handle.clone(),
..default()
});
});
}
ControlScene::Despawn(handle) => {
scenes
.iter()
.find_map(|(entity, this_handle)| (handle == this_handle).then_some(entity))
.into_iter()
.for_each(|entity| commands.entity(entity).despawn_recursive());
}
});
}
pub fn ui_control_scene(
events: Query<
(&Interaction, &ui::TargetAsset<Scene>, Option<&ui::Active>),
(With<Button>, Changed<Interaction>),
>,
mut writer: EventWriter<ControlScene>,
) {
events
.iter()
.filter_map(
|(interaction, ui::TargetAsset { handle }, active)| match interaction {
Interaction::Pressed => Some((handle, active)),
_ => None,
},
)
.for_each(|(handle, active)| match active {
Some(_) => writer.send(ControlScene::Despawn(handle.clone())),
None => writer.send(ControlScene::Spawn(handle.clone())),
});
}

@ -367,17 +367,11 @@ mod collapse {
events.iter().for_each(|(entity, children)| {
// Find any tabs which have this as a target
tabs.iter_mut()
.find_map(|(button, collapse)| {
if entity == collapse.target {
Some(button)
} else {
None
}
})
.iter()
.find_map(|(button, collapse)| (entity == collapse.target).then_some(button))
.into_iter()
.for_each(|button| {
let num_children = children.len();
commands.entity(*button).insert(Note {
commands.entity(button).insert(Note {
text: format!("({})", num_children),
});
});

Loading…
Cancel
Save