Add Input Remapping Save As option

This commit is contained in:
twinaphex 2015-01-19 08:37:11 +01:00
parent 019d24102d
commit 6bbc7196a3
2 changed files with 65 additions and 6 deletions

View File

@ -460,6 +460,17 @@ static int action_ok_shader_preset_save_as(const char *path,
return 0;
}
static int action_ok_remap_file_save_as(const char *path,
const char *label, unsigned type, size_t idx)
{
if (!driver.menu)
return -1;
menu_input_key_start_line(driver.menu, "Remapping Filename",
label, type, idx, menu_input_st_string_callback);
return 0;
}
static int action_ok_path_use_directory(const char *path,
const char *label, unsigned type, size_t idx)
{
@ -2114,12 +2125,8 @@ static int deferred_push_core_input_remapping_options(void *data, void *userdata
menu_list_clear(list);
menu_list_push(list, "Remap File Load", "remap_file_load",
MENU_SETTING_ACTION, 0);
#if 0
menu_list_push(list, "Cheat Passes", "cheat_num_passes",
0, 0);
menu_list_push(list, "Apply Cheat Changes", "cheat_apply_changes",
MENU_SETTING_ACTION, 0);
#endif
menu_list_push(list, "Remap File Save As",
"remap_file_save_as", MENU_SETTING_ACTION, 0);
for (p = 0; p < g_settings.input.max_users; p++)
{
@ -2692,6 +2699,8 @@ static void menu_entries_cbs_init_bind_ok(menu_file_list_cbs_t *cbs,
cbs->action_ok = action_ok_cheat_apply_changes;
else if (!strcmp(label, "video_shader_preset_save_as"))
cbs->action_ok = action_ok_shader_preset_save_as;
else if (!strcmp(label, "remap_file_save_as"))
cbs->action_ok = action_ok_remap_file_save_as;
else if (!strcmp(label, "core_list"))
cbs->action_ok = action_ok_core_list;
else if (!strcmp(label, "core_manager_list"))

View File

@ -32,6 +32,53 @@
#include "../settings_data.h"
#include "../input/input_joypad.h"
#include <file/config_file.h>
#include <file/file_path.h>
static void menu_input_remapping_save_file(const char *path)
{
unsigned i, j;
char buf[PATH_MAX_LENGTH];
char remap_file[PATH_MAX_LENGTH];
config_file_t *conf = NULL;
fill_pathname_join(buf, g_settings.input_remapping_directory,
path, sizeof(buf));
fill_pathname_noext(remap_file, buf, ".rmp", sizeof(remap_file));
conf = config_file_new(remap_file);
if (!conf)
conf = config_file_new(NULL);
if (!conf)
return;
for (i = 0; i < g_settings.input.max_users; i++)
{
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"};
snprintf(buf, sizeof(buf), "input_player%u", i + 1);
for (j = 0; j < RARCH_FIRST_META_KEY; j++)
{
snprintf(key_ident[j], sizeof(key_ident[j]), "%s_%s", buf, key_strings[j]);
config_set_int(conf, key_ident[j], g_settings.input.remap_ids[i][j]);
}
}
if (!config_file_write(conf, remap_file))
{
RARCH_ERR("Could not write remapping file to disk.\n");
}
config_file_free(conf);
}
void menu_input_key_start_line(void *data, const char *label,
const char *label_setting, unsigned type, unsigned idx,
input_keyboard_line_complete_t cb)
@ -90,6 +137,7 @@ void menu_input_st_uint_callback(void *userdata, const char *str)
menu_input_key_end_line(menu);
}
void menu_input_st_string_callback(void *userdata, const char *str)
{
menu_handle_t *menu = (menu_handle_t*)userdata;
@ -105,6 +153,8 @@ void menu_input_st_string_callback(void *userdata, const char *str)
{
if (!strcmp(menu->keyboard.label_setting, "video_shader_preset_save_as"))
menu_shader_manager_save_preset(str, false);
else if (!strcmp(menu->keyboard.label_setting, "remap_file_save_as"))
menu_input_remapping_save_file(str);
}
}