You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.0 KiB
Rust
73 lines
2.0 KiB
Rust
use bevy::reflect::{TypePath, TypeUuid};
|
|
|
|
use crate::editor::prelude::*;
|
|
|
|
#[derive(Debug, Default)]
|
|
pub struct EditorTimelinePlugin;
|
|
|
|
impl Plugin for EditorTimelinePlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(Update, add_timeline_epoch.run_if(ui::activated::<AddEpoch>))
|
|
.add_systems(Update, control_active_epoch);
|
|
}
|
|
}
|
|
|
|
#[derive(
|
|
Debug, Component, Resource, Clone, Default, TypeUuid, Deserialize, TypePath, FromReflect,
|
|
)]
|
|
#[uuid = "959f5f02-7c80-4b3d-ad02-9dc2e5d1b963"]
|
|
pub struct Epoch {
|
|
id: usize,
|
|
scene: DynamicScene,
|
|
}
|
|
|
|
/// Timeline widget marker
|
|
#[derive(Debug, Component)]
|
|
pub struct TimelineWidget;
|
|
|
|
/// Add Epoch component, used on a button to trigger a new epoch addition
|
|
#[derive(Debug, Component)]
|
|
pub struct AddEpoch;
|
|
|
|
fn control_active_epoch(
|
|
events: Query<(Entity, &Epoch), Added<ui::Active>>,
|
|
mut commands: Commands,
|
|
) {
|
|
events.iter().for_each(|(entity, epoch)| {
|
|
commands.insert_resource(epoch.clone());
|
|
});
|
|
}
|
|
|
|
/// System for adding an epoch to the level's timeline
|
|
/// Triggered when a button with the AddEpoch marker is Active
|
|
fn add_timeline_epoch(
|
|
root: Query<(Entity, &Children), With<TimelineWidget>>,
|
|
mut commands: Commands,
|
|
) {
|
|
info!("Adding timeline epoch");
|
|
|
|
root.iter().for_each(|(entity, children)| {
|
|
let id = children.iter().len();
|
|
let name = format!("{}", id);
|
|
commands.entity(entity).with_children(|parent| {
|
|
parent.spawn((
|
|
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: name,
|
|
..default()
|
|
},
|
|
Epoch { id, ..default() },
|
|
));
|
|
});
|
|
});
|
|
}
|