|
|
|
@ -1,3 +1,5 @@
|
|
|
|
|
|
|
|
use bevy::window::PrimaryWindow;
|
|
|
|
|
|
|
|
|
|
|
|
use crate::prelude::*;
|
|
|
|
use crate::prelude::*;
|
|
|
|
|
|
|
|
|
|
|
|
pub(crate) struct UiPlugin;
|
|
|
|
pub(crate) struct UiPlugin;
|
|
|
|
@ -16,6 +18,8 @@ impl Plugin for UiPlugin {
|
|
|
|
sync_display_mode
|
|
|
|
sync_display_mode
|
|
|
|
.run_if(state_changed::<DisplayState>())
|
|
|
|
.run_if(state_changed::<DisplayState>())
|
|
|
|
.run_if(in_state(GameState::Play)),
|
|
|
|
.run_if(in_state(GameState::Play)),
|
|
|
|
|
|
|
|
manage_cursor.run_if(any_component_changed::<Interaction>),
|
|
|
|
|
|
|
|
interactive_button.run_if(any_component_changed::<Interaction>),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
@ -96,3 +100,45 @@ fn sync_display_mode(
|
|
|
|
.iter_mut()
|
|
|
|
.iter_mut()
|
|
|
|
.for_each(|mut visibility| *visibility = Visibility::Visible);
|
|
|
|
.for_each(|mut visibility| *visibility = Visibility::Visible);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn manage_cursor(
|
|
|
|
|
|
|
|
mut window: Query<&mut Window, With<PrimaryWindow>>,
|
|
|
|
|
|
|
|
state: Res<State<GameState>>,
|
|
|
|
|
|
|
|
buttons: Query<&Interaction, With<Button>>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
window.single_mut().cursor.icon = {
|
|
|
|
|
|
|
|
// In Loading state, icon is Progess/Wait
|
|
|
|
|
|
|
|
if *state == GameState::Loading {
|
|
|
|
|
|
|
|
CursorIcon::Wait
|
|
|
|
|
|
|
|
// If a button is hovered, icon is hand
|
|
|
|
|
|
|
|
} else if buttons.iter().any(|i| *i == Interaction::Pressed) {
|
|
|
|
|
|
|
|
CursorIcon::Grabbing
|
|
|
|
|
|
|
|
// If a button is clicked, icon is grab
|
|
|
|
|
|
|
|
} else if buttons.iter().any(|i| *i == Interaction::Hovered) {
|
|
|
|
|
|
|
|
CursorIcon::Hand
|
|
|
|
|
|
|
|
// Default icon is Crosshair
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
CursorIcon::Crosshair
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fn interactive_button(
|
|
|
|
|
|
|
|
mut events: Query<(&mut BackgroundColor, &Interaction), (With<Button>, Changed<Interaction>)>,
|
|
|
|
|
|
|
|
mut writer: EventWriter<audio::AudioEvent>,
|
|
|
|
|
|
|
|
) {
|
|
|
|
|
|
|
|
events
|
|
|
|
|
|
|
|
.iter_mut()
|
|
|
|
|
|
|
|
.for_each(|(mut bg_color, interaction)| match interaction {
|
|
|
|
|
|
|
|
Interaction::None => {
|
|
|
|
|
|
|
|
bg_color.0.set_a(0.5);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Interaction::Hovered => {
|
|
|
|
|
|
|
|
bg_color.0.set_a(0.75);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
Interaction::Pressed => {
|
|
|
|
|
|
|
|
bg_color.0.set_a(1.0);
|
|
|
|
|
|
|
|
writer.send(audio::AudioEvent::MenuSelect)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|