mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-10 08:09:26 +01:00
Android: Change how the overlay controller setting works, part 2
The previous commit wasn't enough for getting inputs to work for controllers 2-4.
This commit is contained in:
parent
1b55d7c594
commit
6b5f82c12f
@ -39,6 +39,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
|
|||||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@ -67,10 +68,11 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
private Rect mSurfacePosition = null;
|
private Rect mSurfacePosition = null;
|
||||||
|
|
||||||
private boolean mIsFirstRun = true;
|
private boolean mIsFirstRun = true;
|
||||||
private boolean mGameCubeRegistered = false;
|
private boolean[] mGcPadRegistered = new boolean[4];
|
||||||
private boolean mWiiRegistered = false;
|
private boolean[] mWiimoteRegistered = new boolean[4];
|
||||||
private boolean mIsInEditMode = false;
|
private boolean mIsInEditMode = false;
|
||||||
private int mControllerType = -1;
|
private int mControllerType = -1;
|
||||||
|
private int mControllerIndex = 0;
|
||||||
private InputOverlayDrawableButton mButtonBeingConfigured;
|
private InputOverlayDrawableButton mButtonBeingConfigured;
|
||||||
private InputOverlayDrawableDpad mDpadBeingConfigured;
|
private InputOverlayDrawableDpad mDpadBeingConfigured;
|
||||||
private InputOverlayDrawableJoystick mJoystickBeingConfigured;
|
private InputOverlayDrawableJoystick mJoystickBeingConfigured;
|
||||||
@ -184,7 +186,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
|
|
||||||
overlayPointer = new InputOverlayPointer(mSurfacePosition, doubleTapControl,
|
overlayPointer = new InputOverlayPointer(mSurfacePosition, doubleTapControl,
|
||||||
IntSetting.MAIN_IR_MODE.getIntGlobal(),
|
IntSetting.MAIN_IR_MODE.getIntGlobal(),
|
||||||
BooleanSetting.MAIN_IR_ALWAYS_RECENTER.getBooleanGlobal());
|
BooleanSetting.MAIN_IR_ALWAYS_RECENTER.getBooleanGlobal(), mControllerIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -237,11 +239,11 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
button.setPressedState(true);
|
button.setPressedState(true);
|
||||||
button.setTrackId(event.getPointerId(pointerIndex));
|
button.setTrackId(event.getPointerId(pointerIndex));
|
||||||
pressed = true;
|
pressed = true;
|
||||||
InputOverrider.setControlState(0, button.getControl(), 1.0);
|
InputOverrider.setControlState(mControllerIndex, button.getControl(), 1.0);
|
||||||
|
|
||||||
int analogControl = getAnalogControlForTrigger(button.getControl());
|
int analogControl = getAnalogControlForTrigger(button.getControl());
|
||||||
if (analogControl >= 0)
|
if (analogControl >= 0)
|
||||||
InputOverrider.setControlState(0, analogControl, 1.0);
|
InputOverrider.setControlState(mControllerIndex, analogControl, 1.0);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case MotionEvent.ACTION_UP:
|
case MotionEvent.ACTION_UP:
|
||||||
@ -250,11 +252,11 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
if (button.getTrackId() == event.getPointerId(pointerIndex))
|
if (button.getTrackId() == event.getPointerId(pointerIndex))
|
||||||
{
|
{
|
||||||
button.setPressedState(false);
|
button.setPressedState(false);
|
||||||
InputOverrider.setControlState(0, button.getControl(), 0.0);
|
InputOverrider.setControlState(mControllerIndex, button.getControl(), 0.0);
|
||||||
|
|
||||||
int analogControl = getAnalogControlForTrigger(button.getControl());
|
int analogControl = getAnalogControlForTrigger(button.getControl());
|
||||||
if (analogControl >= 0)
|
if (analogControl >= 0)
|
||||||
InputOverrider.setControlState(0, analogControl, 0.0);
|
InputOverrider.setControlState(mControllerIndex, analogControl, 0.0);
|
||||||
|
|
||||||
button.setTrackId(-1);
|
button.setTrackId(-1);
|
||||||
}
|
}
|
||||||
@ -296,7 +298,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
{
|
{
|
||||||
if (!dpadPressed[i])
|
if (!dpadPressed[i])
|
||||||
{
|
{
|
||||||
InputOverrider.setControlState(0, dpad.getControl(i), 0.0);
|
InputOverrider.setControlState(mControllerIndex, dpad.getControl(i), 0.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Press buttons
|
// Press buttons
|
||||||
@ -304,7 +306,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
{
|
{
|
||||||
if (dpadPressed[i])
|
if (dpadPressed[i])
|
||||||
{
|
{
|
||||||
InputOverrider.setControlState(0, dpad.getControl(i), 1.0);
|
InputOverrider.setControlState(mControllerIndex, dpad.getControl(i), 1.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
setDpadState(dpad, dpadPressed[0], dpadPressed[1], dpadPressed[2], dpadPressed[3]);
|
setDpadState(dpad, dpadPressed[0], dpadPressed[1], dpadPressed[2], dpadPressed[3]);
|
||||||
@ -318,7 +320,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
for (int i = 0; i < 4; i++)
|
for (int i = 0; i < 4; i++)
|
||||||
{
|
{
|
||||||
dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT);
|
dpad.setState(InputOverlayDrawableDpad.STATE_DEFAULT);
|
||||||
InputOverrider.setControlState(0, dpad.getControl(i), 0.0);
|
InputOverrider.setControlState(mControllerIndex, dpad.getControl(i), 0.0);
|
||||||
}
|
}
|
||||||
dpad.setTrackId(-1);
|
dpad.setTrackId(-1);
|
||||||
}
|
}
|
||||||
@ -334,16 +336,18 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
pressed = true;
|
pressed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
InputOverrider.setControlState(0, joystick.getXControl(), joystick.getX());
|
InputOverrider.setControlState(mControllerIndex, joystick.getXControl(), joystick.getX());
|
||||||
InputOverrider.setControlState(0, joystick.getYControl(), -joystick.getY());
|
InputOverrider.setControlState(mControllerIndex, joystick.getYControl(), -joystick.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
// No button/joystick pressed, safe to move pointer
|
// No button/joystick pressed, safe to move pointer
|
||||||
if (!pressed && overlayPointer != null)
|
if (!pressed && overlayPointer != null)
|
||||||
{
|
{
|
||||||
overlayPointer.onTouch(event);
|
overlayPointer.onTouch(event);
|
||||||
InputOverrider.setControlState(0, ControlId.WIIMOTE_IR_X, overlayPointer.getX());
|
InputOverrider.setControlState(mControllerIndex, ControlId.WIIMOTE_IR_X,
|
||||||
InputOverrider.setControlState(0, ControlId.WIIMOTE_IR_Y, -overlayPointer.getY());
|
overlayPointer.getX());
|
||||||
|
InputOverrider.setControlState(mControllerIndex, ControlId.WIIMOTE_IR_Y,
|
||||||
|
-overlayPointer.getY());
|
||||||
}
|
}
|
||||||
|
|
||||||
invalidate();
|
invalidate();
|
||||||
@ -483,14 +487,20 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
|
|
||||||
private void unregisterControllers()
|
private void unregisterControllers()
|
||||||
{
|
{
|
||||||
if (mGameCubeRegistered)
|
for (int i = 0; i < mGcPadRegistered.length; i++)
|
||||||
InputOverrider.unregisterGameCube(0);
|
{
|
||||||
|
if (mGcPadRegistered[i])
|
||||||
|
InputOverrider.unregisterGameCube(i);
|
||||||
|
}
|
||||||
|
|
||||||
if (mWiiRegistered)
|
for (int i = 0; i < mWiimoteRegistered.length; i++)
|
||||||
InputOverrider.unregisterWii(0);
|
{
|
||||||
|
if (mWiimoteRegistered[i])
|
||||||
|
InputOverrider.unregisterWii(i);
|
||||||
|
}
|
||||||
|
|
||||||
mGameCubeRegistered = false;
|
Arrays.fill(mGcPadRegistered, false);
|
||||||
mWiiRegistered = false;
|
Arrays.fill(mWiimoteRegistered, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getAnalogControlForTrigger(int control)
|
private int getAnalogControlForTrigger(int control)
|
||||||
@ -797,16 +807,16 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
|
|
||||||
mControllerType = getConfiguredControllerType(settings);
|
mControllerType = getConfiguredControllerType(settings);
|
||||||
|
|
||||||
|
IntSetting controllerSetting = NativeLibrary.IsEmulatingWii() ?
|
||||||
|
IntSetting.MAIN_OVERLAY_WII_CONTROLLER : IntSetting.MAIN_OVERLAY_GC_CONTROLLER;
|
||||||
|
int controllerIndex = controllerSetting.getInt(settings);
|
||||||
|
|
||||||
if (BooleanSetting.MAIN_SHOW_INPUT_OVERLAY.getBooleanGlobal())
|
if (BooleanSetting.MAIN_SHOW_INPUT_OVERLAY.getBooleanGlobal())
|
||||||
{
|
{
|
||||||
// Add all the enabled overlay items back to the HashSet.
|
// Add all the enabled overlay items back to the HashSet.
|
||||||
switch (mControllerType)
|
switch (mControllerType)
|
||||||
{
|
{
|
||||||
case OVERLAY_GAMECUBE:
|
case OVERLAY_GAMECUBE:
|
||||||
IntSetting controllerSetting = NativeLibrary.IsEmulatingWii() ?
|
|
||||||
IntSetting.MAIN_OVERLAY_WII_CONTROLLER : IntSetting.MAIN_OVERLAY_GC_CONTROLLER;
|
|
||||||
int controllerIndex = controllerSetting.getInt(settings);
|
|
||||||
|
|
||||||
if (IntSetting.getSettingForSIDevice(controllerIndex).getInt(settings) ==
|
if (IntSetting.getSettingForSIDevice(controllerIndex).getInt(settings) ==
|
||||||
DISABLED_GAMECUBE_CONTROLLER && mIsFirstRun)
|
DISABLED_GAMECUBE_CONTROLLER && mIsFirstRun)
|
||||||
{
|
{
|
||||||
@ -814,28 +824,36 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
InputOverrider.registerGameCube(0);
|
mControllerIndex = controllerIndex;
|
||||||
mGameCubeRegistered = true;
|
InputOverrider.registerGameCube(mControllerIndex);
|
||||||
|
mGcPadRegistered[mControllerIndex] = true;
|
||||||
|
|
||||||
addGameCubeOverlayControls(orientation);
|
addGameCubeOverlayControls(orientation);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OVERLAY_WIIMOTE:
|
case OVERLAY_WIIMOTE:
|
||||||
case OVERLAY_WIIMOTE_SIDEWAYS:
|
case OVERLAY_WIIMOTE_SIDEWAYS:
|
||||||
InputOverrider.registerWii(0);
|
mControllerIndex = controllerIndex - 4;
|
||||||
mWiiRegistered = true;
|
InputOverrider.registerWii(mControllerIndex);
|
||||||
|
mWiimoteRegistered[mControllerIndex] = true;
|
||||||
|
|
||||||
addWiimoteOverlayControls(orientation);
|
addWiimoteOverlayControls(orientation);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OVERLAY_WIIMOTE_NUNCHUK:
|
case OVERLAY_WIIMOTE_NUNCHUK:
|
||||||
InputOverrider.registerWii(0);
|
mControllerIndex = controllerIndex - 4;
|
||||||
mWiiRegistered = true;
|
InputOverrider.registerWii(mControllerIndex);
|
||||||
|
mWiimoteRegistered[mControllerIndex] = true;
|
||||||
|
|
||||||
addWiimoteOverlayControls(orientation);
|
addWiimoteOverlayControls(orientation);
|
||||||
addNunchukOverlayControls(orientation);
|
addNunchukOverlayControls(orientation);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case OVERLAY_WIIMOTE_CLASSIC:
|
case OVERLAY_WIIMOTE_CLASSIC:
|
||||||
InputOverrider.registerWii(0);
|
mControllerIndex = controllerIndex - 4;
|
||||||
mWiiRegistered = true;
|
InputOverrider.registerWii(mControllerIndex);
|
||||||
|
mWiimoteRegistered[mControllerIndex] = true;
|
||||||
|
|
||||||
addClassicOverlayControls(orientation);
|
addClassicOverlayControls(orientation);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1229,7 +1247,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
// Send the drawableId to the joystick so it can be referenced when saving control position.
|
// Send the drawableId to the joystick so it can be referenced when saving control position.
|
||||||
final InputOverlayDrawableJoystick overlayDrawable =
|
final InputOverlayDrawableJoystick overlayDrawable =
|
||||||
new InputOverlayDrawableJoystick(res, bitmapOuter, bitmapInnerDefault,
|
new InputOverlayDrawableJoystick(res, bitmapOuter, bitmapInnerDefault,
|
||||||
bitmapInnerPressed, outerRect, innerRect, legacyId, xControl, yControl);
|
bitmapInnerPressed, outerRect, innerRect, legacyId, xControl, yControl,
|
||||||
|
mControllerIndex);
|
||||||
|
|
||||||
// Need to set the image's position
|
// Need to set the image's position
|
||||||
overlayDrawable.setPosition(drawableX, drawableY);
|
overlayDrawable.setPosition(drawableX, drawableY);
|
||||||
|
@ -31,6 +31,7 @@ public final class InputOverlayDrawableJoystick
|
|||||||
private int mPreviousTouchX, mPreviousTouchY;
|
private int mPreviousTouchX, mPreviousTouchY;
|
||||||
private final int mWidth;
|
private final int mWidth;
|
||||||
private final int mHeight;
|
private final int mHeight;
|
||||||
|
private final int mControllerIndex;
|
||||||
private Rect mVirtBounds;
|
private Rect mVirtBounds;
|
||||||
private Rect mOrigBounds;
|
private Rect mOrigBounds;
|
||||||
private int mOpacity;
|
private int mOpacity;
|
||||||
@ -55,7 +56,7 @@ public final class InputOverlayDrawableJoystick
|
|||||||
*/
|
*/
|
||||||
public InputOverlayDrawableJoystick(Resources res, Bitmap bitmapOuter, Bitmap bitmapInnerDefault,
|
public InputOverlayDrawableJoystick(Resources res, Bitmap bitmapOuter, Bitmap bitmapInnerDefault,
|
||||||
Bitmap bitmapInnerPressed, Rect rectOuter, Rect rectInner, int legacyId, int xControl,
|
Bitmap bitmapInnerPressed, Rect rectOuter, Rect rectInner, int legacyId, int xControl,
|
||||||
int yControl)
|
int yControl, int controllerIndex)
|
||||||
{
|
{
|
||||||
mJoystickLegacyId = legacyId;
|
mJoystickLegacyId = legacyId;
|
||||||
mJoystickXControl = xControl;
|
mJoystickXControl = xControl;
|
||||||
@ -68,6 +69,10 @@ public final class InputOverlayDrawableJoystick
|
|||||||
mWidth = bitmapOuter.getWidth();
|
mWidth = bitmapOuter.getWidth();
|
||||||
mHeight = bitmapOuter.getHeight();
|
mHeight = bitmapOuter.getHeight();
|
||||||
|
|
||||||
|
if (controllerIndex < 0 || controllerIndex >= 4)
|
||||||
|
throw new IllegalArgumentException("controllerIndex must be 0-3");
|
||||||
|
mControllerIndex = controllerIndex;
|
||||||
|
|
||||||
setBounds(rectOuter);
|
setBounds(rectOuter);
|
||||||
mDefaultStateInnerBitmap.setBounds(rectInner);
|
mDefaultStateInnerBitmap.setBounds(rectInner);
|
||||||
mPressedStateInnerBitmap.setBounds(rectInner);
|
mPressedStateInnerBitmap.setBounds(rectInner);
|
||||||
@ -221,7 +226,8 @@ public final class InputOverlayDrawableJoystick
|
|||||||
|
|
||||||
double angle = Math.atan2(y, x) + Math.PI + Math.PI;
|
double angle = Math.atan2(y, x) + Math.PI + Math.PI;
|
||||||
double radius = Math.hypot(y, x);
|
double radius = Math.hypot(y, x);
|
||||||
double maxRadius = InputOverrider.getGateRadiusAtAngle(0, mJoystickXControl, angle);
|
double maxRadius = InputOverrider.getGateRadiusAtAngle(mControllerIndex, mJoystickXControl,
|
||||||
|
angle);
|
||||||
if (radius > maxRadius)
|
if (radius > maxRadius)
|
||||||
{
|
{
|
||||||
y = maxRadius * Math.sin(angle);
|
y = maxRadius * Math.sin(angle);
|
||||||
|
@ -32,6 +32,7 @@ public class InputOverlayPointer
|
|||||||
|
|
||||||
private int mMode;
|
private int mMode;
|
||||||
private boolean mRecenter;
|
private boolean mRecenter;
|
||||||
|
private int mControllerIndex;
|
||||||
|
|
||||||
private boolean doubleTap = false;
|
private boolean doubleTap = false;
|
||||||
private int mDoubleTapControl;
|
private int mDoubleTapControl;
|
||||||
@ -47,11 +48,13 @@ public class InputOverlayPointer
|
|||||||
DOUBLE_TAP_OPTIONS.add(NativeLibrary.ButtonType.CLASSIC_BUTTON_A);
|
DOUBLE_TAP_OPTIONS.add(NativeLibrary.ButtonType.CLASSIC_BUTTON_A);
|
||||||
}
|
}
|
||||||
|
|
||||||
public InputOverlayPointer(Rect surfacePosition, int doubleTapControl, int mode, boolean recenter)
|
public InputOverlayPointer(Rect surfacePosition, int doubleTapControl, int mode, boolean recenter,
|
||||||
|
int controllerIndex)
|
||||||
{
|
{
|
||||||
mDoubleTapControl = doubleTapControl;
|
mDoubleTapControl = doubleTapControl;
|
||||||
mMode = mode;
|
mMode = mode;
|
||||||
mRecenter = recenter;
|
mRecenter = recenter;
|
||||||
|
mControllerIndex = controllerIndex;
|
||||||
|
|
||||||
mGameCenterX = (surfacePosition.left + surfacePosition.right) / 2.0f;
|
mGameCenterX = (surfacePosition.left + surfacePosition.right) / 2.0f;
|
||||||
mGameCenterY = (surfacePosition.top + surfacePosition.bottom) / 2.0f;
|
mGameCenterY = (surfacePosition.top + surfacePosition.bottom) / 2.0f;
|
||||||
@ -128,8 +131,9 @@ public class InputOverlayPointer
|
|||||||
{
|
{
|
||||||
if (doubleTap)
|
if (doubleTap)
|
||||||
{
|
{
|
||||||
InputOverrider.setControlState(0, mDoubleTapControl, 1.0);
|
InputOverrider.setControlState(mControllerIndex, mDoubleTapControl, 1.0);
|
||||||
new Handler().postDelayed(() -> InputOverrider.setControlState(0, mDoubleTapControl, 0.0),
|
new Handler().postDelayed(() -> InputOverrider.setControlState(mControllerIndex,
|
||||||
|
mDoubleTapControl, 0.0),
|
||||||
50);
|
50);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
x
Reference in New Issue
Block a user