diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 4a02cfc89c..8ecb545298 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -120,6 +120,7 @@ public final class EmulationActivity extends AppCompatActivity public static final int MENU_ACTION_LOAD_SLOT6 = 21; public static final int MENU_ACTION_EXIT = 22; public static final int MENU_ACTION_CHANGE_DISC = 23; + public static final int MENU_ACTION_JOYSTICK_REL_CENTER = 24; private static SparseIntArray buttonsActionsMap = new SparseIntArray(); @@ -147,6 +148,7 @@ public final class EmulationActivity extends AppCompatActivity buttonsActionsMap.append(R.id.menu_emulation_load_5, EmulationActivity.MENU_ACTION_LOAD_SLOT5); buttonsActionsMap.append(R.id.menu_change_disc, EmulationActivity.MENU_ACTION_CHANGE_DISC); buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT); + buttonsActionsMap.append(R.id.menu_emulation_joystick_rel_center, EmulationActivity.MENU_ACTION_JOYSTICK_REL_CENTER); } public static void launch(FragmentActivity activity, GameFile gameFile, int position, View sharedView) @@ -431,6 +433,10 @@ public final class EmulationActivity extends AppCompatActivity { getMenuInflater().inflate(R.menu.menu_emulation_wii, menu); } + + // Populate the checkbox value for joystick center on touch + menu.findItem(R.id.menu_emulation_joystick_rel_center).setChecked(mPreferences.getBoolean("joystickRelCenter", true)); + return true; } @@ -441,11 +447,30 @@ public final class EmulationActivity extends AppCompatActivity int action = buttonsActionsMap.get(item.getItemId(), -1); if (action >= 0) { - handleMenuAction(action); + if (item.isCheckable()) + { + // Need to pass a reference to the item to set the checkbox state, since it is not done automatically + handleCheckableMenuAction(action, item); + } + else + { + handleMenuAction(action); + } } return true; } + public void handleCheckableMenuAction(@MenuAction int menuAction, MenuItem item) + { + switch (menuAction) + { + case MENU_ACTION_JOYSTICK_REL_CENTER: + item.setChecked(!item.isChecked()); + toggleJoystickRelCenter(item.isChecked()); + return; + } + } + public void handleMenuAction(@MenuAction int menuAction) { switch (menuAction) @@ -565,6 +590,13 @@ public final class EmulationActivity extends AppCompatActivity } } + private void toggleJoystickRelCenter(boolean state) + { + final SharedPreferences.Editor editor = mPreferences.edit(); + editor.putBoolean("joystickRelCenter", state); + editor.commit(); + } + private void editControlsPlacement() { diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java index 1957ff7f67..d3726bf88f 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java @@ -829,7 +829,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener final InputOverlayDrawableJoystick overlayDrawable = new InputOverlayDrawableJoystick(res, bitmapOuter, bitmapInnerDefault, bitmapInnerPressed, - outerRect, innerRect, joystick); + outerRect, innerRect, joystick, sPrefs); // Need to set the image's position overlayDrawable.setPosition(drawableX, drawableY); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java index 1c94b44135..8083b0d2ee 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlayDrawableJoystick.java @@ -6,6 +6,8 @@ package org.dolphinemu.dolphinemu.overlay; +import android.content.Context; +import android.content.SharedPreferences; import android.content.res.Resources; import android.graphics.Bitmap; import android.graphics.Canvas; @@ -19,6 +21,8 @@ import android.view.MotionEvent; */ public final class InputOverlayDrawableJoystick { + private SharedPreferences mPreferences; + private final int[] axisIDs = {0, 0, 0, 0}; private final float[] axises = {0f, 0f}; private int trackId = -1; @@ -48,7 +52,7 @@ public final class InputOverlayDrawableJoystick */ public InputOverlayDrawableJoystick(Resources res, Bitmap bitmapOuter, Bitmap bitmapInnerDefault, Bitmap bitmapInnerPressed, - Rect rectOuter, Rect rectInner, int joystick) + Rect rectOuter, Rect rectInner, int joystick, SharedPreferences prefsHandle) { axisIDs[0] = joystick + 1; axisIDs[1] = joystick + 2; @@ -56,6 +60,7 @@ public final class InputOverlayDrawableJoystick axisIDs[3] = joystick + 4; mJoystickType = joystick; + mPreferences = prefsHandle; mOuterBitmap = new BitmapDrawable(res, bitmapOuter); mDefaultStateInnerBitmap = new BitmapDrawable(res, bitmapInnerDefault); mPressedStateInnerBitmap = new BitmapDrawable(res, bitmapInnerPressed); @@ -92,6 +97,7 @@ public final class InputOverlayDrawableJoystick public void TrackEvent(MotionEvent event) { + boolean reCenter = mPreferences.getBoolean("joystickRelCenter", true); int pointerIndex = event.getActionIndex(); switch(event.getAction() & MotionEvent.ACTION_MASK) @@ -103,7 +109,10 @@ public final class InputOverlayDrawableJoystick mPressedState = true; mOuterBitmap.setAlpha(0); mBoundsBoxBitmap.setAlpha(255); - getVirtBounds().offset((int)event.getX(pointerIndex) - getVirtBounds().centerX(), (int)event.getY(pointerIndex) - getVirtBounds().centerY()); + if (reCenter) + { + getVirtBounds().offset((int)event.getX(pointerIndex) - getVirtBounds().centerX(), (int)event.getY(pointerIndex) - getVirtBounds().centerY()); + } mBoundsBoxBitmap.setBounds(getVirtBounds()); trackId = event.getPointerId(pointerIndex); } diff --git a/Source/Android/app/src/main/res/menu/menu_emulation.xml b/Source/Android/app/src/main/res/menu/menu_emulation.xml index 2dacda4668..5f4c1272b1 100644 --- a/Source/Android/app/src/main/res/menu/menu_emulation.xml +++ b/Source/Android/app/src/main/res/menu/menu_emulation.xml @@ -93,6 +93,11 @@ + + @@ -101,4 +106,4 @@ app:showAsAction="never" android:title="@string/emulation_change_disc"/> - \ No newline at end of file + diff --git a/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml b/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml index 3b8f66acf2..87c61eefc0 100644 --- a/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml +++ b/Source/Android/app/src/main/res/menu/menu_emulation_wii.xml @@ -93,10 +93,17 @@ android:id="@+id/menu_emulation_adjust_scale" android:title="@string/emulation_control_scale"/> + + + + - \ No newline at end of file + diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index c3f97ae4de..a02823e383 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -246,6 +246,7 @@ Toggle Controls Toggle All Adjust Scale + Relative Stick Center Choose Controller You may have to reload the game after changing extensions.