Skip to content

Commit

Permalink
Update for Bevy 0.9 and release 0.7 (Leafwing-Studios#284)
Browse files Browse the repository at this point in the history
* Bump version number

* Temporarily remove binding_menu example to avoid blocking on bevy_egui

* Core library compiles

* Temporarily strip egui support

* Fix tests and examples

* Strip egui from Cargo.toml

* Revert "Strip egui from Cargo.toml"

This reverts commit d06d33c.

* Revert "Temporarily strip egui support"

This reverts commit 81da2b4.

* Revert "Temporarily remove binding_menu example to avoid blocking on bevy_egui"

This reverts commit 86487c3.

* Update bevy_egui to 0.19

* Disable inputs when egui is focused more holistically

* Fix coordinates of mouse_motion example

* Remove Option from InputStreams fields
  • Loading branch information
alice-i-cecile authored Nov 13, 2022
1 parent 8feb168 commit 7c3a07d
Show file tree
Hide file tree
Showing 28 changed files with 159 additions and 134 deletions.
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "leafwing-input-manager"
description = "A powerfully direct stateful input manager for the Bevy game engine."
version = "0.6.1"
version = "0.7.0"
authors = ["Leafwing Studios"]
homepage = "https://leafwing-studios.com/"
repository = "https://github.com/leafwing-studios/leafwing-input-manager"
Expand All @@ -24,19 +24,19 @@ ui = ['bevy/bevy_ui']
egui = ['dep:bevy_egui']

[dependencies]
leafwing_input_manager_macros = { path = "macros", version = "0.6" }
leafwing_input_manager_macros = { path = "macros", version = "0.7" }

bevy = {version = "0.8", default-features = false, features = ["serialize", "bevy_gilrs"]}
bevy_egui = {version = "0.16", optional = true}
bevy = {version = "0.9", default-features = false, features = ["serialize", "bevy_gilrs"]}
bevy_egui = {version = "0.17", optional = true}

petitset = {version = "0.2.1", features = ["serde_compat"]}
derive_more = {version = "0.99", default-features = false, features = ["display", "error"]}
itertools = "0.10"
serde = {version = "1.0", features = ["derive"]}

[dev-dependencies]
bevy = {version = "0.8", default-features = false, features = ["bevy_asset", "bevy_sprite", "bevy_text", "bevy_ui", "bevy_render", "bevy_core_pipeline", "x11"]}
bevy_egui = "0.16"
bevy = {version = "0.9", default-features = false, features = ["bevy_asset", "bevy_sprite", "bevy_text", "bevy_ui", "bevy_render", "bevy_core_pipeline", "x11"]}
bevy_egui = {version = "0.17"}

[lib]
name = "leafwing_input_manager"
Expand Down
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,14 +82,13 @@ struct Player;
fn spawn_player(mut commands: Commands) {
commands
.spawn()
.insert(Player)
.insert_bundle(InputManagerBundle::<Action> {
.spawn(InputManagerBundle::<Action> {
// Stores "which actions are currently pressed"
action_state: ActionState::default(),
// Describes how to convert from player inputs into those actions
input_map: InputMap::new([(KeyCode::Space, Action::Jump)]),
});
})
.insert(Player);
}
// Query for the `ActionState` component in your game logic systems!
Expand Down
3 changes: 2 additions & 1 deletion RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Release Notes

## Unreleased
## Version 0.7

### Enhancements

Expand All @@ -9,6 +9,7 @@
### Usability

- Added `egui` feature to not take specific input sources into account when egui is using them. For example, when the user clicks on a widget, the actions associated with the mouse will not be taken into account.
- `InputStreams` no longer stores an `Option` to an input stream type: all fields other than `associated_gamepad` are now required. This was not useful in practice and added significant complexity.

## Version 0.6.1

Expand Down
2 changes: 1 addition & 1 deletion examples/arpg_indirection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ fn spawn_player(mut commands: Commands) {
ability_slot_map.insert(Slot::Ability3, Ability::Dash);
ability_slot_map.insert(Slot::Ability4, Ability::PolymorphSheep);

commands.spawn_bundle(PlayerBundle {
commands.spawn(PlayerBundle {
player: Player,
slot_input_map: InputMap::new([
(Q, Slot::Ability1),
Expand Down
7 changes: 3 additions & 4 deletions examples/axis_inputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@ struct Player;

fn spawn_player(mut commands: Commands) {
commands
.spawn()
.insert(Player)
.insert_bundle(InputManagerBundle::<Action> {
.spawn(InputManagerBundle::<Action> {
// Stores "which actions are currently activated"
action_state: ActionState::default(),
// Describes how to convert from player inputs into those actions
Expand All @@ -44,7 +42,8 @@ fn spawn_player(mut commands: Commands) {
Action::Rudder,
)
.build(),
});
})
.insert(Player);
}

// Query for the `ActionState` component in your game logic systems!
Expand Down
19 changes: 18 additions & 1 deletion examples/binding_menu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ use bevy_egui::{
};
use derive_more::Display;
use leafwing_input_manager::{prelude::*, user_input::InputKind};

const UI_MARGIN: f32 = 10.0;

fn main() {
App::new()
.insert_resource(ControlSettings::default())
Expand All @@ -23,14 +25,16 @@ fn main() {
.add_system(binding_window_system)
.run();
}

fn spawn_player_system(mut commands: Commands, control_settings: Res<ControlSettings>) {
commands.spawn().insert(control_settings.input.clone());
commands.spawn(control_settings.input.clone());
commands.insert_resource(InputMap::<UiAction>::new([(
KeyCode::Escape,
UiAction::Back,
)]));
commands.insert_resource(ActionState::<UiAction>::default());
}

fn controls_window_system(
mut commands: Commands,
mut egui: ResMut<EguiContext>,
Expand Down Expand Up @@ -83,6 +87,7 @@ fn controls_window_system(
ui.expand_to_include_rect(ui.available_rect_before_wrap());
});
}

fn buttons_system(
mut egui: ResMut<EguiContext>,
mut control_settings: ResMut<ControlSettings>,
Expand All @@ -101,6 +106,7 @@ fn buttons_system(
})
});
}

fn binding_window_system(
mut commands: Commands,
mut egui: ResMut<EguiContext>,
Expand Down Expand Up @@ -170,6 +176,7 @@ fn binding_window_system(
}
});
}

#[derive(Actionlike, Debug, PartialEq, Clone, Copy, Display)]
pub(crate) enum ControlAction {
// Movement
Expand All @@ -185,13 +192,17 @@ pub(crate) enum ControlAction {
Ability3,
Ultimate,
}

#[derive(Actionlike, Debug, PartialEq, Clone, Copy)]
pub(crate) enum UiAction {
Back,
}

#[derive(Resource)]
struct ControlSettings {
input: InputMap<ControlAction>,
}

impl Default for ControlSettings {
fn default() -> Self {
let mut input = InputMap::default();
Expand All @@ -209,11 +220,14 @@ impl Default for ControlSettings {
Self { input }
}
}

#[derive(Resource)]
struct ActiveBinding {
action: ControlAction,
index: usize,
conflict: Option<BindingConflict>,
}

impl ActiveBinding {
fn new(action: ControlAction, index: usize) -> Self {
Self {
Expand All @@ -223,17 +237,20 @@ impl ActiveBinding {
}
}
}

struct BindingConflict {
action: ControlAction,
input_button: InputKind,
}

/// Helper for collecting input
#[derive(SystemParam)]
struct InputEvents<'w, 's> {
keys: EventReader<'w, 's, KeyboardInput>,
mouse_buttons: EventReader<'w, 's, MouseButtonInput>,
gamepad_events: EventReader<'w, 's, GamepadEvent>,
}

impl InputEvents<'_, '_> {
fn input_button(&mut self) -> Option<InputKind> {
if let Some(keyboard_input) = self.keys.iter().next() {
Expand Down
2 changes: 1 addition & 1 deletion examples/clash_handling.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ fn spawn_input_map(mut commands: Commands) {

input_map.insert_chord([Key1, Key2, Key3], OneAndTwoAndThree);

commands.spawn_bundle(InputManagerBundle {
commands.spawn(InputManagerBundle {
input_map,
..Default::default()
});
Expand Down
5 changes: 3 additions & 2 deletions examples/consuming_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ fn close_menu<M: Resource + Menu>(

// A quick mock of some UI behavior for demonstration purposes
mod menu_mocking {
use bevy::prelude::Resource;
pub trait Menu {
fn is_open(&self) -> bool;

Expand All @@ -93,7 +94,7 @@ mod menu_mocking {
fn close(&mut self);
}

#[derive(Default)]
#[derive(Resource, Default)]
pub struct MainMenu {
is_open: bool,
}
Expand All @@ -112,7 +113,7 @@ mod menu_mocking {
}
}

#[derive(Default)]
#[derive(Resource, Default)]
pub struct SubMenu {
is_open: bool,
}
Expand Down
7 changes: 3 additions & 4 deletions examples/minimal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,13 @@ struct Player;

fn spawn_player(mut commands: Commands) {
commands
.spawn()
.insert(Player)
.insert_bundle(InputManagerBundle::<Action> {
.spawn(InputManagerBundle::<Action> {
// Stores "which actions are currently pressed"
action_state: ActionState::default(),
// Describes how to convert from player inputs into those actions
input_map: InputMap::new([(KeyCode::Space, Action::Jump)]),
});
})
.insert(Player);
}

// Query for the `ActionState` component in your game logic systems!
Expand Down
10 changes: 5 additions & 5 deletions examples/mouse_motion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,8 @@ enum CameraMovement {

fn setup(mut commands: Commands) {
commands
.spawn()
.insert_bundle(Camera2dBundle::default())
.insert_bundle(InputManagerBundle::<CameraMovement> {
.spawn(Camera2dBundle::default())
.insert(InputManagerBundle::<CameraMovement> {
input_map: InputMap::default()
// This will capture the total continous value, for direct use
// Note that you can also use discrete gesture-like motion, via the `MouseMotionDirection` enum
Expand All @@ -28,7 +27,7 @@ fn setup(mut commands: Commands) {
..default()
});

commands.spawn().insert_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
transform: Transform::from_scale(Vec3::new(100., 100., 1.)),
..default()
});
Expand All @@ -42,6 +41,7 @@ fn pan_camera(mut query: Query<(&mut Transform, &ActionState<CameraMovement>), W
let camera_pan_vector = action_state.axis_pair(CameraMovement::Pan).unwrap();

// Because we're moving the camera, not the object, we want to pan in the opposite direction
// However, UI cordinates are inverted on the y-axis, so we need to flip y a second time
camera_transform.translation.x -= CAMERA_PAN_RATE * camera_pan_vector.x();
camera_transform.translation.y -= CAMERA_PAN_RATE * camera_pan_vector.y();
camera_transform.translation.y += CAMERA_PAN_RATE * camera_pan_vector.y();
}
7 changes: 3 additions & 4 deletions examples/mouse_wheel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ enum CameraMovement {

fn setup(mut commands: Commands) {
commands
.spawn()
.insert_bundle(Camera2dBundle::default())
.insert_bundle(InputManagerBundle::<CameraMovement> {
.spawn(Camera2dBundle::default())
.insert(InputManagerBundle::<CameraMovement> {
input_map: InputMap::default()
// This will capture the total continous value, for direct use
.insert(SingleAxis::mouse_wheel_y(), CameraMovement::Zoom)
Expand All @@ -38,7 +37,7 @@ fn setup(mut commands: Commands) {
..default()
});

commands.spawn().insert_bundle(SpriteBundle {
commands.spawn(SpriteBundle {
transform: Transform::from_scale(Vec3::new(100., 100., 1.)),
..default()
});
Expand Down
4 changes: 2 additions & 2 deletions examples/multiplayer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,15 @@ impl PlayerBundle {
}

fn spawn_players(mut commands: Commands) {
commands.spawn_bundle(PlayerBundle {
commands.spawn(PlayerBundle {
player: Player::One,
input_manager: InputManagerBundle {
input_map: PlayerBundle::input_map(Player::One),
..Default::default()
},
});

commands.spawn_bundle(PlayerBundle {
commands.spawn(PlayerBundle {
player: Player::Two,
input_manager: InputManagerBundle {
input_map: PlayerBundle::input_map(Player::Two),
Expand Down
4 changes: 2 additions & 2 deletions examples/press_duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl PlayerBundle {
}

fn spawn_player(mut commands: Commands) {
commands.spawn_bundle(PlayerBundle {
commands.spawn(PlayerBundle {
player: Player,
velocity: Velocity { x: 0.0 },
input_manager: InputManagerBundle {
Expand All @@ -80,7 +80,7 @@ fn spawn_player(mut commands: Commands) {
}

fn spawn_camera(mut commands: Commands) {
commands.spawn_bundle(Camera2dBundle::default());
commands.spawn(Camera2dBundle::default());
}

/// The longer you hold, the faster you dash when released!
Expand Down
2 changes: 1 addition & 1 deletion examples/send_actions_over_network.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ fn spawn_player(mut commands: Commands) {
use KeyCode::*;

commands
.spawn_bundle(InputManagerBundle {
.spawn(InputManagerBundle {
input_map: InputMap::new([(W, MoveLeft), (D, MoveRight), (Space, Jump)])
.insert(MouseButton::Left, Shoot)
.build(),
Expand Down
2 changes: 1 addition & 1 deletion examples/single_player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ impl PlayerBundle {
}

fn spawn_player(mut commands: Commands) {
commands.spawn_bundle(PlayerBundle {
commands.spawn(PlayerBundle {
player: Player,
input_manager: InputManagerBundle {
input_map: PlayerBundle::default_input_map(),
Expand Down
Loading

0 comments on commit 7c3a07d

Please sign in to comment.