|
|
|
@ -2,6 +2,7 @@ use std::{f32::consts::PI, ops::RangeInclusive};
|
|
|
|
|
|
|
|
|
|
|
|
use bevy::{
|
|
|
|
use bevy::{
|
|
|
|
animation::{animated_field, AnimationTarget, AnimationTargetId},
|
|
|
|
animation::{animated_field, AnimationTarget, AnimationTargetId},
|
|
|
|
|
|
|
|
color::palettes::css::{BLACK, BLUE, GREEN, PINK, RED},
|
|
|
|
prelude::*,
|
|
|
|
prelude::*,
|
|
|
|
utils::HashMap,
|
|
|
|
utils::HashMap,
|
|
|
|
};
|
|
|
|
};
|
|
|
|
@ -15,7 +16,10 @@ pub struct AnimationPlugin;
|
|
|
|
|
|
|
|
|
|
|
|
impl Plugin for AnimationPlugin {
|
|
|
|
impl Plugin for AnimationPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_systems(Update, delayed_animation);
|
|
|
|
app.add_systems(Update, delayed_animation).add_systems(
|
|
|
|
|
|
|
|
Update,
|
|
|
|
|
|
|
|
animate_button.run_if(any_with_component::<AnimateButton>),
|
|
|
|
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@ -25,12 +29,11 @@ struct AnimationComplete;
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
#[derive(Resource, Default)]
|
|
|
|
pub(crate) struct AnimationStore {
|
|
|
|
pub(crate) struct AnimationStore {
|
|
|
|
pub store: HashMap<String, AnimationNodeIndex>,
|
|
|
|
pub store: HashMap<String, AnimationNodeIndex>,
|
|
|
|
pub graph: AnimationGraphHandle,
|
|
|
|
pub card_graph: AnimationGraphHandle,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
#[derive(Component)]
|
|
|
|
pub(crate) struct DelayedAnimation {
|
|
|
|
pub(crate) struct DelayedAnimation {
|
|
|
|
pub graph: AnimationGraphHandle,
|
|
|
|
|
|
|
|
pub animation_index: AnimationNodeIndex,
|
|
|
|
pub animation_index: AnimationNodeIndex,
|
|
|
|
pub delay: Timer,
|
|
|
|
pub delay: Timer,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -126,13 +129,9 @@ pub(crate) fn setup_animations(
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
animation_store.graph = AnimationGraphHandle(graphs.add(animation_graph));
|
|
|
|
animation_store.card_graph = AnimationGraphHandle(graphs.add(animation_graph));
|
|
|
|
|
|
|
|
|
|
|
|
commands.insert_resource(animation_store);
|
|
|
|
commands.insert_resource(animation_store);
|
|
|
|
|
|
|
|
|
|
|
|
// TODO: (example: https://bevyengine.org/examples/animation/animated-transform/)
|
|
|
|
|
|
|
|
// Button Animations:
|
|
|
|
|
|
|
|
// active_button_animation = AnimationClip::default() // color and size
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn play_selected_animation(
|
|
|
|
pub(crate) fn play_selected_animation(
|
|
|
|
@ -168,10 +167,36 @@ fn delayed_animation(
|
|
|
|
delayed_animation.delay.tick(time.delta());
|
|
|
|
delayed_animation.delay.tick(time.delta());
|
|
|
|
if delayed_animation.delay.just_finished() {
|
|
|
|
if delayed_animation.delay.just_finished() {
|
|
|
|
animation_player.start(delayed_animation.animation_index);
|
|
|
|
animation_player.start(delayed_animation.animation_index);
|
|
|
|
commands
|
|
|
|
commands.entity(entity).remove::<DelayedAnimation>();
|
|
|
|
.entity(entity)
|
|
|
|
|
|
|
|
.insert(delayed_animation.graph.clone())
|
|
|
|
|
|
|
|
.remove::<DelayedAnimation>();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
|
|
|
pub(crate) struct AnimateButton;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) fn animate_button(
|
|
|
|
|
|
|
|
query: Single<(&mut BackgroundColor, &mut Transform), With<AnimateButton>>,
|
|
|
|
|
|
|
|
time: Res<Time>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
// t is a value in the range (0..=1)
|
|
|
|
|
|
|
|
let t = (f32::cos(time.elapsed_secs_wrapped()) + 1.0) / 2.0;
|
|
|
|
|
|
|
|
let (mut bg, mut tr) = query.into_inner();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We want values from 0..3 for picking a color
|
|
|
|
|
|
|
|
bg.0 = match t * 3.0 {
|
|
|
|
|
|
|
|
0.0..=1.0 => Srgba::interpolate(&RED, &GREEN, t % 1.0).into(),
|
|
|
|
|
|
|
|
1.0..=2.0 => Srgba::interpolate(&GREEN, &BLUE, t % 1.0).into(),
|
|
|
|
|
|
|
|
2.0..=3.0 => Srgba::interpolate(&BLUE, &RED, t % 1.0).into(),
|
|
|
|
|
|
|
|
_ => todo!(),
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We want angles from -0.5..0.5 for angle
|
|
|
|
|
|
|
|
tr.rotation = Quat::from_axis_angle(Vec3::Z, (t / 2.0) - 0.25);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if t > 0.5 {
|
|
|
|
|
|
|
|
tr.scale += time.delta_secs() / 20.0;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
tr.scale -= time.delta_secs() / 20.0;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|