Android: Change how the overlay controller setting works

Up until now, there have been two settings on Android that stored the
selected Wii Remote extension: the normal one that's also used on PC,
and a SharedPreferences one that's used by the overlay controls to
determine what controls to show. It is possible for these two to end up
out of sync, and my input changes have made that more likely to happen.

To fix this, let's rework how the overlay controller setting works.
We don't want it to encode the currently selected Wii Remote extension.
However, we can't simply get rid of the setting, because for some Wii
games we need the ability to switch between a GameCube controller and a
Wii Remote. What this commit does is give the user the option to select
any of the 4 GameCube controllers and any of the 4 Wii Remotes. (Before,
controllers 2-4 weren't available in the overlay.) Could be useful for
things like the Psycho Mantis fight in Metal Gear Solid. I'm also
switching from SharedPreferences to Dolphin.ini while I'm at it.
This commit is contained in:
JosJuice 2022-06-26 20:27:18 +02:00
parent 4c326f2030
commit 1b55d7c594
17 changed files with 233 additions and 190 deletions

View File

@ -404,8 +404,6 @@ public final class NativeLibrary
*/
public static native void RefreshWiimotes();
public static native void ReloadWiimoteConfig();
public static native LinkedHashMap<String, String> GetLogTypeNames();
public static native void ReloadLoggerConfig();

View File

@ -2,7 +2,6 @@
package org.dolphinemu.dolphinemu.activities;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.SharedPreferences;
@ -48,7 +47,6 @@ import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivity;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.features.skylanders.SkylanderConfig;
import org.dolphinemu.dolphinemu.features.skylanders.model.Skylander;
import org.dolphinemu.dolphinemu.features.skylanders.ui.SkylanderSlot;
@ -62,10 +60,8 @@ import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.ui.main.ThemeProvider;
import org.dolphinemu.dolphinemu.utils.AfterDirectoryInitializationRunner;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.IniFile;
import org.dolphinemu.dolphinemu.utils.ThemeHelper;
import java.io.File;
import java.lang.annotation.Retention;
import java.util.ArrayList;
import java.util.List;
@ -290,21 +286,6 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
sIgnoreLaunchRequests = false;
}
public static void updateWiimoteNewIniPreferences(Context context)
{
updateWiimoteNewController(InputOverlay.getConfiguredControllerType(context), context);
}
private static void updateWiimoteNewController(int value, Context context)
{
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
wiimoteNewIni.setString("Wiimote1", "Extension",
context.getResources().getStringArray(R.array.controllersValues)[value]);
wiimoteNewIni.setBoolean("Wiimote1", "Options/Sideways Wiimote", value == 2);
wiimoteNewIni.save(wiimoteNewFile);
}
@Override
protected void onCreate(Bundle savedInstanceState)
{
@ -456,7 +437,7 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
setTitle(NativeLibrary.GetCurrentTitleDescription());
mEmulationFragment.refreshInputOverlay();
mEmulationFragment.refreshInputOverlay(mSettings);
}
@Override
@ -680,7 +661,7 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
adjustScale();
break;
// (Wii games only) Change the controller for the input overlay.
// Change the controller for the input overlay.
case MENU_ACTION_CHOOSE_CONTROLLER:
chooseController();
break;
@ -850,9 +831,9 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this)
.setTitle(R.string.emulation_toggle_controls);
int currentController = InputOverlay.getConfiguredControllerType(this);
int currentController = InputOverlay.getConfiguredControllerType(mSettings);
if (!NativeLibrary.IsEmulatingWii() || currentController == InputOverlay.OVERLAY_GAMECUBE)
if (currentController == InputOverlay.OVERLAY_GAMECUBE)
{
boolean[] gcEnabledButtons = new boolean[11];
String gcSettingBase = "MAIN_BUTTON_TOGGLE_GC_";
@ -906,7 +887,7 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
builder.setNeutralButton(R.string.emulation_toggle_all,
(dialogInterface, i) -> mEmulationFragment.toggleInputOverlayVisibility(mSettings))
.setPositiveButton(R.string.ok, (dialogInterface, i) ->
mEmulationFragment.refreshInputOverlay())
mEmulationFragment.refreshInputOverlay(mSettings))
.show();
}
@ -914,7 +895,7 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
{
int currentValue = IntSetting.MAIN_DOUBLE_TAP_BUTTON.getInt(mSettings);
int buttonList = InputOverlay.getConfiguredControllerType(this) ==
int buttonList = InputOverlay.getConfiguredControllerType(mSettings) ==
InputOverlay.OVERLAY_WIIMOTE_CLASSIC ? R.array.doubleTapWithClassic : R.array.doubleTap;
int checkedItem = -1;
@ -933,7 +914,7 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
(DialogInterface dialog, int which) -> IntSetting.MAIN_DOUBLE_TAP_BUTTON.setInt(
mSettings, InputOverlayPointer.DOUBLE_TAP_OPTIONS.get(which)))
.setPositiveButton(R.string.ok,
(dialogInterface, i) -> mEmulationFragment.initInputPointer())
(dialogInterface, i) -> mEmulationFragment.initInputPointer(mSettings))
.show();
}
@ -967,35 +948,72 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
{
IntSetting.MAIN_CONTROL_SCALE.setInt(mSettings, (int) scaleSlider.getValue());
IntSetting.MAIN_CONTROL_OPACITY.setInt(mSettings, (int) sliderOpacity.getValue());
mEmulationFragment.refreshInputOverlay();
mEmulationFragment.refreshInputOverlay(mSettings);
})
.setNeutralButton(R.string.default_values, (dialog, which) ->
{
IntSetting.MAIN_CONTROL_SCALE.delete(mSettings);
IntSetting.MAIN_CONTROL_OPACITY.delete(mSettings);
mEmulationFragment.refreshInputOverlay();
mEmulationFragment.refreshInputOverlay(mSettings);
})
.show();
}
private void addControllerIfNotNone(List<CharSequence> entries, List<Integer> values,
IntSetting controller, int entry, int value)
{
if (controller.getInt(mSettings) != 0)
{
entries.add(getString(entry));
values.add(value);
}
}
private void chooseController()
{
ArrayList<CharSequence> entries = new ArrayList<>();
ArrayList<Integer> values = new ArrayList<>();
entries.add(getString(R.string.none));
values.add(-1);
addControllerIfNotNone(entries, values, IntSetting.MAIN_SI_DEVICE_0, R.string.controller_0, 0);
addControllerIfNotNone(entries, values, IntSetting.MAIN_SI_DEVICE_1, R.string.controller_1, 1);
addControllerIfNotNone(entries, values, IntSetting.MAIN_SI_DEVICE_2, R.string.controller_2, 2);
addControllerIfNotNone(entries, values, IntSetting.MAIN_SI_DEVICE_3, R.string.controller_3, 3);
if (NativeLibrary.IsEmulatingWii())
{
addControllerIfNotNone(entries, values, IntSetting.WIIMOTE_1_SOURCE, R.string.wiimote_0, 4);
addControllerIfNotNone(entries, values, IntSetting.WIIMOTE_2_SOURCE, R.string.wiimote_1, 5);
addControllerIfNotNone(entries, values, IntSetting.WIIMOTE_3_SOURCE, R.string.wiimote_2, 6);
addControllerIfNotNone(entries, values, IntSetting.WIIMOTE_4_SOURCE, R.string.wiimote_3, 7);
}
IntSetting controllerSetting = NativeLibrary.IsEmulatingWii() ?
IntSetting.MAIN_OVERLAY_WII_CONTROLLER : IntSetting.MAIN_OVERLAY_GC_CONTROLLER;
int currentValue = controllerSetting.getInt(mSettings);
int checkedItem = -1;
for (int i = 0; i < values.size(); i++)
{
if (values.get(i) == currentValue)
{
checkedItem = i;
break;
}
}
final SharedPreferences.Editor editor = mPreferences.edit();
new MaterialAlertDialogBuilder(this)
.setTitle(R.string.emulation_choose_controller)
.setSingleChoiceItems(R.array.controllersEntries,
InputOverlay.getConfiguredControllerType(this),
.setSingleChoiceItems(entries.toArray(new CharSequence[]{}), checkedItem,
(dialog, indexSelected) ->
{
editor.putInt("wiiController", indexSelected);
updateWiimoteNewController(indexSelected, this);
NativeLibrary.ReloadWiimoteConfig();
})
controllerSetting.setInt(mSettings, values.get(indexSelected)))
.setPositiveButton(R.string.ok, (dialogInterface, i) ->
{
editor.apply();
mEmulationFragment.refreshInputOverlay();
mEmulationFragment.refreshInputOverlay(mSettings);
})
.show();
}
@ -1045,7 +1063,7 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
new MaterialAlertDialogBuilder(this)
.setTitle(getString(R.string.emulation_touch_overlay_reset))
.setPositiveButton(R.string.yes,
(dialogInterface, i) -> mEmulationFragment.resetInputOverlay())
(dialogInterface, i) -> mEmulationFragment.resetInputOverlay(mSettings))
.setNegativeButton(R.string.cancel, null)
.show();
}
@ -1140,7 +1158,7 @@ public final class EmulationActivity extends AppCompatActivity implements ThemeP
public void initInputPointer()
{
mEmulationFragment.initInputPointer();
mEmulationFragment.initInputPointer(mSettings);
}
@Override

View File

@ -45,4 +45,8 @@ public class EmulatedController
public static native EmulatedController getWiimoteAttachment(int controllerIndex,
int attachmentIndex);
public static native int getSelectedWiimoteAttachment(int controllerIndex);
public static native NumericSetting getSidewaysWiimoteSetting(int controllerIndex);
}

View File

@ -33,6 +33,10 @@ public enum IntSetting implements AbstractIntSetting
MAIN_AUDIO_VOLUME(Settings.FILE_DOLPHIN, Settings.SECTION_INI_DSP, "Volume", 100),
MAIN_OVERLAY_GC_CONTROLLER(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID,
"OverlayGCController", 0), // Defaults to GameCube controller 1
MAIN_OVERLAY_WII_CONTROLLER(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID,
"OverlayWiiController", 4), // Defaults to Wii Remote 1
MAIN_CONTROL_SCALE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "ControlScale", 50),
MAIN_CONTROL_OPACITY(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "ControlOpacity", 65),
MAIN_EMULATION_ORIENTATION(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID,
@ -188,4 +192,16 @@ public enum IntSetting implements AbstractIntSetting
{
NativeConfig.setInt(layer, mFile, mSection, mKey, newValue);
}
public static IntSetting getSettingForSIDevice(int channel)
{
return new IntSetting[]{MAIN_SI_DEVICE_0, MAIN_SI_DEVICE_1, MAIN_SI_DEVICE_2, MAIN_SI_DEVICE_3}
[channel];
}
public static IntSetting getSettingForWiimoteSource(int index)
{
return new IntSetting[]{WIIMOTE_1_SOURCE, WIIMOTE_2_SOURCE, WIIMOTE_3_SOURCE, WIIMOTE_4_SOURCE,
WIIMOTE_BB_SOURCE}[index];
}
}

View File

@ -20,8 +20,6 @@ public final class SettingsFile
public static final String KEY_ISO_PATH_BASE = "ISOPath";
public static final String KEY_ISO_PATHS = "ISOPaths";
public static final String KEY_GCPAD_PLAYER_1 = "SIDevice0";
private static BiMap<String, String> sectionsMap = new BiMap<>();
static

View File

@ -115,7 +115,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
{
int overlayX = mInputOverlay.getLeft();
int overlayY = mInputOverlay.getTop();
mInputOverlay.setSurfacePosition(new Rect(
mInputOverlay.setSurfacePosition(activity.getSettings(), new Rect(
surfaceView.getLeft() - overlayX, surfaceView.getTop() - overlayY,
surfaceView.getRight() - overlayX, surfaceView.getBottom() - overlayY));
});
@ -135,7 +135,7 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
super.onResume();
if (mInputOverlay != null && NativeLibrary.IsGameMetadataValid())
mInputOverlay.refreshControls();
mInputOverlay.refreshControls(activity.getSettings());
run(activity.isActivityRecreated());
}
@ -174,19 +174,19 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
.setBoolean(settings, !BooleanSetting.MAIN_SHOW_INPUT_OVERLAY.getBoolean(settings));
if (mInputOverlay != null)
mInputOverlay.refreshControls();
mInputOverlay.refreshControls(settings);
}
public void initInputPointer()
public void initInputPointer(Settings settings)
{
if (mInputOverlay != null)
mInputOverlay.initTouchPointer();
mInputOverlay.initTouchPointer(settings);
}
public void refreshInputOverlay()
public void refreshInputOverlay(Settings settings)
{
if (mInputOverlay != null)
mInputOverlay.refreshControls();
mInputOverlay.refreshControls(settings);
}
public void refreshOverlayPointer(Settings settings)
@ -195,10 +195,10 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
mInputOverlay.refreshOverlayPointer(settings);
}
public void resetInputOverlay()
public void resetInputOverlay(Settings settings)
{
if (mInputOverlay != null)
mInputOverlay.resetButtonPlacement();
mInputOverlay.resetButtonPlacement(settings);
}
@Override

View File

@ -29,13 +29,14 @@ import androidx.preference.PreferenceManager;
import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.NativeLibrary.ButtonType;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.input.model.InputMappingBooleanSetting;
import org.dolphinemu.dolphinemu.features.input.model.InputOverrider;
import org.dolphinemu.dolphinemu.features.input.model.InputOverrider.ControlId;
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.EmulatedController;
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.NumericSetting;
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.utils.IniFile;
import java.util.ArrayList;
import java.util.HashSet;
@ -69,6 +70,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
private boolean mGameCubeRegistered = false;
private boolean mWiiRegistered = false;
private boolean mIsInEditMode = false;
private int mControllerType = -1;
private InputOverlayDrawableButton mButtonBeingConfigured;
private InputOverlayDrawableDpad mDpadBeingConfigured;
private InputOverlayDrawableJoystick mJoystickBeingConfigured;
@ -141,13 +143,13 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
requestFocus();
}
public void setSurfacePosition(Rect rect)
public void setSurfacePosition(Settings settings, Rect rect)
{
mSurfacePosition = rect;
initTouchPointer();
initTouchPointer(settings);
}
public void initTouchPointer()
public void initTouchPointer(Settings settings)
{
// Check if we have all the data we need yet
boolean aspectRatioAvailable = NativeLibrary.IsRunningAndStarted();
@ -160,7 +162,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
int doubleTapButton = IntSetting.MAIN_DOUBLE_TAP_BUTTON.getIntGlobal();
if (getConfiguredControllerType() != InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
if (getConfiguredControllerType(settings) != InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
doubleTapButton == ButtonType.CLASSIC_BUTTON_A)
{
doubleTapButton = ButtonType.WIIMOTE_BUTTON_A;
@ -355,7 +357,6 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
int fingerPositionX = (int) event.getX(pointerIndex);
int fingerPositionY = (int) event.getY(pointerIndex);
int controller = getConfiguredControllerType();
String orientation =
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ?
"-Portrait" : "";
@ -394,7 +395,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// Persist button position by saving new place.
saveControlPosition(mButtonBeingConfigured.getLegacyId(),
mButtonBeingConfigured.getBounds().left,
mButtonBeingConfigured.getBounds().top, controller, orientation);
mButtonBeingConfigured.getBounds().top, orientation);
mButtonBeingConfigured = null;
}
break;
@ -432,7 +433,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
// Persist button position by saving new place.
saveControlPosition(mDpadBeingConfigured.getLegacyId(),
mDpadBeingConfigured.getBounds().left, mDpadBeingConfigured.getBounds().top,
controller, orientation);
orientation);
mDpadBeingConfigured = null;
}
break;
@ -465,7 +466,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
{
saveControlPosition(mJoystickBeingConfigured.getLegacyId(),
mJoystickBeingConfigured.getBounds().left,
mJoystickBeingConfigured.getBounds().top, controller, orientation);
mJoystickBeingConfigured.getBounds().top, orientation);
mJoystickBeingConfigured = null;
}
break;
@ -781,7 +782,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
}
}
public void refreshControls()
public void refreshControls(Settings settings)
{
unregisterControllers();
@ -794,67 +795,52 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT ?
"-Portrait" : "";
mControllerType = getConfiguredControllerType(settings);
if (BooleanSetting.MAIN_SHOW_INPUT_OVERLAY.getBooleanGlobal())
{
// Add all the enabled overlay items back to the HashSet.
if (!NativeLibrary.IsEmulatingWii())
switch (mControllerType)
{
IniFile dolphinIni = new IniFile(SettingsFile.getSettingsFile(Settings.FILE_DOLPHIN));
case OVERLAY_GAMECUBE:
IntSetting controllerSetting = NativeLibrary.IsEmulatingWii() ?
IntSetting.MAIN_OVERLAY_WII_CONTROLLER : IntSetting.MAIN_OVERLAY_GC_CONTROLLER;
int controllerIndex = controllerSetting.getInt(settings);
switch (dolphinIni.getInt(Settings.SECTION_INI_CORE, SettingsFile.KEY_GCPAD_PLAYER_1,
EMULATED_GAMECUBE_CONTROLLER))
{
case DISABLED_GAMECUBE_CONTROLLER:
if (mIsFirstRun)
{
Toast.makeText(getContext(), R.string.disabled_gc_overlay_notice, Toast.LENGTH_SHORT)
.show();
}
break;
if (IntSetting.getSettingForSIDevice(controllerIndex).getInt(settings) ==
DISABLED_GAMECUBE_CONTROLLER && mIsFirstRun)
{
Toast.makeText(getContext(), R.string.disabled_gc_overlay_notice, Toast.LENGTH_SHORT)
.show();
}
case EMULATED_GAMECUBE_CONTROLLER:
InputOverrider.registerGameCube(0);
mGameCubeRegistered = true;
addGameCubeOverlayControls(orientation);
break;
InputOverrider.registerGameCube(0);
mGameCubeRegistered = true;
addGameCubeOverlayControls(orientation);
break;
case GAMECUBE_ADAPTER:
break;
}
}
else
{
switch (getConfiguredControllerType())
{
case OVERLAY_GAMECUBE:
InputOverrider.registerGameCube(0);
mGameCubeRegistered = true;
addGameCubeOverlayControls(orientation);
break;
case OVERLAY_WIIMOTE:
case OVERLAY_WIIMOTE_SIDEWAYS:
InputOverrider.registerWii(0);
mWiiRegistered = true;
addWiimoteOverlayControls(orientation);
break;
case OVERLAY_WIIMOTE:
case OVERLAY_WIIMOTE_SIDEWAYS:
InputOverrider.registerWii(0);
mWiiRegistered = true;
addWiimoteOverlayControls(orientation);
break;
case OVERLAY_WIIMOTE_NUNCHUK:
InputOverrider.registerWii(0);
mWiiRegistered = true;
addWiimoteOverlayControls(orientation);
addNunchukOverlayControls(orientation);
break;
case OVERLAY_WIIMOTE_NUNCHUK:
InputOverrider.registerWii(0);
mWiiRegistered = true;
addWiimoteOverlayControls(orientation);
addNunchukOverlayControls(orientation);
break;
case OVERLAY_WIIMOTE_CLASSIC:
InputOverrider.registerWii(0);
mWiiRegistered = true;
addClassicOverlayControls(orientation);
break;
case OVERLAY_WIIMOTE_CLASSIC:
InputOverrider.registerWii(0);
mWiiRegistered = true;
addClassicOverlayControls(orientation);
break;
case OVERLAY_NONE:
break;
}
case OVERLAY_NONE:
break;
}
}
@ -871,20 +857,20 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
}
}
public void resetButtonPlacement()
public void resetButtonPlacement(Settings settings)
{
boolean isLandscape =
getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
// Values for these come from R.array.controllersEntries
if (!NativeLibrary.IsEmulatingWii() || getConfiguredControllerType() == OVERLAY_GAMECUBE)
final int controller = getConfiguredControllerType(settings);
if (controller == OVERLAY_GAMECUBE)
{
if (isLandscape)
gcDefaultOverlay();
else
gcPortraitDefaultOverlay();
}
else if (getConfiguredControllerType() == OVERLAY_WIIMOTE_CLASSIC)
else if (controller == OVERLAY_WIIMOTE_CLASSIC)
{
if (isLandscape)
wiiClassicDefaultOverlay();
@ -904,27 +890,52 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
wiiOnlyPortraitDefaultOverlay();
}
}
refreshControls();
refreshControls(settings);
}
public static int getConfiguredControllerType(Context context)
public static int getConfiguredControllerType(Settings settings)
{
return PreferenceManager.getDefaultSharedPreferences(context)
.getInt("wiiController", OVERLAY_WIIMOTE_NUNCHUK);
IntSetting controllerSetting = NativeLibrary.IsEmulatingWii() ?
IntSetting.MAIN_OVERLAY_WII_CONTROLLER : IntSetting.MAIN_OVERLAY_GC_CONTROLLER;
int controllerIndex = controllerSetting.getInt(settings);
if (controllerIndex >= 0 && controllerIndex < 4)
{
// GameCube controller
if (IntSetting.getSettingForSIDevice(controllerIndex).getInt(settings) == 6)
return OVERLAY_GAMECUBE;
}
else if (controllerIndex >= 4 && controllerIndex < 8)
{
// Wii Remote
int wiimoteIndex = controllerIndex - 4;
if (IntSetting.getSettingForWiimoteSource(wiimoteIndex).getInt(settings) == 1)
{
int attachmentIndex = EmulatedController.getSelectedWiimoteAttachment(wiimoteIndex);
switch (attachmentIndex)
{
case 1:
return OVERLAY_WIIMOTE_NUNCHUK;
case 2:
return OVERLAY_WIIMOTE_CLASSIC;
}
NumericSetting sidewaysSetting = EmulatedController.getSidewaysWiimoteSetting(wiimoteIndex);
boolean sideways = new InputMappingBooleanSetting(sidewaysSetting).getBoolean(settings);
return sideways ? OVERLAY_WIIMOTE_SIDEWAYS : OVERLAY_WIIMOTE;
}
}
return OVERLAY_NONE;
}
private int getConfiguredControllerType()
{
return mPreferences.getInt("wiiController", OVERLAY_WIIMOTE_NUNCHUK);
}
private void saveControlPosition(int sharedPrefsId, int x, int y, int controller,
String orientation)
private void saveControlPosition(int sharedPrefsId, int x, int y, String orientation)
{
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(getContext());
SharedPreferences.Editor sPrefsEditor = sPrefs.edit();
sPrefsEditor.putFloat(getXKey(sharedPrefsId, controller, orientation), x);
sPrefsEditor.putFloat(getYKey(sharedPrefsId, controller, orientation), y);
sPrefsEditor.putFloat(getXKey(sharedPrefsId, mControllerType, orientation), x);
sPrefsEditor.putFloat(getYKey(sharedPrefsId, mControllerType, orientation), y);
sPrefsEditor.apply();
}
@ -985,7 +996,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
* @param control Control identifier for the button the InputOverlayDrawableButton represents.
* @return An {@link InputOverlayDrawableButton} with the correct drawing bounds set.
*/
private static InputOverlayDrawableButton initializeOverlayButton(Context context,
private InputOverlayDrawableButton initializeOverlayButton(Context context,
int defaultResId, int pressedResId, int legacyId, int control, String orientation)
{
// Resources handle for fetching the initial Drawable resource.
@ -993,7 +1004,6 @@ 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 = getConfiguredControllerType(context);
// Decide scale based on button ID and user preference
float scale;
@ -1019,7 +1029,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
break;
case ButtonType.WIIMOTE_BUTTON_1:
case ButtonType.WIIMOTE_BUTTON_2:
if (controller == 2)
if (mControllerType == OVERLAY_WIIMOTE_SIDEWAYS)
scale = 0.14f;
else
scale = 0.0875f;
@ -1057,8 +1067,8 @@ 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(getXKey(legacyId, controller, orientation), 0f);
int drawableY = (int) sPrefs.getFloat(getYKey(legacyId, controller, orientation), 0f);
int drawableX = (int) sPrefs.getFloat(getXKey(legacyId, mControllerType, orientation), 0f);
int drawableY = (int) sPrefs.getFloat(getYKey(legacyId, mControllerType, orientation), 0f);
int width = overlayDrawable.getWidth();
int height = overlayDrawable.getHeight();
@ -1088,7 +1098,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
* @param rightControl Control identifier for the right button.
* @return the initialized {@link InputOverlayDrawableDpad}
*/
private static InputOverlayDrawableDpad initializeOverlayDpad(Context context,
private InputOverlayDrawableDpad initializeOverlayDpad(Context context,
int defaultResId,
int pressedOneDirectionResId,
int pressedTwoDirectionsResId,
@ -1104,7 +1114,6 @@ 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 = getConfiguredControllerType(context);
// Decide scale based on button ID and user preference
float scale;
@ -1118,7 +1127,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
scale = 0.275f;
break;
default:
if (controller == 2 || controller == 1)
if (mControllerType == OVERLAY_WIIMOTE_SIDEWAYS || mControllerType == OVERLAY_WIIMOTE)
scale = 0.275f;
else
scale = 0.2125f;
@ -1144,8 +1153,8 @@ 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(getXKey(legacyId, controller, orientation), 0f);
int drawableY = (int) sPrefs.getFloat(getYKey(legacyId, controller, orientation), 0f);
int drawableX = (int) sPrefs.getFloat(getXKey(legacyId, mControllerType, orientation), 0f);
int drawableY = (int) sPrefs.getFloat(getYKey(legacyId, mControllerType, orientation), 0f);
int width = overlayDrawable.getWidth();
int height = overlayDrawable.getHeight();
@ -1173,16 +1182,15 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
* @param yControl Control identifier for the Y axis.
* @return the initialized {@link InputOverlayDrawableJoystick}.
*/
private static InputOverlayDrawableJoystick initializeOverlayJoystick(Context context,
int resOuter, int defaultResInner, int pressedResInner, int legacyId, int xControl,
int yControl, String orientation)
private InputOverlayDrawableJoystick initializeOverlayJoystick(Context context, int resOuter,
int defaultResInner, int pressedResInner, int legacyId, int xControl, int yControl,
String orientation)
{
// Resources handle for fetching the initial Drawable resource.
final Resources res = context.getResources();
// SharedPreference to retrieve the X and Y coordinates for the InputOverlayDrawableJoystick.
final SharedPreferences sPrefs = PreferenceManager.getDefaultSharedPreferences(context);
int controller = getConfiguredControllerType(context);
// Decide scale based on user preference
float scale = 0.275f;
@ -1197,8 +1205,8 @@ 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(getXKey(legacyId, controller, orientation), 0f);
int drawableY = (int) sPrefs.getFloat(getYKey(legacyId, controller, orientation), 0f);
int drawableX = (int) sPrefs.getFloat(getXKey(legacyId, mControllerType, orientation), 0f);
int drawableY = (int) sPrefs.getFloat(getYKey(legacyId, mControllerType, orientation), 0f);
// Decide inner scale based on joystick ID
float innerScale;

View File

@ -85,14 +85,6 @@ public final class DirectoryInitialization
checkThemeSettings(context);
// TODO: Does doing this still make sense?
if (false)
{
// This has to be done after calling NativeLibrary.Initialize(),
// as it relies on the config system
EmulationActivity.updateWiimoteNewIniPreferences(context);
}
directoryState.postValue(DirectoryInitializationState.DOLPHIN_DIRECTORIES_INITIALIZED);
}

View File

@ -19,6 +19,10 @@
android:checkable="true"
android:title="@string/emulation_control_joystick_rel_center"/>
<item
android:id="@+id/menu_emulation_choose_controller"
android:title="@string/emulation_choose_controller"/>
<item
android:id="@+id/menu_emulation_reset_overlay"
android:title="@string/emulation_touch_overlay_reset"/>

View File

@ -386,23 +386,6 @@
<item>2</item>
</integer-array>
<string-array name="controllersEntries">
<item>@string/controller_gc</item>
<item>@string/controller_wiimote</item>
<item>@string/controller_horizontal_wiimote</item>
<item>@string/controller_wiimote_plus_nunchuk</item>
<item>@string/controller_classic</item>
<item>@string/controller_none</item>
</string-array>
<string-array name="controllersValues">
<item>None</item>
<item>None</item>
<item>None</item>
<item>Nunchuk</item>
<item>Classic</item>
<item>None</item>
</string-array>
<string-array name="gcpadButtons">
<item>A</item>
<item>B</item>

View File

@ -6,6 +6,8 @@
<string name="host">app</string>
<string name="scheme">dolphinemu</string>
<string name="none">None</string>
<string name="controller_0">GameCube Controller 1</string>
<string name="controller_1">GameCube Controller 2</string>
<string name="controller_2">GameCube Controller 3</string>
@ -614,7 +616,7 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="slider_setting_value">%1$d%2$s</string>
<string name="disc_number">Disc %1$d</string>
<string name="replug_gc_adapter">GameCube Adapter couldn\'t be opened. Please re-plug the device.</string>
<string name="disabled_gc_overlay_notice">GameCube Controller 1 is set to \"None\"</string>
<string name="disabled_gc_overlay_notice">The selected GameCube controller is set to \"None\"</string>
<string name="ignore_warning_alert_messages">Ignore for this session</string>
<!-- UI CPU Core selection -->
@ -758,14 +760,6 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="wiimote_emulated">Emulated</string>
<string name="wiimote_real">Real Wii Remote (DolphinBar required)</string>
<!-- Controller Types -->
<string name="controller_gc">GameCube Controller</string>
<string name="controller_wiimote">Wii Remote</string>
<string name="controller_horizontal_wiimote">Horizontal Wii Remote</string>
<string name="controller_wiimote_plus_nunchuk">Wii Remote + Nunchuk</string>
<string name="controller_classic">Classic Controller</string>
<string name="controller_none">None</string>
<!-- Gamepad Controls -->
<string name="gamepad_start">Start</string>
<string name="gamepad_d_pad">D-Pad</string>

View File

@ -17,6 +17,7 @@
#include "jni/Input/Control.h"
#include "jni/Input/ControlGroup.h"
#include "jni/Input/ControlReference.h"
#include "jni/Input/NumericSetting.h"
ControllerEmu::EmulatedController* EmulatedControllerFromJava(JNIEnv* env, jobject obj)
{
@ -145,4 +146,29 @@ Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedContro
Wiimote::GetWiimoteGroup(controller_index, WiimoteEmu::WiimoteGroup::Attachments));
return EmulatedControllerToJava(env, attachments->GetAttachmentList()[attachment_index].get());
}
JNIEXPORT jint JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getSelectedWiimoteAttachment(
JNIEnv* env, jclass, jint controller_index)
{
auto* attachments = static_cast<ControllerEmu::Attachments*>(
Wiimote::GetWiimoteGroup(controller_index, WiimoteEmu::WiimoteGroup::Attachments));
return static_cast<jint>(attachments->GetSelectedAttachment());
}
JNIEXPORT jobject JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getSidewaysWiimoteSetting(
JNIEnv* env, jclass, jint controller_index)
{
ControllerEmu::ControlGroup* options =
Wiimote::GetWiimoteGroup(controller_index, WiimoteEmu::WiimoteGroup::Options);
for (auto& setting : options->numeric_settings)
{
if (setting->GetININame() == WiimoteEmu::Wiimote::SIDEWAYS_OPTION)
return NumericSettingToJava(env, setting.get());
}
return nullptr;
}
}

View File

@ -478,12 +478,6 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_RefreshWiimo
WiimoteReal::Refresh();
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadWiimoteConfig(JNIEnv*,
jclass)
{
Wiimote::LoadConfig();
}
JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_ReloadConfig(JNIEnv*, jclass)
{
SConfig::GetInstance().LoadSettings();

View File

@ -299,11 +299,10 @@ Wiimote::Wiimote(const unsigned int index) : m_index(index), m_bt_device_index(i
// Note: "Upright" and "Sideways" options can be enabled at the same time which produces an
// orientation where the wiimote points towards the left with the buttons towards you.
m_options->AddSetting(&m_upright_setting,
{"Upright Wiimote", nullptr, nullptr, _trans("Upright Wii Remote")}, false);
{UPRIGHT_OPTION, nullptr, nullptr, _trans("Upright Wii Remote")}, false);
m_options->AddSetting(&m_sideways_setting,
{"Sideways Wiimote", nullptr, nullptr, _trans("Sideways Wii Remote")},
false);
{SIDEWAYS_OPTION, nullptr, nullptr, _trans("Sideways Wii Remote")}, false);
Reset();

View File

@ -129,6 +129,9 @@ public:
static constexpr const char* PLUS_BUTTON = "+";
static constexpr const char* HOME_BUTTON = "Home";
static constexpr const char* UPRIGHT_OPTION = "Upright Wiimote";
static constexpr const char* SIDEWAYS_OPTION = "Sideways Wiimote";
explicit Wiimote(unsigned int index);
~Wiimote();

View File

@ -11,6 +11,11 @@ NumericSettingBase::NumericSettingBase(const NumericSettingDetails& details) : m
{
}
const char* NumericSettingBase::GetININame() const
{
return m_details.ini_name;
}
const char* NumericSettingBase::GetUIName() const
{
return m_details.ui_name;

View File

@ -78,6 +78,7 @@ public:
virtual void SetToDefault() = 0;
const char* GetININame() const;
const char* GetUIName() const;
const char* GetUISuffix() const;
const char* GetUIDescription() const;