use std::time::Duration; use bevy::prelude::*; use bevy_tweening::lens::TextColorLens; use bevy_tweening::{Animator, EaseFunction, RepeatCount, RepeatStrategy, Tween}; use iyes_loopless::state::NextState; use crate::assets::AssetHandles; use crate::graphics::AlignedBackground; use crate::system::flow::AppState; #[derive(Component)] pub struct MenuStateEntity; pub fn spawn_menu_entities(mut commands: Commands, assets: Res<AssetHandles>) { commands.spawn(( SpriteBundle { texture: assets.image("menu_background"), ..Default::default() }, MenuStateEntity, )); commands .spawn(( MenuStateEntity, NodeBundle { style: Style { size: Size::new(Val::Percent(100.0), Val::Percent(100.0)), flex_direction: FlexDirection::Column, align_items: AlignItems::Center, ..Default::default() }, ..Default::default() }, )) .with_children(|commands| { commands.spawn(TextBundle { text: Text::from_section( "Trader Tales", TextStyle { font_size: 72.0, font: assets.font("compass_pro"), color: Color::ANTIQUE_WHITE, }, ), style: Style { margin: UiRect::top(Val::Percent(20.0)), ..Default::default() }, ..Default::default() }); commands.spawn(( TextBundle { text: Text::from_section( "> Press Space <", TextStyle { font_size: 48.0, font: assets.font("compass_pro"), color: Color::ANTIQUE_WHITE, }, ), style: Style { margin: UiRect::top(Val::Px(50.0)), ..Default::default() }, ..Default::default() }, Animator::new( Tween::new( EaseFunction::QuadraticInOut, Duration::from_secs(1), TextColorLens { start: Color::ANTIQUE_WHITE, end: *Color::ANTIQUE_WHITE.set_a(0.0), section: 0, }, ) .with_repeat_count(RepeatCount::Infinite) .with_repeat_strategy(RepeatStrategy::MirroredRepeat), ), )); }); } pub fn go_to_game(input: Res<Input<KeyCode>>, mut commands: Commands) { if input.just_released(KeyCode::Space) { commands.insert_resource(NextState(AppState::InGame)); } } pub fn despawn_menu_entities(mut commands: Commands, query: Query<Entity, With<MenuStateEntity>>) { for entity in &query { commands.entity(entity).despawn_recursive(); } }