1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
use bevy::prelude::*;
use bevy_lunex::{
    prelude::{MainUi, Rl, UiNodeTreeInitTrait, UiTree},
    Base, MovableByCamera, PackageLayout, UiImage2dBundle, UiLayout, UiLink, UiTreeBundle,
};

use crate::{main_menu::components::MainMenu, UiState};

use super::components::{SplashScreen, SplashTimer};

pub fn build_splash(
    mut commands: Commands,
    assets: Res<AssetServer>,
    query: Query<Entity, Added<SplashScreen>>,
) {
    for route_entity in &query {
        // Spawn the route
        commands
            .entity(route_entity)
            .insert(SpatialBundle::default())
            .with_children(|route| {
                // Spawn the master ui tree
                route
                    .spawn((
                        UiTreeBundle::<MainUi>::from(UiTree::new("MainMenu")),
                        MovableByCamera,
                    ))
                    .with_children(|ui| {
                        let root: UiLink<_> = UiLink::<MainUi>::path("Root"); // Here we can define the name of the node
                        ui.spawn((
                            root.clone(),                           // Here we add the link
                            UiLayout::window_full().pack::<Base>(), // This is where we define layout
                        ));

                        // Spawn the background
                        ui.spawn((
                            root.add("Background"), // You can see here that we used existing "root" link to create chained link (same as "Root/Background")
                            UiLayout::boundary()
                                .pos1(Rl(40.0))
                                .pos2(Rl(60.0))
                                .pack::<Base>(),
                            UiImage2dBundle::from(assets.load("branding/icon.png")), // We use this bundle to add background image to our node
                        ));
                    });
            });
    }
}
pub fn count_down(
    mut commands: Commands,
    mut state: ResMut<NextState<UiState>>,
    mut timer: ResMut<SplashTimer>,
    splash: Query<Entity, With<SplashScreen>>,
    time: Res<Time>,
) {
    timer.0.tick(time.delta());
    if timer.finished() {
        state.set(UiState::MainMenu);
        for route_entity in &splash {
            println!("despawn splash");
            commands.entity(route_entity).despawn_recursive();
        }
        commands.spawn(MainMenu);
    }
}