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 basic gamepad support for bevy_ui by emulating a mouse #6553

Open
alice-i-cecile opened this issue Nov 11, 2022 · 3 comments
Open

Add basic gamepad support for bevy_ui by emulating a mouse #6553

alice-i-cecile opened this issue Nov 11, 2022 · 3 comments
Labels
A-Input Player input via keyboard, mouse, gamepad, and more A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible

Comments

@alice-i-cecile
Copy link
Member

What problem does this solve or what need does it fill?

bevy_ui is, first and foremost a game UI library. However, it is currently very challenging to work with via a gamepad.

What solution would you like?

When used in menus, gamepads should:

  • control the mouse cursor with either analog sticks or the d-pad
  • click buttons (typically when A is pressed)

This requires:

  • a configurable sensitivity that converts these gamepad movements into mouse motion
  • a way to detect whether the KBM or gamepad is being used to drive the UI
  • a way to control whether or not this behavior should be enabled

What alternative(s) have you considered?

You can work around this by mocking mouse movement and mouse button presses, tied to gamepad controls.

However this is non-obvious, frustrating, and not terribly robust.

Additional context

A full-fledged UI navigation system as laid out in bevyengine/rfcs#41 would be very helpful to supplement this, but is not required. Emulating mouse-like behavior is plenty.

@alice-i-cecile alice-i-cecile added C-Feature A new feature, making something new possible A-Input Player input via keyboard, mouse, gamepad, and more A-UI Graphical user interfaces, styles, layouts, and widgets D-Complex Quite challenging from either a design or technical perspective. Ask for help! labels Nov 11, 2022
@alice-i-cecile
Copy link
Member Author

/// A resource that determines which input mode the player is using
enum InputMode {
    KBM,
    Gamepad,
}

fn set_input_mode(
    mut input_mode: ResMut<InputMode>,
    gamepad_events: EventReader<GamepadEvent>,
    keyboard_events: EventReader<KeyboardInput>,
    mouse_events: EventReader<MouseMotion>,
) {
    if !keyboard_events.is_empty() || !mouse_events.is_empty() {
        *input_mode = InputMode::KBM;
    }

    if !gamepad_events.is_empty() {
        *input_mode = InputMode::Gamepad;
    }
}

This code is working well to set the input mode for me.

@alice-i-cecile alice-i-cecile moved this to Todo in UI Nov 11, 2022
@nicopap
Copy link
Contributor

nicopap commented Nov 12, 2022

Note that RFC 41 is fully implemented in #5378 However, I'm still missing a story for mixing hover and focus highlights.

@alice-i-cecile alice-i-cecile removed the D-Complex Quite challenging from either a design or technical perspective. Ask for help! label Nov 12, 2022
@alice-i-cecile alice-i-cecile changed the title Add gamepad support for bevy_ui Add basic gamepad support for bevy_ui by emulating a mouse Nov 12, 2022
@alice-i-cecile
Copy link
Member Author

Removing D-Complex, as I think that the very basic form of this is relatively straightforward to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Input Player input via keyboard, mouse, gamepad, and more A-UI Graphical user interfaces, styles, layouts, and widgets C-Feature A new feature, making something new possible
Projects
Status: Todo
Development

No branches or pull requests

2 participants