animation play all button

main
Elijah Voigt 2 years ago
parent dc8b0e73ce
commit f66dd9792c

@ -3,12 +3,15 @@
// Editor for creating Monologue Trees levels
//
// BUGS:
// * Multi-GLTF UX is bad.
// * Consider GLTF hierarchy (GLTF1 > Scene1a/Scene1b, GlTF2 > Scene2a/Scene2b, etc)
// * Easy despawn when de-selecting gltf
//
// TODO:
// * (medium) Load default scene when gltf selected
// * Use default camera.
// * (easy) Play all animations
// * (medium) Visual errors for GLTFs problems (no cameras)
// * (easy) Clear button to wipe spawned scene
// * (brutal) export level
// * (hard) import level
//
// Asset types:
// * Audios (done)
@ -66,23 +69,35 @@ fn main() {
.add_systems(
Update,
(
import_files,
audio_ui,
gltf_ui,
fonts_ui,
texts_ui,
cameras_ui,
manage_active_gltf,
manage_gltf_scene_ui,
manage_gltf_animation_ui,
scenes_ui,
init_animations_ui,
animations_ui,
control_active_scenes,
play_all_animations,
play_animation,
),
)
.add_systems(
Update,
(manage_gltf_scene_ui, scenes_ui, control_active_scenes),
)
.add_systems(
Update,
(
cameras_ui,
manage_active_camera,
control_active_camera,
fallback_camera,
play_animation,
play_audio,
),
)
.add_systems(Update, (audio_ui, play_audio))
.add_systems(
Update,
(
import_files,
gltf_ui,
fonts_ui,
texts_ui,
manage_active_gltf,
show_preview_text,
sync_monologue_font,
),
@ -832,6 +847,36 @@ mod animations {
#[derive(Debug, Component, Default)]
pub struct AnimationWidget;
#[derive(Debug, Component)]
pub struct AnimationPlayAll;
pub fn init_animations_ui(
events: Query<Entity, Added<AnimationWidget>>,
mut commands: Commands,
) {
events.iter().for_each(|entity| {
commands.entity(entity).with_children(|parent| {
parent.spawn((
AnimationPlayAll,
ButtonBundle {
style: Style {
border: UiRect::all(Val::Px(1.0)),
margin: UiRect::all(Val::Px(1.0)),
padding: UiRect::all(Val::Px(1.0)),
..default()
},
border_color: Color::BLACK.into(),
..default()
},
ui::Title {
text: "Play All".into(),
..default()
},
));
});
})
}
pub fn animations_ui(
mut events: EventReader<CustomAssetEvent<AnimationClip>>,
mut commands: Commands,
@ -869,26 +914,59 @@ mod animations {
});
}
pub fn play_all_animations(
start: Query<Entity, (With<Button>, Added<ui::Active>)>,
mut stop: RemovedComponents<ui::Active>,
play_all_btn: Query<Entity, With<AnimationPlayAll>>,
clip_btns: Query<Entity, With<ui::TargetAsset<AnimationClip>>>,
mut commands: Commands,
) {
stop.iter()
.filter(|&entity| play_all_btn.contains(entity))
.for_each(|_| {
clip_btns.iter().for_each(|entity| {
commands.entity(entity).remove::<ui::Active>();
})
});
start
.iter()
.filter(|&entity| play_all_btn.contains(entity))
.for_each(|_| {
clip_btns.iter().for_each(|entity| {
commands.entity(entity).insert(ui::Active);
})
});
}
pub fn play_animation(
events: Query<
(&Interaction, &ui::TargetAsset<AnimationClip>),
(With<Button>, Changed<Interaction>),
>,
start: Query<Entity, (With<Button>, Added<ui::Active>)>,
mut stop: RemovedComponents<ui::Active>,
clip_refs: Query<&ui::TargetAsset<AnimationClip>>,
mut targets: Query<(&mut AnimationPlayer, &Name), With<Transform>>,
clips: Res<Assets<AnimationClip>>,
) {
events
.iter()
.filter(|(&interaction, _)| interaction == Interaction::Pressed)
.for_each(|(_, ui::TargetAsset { handle })| {
let clip = clips.get(handle).expect("Load animation clip");
stop.iter().for_each(|entity| {
if let Ok(ui::TargetAsset { handle }) = clip_refs.get(entity) {
let clip = clips.get(&handle).expect("Load animation clip");
targets
.iter_mut()
.filter(|(_, name)| clip.compatible_with(name))
.for_each(|(mut player, _)| {
player.pause();
})
}
});
start.iter().for_each(|entity| {
if let Ok(ui::TargetAsset { handle }) = clip_refs.get(entity) {
let clip = clips.get(&handle).expect("Load animation clip");
targets
.iter_mut()
.filter(|(_, name)| clip.compatible_with(name))
.for_each(|(mut player, _)| {
player.play(handle.clone()).repeat();
})
});
}
});
}
}
@ -899,7 +977,6 @@ mod fonts {
#[derive(Debug, Component, Default)]
pub struct FontWidget;
// TODO: Make each button have the font
pub fn fonts_ui(
mut events: EventReader<AssetEvent<Font>>,
mut commands: Commands,

@ -636,3 +636,15 @@ pub mod alert {
});
}
}
use dragndrop::*;
pub mod dragndrop {
use super::*;
#[derive(Debug, Component)]
struct DragNDrop;
pub fn dragndrop() {
todo!()
}
}

Loading…
Cancel
Save