mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-01-25 15:31:17 +01:00
Android: Make touch joystick re centering configurable
This commit is contained in:
parent
227290055d
commit
82ec3c929c
@ -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_LOAD_SLOT6 = 21;
|
||||||
public static final int MENU_ACTION_EXIT = 22;
|
public static final int MENU_ACTION_EXIT = 22;
|
||||||
public static final int MENU_ACTION_CHANGE_DISC = 23;
|
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();
|
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_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_change_disc, EmulationActivity.MENU_ACTION_CHANGE_DISC);
|
||||||
buttonsActionsMap.append(R.id.menu_exit, EmulationActivity.MENU_ACTION_EXIT);
|
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)
|
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);
|
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;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -441,11 +447,30 @@ public final class EmulationActivity extends AppCompatActivity
|
|||||||
int action = buttonsActionsMap.get(item.getItemId(), -1);
|
int action = buttonsActionsMap.get(item.getItemId(), -1);
|
||||||
if (action >= 0)
|
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;
|
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)
|
public void handleMenuAction(@MenuAction int menuAction)
|
||||||
{
|
{
|
||||||
switch (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()
|
private void editControlsPlacement()
|
||||||
{
|
{
|
||||||
|
@ -829,7 +829,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
|
|||||||
final InputOverlayDrawableJoystick overlayDrawable
|
final InputOverlayDrawableJoystick overlayDrawable
|
||||||
= new InputOverlayDrawableJoystick(res, bitmapOuter,
|
= new InputOverlayDrawableJoystick(res, bitmapOuter,
|
||||||
bitmapInnerDefault, bitmapInnerPressed,
|
bitmapInnerDefault, bitmapInnerPressed,
|
||||||
outerRect, innerRect, joystick);
|
outerRect, innerRect, joystick, sPrefs);
|
||||||
|
|
||||||
// Need to set the image's position
|
// Need to set the image's position
|
||||||
overlayDrawable.setPosition(drawableX, drawableY);
|
overlayDrawable.setPosition(drawableX, drawableY);
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
package org.dolphinemu.dolphinemu.overlay;
|
package org.dolphinemu.dolphinemu.overlay;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
@ -19,6 +21,8 @@ import android.view.MotionEvent;
|
|||||||
*/
|
*/
|
||||||
public final class InputOverlayDrawableJoystick
|
public final class InputOverlayDrawableJoystick
|
||||||
{
|
{
|
||||||
|
private SharedPreferences mPreferences;
|
||||||
|
|
||||||
private final int[] axisIDs = {0, 0, 0, 0};
|
private final int[] axisIDs = {0, 0, 0, 0};
|
||||||
private final float[] axises = {0f, 0f};
|
private final float[] axises = {0f, 0f};
|
||||||
private int trackId = -1;
|
private int trackId = -1;
|
||||||
@ -48,7 +52,7 @@ public final class InputOverlayDrawableJoystick
|
|||||||
*/
|
*/
|
||||||
public InputOverlayDrawableJoystick(Resources res, Bitmap bitmapOuter,
|
public InputOverlayDrawableJoystick(Resources res, Bitmap bitmapOuter,
|
||||||
Bitmap bitmapInnerDefault, Bitmap bitmapInnerPressed,
|
Bitmap bitmapInnerDefault, Bitmap bitmapInnerPressed,
|
||||||
Rect rectOuter, Rect rectInner, int joystick)
|
Rect rectOuter, Rect rectInner, int joystick, SharedPreferences prefsHandle)
|
||||||
{
|
{
|
||||||
axisIDs[0] = joystick + 1;
|
axisIDs[0] = joystick + 1;
|
||||||
axisIDs[1] = joystick + 2;
|
axisIDs[1] = joystick + 2;
|
||||||
@ -56,6 +60,7 @@ public final class InputOverlayDrawableJoystick
|
|||||||
axisIDs[3] = joystick + 4;
|
axisIDs[3] = joystick + 4;
|
||||||
mJoystickType = joystick;
|
mJoystickType = joystick;
|
||||||
|
|
||||||
|
mPreferences = prefsHandle;
|
||||||
mOuterBitmap = new BitmapDrawable(res, bitmapOuter);
|
mOuterBitmap = new BitmapDrawable(res, bitmapOuter);
|
||||||
mDefaultStateInnerBitmap = new BitmapDrawable(res, bitmapInnerDefault);
|
mDefaultStateInnerBitmap = new BitmapDrawable(res, bitmapInnerDefault);
|
||||||
mPressedStateInnerBitmap = new BitmapDrawable(res, bitmapInnerPressed);
|
mPressedStateInnerBitmap = new BitmapDrawable(res, bitmapInnerPressed);
|
||||||
@ -92,6 +97,7 @@ public final class InputOverlayDrawableJoystick
|
|||||||
|
|
||||||
public void TrackEvent(MotionEvent event)
|
public void TrackEvent(MotionEvent event)
|
||||||
{
|
{
|
||||||
|
boolean reCenter = mPreferences.getBoolean("joystickRelCenter", true);
|
||||||
int pointerIndex = event.getActionIndex();
|
int pointerIndex = event.getActionIndex();
|
||||||
|
|
||||||
switch(event.getAction() & MotionEvent.ACTION_MASK)
|
switch(event.getAction() & MotionEvent.ACTION_MASK)
|
||||||
@ -103,7 +109,10 @@ public final class InputOverlayDrawableJoystick
|
|||||||
mPressedState = true;
|
mPressedState = true;
|
||||||
mOuterBitmap.setAlpha(0);
|
mOuterBitmap.setAlpha(0);
|
||||||
mBoundsBoxBitmap.setAlpha(255);
|
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());
|
mBoundsBoxBitmap.setBounds(getVirtBounds());
|
||||||
trackId = event.getPointerId(pointerIndex);
|
trackId = event.getPointerId(pointerIndex);
|
||||||
}
|
}
|
||||||
|
@ -93,6 +93,11 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/menu_emulation_adjust_scale"
|
android:id="@+id/menu_emulation_adjust_scale"
|
||||||
android:title="@string/emulation_control_scale"/>
|
android:title="@string/emulation_control_scale"/>
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_emulation_joystick_rel_center"
|
||||||
|
android:checkable="true"
|
||||||
|
android:title="@string/emulation_control_joystick_rel_center"/>
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
@ -101,4 +106,4 @@
|
|||||||
app:showAsAction="never"
|
app:showAsAction="never"
|
||||||
android:title="@string/emulation_change_disc"/>
|
android:title="@string/emulation_change_disc"/>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -93,10 +93,17 @@
|
|||||||
android:id="@+id/menu_emulation_adjust_scale"
|
android:id="@+id/menu_emulation_adjust_scale"
|
||||||
android:title="@string/emulation_control_scale"/>
|
android:title="@string/emulation_control_scale"/>
|
||||||
|
|
||||||
|
<group android:checkableBehavior="all">
|
||||||
|
<item
|
||||||
|
android:id="@+id/menu_emulation_joystick_rel_center"
|
||||||
|
android:checkable="true"
|
||||||
|
android:title="@string/emulation_control_joystick_rel_center"/>
|
||||||
|
</group>
|
||||||
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/menu_emulation_choose_controller"
|
android:id="@+id/menu_emulation_choose_controller"
|
||||||
android:title="@string/emulation_choose_controller"/>
|
android:title="@string/emulation_choose_controller"/>
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
</menu>
|
</menu>
|
||||||
|
@ -246,6 +246,7 @@
|
|||||||
<string name="emulation_toggle_controls">Toggle Controls</string>
|
<string name="emulation_toggle_controls">Toggle Controls</string>
|
||||||
<string name="emulation_toggle_all">Toggle All</string>
|
<string name="emulation_toggle_all">Toggle All</string>
|
||||||
<string name="emulation_control_scale">Adjust Scale</string>
|
<string name="emulation_control_scale">Adjust Scale</string>
|
||||||
|
<string name="emulation_control_joystick_rel_center">Relative Stick Center</string>
|
||||||
<string name="emulation_choose_controller">Choose Controller</string>
|
<string name="emulation_choose_controller">Choose Controller</string>
|
||||||
<string name="emulation_controller_changed">You may have to reload the game after changing extensions.</string>
|
<string name="emulation_controller_changed">You may have to reload the game after changing extensions.</string>
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user