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)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
updateWiimoteNewController(preferences.getInt("wiiController", 3), context);
updateWiimoteNewController(InputOverlay.getConfiguredControllerType(context), context);
updateWiimoteNewImuIr(IntSetting.MAIN_MOTION_CONTROLS.getIntGlobal());
}
@ -820,7 +818,10 @@ public final class EmulationActivity extends AppCompatActivity
{
AlertDialog.Builder builder = new AlertDialog.Builder(this);
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];
String gcSettingBase = "MAIN_BUTTON_TOGGLE_GC_";
@ -833,7 +834,7 @@ public final class EmulationActivity extends AppCompatActivity
(dialog, indexSelected, isChecked) -> BooleanSetting
.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];
String classicSettingBase = "MAIN_BUTTON_TOGGLE_CLASSIC_";
@ -857,7 +858,7 @@ public final class EmulationActivity extends AppCompatActivity
{
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,
(dialog, indexSelected, isChecked) -> BooleanSetting
@ -870,6 +871,7 @@ public final class EmulationActivity extends AppCompatActivity
.valueOf(wiiSettingBase + indexSelected).setBoolean(mSettings, isChecked));
}
}
builder.setNeutralButton(R.string.emulation_toggle_all,
(dialogInterface, i) -> mEmulationFragment.toggleInputOverlayVisibility(mSettings));
builder.setPositiveButton(R.string.ok, (dialogInterface, i) ->
@ -882,13 +884,10 @@ public final class EmulationActivity extends AppCompatActivity
{
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 buttonList = currentController == InputOverlay.OVERLAY_WIIMOTE_CLASSIC ?
R.array.doubleTapWithClassic : R.array.doubleTap;
int buttonList = InputOverlay.getConfiguredControllerType(this) ==
InputOverlay.OVERLAY_WIIMOTE_CLASSIC ? R.array.doubleTapWithClassic : R.array.doubleTap;
int checkedItem = -1;
int itemCount = getResources().getStringArray(buttonList).length;
@ -991,7 +990,7 @@ public final class EmulationActivity extends AppCompatActivity
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle(R.string.emulation_choose_controller);
builder.setSingleChoiceItems(R.array.controllersEntries,
mPreferences.getInt("wiiController", 3),
InputOverlay.getConfiguredControllerType(this),
(dialog, 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();
if (mPreferences.getInt("wiiController", OVERLAY_WIIMOTE_NUNCHUK) !=
InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
if (getConfiguredControllerType() != InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
doubleTapButton == InputOverlayPointer.DOUBLE_TAP_CLASSIC_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 fingerPositionY = (int) event.getY(pointerIndex);
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
int controller = sPrefs.getInt("wiiController", 3);
int controller = getConfiguredControllerType();
String orientation =
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ?
"-Portrait" : "";
@ -745,7 +743,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
}
else
{
switch (mPreferences.getInt("wiiController", 3))
switch (getConfiguredControllerType())
{
case OVERLAY_GAMECUBE:
addGameCubeOverlayControls(orientation);
@ -789,14 +787,14 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
// Values for these come from R.array.controllersEntries
if (!NativeLibrary.IsEmulatingWii() || mPreferences.getInt("wiiController", 3) == 0)
if (!NativeLibrary.IsEmulatingWii() || getConfiguredControllerType() == OVERLAY_GAMECUBE)
{
if (isLandscape)
gcDefaultOverlay();
else
gcPortraitDefaultOverlay();
}
else if (mPreferences.getInt("wiiController", 3) == 4)
else if (getConfiguredControllerType() == OVERLAY_WIIMOTE_CLASSIC)
{
if (isLandscape)
wiiClassicDefaultOverlay();
@ -819,6 +817,17 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
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,
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)
{
if (controller == 2 && WIIMOTE_H_BUTTONS.contains(sharedPrefsId))
if (controller == OVERLAY_WIIMOTE_SIDEWAYS && WIIMOTE_H_BUTTONS.contains(sharedPrefsId))
{
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;
}
@ -893,7 +902,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);
int controller = getConfiguredControllerType(context);
// Decide scale based on button ID and user preference
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.
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
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.
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
int controller = sPrefs.getInt("wiiController", 3);
int controller = getConfiguredControllerType(context);
// Decide scale based on user preference
float scale = 0.275f;