Skip to content

Commit

Permalink
Input Remapping: Reorder selectable buttons
Browse files Browse the repository at this point in the history
- Put A,B,X,Y together. Match dpad and analog direction orders
  • Loading branch information
neil4 committed Oct 20, 2024
1 parent 047ea86 commit aed6088
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 43 deletions.
70 changes: 70 additions & 0 deletions input/input_remapping.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,76 @@ const struct retro_input_descriptor default_rid[DEFAULT_NUM_REMAPS] = {
{ 0, RETRO_DEVICE_ANALOG, RETRO_DEVICE_INDEX_ANALOG_RIGHT, RETRO_DEVICE_ID_ANALOG_Y, "Right Analog Y" }
};

#define NUM_REMAP_BTNS 25
#define NUM_DIGITAL_REMAP_BTNS 17

/* Defines the order of selectable buttons */
const unsigned input_remapping_btn_order[NUM_REMAP_BTNS] = {
NO_BTN,
RETRO_DEVICE_ID_JOYPAD_A,
RETRO_DEVICE_ID_JOYPAD_B,
RETRO_DEVICE_ID_JOYPAD_X,
RETRO_DEVICE_ID_JOYPAD_Y,
RETRO_DEVICE_ID_JOYPAD_SELECT,
RETRO_DEVICE_ID_JOYPAD_START,
RETRO_DEVICE_ID_JOYPAD_LEFT,
RETRO_DEVICE_ID_JOYPAD_RIGHT,
RETRO_DEVICE_ID_JOYPAD_UP,
RETRO_DEVICE_ID_JOYPAD_DOWN,
RETRO_DEVICE_ID_JOYPAD_L,
RETRO_DEVICE_ID_JOYPAD_R,
RETRO_DEVICE_ID_JOYPAD_L2,
RETRO_DEVICE_ID_JOYPAD_R2,
RETRO_DEVICE_ID_JOYPAD_L3,
RETRO_DEVICE_ID_JOYPAD_R3,
RARCH_ANALOG_LEFT_X_MINUS,
RARCH_ANALOG_LEFT_X_PLUS,
RARCH_ANALOG_LEFT_Y_MINUS,
RARCH_ANALOG_LEFT_Y_PLUS,
RARCH_ANALOG_RIGHT_X_MINUS,
RARCH_ANALOG_RIGHT_X_PLUS,
RARCH_ANALOG_RIGHT_Y_MINUS,
RARCH_ANALOG_RIGHT_Y_PLUS
};

unsigned input_remapping_next_id(unsigned id, bool digital_only)
{
const int max_i = digital_only
? NUM_DIGITAL_REMAP_BTNS - 1
: NUM_REMAP_BTNS - 1;
int i = max_i;

/* Find index of id. Default to 0 (NO_BTN) */
while (i && id != input_remapping_btn_order[i])
i--;

/* Get next */
return input_remapping_btn_order[min(i + 1, max_i)];
}

unsigned input_remapping_prev_id(unsigned id, bool digital_only)
{
int i = digital_only
? NUM_DIGITAL_REMAP_BTNS - 1
: NUM_REMAP_BTNS - 1;

/* Find index of id. Default to 0 (NO_BTN) */
while (i && id != input_remapping_btn_order[i])
i--;

/* Get previous */
return input_remapping_btn_order[max(i - 1, 0)];
}

unsigned input_remapping_last_id(bool digital_only)
{
const int num_btns = digital_only
? NUM_DIGITAL_REMAP_BTNS
: NUM_REMAP_BTNS;

return input_remapping_btn_order[num_btns - 1];
}

/**
* input_remapping_load_file:
* @path : Path to remapping file (absolute path).
Expand Down
5 changes: 5 additions & 0 deletions input/input_remapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ extern "C" {

extern unsigned input_remapping_scope;
extern bool input_remapping_touched;
extern const unsigned input_remapping_btn_order[];

/**
* input_remapping_load_file:
Expand Down Expand Up @@ -71,6 +72,10 @@ void input_remapping_set_default_desc();
*/
void input_remapping_get_path(char* path, unsigned scope);

unsigned input_remapping_next_id(unsigned id, bool digital_only);
unsigned input_remapping_prev_id(unsigned id, bool digital_only);
unsigned input_remapping_last_id(bool digital_only);

#ifdef __cplusplus
}
#endif
Expand Down
29 changes: 13 additions & 16 deletions menu/cbs/menu_cbs_left.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../menu_shader.h"
#include "../menu_navigation.h"

#include "../../input/input_remapping.h"
#include "../../input/input_joypad_to_keyboard.h"

#include "../../general.h"
Expand Down Expand Up @@ -111,11 +112,14 @@ static int action_left_input_desc(unsigned type, const char *label,
else
mapped_id = &settings->input.remap_ids[inp_desc_user][inp_desc_button_index_offset];

(*mapped_id)--;

/* Treat NO_BTN as leftmost value */
if (*mapped_id > RARCH_FIRST_CUSTOM_BIND + 3)
*mapped_id = NO_BTN;
if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND)
*mapped_id = input_remapping_prev_id(*mapped_id, true);
else
{
(*mapped_id)--;
if (*mapped_id > RARCH_FIRST_CUSTOM_BIND + 3)
*mapped_id = NO_BTN;
}

input_remapping_touched = true;
return 0;
Expand All @@ -134,7 +138,6 @@ static int action_l_input_desc(unsigned type, const char *label)
else
mapped_id = &settings->input.remap_ids[inp_desc_user][inp_desc_button_index_offset];

/* Treat NO_BTN as leftmost value */
*mapped_id = NO_BTN;

input_remapping_touched = true;
Expand All @@ -148,13 +151,9 @@ static int action_left_joykbd_input_desc(unsigned type, const char *label,
uint16_t joy_btn = joykbd_bind_list[joykbd_list_offset].btn;
enum retro_key rk = joykbd_bind_list[joykbd_list_offset].rk;

/* Treat NO_BTN as leftmost value */
if (joy_btn < NUM_JOYKBD_BTNS)
{
input_joykbd_remove_bind(rk, joy_btn);
joy_btn--;
input_joykbd_add_bind(rk, joy_btn);
}
input_joykbd_remove_bind(rk, joy_btn);
joy_btn = input_remapping_prev_id(joy_btn, false);
input_joykbd_add_bind(rk, joy_btn);

input_remapping_touched = true;
return 0;
Expand All @@ -166,9 +165,7 @@ static int action_l_joykbd_input_desc(unsigned type, const char *label)
uint16_t joy_btn = joykbd_bind_list[joykbd_list_offset].btn;
enum retro_key rk = joykbd_bind_list[joykbd_list_offset].rk;

/* Treat NO_BTN as leftmost value */
if (joy_btn < NUM_JOYKBD_BTNS)
input_joykbd_remove_bind(rk, joy_btn);
input_joykbd_remove_bind(rk, joy_btn);

input_remapping_touched = true;
return 0;
Expand Down
36 changes: 9 additions & 27 deletions menu/cbs/menu_cbs_right.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#include "../menu_shader.h"
#include "../menu_navigation.h"
#include "../../retroarch.h"
#include "../../input/input_remapping.h"

extern unsigned input_remapping_scope;
extern bool input_remapping_touched;
Expand Down Expand Up @@ -106,14 +107,8 @@ int action_right_input_desc(unsigned type, const char *label,
else
mapped_id = &settings->input.remap_ids[inp_desc_user][inp_desc_button_index_offset];

/* Treat NO_BTN as leftmost value */
if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND)
{
if (*mapped_id < RARCH_FIRST_CUSTOM_BIND - 1)
(*mapped_id)++;
else if (*mapped_id > RARCH_FIRST_CUSTOM_BIND)
*mapped_id = 0;
}
*mapped_id = input_remapping_next_id(*mapped_id, true);
else
{
if (*mapped_id < 4 - 1)
Expand All @@ -140,7 +135,7 @@ int action_r_input_desc(unsigned type, const char *label)
mapped_id = &settings->input.remap_ids[inp_desc_user][inp_desc_button_index_offset];

if (inp_desc_button_index_offset < RARCH_FIRST_CUSTOM_BIND)
*mapped_id = RARCH_FIRST_CUSTOM_BIND - 1;
*mapped_id = input_remapping_last_id(true);
else
*mapped_id = 4 - 1;

Expand All @@ -155,18 +150,9 @@ static int action_right_joykbd_input_desc(unsigned type, const char *label,
uint16_t joy_btn = joykbd_bind_list[joykbd_list_offset].btn;
enum retro_key rk = joykbd_bind_list[joykbd_list_offset].rk;

/* Treat NO_BTN as leftmost value */
if (joy_btn < NUM_JOYKBD_BTNS - 1)
{
input_joykbd_remove_bind(rk, joy_btn);
joy_btn++;
input_joykbd_add_bind(rk, joy_btn);
}
else if (joy_btn > NUM_JOYKBD_BTNS - 1)
{
joy_btn = 0;
input_joykbd_add_bind(rk, joy_btn);
}
input_joykbd_remove_bind(rk, joy_btn);
joy_btn = input_remapping_next_id(joy_btn, false);
input_joykbd_add_bind(rk, joy_btn);

input_remapping_touched = true;
return 0;
Expand All @@ -178,13 +164,9 @@ static int action_r_joykbd_input_desc(unsigned type, const char *label)
uint16_t joy_btn = joykbd_bind_list[joykbd_list_offset].btn;
enum retro_key rk = joykbd_bind_list[joykbd_list_offset].rk;

/* Treat NO_BTN as leftmost value */
if (joy_btn != NUM_JOYKBD_BTNS - 1)
{
input_joykbd_remove_bind(rk, joy_btn);
joy_btn = NUM_JOYKBD_BTNS - 1;
input_joykbd_add_bind(rk, joy_btn);
}
input_joykbd_remove_bind(rk, joy_btn);
joy_btn = input_remapping_last_id(false);
input_joykbd_add_bind(rk, joy_btn);

input_remapping_touched = true;
return 0;
Expand Down

0 comments on commit aed6088

Please sign in to comment.