|
|
|
|
@ -11,9 +11,11 @@ impl Plugin for GameActionsPlugin {
|
|
|
|
|
.bind(SimAction::Reset, [Binding::Key(KeyCode::KeyR)]),
|
|
|
|
|
ActionsPlugin::<AudioAction>::new()
|
|
|
|
|
.bind(AudioAction::Toggle, [Binding::Key(KeyCode::KeyM)]),
|
|
|
|
|
ActionsPlugin::<ZoomAction>::new()
|
|
|
|
|
.bind(ZoomAction::Zoom, [Binding::Scroll])
|
|
|
|
|
.bind(ZoomAction::ZoomIn, [Binding::Key(KeyCode::Equal)])
|
|
|
|
|
.bind(ZoomAction::ZoomOut, [Binding::Key(KeyCode::Minus)]),
|
|
|
|
|
ActionsPlugin::<Action>::new()
|
|
|
|
|
.bind(Action::ZoomIn, [Binding::Key(KeyCode::Equal)])
|
|
|
|
|
.bind(Action::ZoomOut, [Binding::Key(KeyCode::Minus)])
|
|
|
|
|
.bind(Action::Quit, [Binding::Key(KeyCode::Escape)]),
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
@ -86,34 +88,52 @@ impl SimAction {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Eq, PartialEq, Hash, GameAction, Default)]
|
|
|
|
|
pub(crate) enum Action {
|
|
|
|
|
#[action_handler(Action::zoom_in)]
|
|
|
|
|
pub(crate) enum ZoomAction {
|
|
|
|
|
#[action_kind(axis)]
|
|
|
|
|
#[action_handler(ZoomAction::zoom)]
|
|
|
|
|
Zoom,
|
|
|
|
|
#[action_handler(ZoomAction::zoom_in)]
|
|
|
|
|
ZoomIn,
|
|
|
|
|
#[action_handler(Action::zoom_out)]
|
|
|
|
|
#[action_handler(ZoomAction::zoom_out)]
|
|
|
|
|
ZoomOut,
|
|
|
|
|
#[default]
|
|
|
|
|
None
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[derive(Copy, Clone, Eq, PartialEq, Hash, GameAction, Default)]
|
|
|
|
|
pub(crate) enum Action {
|
|
|
|
|
#[action_handler(Action::quit)]
|
|
|
|
|
Quit,
|
|
|
|
|
#[default]
|
|
|
|
|
None,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Action {
|
|
|
|
|
fn zoom_in(mut projection: Query<&mut Projection>) {
|
|
|
|
|
projection.iter_mut().for_each(|mut p| match *p {
|
|
|
|
|
Projection::Orthographic(ref mut o) => {
|
|
|
|
|
o.scale *= 0.5;
|
|
|
|
|
impl ZoomAction {
|
|
|
|
|
fn zoom_by(factor: f32, mut projection: Query<&mut Projection>) {
|
|
|
|
|
projection.iter_mut().for_each(|mut p| {
|
|
|
|
|
if let Projection::Orthographic(o) = &mut *p {
|
|
|
|
|
o.scale = (o.scale * factor).clamp(0.05, 20.0);
|
|
|
|
|
}
|
|
|
|
|
_ => todo!(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
fn zoom_out(mut projection: Query<&mut Projection>) {
|
|
|
|
|
projection.iter_mut().for_each(|mut p| match *p {
|
|
|
|
|
Projection::Orthographic(ref mut o) => {
|
|
|
|
|
o.scale /= 0.5;
|
|
|
|
|
|
|
|
|
|
// Simple UI zoom out
|
|
|
|
|
fn zoom(In(delta): In<Vec2>, projection: Query<&mut Projection>) {
|
|
|
|
|
if delta.y != 0.0 {
|
|
|
|
|
ZoomAction::zoom_by(0.9_f32.powf(delta.y), projection); // up = zoom in
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn zoom_in(projection: Query<&mut Projection>) {
|
|
|
|
|
ZoomAction::zoom_by(0.5, projection);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
fn zoom_out(projection: Query<&mut Projection>) {
|
|
|
|
|
ZoomAction::zoom_by(2.0, projection);
|
|
|
|
|
}
|
|
|
|
|
_ => todo!(),
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl Action {
|
|
|
|
|
fn quit(mut writer: MessageWriter<AppExit>) {
|
|
|
|
|
writer.write(AppExit::Success);
|
|
|
|
|
}
|
|
|
|
|
|