Skip to content

Commit

Permalink
Add block_ui_interactions feature (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
100-TomatoJuice authored Oct 7, 2023
1 parent 5a5f82b commit a6cbb21
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
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

0 comments on commit a6cbb21

Please sign in to comment.