You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
4.7 KiB
Rust
143 lines
4.7 KiB
Rust
use bevy::{
|
|
color::palettes::css::{BLACK, INDIGO, ORANGE, PURPLE, RED, TEAL},
|
|
prelude::*,
|
|
};
|
|
|
|
use crate::view::{button_set_state, ViewState};
|
|
|
|
/// Game Menu
|
|
pub struct MenuPlugin;
|
|
|
|
impl Plugin for MenuPlugin {
|
|
fn build(&self, app: &mut App) {
|
|
app.add_systems(
|
|
Startup,
|
|
(
|
|
setup,
|
|
setup_about,
|
|
setup_how_to_play,
|
|
setup_deck,
|
|
setup_sets,
|
|
),
|
|
);
|
|
}
|
|
}
|
|
|
|
fn setup(mut commands: Commands) {
|
|
commands
|
|
.spawn((ViewState::Menu, Node::default()))
|
|
.with_children(|parent| {
|
|
parent
|
|
.spawn((Button, BackgroundColor(TEAL.into())))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("Play".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::Play));
|
|
parent
|
|
.spawn((Button, BackgroundColor(ORANGE.into())))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("About".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::About));
|
|
parent
|
|
.spawn((Button, BackgroundColor(PURPLE.into())))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("How to Play".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::HowToPlay));
|
|
parent
|
|
.spawn((Button, BackgroundColor(RED.into())))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("Quit".to_string()));
|
|
})
|
|
.observe(quit_button);
|
|
});
|
|
|
|
commands
|
|
.spawn((ViewState::Play, Node::default()))
|
|
.with_children(|parent| {
|
|
parent
|
|
.spawn((Button, BackgroundColor(TEAL.into()), GlobalZIndex(1)))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("Menu".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::Menu));
|
|
parent
|
|
.spawn((Button, BackgroundColor(INDIGO.into()), GlobalZIndex(1)))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("Deck".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::Deck));
|
|
parent
|
|
.spawn((Button, BackgroundColor(ORANGE.into()), GlobalZIndex(1)))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("Sets".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::Sets));
|
|
});
|
|
}
|
|
|
|
fn setup_about(mut commands: Commands) {
|
|
commands
|
|
.spawn((ViewState::About, Node::default()))
|
|
.with_children(|parent| {
|
|
parent
|
|
.spawn((Button, BackgroundColor(TEAL.into())))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("Menu".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::Menu));
|
|
parent.spawn((
|
|
Text("This is the about page".to_string()),
|
|
BackgroundColor(BLACK.into()),
|
|
));
|
|
});
|
|
}
|
|
|
|
fn setup_how_to_play(mut commands: Commands) {
|
|
commands
|
|
.spawn((ViewState::HowToPlay, Node::default()))
|
|
.with_children(|parent| {
|
|
parent
|
|
.spawn((Button, BackgroundColor(TEAL.into())))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("Menu".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::Menu));
|
|
parent.spawn((
|
|
Text("This is the how to play page".to_string()),
|
|
BackgroundColor(BLACK.into()),
|
|
));
|
|
});
|
|
}
|
|
|
|
fn setup_deck(mut commands: Commands) {
|
|
commands
|
|
.spawn((ViewState::Deck, Node::default()))
|
|
.with_children(|parent| {
|
|
parent
|
|
.spawn((Button, BackgroundColor(TEAL.into())))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("Back".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::Play));
|
|
});
|
|
}
|
|
|
|
fn setup_sets(mut commands: Commands) {
|
|
commands
|
|
.spawn((ViewState::Sets, Node::default()))
|
|
.with_children(|parent| {
|
|
parent
|
|
.spawn((Button, BackgroundColor(TEAL.into())))
|
|
.with_children(|parent| {
|
|
parent.spawn(Text("Back".to_string()));
|
|
})
|
|
.observe(button_set_state(ViewState::Play));
|
|
});
|
|
}
|
|
|
|
fn quit_button(_trigger: Trigger<Pointer<Click>>, mut exit_event: EventWriter<AppExit>) {
|
|
exit_event.send(AppExit::Success);
|
|
}
|