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
65
66
67
68
69
70
71
72
73
74
75
use bevy::{color::palettes::css::YELLOW, prelude::*, sprite::Anchor};
use bevy_lunex::prelude::*;

use crate::{components::Quit, events::SelectEvent, splash::components::SplashScreen};

pub fn init_ui_cam(mut commands: Commands, assets: Res<AssetServer>) {
    commands.spawn(camera()).with_children(|cam| {
        let mut cursor = Cursor2d::new();
        cursor.request_cursor(CursorIcon::Default, 0.0);
        cursor.request_cursor(CursorIcon::Pointer, 1.0);
        cursor.request_cursor(CursorIcon::Grab, 2.0);

        cam.spawn(StyledCursorBundle {
            cursor,
            sprite: SpriteBundle {
                texture: assets.load("images/ui/cursor_pointer3D_shadow.png"),
                transform: Transform {
                    scale: Vec3::new(0.45, 0.45, 1.0),
                    ..default()
                },
                sprite: Sprite {
                    color: YELLOW.into(),
                    anchor: Anchor::TopLeft,
                    ..default()
                },
                ..default()
            },
            ..default()
        });
    });

    commands.spawn(SplashScreen);
}
pub fn exit(mut app_exit_event_writer: EventWriter<AppExit>, quit: Query<Entity, Added<Quit>>) {
    for _ in &quit {
        app_exit_event_writer.send(AppExit::Success);
    }
}

/// Function to return camera will all appropriate settings
pub fn camera() -> impl Bundle {
    (
        MainUi,
        Camera2dBundle {
            transform: Transform::from_xyz(0.0, 0.0, 1000.0),
            camera: Camera {
                hdr: true,
                ..default()
            },
            ..default()
        },
        InheritedVisibility::default(),
    )
}

pub fn create_root(commands: &mut Commands, r_size: (f32, f32)) {
    commands
        .spawn(SpatialBundle::default())
        .with_children(|route| {
            route
                .spawn((
                    UiTreeBundle::<MainUi>::from(UiTree::new2d("Main")),
                    MovableByCamera,
                ))
                .with_children(|ui| {
                    let root = UiLink::<MainUi>::path("Root");
                    ui.spawn((root.clone(), UiLayout::window().size(r_size).pack::<Base>()));
                });
        });
}
pub fn button_click(mut events: EventReader<UiClickEvent>, mut ev_w: EventWriter<SelectEvent>) {
    for event in events.read() {
        ev_w.send(SelectEvent(event.clone()));
    }
}