|
|
|
@ -1,15 +1,25 @@
|
|
|
|
|
use bevy::ecs::system::EntityCommand;
|
|
|
|
|
use bevy::prelude::*;
|
|
|
|
|
use bevy::text::DEFAULT_FONT_HANDLE;
|
|
|
|
|
use tracing::info;
|
|
|
|
|
|
|
|
|
|
pub struct StartMenu {}
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct InactiveColor(Color);
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct HoverColor(Color);
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct Title;
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct QuitButton;
|
|
|
|
|
|
|
|
|
|
#[derive(Component)]
|
|
|
|
|
struct PlayButton;
|
|
|
|
|
|
|
|
|
|
fn title_text() -> TextBundle {
|
|
|
|
|
let style = TextStyle {
|
|
|
|
|
font: DEFAULT_FONT_HANDLE.typed(),
|
|
|
|
@ -19,7 +29,7 @@ fn title_text() -> TextBundle {
|
|
|
|
|
TextBundle::from_section("Rock, Paper, Scissors", style)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn quit_button() -> ButtonBundle {
|
|
|
|
|
fn thicc_button() -> ButtonBundle {
|
|
|
|
|
ButtonBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
flex_direction: FlexDirection::Column,
|
|
|
|
@ -34,30 +44,50 @@ fn quit_button() -> ButtonBundle {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn click_quit(
|
|
|
|
|
fn hover_colors(
|
|
|
|
|
mut actions: Query<
|
|
|
|
|
(&Interaction, &mut BackgroundColor),
|
|
|
|
|
(Changed<Interaction>, With<QuitButton>),
|
|
|
|
|
(
|
|
|
|
|
&Interaction,
|
|
|
|
|
&mut BackgroundColor,
|
|
|
|
|
&InactiveColor,
|
|
|
|
|
&HoverColor,
|
|
|
|
|
),
|
|
|
|
|
(Changed<Interaction>, With<InactiveColor>, With<HoverColor>),
|
|
|
|
|
>,
|
|
|
|
|
mut quit: ResMut<Events<bevy::app::AppExit>>,
|
|
|
|
|
) {
|
|
|
|
|
for (interaction, mut bg) in &mut actions {
|
|
|
|
|
match interaction {
|
|
|
|
|
Interaction::Pressed => {
|
|
|
|
|
info!("Quit button clicked");
|
|
|
|
|
bg.0 = Color::BLUE;
|
|
|
|
|
quit.send_default();
|
|
|
|
|
}
|
|
|
|
|
for (act, mut bg, off, on) in &mut actions {
|
|
|
|
|
match act {
|
|
|
|
|
Interaction::Pressed => {}
|
|
|
|
|
Interaction::Hovered => {
|
|
|
|
|
bg.0 = Color::rgb(0.4, 0.3, 0.3);
|
|
|
|
|
bg.0 = on.0;
|
|
|
|
|
}
|
|
|
|
|
Interaction::None => {
|
|
|
|
|
bg.0 = Color::rgb(0.4, 0.2, 0.2);
|
|
|
|
|
bg.0 = off.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn click_play(mut actions: Query<&Interaction, (Changed<Interaction>, With<PlayButton>)>) {
|
|
|
|
|
for interaction in &mut actions {
|
|
|
|
|
if matches!(interaction, Interaction::Pressed) {
|
|
|
|
|
todo!()
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn click_quit(
|
|
|
|
|
mut actions: Query<&Interaction, (Changed<Interaction>, With<QuitButton>)>,
|
|
|
|
|
mut quit: ResMut<Events<bevy::app::AppExit>>,
|
|
|
|
|
) {
|
|
|
|
|
for interaction in &mut actions {
|
|
|
|
|
if matches!(interaction, Interaction::Pressed) {
|
|
|
|
|
info!("Quit button clicked");
|
|
|
|
|
quit.send_default();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn vertical_spacer(height: f32) -> NodeBundle {
|
|
|
|
|
NodeBundle {
|
|
|
|
|
style: Style {
|
|
|
|
@ -68,16 +98,9 @@ fn vertical_spacer(height: f32) -> NodeBundle {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn setup(mut commands: Commands) {
|
|
|
|
|
commands.spawn(Camera2dBundle::default());
|
|
|
|
|
|
|
|
|
|
commands
|
|
|
|
|
.spawn(NodeBundle {
|
|
|
|
|
fn column() -> NodeBundle {
|
|
|
|
|
NodeBundle {
|
|
|
|
|
style: Style {
|
|
|
|
|
padding: UiRect {
|
|
|
|
|
top: Val::Px(30.0),
|
|
|
|
|
..default()
|
|
|
|
|
},
|
|
|
|
|
display: Display::Flex,
|
|
|
|
|
width: Val::Percent(100.0),
|
|
|
|
|
flex_direction: FlexDirection::Column,
|
|
|
|
@ -86,20 +109,22 @@ fn setup(mut commands: Commands) {
|
|
|
|
|
},
|
|
|
|
|
background_color: BackgroundColor(Color::BLACK),
|
|
|
|
|
..default()
|
|
|
|
|
})
|
|
|
|
|
.with_children(|column| {
|
|
|
|
|
column.spawn((Title, title_text()));
|
|
|
|
|
column.spawn(vertical_spacer(20.0));
|
|
|
|
|
column
|
|
|
|
|
.spawn((QuitButton, quit_button()))
|
|
|
|
|
.with_children(|button| {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
struct AddChildLabel {
|
|
|
|
|
text: String,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl EntityCommand for AddChildLabel {
|
|
|
|
|
fn apply(self, id: Entity, world: &mut World) {
|
|
|
|
|
let style = TextStyle {
|
|
|
|
|
font: DEFAULT_FONT_HANDLE.typed(),
|
|
|
|
|
font_size: 24.0,
|
|
|
|
|
color: Color::WHITE,
|
|
|
|
|
};
|
|
|
|
|
button.spawn(
|
|
|
|
|
TextBundle::from_section("Quit", style)
|
|
|
|
|
world.spawn_empty().set_parent(id).insert(
|
|
|
|
|
TextBundle::from_section(self.text, style)
|
|
|
|
|
.with_text_alignment(TextAlignment::Center)
|
|
|
|
|
.with_style(Style {
|
|
|
|
|
display: Display::Flex,
|
|
|
|
@ -112,6 +137,38 @@ fn setup(mut commands: Commands) {
|
|
|
|
|
..Default::default()
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn setup(mut commands: Commands) {
|
|
|
|
|
let red = Color::rgb(0.8, 0.2, 0.2);
|
|
|
|
|
let green = Color::rgb(0.2, 0.8, 0.2);
|
|
|
|
|
|
|
|
|
|
commands.spawn(Camera2dBundle::default());
|
|
|
|
|
commands.spawn(column()).with_children(|menu| {
|
|
|
|
|
menu.spawn(vertical_spacer(80.0));
|
|
|
|
|
menu.spawn((Title, title_text()));
|
|
|
|
|
menu.spawn(vertical_spacer(32.0));
|
|
|
|
|
|
|
|
|
|
menu.spawn((
|
|
|
|
|
PlayButton,
|
|
|
|
|
thicc_button(),
|
|
|
|
|
HoverColor(green),
|
|
|
|
|
InactiveColor(red),
|
|
|
|
|
))
|
|
|
|
|
.add(AddChildLabel {
|
|
|
|
|
text: String::from("Play"),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
menu.spawn(vertical_spacer(32.0));
|
|
|
|
|
menu.spawn((
|
|
|
|
|
QuitButton,
|
|
|
|
|
thicc_button(),
|
|
|
|
|
HoverColor(green),
|
|
|
|
|
InactiveColor(red),
|
|
|
|
|
))
|
|
|
|
|
.add(AddChildLabel {
|
|
|
|
|
text: String::from("Quit"),
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@ -119,6 +176,6 @@ fn setup(mut commands: Commands) {
|
|
|
|
|
impl Plugin for StartMenu {
|
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
|
app.add_systems(Startup, setup);
|
|
|
|
|
app.add_systems(Update, click_quit);
|
|
|
|
|
app.add_systems(Update, (hover_colors, click_quit, click_play));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|