From 10238b45a404b0f97b36d1c07defd2a432e41dce Mon Sep 17 00:00:00 2001 From: zackhow Date: Fri, 11 Jan 2019 19:40:20 -0500 Subject: [PATCH] Android: Wiimote only(no nunchuck) overlay upgrades Increase some button sizes Create new defaults for Wiimote only and horizontal wiimote --- .../dolphinemu/overlay/InputOverlay.java | 241 +++++++++++++++--- .../app/src/main/res/values/integers.xml | 28 +- 2 files changed, 233 insertions(+), 36 deletions(-) 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 de29e00ed5..ba0b74b293 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 @@ -31,6 +31,7 @@ import org.dolphinemu.dolphinemu.NativeLibrary.ButtonType; import org.dolphinemu.dolphinemu.R; import org.dolphinemu.dolphinemu.activities.EmulationActivity; +import java.util.ArrayList; import java.util.HashSet; import java.util.Set; @@ -51,6 +52,24 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener private SharedPreferences mPreferences; + // Buttons that have special positions in Wiimote only + private static final ArrayList WIIMOTE_H_BUTTONS = new ArrayList<>(); + + static + { + WIIMOTE_H_BUTTONS.add(ButtonType.WIIMOTE_BUTTON_A); + WIIMOTE_H_BUTTONS.add(ButtonType.WIIMOTE_BUTTON_B); + WIIMOTE_H_BUTTONS.add(ButtonType.WIIMOTE_BUTTON_1); + WIIMOTE_H_BUTTONS.add(ButtonType.WIIMOTE_BUTTON_2); + } + + private static final ArrayList WIIMOTE_O_BUTTONS = new ArrayList<>(); + + static + { + WIIMOTE_O_BUTTONS.add(ButtonType.WIIMOTE_UP); + } + /** * Resizes a {@link Bitmap} by a given scale factor * @@ -83,7 +102,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener super(context, attrs); mPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); - if (!mPreferences.getBoolean("OverlayInitV2", false)) + if (!mPreferences.getBoolean("OverlayInitV3", false)) defaultOverlay(); // Load the controls. refreshControls(); @@ -661,9 +680,15 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener else { if (isLandscape) + { wiiDefaultOverlay(); + wiiOnlyDefaultOverlay(); + } else + { wiiPortraitDefaultOverlay(); + wiiOnlyPortraitDefaultOverlay(); + } } refreshControls(); } @@ -715,6 +740,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableButton. final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); + int controller = sPrefs.getInt("wiiController", 3); // Decide scale based on button ID and user preference float scale; @@ -740,7 +766,10 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener break; case ButtonType.WIIMOTE_BUTTON_1: case ButtonType.WIIMOTE_BUTTON_2: - scale = 0.0875f; + if (controller == 2) + scale = 0.14f; + else + scale = 0.0875f; break; case ButtonType.WIIMOTE_BUTTON_PLUS: case ButtonType.WIIMOTE_BUTTON_MINUS: @@ -774,8 +803,27 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // The X and Y coordinates of the InputOverlayDrawableButton on the InputOverlay. // These were set in the input overlay configuration menu. - int drawableX = (int) sPrefs.getFloat(buttonId + orientation + "-X", 0f); - int drawableY = (int) sPrefs.getFloat(buttonId + orientation + "-Y", 0f); + String xKey; + String yKey; + + 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 height = overlayDrawable.getHeight(); @@ -818,6 +866,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableDpad. final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); + int controller = sPrefs.getInt("wiiController", 3); // Decide scale based on button ID and user preference float scale; @@ -831,7 +880,10 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener scale = 0.275f; break; default: - scale = 0.2125f; + if (controller == 2 || controller == 1) + scale = 0.275f; + else + scale = 0.2125f; break; } @@ -854,8 +906,26 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener // The X and Y coordinates of the InputOverlayDrawableDpad on the InputOverlay. // These were set in the input overlay configuration menu. - int drawableX = (int) sPrefs.getFloat(buttonUp + orientation + "-X", 0f); - int drawableY = (int) sPrefs.getFloat(buttonUp + orientation + "-Y", 0f); + String xKey; + String yKey; + + 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 height = overlayDrawable.getHeight(); @@ -948,40 +1018,50 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener private void defaultOverlay() { - // It's possible that a user has created their overlay before this was added - // Only change the overlay if the 'A' button is not in the upper corner. - // GameCube - if (mPreferences.getFloat(ButtonType.BUTTON_A + "-X", 0f) == 0f) + if (!mPreferences.getBoolean("OverlayInitV2", false)) { - gcDefaultOverlay(); - } - if (mPreferences.getFloat(ButtonType.BUTTON_A + "-Portrait" + "-X", 0f) == 0f) - { - gcPortraitDefaultOverlay(); + // It's possible that a user has created their overlay before this was added + // Only change the overlay if the 'A' button is not in the upper corner. + // GameCube + if (mPreferences.getFloat(ButtonType.BUTTON_A + "-X", 0f) == 0f) + { + gcDefaultOverlay(); + } + if (mPreferences.getFloat(ButtonType.BUTTON_A + "-Portrait" + "-X", 0f) == 0f) + { + gcPortraitDefaultOverlay(); + } + + // Wii + if (mPreferences.getFloat(ButtonType.WIIMOTE_BUTTON_A + "-X", 0f) == 0f) + { + wiiDefaultOverlay(); + } + if (mPreferences.getFloat(ButtonType.WIIMOTE_BUTTON_A + "-Portrait" + "-X", 0f) == 0f) + { + wiiPortraitDefaultOverlay(); + } + + // Wii Classic + if (mPreferences.getFloat(ButtonType.CLASSIC_BUTTON_A + "-X", 0f) == 0f) + { + wiiClassicDefaultOverlay(); + } + if (mPreferences.getFloat(ButtonType.CLASSIC_BUTTON_A + "-Portrait" + "-X", 0f) == 0f) + { + wiiClassicPortraitDefaultOverlay(); + } } - // Wii - if (mPreferences.getFloat(ButtonType.WIIMOTE_BUTTON_A + "-X", 0f) == 0f) + if (!mPreferences.getBoolean("OverlayInitV3", false)) { - wiiDefaultOverlay(); - } - if (mPreferences.getFloat(ButtonType.WIIMOTE_BUTTON_A + "-Portrait" + "-X", 0f) == 0f) - { - wiiPortraitDefaultOverlay(); - } - - // Wii Classic - if (mPreferences.getFloat(ButtonType.CLASSIC_BUTTON_A + "-X", 0f) == 0f) - { - wiiClassicDefaultOverlay(); - } - if (mPreferences.getFloat(ButtonType.CLASSIC_BUTTON_A + "-Portrait" + "-X", 0f) == 0f) - { - wiiClassicPortraitDefaultOverlay(); + wiiOnlyDefaultOverlay(); + wiiOnlyPortraitDefaultOverlay(); } SharedPreferences.Editor sPrefsEditor = mPreferences.edit(); sPrefsEditor.putBoolean("OverlayInitV2", true); + sPrefsEditor.putBoolean("OverlayInitV3", true); sPrefsEditor.apply(); } @@ -1192,6 +1272,53 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener (((float) res.getInteger(R.integer.NUNCHUK_STICK_X) / 1000) * maxX)); sPrefsEditor.putFloat(ButtonType.NUNCHUK_STICK + "-Y", (((float) res.getInteger(R.integer.NUNCHUK_STICK_Y) / 1000) * maxY)); + + // We want to commit right away, otherwise the overlay could load before this is saved. + sPrefsEditor.commit(); + } + + private void wiiOnlyDefaultOverlay() + { + SharedPreferences.Editor sPrefsEditor = mPreferences.edit(); + + // Get screen size + Display display = ((Activity) getContext()).getWindowManager().getDefaultDisplay(); + DisplayMetrics outMetrics = new DisplayMetrics(); + display.getMetrics(outMetrics); + float maxX = outMetrics.heightPixels; + float maxY = outMetrics.widthPixels; + // Height and width changes depending on orientation. Use the larger value for maxX. + if (maxY > maxX) + { + float tmp = maxX; + maxX = maxY; + maxY = tmp; + } + Resources res = getResources(); + + // Each value is a percent from max X/Y stored as an int. Have to bring that value down + // to a decimal before multiplying by MAX X/Y. + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_A + "_H-X", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_A_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_A + "_H-Y", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_A_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_B + "_H-X", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_B_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_B + "_H-Y", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_B_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_1 + "_H-X", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_1_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_1 + "_H-Y", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_1_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_2 + "_H-X", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_2_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_2 + "_H-Y", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_2_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_UP + "_O-X", + (((float) res.getInteger(R.integer.WIIMOTE_O_UP_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_UP + "_O-Y", + (((float) res.getInteger(R.integer.WIIMOTE_O_UP_Y) / 1000) * maxY)); + // Horizontal dpad sPrefsEditor.putFloat(ButtonType.WIIMOTE_RIGHT + "-X", (((float) res.getInteger(R.integer.WIIMOTE_RIGHT_X) / 1000) * maxX)); @@ -1278,6 +1405,53 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener sPrefsEditor.commit(); } + private void wiiOnlyPortraitDefaultOverlay() + { + SharedPreferences.Editor sPrefsEditor = mPreferences.edit(); + + // Get screen size + Display display = ((Activity) getContext()).getWindowManager().getDefaultDisplay(); + DisplayMetrics outMetrics = new DisplayMetrics(); + display.getMetrics(outMetrics); + float maxX = outMetrics.heightPixels; + float maxY = outMetrics.widthPixels; + // Height and width changes depending on orientation. Use the larger value for maxX. + if (maxY < maxX) + { + float tmp = maxX; + maxX = maxY; + maxY = tmp; + } + Resources res = getResources(); + String portrait = "-Portrait"; + + // Each value is a percent from max X/Y stored as an int. Have to bring that value down + // to a decimal before multiplying by MAX X/Y. + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_A + "_H" + portrait + "-X", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_A_PORTRAIT_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_A + "_H" + portrait + "-Y", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_A_PORTRAIT_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_B + "_H" + portrait + "-X", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_B_PORTRAIT_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_B + "_H" + portrait + "-Y", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_B_PORTRAIT_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_1 + "_H" + portrait + "-X", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_1_PORTRAIT_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_1 + "_H" + portrait + "-Y", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_1_PORTRAIT_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_2 + "_H" + portrait + "-X", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_2_PORTRAIT_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_2 + "_H" + portrait + "-Y", + (((float) res.getInteger(R.integer.WIIMOTE_H_BUTTON_2_PORTRAIT_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_UP + "_O" + portrait + "-X", + (((float) res.getInteger(R.integer.WIIMOTE_O_UP_PORTRAIT_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_UP + "_O" + portrait + "-Y", + (((float) res.getInteger(R.integer.WIIMOTE_O_UP_PORTRAIT_Y) / 1000) * maxY)); + + // We want to commit right away, otherwise the overlay could load before this is saved. + sPrefsEditor.commit(); + } + private void wiiClassicDefaultOverlay() { SharedPreferences.Editor sPrefsEditor = mPreferences.edit(); @@ -1360,7 +1534,6 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener sPrefsEditor.commit(); } - private void wiiClassicPortraitDefaultOverlay() { SharedPreferences.Editor sPrefsEditor = mPreferences.edit(); diff --git a/Source/Android/app/src/main/res/values/integers.xml b/Source/Android/app/src/main/res/values/integers.xml index 094945ca8f..1585d38ff4 100644 --- a/Source/Android/app/src/main/res/values/integers.xml +++ b/Source/Android/app/src/main/res/values/integers.xml @@ -74,8 +74,21 @@ 51 681 - 100 - 683 + + 48 + 652 + + + 48 + 187 + 890 + 734 + 731 + 715 + 867 + 303 + 925 + 103 769 @@ -104,6 +117,17 @@ 68 602 + 769 + 584 + 553 + 621 + 707 + 742 + 846 + 692 + 260 + 773 + 860 688