From 822c2de042dfe4a3c1043381e6799f85c16678b4 Mon Sep 17 00:00:00 2001 From: Elijah Voigt Date: Sat, 23 Sep 2023 22:48:50 -0700 Subject: [PATCH] Everything except animation buttons are donegit grep ui_active --- src/editor/assets.rs | 4 ++-- src/editor/audio.rs | 8 +++---- src/editor/camera.rs | 54 ++++++++++++++++++++++++++++++++++---------- src/editor/mod.rs | 1 + src/editor/scene.rs | 4 ++-- 5 files changed, 51 insertions(+), 20 deletions(-) diff --git a/src/editor/assets.rs b/src/editor/assets.rs index a001fbe..c6ab48e 100644 --- a/src/editor/assets.rs +++ b/src/editor/assets.rs @@ -5,9 +5,9 @@ pub struct EditorAssetsPlugin; impl Plugin for EditorAssetsPlugin { fn build(&self, app: &mut App) { - app.add_systems(Startup, reload_assets) + app.init_resource::() + .add_systems(Startup, reload_assets) .add_systems(Update, reload_assets.run_if(ui::activated::)) - .init_resource::() .add_systems(Update, clear_assets.run_if(ui::activated::)); } } diff --git a/src/editor/audio.rs b/src/editor/audio.rs index 5b6b884..213a38e 100644 --- a/src/editor/audio.rs +++ b/src/editor/audio.rs @@ -8,13 +8,13 @@ impl Plugin for EditorAudioPlugin { fn build(&self, app: &mut App) { app.register_type::() .add_event::() - .add_systems(Update, audio_ui) - .add_systems(Update, ui_control_audio) .add_systems(Update, ui_active::) .add_systems(Update, ui_inactive::) - .add_systems(Update, control_audio) .add_systems(Update, sync_asset_buttons::) - .add_systems(Update, sync_remove_asset_buttons::); + .add_systems(Update, sync_remove_asset_buttons::) + .add_systems(Update, audio_ui) + .add_systems(Update, ui_control_audio) + .add_systems(Update, control_audio); } } diff --git a/src/editor/camera.rs b/src/editor/camera.rs index 099cd87..db840d2 100644 --- a/src/editor/camera.rs +++ b/src/editor/camera.rs @@ -6,7 +6,8 @@ pub struct EditorCameraPlugin; impl Plugin for EditorCameraPlugin { fn build(&self, app: &mut App) { app.add_systems(Update, cameras_ui) - .add_systems(Update, manage_active_camera) + .add_systems(Update, control_active_camera) + .add_systems(Update, ui_control_active_camera) .add_systems(Update, fallback_camera); } } @@ -42,21 +43,50 @@ pub fn cameras_ui( } /// Set the camera active component based on button clicks -pub fn manage_active_camera( - events: Query<&ui::TargetEntity, Added>, - mut cameras: Query<(Entity, &mut Camera)>, +pub fn control_active_camera( + events: Query<(Entity, &Camera), Changed>, + buttons: Query<(Entity, &ui::TargetEntity)>, + mut commands: Commands, ) { - events.iter().for_each(|ui::TargetEntity { entity }| { - cameras.iter_mut().for_each(|(this_entity, mut camera)| { - if this_entity == *entity { - info!("Marking {:?} as active camera", entity); - camera.is_active = true; + events + .iter() + .filter_map(|(e, c)| { + buttons + .iter() + .find_map(|(button, ui::TargetEntity { entity })| { + (e == *entity).then_some((button, c)) + }) + }) + .for_each(|(button, camera)| { + if camera.is_active { + commands.entity(button).insert(ui::Active); } else { - info!("Marking {:?} as inactive camera", entity); - camera.is_active = false; + commands.entity(button).remove::(); } }); - }); +} + +pub fn ui_control_active_camera( + events: Query< + (&Interaction, &ui::TargetEntity, Option<&ui::Active>), + (With