Android: Fix saving Horizonal Wii Remote overlay A/B/1/2 positions

saveControlPosition was not applying the _H part of the key.
This commit is contained in:
JosJuice 2020-07-08 15:49:37 +02:00
parent 87287181dd
commit a23e14fe76
1 changed files with 42 additions and 49 deletions

View File

@ -328,6 +328,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
int fingerPositionX = (int) event.getX(pointerIndex); int fingerPositionX = (int) event.getX(pointerIndex);
int fingerPositionY = (int) event.getY(pointerIndex); int fingerPositionY = (int) event.getY(pointerIndex);
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
int controller = sPrefs.getInt("wiiController", 3);
String orientation = String orientation =
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ?
"-Portrait" : ""; "-Portrait" : "";
@ -366,7 +368,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// Persist button position by saving new place. // Persist button position by saving new place.
saveControlPosition(mButtonBeingConfigured.getId(), saveControlPosition(mButtonBeingConfigured.getId(),
mButtonBeingConfigured.getBounds().left, mButtonBeingConfigured.getBounds().left,
mButtonBeingConfigured.getBounds().top, orientation); mButtonBeingConfigured.getBounds().top, controller, orientation);
mButtonBeingConfigured = null; mButtonBeingConfigured = null;
} }
break; break;
@ -404,7 +406,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// Persist button position by saving new place. // Persist button position by saving new place.
saveControlPosition(mDpadBeingConfigured.getId(0), saveControlPosition(mDpadBeingConfigured.getId(0),
mDpadBeingConfigured.getBounds().left, mDpadBeingConfigured.getBounds().top, mDpadBeingConfigured.getBounds().left, mDpadBeingConfigured.getBounds().top,
orientation); controller, orientation);
mDpadBeingConfigured = null; mDpadBeingConfigured = null;
} }
break; break;
@ -437,7 +439,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
{ {
saveControlPosition(mJoystickBeingConfigured.getId(), saveControlPosition(mJoystickBeingConfigured.getId(),
mJoystickBeingConfigured.getBounds().left, mJoystickBeingConfigured.getBounds().left,
mJoystickBeingConfigured.getBounds().top, orientation); mJoystickBeingConfigured.getBounds().top, controller, orientation);
mJoystickBeingConfigured = null; mJoystickBeingConfigured = null;
} }
break; break;
@ -790,15 +792,42 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
refreshControls(); refreshControls();
} }
private void saveControlPosition(int sharedPrefsId, int x, int y, String orientation) private void saveControlPosition(int sharedPrefsId, int x, int y, int controller,
String orientation)
{ {
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getContext()); final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor sPrefsEditor = sPrefs.edit(); SharedPreferences.Editor sPrefsEditor = sPrefs.edit();
sPrefsEditor.putFloat(sharedPrefsId + orientation + "-X", x); sPrefsEditor.putFloat(getXKey(sharedPrefsId, controller, orientation), x);
sPrefsEditor.putFloat(sharedPrefsId + orientation + "-Y", y); sPrefsEditor.putFloat(getYKey(sharedPrefsId, controller, orientation), y);
sPrefsEditor.apply(); sPrefsEditor.apply();
} }
private static String getKey(int sharedPrefsId, int controller, String orientation, String suffix)
{
if (controller == 2 && WIIMOTE_H_BUTTONS.contains(sharedPrefsId))
{
return sharedPrefsId + "_H" + orientation + suffix;
}
else if (controller == 1 && WIIMOTE_O_BUTTONS.contains(sharedPrefsId))
{
return sharedPrefsId + "_O" + orientation + suffix;
}
else
{
return sharedPrefsId + orientation + suffix;
}
}
private static String getXKey(int sharedPrefsId, int controller, String orientation)
{
return getKey(sharedPrefsId, controller, orientation, "-X");
}
private static String getYKey(int sharedPrefsId, int controller, String orientation)
{
return getKey(sharedPrefsId, controller, orientation, "-Y");
}
/** /**
* Initializes an InputOverlayDrawableButton, given by resId, with all of the * Initializes an InputOverlayDrawableButton, given by resId, with all of the
* parameters set for it to be properly shown on the InputOverlay. * parameters set for it to be properly shown on the InputOverlay.
@ -900,27 +929,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay. // The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
// These were set in the input overlay configuration menu. // These were set in the input overlay configuration menu.
String xKey; int drawableX = (int) sPrefs.getFloat(getXKey(buttonId, controller, orientation), 0f);
String yKey; int drawableY = (int) sPrefs.getFloat(getYKey(buttonId, controller, orientation), 0f);
if (controller == 2 && WIIMOTE_H_BUTTONS.contains(buttonId))
{
xKey = buttonId + "_H" + orientation + "-X";
yKey = buttonId + "_H" + orientation + "-Y";
}
else if (controller == 1 && WIIMOTE_O_BUTTONS.contains(buttonId))
{
xKey = buttonId + "_O" + orientation + "-X";
yKey = buttonId + "_O" + orientation + "-Y";
}
else
{
xKey = buttonId + orientation + "-X";
yKey = buttonId + orientation + "-Y";
}
int drawableX = (int) sPrefs.getFloat(xKey, 0f);
int drawableY = (int) sPrefs.getFloat(yKey, 0f);
int width = overlayDrawable.getWidth(); int width = overlayDrawable.getWidth();
int height = overlayDrawable.getHeight(); int height = overlayDrawable.getHeight();
@ -1003,26 +1013,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// The X and Y coordinates of the InputOverlayDrawableDpad on the InputOverlay. // The X and Y coordinates of the InputOverlayDrawableDpad on the InputOverlay.
// These were set in the input overlay configuration menu. // These were set in the input overlay configuration menu.
String xKey; int drawableX = (int) sPrefs.getFloat(getXKey(buttonUp, controller, orientation), 0f);
String yKey; int drawableY = (int) sPrefs.getFloat(getYKey(buttonUp, controller, orientation), 0f);
if (controller == 2 && WIIMOTE_H_BUTTONS.contains(buttonUp))
{
xKey = buttonUp + "_H" + orientation + "-X";
yKey = buttonUp + "_H" + orientation + "-Y";
}
else if (controller == 1 && WIIMOTE_O_BUTTONS.contains(buttonUp))
{
xKey = buttonUp + "_O" + orientation + "-X";
yKey = buttonUp + "_O" + orientation + "-Y";
}
else
{
xKey = buttonUp + orientation + "-X";
yKey = buttonUp + orientation + "-Y";
}
int drawableX = (int) sPrefs.getFloat(xKey, 0f);
int drawableY = (int) sPrefs.getFloat(yKey, 0f);
int width = overlayDrawable.getWidth(); int width = overlayDrawable.getWidth();
int height = overlayDrawable.getHeight(); int height = overlayDrawable.getHeight();
@ -1055,6 +1047,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableJoystick. // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableJoystick.
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
int controller = sPrefs.getInt("wiiController", 3);
// Decide scale based on user preference // Decide scale based on user preference
float scale = 0.275f; float scale = 0.275f;
@ -1069,8 +1062,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay. // The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay.
// These were set in the input overlay configuration menu. // These were set in the input overlay configuration menu.
int drawableX = (int) sPrefs.getFloat(joystick + orientation + "-X", 0f); int drawableX = (int) sPrefs.getFloat(getXKey(joystick, controller, orientation), 0f);
int drawableY = (int) sPrefs.getFloat(joystick + orientation + "-Y", 0f); int drawableY = (int) sPrefs.getFloat(getYKey(joystick, controller, orientation), 0f);
// Decide inner scale based on joystick ID // Decide inner scale based on joystick ID
float innerScale; float innerScale;