From 82f6c57966c7e18a818f5f4a83db010f2d5230c4 Mon Sep 17 00:00:00 2001 From: twinaphex Date: Tue, 16 Dec 2014 06:21:18 +0100 Subject: [PATCH] Add new option 'Show Autoconfig Descriptor Labels' for more comprehensible button labels per joypad - needs to be added per autoconfig file --- driver.h | 3 +++ general.h | 1 + input/input_autodetect.c | 2 ++ input/input_common.c | 34 ++++++++++++++++++++++++++++------ settings.c | 4 ++++ settings_data.c | 14 +++++++++++++- 6 files changed, 51 insertions(+), 7 deletions(-) diff --git a/driver.h b/driver.h index 1a165920ae..6789850f51 100644 --- a/driver.h +++ b/driver.h @@ -152,6 +152,9 @@ struct retro_keybind /* Used by input_{push,pop}_analog_dpad(). */ uint32_t orig_joyaxis; + + char joykey_label[256]; + char joyaxis_label[256]; }; struct platform_bind diff --git a/general.h b/general.h index e54f3731e7..f314df6655 100644 --- a/general.h +++ b/general.h @@ -378,6 +378,7 @@ struct settings float overlay_scale; char autoconfig_dir[PATH_MAX]; + bool autoconfig_descriptor_label_show; bool input_descriptor_label_show; bool input_descriptor_hide_unbound; } input; diff --git a/input/input_autodetect.c b/input/input_autodetect.c index d605e26dfc..3c268105c8 100644 --- a/input/input_autodetect.c +++ b/input/input_autodetect.c @@ -112,6 +112,8 @@ void input_config_autoconfigure_joypad(unsigned idx, { g_settings.input.autoconf_binds[idx][i].joykey = NO_BTN; g_settings.input.autoconf_binds[idx][i].joyaxis = AXIS_NONE; + g_settings.input.autoconf_binds[idx][i].joykey_label[0] = '\0'; + g_settings.input.autoconf_binds[idx][i].joyaxis_label[0] = '\0'; } g_settings.input.autoconfigured[idx] = false; diff --git a/input/input_common.c b/input/input_common.c index 762568b4ab..6fdd378883 100644 --- a/input/input_common.c +++ b/input/input_common.c @@ -358,8 +358,10 @@ void input_config_parse_joy_button(config_file_t *conf, const char *prefix, const char *btn, struct retro_keybind *bind) { char tmp[64]; - char key[64]; + char *tmp_a = NULL; + char key[64], key_label[64]; snprintf(key, sizeof(key), "%s_%s_btn", prefix, btn); + snprintf(key_label, sizeof(key_label), "%s_%s_btn_label", prefix, btn); if (config_get_array(conf, key, tmp, sizeof(tmp))) { @@ -374,14 +376,19 @@ void input_config_parse_joy_button(config_file_t *conf, const char *prefix, bind->joykey = strtoull(tmp, NULL, 0); } } + + if (config_get_string(conf, key_label, &tmp_a)) + strlcpy(bind->joykey_label, tmp_a, sizeof(bind->joykey_label)); } void input_config_parse_joy_axis(config_file_t *conf, const char *prefix, const char *axis, struct retro_keybind *bind) { char tmp[64]; - char key[64]; + char *tmp_a = NULL; + char key[64], key_label[64]; snprintf(key, sizeof(key), "%s_%s_axis", prefix, axis); + snprintf(key_label, sizeof(key_label), "%s_%s_axis_label", prefix, axis); if (config_get_array(conf, key, tmp, sizeof(tmp))) { @@ -399,6 +406,9 @@ void input_config_parse_joy_axis(config_file_t *conf, const char *prefix, /* Ensure that d-pad emulation doesn't screw this over. */ bind->orig_joyaxis = bind->joyaxis; } + + if (config_get_string(conf, key_label, &tmp_a)) + strlcpy(bind->joyaxis_label, tmp_a, sizeof(bind->joyaxis_label)); } #if !defined(IS_JOYCONFIG) @@ -426,11 +436,20 @@ static void input_get_bind_string_joykey(char *buf, const char *prefix, dir = "?"; break; } - snprintf(buf, size, "%sHat #%u %s ", prefix, - (unsigned)GET_HAT(bind->joykey), dir); + + if (bind->joykey_label[0] != '\0' && g_settings.input.autoconfig_descriptor_label_show) + snprintf(buf, size, "%s %s ", prefix, bind->joykey_label); + else + snprintf(buf, size, "%sHat #%u %s ", prefix, + (unsigned)GET_HAT(bind->joykey), dir); } else - snprintf(buf, size, "%s%u (btn) ", prefix, (unsigned)bind->joykey); + { + if (bind->joykey_label[0] != '\0' && g_settings.input.autoconfig_descriptor_label_show) + snprintf(buf, size, "%s%s (btn) ", prefix, bind->joykey_label); + else + snprintf(buf, size, "%s%u (btn) ", prefix, (unsigned)bind->joykey); + } } static void input_get_bind_string_joyaxis(char *buf, const char *prefix, @@ -448,7 +467,10 @@ static void input_get_bind_string_joyaxis(char *buf, const char *prefix, dir = '+'; axis = AXIS_POS_GET(bind->joyaxis); } - snprintf(buf, size, "%s%c%u (axis) ", prefix, dir, axis); + if (bind->joyaxis_label[0] != '\0' && g_settings.input.autoconfig_descriptor_label_show) + snprintf(buf, size, "%s%s (axis) ", prefix, bind->joyaxis_label); + else + snprintf(buf, size, "%s%c%u (axis) ", prefix, dir, axis); } void input_get_bind_string(char *buf, const struct retro_keybind *bind, diff --git a/settings.c b/settings.c index 2ee3b191a4..7e369a5e39 100644 --- a/settings.c +++ b/settings.c @@ -1004,6 +1004,8 @@ static bool config_load_file(const char *path, bool set_defaults) "input_descriptor_label_show"); CONFIG_GET_BOOL(input.input_descriptor_hide_unbound, "input_descriptor_hide_unbound"); + CONFIG_GET_BOOL(input.autoconfig_descriptor_label_show, + "autoconfig_descriptor_label_show"); for (i = 0; i < MAX_PLAYERS; i++) { @@ -1568,6 +1570,8 @@ bool config_save_file(const char *path) g_settings.input.netplay_client_swap_input); config_set_bool(conf, "input_descriptor_label_show", g_settings.input.input_descriptor_label_show); + config_set_bool(conf, "autoconfig_descriptor_label_show", + g_settings.input.autoconfig_descriptor_label_show); config_set_bool(conf, "input_descriptor_hide_unbound", g_settings.input.input_descriptor_hide_unbound); config_set_bool(conf, "load_dummy_on_core_shutdown", diff --git a/settings_data.c b/settings_data.c index c085d3dc5f..6c6fd06bc3 100644 --- a/settings_data.c +++ b/settings_data.c @@ -4321,7 +4321,7 @@ static bool setting_data_append_list_input_options( CONFIG_BOOL( g_settings.input.autodetect_enable, "input_autodetect_enable", - "Autodetect Enable", + "Autoconfig Enable", input_autodetect_enable, "OFF", "ON", @@ -4330,6 +4330,18 @@ static bool setting_data_append_list_input_options( general_write_handler, general_read_handler); + CONFIG_BOOL( + g_settings.input.autoconfig_descriptor_label_show, + "autoconfig_descriptor_label_show", + "Show Autoconfig Descriptor Labels", + true, + "OFF", + "ON", + group_info.name, + subgroup_info.name, + general_write_handler, + general_read_handler); + CONFIG_BOOL( g_settings.input.input_descriptor_label_show, "input_descriptor_label_show",