-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
custom_skip.rs
153 lines (147 loc) · 5.53 KB
/
custom_skip.rs
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
use std::time::Duration;
use bevy::prelude::*;
use bevy_splash_screen::{
ClearSplash, SplashAssetType, SplashItem, SplashPlugin, SplashScreen, SplashScreenSkipEvent,
SplashTextColorLens,
};
use bevy_tweening::*;
#[derive(Clone, Copy, Debug, Default, States, Hash, PartialEq, Eq)]
enum ScreenStates {
#[default]
Splash,
Menu,
}
fn main() {
App::new()
.add_plugins(DefaultPlugins)
.init_state::<ScreenStates>()
.add_plugins(
SplashPlugin::new(ScreenStates::Splash, ScreenStates::Menu)
.ignore_default_events()
.skipable()
.add_screen(SplashScreen {
brands: vec![SplashItem {
asset: SplashAssetType::SingleText(
Text::from_sections([
TextSection::new(
"Sergio Ribera\n",
TextStyle {
font_size: 76.,
..default()
},
),
TextSection::new(
"presents\n",
TextStyle {
font_size: 38.,
..default()
},
),
])
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::WHITE,
width: Val::Percent(40.),
height: Val::Px(80.),
ease_function: EaseFunction::QuarticInOut.into(),
duration: Duration::from_secs(5),
is_static: false,
}],
background_color: BackgroundColor(Color::BLACK),
..default()
})
.add_screen(SplashScreen {
brands: vec![SplashItem {
asset: SplashAssetType::SingleText(
Text::from_section(
"Custom Skip\n",
TextStyle {
font_size: 75.,
..default()
},
)
.with_justify(JustifyText::Center),
"FiraSans-Bold.ttf".to_string(),
),
tint: Color::WHITE,
width: Val::Percent(35.),
height: Val::Px(160.),
ease_function: EaseFunction::QuarticInOut.into(),
duration: Duration::from_secs(5),
is_static: false,
}],
background_color: BackgroundColor(Color::BLACK),
..default()
}),
)
.add_systems(Startup, create_scene)
.add_systems(Update, button_system)
.run();
}
fn create_scene(mut cmd: Commands, assets: ResMut<AssetServer>) {
cmd.spawn(Camera2dBundle::default());
cmd.spawn(NodeBundle {
style: Style {
display: Display::Flex,
position_type: PositionType::Absolute,
direction: Direction::LeftToRight,
align_items: AlignItems::FlexEnd,
align_content: AlignContent::Center,
justify_content: JustifyContent::Center,
width: Val::Percent(100.),
height: Val::Percent(100.),
overflow: Overflow::clip(),
..default()
},
..default()
})
.insert(ClearSplash)
.with_children(|cmd| {
cmd.spawn(ButtonBundle {
style: Style {
height: Val::Px(65.0),
justify_content: JustifyContent::Center,
align_items: AlignItems::Center,
..default()
},
background_color: BackgroundColor(Color::WHITE.with_alpha(0.)),
..default()
})
.with_children(|cmd| {
cmd.spawn((
TextBundle {
text: Text::from_section(
"Press Any Key or Touch screen for skip",
TextStyle {
font_size: 50.,
font: assets.load("FiraSans-Bold.ttf"),
..default()
},
)
.with_justify(JustifyText::Center),
..default()
},
Animator::new(
Tween::new(
EaseFunction::QuadraticInOut,
Duration::from_secs(3),
SplashTextColorLens::new(vec![Color::WHITE]),
)
.with_repeat_count(RepeatCount::Infinite)
.with_repeat_strategy(RepeatStrategy::MirroredRepeat),
),
));
});
});
}
fn button_system(
mut interaction_query: Query<&Interaction, (Changed<Interaction>, With<Button>)>,
mut send_skip: EventWriter<SplashScreenSkipEvent>,
) {
for interaction in &mut interaction_query {
if *interaction == Interaction::Pressed {
send_skip.send(SplashScreenSkipEvent);
}
}
}