Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add block_ui_interactions feature #391

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ opt-level = 3
members = ["./", "tools/ci", "macros"]

[features]
default = ['ui']
default = ['ui', 'block_ui_interactions']
ui = ['bevy/bevy_ui']
block_ui_interactions = []
# If this feature is enabled, egui will have priority over actions when processing inputs
egui = ['dep:bevy_egui']

Expand Down
4 changes: 4 additions & 0 deletions RELEASES.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
- Added `DeadZoneShape` for `DualAxis` which allows for different deadzones shapes: cross, rectangle, and ellipse.
- Added sensitivity for `SingleAxis` and `DualAxis`, allowing you to scale mouse, keypad and gamepad inputs differently for each action.

### Usability

- Added `block_ui_interactions` feature flag; when on, mouse input won't be read if any `bevy_ui` element has an active `Interaction`.

## Version 0.10

### Usability
Expand Down
6 changes: 4 additions & 2 deletions src/systems.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ pub fn update_action_state<A: Actionlike>(
mouse_wheel: Option<Res<Events<MouseWheel>>>,
mouse_motion: Res<Events<MouseMotion>>,
clash_strategy: Res<ClashStrategy>,
#[cfg(feature = "ui")] interactions: Query<&Interaction>,
#[cfg(all(feature = "ui", feature = "block_ui_interactions"))] interactions: Query<
&Interaction,
>,
#[cfg(feature = "egui")] mut maybe_egui: EguiContexts,
action_state: Option<ResMut<ActionState<A>>>,
input_map: Option<Res<InputMap<A>>>,
Expand All @@ -94,7 +96,7 @@ pub fn update_action_state<A: Actionlike>(
let mouse_motion = mouse_motion.into_inner();

// If use clicks on a button, do not apply them to the game state
#[cfg(feature = "ui")]
#[cfg(all(feature = "ui", feature = "block_ui_interactions"))]
let (mouse_buttons, mouse_wheel) = if interactions
.iter()
.any(|&interaction| interaction != Interaction::None)
Expand Down