mirror of
https://github.com/hrydgard/ppsspp.git
synced 2024-10-06 18:33:34 +00:00
iOS gamepad mapping: Better mapping, better defaults. Fixes the start button problem.
controller.controllerPausedHandler should not be set.
This commit is contained in:
parent
044451d557
commit
d46a7ed228
@ -741,6 +741,8 @@ void RestoreDefault() {
|
||||
} else {
|
||||
SetDefaultKeyMap(DEFAULT_MAPPING_ANDROID_PAD, false);
|
||||
}
|
||||
#elif PPSSPP_PLATFORM(IOS)
|
||||
SetDefaultKeyMap(DEFAULT_MAPPING_IOS_PAD, false);
|
||||
#else
|
||||
SetDefaultKeyMap(DEFAULT_MAPPING_KEYBOARD, true);
|
||||
SetDefaultKeyMap(DEFAULT_MAPPING_PAD, false);
|
||||
|
@ -275,6 +275,27 @@ static const DefMappingStruct defaultPadMap[] = {
|
||||
{VIRTKEY_PAUSE , NKCODE_BUTTON_L2 },
|
||||
};
|
||||
|
||||
static const DefMappingStruct defaultPadMapIOS[] = {
|
||||
{CTRL_CROSS , NKCODE_BUTTON_2},
|
||||
{CTRL_CIRCLE , NKCODE_BUTTON_3},
|
||||
{CTRL_SQUARE , NKCODE_BUTTON_4},
|
||||
{CTRL_TRIANGLE , NKCODE_BUTTON_1},
|
||||
{CTRL_UP , NKCODE_DPAD_UP},
|
||||
{CTRL_RIGHT , NKCODE_DPAD_RIGHT},
|
||||
{CTRL_DOWN , NKCODE_DPAD_DOWN},
|
||||
{CTRL_LEFT , NKCODE_DPAD_LEFT},
|
||||
{CTRL_START , NKCODE_BUTTON_START},
|
||||
{CTRL_SELECT , NKCODE_BUTTON_SELECT},
|
||||
{CTRL_LTRIGGER , NKCODE_BUTTON_L1},
|
||||
{CTRL_RTRIGGER , NKCODE_BUTTON_R1},
|
||||
{VIRTKEY_AXIS_X_MIN, JOYSTICK_AXIS_X, -1},
|
||||
{VIRTKEY_AXIS_X_MAX, JOYSTICK_AXIS_X, +1},
|
||||
{VIRTKEY_AXIS_Y_MIN, JOYSTICK_AXIS_Y, +1},
|
||||
{VIRTKEY_AXIS_Y_MAX, JOYSTICK_AXIS_Y, -1},
|
||||
{VIRTKEY_PAUSE , NKCODE_BUTTON_THUMBL },
|
||||
{VIRTKEY_FASTFORWARD , JOYSTICK_AXIS_RTRIGGER, +1},
|
||||
};
|
||||
|
||||
static const DefMappingStruct defaultOuyaMap[] = {
|
||||
{CTRL_CROSS , NKCODE_BUTTON_A},
|
||||
{CTRL_CIRCLE , NKCODE_BUTTON_B},
|
||||
@ -382,6 +403,9 @@ void SetDefaultKeyMap(DefaultMaps dmap, bool replace) {
|
||||
case DEFAULT_MAPPING_ANDROID_PAD:
|
||||
SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultPadMapAndroid, ARRAY_SIZE(defaultPadMapAndroid), replace);
|
||||
break;
|
||||
case DEFAULT_MAPPING_IOS_PAD:
|
||||
SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultPadMapIOS, ARRAY_SIZE(defaultPadMapIOS), replace);
|
||||
break;
|
||||
case DEFAULT_MAPPING_OUYA:
|
||||
SetDefaultKeyMap(DEVICE_ID_PAD_0, defaultOuyaMap, ARRAY_SIZE(defaultOuyaMap), replace);
|
||||
break;
|
||||
|
@ -6,6 +6,7 @@ enum DefaultMaps {
|
||||
DEFAULT_MAPPING_KEYBOARD,
|
||||
DEFAULT_MAPPING_PAD,
|
||||
DEFAULT_MAPPING_ANDROID_PAD,
|
||||
DEFAULT_MAPPING_IOS_PAD,
|
||||
DEFAULT_MAPPING_XINPUT,
|
||||
DEFAULT_MAPPING_ANDROID_XBOX, // XBox controller or similar on Android
|
||||
DEFAULT_MAPPING_SHIELD,
|
||||
|
@ -15,20 +15,20 @@ static void controllerButtonPressed(BOOL pressed, InputKeyCode keyCode) {
|
||||
NativeKey(key);
|
||||
}
|
||||
|
||||
static void analogTriggerPressed(InputAxis axis, float value) {
|
||||
AxisInput axisInput;
|
||||
axisInput.deviceId = DEVICE_ID_PAD_0;
|
||||
axisInput.axisId = axis;
|
||||
axisInput.value = value;
|
||||
NativeAxis(&axisInput, 1);
|
||||
}
|
||||
|
||||
bool SetupController(GCController *controller) {
|
||||
GCExtendedGamepad *extendedProfile = controller.extendedGamepad;
|
||||
if (extendedProfile == nil) {
|
||||
return false;
|
||||
}
|
||||
|
||||
controller.controllerPausedHandler = ^(GCController *controller) {
|
||||
KeyInput key;
|
||||
key.flags = KEY_DOWN;
|
||||
key.keyCode = NKCODE_ESCAPE;
|
||||
key.deviceId = DEVICE_ID_KEYBOARD;
|
||||
NativeKey(key);
|
||||
};
|
||||
|
||||
extendedProfile.buttonA.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_2); // Cross
|
||||
};
|
||||
@ -46,11 +46,11 @@ bool SetupController(GCController *controller) {
|
||||
};
|
||||
|
||||
extendedProfile.leftShoulder.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_7); // LTrigger
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_L1); // LTrigger
|
||||
};
|
||||
|
||||
extendedProfile.rightShoulder.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_8); // RTrigger
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_R1); // RTrigger
|
||||
};
|
||||
|
||||
extendedProfile.dpad.up.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
@ -70,34 +70,36 @@ bool SetupController(GCController *controller) {
|
||||
};
|
||||
|
||||
extendedProfile.leftTrigger.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_9); // Select
|
||||
INFO_LOG(SYSTEM, "ltrigger: %f %d", value, (int)pressed);
|
||||
analogTriggerPressed(JOYSTICK_AXIS_LTRIGGER, value);
|
||||
};
|
||||
|
||||
extendedProfile.rightTrigger.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_10); // Start
|
||||
INFO_LOG(SYSTEM, "rtrigger: %f %d", value, (int)pressed);
|
||||
analogTriggerPressed(JOYSTICK_AXIS_RTRIGGER, value);
|
||||
};
|
||||
|
||||
#if defined(__IPHONE_12_1) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_12_1
|
||||
if ([extendedProfile respondsToSelector:@selector(leftThumbstickButton)] && extendedProfile.leftThumbstickButton != nil) {
|
||||
extendedProfile.leftThumbstickButton.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_11);
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_THUMBL);
|
||||
};
|
||||
}
|
||||
if ([extendedProfile respondsToSelector:@selector(rightThumbstickButton)] && extendedProfile.rightThumbstickButton != nil) {
|
||||
extendedProfile.rightThumbstickButton.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_12);
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_THUMBR);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
#if defined(__IPHONE_13_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_13_0
|
||||
if ([extendedProfile respondsToSelector:@selector(buttonOptions)] && extendedProfile.buttonOptions != nil) {
|
||||
extendedProfile.buttonOptions.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_13);
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_SELECT);
|
||||
};
|
||||
}
|
||||
if ([extendedProfile respondsToSelector:@selector(buttonMenu)] && extendedProfile.buttonMenu != nil) {
|
||||
extendedProfile.buttonMenu.valueChangedHandler = ^(GCControllerButtonInput *button, float value, BOOL pressed) {
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_14);
|
||||
controllerButtonPressed(pressed, NKCODE_BUTTON_START);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@ -143,7 +145,7 @@ bool SetupController(GCController *controller) {
|
||||
NativeAxis(&axisInput, 1);
|
||||
};
|
||||
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void TouchTracker::SendTouchEvent(float x, float y, int code, int pointerId) {
|
||||
@ -203,7 +205,7 @@ void TouchTracker::Began(NSSet *touches, UIView *view) {
|
||||
}
|
||||
|
||||
void TouchTracker::Moved(NSSet *touches, UIView *view) {
|
||||
for (UITouch* touch in touches) {
|
||||
for (UITouch* touch in touches) {
|
||||
CGPoint point = [touch locationInView:view];
|
||||
int touchId = ToTouchID(touch, true);
|
||||
SendTouchEvent(point.x, point.y, 0, touchId);
|
||||
@ -211,40 +213,40 @@ void TouchTracker::Moved(NSSet *touches, UIView *view) {
|
||||
}
|
||||
|
||||
void TouchTracker::Ended(NSSet *touches, UIView *view) {
|
||||
for (UITouch* touch in touches) {
|
||||
for (UITouch* touch in touches) {
|
||||
CGPoint point = [touch locationInView:view];
|
||||
int touchId = ToTouchID(touch, false);
|
||||
if (touchId >= 0) {
|
||||
SendTouchEvent(point.x, point.y, 2, touchId);
|
||||
SendTouchEvent(point.x, point.y, 2, touchId);
|
||||
touches_[touchId] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void TouchTracker::Cancelled(NSSet *touches, UIView *view) {
|
||||
for (UITouch* touch in touches) {
|
||||
for (UITouch* touch in touches) {
|
||||
CGPoint point = [touch locationInView:view];
|
||||
int touchId = ToTouchID(touch, false);
|
||||
if (touchId >= 0) {
|
||||
SendTouchEvent(point.x, point.y, 2, touchId);
|
||||
SendTouchEvent(point.x, point.y, 2, touchId);
|
||||
touches_[touchId] = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ICadeTracker::InitKeyMap() {
|
||||
iCadeToKeyMap[iCadeJoystickUp] = NKCODE_DPAD_UP;
|
||||
iCadeToKeyMap[iCadeJoystickRight] = NKCODE_DPAD_RIGHT;
|
||||
iCadeToKeyMap[iCadeJoystickDown] = NKCODE_DPAD_DOWN;
|
||||
iCadeToKeyMap[iCadeJoystickLeft] = NKCODE_DPAD_LEFT;
|
||||
iCadeToKeyMap[iCadeButtonA] = NKCODE_BUTTON_9; // Select
|
||||
iCadeToKeyMap[iCadeButtonB] = NKCODE_BUTTON_7; // LTrigger
|
||||
iCadeToKeyMap[iCadeButtonC] = NKCODE_BUTTON_10; // Start
|
||||
iCadeToKeyMap[iCadeButtonD] = NKCODE_BUTTON_8; // RTrigger
|
||||
iCadeToKeyMap[iCadeButtonE] = NKCODE_BUTTON_4; // Square
|
||||
iCadeToKeyMap[iCadeButtonF] = NKCODE_BUTTON_2; // Cross
|
||||
iCadeToKeyMap[iCadeButtonG] = NKCODE_BUTTON_1; // Triangle
|
||||
iCadeToKeyMap[iCadeButtonH] = NKCODE_BUTTON_3; // Circle
|
||||
iCadeToKeyMap[iCadeJoystickUp] = NKCODE_DPAD_UP;
|
||||
iCadeToKeyMap[iCadeJoystickRight] = NKCODE_DPAD_RIGHT;
|
||||
iCadeToKeyMap[iCadeJoystickDown] = NKCODE_DPAD_DOWN;
|
||||
iCadeToKeyMap[iCadeJoystickLeft] = NKCODE_DPAD_LEFT;
|
||||
iCadeToKeyMap[iCadeButtonA] = NKCODE_BUTTON_9; // Select
|
||||
iCadeToKeyMap[iCadeButtonB] = NKCODE_BUTTON_7; // LTrigger
|
||||
iCadeToKeyMap[iCadeButtonC] = NKCODE_BUTTON_10; // Start
|
||||
iCadeToKeyMap[iCadeButtonD] = NKCODE_BUTTON_8; // RTrigger
|
||||
iCadeToKeyMap[iCadeButtonE] = NKCODE_BUTTON_4; // Square
|
||||
iCadeToKeyMap[iCadeButtonF] = NKCODE_BUTTON_2; // Cross
|
||||
iCadeToKeyMap[iCadeButtonG] = NKCODE_BUTTON_1; // Triangle
|
||||
iCadeToKeyMap[iCadeButtonH] = NKCODE_BUTTON_3; // Circle
|
||||
}
|
||||
|
||||
void ICadeTracker::ButtonDown(iCadeState button) {
|
||||
@ -290,7 +292,7 @@ void ICadeTracker::ButtonDown(iCadeState button) {
|
||||
}
|
||||
|
||||
void ICadeTracker::ButtonUp(iCadeState button) {
|
||||
if (!iCadeConnectNotified) {
|
||||
if (!iCadeConnectNotified) {
|
||||
iCadeConnectNotified = true;
|
||||
KeyMap::NotifyPadConnected(DEVICE_ID_PAD_0, "iCade");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user