Added background image
parent
7c737e5d72
commit
6dbffa536c
Binary file not shown.
|
After Width: | Height: | Size: 85 KiB |
@ -0,0 +1,25 @@
|
|||||||
|
use bevy::{color::palettes::css::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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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));
|
||||||
|
});
|
||||||
|
}
|
||||||
@ -0,0 +1,52 @@
|
|||||||
|
use bevy::{prelude::*, state::state::FreelyMutableState};
|
||||||
|
|
||||||
|
/// Deck and Cards
|
||||||
|
pub struct ViewPlugin;
|
||||||
|
|
||||||
|
impl Plugin for ViewPlugin {
|
||||||
|
fn build(&self, app: &mut App) {
|
||||||
|
app.add_observer(state_monitor).init_state::<ViewState>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// State component for which view an entity is associated with
|
||||||
|
///
|
||||||
|
#[derive(States, Component, Default, Clone, Eq, PartialEq, Hash, Debug)]
|
||||||
|
pub(crate) enum ViewState {
|
||||||
|
#[default]
|
||||||
|
None,
|
||||||
|
Menu,
|
||||||
|
Play,
|
||||||
|
HowToPlay,
|
||||||
|
About,
|
||||||
|
Sets,
|
||||||
|
Deck,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn button_set_state<S: FreelyMutableState + Clone>(
|
||||||
|
s: S,
|
||||||
|
) -> impl Fn(Trigger<Pointer<Click>>, ResMut<NextState<S>>) {
|
||||||
|
move |_trigger: Trigger<Pointer<Click>>, mut next: ResMut<NextState<S>>| next.set(s.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn state_monitor(
|
||||||
|
trigger: Trigger<StateTransitionEvent<ViewState>>,
|
||||||
|
mut entities: Query<(&ViewState, &mut Visibility)>,
|
||||||
|
) {
|
||||||
|
entities
|
||||||
|
.iter_mut()
|
||||||
|
.for_each(|(view_state, mut visibility)| {
|
||||||
|
info!(
|
||||||
|
"Transition from {:?} to {:?}",
|
||||||
|
trigger.event().exited,
|
||||||
|
trigger.event().entered
|
||||||
|
);
|
||||||
|
if Some(view_state) == trigger.event().exited.as_ref() {
|
||||||
|
*visibility = Visibility::Hidden;
|
||||||
|
}
|
||||||
|
if Some(view_state) == trigger.event().entered.as_ref() {
|
||||||
|
*visibility = Visibility::Inherited;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue