Merge pull request #7723 from zackhow/newcale

Android: Wiimote only(no nunchuck) overlay upgrades
This commit is contained in:
JMC47 2019-02-25 11:48:05 -05:00 committed by GitHub
commit fa685afd77
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 233 additions and 36 deletions

View File

@ -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;
@ -58,6 +59,24 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
private SharedPreferences mPreferences;
// Buttons that have special positions in Wiimote only
private static final ArrayList<Integer> 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<Integer> WIIMOTE_O_BUTTONS = new ArrayList<>();
static
{
WIIMOTE_O_BUTTONS.add(ButtonType.WIIMOTE_UP);
}
/**
* Resizes a {@link Bitmap} by a given scale factor
*
@ -90,7 +109,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.
@ -726,9 +745,15 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
else
{
if (isLandscape)
{
wiiDefaultOverlay();
wiiOnlyDefaultOverlay();
}
else
{
wiiPortraitDefaultOverlay();
wiiOnlyPortraitDefaultOverlay();
}
}
refreshControls();
}
@ -780,6 +805,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;
@ -805,6 +831,9 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
break;
case ButtonType.WIIMOTE_BUTTON_1:
case ButtonType.WIIMOTE_BUTTON_2:
if (controller == 2)
scale = 0.14f;
else
scale = 0.0875f;
break;
case ButtonType.WIIMOTE_BUTTON_PLUS:
@ -839,8 +868,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();
@ -883,6 +931,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;
@ -896,6 +945,9 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
scale = 0.275f;
break;
default:
if (controller == 2 || controller == 1)
scale = 0.275f;
else
scale = 0.2125f;
break;
}
@ -919,8 +971,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();
@ -1012,6 +1082,8 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
}
private void defaultOverlay()
{
if (!mPreferences.getBoolean("OverlayInitV2", false))
{
// 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.
@ -1044,9 +1116,17 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
{
wiiClassicPortraitDefaultOverlay();
}
}
if (!mPreferences.getBoolean("OverlayInitV3", false))
{
wiiOnlyDefaultOverlay();
wiiOnlyPortraitDefaultOverlay();
}
SharedPreferences.Editor sPrefsEditor = mPreferences.edit();
sPrefsEditor.putBoolean("OverlayInitV2", true);
sPrefsEditor.putBoolean("OverlayInitV3", true);
sPrefsEditor.apply();
}
@ -1257,6 +1337,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));
@ -1343,6 +1470,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();
@ -1425,7 +1599,6 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
sPrefsEditor.commit();
}
private void wiiClassicPortraitDefaultOverlay()
{
SharedPreferences.Editor sPrefsEditor = mPreferences.edit();

View File

@ -74,8 +74,21 @@
<integer name="NUNCHUK_STICK_X">51</integer>
<integer name="NUNCHUK_STICK_Y">681</integer>
<integer name="WIIMOTE_RIGHT_X">100</integer>
<integer name="WIIMOTE_RIGHT_Y">683</integer>
<!-- Wiimote only -->
<integer name="WIIMOTE_O_UP_X">48</integer>
<integer name="WIIMOTE_O_UP_Y">652</integer>
<!-- Horizontal Wiimote -->
<integer name="WIIMOTE_RIGHT_X">48</integer>
<integer name="WIIMOTE_RIGHT_Y">187</integer>
<integer name="WIIMOTE_H_BUTTON_A_X">890</integer>
<integer name="WIIMOTE_H_BUTTON_A_Y">734</integer>
<integer name="WIIMOTE_H_BUTTON_B_X">731</integer>
<integer name="WIIMOTE_H_BUTTON_B_Y">715</integer>
<integer name="WIIMOTE_H_BUTTON_1_X">867</integer>
<integer name="WIIMOTE_H_BUTTON_1_Y">303</integer>
<integer name="WIIMOTE_H_BUTTON_2_X">925</integer>
<integer name="WIIMOTE_H_BUTTON_2_Y">103</integer>
<!-- Default Wii portrait layout -->
<integer name="WIIMOTE_BUTTON_A_PORTRAIT_X">769</integer>
@ -104,6 +117,17 @@
<integer name="WIIMOTE_RIGHT_PORTRAIT_X">68</integer>
<integer name="WIIMOTE_RIGHT_PORTRAIT_Y">602</integer>
<integer name="WIIMOTE_H_BUTTON_A_PORTRAIT_X">769</integer>
<integer name="WIIMOTE_H_BUTTON_A_PORTRAIT_Y">584</integer>
<integer name="WIIMOTE_H_BUTTON_B_PORTRAIT_X">553</integer>
<integer name="WIIMOTE_H_BUTTON_B_PORTRAIT_Y">621</integer>
<integer name="WIIMOTE_H_BUTTON_1_PORTRAIT_X">707</integer>
<integer name="WIIMOTE_H_BUTTON_1_PORTRAIT_Y">742</integer>
<integer name="WIIMOTE_H_BUTTON_2_PORTRAIT_X">846</integer>
<integer name="WIIMOTE_H_BUTTON_2_PORTRAIT_Y">692</integer>
<integer name="WIIMOTE_O_UP_PORTRAIT_X">260</integer>
<integer name="WIIMOTE_O_UP_PORTRAIT_Y">773</integer>
<!-- Default Wii classic landscape layout -->
<integer name="CLASSIC_BUTTON_A_X">860</integer>
<integer name="CLASSIC_BUTTON_A_Y">688</integer>