Cleanup controller support code using the iOS 13 SDK directly

This commit is contained in:
Cameron Gutman
2019-09-11 18:44:37 -07:00
parent b9656da8a5
commit 597aaa1bab

View File

@@ -213,7 +213,10 @@
if (controller != NULL) {
// On iOS 13, we want to use the new buttonMenu property which lets users hold down Start.
// On prior versions, we must use the controllerPausedHandler.
if (![controller.extendedGamepad respondsToSelector:@selector(buttonMenu)]) {
if (@available(iOS 13.0, tvOS 13.0, *)) {
// Nothing - buttonMenu is already handled in valueChangedHandler
}
else {
controller.controllerPausedHandler = ^(GCController *controller) {
Controller* limeController = [self->_controllers objectForKey:[NSNumber numberWithInteger:controller.playerIndex]];
@@ -261,22 +264,13 @@
}
}
// Until the iOS 13 SDK is released, we must use performSelector: and respondsToSelector:
// to exercise the new buttonMenu and buttonOptions properties.
if (@available(iOS 13.0, tvOS 13.0, *)) {
if ([gamepad respondsToSelector:@selector(buttonMenu)]) {
GCControllerButtonInput* menuButton = [gamepad performSelector:@selector(buttonMenu)];
// Menu button is mandatory, so no need to check for nil
UPDATE_BUTTON_FLAG(limeController, PLAY_FLAG, menuButton.pressed);
}
if ([gamepad respondsToSelector:@selector(buttonOptions)]) {
GCControllerButtonInput* optionsButton = [gamepad performSelector:@selector(buttonOptions)];
// Options button is optional (only present on Xbox One S and PS4 gamepads)
if (optionsButton != nil) {
UPDATE_BUTTON_FLAG(limeController, BACK_FLAG, optionsButton.pressed);
}
// Menu button is mandatory, so no need to check for nil
UPDATE_BUTTON_FLAG(limeController, PLAY_FLAG, gamepad.buttonMenu.pressed);
// Options button is optional (only present on Xbox One S and PS4 gamepads)
if (gamepad.buttonOptions != nil) {
UPDATE_BUTTON_FLAG(limeController, BACK_FLAG, gamepad.buttonOptions.pressed);
}
}
@@ -339,23 +333,13 @@
if (@available(iOS 12.1, tvOS 12.1, *)) {
if (controller.extendedGamepad.leftThumbstickButton != nil &&
controller.extendedGamepad.rightThumbstickButton != nil) {
GCControllerButtonInput* optionsButton = nil;
level = OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons;
if (@available(iOS 13.0, tvOS 13.0, *)) {
// TODO: Update when iOS 13 SDK is officially released
if ([controller.extendedGamepad respondsToSelector:@selector(buttonOptions)]) {
optionsButton = [controller.extendedGamepad performSelector:@selector(buttonOptions)];
if (controller.extendedGamepad.buttonOptions != nil) {
// Has L3/R3 and Select, so we can show nothing :)
level = OnScreenControlsLevelOff;
}
}
if (optionsButton != nil) {
// Has L3/R3 and Select, so we can show nothing :)
level = OnScreenControlsLevelOff;
}
else {
// Has L3/R3 but no Select button
level = OnScreenControlsLevelAutoGCExtendedGamepadWithStickButtons;
}
}
}
break;