From 19d090d3ae69acc2703dfc86ddc8141cf50a4ee5 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Sun, 25 Jan 2015 03:32:03 +0100 Subject: [PATCH] Part 2 of menu input remapping --- general.h | 2 + input/input_remapping.c | 39 +++++++++++++++++++ input/input_remapping.h | 10 +++++ menu/menu.h | 1 + menu/menu_entries_cbs.c | 86 ++++++++++++++++++++++++++++++++++++++++- settings_data.c | 6 +++ 6 files changed, 142 insertions(+), 2 deletions(-) diff --git a/general.h b/general.h index c09b258eea..2baeaef783 100644 --- a/general.h +++ b/general.h @@ -307,6 +307,7 @@ struct settings bool input_descriptor_label_show; bool input_descriptor_hide_unbound; + char menu_remapping_path[PATH_MAX_LENGTH]; char remapping_path[PATH_MAX_LENGTH]; } input; @@ -334,6 +335,7 @@ struct settings char content_database[PATH_MAX_LENGTH]; char cheat_database[PATH_MAX_LENGTH]; char cheat_settings_path[PATH_MAX_LENGTH]; + char menu_input_remapping_directory[PATH_MAX_LENGTH]; char input_remapping_directory[PATH_MAX_LENGTH]; char resampler_directory[PATH_MAX_LENGTH]; diff --git a/input/input_remapping.c b/input/input_remapping.c index 5bd3659765..2935728293 100644 --- a/input/input_remapping.c +++ b/input/input_remapping.c @@ -108,6 +108,45 @@ void input_remapping_save_file(const char *path) config_file_free(conf); } +/** + * input_menu_remapping_load_file: + * @path : Path to menu remapping file (absolute path). + * + * Loads a menu remap file from disk to memory. + * + * Returns: true (1) if successful, otherwise false (0). + **/ +bool input_menu_remapping_load_file(const char *path) +{ + unsigned j; + char buf[64]; + char key_ident[RARCH_FIRST_META_KEY][128]; + char key_strings[RARCH_FIRST_META_KEY][128] = { "b", "y", "select", "start", + "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", "l3", "r3"}; + config_file_t *conf = config_file_new(path); + + if (!conf) + return false; + + strlcpy(g_settings.input.menu_remapping_path, path, + sizeof(g_settings.input.menu_remapping_path)); + + snprintf(buf, sizeof(buf), "input_player%u", 1); + + for (j = 0; j < RARCH_FIRST_META_KEY; j++) + { + int key_remap = -1; + + snprintf(key_ident[j], sizeof(key_ident[j]), "%s_%s", buf, key_strings[j]); + if (config_get_int(conf, key_ident[j], &key_remap)) + g_settings.input.menu_remap_ids[0][j] = key_remap; + } + + config_file_free(conf); + + return true; +} + void input_remapping_set_defaults(void) { unsigned i, j; diff --git a/input/input_remapping.h b/input/input_remapping.h index a202cc0a03..49d7a62067 100644 --- a/input/input_remapping.h +++ b/input/input_remapping.h @@ -34,6 +34,16 @@ extern "C" { **/ bool input_remapping_load_file(const char *path); +/** + * input_menu_remapping_load_file: + * @path : Path to menu remapping file (absolute path). + * + * Loads a menu remap file from disk to memory. + * + * Returns: true (1) if successful, otherwise false (0). + **/ +bool input_menu_remapping_load_file(const char *path); + /** * input_remapping_save_file: * @path : Path to remapping file (relative path). diff --git a/menu/menu.h b/menu/menu.h index bbc6684fdc..86c026a83e 100644 --- a/menu/menu.h +++ b/menu/menu.h @@ -76,6 +76,7 @@ typedef enum MENU_FILE_IN_CARCHIVE, MENU_FILE_IMAGE, MENU_FILE_REMAP, + MENU_FILE_MENU_REMAP, MENU_FILE_DOWNLOAD_CORE, MENU_FILE_DOWNLOAD_CORE_INFO, MENU_FILE_RDB, diff --git a/menu/menu_entries_cbs.c b/menu/menu_entries_cbs.c index 4f7a99f6f8..d5d12d0f3c 100644 --- a/menu/menu_entries_cbs.c +++ b/menu/menu_entries_cbs.c @@ -20,6 +20,7 @@ #include "menu_input.h" #include "menu_entries.h" #include "menu_shader.h" +#include "menu_database.h" #include "../file_ext.h" #include "../file_extract.h" @@ -32,8 +33,6 @@ #include "../net_http.h" #endif -#include "menu_database.h" - #include "../input/input_remapping.h" #ifdef GEKKO @@ -302,6 +301,14 @@ static int action_ok_cheat_file(const char *path, label, type, idx); } +static int action_ok_menu_remap_file(const char *path, + const char *label, unsigned type, size_t idx) +{ + return action_ok_file_generic( + g_settings.menu_input_remapping_directory, + label, type, idx); +} + static int action_ok_remap_file(const char *path, const char *label, unsigned type, size_t idx) { @@ -339,6 +346,27 @@ static int action_ok_remap_file_load(const char *path, return 0; } +static int action_ok_menu_remap_file_load(const char *path, + const char *label, unsigned type, size_t idx) +{ + const char *menu_path = NULL; + char remap_path[PATH_MAX_LENGTH]; + if (!driver.menu) + return -1; + + (void)remap_path; + (void)menu_path; + menu_list_get_last_stack(driver.menu->menu_list, &menu_path, NULL, + NULL); + + fill_pathname_join(remap_path, menu_path, path, sizeof(remap_path)); + input_menu_remapping_load_file(remap_path); + + menu_list_flush_stack_by_needle(driver.menu->menu_list, "menu_input_remapping_options"); + + return 0; +} + static int action_ok_cheat_file_load(const char *path, const char *label, unsigned type, size_t idx) { @@ -460,6 +488,13 @@ static int action_ok_remap_file_save_as(const char *path, label, type, idx, menu_input_st_string_callback); } +static int action_ok_menu_remap_file_save_as(const char *path, + const char *label, unsigned type, size_t idx) +{ + return action_ok_save_as_generic("Menu Remapping Filename", + label, type, idx, menu_input_st_string_callback); +} + static int action_ok_path_use_directory(const char *path, const char *label, unsigned type, size_t idx) { @@ -2150,6 +2185,43 @@ static int deferred_push_core_input_remapping_options(void *data, void *userdata return 0; } +static int deferred_push_menu_input_remapping_options(void *data, void *userdata, + const char *path, const char *label, unsigned type) +{ + unsigned p = 0, retro_id; + file_list_t *list = (file_list_t*)data; + + (void)userdata; + (void)type; + + if (!list) + return -1; + + menu_list_clear(list); + menu_list_push(list, "Menu Remap File Load", "remap_menu_file_load", + MENU_SETTING_ACTION, 0); + menu_list_push(list, "Menu Remap File Save As", + "remap_menu_file_save_as", MENU_SETTING_ACTION, 0); + + for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND; retro_id++) + { + char desc_label[64]; + unsigned user = p + 1; + const char *description = g_extern.system.input_desc_btn[p][retro_id]; + + if (!description) + continue; + + snprintf(desc_label, sizeof(desc_label), "%s : ", description); + menu_list_push(list, desc_label, "", MENU_SETTINGS_INPUT_DESC_BEGIN + (p * RARCH_FIRST_CUSTOM_BIND) + retro_id, 0); + } + + if (driver.menu_ctx && driver.menu_ctx->populate_entries) + driver.menu_ctx->populate_entries(driver.menu, path, label, type); + + return 0; +} + static int deferred_push_core_options(void *data, void *userdata, const char *path, const char *label, unsigned type) { @@ -2642,6 +2714,9 @@ static int menu_entries_cbs_init_bind_ok_first(menu_file_list_cbs_t *cbs, case MENU_FILE_REMAP: cbs->action_ok = action_ok_remap_file_load; break; + case MENU_FILE_MENU_REMAP: + cbs->action_ok = action_ok_menu_remap_file_load; + break; case MENU_FILE_SHADER_PRESET: cbs->action_ok = action_ok_shader_preset_load; break; @@ -2813,6 +2888,8 @@ static void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs, cbs->action_ok = action_ok_cheat_file; else if (!strcmp(label, "remap_file_load")) cbs->action_ok = action_ok_remap_file; + else if (!strcmp(label, "remap_menu_file_load")) + cbs->action_ok = action_ok_menu_remap_file; else if (!strcmp(label, "video_shader_parameters") || !strcmp(label, "video_shader_preset_parameters") ) @@ -2823,6 +2900,7 @@ static void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs, !strcmp(label, "core_options") || !strcmp(label, "core_cheat_options") || !strcmp(label, "core_input_remapping_options") || + !strcmp(label, "menu_input_remapping_options") || !strcmp(label, "core_information") || !strcmp(label, "disk_options") || !strcmp(label, "settings") || @@ -2852,6 +2930,8 @@ static void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs, cbs->action_ok = action_ok_cheat_file_save_as; else if (!strcmp(label, "remap_file_save_as")) cbs->action_ok = action_ok_remap_file_save_as; + else if (!strcmp(label, "remap_menu_file_save_as")) + cbs->action_ok = action_ok_menu_remap_file_save_as; else if (!strcmp(label, "core_list")) cbs->action_ok = action_ok_core_list; else if (!strcmp(label, "disk_image_append")) @@ -3002,6 +3082,8 @@ static void menu_entries_cbs_init_bind_deferred_push(menu_file_list_cbs_t *cbs, cbs->action_deferred_push = deferred_push_core_cheat_options; else if (!strcmp(label, "core_input_remapping_options")) cbs->action_deferred_push = deferred_push_core_input_remapping_options; + else if (!strcmp(label, "menu_input_remapping_options")) + cbs->action_deferred_push = deferred_push_menu_input_remapping_options; else if (!strcmp(label, "disk_options")) cbs->action_deferred_push = deferred_push_disk_options; else if (!strcmp(label, "core_list")) diff --git a/settings_data.c b/settings_data.c index caca8bb3d5..68a1afdc2b 100644 --- a/settings_data.c +++ b/settings_data.c @@ -3408,6 +3408,12 @@ static bool setting_data_append_list_main_menu_options( group_info.name, subgroup_info.name); + CONFIG_ACTION( + "menu_input_remapping_options", + "Menu Input Remapping Options", + group_info.name, + subgroup_info.name); + if (g_extern.main_is_init) { if (g_extern.has_set_input_descriptors)