From d5f44b963912c199a77f8b60a7153c82dec5fe54 Mon Sep 17 00:00:00 2001 From: "Elijah C. Voigt" Date: Sat, 17 Feb 2024 00:16:24 -0800 Subject: [PATCH] Technically works, but want to tweak showing/hiding text boxes --- assets/martian.tweak.toml | 2 +- src/intro.rs | 251 ++++++++++++++++++++++---------------- src/loading.rs | 18 ++- src/ui.rs | 2 +- 4 files changed, 159 insertions(+), 114 deletions(-) diff --git a/assets/martian.tweak.toml b/assets/martian.tweak.toml index 0eb9e68..e721177 100644 --- a/assets/martian.tweak.toml +++ b/assets/martian.tweak.toml @@ -43,7 +43,7 @@ rgba_hidden = "#00000000" rgba_visible = "#FFFFFFFF" rgba_background = "#000000FF" # Higher rate is slower typing speed. Integers only! -delay = 1.0 +delay = 0.1 text = [ """ At the intersection of humanity's wildest imaginations and the infinite of the cosmos, the lines between possible and real fall apart like dissolving paper. diff --git a/src/intro.rs b/src/intro.rs index c16af98..a30c6e1 100644 --- a/src/intro.rs +++ b/src/intro.rs @@ -1,11 +1,7 @@ -use std::collections::VecDeque; - -use bevy::{core::FrameCount, utils::HashMap}; +use bevy::core::FrameCount; use crate::prelude::*; -use self::ui::TextScroll; - pub(crate) struct IntroPlugin; impl Plugin for IntroPlugin { @@ -20,18 +16,21 @@ impl Plugin for IntroPlugin { .add_systems(OnExit(GameState::Intro), deactivate::) .add_systems( Update, - play_text_scroll + // Started when the TextScrollAnimation component is added to the parent entity + // Updated for as long as there is scrolling text + manage_scroll_text_animation .run_if(in_state(GameState::Intro)) - .run_if(any_component_changed::), + .run_if(any_component_added::.or_else( + |keys: Res>| -> bool { keys.just_pressed(KeyCode::Return) }, + )), ) .add_systems( Update, // Play intro manages playing the intro of each individual paragraph - play_intro.run_if( - any_component_added:: - .or_else(any_component_removed::()) - .or_else(|keys: Res>| -> bool { keys.just_pressed(KeyCode::Return) }) - ) + // Runs every time the TextScroll component (managed by manage_scroll_text_animation) is updated + scroll_text + .run_if(in_state(GameState::Intro)) + .run_if(any_with_component::()), ); } } @@ -68,7 +67,6 @@ fn init_intro_text( align_items: AlignItems::Center, flex_direction: FlexDirection::Column, position_type: PositionType::Absolute, - padding: UiRect::all(Val::Px(50.0)), ..default() }, background_color: Color::NONE.into(), @@ -77,132 +75,169 @@ fn init_intro_text( }, )) .with_children(|parent| { - parent - .spawn(( - Intro, - NodeBundle { - style: Style { - padding: UiRect::all(Val::Px(25.0)), + texts.iter().for_each(|text| { + parent + .spawn(( + Intro, + NodeBundle { + style: Style { + width: Val::Percent(100.0), + justify_content: JustifyContent::Center, + align_content: AlignContent::Center, + flex_direction: FlexDirection::Column, + align_items: AlignItems::Center, + justify_items: JustifyItems::Center, + ..default() + }, + background_color: Color::hex(&background_hex).unwrap().into(), ..default() }, - background_color: Color::hex(&background_hex).unwrap().into(), - ..default() - }, - )) - .with_children(|parent| { - texts.iter().for_each(|text| { + )) + .with_children(|parent| { parent.spawn(( Intro, - TextBundle::from_sections(text.chars().into_iter().map(|c| TextSection { - value: c.to_string(), - style: TextStyle { - font_size: 16.0, - color: Color::hex(&text_hidden_hex).unwrap(), - font: ui_font.handle.clone(), + TextBundle { + style: Style { + // position_type: PositionType::Absolute, + top: Val::Px(0.0), + left: Val::Px(0.0), + justify_self: JustifySelf::Center, + align_self: AlignSelf::Center, + ..default() + }, + text: Text { + sections: text + .chars() + .into_iter() + .map(|c| TextSection { + value: c.to_string(), + style: TextStyle { + font_size: 16.0, + color: Color::hex(&text_hidden_hex).unwrap(), + font: ui_font.handle.clone(), + }, + }) + .collect(), + alignment: TextAlignment::Center, + ..default() }, - })) - .with_text_alignment(TextAlignment::Center), + ..default() + }, )); }); - }); + }); }); } fn start_intro( - query: Query, With)>, + // Hack, this way of "finding" the Node with our animated Text is precarious + query: Query, With, With, Without)>, mut commands: Commands, ) { query.iter().for_each(|e| { - commands.entity(e).insert(TextScroll { progress: 0, start: 0 }); + commands.entity(e).insert(ui::TextScrollAnimation); }); } -// Manages playing the intro animation -// Each paragrpah types out letter by letter in a separate animation handled by play_text_scroll -// This simply marks each paragraph for play and (should) stay dormant while those animations are playing -fn play_intro( - parents: Query, With, With)>, - mut texts: Query<(Entity, Option<&mut TextScroll>), (With, With)>, +fn manage_scroll_text_animation( + roots: Query>, + texts: Query, With)>, + animated_texts: Query<&ui::TextScroll>, children: Query<&Children>, - mut queues: Local>>, - mut commands: Commands, - tweaks_file: Res, - tweaks: Res>, + time: Res