-
-
Notifications
You must be signed in to change notification settings - Fork 289
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
Implement keyboard rebinding support #1301
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments. Another thing I noticed while using it:
- While remapping keys, it's possible for the keyboard inputs to be used to navigate the UI. I think this should be disabled while remapping.
- The need to disable auto-bind is rather unintuitive. If there is some bug where the config is overwritten by auto-bind being on, then I think it should be fixed instead of requiring it to be disabled.
…iption and event handling.
… Reworked a bit code structure to be less redundant.
…ng messages from infos. Inform the user after the remapping is done.
The modifications are tested and complete, feel free to test it and report if you agree with the choices applied to the input management and code design |
Does this includes rebinding buttons to mouse? |
No, of course it can be implemented by just catching the SDL event for the mouse press and bind it to that scancode, but the right mouse button is used to access the UI. Besides i think it's more proper to implement the mouse binding only on analog axis movement since that's the most useful thing when playing with both keyboard and mouse. If the devs agree with this thinkering i might implement it in this PR already. UPDATE: If we want to make sure that the user can use the ESC Button and the mouse buttons/movement we should: -Disable the esc button for the UI permanently, i already have an idea for it. This is needed if we have to guarantee the usage of all keys for the user while playing and not having interferences with the UI, not to mention if i add mouse remapping as well that could be very useful. I can already do the code but i need a response to understand how i have to move. So guarantee freedom with keyboard + mouse but disable button UI interaction, and just let the user move the mouse/use the controller to access the UI, or it stays like so. UPDATE: I guess i'll leave it as it is to avoid a mess. The code works as intended for the keyboard rebinding, mouse/controller might come in another PR later. |
Tried the build for a few weeks, works fine. However, I think it would be a lot more convenient if you could remap specific buttons separately instead of going through the whole remap process. It would also be nice if you could add key mapping profiles as well, since not all games are comfortable to play with the same keys. |
For the profiles might be doable, for the specific buttons i have to see |
The system works as intended, but in the future it will be made more flexible, but for now it's possible to simply bind all the keys to the combination wanted. |
} else if (is_remapping_active) { | ||
xemu_input_keyboard_rebind(event); | ||
} else if (restore_controls) { | ||
xemu_input_restore_defaults(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this done here instead of being called directly when the restore button is pressed?
|
||
void xemu_input_keyboard_rebind(const SDL_Event *ev) | ||
{ | ||
//Check if the user aborts the remapping process. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: This comment adds no value
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Extra newline
primary_color, | ||
(state->buttons & CONTROLLER_BUTTON_RSTICK) ? primary_color : | ||
(state->buttons & rstick_press_anim) ? primary_color : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same as above
float w = tex_items[obj_lstick].w; | ||
float h = tex_items[obj_lstick].h; | ||
float c_x = frame_x+lstick_ctr.x; | ||
float c_y = frame_y+lstick_ctr.y; | ||
float lstick_x = (float)state->axis[CONTROLLER_AXIS_LSTICK_X]/32768.0; | ||
float lstick_y = (float)state->axis[CONTROLLER_AXIS_LSTICK_Y]/32768.0; | ||
int lstick_press_anim = CONTROLLER_BUTTON_LSTICK; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this take the remapping into account?
@@ -38,6 +38,16 @@ | |||
#include "../xemu-xbe.h" | |||
|
|||
MainMenuScene g_main_menu; | |||
bool is_remapping_active = false; | |||
bool duplicate_found = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This variable is unused
} | ||
|
||
if (!is_remapping_active) { | ||
if (Toggle("Reset controls to default", &restore_controls, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about being a toggle as below
@@ -38,6 +38,16 @@ | |||
#include "../xemu-xbe.h" | |||
|
|||
MainMenuScene g_main_menu; | |||
bool is_remapping_active = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Globals should be prefixed with g_
sdl_kbd_scancode_map[23] = SDL_SCANCODE_K; | ||
sdl_kbd_scancode_map[24] = SDL_SCANCODE_O; | ||
|
||
g_config.input.keyboard_controller_scancode_map.a = SDL_SCANCODE_A; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Create a function that takes sdl_kbd_scancode_map
as a parameter and sets the g_config
values like you do when binding is complete, then reuse that here to clean this up.
bool is_remapping_active = false; | ||
bool duplicate_found = false; | ||
bool restore_controls = false; | ||
bool abort_rebinding = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can detect the abort case if you keep a static variable in_progress
in xemu_input_keyboard_rebind
that tracks this:
- Initialize to false
- If
is_remapping_active
is true, andin_progress
is false, set it to true - If
is_remapping_active
is false, andin_progress
is true, this is the abort case. Only change you have to add is to setin_progress
to false after handling - If both are false do nothing, same as now.
- When finished remapping, set
in_progress
to false.
You can rename it to something better if you want, just a suggestion. This removes the need for an extra global.
closing this, please follow #1516 since it's in a better state. |
Special thanks to:
toxicshadow, dracc and antangelo for suggestions.
SSUPI for correcting some errors in the SDL_Event handling.
Partially fixes #136 for keyboard rebinding. Controller rebinding will come in another PR
-Allows you to rebind keyboard controls
-Controls are stored in the .toml file configuration for next boots (no need to remap)
-Checks if a key has already been bound to any previous key to avoid conflicts.
-Uses same window for the controller, no extra UI windows.
-A white text under the toggles tells to the user what key for xemu he is binding for each key.
-Button press, rumble, analog movement and trigger animations during remapping are disabled to avoid confusing visual conflicts with already mapped keys before changing them.
-When remapping, a "Abort rebinding" toggle will appear, so the user can manually stop the binding process. This will not alter the already done bindings just in case the user presses the toggle by mistake.
-The auto-bind option has been removed, instead there's a "Reset controls to default" option, so the user can reset his controls while running xemu, and doesn't need to reboot to get the controls updated at runtime. The .toml file is updated on reboot with defaults if a remapping is not done after this option.
-While remapping, the "Reset controls to default" toggle will disappear.
-As soon the user by mistake changes window or closes the menu, the remapping process is aborted and we restore the default keys, since SDL still continues to catch events if outside of that window, meaning that the user will involountary map the keys even if it doesn't want to.
-The ESC button will NOT make the user exit the window while remapping. The button can be mapped as well.
Showcase (updated at 6/12/2022 14:56pm):
8mb.video-DjK-X4K1DlWm.mp4