Skip to content

Commit

Permalink
Android: Add emulated Wii Remote orientation setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebola16 committed Jul 4, 2020
1 parent a590204 commit 6efcb78
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 71 deletions.
Expand Up @@ -823,7 +823,7 @@ public void chooseDoubleTapButton()
if (currentController != InputOverlay.OVERLAY_WIIMOTE_CLASSIC &&
currentValue == InputOverlay.OVERLAY_WIIMOTE_CLASSIC)
{
currentValue = InputOverlay.OVERLAY_WIIMOTE;
currentValue = InputOverlay.OVERLAY_WIIMOTE_VERTICAL;
}

builder.setSingleChoiceItems(buttonList, currentValue, (DialogInterface dialog, int which) ->
Expand Down Expand Up @@ -906,7 +906,7 @@ private void chooseController()
getResources().getStringArray(R.array.controllersValues)[indexSelected]);
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini",
SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_ORIENTATION,
indexSelected == InputOverlay.OVERLAY_WIIMOTE_SIDEWAYS ? "True" : "False");
indexSelected == InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL ? "1" : "0");

// Delay needed to avoid registering overlay Wii Remote as Player 2 in Super Smash
// Bros. Brawl's character selection screen when switching controllers with
Expand Down
Expand Up @@ -290,13 +290,13 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
if (NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini",
SettingsFile.KEY_WIIMOTE_PLAYER_1,
SettingsFile.KEY_WIIMOTE_ORIENTATION, "False").equals("False"))
SettingsFile.KEY_WIIMOTE_ORIENTATION, "0").equals("1"))
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE);
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL);
}
else
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_SIDEWAYS);
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_VERTICAL);
}
break;

Expand All @@ -311,12 +311,9 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
editor.commit();
}

if (value != 0) // None
{
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, gameId);
}
Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, gameId);
}

public static void wiiOverlayDetermineExtension(Context context, String extension)
Expand All @@ -329,14 +326,14 @@ public static void wiiOverlayDetermineExtension(Context context, String extensio
case "None":
if (NativeLibrary.GetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini",
SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_ORIENTATION,
"False")
.equals("False"))
"0")
.equals("1"))
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE);
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL);
}
else
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_SIDEWAYS);
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_VERTICAL);
}
break;

Expand Down
Expand Up @@ -43,6 +43,7 @@
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SliderViewHolder;
import org.dolphinemu.dolphinemu.features.settings.ui.viewholder.SubmenuViewHolder;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.overlay.InputOverlay;
import org.dolphinemu.dolphinemu.ui.main.MainPresenter;
import org.dolphinemu.dolphinemu.utils.FileBrowserHelper;
import org.dolphinemu.dolphinemu.utils.Log;
Expand Down Expand Up @@ -374,6 +375,8 @@ public void onClick(DialogInterface dialog, int which)
{
if (mClickedItem instanceof SingleChoiceSetting)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(mContext);
final SharedPreferences.Editor editor = preferences.edit();
SingleChoiceSetting scSetting = (SingleChoiceSetting) mClickedItem;

int value = getValueForSingleChoiceSelection(scSetting, which);
Expand Down Expand Up @@ -425,6 +428,22 @@ else if (scSetting.getKey().contains(SettingsFile.KEY_WIIMOTE_EXTENSION) &&
}
}

if (mClickedItem.getSection().equals(SettingsFile.KEY_WIIMOTE_PLAYER_1) &&
mClickedItem.getKey().equals(SettingsFile.KEY_WIIMOTE_ORIENTATION) && NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini", SettingsFile.KEY_WIIMOTE_PLAYER_1,
SettingsFile.KEY_WIIMOTE_EXTENSION, "None").equals("None"))
{
if (value == 1)
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL);
}
else
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_VERTICAL);
}
editor.commit();
}

closeDialog();
}
else if (mClickedItem instanceof SingleChoiceSettingDynamicDescriptions)
Expand Down
Expand Up @@ -933,7 +933,6 @@ private void addWiimoteSubSettings(ArrayList<SettingsItem> sl, int wiimoteNumber
{
SettingSection bindingsSection = mSettings.getSection(Settings.SECTION_BINDINGS);


Setting bindA = bindingsSection.getSetting(SettingsFile.KEY_WIIBIND_A + wiimoteNumber);
Setting bindB = bindingsSection.getSetting(SettingsFile.KEY_WIIBIND_B + wiimoteNumber);
Setting bind1 = bindingsSection.getSetting(SettingsFile.KEY_WIIBIND_1 + wiimoteNumber);
Expand Down Expand Up @@ -1108,9 +1107,18 @@ private void addExtensionTypeSettings(ArrayList<SettingsItem> sl, int wiimoteNum
int extentionType)
{
SettingSection bindingsSection = mSettings.getSection(Settings.SECTION_BINDINGS);
SettingSection wiimoteSection = mSettings.getSection(Settings.SECTION_WIIMOTE + (wiimoteNumber - 3));

switch (extentionType)
{
case 0: // None
Setting orientation = wiimoteSection.getSetting(SettingsFile.KEY_WIIMOTE_ORIENTATION);

sl.add(new SingleChoiceSetting(SettingsFile.KEY_WIIMOTE_ORIENTATION,
Settings.SECTION_WIIMOTE + (wiimoteNumber - 3), R.string.wiimote_orientation, 0,
R.array.wiimoteOrientationEntries, R.array.wiimoteOrientationValues, 0, orientation));
break;

case 1: // Nunchuk
Setting bindC =
bindingsSection.getSetting(SettingsFile.KEY_WIIBIND_NUNCHUK_C + wiimoteNumber);
Expand Down Expand Up @@ -1577,25 +1585,23 @@ private int getVideoBackendValue()
{
String videoBackend =
((StringSetting) coreSection.getSetting(SettingsFile.KEY_VIDEO_BACKEND)).getValue();
if (videoBackend.equals("OGL"))
switch (videoBackend)
{
videoBackendValue = 0;
}
else if (videoBackend.equals("Vulkan"))
{
videoBackendValue = 1;
}
else if (videoBackend.equals("Software Renderer"))
{
videoBackendValue = 2;
}
else if (videoBackend.equals("Null"))
{
videoBackendValue = 3;
}
else
{
videoBackendValue = 0;
case "Vulkan":
videoBackendValue = 1;
break;

case "Software Renderer":
videoBackendValue = 2;
break;

case "Null":
videoBackendValue = 3;
break;

default:
videoBackendValue = 0;
break;
}
}
catch (NullPointerException ex)
Expand Down Expand Up @@ -1625,33 +1631,31 @@ private int getExtensionValue(int wiimoteNumber)
.getSetting(SettingsFile.KEY_WIIMOTE_EXTENSION)).getValue();
}

if (extension.equals("None"))
{
extensionValue = 0;
}
else if (extension.equals("Nunchuk"))
{
extensionValue = 1;
}
else if (extension.equals("Classic"))
{
extensionValue = 2;
}
else if (extension.equals("Guitar"))
{
extensionValue = 3;
}
else if (extension.equals("Drums"))
{
extensionValue = 4;
}
else if (extension.equals("Turntable"))
switch (extension)
{
extensionValue = 5;
}
else
{
extensionValue = 0;
case "Nunchuk":
extensionValue = 1;
break;

case "Classic":
extensionValue = 2;
break;

case "Guitar":
extensionValue = 3;
break;

case "Drums":
extensionValue = 4;
break;

case "Turntable":
extensionValue = 5;
break;

default:
extensionValue = 0;
break;
}
}
catch (NullPointerException ex)
Expand Down
Expand Up @@ -482,7 +482,8 @@ public static void saveCustomGameSettings(final String gameId,
HashMap<String, Setting> settings = section.getSettings();
Set<String> sortedKeySet = new TreeSet<>(settings.keySet());

// Profile options(wii extension) are not saved, only used to properly display values
// Profile options (wii extension and orientation) are not saved,
// only used to properly display values
if (sectionKey.contains(Settings.SECTION_PROFILE))
{
continue;
Expand All @@ -491,15 +492,21 @@ public static void saveCustomGameSettings(final String gameId,
for (String settingKey : sortedKeySet)
{
Setting setting = settings.get(settingKey);
// Special case. Extension gets saved into a controller profile
// Extension and orientation gets saved into a controller profile.
if (settingKey.contains(SettingsFile.KEY_WIIMOTE_EXTENSION))
{
String padId =
setting.getKey()
.substring(setting.getKey().length() - 1, setting.getKey().length());
String padId = setting.getKey().substring(setting.getKey().length() - 1);
saveCustomWiimoteSetting(gameId, KEY_WIIMOTE_EXTENSION, setting.getValueAsString(),
padId);
}
else if (settingKey.contains(SettingsFile.KEY_WIIMOTE_ORIENTATION))
{
String padId =
String.valueOf(
Integer.parseInt(sectionKey.substring(sectionKey.length() - 1)) - 1);
saveCustomWiimoteSetting(gameId, KEY_WIIMOTE_ORIENTATION, setting.getValueAsString(),
padId);
}
else
{
NativeLibrary.SetUserSetting(gameId, mapSectionNameFromIni(section.getName()),
Expand Down Expand Up @@ -536,14 +543,14 @@ private static void saveCustomWiimoteSetting(final String gameId, final String k
DirectoryInitialization.copyFile(defautlWiiProfilePath, wiiConfigPath);

NativeLibrary.SetProfileSetting(profile, Settings.SECTION_PROFILE, "Device",
"Android/" + (Integer.valueOf(padId) + 4) + "/Touchscreen");
"Android/" + (Integer.parseInt(padId) + 4) + "/Touchscreen");
}

NativeLibrary.SetProfileSetting(profile, Settings.SECTION_PROFILE, key, value);

// Enable the profile
NativeLibrary.SetUserSetting(gameId, Settings.SECTION_CONTROLS,
KEY_WIIMOTE_PROFILE + (Integer.valueOf(padId) + 1), profile);
KEY_WIIMOTE_PROFILE + (Integer.parseInt(padId) + 1), profile);
}

private static String mapSectionNameFromIni(String generalSectionName)
Expand Down
Expand Up @@ -46,8 +46,8 @@
public final class InputOverlay extends SurfaceView implements OnTouchListener
{
public static final int OVERLAY_GAMECUBE = 0;
public static final int OVERLAY_WIIMOTE = 1;
public static final int OVERLAY_WIIMOTE_SIDEWAYS = 2;
public static final int OVERLAY_WIIMOTE_VERTICAL = 1;
public static final int OVERLAY_WIIMOTE_HORIZONTAL = 2;
public static final int OVERLAY_WIIMOTE_NUNCHUK = 3;
public static final int OVERLAY_WIIMOTE_CLASSIC = 4;
public static final int OVERLAY_NONE = 5;
Expand Down Expand Up @@ -769,8 +769,8 @@ public void refreshControls()
addGameCubeOverlayControls(orientation);
break;

case OVERLAY_WIIMOTE:
case OVERLAY_WIIMOTE_SIDEWAYS:
case OVERLAY_WIIMOTE_VERTICAL:
case OVERLAY_WIIMOTE_HORIZONTAL:
addWiimoteOverlayControls(orientation);
break;

Expand Down
10 changes: 10 additions & 0 deletions Source/Android/app/src/main/res/values/arrays.xml
Expand Up @@ -117,6 +117,16 @@
<item>5</item>
</integer-array>

<!-- Wii Remote orientation -->
<string-array name="wiimoteOrientationEntries" translatable="false">
<item>Vertical</item>
<item>Horizontal</item>
</string-array>
<integer-array name="wiimoteOrientationValues" translatable="false">
<item>0</item>
<item>1</item>
</integer-array>

<!-- Texture Cache Accuracy Preference -->
<string-array name="textureCacheAccuracyEntries" translatable="false">
<item>Low</item>
Expand Down
1 change: 1 addition & 0 deletions Source/Android/app/src/main/res/values/strings.xml
Expand Up @@ -41,6 +41,7 @@
<!-- END WARNING -->

<string name="wiimote_extensions">Extension</string>
<string name="wiimote_orientation">Orientation</string>
<string name="wiimote_extensions_description">Choose and bind the Wii Remote extension.</string>
<string name="wiimote_ir">IR</string>
<string name="wiimote_swing">Swing</string>
Expand Down

0 comments on commit 6efcb78

Please sign in to comment.