diff controller_info.c @ 1645:84ef1eb2c96a

Added code for actually saving new controller bindings to an appropriate key in the config file
author Michael Pavone <pavone@retrodev.com>
date Fri, 30 Nov 2018 00:35:05 -0800
parents 419a0a133b5c
children 3a8c4ee68568
line wrap: on
line diff
--- a/controller_info.c	Tue Nov 20 01:10:03 2018 -0800
+++ b/controller_info.c	Fri Nov 30 00:35:05 2018 -0800
@@ -41,6 +41,19 @@
 	"genesis",
 	"saturn"
 };
+static const char *subtype_human_names[] = {
+	"unknown",
+	"Xbos",
+	"Xbox 360",
+	"Xbox One",
+	"PS2",
+	"PS3",
+	"PS4",
+	"Wii-U",
+	"Switch",
+	"Genesis",
+	"Saturn"
+};
 static const char *variant_names[] = {
 	"normal",
 	"6b bumpers",
@@ -295,3 +308,27 @@
 	return ret;
 }
 
+char *make_human_readable_type_name(controller_info *info)
+{
+	const char *base = subtype_human_names[info->subtype];
+	char *prefix;
+	if (info->variant == VARIANT_NORMAL) {
+		prefix = "Normal ";
+	} else {
+		static const char *parts[] = {"6 button (", NULL, "/", NULL, ") "};
+		if (info->variant == VARIANT_6B_BUMPERS) {
+			parts[1] = get_button_label(info, SDL_CONTROLLER_BUTTON_LEFTSHOULDER);
+			parts[3] = get_button_label(info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
+		} else {
+			parts[1] = get_button_label(info, SDL_CONTROLLER_BUTTON_RIGHTSHOULDER);
+			parts[3] = get_axis_label(info, SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
+		}
+		prefix = alloc_concat_m(5, parts);
+	}
+	char *ret = alloc_concat(prefix, base);
+	if (info->variant != VARIANT_NORMAL) {
+		free(prefix);
+	}
+	return ret;
+}
+