Merge pull request #10790 from JosJuice/android-wii-controller-magic

Android: Refactor reading "wiiController" preference
This commit is contained in:
Mai 2022-08-03 20:21:11 -04:00 committed by GitHub
commit 098fc8cadc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 24 deletions

View File

@ -270,9 +270,7 @@ public final class EmulationActivity extends AppCompatActivity
public static void updateWiimoteNewIniPreferences(Context context) public static void updateWiimoteNewIniPreferences(Context context)
{ {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context); updateWiimoteNewController(InputOverlay.getConfiguredControllerType(context), context);
updateWiimoteNewController(preferences.getInt("wiiController", 3), context);
updateWiimoteNewImuIr(IntSetting.MAIN_MOTION_CONTROLS.getIntGlobal()); updateWiimoteNewImuIr(IntSetting.MAIN_MOTION_CONTROLS.getIntGlobal());
} }
@ -820,7 +818,10 @@ public final class EmulationActivity extends AppCompatActivity
{ {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.emulation_toggle_controls); builder.setTitle(R.string.emulation_toggle_controls);
if (!NativeLibrary.IsEmulatingWii() || mPreferences.getInt("wiiController", 3) == 0)
int currentController = InputOverlay.getConfiguredControllerType(this);
if (!NativeLibrary.IsEmulatingWii() || currentController == InputOverlay.OVERLAY_GAMECUBE)
{ {
boolean[] gcEnabledButtons = new boolean[11]; boolean[] gcEnabledButtons = new boolean[11];
String gcSettingBase = "MAIN_BUTTON_TOGGLE_GC_"; String gcSettingBase = "MAIN_BUTTON_TOGGLE_GC_";
@ -833,7 +834,7 @@ public final class EmulationActivity extends AppCompatActivity
(dialog, indexSelected, isChecked) -> BooleanSetting (dialog, indexSelected, isChecked) -> BooleanSetting
.valueOf(gcSettingBase + indexSelected).setBoolean(mSettings, isChecked)); .valueOf(gcSettingBase + indexSelected).setBoolean(mSettings, isChecked));
} }
else if (mPreferences.getInt("wiiController", 3) == 4) else if (currentController == InputOverlay.OVERLAY_WIIMOTE_CLASSIC)
{ {
boolean[] wiiClassicEnabledButtons = new boolean[14]; boolean[] wiiClassicEnabledButtons = new boolean[14];
String classicSettingBase = "MAIN_BUTTON_TOGGLE_CLASSIC_"; String classicSettingBase = "MAIN_BUTTON_TOGGLE_CLASSIC_";
@ -857,7 +858,7 @@ public final class EmulationActivity extends AppCompatActivity
{ {
wiiEnabledButtons[i] = BooleanSetting.valueOf(wiiSettingBase + i).getBoolean(mSettings); wiiEnabledButtons[i] = BooleanSetting.valueOf(wiiSettingBase + i).getBoolean(mSettings);
} }
if (mPreferences.getInt("wiiController", 3) == 3) if (currentController == InputOverlay.OVERLAY_WIIMOTE_NUNCHUK)
{ {
builder.setMultiChoiceItems(R.array.nunchukButtons, wiiEnabledButtons, builder.setMultiChoiceItems(R.array.nunchukButtons, wiiEnabledButtons,
(dialog, indexSelected, isChecked) -> BooleanSetting (dialog, indexSelected, isChecked) -> BooleanSetting
@ -870,6 +871,7 @@ public final class EmulationActivity extends AppCompatActivity
.valueOf(wiiSettingBase + indexSelected).setBoolean(mSettings, isChecked)); .valueOf(wiiSettingBase + indexSelected).setBoolean(mSettings, isChecked));
} }
} }
builder.setNeutralButton(R.string.emulation_toggle_all, builder.setNeutralButton(R.string.emulation_toggle_all,
(dialogInterface, i) -> mEmulationFragment.toggleInputOverlayVisibility(mSettings)); (dialogInterface, i) -> mEmulationFragment.toggleInputOverlayVisibility(mSettings));
builder.setPositiveButton(R.string.ok, (dialogInterface, i) -> builder.setPositiveButton(R.string.ok, (dialogInterface, i) ->
@ -882,13 +884,10 @@ public final class EmulationActivity extends AppCompatActivity
{ {
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
int currentController =
mPreferences.getInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK);
int currentValue = IntSetting.MAIN_DOUBLE_TAP_BUTTON.getInt(mSettings); int currentValue = IntSetting.MAIN_DOUBLE_TAP_BUTTON.getInt(mSettings);
int buttonList = currentController == InputOverlay.OVERLAY_WIIMOTE_CLASSIC ? int buttonList = InputOverlay.getConfiguredControllerType(this) ==
R.array.doubleTapWithClassic : R.array.doubleTap; InputOverlay.OVERLAY_WIIMOTE_CLASSIC ? R.array.doubleTapWithClassic : R.array.doubleTap;
int checkedItem = -1; int checkedItem = -1;
int itemCount = getResources().getStringArray(buttonList).length; int itemCount = getResources().getStringArray(buttonList).length;
@ -991,7 +990,7 @@ public final class EmulationActivity extends AppCompatActivity
AlertDialog.Builder builder = new AlertDialog.Builder(this); AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.emulation_choose_controller); builder.setTitle(R.string.emulation_choose_controller);
builder.setSingleChoiceItems(R.array.controllersEntries, builder.setSingleChoiceItems(R.array.controllersEntries,
mPreferences.getInt("wiiController", 3), InputOverlay.getConfiguredControllerType(this),
(dialog, indexSelected) -> (dialog, indexSelected) ->
{ {
editor.putInt("wiiController", indexSelected); editor.putInt("wiiController", indexSelected);

View File

@ -157,8 +157,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
int doubleTapButton = IntSetting.MAIN_DOUBLE_TAP_BUTTON.getIntGlobal(); int doubleTapButton = IntSetting.MAIN_DOUBLE_TAP_BUTTON.getIntGlobal();
if (mPreferences.getInt("wiiController", OVERLAY_WIIMOTE_NUNCHUK) != if (getConfiguredControllerType() != InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
doubleTapButton == InputOverlayPointer.DOUBLE_TAP_CLASSIC_A) doubleTapButton == InputOverlayPointer.DOUBLE_TAP_CLASSIC_A)
{ {
doubleTapButton = InputOverlayPointer.DOUBLE_TAP_A; doubleTapButton = InputOverlayPointer.DOUBLE_TAP_A;
@ -345,8 +344,7 @@ 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 = getConfiguredControllerType();
int controller = sPrefs.getInt("wiiController", 3);
String orientation = String orientation =
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ? getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ?
"-Portrait" : ""; "-Portrait" : "";
@ -745,7 +743,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
} }
else else
{ {
switch (mPreferences.getInt("wiiController", 3)) switch (getConfiguredControllerType())
{ {
case OVERLAY_GAMECUBE: case OVERLAY_GAMECUBE:
addGameCubeOverlayControls(orientation); addGameCubeOverlayControls(orientation);
@ -789,14 +787,14 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE; getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
// Values for these come from R.array.controllersEntries // Values for these come from R.array.controllersEntries
if (!NativeLibrary.IsEmulatingWii() || mPreferences.getInt("wiiController", 3) == 0) if (!NativeLibrary.IsEmulatingWii() || getConfiguredControllerType() == OVERLAY_GAMECUBE)
{ {
if (isLandscape) if (isLandscape)
gcDefaultOverlay(); gcDefaultOverlay();
else else
gcPortraitDefaultOverlay(); gcPortraitDefaultOverlay();
} }
else if (mPreferences.getInt("wiiController", 3) == 4) else if (getConfiguredControllerType() == OVERLAY_WIIMOTE_CLASSIC)
{ {
if (isLandscape) if (isLandscape)
wiiClassicDefaultOverlay(); wiiClassicDefaultOverlay();
@ -819,6 +817,17 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
refreshControls(); refreshControls();
} }
public static int getConfiguredControllerType(Context context)
{
return PreferenceManager.getDefaultSharedPreferences(context)
.getInt("wiiController", OVERLAY_WIIMOTE_NUNCHUK);
}
private int getConfiguredControllerType()
{
return mPreferences.getInt("wiiController", OVERLAY_WIIMOTE_NUNCHUK);
}
private void saveControlPosition(int sharedPrefsId, int x, int y, int controller, private void saveControlPosition(int sharedPrefsId, int x, int y, int controller,
String orientation) String orientation)
{ {
@ -831,11 +840,11 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
private static String getKey(int sharedPrefsId, int controller, String orientation, String suffix) private static String getKey(int sharedPrefsId, int controller, String orientation, String suffix)
{ {
if (controller == 2 && WIIMOTE_H_BUTTONS.contains(sharedPrefsId)) if (controller == OVERLAY_WIIMOTE_SIDEWAYS && WIIMOTE_H_BUTTONS.contains(sharedPrefsId))
{ {
return sharedPrefsId + "_H" + orientation + suffix; return sharedPrefsId + "_H" + orientation + suffix;
} }
else if (controller == 1 && WIIMOTE_O_BUTTONS.contains(sharedPrefsId)) else if (controller == OVERLAY_WIIMOTE && WIIMOTE_O_BUTTONS.contains(sharedPrefsId))
{ {
return sharedPrefsId + "_O" + orientation + suffix; return sharedPrefsId + "_O" + orientation + suffix;
} }
@ -893,7 +902,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableButton. // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableButton.
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
int controller = sPrefs.getInt("wiiController", 3); int controller = getConfiguredControllerType(context);
// Decide scale based on button ID and user preference // Decide scale based on button ID and user preference
float scale; float scale;
@ -1001,7 +1010,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableDpad. // SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableDpad.
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context); final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
int controller = sPrefs.getInt("wiiController", 3); int controller = getConfiguredControllerType(context);
// Decide scale based on button ID and user preference // Decide scale based on button ID and user preference
float scale; float scale;
@ -1076,7 +1085,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); int controller = getConfiguredControllerType(context);
// Decide scale based on user preference // Decide scale based on user preference
float scale = 0.275f; float scale = 0.275f;