|
|
|
@ -7,6 +7,7 @@ pub(crate) struct IntroPlugin;
|
|
|
|
impl Plugin for IntroPlugin {
|
|
|
|
impl Plugin for IntroPlugin {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.init_resource::<CurrentIntroParagraph>()
|
|
|
|
app.init_resource::<CurrentIntroParagraph>()
|
|
|
|
|
|
|
|
.init_resource::<TextAnimationSpeed>()
|
|
|
|
.add_systems(
|
|
|
|
.add_systems(
|
|
|
|
OnExit(GameState::Loading),
|
|
|
|
OnExit(GameState::Loading),
|
|
|
|
init_intro_text
|
|
|
|
init_intro_text
|
|
|
|
@ -30,6 +31,13 @@ impl Plugin for IntroPlugin {
|
|
|
|
// Play intro manages playing the intro of each individual paragraph
|
|
|
|
// Play intro manages playing the intro of each individual paragraph
|
|
|
|
// Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated
|
|
|
|
// Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated
|
|
|
|
scroll_text.run_if(any_with_component::<ui::TextScroll>),
|
|
|
|
scroll_text.run_if(any_with_component::<ui::TextScroll>),
|
|
|
|
|
|
|
|
set_text_animation_speed
|
|
|
|
|
|
|
|
.run_if(
|
|
|
|
|
|
|
|
just_pressed(KeyCode::Enter)
|
|
|
|
|
|
|
|
.or_else(just_pressed(MouseButton::Left))
|
|
|
|
|
|
|
|
.or_else(just_released(KeyCode::Enter))
|
|
|
|
|
|
|
|
.or_else(just_released(MouseButton::Left))
|
|
|
|
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
.run_if(in_state(GameState::Intro)),
|
|
|
|
.run_if(in_state(GameState::Intro)),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
@ -39,6 +47,35 @@ impl Plugin for IntroPlugin {
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
#[derive(Debug, Component)]
|
|
|
|
struct IntroUi;
|
|
|
|
struct IntroUi;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, Resource)]
|
|
|
|
|
|
|
|
struct TextAnimationSpeed(f32);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
impl Default for TextAnimationSpeed {
|
|
|
|
|
|
|
|
fn default() -> Self {
|
|
|
|
|
|
|
|
TextAnimationSpeed(5.0)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn set_text_animation_speed(
|
|
|
|
|
|
|
|
mut animation_speed: ResMut<TextAnimationSpeed>,
|
|
|
|
|
|
|
|
tweaks: Res<Assets<Tweaks>>,
|
|
|
|
|
|
|
|
tweaks_file: Res<tweak::GameTweaks>,
|
|
|
|
|
|
|
|
keys: Res<ButtonInput<KeyCode>>,
|
|
|
|
|
|
|
|
mouse: Res<ButtonInput<MouseButton>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
*animation_speed = if keys.just_pressed(KeyCode::Enter) || mouse.just_pressed(MouseButton::Left) {
|
|
|
|
|
|
|
|
let tweak = tweaks
|
|
|
|
|
|
|
|
.get(tweaks_file.handle.clone())
|
|
|
|
|
|
|
|
.expect("Load tweakfile");
|
|
|
|
|
|
|
|
let speed = tweak.get::<f32>("animation_fast_text_speed").unwrap();
|
|
|
|
|
|
|
|
TextAnimationSpeed(speed)
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
TextAnimationSpeed::default()
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
info!("Set animation speeds {:?}", *animation_speed);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Draw the intro text (invisible) on startup
|
|
|
|
// Draw the intro text (invisible) on startup
|
|
|
|
// Requires the Tweakfile to be loaded
|
|
|
|
// Requires the Tweakfile to be loaded
|
|
|
|
fn init_intro_text(
|
|
|
|
fn init_intro_text(
|
|
|
|
@ -181,6 +218,9 @@ fn manage_scroll_text_animation(
|
|
|
|
mut next_state: ResMut<NextState<GameState>>,
|
|
|
|
mut next_state: ResMut<NextState<GameState>>,
|
|
|
|
mut curr: ResMut<CurrentIntroParagraph>,
|
|
|
|
mut curr: ResMut<CurrentIntroParagraph>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
|
|
|
|
mut speed: ResMut<TextAnimationSpeed>,
|
|
|
|
|
|
|
|
mut keys: ResMut<ButtonInput<KeyCode>>,
|
|
|
|
|
|
|
|
mut mouse: ResMut<ButtonInput<MouseButton>>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
info!("Managing scroll text animation");
|
|
|
|
info!("Managing scroll text animation");
|
|
|
|
|
|
|
|
|
|
|
|
@ -203,6 +243,10 @@ fn manage_scroll_text_animation(
|
|
|
|
commands.entity(p.get()).insert(Visibility::Hidden);
|
|
|
|
commands.entity(p.get()).insert(Visibility::Hidden);
|
|
|
|
|
|
|
|
|
|
|
|
commands.entity(e).insert(Visibility::Hidden);
|
|
|
|
commands.entity(e).insert(Visibility::Hidden);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
*speed = TextAnimationSpeed::default();
|
|
|
|
|
|
|
|
keys.clear();
|
|
|
|
|
|
|
|
mouse.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Locate the last entity we were operating with
|
|
|
|
// Locate the last entity we were operating with
|
|
|
|
for entity in paragraphs.by_ref() {
|
|
|
|
for entity in paragraphs.by_ref() {
|
|
|
|
@ -216,11 +260,13 @@ fn manage_scroll_text_animation(
|
|
|
|
|
|
|
|
|
|
|
|
info!("Curr: {:?}", curr.0);
|
|
|
|
info!("Curr: {:?}", curr.0);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Progress to the next paragraph
|
|
|
|
if let Some(e) = curr.0 {
|
|
|
|
if let Some(e) = curr.0 {
|
|
|
|
commands.entity(e).insert(ui::TextScroll {
|
|
|
|
commands.entity(e).insert(ui::TextScroll {
|
|
|
|
progress: 0,
|
|
|
|
progress: 0,
|
|
|
|
stopwatch: Stopwatch::new(),
|
|
|
|
stopwatch: Stopwatch::new(),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
// Continue to the title
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
commands.entity(r).remove::<ui::TextScrollAnimation>();
|
|
|
|
commands.entity(r).remove::<ui::TextScrollAnimation>();
|
|
|
|
next_state.set(GameState::Title);
|
|
|
|
next_state.set(GameState::Title);
|
|
|
|
@ -237,7 +283,7 @@ fn scroll_text(
|
|
|
|
parents: Query<&Parent>,
|
|
|
|
parents: Query<&Parent>,
|
|
|
|
mut prompt: ResMut<NextState<ui::Prompt>>,
|
|
|
|
mut prompt: ResMut<NextState<ui::Prompt>>,
|
|
|
|
mut commands: Commands,
|
|
|
|
mut commands: Commands,
|
|
|
|
animation_speed: Res<display3d::AnimationSpeed>,
|
|
|
|
animation_speed: Res<TextAnimationSpeed>,
|
|
|
|
) {
|
|
|
|
) {
|
|
|
|
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
|
|
|
|
let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks");
|
|
|
|
texts
|
|
|
|
texts
|
|
|
|
@ -254,7 +300,7 @@ fn scroll_text(
|
|
|
|
*vis = Visibility::Inherited;
|
|
|
|
*vis = Visibility::Inherited;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
text_scroll.stopwatch.tick(Duration::from_secs_f32(time.delta_seconds() * animation_speed.text));
|
|
|
|
text_scroll.stopwatch.tick(Duration::from_secs_f32(time.delta_seconds() * animation_speed.0));
|
|
|
|
|
|
|
|
|
|
|
|
text_scroll.progress = {
|
|
|
|
text_scroll.progress = {
|
|
|
|
// Update animation progress for this paragrpah
|
|
|
|
// Update animation progress for this paragrpah
|
|
|
|
|