diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java index 1db70b72d9..68fdfee277 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java @@ -404,8 +404,6 @@ public final class NativeLibrary */ public static native void RefreshWiimotes(); - public static native void ReloadWiimoteConfig(); - public static native LinkedHashMap GetLogTypeNames(); public static native void ReloadLoggerConfig(); diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java index 439d697247..9780f8de7b 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java @@ -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 entries, List values, + IntSetting controller, int entry, int value) + { + if (controller.getInt(mSettings) != 0) + { + entries.add(getString(entry)); + values.add(value); + } + } + private void chooseController() { + ArrayList entries = new ArrayList<>(); + ArrayList 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 diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.java index 47d4dc5c96..39645ffbba 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/input/model/controlleremu/EmulatedController.java @@ -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); } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java index 10503f7da0..77cf7b339a 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/model/IntSetting.java @@ -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]; + } } diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java index 2cabb8edc7..acad8c2d19 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/features/settings/utils/SettingsFile.java @@ -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 sectionsMap = new BiMap<>(); static diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java index c356969136..27e425d8b6 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java @@ -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 diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java index 0a961ac16f..1fed472b56 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/overlay/InputOverlay.java @@ -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; diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java index 45f2960bd9..bb2f45de43 100644 --- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java +++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/utils/DirectoryInitialization.java @@ -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); } diff --git a/Source/Android/app/src/main/res/menu/menu_overlay_controls_gc.xml b/Source/Android/app/src/main/res/menu/menu_overlay_controls_gc.xml index e55c310b22..fc33d4639f 100644 --- a/Source/Android/app/src/main/res/menu/menu_overlay_controls_gc.xml +++ b/Source/Android/app/src/main/res/menu/menu_overlay_controls_gc.xml @@ -19,6 +19,10 @@ android:checkable="true" android:title="@string/emulation_control_joystick_rel_center"/> + + diff --git a/Source/Android/app/src/main/res/values/arrays.xml b/Source/Android/app/src/main/res/values/arrays.xml index 5afaf8ba2c..fd2618af70 100644 --- a/Source/Android/app/src/main/res/values/arrays.xml +++ b/Source/Android/app/src/main/res/values/arrays.xml @@ -386,23 +386,6 @@ 2 - - @string/controller_gc - @string/controller_wiimote - @string/controller_horizontal_wiimote - @string/controller_wiimote_plus_nunchuk - @string/controller_classic - @string/controller_none - - - None - None - None - Nunchuk - Classic - None - - A B diff --git a/Source/Android/app/src/main/res/values/strings.xml b/Source/Android/app/src/main/res/values/strings.xml index 38d64ad485..3c15318f01 100644 --- a/Source/Android/app/src/main/res/values/strings.xml +++ b/Source/Android/app/src/main/res/values/strings.xml @@ -6,6 +6,8 @@ app dolphinemu + None + GameCube Controller 1 GameCube Controller 2 GameCube Controller 3 @@ -614,7 +616,7 @@ It can efficiently compress both junk data and encrypted Wii data. %1$d%2$s Disc %1$d GameCube Adapter couldn\'t be opened. Please re-plug the device. - GameCube Controller 1 is set to \"None\" + The selected GameCube controller is set to \"None\" Ignore for this session @@ -758,14 +760,6 @@ It can efficiently compress both junk data and encrypted Wii data. Emulated Real Wii Remote (DolphinBar required) - - GameCube Controller - Wii Remote - Horizontal Wii Remote - Wii Remote + Nunchuk - Classic Controller - None - Start D-Pad diff --git a/Source/Android/jni/Input/EmulatedController.cpp b/Source/Android/jni/Input/EmulatedController.cpp index 567049cb2b..6c8d64e22f 100644 --- a/Source/Android/jni/Input/EmulatedController.cpp +++ b/Source/Android/jni/Input/EmulatedController.cpp @@ -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( + Wiimote::GetWiimoteGroup(controller_index, WiimoteEmu::WiimoteGroup::Attachments)); + return static_cast(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; +} } diff --git a/Source/Android/jni/MainAndroid.cpp b/Source/Android/jni/MainAndroid.cpp index 375d470eb5..ff6b4f9a13 100644 --- a/Source/Android/jni/MainAndroid.cpp +++ b/Source/Android/jni/MainAndroid.cpp @@ -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(); diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp index 3b0018a76b..8a087e2098 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.cpp @@ -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(); diff --git a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h index 0394e21e6e..59f867be10 100644 --- a/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h +++ b/Source/Core/Core/HW/WiimoteEmu/WiimoteEmu.h @@ -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(); diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp index f7f2054927..ec28a4d6f6 100644 --- a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp +++ b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp @@ -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; diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h index 8b36ab117e..d123117eb0 100644 --- a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h +++ b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h @@ -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;