-
Notifications
You must be signed in to change notification settings - Fork 0
/
credits.rs
63 lines (52 loc) · 1.83 KB
/
credits.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
//! A credits screen that can be accessed from the title screen.
use bevy::prelude::*;
use super::Screen;
use crate::{
game::{assets::SoundtrackKey, audio::soundtrack::PlaySoundtrack},
ui::prelude::*,
};
pub(super) fn plugin(app: &mut App) {
app.add_systems(OnEnter(Screen::Credits), enter_credits);
app.add_systems(OnExit(Screen::Credits), exit_credits);
app.add_systems(
Update,
handle_credits_action.run_if(in_state(Screen::Credits)),
);
app.register_type::<CreditsAction>();
}
#[derive(Component, Debug, Clone, Copy, PartialEq, Eq, Reflect)]
#[reflect(Component)]
enum CreditsAction {
Back,
}
fn enter_credits(mut commands: Commands) {
commands
.ui_root()
.insert(StateScoped(Screen::Credits))
.with_children(|children| {
children.header("Made by");
children.label("Alice - Foo");
children.label("Bob - Bar");
children.header("Assets");
children.label("Bevy logo - All rights reserved by the Bevy Foundation. Permission granted for splash screen use when unmodified.");
children.label("Ducky sprite - CC0 by Caz Creates Games");
children.label("Music - CC BY 3.0 by Kevin MacLeod");
children.button("Back").insert(CreditsAction::Back);
});
commands.trigger(PlaySoundtrack::Key(SoundtrackKey::Credits));
}
fn exit_credits(mut commands: Commands) {
commands.trigger(PlaySoundtrack::Disable);
}
fn handle_credits_action(
mut next_screen: ResMut<NextState<Screen>>,
mut button_query: InteractionQuery<&CreditsAction>,
) {
for (interaction, action) in &mut button_query {
if matches!(interaction, Interaction::Pressed) {
match action {
CreditsAction::Back => next_screen.set(Screen::Title),
}
}
}
}