From 6f53ff26112fd64c9c6d3a361a4dea0bc2282074 Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Thu, 16 May 2024 20:25:00 -0700 Subject: [PATCH] Make intro speedier --- assets/martian.tweak.toml | 4 ++-- src/display3d.rs | 9 +++---- src/intro.rs | 50 +++++++++++++++++++++++++++++++++++++-- src/ui.rs | 12 ++++------ 4 files changed, 57 insertions(+), 18 deletions(-) diff --git a/assets/martian.tweak.toml b/assets/martian.tweak.toml index 7b3032b..0a88aee 100644 --- a/assets/martian.tweak.toml +++ b/assets/martian.tweak.toml @@ -271,7 +271,7 @@ QueenRed = "QueenRedPieceIdle" ### Animation Settings ###################### [animation] -fast_movement_speed = 2.0 -fast_text_speed = 4.0 +fast_movement_speed = 5.0 +fast_text_speed = 999.0 fast_dissolve_speed = 1.0 fast_light_speed = 1.0 \ No newline at end of file diff --git a/src/display3d.rs b/src/display3d.rs index 365fc10..9cde979 100644 --- a/src/display3d.rs +++ b/src/display3d.rs @@ -190,7 +190,6 @@ pub(crate) enum Dissolving { #[derive(Debug, Resource)] pub(crate) struct AnimationSpeed { pub movement: f32, - pub text: f32, pub dissolve: f32, } @@ -198,7 +197,6 @@ impl Default for AnimationSpeed { fn default() -> Self { AnimationSpeed { movement: 1.0, - text: 1.0, dissolve: 1.0, } } @@ -1029,19 +1027,18 @@ fn set_animation_speed( keys: Res>, mouse: Res>, ) { - *animation_speed = if keys.pressed(KeyCode::Enter) || mouse.pressed(MouseButton::Left) { + *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 movement = tweak.get::("animation_fast_movement_speed").unwrap(); - let text = tweak.get::("animation_fast_text_speed").unwrap(); let dissolve = tweak.get::("animation_fast_dissolve_speed").unwrap(); - AnimationSpeed { movement, text, dissolve } + AnimationSpeed { movement, dissolve } } else { AnimationSpeed::default() }; - debug!("Animation speed: {:?}", animation_speed.movement); + info!("Set animation speeds {:?}", *animation_speed); } // When an animation starts, or the animation speed changes, update player speed diff --git a/src/intro.rs b/src/intro.rs index a4cbe2e..7cf4b48 100644 --- a/src/intro.rs +++ b/src/intro.rs @@ -7,6 +7,7 @@ pub(crate) struct IntroPlugin; impl Plugin for IntroPlugin { fn build(&self, app: &mut App) { app.init_resource::() + .init_resource::() .add_systems( OnExit(GameState::Loading), init_intro_text @@ -30,6 +31,13 @@ impl Plugin for IntroPlugin { // Play intro manages playing the intro of each individual paragraph // Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated scroll_text.run_if(any_with_component::), + 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)), ); @@ -39,6 +47,35 @@ impl Plugin for IntroPlugin { #[derive(Debug, Component)] 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, + tweaks: Res>, + tweaks_file: Res, + keys: Res>, + mouse: Res>, +) { + *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::("animation_fast_text_speed").unwrap(); + TextAnimationSpeed(speed) + } else { + TextAnimationSpeed::default() + }; + + info!("Set animation speeds {:?}", *animation_speed); +} + // Draw the intro text (invisible) on startup // Requires the Tweakfile to be loaded fn init_intro_text( @@ -181,6 +218,9 @@ fn manage_scroll_text_animation( mut next_state: ResMut>, mut curr: ResMut, mut commands: Commands, + mut speed: ResMut, + mut keys: ResMut>, + mut mouse: ResMut>, ) { info!("Managing scroll text animation"); @@ -203,6 +243,10 @@ fn manage_scroll_text_animation( commands.entity(p.get()).insert(Visibility::Hidden); commands.entity(e).insert(Visibility::Hidden); + + *speed = TextAnimationSpeed::default(); + keys.clear(); + mouse.clear(); } // Locate the last entity we were operating with for entity in paragraphs.by_ref() { @@ -216,11 +260,13 @@ fn manage_scroll_text_animation( info!("Curr: {:?}", curr.0); + // Progress to the next paragraph if let Some(e) = curr.0 { commands.entity(e).insert(ui::TextScroll { progress: 0, stopwatch: Stopwatch::new(), }); + // Continue to the title } else { commands.entity(r).remove::(); next_state.set(GameState::Title); @@ -237,7 +283,7 @@ fn scroll_text( parents: Query<&Parent>, mut prompt: ResMut>, mut commands: Commands, - animation_speed: Res, + animation_speed: Res, ) { let tweak = tweaks.get(tweaks_file.handle.clone()).expect("Load tweaks"); texts @@ -254,7 +300,7 @@ fn scroll_text( *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 = { // Update animation progress for this paragrpah diff --git a/src/ui.rs b/src/ui.rs index 567c816..19048f7 100644 --- a/src/ui.rs +++ b/src/ui.rs @@ -1,4 +1,4 @@ -use bevy::time::Stopwatch; +use bevy::{time::Stopwatch, window::WindowResized}; use crate::prelude::*; @@ -18,7 +18,7 @@ impl Plugin for UiPlugin { interactive_button.run_if(any_component_changed::()), scale_ui.run_if( on_event::>() - .or_else(any_component_changed::()) + .or_else(on_event::()) .and_then(resource_exists::), ), ), @@ -127,9 +127,8 @@ fn interactive_button( } fn scale_ui( - mut windows: Query<&mut Window, Changed>, + mut windows: Query<&mut Window>, mut ui_scale: ResMut, - mut resolution_set: Local, tweakfile: Res, tweaks: Res>, ) { @@ -142,10 +141,7 @@ fn scale_ui( windows.iter_mut().for_each(|mut w| { // Setting window resolution at startup - if !*resolution_set { - w.resolution.set(width, height); - *resolution_set = true; - } + w.resolution.set(width, height); // Check if window is minimized if w.resolution.height() > 0.0 && w.resolution.height() > 0.0 {