bevy_codex/splash/
systems.rs1use bevy::{prelude::*, window::PrimaryWindow};
2use bevy_lunex::{
3 prelude::{MainUi, Rl, UiNodeTreeInitTrait, UiTree},
4 Base, MovableByCamera, PackageLayout, UiImage2dBundle, UiLayout, UiLink, UiTreeBundle,
5};
6
7use super::components::{SplashScreen, SplashTimer};
8use crate::{main_menu::components::MainMenu, UiState};
9
10pub fn build_splash(
11 mut commands: Commands,
12 assets: Res<AssetServer>,
13 window: Query<&Window, With<PrimaryWindow>>,
14 query: Query<Entity, Added<SplashScreen>>,
15) {
16 for route_entity in &query {
17 if let Ok(resolution) = window.get_single() {
18 let r_size = (resolution.width(), resolution.height());
19 commands
20 .entity(route_entity)
21 .insert(SpatialBundle::default())
22 .with_children(|route| {
23 route
24 .spawn((
25 UiTreeBundle::<MainUi>::from(UiTree::new2d("MainMenu")),
26 MovableByCamera,
27 ))
28 .with_children(|ui| {
29 let root = UiLink::<MainUi>::path("Root");
30 ui.spawn((
31 root.clone(),
32 UiLayout::window().size(r_size).pack::<Base>(),
33 ));
34 ui.spawn((
36 UiLink::<MainUi>::path("Background"), UiLayout::boundary()
38 .pos1(Rl(40.0))
39 .pos2(Rl(60.0))
40 .pack::<Base>(),
41 UiImage2dBundle::from(assets.load("branding/icon.png")), ));
43 });
44 });
45 }
46 }
47}
48pub fn count_down(
49 mut commands: Commands,
50 mut state: ResMut<NextState<UiState>>,
51 mut timer: ResMut<SplashTimer>,
52 splash: Query<Entity, With<SplashScreen>>,
53 time: Res<Time>,
54) {
55 timer.0.tick(time.delta());
56 if timer.finished() {
57 state.set(UiState::MainMenu);
58 for route_entity in &splash {
59 println!("despawn splash");
60 commands.entity(route_entity).despawn_recursive();
61 }
62 commands.spawn(MainMenu);
63 }
64}