Skip to content

Commit

Permalink
Mapping of descriptor binds?
Browse files Browse the repository at this point in the history
  • Loading branch information
XerTheSquirrel committed Dec 23, 2023
1 parent b150feb commit 8c0f968
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 21 deletions.
26 changes: 23 additions & 3 deletions configuration.c
Original file line number Diff line number Diff line change
Expand Up @@ -6089,6 +6089,10 @@ void config_save_file_salamander(void)

bool input_config_bind_map_get_valid(unsigned bind_index)
{
/* Binds for extra keys are always valid. */
if (bind_index >= RARCH_BIND_ID_EXTRA_BUTTON_START && bind_index <= RARCH_BIND_ID_EXTRA_BUTTON_END)
return true;

const struct input_bind_map *keybind =
(const struct input_bind_map*)INPUT_CONFIG_BIND_MAP_GET(bind_index);
if (!keybind)
Expand All @@ -6111,7 +6115,11 @@ unsigned input_config_bind_map_get_meta(unsigned bind_index)

const char *input_config_bind_map_get_base(unsigned bind_index)
{
const struct input_bind_map *keybind =
/* Binds for extra keys are never mappable in any way. */
if (bind_index >= RARCH_BIND_ID_EXTRA_BUTTON_START && bind_index <= RARCH_BIND_ID_EXTRA_BUTTON_END)
return 0;

const struct input_bind_map *keybind =
(const struct input_bind_map*)INPUT_CONFIG_BIND_MAP_GET(bind_index);
if (!keybind)
return NULL;
Expand All @@ -6120,7 +6128,11 @@ const char *input_config_bind_map_get_base(unsigned bind_index)

const char *input_config_bind_map_get_desc(unsigned bind_index)
{
const struct input_bind_map *keybind =
/* Binds for extra keys are never mappable in any way. */
if (bind_index >= RARCH_BIND_ID_EXTRA_BUTTON_START && bind_index <= RARCH_BIND_ID_EXTRA_BUTTON_END)
return NULL;

const struct input_bind_map *keybind =
(const struct input_bind_map*)INPUT_CONFIG_BIND_MAP_GET(bind_index);
if (!keybind)
return NULL;
Expand All @@ -6129,7 +6141,15 @@ const char *input_config_bind_map_get_desc(unsigned bind_index)

uint8_t input_config_bind_map_get_retro_key(unsigned bind_index)
{
const struct input_bind_map *keybind =
/* Extra binds are very special keys. */
if (bind_index >= RARCH_BIND_ID_EXTRA_BUTTON_START && bind_index <= RARCH_BIND_ID_EXTRA_BUTTON_END)
{
RARCH_LOG("TODO: Handle extra key in input_config_bind_map_get_retro_key(%d)\n",
bind_index);
return 0;
}

const struct input_bind_map *keybind =
(const struct input_bind_map*)INPUT_CONFIG_BIND_MAP_GET(bind_index);
if (!keybind)
return 0;
Expand Down
56 changes: 38 additions & 18 deletions menu/menu_setting.c
Original file line number Diff line number Diff line change
Expand Up @@ -9021,7 +9021,7 @@ static bool setting_append_list_input_player_options(
*/
static char buffer[MAX_USERS][13+2+1];
static char group_label[MAX_USERS][255];
unsigned bindIndex, j;
unsigned logicalIndex, bindIndex;
rarch_setting_group_info_t group_info;
rarch_setting_group_info_t subgroup_info;
settings_t *settings = config_get_ptr();
Expand Down Expand Up @@ -9254,18 +9254,18 @@ static bool setting_append_list_input_player_options(
{
const char *value_na =
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_NOT_AVAILABLE);
for (j = 0; j < RARCH_BIND_LIST_END; j++)
for (bindIndex = 0; bindIndex < RARCH_BIND_LIST_END; bindIndex++)
{
char label[NAME_MAX_LENGTH];
char name[NAME_MAX_LENGTH];
bool isExtraKey = (j >= RARCH_BIND_ID_EXTRA_BUTTON_START && j < RARCH_BIND_ID_EXTRA_BUTTON_END);
bool isExtraKey = (bindIndex >= RARCH_BIND_ID_EXTRA_BUTTON_START && bindIndex <= RARCH_BIND_ID_EXTRA_BUTTON_END);
size_t _len = 0;

bindIndex = (j < RARCH_ANALOG_BIND_LIST_END)
? input_config_bind_order[j]
: j;
logicalIndex = (bindIndex < RARCH_ANALOG_BIND_LIST_END)
? input_config_bind_order[bindIndex]
: bindIndex;

if (!isExtraKey && input_config_bind_map_get_meta(bindIndex))
if (!isExtraKey && input_config_bind_map_get_meta(logicalIndex))
continue;

name[0] = '\0';
Expand All @@ -9281,44 +9281,64 @@ static bool setting_append_list_input_player_options(

if (
settings->bools.input_descriptor_label_show
&& (bindIndex < RARCH_FIRST_META_KEY)
&& (isExtraKey || logicalIndex < RARCH_FIRST_META_KEY)
&& core_has_set_input_descriptor()
&& (bindIndex != RARCH_TURBO_ENABLE)
&& (logicalIndex != RARCH_TURBO_ENABLE)
)
{
if (sys_info->input_desc_btn[user][bindIndex])
/* Remap the binding key to extra key accordingly. */
if (isExtraKey)
{
logicalIndex = RETRO_DEVICE_ID_JOYPAD_MAX_BUTTONS + (bindIndex - RARCH_BIND_ID_EXTRA_BUTTON_START);

/* Debug. */
RARCH_LOG("Reassigned bindIndex %d to logicalIndex %d\n",
bindIndex, logicalIndex);
}

/* Debug. */
if (sys_info->input_desc_btn[user][logicalIndex])
RARCH_LOG("Desc of bind %d/logical %d is %s\n",
bindIndex, logicalIndex,
sys_info->input_desc_btn[user][logicalIndex]);

if (sys_info->input_desc_btn[user][logicalIndex])
strlcpy(label + _len,
sys_info->input_desc_btn[user][bindIndex],
sys_info->input_desc_btn[user][logicalIndex],
sizeof(label) - _len);
else
{
snprintf(label, sizeof(label), "%s (%s)",
input_config_bind_map_get_desc(bindIndex),
input_config_bind_map_get_desc(logicalIndex),
value_na);

if (settings->bools.input_descriptor_hide_unbound)
continue;
}
}
else
else if (!isExtraKey)
strlcpy(label + _len,
input_config_bind_map_get_desc(bindIndex),
input_config_bind_map_get_desc(logicalIndex),
sizeof(label) - _len);

snprintf(name, sizeof(name), "p%u_%s", user + 1, input_config_bind_map_get_base(bindIndex));
/* Not a valid controller key. */
else
continue;

snprintf(name, sizeof(name), "p%u_%s", user + 1, input_config_bind_map_get_base(logicalIndex));

CONFIG_BIND_ALT(
list, list_info,
&input_config_binds[user][bindIndex],
&input_config_binds[user][logicalIndex],
user + 1,
user,
strdup(name),
strdup(label),
&defaults[bindIndex],
&defaults[logicalIndex],
&group_info,
&subgroup_info,
parent_group);
(*list)[list_info->index - 1].bind_type = bindIndex + MENU_SETTINGS_BIND_BEGIN;
(*list)[list_info->index - 1].bind_type = logicalIndex + MENU_SETTINGS_BIND_BEGIN;
}
}

Expand Down

0 comments on commit 8c0f968

Please sign in to comment.