From 75f4e74e947a5a7fe21f7f73533e30a6417b67c7 Mon Sep 17 00:00:00 2001 From: zackhow Date: Wed, 8 Aug 2018 18:39:25 -0400 Subject: [PATCH] Android: Add default touch button overlay This sets up default positions for touch buttons so they are not just bunched in the corner on a fresh install. Also added a toast when emulation starts on how to edit button layout --- .../activities/EmulationActivity.java | 1 + .../dolphinemu/overlay/InputOverlay.java | 183 +++++++++++++++++- .../app/src/main/res/values/integers.xml | 80 ++++++++ .../app/src/main/res/values/strings.xml | 1 + 4 files changed, 264 insertions(+), 1 deletion(-) 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 ab2f4fefac..f1ea6fe52b 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 @@ -223,6 +223,7 @@ public final class EmulationActivity extends AppCompatActivity }); // Set these options now so that the SurfaceView the game renders into is the right size. enableFullscreenImmersive(); + Toast.makeText(this, getString(R.string.emulation_touch_button_help), Toast.LENGTH_LONG).show(); } else { 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 d3726bf88f..f49e046fdd 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 @@ -6,6 +6,7 @@ package org.dolphinemu.dolphinemu.overlay; +import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.content.res.Resources; @@ -17,6 +18,7 @@ import android.graphics.drawable.Drawable; import android.preference.PreferenceManager; import android.util.AttributeSet; import android.util.DisplayMetrics; +import android.view.Display; import android.view.MotionEvent; import android.view.SurfaceView; import android.view.View; @@ -81,7 +83,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener super(context, attrs); mPreferences = PreferenceManager.getDefaultSharedPreferences(getContext()); - + if(!mPreferences.getBoolean("OverlayInit", false)) + defaultOverlay(); // Load the controls. refreshControls(); @@ -846,4 +849,182 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener { return mIsInEditMode; } + + 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) + { + gcDefaultOverlay(); + } + // Wii + if (mPreferences.getFloat(ButtonType.WIIMOTE_BUTTON_A + "-X", 0f) == 0f) + { + wiiDefaultOverlay(); + } + + // Wii Classic + if (mPreferences.getFloat(ButtonType.CLASSIC_BUTTON_A + "-X", 0f) == 0f) + { + wiiClassicDefaultOverlay(); + } + + SharedPreferences.Editor sPrefsEditor = mPreferences.edit(); + sPrefsEditor.putBoolean("OverlayInit", true); + sPrefsEditor.apply(); + } + + private void gcDefaultOverlay() + { + 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 height. + 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.BUTTON_A + "-X", (((float)res.getInteger(R.integer.BUTTON_A_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.BUTTON_A + "-Y", (((float)res.getInteger(R.integer.BUTTON_A_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.BUTTON_B + "-X", (((float)res.getInteger(R.integer.BUTTON_B_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.BUTTON_B + "-Y", (((float)res.getInteger(R.integer.BUTTON_B_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.BUTTON_X + "-X", (((float)res.getInteger(R.integer.BUTTON_X_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.BUTTON_X + "-Y", (((float)res.getInteger(R.integer.BUTTON_X_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.BUTTON_Y + "-X", (((float)res.getInteger(R.integer.BUTTON_Y_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.BUTTON_Y + "-Y", (((float)res.getInteger(R.integer.BUTTON_Y_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.BUTTON_Z + "-X", (((float)res.getInteger(R.integer.BUTTON_Z_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.BUTTON_Z + "-Y", (((float)res.getInteger(R.integer.BUTTON_Z_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.BUTTON_UP + "-X", (((float)res.getInteger(R.integer.BUTTON_UP_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.BUTTON_UP + "-Y", (((float)res.getInteger(R.integer.BUTTON_UP_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.TRIGGER_L + "-X", (((float)res.getInteger(R.integer.TRIGGER_L_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.TRIGGER_L + "-Y", (((float)res.getInteger(R.integer.TRIGGER_L_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.TRIGGER_R + "-X", (((float)res.getInteger(R.integer.TRIGGER_R_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.TRIGGER_R + "-Y", (((float)res.getInteger(R.integer.TRIGGER_R_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.BUTTON_START + "-X", (((float)res.getInteger(R.integer.BUTTON_START_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.BUTTON_START + "-Y", (((float)res.getInteger(R.integer.BUTTON_START_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.STICK_C + "-X", (((float)res.getInteger(R.integer.STICK_C_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.STICK_C + "-Y", (((float)res.getInteger(R.integer.STICK_C_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.STICK_MAIN + "-X", (((float)res.getInteger(R.integer.STICK_MAIN_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.STICK_MAIN + "-Y", (((float)res.getInteger(R.integer.STICK_MAIN_Y) / 1000) * maxY)); + + // We want to commit right away, otherwise the overlay could load before this is saved. + sPrefsEditor.commit(); + } + + private void wiiDefaultOverlay() + { + 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 + "-X", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_A_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_A + "-Y", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_A_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_B + "-X", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_B_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_B + "-Y", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_B_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_1 + "-X", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_1_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_1 + "-Y", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_1_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_2 + "-X", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_2_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_2 + "-Y", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_2_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.NUNCHUK_BUTTON_Z + "-X", (((float) res.getInteger(R.integer.NUNCHUK_BUTTON_Z_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.NUNCHUK_BUTTON_Z + "-Y", (((float) res.getInteger(R.integer.NUNCHUK_BUTTON_Z_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.NUNCHUK_BUTTON_C + "-X", (((float) res.getInteger(R.integer.NUNCHUK_BUTTON_C_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.NUNCHUK_BUTTON_C + "-Y", (((float) res.getInteger(R.integer.NUNCHUK_BUTTON_C_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_MINUS + "-X", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_MINUS_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_MINUS + "-Y", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_MINUS_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_PLUS + "-X", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_PLUS_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_PLUS + "-Y", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_PLUS_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_UP + "-X", (((float) res.getInteger(R.integer.WIIMOTE_UP_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_UP + "-Y", (((float) res.getInteger(R.integer.WIIMOTE_UP_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_HOME + "-X", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_HOME_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_BUTTON_HOME + "-Y", (((float) res.getInteger(R.integer.WIIMOTE_BUTTON_HOME_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.NUNCHUK_STICK + "-X", (((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)); + // Horizontal dpad + sPrefsEditor.putFloat(ButtonType.WIIMOTE_RIGHT + "-X", (((float) res.getInteger(R.integer.WIIMOTE_RIGHT_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.WIIMOTE_RIGHT + "-Y", (((float) res.getInteger(R.integer.WIIMOTE_RIGHT_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(); + + // 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.CLASSIC_BUTTON_A + "-X", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_A_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_A + "-Y", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_A_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_B + "-X", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_B_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_B + "-Y", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_B_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_X + "-X", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_X_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_X + "-Y", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_X_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_Y + "-X", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_Y_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_Y + "-Y", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_Y_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_MINUS + "-X", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_MINUS_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_MINUS + "-Y", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_MINUS_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_PLUS + "-X", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_PLUS_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_PLUS + "-Y", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_PLUS_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_HOME + "-X", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_HOME_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_HOME + "-Y", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_HOME_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_ZL + "-X", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_ZL_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_ZL + "-Y", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_ZL_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_ZR + "-X", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_ZR_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_BUTTON_ZR + "-Y", (((float)res.getInteger(R.integer.CLASSIC_BUTTON_ZR_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_DPAD_UP + "-X", (((float)res.getInteger(R.integer.CLASSIC_DPAD_UP_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_DPAD_UP + "-Y", (((float)res.getInteger(R.integer.CLASSIC_DPAD_UP_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_STICK_LEFT + "-X", (((float)res.getInteger(R.integer.CLASSIC_STICK_LEFT_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_STICK_LEFT + "-Y", (((float)res.getInteger(R.integer.CLASSIC_STICK_LEFT_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_STICK_RIGHT + "-X", (((float)res.getInteger(R.integer.CLASSIC_STICK_RIGHT_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_STICK_RIGHT + "-Y", (((float)res.getInteger(R.integer.CLASSIC_STICK_RIGHT_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_TRIGGER_L + "-X", (((float)res.getInteger(R.integer.CLASSIC_TRIGGER_L_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_TRIGGER_L + "-Y", (((float)res.getInteger(R.integer.CLASSIC_TRIGGER_L_Y) / 1000) * maxY)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_TRIGGER_R + "-X", (((float)res.getInteger(R.integer.CLASSIC_TRIGGER_R_X) / 1000) * maxX)); + sPrefsEditor.putFloat(ButtonType.CLASSIC_TRIGGER_R + "-Y", (((float)res.getInteger(R.integer.CLASSIC_TRIGGER_R_Y) / 1000) * maxY)); + + // We want to commit right away, otherwise the overlay could load before this is saved. + sPrefsEditor.commit(); + } } diff --git a/Source/Android/app/src/main/res/values/integers.xml b/Source/Android/app/src/main/res/values/integers.xml index 9ddac4cff1..131c9d05f3 100644 --- a/Source/Android/app/src/main/res/values/integers.xml +++ b/Source/Android/app/src/main/res/values/integers.xml @@ -1,4 +1,84 @@ 1 + + + 865 + 652 + 785 + 524 + 896 + 388 + 784 + 297 + 131 + 431 + 222 + 629 + 13 + 330 + 845 + 133 + 506 + 818 + 686 + 676 + 17 + 620 + + + 858 + 772 + 850 + 460 + 778 + 715 + 778 + 864 + 850 + 208 + 681 + 765 + 787 + 578 + 701 + 630 + 224 + 652 + 514 + 854 + 51 + 681 + + 100 + 683 + + 860 + 688 + 787 + 806 + 932 + 523 + 823 + 522 + 420 + 870 + 580 + 870 + 500 + 834 + 19 + 223 + 897 + 263 + 203 + 680 + 23 + 622 + 636 + 655 + 124 + 429 + 737 + 311 \ 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 1b7d1822ab..e22775ad0b 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -269,6 +269,7 @@ Relative Stick Center Choose Controller You may have to reload the game after changing extensions. + To change the button layout, open the menu -> Configure Controls -> Edit Layout Enable Vibration