From 0df043aff15f49a9694eb306361a52d056f3270f Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 24 Dec 2019 07:36:01 +0100 Subject: [PATCH] (Menu) Refactor Quick Menu - Controls - each port now has its own submenu --- intl/msg_hash_lbl.h | 2 + menu/cbs/menu_cbs_deferred_push.c | 6 + menu/cbs/menu_cbs_ok.c | 26 +++ menu/menu_cbs.h | 1 + menu/menu_displaylist.c | 342 ++++++++++++++++++++---------- menu/menu_displaylist.h | 1 + menu/menu_driver.h | 2 + msg_hash.h | 1 + 8 files changed, 268 insertions(+), 113 deletions(-) diff --git a/intl/msg_hash_lbl.h b/intl/msg_hash_lbl.h index 51fb5b31c1..f33f5e2a8e 100644 --- a/intl/msg_hash_lbl.h +++ b/intl/msg_hash_lbl.h @@ -277,6 +277,8 @@ MSG_HASH(MENU_ENUM_LABEL_DEFERRED_CDROM_INFO_LIST, "deferred_cdrom_info_list") MSG_HASH(MENU_ENUM_LABEL_DEFERRED_CDROM_INFO_DETAIL_LIST, "deferred_cdrom_info_detail_list") +MSG_HASH(MENU_ENUM_LABEL_DEFERRED_REMAPPINGS_PORT_LIST, + "deferred_remappings_port_list") MSG_HASH(MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST, "deferred_dropdown_box_list") MSG_HASH(MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST_SPECIAL, diff --git a/menu/cbs/menu_cbs_deferred_push.c b/menu/cbs/menu_cbs_deferred_push.c index c901940fd8..337f30bad5 100644 --- a/menu/cbs/menu_cbs_deferred_push.c +++ b/menu/cbs/menu_cbs_deferred_push.c @@ -78,6 +78,11 @@ static int (name)(menu_displaylist_info_t *info) \ return deferred_push_dlist(info, type); \ } +static int deferred_push_remappings_port(menu_displaylist_info_t *info) +{ + return deferred_push_dlist(info, DISPLAYLIST_OPTIONS_REMAPPINGS_PORT); +} + generic_deferred_push(deferred_push_video_shader_preset_parameters, DISPLAYLIST_SHADER_PARAMETERS_PRESET) generic_deferred_push(deferred_push_video_shader_parameters, DISPLAYLIST_SHADER_PARAMETERS) generic_deferred_push(deferred_push_video_shader_preset_save, DISPLAYLIST_SHADER_PRESET_SAVE) @@ -760,6 +765,7 @@ static int menu_cbs_init_bind_deferred_push_compare_label( #if defined(HAVE_LAKKA_SWITCH) || defined(HAVE_LIBNX) {MENU_ENUM_LABEL_SWITCH_CPU_PROFILE, deferred_push_switch_cpu_profile}, #endif + {MENU_ENUM_LABEL_DEFERRED_REMAPPINGS_PORT_LIST, deferred_push_remappings_port }, {MENU_ENUM_LABEL_DEFERRED_ACCOUNTS_LIST, deferred_push_accounts_list}, {MENU_ENUM_LABEL_CORE_LIST, deferred_push_core_list}, {MENU_ENUM_LABEL_LOAD_CONTENT_HISTORY, deferred_push_history_list}, diff --git a/menu/cbs/menu_cbs_ok.c b/menu/cbs/menu_cbs_ok.c index 87486ad21e..b5fd4cb779 100644 --- a/menu/cbs/menu_cbs_ok.c +++ b/menu/cbs/menu_cbs_ok.c @@ -170,6 +170,8 @@ static enum msg_hash_enums action_ok_dl_to_enum(unsigned lbl) { switch (lbl) { + case ACTION_OK_DL_REMAPPINGS_PORT_LIST: + return MENU_ENUM_LABEL_DEFERRED_REMAPPINGS_PORT_LIST; case ACTION_OK_DL_DROPDOWN_BOX_LIST_SHADER_PARAMETER: return MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST_VIDEO_SHADER_PARAMETER; case ACTION_OK_DL_DROPDOWN_BOX_LIST_SHADER_PRESET_PARAMETER: @@ -416,6 +418,15 @@ int generic_action_ok_displaylist_push(const char *path, info.enum_idx = MENU_ENUM_LABEL_DEFERRED_VIDEO_LIST; dl_type = DISPLAYLIST_GENERIC; break; + case ACTION_OK_DL_REMAPPINGS_PORT_LIST: + info.type = type; + info.directory_ptr = idx; + info.path = strdup(label); + info_label = msg_hash_to_str( + MENU_ENUM_LABEL_DEFERRED_REMAPPINGS_PORT_LIST); + info.enum_idx = MENU_ENUM_LABEL_DEFERRED_REMAPPINGS_PORT_LIST; + dl_type = DISPLAYLIST_GENERIC; + break; case ACTION_OK_DL_DROPDOWN_BOX_LIST: info.type = type; info.directory_ptr = idx; @@ -5981,6 +5992,16 @@ static int action_ok_playlist_right_thumbnail_mode(const char *path, ACTION_OK_DL_DROPDOWN_BOX_LIST_PLAYLIST_RIGHT_THUMBNAIL_MODE); } +static int action_ok_remappings_port_list(const char *path, + const char *label, unsigned type, size_t idx, size_t entry_idx) +{ + generic_action_ok_displaylist_push( + path, + NULL, label, 0, idx, 0, + ACTION_OK_DL_REMAPPINGS_PORT_LIST); + return 0; +} + static int action_ok_shader_parameter_dropdown_box_list(const char *path, const char *label, unsigned type, size_t idx, size_t entry_idx) { @@ -7238,6 +7259,11 @@ static int menu_cbs_init_bind_ok_compare_type(menu_file_list_cbs_t *cbs, BIND_ACTION_OK(cbs, action_ok_mixer_stream_actions); } #endif + else if (type >= MENU_SETTINGS_REMAPPING_PORT_BEGIN + && type <= MENU_SETTINGS_REMAPPING_PORT_END) + { + BIND_ACTION_OK(cbs, action_ok_remappings_port_list); + } else if (type >= MENU_SETTINGS_SHADER_PARAMETER_0 && type <= MENU_SETTINGS_SHADER_PARAMETER_LAST) { diff --git a/menu/menu_cbs.h b/menu/menu_cbs.h index f62ddc0554..6774240e6e 100644 --- a/menu/menu_cbs.h +++ b/menu/menu_cbs.h @@ -84,6 +84,7 @@ enum ACTION_OK_DL_FILE_BROWSER_SELECT_DIR, ACTION_OK_DL_INPUT_SETTINGS_LIST, ACTION_OK_DL_INPUT_HAPTIC_FEEDBACK_SETTINGS_LIST, + ACTION_OK_DL_REMAPPINGS_PORT_LIST, ACTION_OK_DL_INPUT_MENU_SETTINGS_LIST, ACTION_OK_DL_DRIVER_SETTINGS_LIST, ACTION_OK_DL_VIDEO_SETTINGS_LIST, diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index f8b807591c..4b2db9d68c 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -4342,29 +4342,6 @@ unsigned menu_displaylist_build_list(file_list_t *list, enum menu_displaylist_ct unsigned p; settings_t *settings = config_get_ptr(); unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS)); - bool is_rgui = string_is_equal( - settings->arrays.menu_driver, "rgui"); - - for (p = 0; p < max_users; p++) - { - char key_type[PATH_MAX_LENGTH]; - char key_analog[PATH_MAX_LENGTH]; - unsigned val = p + 1; - - key_type[0] = key_analog[0] = '\0'; - - snprintf(key_type, sizeof(key_type), - msg_hash_to_str(MENU_ENUM_LABEL_INPUT_LIBRETRO_DEVICE), val); - snprintf(key_analog, sizeof(key_analog), - msg_hash_to_str(MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE), val); - - if (menu_displaylist_parse_settings(list, - key_type, PARSE_ONLY_UINT, true, 0) == 0) - count++; - if (menu_displaylist_parse_settings(list, - key_analog, PARSE_ONLY_UINT, true, 0) == 0) - count++; - } if (menu_entries_append_enum(list, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_REMAP_FILE_LOAD), @@ -4417,96 +4394,13 @@ unsigned menu_displaylist_build_list(file_list_t *list, enum menu_displaylist_ct for (p = 0; p < max_users; p++) { - unsigned retro_id; - unsigned device = settings->uints.input_libretro_device[p]; - device &= RETRO_DEVICE_MASK; - - if (device == RETRO_DEVICE_JOYPAD || device == RETRO_DEVICE_ANALOG) - { - for (retro_id = 0; retro_id < RARCH_ANALOG_BIND_LIST_END; retro_id++) - { - char desc_label[400]; - char descriptor[300]; - const struct retro_keybind *keybind = - &input_config_binds[p][retro_id]; - const struct retro_keybind *auto_bind = - (const struct retro_keybind*) - input_config_get_bind_auto(p, retro_id); - - input_config_get_bind_string(descriptor, - keybind, auto_bind, sizeof(descriptor)); - - if (!strstr(descriptor, "Auto")) - { - const struct retro_keybind *keyptr = - &input_config_binds[p][retro_id]; - - snprintf(desc_label, sizeof(desc_label), - "%s %s", msg_hash_to_str(keyptr->enum_idx), descriptor); - strlcpy(descriptor, desc_label, sizeof(descriptor)); - } - - /* Add user index when display driver == rgui and sublabels - * are disabled, but only if there is more than one user */ - if ( (is_rgui) - && (max_users > 1) - && !settings->bools.menu_show_sublabels) - { - snprintf(desc_label, sizeof(desc_label), - "%s [%s %u]", descriptor, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PORT), p + 1); - strlcpy(descriptor, desc_label, sizeof(descriptor)); - } - - if (menu_entries_append_enum(list, descriptor, "", - MSG_UNKNOWN, - MENU_SETTINGS_INPUT_DESC_BEGIN + - (p * (RARCH_FIRST_CUSTOM_BIND + 8)) + retro_id, 0, 0)) - count++; - } - } - else if (device == RETRO_DEVICE_KEYBOARD) - { - for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND; retro_id++) - { - char desc_label[400]; - char descriptor[300]; - const struct retro_keybind *keybind = - &input_config_binds[p][retro_id]; - const struct retro_keybind *auto_bind = - (const struct retro_keybind*) - input_config_get_bind_auto(p, retro_id); - - input_config_get_bind_string(descriptor, - keybind, auto_bind, sizeof(descriptor)); - - if (!strstr(descriptor, "Auto")) - { - const struct retro_keybind *keyptr = - &input_config_binds[p][retro_id]; - - strlcpy(descriptor, - msg_hash_to_str(keyptr->enum_idx), sizeof(descriptor)); - } - - /* Add user index when display driver == rgui and sublabels - * are disabled, but only if there is more than one user */ - if ( (is_rgui) - && (max_users > 1) - && !settings->bools.menu_show_sublabels) - { - snprintf(desc_label, sizeof(desc_label), - "%s [%s %u]", descriptor, - msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PORT), p + 1); - strlcpy(descriptor, desc_label, sizeof(descriptor)); - } - - if (menu_entries_append_enum(list, descriptor, "", - MSG_UNKNOWN, - MENU_SETTINGS_INPUT_DESC_KBD_BEGIN + - (p * RARCH_FIRST_CUSTOM_BIND) + retro_id, 0, 0)) - count++; - } - } + char val_s[16], val_d[16]; + snprintf(val_s, sizeof(val_s), "Port %d Controls", p+1); + snprintf(val_d, sizeof(val_d), "%d", p); + if (menu_entries_append_enum(list, val_s, val_d, + MSG_UNKNOWN, + MENU_SETTINGS_REMAPPING_PORT_BEGIN + p, p, 0)) + count++; } } break; @@ -7098,6 +6992,228 @@ bool menu_displaylist_ctl(enum menu_displaylist_ctl_state type, switch (type) { + case DISPLAYLIST_OPTIONS_REMAPPINGS_PORT: + menu_entries_ctl(MENU_ENTRIES_CTL_CLEAR, info->list); + + { + settings_t *settings = config_get_ptr(); + unsigned max_users = *(input_driver_get_uint(INPUT_ACTION_MAX_USERS)); + bool is_rgui = string_is_equal( + settings->arrays.menu_driver, "rgui"); + file_list_t *list = info->list; + unsigned p = atoi(info->path); + + { + char key_type[PATH_MAX_LENGTH]; + char key_analog[PATH_MAX_LENGTH]; + unsigned val = p + 1; + + key_type[0] = key_analog[0] = '\0'; + + snprintf(key_type, sizeof(key_type), + msg_hash_to_str(MENU_ENUM_LABEL_INPUT_LIBRETRO_DEVICE), val); + snprintf(key_analog, sizeof(key_analog), + msg_hash_to_str(MENU_ENUM_LABEL_INPUT_PLAYER_ANALOG_DPAD_MODE), val); + + if (menu_displaylist_parse_settings(list, + key_type, PARSE_ONLY_UINT, true, 0) == 0) + count++; + if (menu_displaylist_parse_settings(list, + key_analog, PARSE_ONLY_UINT, true, 0) == 0) + count++; + } + + { + unsigned retro_id; + unsigned device = settings->uints.input_libretro_device[p]; + device &= RETRO_DEVICE_MASK; + + if (device == RETRO_DEVICE_JOYPAD || device == RETRO_DEVICE_ANALOG) + { + for (retro_id = 0; retro_id < RARCH_ANALOG_BIND_LIST_END; retro_id++) + { + char desc_label[400]; + char descriptor[300]; + const struct retro_keybind *keybind = + &input_config_binds[p][retro_id]; + const struct retro_keybind *auto_bind = + (const struct retro_keybind*) + input_config_get_bind_auto(p, retro_id); + + input_config_get_bind_string(descriptor, + keybind, auto_bind, sizeof(descriptor)); + + if (!strstr(descriptor, "Auto")) + { + const struct retro_keybind *keyptr = + &input_config_binds[p][retro_id]; + + snprintf(desc_label, sizeof(desc_label), + "%s %s", msg_hash_to_str(keyptr->enum_idx), descriptor); + strlcpy(descriptor, desc_label, sizeof(descriptor)); + } + + /* Add user index when display driver == rgui and sublabels + * are disabled, but only if there is more than one user */ + if ( (is_rgui) + && (max_users > 1) + && !settings->bools.menu_show_sublabels) + { + snprintf(desc_label, sizeof(desc_label), + "%s [%s %u]", descriptor, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PORT), p + 1); + strlcpy(descriptor, desc_label, sizeof(descriptor)); + } + + if (menu_entries_append_enum(list, descriptor, "", + MSG_UNKNOWN, + MENU_SETTINGS_INPUT_DESC_BEGIN + + (p * (RARCH_FIRST_CUSTOM_BIND + 8)) + retro_id, 0, 0)) + count++; + } + } + else if (device == RETRO_DEVICE_KEYBOARD) + { + for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND; retro_id++) + { + char desc_label[400]; + char descriptor[300]; + const struct retro_keybind *keybind = + &input_config_binds[p][retro_id]; + const struct retro_keybind *auto_bind = + (const struct retro_keybind*) + input_config_get_bind_auto(p, retro_id); + + input_config_get_bind_string(descriptor, + keybind, auto_bind, sizeof(descriptor)); + + if (!strstr(descriptor, "Auto")) + { + const struct retro_keybind *keyptr = + &input_config_binds[p][retro_id]; + + strlcpy(descriptor, + msg_hash_to_str(keyptr->enum_idx), sizeof(descriptor)); + } + + /* Add user index when display driver == rgui and sublabels + * are disabled, but only if there is more than one user */ + if ( (is_rgui) + && (max_users > 1) + && !settings->bools.menu_show_sublabels) + { + snprintf(desc_label, sizeof(desc_label), + "%s [%s %u]", descriptor, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PORT), p + 1); + strlcpy(descriptor, desc_label, sizeof(descriptor)); + } + + if (menu_entries_append_enum(list, descriptor, "", + MSG_UNKNOWN, + MENU_SETTINGS_INPUT_DESC_KBD_BEGIN + + (p * RARCH_FIRST_CUSTOM_BIND) + retro_id, 0, 0)) + count++; + } + } + } + + { + unsigned retro_id; + unsigned device = settings->uints.input_libretro_device[p]; + device &= RETRO_DEVICE_MASK; + + if (device == RETRO_DEVICE_JOYPAD || device == RETRO_DEVICE_ANALOG) + { + for (retro_id = 0; retro_id < RARCH_ANALOG_BIND_LIST_END; retro_id++) + { + char desc_label[400]; + char descriptor[300]; + const struct retro_keybind *keybind = + &input_config_binds[p][retro_id]; + const struct retro_keybind *auto_bind = + (const struct retro_keybind*) + input_config_get_bind_auto(p, retro_id); + + input_config_get_bind_string(descriptor, + keybind, auto_bind, sizeof(descriptor)); + + if (!strstr(descriptor, "Auto")) + { + const struct retro_keybind *keyptr = + &input_config_binds[p][retro_id]; + + snprintf(desc_label, sizeof(desc_label), + "%s %s", msg_hash_to_str(keyptr->enum_idx), descriptor); + strlcpy(descriptor, desc_label, sizeof(descriptor)); + } + + /* Add user index when display driver == rgui and sublabels + * are disabled, but only if there is more than one user */ + if ( (is_rgui) + && (max_users > 1) + && !settings->bools.menu_show_sublabels) + { + snprintf(desc_label, sizeof(desc_label), + "%s [%s %u]", descriptor, msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PORT), p + 1); + strlcpy(descriptor, desc_label, sizeof(descriptor)); + } + + if (menu_entries_append_enum(list, descriptor, "", + MSG_UNKNOWN, + MENU_SETTINGS_INPUT_DESC_BEGIN + + (p * (RARCH_FIRST_CUSTOM_BIND + 8)) + retro_id, 0, 0)) + count++; + } + } + else if (device == RETRO_DEVICE_KEYBOARD) + { + for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND; retro_id++) + { + char desc_label[400]; + char descriptor[300]; + const struct retro_keybind *keybind = + &input_config_binds[p][retro_id]; + const struct retro_keybind *auto_bind = + (const struct retro_keybind*) + input_config_get_bind_auto(p, retro_id); + + input_config_get_bind_string(descriptor, + keybind, auto_bind, sizeof(descriptor)); + + if (!strstr(descriptor, "Auto")) + { + const struct retro_keybind *keyptr = + &input_config_binds[p][retro_id]; + + strlcpy(descriptor, + msg_hash_to_str(keyptr->enum_idx), sizeof(descriptor)); + } + + /* Add user index when display driver == rgui and sublabels + * are disabled, but only if there is more than one user */ + if ( (is_rgui) + && (max_users > 1) + && !settings->bools.menu_show_sublabels) + { + snprintf(desc_label, sizeof(desc_label), + "%s [%s %u]", descriptor, + msg_hash_to_str(MENU_ENUM_LABEL_VALUE_PORT), p + 1); + strlcpy(descriptor, desc_label, sizeof(descriptor)); + } + + if (menu_entries_append_enum(list, descriptor, "", + MSG_UNKNOWN, + MENU_SETTINGS_INPUT_DESC_KBD_BEGIN + + (p * RARCH_FIRST_CUSTOM_BIND) + retro_id, 0, 0)) + count++; + } + } + } + + info->need_push = true; + info->need_refresh = true; + info->need_clear = true; + } + break; #ifdef HAVE_CDROM case DISPLAYLIST_CDROM_DETAIL_INFO: { diff --git a/menu/menu_displaylist.h b/menu/menu_displaylist.h index a3a3aa4a4a..0004ee0e41 100644 --- a/menu/menu_displaylist.h +++ b/menu/menu_displaylist.h @@ -207,6 +207,7 @@ enum menu_displaylist_ctl_state DISPLAYLIST_OPTIONS, DISPLAYLIST_OPTIONS_CHEATS, DISPLAYLIST_OPTIONS_REMAPPINGS, + DISPLAYLIST_OPTIONS_REMAPPINGS_PORT, DISPLAYLIST_OPTIONS_MANAGEMENT, DISPLAYLIST_OPTIONS_DISK, DISPLAYLIST_OPTIONS_SHADERS, diff --git a/menu/menu_driver.h b/menu/menu_driver.h index 8fa4b0c647..ca2c972fd1 100644 --- a/menu/menu_driver.h +++ b/menu/menu_driver.h @@ -191,6 +191,8 @@ enum menu_settings_type MENU_SETTINGS_INPUT_DESC_END = MENU_SETTINGS_INPUT_DESC_BEGIN + ((RARCH_FIRST_CUSTOM_BIND + 8) * MAX_USERS), MENU_SETTINGS_INPUT_DESC_KBD_BEGIN, MENU_SETTINGS_INPUT_DESC_KBD_END = MENU_SETTINGS_INPUT_DESC_KBD_BEGIN + (RARCH_MAX_KEYS * MAX_USERS), + MENU_SETTINGS_REMAPPING_PORT_BEGIN, + MENU_SETTINGS_REMAPPING_PORT_END = MENU_SETTINGS_REMAPPING_PORT_BEGIN + (MAX_USERS), MENU_SETTINGS_SUBSYSTEM_LOAD, diff --git a/msg_hash.h b/msg_hash.h index 7412b57ae7..87f6f3eb69 100644 --- a/msg_hash.h +++ b/msg_hash.h @@ -1243,6 +1243,7 @@ enum msg_hash_enums MENU_ENUM_LABEL_DEFERRED_CDROM_INFO_DETAIL_LIST, MENU_ENUM_LABEL_DEFERRED_LOAD_DISC_LIST, MENU_ENUM_LABEL_DEFERRED_DUMP_DISC_LIST, + MENU_ENUM_LABEL_DEFERRED_REMAPPINGS_PORT_LIST, MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST, MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST_SPECIAL, MENU_ENUM_LABEL_DEFERRED_DROPDOWN_BOX_LIST_RESOLUTION,