|
|
@ -1,12 +1,26 @@
|
|
|
|
use crate::events;
|
|
|
|
use crate::{events, game::Throw};
|
|
|
|
use bevy::ecs::system::EntityCommand;
|
|
|
|
use bevy::ecs::system::EntityCommand;
|
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy::prelude::*;
|
|
|
|
use bevy::text::DEFAULT_FONT_HANDLE;
|
|
|
|
use bevy::text::DEFAULT_FONT_HANDLE;
|
|
|
|
|
|
|
|
|
|
|
|
pub struct Play {}
|
|
|
|
pub struct Play {}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Component, Debug)]
|
|
|
|
|
|
|
|
struct Action {
|
|
|
|
|
|
|
|
throw: Throw,
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn handle_actions(actions: Query<(&Interaction, &Action), (Changed<Interaction>, With<Action>)>) {
|
|
|
|
|
|
|
|
for (interaction, action) in actions.iter() {
|
|
|
|
|
|
|
|
if matches!(interaction, Interaction::Pressed) {
|
|
|
|
|
|
|
|
info!("Clicked {throw:?}", throw = action.throw);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
struct ActionButton {
|
|
|
|
struct ActionButton {
|
|
|
|
text: String,
|
|
|
|
text: String,
|
|
|
|
|
|
|
|
throw: Throw,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
impl EntityCommand for ActionButton {
|
|
|
|
impl EntityCommand for ActionButton {
|
|
|
@ -19,7 +33,8 @@ impl EntityCommand for ActionButton {
|
|
|
|
|
|
|
|
|
|
|
|
let button = world
|
|
|
|
let button = world
|
|
|
|
.spawn((
|
|
|
|
.spawn((
|
|
|
|
Name::new("action button"),
|
|
|
|
Name::new(format!("{action} button", action = &self.text)),
|
|
|
|
|
|
|
|
Action { throw: self.throw },
|
|
|
|
ButtonBundle {
|
|
|
|
ButtonBundle {
|
|
|
|
style: Style {
|
|
|
|
style: Style {
|
|
|
|
align_items: AlignItems::Center,
|
|
|
|
align_items: AlignItems::Center,
|
|
|
@ -32,14 +47,13 @@ impl EntityCommand for ActionButton {
|
|
|
|
background_color: Color::GRAY.into(),
|
|
|
|
background_color: Color::GRAY.into(),
|
|
|
|
..default()
|
|
|
|
..default()
|
|
|
|
},
|
|
|
|
},
|
|
|
|
// TextBundle::from_section("Cool", style),
|
|
|
|
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.set_parent(id)
|
|
|
|
.set_parent(id)
|
|
|
|
.id();
|
|
|
|
.id();
|
|
|
|
|
|
|
|
|
|
|
|
world
|
|
|
|
world
|
|
|
|
.spawn((
|
|
|
|
.spawn((
|
|
|
|
Name::new("fart"),
|
|
|
|
Name::new("label"),
|
|
|
|
TextBundle::from_section(self.text, style),
|
|
|
|
TextBundle::from_section(self.text, style),
|
|
|
|
))
|
|
|
|
))
|
|
|
|
.set_parent(button);
|
|
|
|
.set_parent(button);
|
|
|
@ -49,7 +63,7 @@ impl EntityCommand for ActionButton {
|
|
|
|
fn handle_play(mut events: EventReader<events::Play>, mut commands: Commands) {
|
|
|
|
fn handle_play(mut events: EventReader<events::Play>, mut commands: Commands) {
|
|
|
|
for _ in events.iter() {
|
|
|
|
for _ in events.iter() {
|
|
|
|
let mut bg = commands.spawn((
|
|
|
|
let mut bg = commands.spawn((
|
|
|
|
Name::new("UI Container"),
|
|
|
|
Name::new("Play Container"),
|
|
|
|
NodeBundle {
|
|
|
|
NodeBundle {
|
|
|
|
style: Style {
|
|
|
|
style: Style {
|
|
|
|
display: Display::Flex,
|
|
|
|
display: Display::Flex,
|
|
|
@ -121,12 +135,15 @@ fn handle_play(mut events: EventReader<events::Play>, mut commands: Commands) {
|
|
|
|
|
|
|
|
|
|
|
|
control_row.add(ActionButton {
|
|
|
|
control_row.add(ActionButton {
|
|
|
|
text: "Rock".into(),
|
|
|
|
text: "Rock".into(),
|
|
|
|
|
|
|
|
throw: Throw::Rock,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
control_row.add(ActionButton {
|
|
|
|
control_row.add(ActionButton {
|
|
|
|
text: "Paper".into(),
|
|
|
|
text: "Paper".into(),
|
|
|
|
|
|
|
|
throw: Throw::Paper,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
control_row.add(ActionButton {
|
|
|
|
control_row.add(ActionButton {
|
|
|
|
text: "Scissors".into(),
|
|
|
|
text: "Scissors".into(),
|
|
|
|
|
|
|
|
throw: Throw::Scissors,
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -134,6 +151,6 @@ fn handle_play(mut events: EventReader<events::Play>, mut commands: Commands) {
|
|
|
|
|
|
|
|
|
|
|
|
impl Plugin for Play {
|
|
|
|
impl Plugin for Play {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
fn build(&self, app: &mut App) {
|
|
|
|
app.add_systems(Update, handle_play);
|
|
|
|
app.add_systems(Update, (handle_play, handle_actions));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|