From f662d9f65fc593b4d526e7d3f7212452214276b5 Mon Sep 17 00:00:00 2001 From: radius Date: Sat, 7 Apr 2018 23:43:41 -0500 Subject: [PATCH] remap-redux part2: start adding analog remapping --- input/input_remapping.c | 93 ++++++++++++++++++++--------------- menu/cbs/menu_cbs_get_value.c | 20 ++++++-- menu/cbs/menu_cbs_left.c | 4 +- menu/cbs/menu_cbs_right.c | 4 +- menu/menu_displaylist.c | 2 +- 5 files changed, 72 insertions(+), 51 deletions(-) diff --git a/input/input_remapping.c b/input/input_remapping.c index 370e31a6a9..15a34c1d7d 100644 --- a/input/input_remapping.c +++ b/input/input_remapping.c @@ -53,64 +53,70 @@ bool input_remapping_load_file(void *data, const char *path) for (i = 0; i < MAX_USERS; i++) { - char s1[64], s2[64]; + char s1[64], s2[64], s3[64]; + char btn_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; char key_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; - char keymapper_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; - char key_strings[RARCH_FIRST_CUSTOM_BIND + 4][128] = - { "b", "y", "select", "start", + char stk_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; + + char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = { + "b", "y", "select", "start", "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", - "l3", "r3", "l_x", "l_y", "r_x", "r_y" }; + "l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" }; old_analog_dpad_mode[i] = settings->uints.input_analog_dpad_mode[i]; old_libretro_device[i] = settings->uints.input_libretro_device[i]; s1[0] = '\0'; s2[0] = '\0'; + s3[0] = '\0'; snprintf(s1, sizeof(s1), "input_player%u_btn", i + 1); snprintf(s2, sizeof(s2), "input_player%u_key", i + 1); + snprintf(s3, sizeof(s3), "input_player%u_stk", i + 1); - for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 4; j++) + for (j = 0; j < RARCH_FIRST_CUSTOM_BIND; j++) { int btn_remap = -1; - fill_pathname_join_delim(key_ident[j], s1, - key_strings[j], '_', sizeof(key_ident[j])); - fill_pathname_join_delim(keymapper_ident[j], s2, - key_strings[j], '_', sizeof(key_ident[j])); + fill_pathname_join_delim(btn_ident[j], s1, + key_strings[j], '_', sizeof(btn_ident[j])); + fill_pathname_join_delim(key_ident[j], s2, + key_strings[j], '_', sizeof(btn_ident[j])); - if (config_get_int(conf, key_ident[j], &btn_remap) + if (config_get_int(conf, btn_ident[j], &btn_remap) && (btn_remap < RARCH_FIRST_CUSTOM_BIND && btn_remap != -1)) settings->uints.input_remap_ids[i][j] = btn_remap; - else if (config_get_int(conf, key_ident[j], &btn_remap) + else if (config_get_int(conf, btn_ident[j], &btn_remap) && (btn_remap == -1)) settings->uints.input_remap_ids[i][j] = RARCH_UNMAPPED; int key_remap = -1; - if (config_get_int(conf, keymapper_ident[j], &key_remap)) + if (config_get_int(conf, key_ident[j], &key_remap)) settings->uints.input_keymapper_ids[i][j] = key_remap; else settings->uints.input_keymapper_ids[i][j] = RETROK_UNKNOWN; - - } - for (j = 0; j < 4; j++) + for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_FIRST_CUSTOM_BIND + 8; j++) { - int btn_remap = -1; + int stk_remap = -1; - snprintf(key_ident[RARCH_FIRST_CUSTOM_BIND + j], - sizeof(key_ident[RARCH_FIRST_CUSTOM_BIND + j]), + fill_pathname_join_delim(stk_ident[j], s3, + key_strings[j], '$', sizeof(stk_ident[j])); + + snprintf(stk_ident[j], + sizeof(stk_ident[j]), "%s_%s", - s1, - key_strings[RARCH_FIRST_CUSTOM_BIND + j]); + s3, + key_strings[j]); - if (config_get_int(conf, key_ident[RARCH_FIRST_CUSTOM_BIND + j], - &btn_remap) && (btn_remap < 4)) - settings->uints.input_remap_ids[i][RARCH_FIRST_CUSTOM_BIND + j] = - btn_remap; + if (config_get_int(conf, stk_ident[j], + &stk_remap)) + settings->uints.input_remap_ids[i][j] = + stk_remap; + RARCH_LOG("stk_ident: %s:%d\n", stk_ident[j], settings->uints.input_remap_ids[i][j]); } snprintf(s1, sizeof(s1), "input_player%u_analog_dpad_mode", i + 1); @@ -167,50 +173,55 @@ bool input_remapping_save_file(const char *path) for (i = 0; i < max_users; i++) { - char s1[64], s2[64]; + char s1[64], s2[64], s3[64]; + char btn_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; char key_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; - char keymapper_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; - char key_strings[RARCH_FIRST_CUSTOM_BIND + 4][128] = { + char stk_ident[RARCH_FIRST_CUSTOM_BIND + 4][128] = {{0}}; + + char key_strings[RARCH_FIRST_CUSTOM_BIND + 8][128] = { "b", "y", "select", "start", "up", "down", "left", "right", "a", "x", "l", "r", "l2", "r2", - "l3", "r3", "l_x", "l_y", "r_x", "r_y" }; + "l3", "r3", "l_x+", "l_x-", "l_y+", "l_y-", "r_x+", "r_x-", "r_y+", "r_y-" }; s1[0] = '\0'; s2[0] = '\0'; snprintf(s1, sizeof(s1), "input_player%u_btn", i + 1); snprintf(s2, sizeof(s2), "input_player%u_key", i + 1); + snprintf(s3, sizeof(s1), "input_player%u_stk", i + 1); for (j = 0; j < RARCH_FIRST_CUSTOM_BIND + 4; j++) { - fill_pathname_join_delim(key_ident[j], s1, - key_strings[j], '_', sizeof(key_ident[j])); - fill_pathname_join_delim(keymapper_ident[j], s2, - key_strings[j], '_', sizeof(key_ident[j])); + fill_pathname_join_delim(btn_ident[j], s1, + key_strings[j], '_', sizeof(btn_ident[j])); + fill_pathname_join_delim(key_ident[j], s2, + key_strings[j], '_', sizeof(btn_ident[j])); /* only save values that have been modified */ if(j < RARCH_FIRST_CUSTOM_BIND) { if(settings->uints.input_remap_ids[i][j] != j && settings->uints.input_remap_ids[i][j] != RARCH_UNMAPPED) - config_set_int(conf, key_ident[j], settings->uints.input_remap_ids[i][j]); + config_set_int(conf, btn_ident[j], settings->uints.input_remap_ids[i][j]); else if (settings->uints.input_remap_ids[i][j] != j && settings->uints.input_remap_ids[i][j] == RARCH_UNMAPPED) - config_set_int(conf, key_ident[j], -1); + config_set_int(conf, btn_ident[j], -1); else - config_unset(conf,key_ident[j]); + config_unset(conf,btn_ident[j]); if (settings->uints.input_keymapper_ids[i][j] != RETROK_UNKNOWN) - config_set_int(conf, keymapper_ident[j], + config_set_int(conf, key_ident[j], settings->uints.input_keymapper_ids[i][j]); } else { + fill_pathname_join_delim(stk_ident[j], s3, + key_strings[j], '_', sizeof(stk_ident[j])); if(settings->uints.input_remap_ids[i][j] != j - RARCH_FIRST_CUSTOM_BIND) - config_set_int(conf, key_ident[j], + config_set_int(conf, stk_ident[j], settings->uints.input_remap_ids[i][j]); else - config_unset(conf,key_ident[j]); + config_unset(conf,btn_ident[j]); } } snprintf(s1, sizeof(s1), "input_libretro_device_p%u", i + 1); @@ -274,8 +285,8 @@ void input_remapping_set_defaults(bool deinit) settings->uints.input_remap_ids[i][j] = keybind->id; settings->uints.input_keymapper_ids[i][j] = RETROK_UNKNOWN; } - for (j = 0; j < 4; j++) - settings->uints.input_remap_ids[i][RARCH_FIRST_CUSTOM_BIND + j] = j; + for (j = RARCH_FIRST_CUSTOM_BIND; j < RARCH_FIRST_CUSTOM_BIND + 8; j++) + settings->uints.input_remap_ids[i][j] = j; if (old_analog_dpad_mode[i]) settings->uints.input_analog_dpad_mode[i] = old_analog_dpad_mode[i]; diff --git a/menu/cbs/menu_cbs_get_value.c b/menu/cbs/menu_cbs_get_value.c index 54e39b2bcd..215162cf77 100644 --- a/menu/cbs/menu_cbs_get_value.c +++ b/menu/cbs/menu_cbs_get_value.c @@ -550,6 +550,7 @@ static void menu_action_setting_disp_set_label_input_desc( rarch_system_info_t *system = runloop_get_system_info(); settings_t *settings = config_get_ptr(); const char* descriptor = NULL; + char buf[256]; unsigned btn_idx, user_idx, remap_idx; @@ -561,18 +562,27 @@ static void menu_action_setting_disp_set_label_input_desc( remap_idx = settings->uints.input_remap_ids[user_idx][btn_idx]; - +/* if (remap_idx == RARCH_UNMAPPED) settings->uints.input_remap_ids[user_idx][btn_idx] = RARCH_UNMAPPED; - +*/ if (!system) return; - if (btn_idx < RARCH_FIRST_CUSTOM_BIND) - descriptor = system->input_desc_btn[user_idx][remap_idx]; + descriptor = system->input_desc_btn[user_idx][remap_idx]; - if (!string_is_empty(descriptor)) + if (!string_is_empty(descriptor) && remap_idx < RARCH_FIRST_CUSTOM_BIND) strlcpy(s, descriptor, len); + else if (!string_is_empty(descriptor) && remap_idx >= RARCH_FIRST_CUSTOM_BIND && remap_idx % 2 == 0) + { + snprintf(buf, sizeof(buf), "%s %c", descriptor, '+'); + strlcpy(s, buf, len); + } + else if (!string_is_empty(descriptor) && remap_idx >= RARCH_FIRST_CUSTOM_BIND && remap_idx % 2 != 0) + { + snprintf(buf, sizeof(buf), "%s %c", descriptor, '-'); + strlcpy(s, buf, len); + } else strlcpy(s, "---", len); diff --git a/menu/cbs/menu_cbs_left.c b/menu/cbs/menu_cbs_left.c index 37b0d51270..53115b011d 100644 --- a/menu/cbs/menu_cbs_left.c +++ b/menu/cbs/menu_cbs_left.c @@ -117,8 +117,8 @@ static int action_left_input_desc(unsigned type, const char *label, /* skip the not used buttons (unless they are at the end by calling the right desc function recursively also skip all the axes until analog remapping is implemented */ - if ((string_is_empty(system->input_desc_btn[user_idx][remap_idx]) && remap_idx < RARCH_CUSTOM_BIND_LIST_END) || - (remap_idx >= RARCH_FIRST_CUSTOM_BIND && remap_idx < RARCH_CUSTOM_BIND_LIST_END)) + if ((string_is_empty(system->input_desc_btn[user_idx][remap_idx]) && remap_idx < RARCH_CUSTOM_BIND_LIST_END) /*|| + (remap_idx >= RARCH_FIRST_CUSTOM_BIND && remap_idx < RARCH_CUSTOM_BIND_LIST_END)*/) action_left_input_desc(type, label, wraparound); return 0; diff --git a/menu/cbs/menu_cbs_right.c b/menu/cbs/menu_cbs_right.c index 8451f51029..0f2fa245a6 100644 --- a/menu/cbs/menu_cbs_right.c +++ b/menu/cbs/menu_cbs_right.c @@ -164,8 +164,8 @@ int action_right_input_desc(unsigned type, const char *label, /* skip the not used buttons (unless they are at the end by calling the right desc function recursively also skip all the axes until analog remapping is implemented */ - if ((string_is_empty(system->input_desc_btn[user_idx][remap_idx]) && remap_idx < RARCH_CUSTOM_BIND_LIST_END) || - (remap_idx >= RARCH_FIRST_CUSTOM_BIND && remap_idx < RARCH_CUSTOM_BIND_LIST_END)) + if ((string_is_empty(system->input_desc_btn[user_idx][remap_idx]) && remap_idx < RARCH_CUSTOM_BIND_LIST_END) /*|| + (remap_idx >= RARCH_FIRST_CUSTOM_BIND && remap_idx < RARCH_CUSTOM_BIND_LIST_END)*/) action_right_input_desc(type, label, wraparound); #if 0 diff --git a/menu/menu_displaylist.c b/menu/menu_displaylist.c index 44df5c5cf4..d8a276e72a 100644 --- a/menu/menu_displaylist.c +++ b/menu/menu_displaylist.c @@ -3250,7 +3250,7 @@ static int menu_displaylist_parse_options_remappings( if (device == RETRO_DEVICE_JOYPAD || device == RETRO_DEVICE_ANALOG) { /* change to RARCH_FIRST_CUSTOM_BIND + 8 once analog remapping is implemented */ - for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND; retro_id++) + for (retro_id = 0; retro_id < RARCH_FIRST_CUSTOM_BIND + 8; retro_id++) { char desc_label[64]; unsigned user = p + 1;