We'll just use the legacy names for face buttons in the mappings

This fixes being able to accidentally rebind the face buttons in testcontroller
main
Sam Lantinga 2023-11-15 22:09:09 -08:00
parent 051ed397d1
commit 57e5c7f6ee
2 changed files with 19 additions and 62 deletions

View File

@ -1066,10 +1066,10 @@ const char *SDL_GetGamepadStringForAxis(SDL_GamepadAxis axis)
}
static const char *map_StringForGamepadButton[] = {
"s",
"e",
"w",
"n",
"a",
"b",
"x",
"y",
"back",
"guide",
"start",
@ -1103,43 +1103,24 @@ SDL_GamepadButton SDL_PrivateGetGamepadButtonFromString(const char *str, SDL_boo
for (i = 0; i < SDL_arraysize(map_StringForGamepadButton); ++i) {
if (SDL_strcasecmp(str, map_StringForGamepadButton[i]) == 0) {
if (baxy) {
/* Need to swap face buttons */
switch (i) {
case SDL_GAMEPAD_BUTTON_SOUTH:
return SDL_GAMEPAD_BUTTON_EAST;
case SDL_GAMEPAD_BUTTON_EAST:
return SDL_GAMEPAD_BUTTON_SOUTH;
case SDL_GAMEPAD_BUTTON_WEST:
return SDL_GAMEPAD_BUTTON_NORTH;
case SDL_GAMEPAD_BUTTON_NORTH:
return SDL_GAMEPAD_BUTTON_WEST;
default:
break;
}
}
return (SDL_GamepadButton)i;
}
}
if (SDL_strcasecmp(str, "a") == 0) {
if (baxy) {
return SDL_GAMEPAD_BUTTON_EAST;
} else {
return SDL_GAMEPAD_BUTTON_SOUTH;
}
} else if (SDL_strcasecmp(str, "b") == 0) {
if (baxy) {
return SDL_GAMEPAD_BUTTON_SOUTH;
} else {
return SDL_GAMEPAD_BUTTON_EAST;
}
} else if (SDL_strcasecmp(str, "x") == 0) {
if (baxy) {
return SDL_GAMEPAD_BUTTON_NORTH;
} else {
return SDL_GAMEPAD_BUTTON_WEST;
}
} else if (SDL_strcasecmp(str, "y") == 0) {
if (baxy) {
return SDL_GAMEPAD_BUTTON_WEST;
} else {
return SDL_GAMEPAD_BUTTON_NORTH;
}
} else if (SDL_strcasecmp(str, "cross") == 0) {
return SDL_GAMEPAD_BUTTON_SOUTH;
} else if (SDL_strcasecmp(str, "circle") == 0) {
return SDL_GAMEPAD_BUTTON_EAST;
} else if (SDL_strcasecmp(str, "square") == 0) {
return SDL_GAMEPAD_BUTTON_WEST;
} else if (SDL_strcasecmp(str, "triangle") == 0) {
return SDL_GAMEPAD_BUTTON_NORTH;
}
return SDL_GAMEPAD_BUTTON_INVALID;
}
SDL_GamepadButton SDL_GetGamepadButtonFromString(const char *str)

View File

@ -2292,33 +2292,9 @@ static void ConvertBAXYMapping(MappingParts *parts)
}
}
static void UseLegacyButtonNames(MappingParts *parts)
{
int i;
for (i = 0; i < parts->num_elements; ++i) {
char *key = parts->keys[i];
if (SDL_strcmp(key, "s") == 0) {
parts->keys[i] = SDL_strdup("a");
SDL_free(key);
} else if (SDL_strcmp(key, "e") == 0) {
parts->keys[i] = SDL_strdup("b");
SDL_free(key);
} else if (SDL_strcmp(key, "w") == 0) {
parts->keys[i] = SDL_strdup("x");
SDL_free(key);
} else if (SDL_strcmp(key, "n") == 0) {
parts->keys[i] = SDL_strdup("y");
SDL_free(key);
}
}
}
static void UpdateLegacyElements(MappingParts *parts)
{
ConvertBAXYMapping(parts);
UseLegacyButtonNames(parts);
}
static SDL_bool CombineMappingAxes(MappingParts *parts)