From 3a2905067d9dae6172580d39a3eb112a0b62c2fb Mon Sep 17 00:00:00 2001 From: zoltanvb Date: Thu, 15 Feb 2024 16:15:38 +0100 Subject: [PATCH] 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). --- intl/msg_hash_lbl.h | 16 +++++ intl/msg_hash_us.h | 16 +++++ menu/cbs/menu_cbs_sublabel.c | 116 ++++++++++++++++++++++++----------- menu/menu_setting.c | 22 +++---- msg_hash.h | 8 +++ 5 files changed, 130 insertions(+), 48 deletions(-) diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index a754c76b068..dd429f95dad 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -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" diff --git a/intl/msg_hash_us.h b/intl/msg_hash_us.h index 1d9b5d94e13..a1440af263d 100644 --- a/intl/msg_hash_us.h +++ b/intl/msg_hash_us.h @@ -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" diff --git a/menu/cbs/menu_cbs_sublabel.c b/menu/cbs/menu_cbs_sublabel.c index 11a9c4a4394..769ceb0f5b7 100644 --- a/menu/cbs/menu_cbs_sublabel.c +++ b/menu/cbs/menu_cbs_sublabel.c @@ -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,14 @@ 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 +5554,71 @@ 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 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; + + info_single_list_t info_list[] = { +/* { + MENU_ENUM_LABEL_INPUT_LIBRETRO_DEVICE, + NULL + },*/ + { + 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++) { - 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++) + 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)))) { - 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); + BIND_ACTION_SUBLABEL(cbs, info_list[i].cb); return 0; } } diff --git a/menu/menu_setting.c b/menu/menu_setting.c index 459ad253c93..cad4564b3a1 100644 --- a/menu/menu_setting.c +++ b/menu/menu_setting.c @@ -9300,18 +9300,16 @@ static bool setting_append_list_input_player_options( 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), diff --git a/msg_hash.h b/msg_hash.h index dd720ee0b31..c6467c7d645 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -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,