Sublabels for input bind common entries (#16242)

* Add sublabels for "port x controls" entries

Due to the port-specific indexes, sublabels for these entries
are handled specially. Some simplification/generalization  was
applied and hand-crafted string joining was removed from a few
places, though it remains still in other places.

Preparation for #16121 (this commit does not do anything yet with
file names).

* Further simplifications around joypad_index

Removed a few labels, now unused, and the left/right check, as it
fell back to the default which is given anyway in advance.
This commit is contained in:
zoltanvb 2024-02-18 17:23:56 +01:00 committed by GitHub
parent 8071b49f9d
commit 46cc2250cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 133 additions and 111 deletions

View File

@ -1975,6 +1975,22 @@ MSG_HASH(
MENU_ENUM_LABEL_INPUT_MOUSE_INDEX,
"input_player%u_mouse_index"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_JOYPAD_INDEX,
"input_player%u_joypad_index"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_BIND_ALL_INDEX,
"input_player%u_bind_all"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_SAVE_AUTOCONFIG_INDEX,
"input_player%u_bind_all_save_autoconfig"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_BIND_DEFAULTS_INDEX,
"input_player%u_bind_all_bind_defaults"
)
MSG_HASH(
MENU_ENUM_LABEL_INPUT_REMAP_PORT,
"input_remap_port_p%u"

View File

@ -4101,6 +4101,10 @@ MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_DEVICE_INDEX,
"Device Index"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_DEVICE_INDEX,
"The physical controller as recognized by RetroArch."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_REMAP_PORT,
"Mapped Port"
@ -4113,14 +4117,26 @@ MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_BIND_ALL,
"Set All Controls"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_BIND_ALL,
"Assign all directions and buttons, one after the other, in the order they appear in this menu."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_BIND_DEFAULT_ALL,
"Reset to Default Controls"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_BIND_DEFAULTS,
"Clear input bind settings to their default values."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_SAVE_AUTOCONFIG,
"Save Controller Profile"
)
MSG_HASH(
MENU_ENUM_SUBLABEL_INPUT_SAVE_AUTOCONFIG,
"Save an autoconfiguration file that will be applied automatically whenever this controller is detected again."
)
MSG_HASH(
MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_INDEX,
"Mouse Index"

View File

@ -1000,25 +1000,6 @@ static int menu_cbs_init_bind_left_compare_label(menu_file_list_cbs_t *cbs,
const char *label, size_t lbl_len, const char *menu_label, size_t menu_lbl_len)
{
if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player"))
&& string_ends_with_size(label, "_joypad_index", lbl_len,
STRLEN_CONST("_joypad_index")))
{
unsigned i;
char lbl_setting[128];
size_t _len = strlcpy(lbl_setting, "input_player", sizeof(lbl_setting));
for (i = 0; i < MAX_USERS; i++)
{
snprintf(lbl_setting + _len, sizeof(lbl_setting) - _len, "%d_joypad_index", i + 1);
if (!string_is_equal(label, lbl_setting))
continue;
BIND_ACTION_LEFT(cbs, bind_left_generic);
return 0;
}
}
if (string_is_equal(menu_label, msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)))
{
BIND_ACTION_LEFT(cbs, action_left_mainmenu);

View File

@ -1141,26 +1141,6 @@ static int menu_cbs_init_bind_right_compare_label(menu_file_list_cbs_t *cbs,
const char *label, size_t lbl_len, const char *menu_lbl, size_t menu_lbl_len)
{
if ( string_starts_with_size(label, "input_player", STRLEN_CONST("input_player"))
&& string_ends_with_size(label, "_joypad_index", lbl_len,
STRLEN_CONST("_joypad_index")))
{
unsigned i;
char lbl_setting[128];
size_t _len = strlcpy(lbl_setting, "input_player", sizeof(lbl_setting));
for (i = 0; i < MAX_USERS; i++)
{
_len += snprintf(lbl_setting + _len, sizeof(lbl_setting) - _len, "%d", i + 1);
strlcpy(lbl_setting + _len, "_joypad_index", sizeof(lbl_setting) - _len);
if (!string_is_equal(label, lbl_setting))
continue;
BIND_ACTION_RIGHT(cbs, bind_right_generic);
return 0;
}
}
if (string_is_equal(menu_lbl, msg_hash_to_str(MENU_ENUM_LABEL_PLAYLISTS_TAB)))
{
BIND_ACTION_RIGHT(cbs, action_right_mainmenu);

View File

@ -478,7 +478,11 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_meta_netplay_fade_chat_toggle,
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_hotkey_block_delay, MENU_ENUM_SUBLABEL_INPUT_HOTKEY_BLOCK_DELAY)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_hotkey_device_merge, MENU_ENUM_SUBLABEL_INPUT_HOTKEY_DEVICE_MERGE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_device_type, MENU_ENUM_SUBLABEL_INPUT_DEVICE_TYPE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_device_index, MENU_ENUM_SUBLABEL_INPUT_DEVICE_INDEX)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_adc_type, MENU_ENUM_SUBLABEL_INPUT_ADC_TYPE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_bind_all, MENU_ENUM_SUBLABEL_INPUT_BIND_ALL)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_save_autoconfig, MENU_ENUM_SUBLABEL_INPUT_SAVE_AUTOCONFIG)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_bind_defaults, MENU_ENUM_SUBLABEL_INPUT_BIND_DEFAULTS)
#ifdef HAVE_MATERIALUI
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_materialui_icons_enable, MENU_ENUM_SUBLABEL_MATERIALUI_ICONS_ENABLE)
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_materialui_switch_icons, MENU_ENUM_SUBLABEL_MATERIALUI_SWITCH_ICONS)
@ -2180,6 +2184,17 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
action_bind_sublabel_cheat_desc
},
#endif
{
MENU_SETTINGS_CORE_OPTION_START,
MENU_SETTINGS_CHEEVOS_START - 1,
action_bind_sublabel_core_option
},
{
MENU_SETTINGS_REMAPPING_PORT_BEGIN,
MENU_SETTINGS_REMAPPING_PORT_END,
action_bind_sublabel_user_remap_settings
},
};
if (!cbs)
@ -2196,30 +2211,11 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
}
}
if ((type >= MENU_SETTINGS_CORE_OPTION_START) &&
(type < MENU_SETTINGS_CHEEVOS_START))
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_core_option);
return 0;
}
/* Quick Menu Port Controls require special handling */
if ( type >= MENU_SETTINGS_REMAPPING_PORT_BEGIN
&& type <= MENU_SETTINGS_REMAPPING_PORT_END)
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_user_remap_settings);
return 0;
}
else if (type == MENU_SETTINGS_INPUT_LIBRETRO_DEVICE)
if (type == MENU_SETTINGS_INPUT_LIBRETRO_DEVICE)
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_device_type);
return 0;
}
else if (type == MENU_SETTINGS_INPUT_ANALOG_DPAD_MODE)
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_adc_type);
return 0;
}
else if (type == MENU_SETTINGS_INPUT_INPUT_REMAP_PORT)
{
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_remap_port);
@ -5555,26 +5551,72 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
}
else
{
/* Per-port 'Analog to Digital Type' entries
* require special handling */
if ( string_starts_with_size(label, "input_player",
STRLEN_CONST("input_player"))
&& string_ends_with_size(label, "_analog_dpad_mode",
lbl_len, STRLEN_CONST("_analog_dpad_mode")))
/* Per-port entries require string match against label.
* Some cases may be detected above by "type", but not all. */
typedef struct info_single_list
{
unsigned i;
char key_input_adc_type[64];
size_t _len = strlcpy(key_input_adc_type, "input_player", sizeof(key_input_adc_type));
for (i = 0; i < MAX_USERS; i++)
unsigned label_idx;
int (*cb)(file_list_t *list,
unsigned type, unsigned i,
const char *label, const char *path,
char *s, size_t len);
} info_single_list_t;
/* Entries with %u player index placeholder. */
info_single_list_t info_list[] = {
/* {
MENU_ENUM_LABEL_INPUT_LIBRETRO_DEVICE,
NULL
},*/
{
size_t _len2 = snprintf(key_input_adc_type + _len,
sizeof(key_input_adc_type) - _len, "%u", i + 1);
strlcpy(key_input_adc_type + _len2,
"_analog_dpad_mode",
sizeof(key_input_adc_type) - _len2);
if (!string_is_equal(label, key_input_adc_type))
continue;
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_adc_type);
MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE,
action_bind_sublabel_input_adc_type
},
/* {
MENU_ENUM_LABEL_INPUT_DEVICE_INDEX,
NULL
},
{
MENU_ENUM_LABEL_INPUT_MOUSE_INDEX,
NULL
},
{
MENU_ENUM_LABEL_INPUT_REMAP_PORT,
NULL
},*/
{
MENU_ENUM_LABEL_INPUT_JOYPAD_INDEX,
action_bind_sublabel_input_device_index
},
{
MENU_ENUM_LABEL_INPUT_BIND_ALL_INDEX,
action_bind_sublabel_input_bind_all
},
{
MENU_ENUM_LABEL_INPUT_SAVE_AUTOCONFIG_INDEX,
action_bind_sublabel_input_save_autoconfig
},
{
MENU_ENUM_LABEL_INPUT_BIND_DEFAULTS_INDEX,
action_bind_sublabel_input_bind_defaults
},
};
const char* idx_placeholder = "%u";
for (i = 0; i < ARRAY_SIZE(info_list); i++)
{
int idxpos = -1;
idxpos = string_find_index_substring_string(msg_hash_to_str(info_list[i].label_idx), idx_placeholder);
if ( idxpos > 0 &&
string_starts_with_size(label, msg_hash_to_str(info_list[i].label_idx), idxpos) &&
(( (size_t) idxpos == strlen(msg_hash_to_str(info_list[i].label_idx)) - 2) ||
( (size_t) idxpos < strlen(msg_hash_to_str(info_list[i].label_idx)) - 2 &&
string_ends_with_size(label,
msg_hash_to_str(info_list[i].label_idx)+idxpos+2,
lbl_len,
strlen(msg_hash_to_str(info_list[i].label_idx))-idxpos-2))))
{
BIND_ACTION_SUBLABEL(cbs, info_list[i].cb);
return 0;
}
}

View File

@ -8024,13 +8024,6 @@ static void general_read_handler(rarch_setting_t *setting)
case MENU_ENUM_LABEL_VIDEO_REFRESH_RATE_AUTO:
*setting->value.target.fraction = settings->floats.video_refresh_rate;
break;
case MENU_ENUM_LABEL_INPUT_PLAYER1_JOYPAD_INDEX:
case MENU_ENUM_LABEL_INPUT_PLAYER2_JOYPAD_INDEX:
case MENU_ENUM_LABEL_INPUT_PLAYER3_JOYPAD_INDEX:
case MENU_ENUM_LABEL_INPUT_PLAYER4_JOYPAD_INDEX:
case MENU_ENUM_LABEL_INPUT_PLAYER5_JOYPAD_INDEX:
*setting->value.target.integer = settings->uints.input_joypad_index[setting->enum_idx - MENU_ENUM_LABEL_INPUT_PLAYER1_JOYPAD_INDEX];
break;
#ifdef ANDROID
case MENU_ENUM_LABEL_INPUT_SELECT_PHYSICAL_KEYBOARD:
setting->value.target.string = settings->arrays.input_android_physical_keyboard;
@ -8439,14 +8432,6 @@ static void general_write_handler(rarch_setting_t *setting)
case MENU_ENUM_LABEL_INPUT_MAX_USERS:
command_event(CMD_EVENT_CONTROLLER_INIT, NULL);
break;
case MENU_ENUM_LABEL_INPUT_PLAYER1_JOYPAD_INDEX:
case MENU_ENUM_LABEL_INPUT_PLAYER2_JOYPAD_INDEX:
case MENU_ENUM_LABEL_INPUT_PLAYER3_JOYPAD_INDEX:
case MENU_ENUM_LABEL_INPUT_PLAYER4_JOYPAD_INDEX:
case MENU_ENUM_LABEL_INPUT_PLAYER5_JOYPAD_INDEX:
settings->modified = true;
settings->uints.input_joypad_index[setting->enum_idx - MENU_ENUM_LABEL_INPUT_PLAYER1_JOYPAD_INDEX] = *setting->value.target.integer;
break;
#ifdef ANDROID
case MENU_ENUM_LABEL_INPUT_SELECT_PHYSICAL_KEYBOARD:
settings->modified = true;
@ -9275,8 +9260,6 @@ static bool setting_append_list_input_player_options(
parent_group);
{
char tmp_string[32];
static char device_index[MAX_USERS][64];
static char mouse_index[MAX_USERS][64];
static char analog_to_digital[MAX_USERS][64];
@ -9295,23 +9278,19 @@ static bool setting_append_list_input_player_options(
static char split_joycon[MAX_USERS][64];
static char label_split_joycon[MAX_USERS][64];
#endif
size_t _len = strlcpy(tmp_string, "input_player", sizeof(tmp_string));
snprintf(tmp_string + _len, sizeof(tmp_string) - _len, "%u", user + 1);
snprintf(analog_to_digital[user], sizeof(analog_to_digital[user]),
snprintf(analog_to_digital[user], sizeof(analog_to_digital[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE), user + 1);
fill_pathname_join_delim(device_index[user], tmp_string, "joypad_index", '_',
sizeof(device_index[user]));
fill_pathname_join_delim(mouse_index[user], tmp_string, "mouse_index", '_',
sizeof(mouse_index[user]));
fill_pathname_join_delim(bind_all[user], tmp_string, "bind_all", '_',
sizeof(bind_all[user]));
fill_pathname_join_delim(bind_all_save_autoconfig[user],
tmp_string, "bind_all_save_autoconfig", '_',
sizeof(bind_all_save_autoconfig[user]));
fill_pathname_join_delim(bind_defaults[user],
tmp_string, "bind_defaults", '_',
sizeof(bind_defaults[user]));
snprintf(device_index[user], sizeof(device_index[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_JOYPAD_INDEX), user + 1);
snprintf(mouse_index[user], sizeof(mouse_index[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_MOUSE_INDEX), user + 1);
snprintf(bind_all[user], sizeof(bind_all[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_BIND_ALL_INDEX), user + 1);
snprintf(bind_all_save_autoconfig[user], sizeof(bind_all_save_autoconfig[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_SAVE_AUTOCONFIG_INDEX), user + 1);
snprintf(bind_defaults[user], sizeof(bind_defaults[user]),
msg_hash_to_str(MENU_ENUM_LABEL_INPUT_BIND_DEFAULTS_INDEX), user + 1);
strlcpy(label_analog_to_digital[user],
msg_hash_to_str(MENU_ENUM_LABEL_VALUE_INPUT_ADC_TYPE),

View File

@ -892,11 +892,11 @@ enum msg_hash_enums
MENU_LABEL(INPUT_TURBO_DEFAULT_BUTTON),
MENU_LABEL(INPUT_ALLOW_TURBO_DPAD),
MENU_ENUM_LABEL_INPUT_PLAYER1_JOYPAD_INDEX,
/* MENU_ENUM_LABEL_INPUT_PLAYER1_JOYPAD_INDEX,
MENU_ENUM_LABEL_INPUT_PLAYER2_JOYPAD_INDEX,
MENU_ENUM_LABEL_INPUT_PLAYER3_JOYPAD_INDEX,
MENU_ENUM_LABEL_INPUT_PLAYER4_JOYPAD_INDEX,
MENU_ENUM_LABEL_INPUT_PLAYER5_JOYPAD_INDEX,
MENU_ENUM_LABEL_INPUT_PLAYER5_JOYPAD_INDEX,*/
MENU_ENUM_LABEL_INPUT_BIND_DEVICE_TYPE,
MENU_ENUM_LABEL_INPUT_BIND_DEVICE_INDEX,
@ -1148,11 +1148,19 @@ enum msg_hash_enums
MENU_ENUM_LABEL_VALUE_INPUT_BIND_DEFAULT_ALL,
MENU_ENUM_LABEL_VALUE_INPUT_SAVE_AUTOCONFIG,
MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_INDEX,
MENU_ENUM_LABEL_INPUT_JOYPAD_INDEX,
MENU_ENUM_LABEL_INPUT_BIND_ALL_INDEX,
MENU_ENUM_LABEL_INPUT_SAVE_AUTOCONFIG_INDEX,
MENU_ENUM_LABEL_INPUT_BIND_DEFAULTS_INDEX,
MENU_ENUM_LABEL_VALUE_INPUT_REMAP_PORT,
MENU_ENUM_SUBLABEL_INPUT_DEVICE_TYPE,
MENU_ENUM_SUBLABEL_INPUT_DEVICE_INDEX,
MENU_ENUM_SUBLABEL_INPUT_ADC_TYPE,
MENU_ENUM_LABEL_HELP_INPUT_ADC_TYPE,
MENU_ENUM_SUBLABEL_INPUT_BIND_ALL,
MENU_ENUM_SUBLABEL_INPUT_SAVE_AUTOCONFIG,
MENU_ENUM_SUBLABEL_INPUT_BIND_DEFAULTS,
MENU_ENUM_SUBLABEL_INPUT_REMAP_PORT,
MENU_ENUM_SUBLABEL_INPUT_META_ENABLE_HOTKEY,