Android: Wiimote only(no nunchuck) overlay upgrades

Increase some button sizes
Create new defaults for Wiimote only and horizontal wiimote
This commit is contained in:
zackhow 2019-01-11 19:40:20 -05:00
parent d3e1d2ea00
commit 10238b45a4
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;
@ -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<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
*
@ -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();

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>