Clippy help text

main
Elijah Voigt 1 year ago
parent 4f217f541b
commit 51779ab8dc

@ -17,7 +17,9 @@ pub struct MenuPlugin;
impl Plugin for MenuPlugin {
fn build(&self, app: &mut App) {
app.add_observer(set_set_count).add_systems(
app.add_observer(set_set_count)
.add_observer(ui_alert)
.add_systems(
Startup,
(
setup,
@ -26,6 +28,7 @@ impl Plugin for MenuPlugin {
setup_how_to_play.after(boot::load),
setup_deck,
setup_sets,
setup_alert,
),
);
}
@ -481,3 +484,43 @@ fn button_hover_off(trigger: Trigger<Pointer<Out>>, mut query: Query<&mut Backgr
let mut background_color = query.get_mut(trigger.entity()).unwrap();
background_color.0.set_alpha(0.9);
}
#[derive(Component)]
struct Alert;
#[derive(Event)]
pub(crate) struct UiMessage(pub String);
fn setup_alert(mut commands: Commands) {
commands
.spawn((
Node {
position_type: PositionType::Absolute,
bottom: Val::Px(0.0),
width: Val::Percent(100.0),
justify_content: JustifyContent::Start,
..default()
},
ViewState::Play,
))
.with_children(|parent| {
parent
.spawn((
Node {
padding: UiRect::all(Val::Px(10.0)),
margin: UiRect::all(Val::Px(10.0)),
border: UiRect::all(Val::Px(1.0)),
..default()
},
BackgroundColor(Color::BLACK.with_alpha(0.9).into()),
BorderColor(WHITE.into()),
))
.with_children(|parent| {
parent.spawn((Text::default(), Alert));
});
});
}
fn ui_alert(trigger: Trigger<UiMessage>, mut query: Query<&mut Text, With<Alert>>) {
query.single_mut().0 = trigger.event().0.clone();
}

@ -1,6 +1,6 @@
use bevy::prelude::*;
use crate::{deck::Card, GameState};
use crate::{deck::Card, menu::UiMessage, GameState};
pub struct PlayPlugin;
@ -47,6 +47,7 @@ pub(crate) fn toggle_selected(
mut commands: Commands,
query: Query<&Selected>,
) {
commands.trigger(UiMessage("".into()));
let e = trigger.entity();
if query.contains(e) {
commands.entity(e).remove::<Selected>();
@ -68,7 +69,7 @@ pub(crate) fn reset_rotation(
pub(crate) fn check_set(
_trigger: Trigger<Pointer<Click>>,
mut query: Query<(Entity, &Card, &mut Visibility, &mut Transform), With<Selected>>,
mut sets: Query<&SetNumber>,
sets: Query<&SetNumber>,
mut commands: Commands,
) {
let mut cards = query.iter();
@ -91,11 +92,12 @@ pub(crate) fn check_set(
.remove::<Selected>()
.insert(SetNumber(set_number));
});
commands.trigger(UiMessage("Yipee!".into()));
}
} else if cards.len() > 3 {
info!("Too many cards!")
commands.trigger(UiMessage("Too many cards!".into()));
} else if cards.len() < 3 {
info!("Not enough cards!")
commands.trigger(UiMessage("Not enough cards!".into()));
}
}
@ -234,6 +236,14 @@ pub(crate) fn check_for_sets(
});
if let Some((a, b, c)) = candidate {
// Message for adding
match selected.iter().len() {
0 => commands.trigger(UiMessage("First one's free!".into())),
1 => commands.trigger(UiMessage("This one is tricky!".into())),
2 => commands.trigger(UiMessage("Threes company!".into())),
_ => commands.trigger(UiMessage("I don't feel so good...".into())),
};
// Add the selected component to the next entity
if !selected.contains(a) {
commands.entity(a).insert(Selected);
} else if !selected.contains(b) {
@ -241,9 +251,9 @@ pub(crate) fn check_for_sets(
} else if !selected.contains(c) {
commands.entity(c).insert(Selected);
} else {
info!("I cannot hold your hand further...");
commands.trigger(UiMessage("Lock it in!".into()));
}
} else {
info!("No sets!");
commands.trigger(UiMessage("I'm stumped!".into()));
}
}

Loading…
Cancel
Save