Skip to content

Commit

Permalink
Android: Wii Overlay Controller Overhaul
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebola16 committed Jul 3, 2020
1 parent 38b3653 commit a590204
Show file tree
Hide file tree
Showing 11 changed files with 314 additions and 30 deletions.
Expand Up @@ -367,6 +367,8 @@ public static native String GetConfig(String configFile, String Section, String

public static native void ReloadConfig();

public static native void SetOverlaySIDevice(int SIDevice0);

/**
* Initializes the native parts of the app.
*
Expand Down
Expand Up @@ -420,19 +420,17 @@ public void onBackPressed()
protected void onActivityResult(int requestCode, int resultCode, Intent result)
{
super.onActivityResult(requestCode, resultCode, result);
switch (requestCode)
if (requestCode == REQUEST_CHANGE_DISC)
{
case REQUEST_CHANGE_DISC:
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
// If the user picked a file, as opposed to just backing out.
if (resultCode == MainActivity.RESULT_OK)
{
String newDiscPath = FileBrowserHelper.getSelectedPath(result);
if (!TextUtils.isEmpty(newDiscPath))
{
String newDiscPath = FileBrowserHelper.getSelectedPath(result);
if (!TextUtils.isEmpty(newDiscPath))
{
NativeLibrary.ChangeDisc(newDiscPath);
}
NativeLibrary.ChangeDisc(newDiscPath);
}
break;
}
}
}

Expand Down Expand Up @@ -891,6 +889,7 @@ public void onStopTrackingTouch(SeekBar seekBar)

private void chooseController()
{
final Handler handler = new Handler();
final SharedPreferences.Editor editor = mPreferences.edit();
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DolphinDialogBase);
builder.setTitle(R.string.emulation_choose_controller);
Expand All @@ -899,11 +898,20 @@ private void chooseController()
(dialog, indexSelected) ->
{
editor.putInt("wiiController", indexSelected);
NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1", "Extension",

handleWiiOverlayDisablesControllersSetting(indexSelected, false);

NativeLibrary.SetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini",
SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_EXTENSION,
getResources().getStringArray(R.array.controllersValues)[indexSelected]);
NativeLibrary.SetConfig("WiimoteNew.ini", "Wiimote1",
"Options/Sideways Wiimote", indexSelected == 2 ? "True" : "False");
NativeLibrary.ReloadWiimoteConfig();
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini",
SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_ORIENTATION,
indexSelected == InputOverlay.OVERLAY_WIIMOTE_SIDEWAYS ? "True" : "False");

// Delay needed to avoid registering overlay Wii Remote as Player 2 in Super Smash
// Bros. Brawl's character selection screen when switching controllers with
// "Disable Unselected Wii Overlay Controllers" enabled.
handler.postDelayed(NativeLibrary::ReloadWiimoteConfig, 500);
});
builder.setPositiveButton(getString(R.string.ok), (dialogInterface, i) ->
{
Expand All @@ -915,6 +923,63 @@ private void chooseController()
alertDialog.show();
}

public static void handleWiiOverlayDisablesControllersSetting(int selection, boolean IsFirstRun)
{
if (NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_ANDROID,
SettingsFile.KEY_WII_OVERLAY_DISABLES_CONTROLLERS, "False")
.equals("True"))
{
// TODO: Add real controllers to Wii Input overlay so they can be changed by this setting.
if (!NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
SettingsFile.KEY_GCPAD_PLAYER_1, InputOverlay.EMULATED_GAMECUBE_CONTROLLER)
.equals(InputOverlay.GAMECUBE_ADAPTER))
{
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini", Settings.SECTION_INI_CORE,
SettingsFile.KEY_GCPAD_PLAYER_1,
selection == InputOverlay.OVERLAY_GAMECUBE ?
InputOverlay.EMULATED_GAMECUBE_CONTROLLER :
InputOverlay.DISABLED_GAMECUBE_CONTROLLER);

NativeLibrary.SetOverlaySIDevice(selection == InputOverlay.OVERLAY_GAMECUBE ?
Integer.parseInt(InputOverlay.EMULATED_GAMECUBE_CONTROLLER) :
Integer.parseInt(InputOverlay.DISABLED_GAMECUBE_CONTROLLER));
}

if (!NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini", SettingsFile.KEY_WIIMOTE_PLAYER_1,
SettingsFile.KEY_WIIMOTE_TYPE, "1").equals("2"))
{
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini",
SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_TYPE,
selection == InputOverlay.OVERLAY_GAMECUBE ? "0" : "1");
}
}
// The following code is unnecessary on first run.
else if (!IsFirstRun)
{
if (selection == InputOverlay.OVERLAY_GAMECUBE)
{
NativeLibrary
.SetConfig(SettingsFile.FILE_NAME_DOLPHIN + ".ini",
Settings.SECTION_INI_CORE,
SettingsFile.KEY_GCPAD_PLAYER_1,
InputOverlay.EMULATED_GAMECUBE_CONTROLLER);

NativeLibrary
.SetOverlaySIDevice(
Integer.parseInt(InputOverlay.EMULATED_GAMECUBE_CONTROLLER));
}
else
{
NativeLibrary.SetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini",
SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_TYPE, "1");
}
}
}

private void showMotionControlsOptions()
{
final SharedPreferences.Editor editor = mPreferences.edit();
Expand Down Expand Up @@ -974,7 +1039,7 @@ private void chooseOrientation()

private void setIRSensitivity()
{
int ir_pitch = Integer.valueOf(
int ir_pitch = Integer.parseInt(
mPreferences.getString(SettingsFile.KEY_WIIBIND_IR_PITCH + mSelectedGameId, "15"));

LayoutInflater inflater = LayoutInflater.from(this);
Expand Down Expand Up @@ -1007,7 +1072,7 @@ private void setIRSensitivity()
}
});

int ir_yaw = Integer.valueOf(
int ir_yaw = Integer.parseInt(
mPreferences.getString(SettingsFile.KEY_WIIBIND_IR_YAW + mSelectedGameId, "15"));

TextView text_slider_value_yaw = (TextView) view.findViewById(R.id.text_ir_yaw);
Expand Down Expand Up @@ -1038,7 +1103,7 @@ private void setIRSensitivity()
});


int ir_vertical_offset = Integer.valueOf(
int ir_vertical_offset = Integer.parseInt(
mPreferences.getString(SettingsFile.KEY_WIIBIND_IR_VERTICAL_OFFSET + mSelectedGameId,
"10"));

Expand Down
Expand Up @@ -2,11 +2,16 @@

import android.content.Context;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.text.TextUtils;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.R;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.overlay.InputOverlay;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization.DirectoryInitializationState;
import org.dolphinemu.dolphinemu.utils.DirectoryStateReceiver;
Expand All @@ -17,6 +22,14 @@

public final class SettingsActivityPresenter
{
public static final int WIIMOTE_PLAYER_1_DISABLED = 0;
public static final int WIIMOTE_PLAYER_1_EMULATED = 1;
public static final int WIIMOTE_PLAYER_1_REAL = 2;

public static final int WIIMOTE_PLAYER_1_EXT_NONE = 0;
public static final int WIIMOTE_PLAYER_1_EXT_NUNCHUK = 1;
public static final int WIIMOTE_PLAYER_1_EXT_CLASSIC = 2;

private static final String KEY_SHOULD_SAVE = "should_save";

private SettingsActivityView mView;
Expand Down Expand Up @@ -172,11 +185,10 @@ public void onBackPressed()

public boolean handleOptionsItem(int itemId)
{
switch (itemId)
if (itemId == R.id.menu_save_exit)
{
case R.id.menu_save_exit:
mView.finish();
return true;
mView.finish();
return true;
}

return false;
Expand Down Expand Up @@ -204,6 +216,22 @@ public boolean shouldSave()

public void onGcPadSettingChanged(MenuTag key, int value)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = preferences.edit();

if (key == MenuTag.GCPAD_1) // Player 1
{
if (value == 6) // Emulated GC Controller
{
editor.putInt("wiiController", InputOverlay.OVERLAY_GAMECUBE);
}
else
{
editor.putInt("wiiController", InputOverlay.OVERLAY_NONE);
}
editor.commit();
}

if (value != 0) // Not disabled
{
Bundle bundle = new Bundle();
Expand All @@ -214,6 +242,29 @@ public void onGcPadSettingChanged(MenuTag key, int value)

public void onWiimoteSettingChanged(MenuTag menuTag, int value)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = preferences.edit();

String extension = NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini", SettingsFile.KEY_WIIMOTE_PLAYER_1,
SettingsFile.KEY_WIIMOTE_EXTENSION, "None");

if (menuTag == MenuTag.WIIMOTE_1) // Player 1
{
switch (value)
{
case WIIMOTE_PLAYER_1_DISABLED:
case WIIMOTE_PLAYER_1_REAL:
editor.putInt("wiiController", InputOverlay.OVERLAY_NONE);
editor.commit();
break;

case WIIMOTE_PLAYER_1_EMULATED:
wiiOverlayDetermineExtension(context, extension);
break;
}
}

switch (value)
{
case 1:
Expand All @@ -228,6 +279,38 @@ public void onWiimoteSettingChanged(MenuTag menuTag, int value)

public void onExtensionSettingChanged(MenuTag menuTag, int value)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = preferences.edit();

if (menuTag == MenuTag.WIIMOTE_EXTENSION_1) // Player 1
{
switch (value)
{
case WIIMOTE_PLAYER_1_EXT_NONE:
if (NativeLibrary
.GetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini",
SettingsFile.KEY_WIIMOTE_PLAYER_1,
SettingsFile.KEY_WIIMOTE_ORIENTATION, "False").equals("False"))
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE);
}
else
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_SIDEWAYS);
}
break;

case WIIMOTE_PLAYER_1_EXT_NUNCHUK:
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK);
break;

case WIIMOTE_PLAYER_1_EXT_CLASSIC:
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_CLASSIC);
break;
}
editor.commit();
}

if (value != 0) // None
{
Bundle bundle = new Bundle();
Expand All @@ -236,6 +319,38 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
}
}

public static void wiiOverlayDetermineExtension(Context context, String extension)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = preferences.edit();

switch (extension)
{
case "None":
if (NativeLibrary.GetConfig(SettingsFile.FILE_NAME_WIIMOTE + ".ini",
SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_ORIENTATION,
"False")
.equals("False"))
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE);
}
else
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_SIDEWAYS);
}
break;

case "Nunchuk":
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK);
break;

case "Classic":
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_CLASSIC);
break;
}
editor.commit();
}

public void onFileConfirmed(String file)
{
SettingsAdapter.onFilePickerConfirmation(file);
Expand Down
Expand Up @@ -28,6 +28,7 @@
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.EGLHelper;
import org.dolphinemu.dolphinemu.utils.Log;
import org.dolphinemu.dolphinemu.utils.TvUtil;

import java.io.File;
import java.util.ArrayList;
Expand Down Expand Up @@ -389,12 +390,16 @@ private void addWiiSettings(ArrayList<SettingsItem> sl)
Setting wiiSDWrites = null;
Setting continuousScan = null;
Setting wiimoteSpeaker = null;
Setting wiiOverlayDisablesControllers = null;

SettingSection coreSection = mSettings.getSection(Settings.SECTION_INI_CORE);
SettingSection androidSection = mSettings.getSection(Settings.SECTION_INI_ANDROID);
wiiSDCard = coreSection.getSetting(SettingsFile.KEY_WII_SD_CARD);
wiiSDWrites = coreSection.getSetting(SettingsFile.KEY_WII_SD_CARD_ALLOW_WRITES);
continuousScan = coreSection.getSetting(SettingsFile.KEY_WIIMOTE_SCAN);
wiimoteSpeaker = coreSection.getSetting(SettingsFile.KEY_WIIMOTE_SPEAKER);
wiiOverlayDisablesControllers =
androidSection.getSetting(SettingsFile.KEY_WII_OVERLAY_DISABLES_CONTROLLERS);

sl.add(new CheckBoxSetting(SettingsFile.KEY_WII_SD_CARD, Settings.SECTION_INI_CORE,
R.string.insert_sd_card, R.string.insert_sd_card_description, true, wiiSDCard));
Expand All @@ -405,6 +410,13 @@ private void addWiiSettings(ArrayList<SettingsItem> sl)
continuousScan));
sl.add(new CheckBoxSetting(SettingsFile.KEY_WIIMOTE_SPEAKER, Settings.SECTION_INI_CORE,
R.string.wiimote_speaker, R.string.wiimote_speaker_description, true, wiimoteSpeaker));
if (!TvUtil.isLeanback(mView.getActivity().getApplicationContext()))
{
sl.add(new CheckBoxSetting(SettingsFile.KEY_WII_OVERLAY_DISABLES_CONTROLLERS,
Settings.SECTION_INI_ANDROID, R.string.wii_overlay_disables_controllers,
R.string.wii_overlay_disables_controllers_description, false,
wiiOverlayDisablesControllers));
}
}

private void addAdvancedSettings(ArrayList<SettingsItem> sl)
Expand Down
Expand Up @@ -41,6 +41,7 @@ public final class SettingsFile

public static final String KEY_DSP_ENGINE = "DSPEngine";
public static final String KEY_LAST_PLATFORM_TAB = "LastPlatformTab";
public static final String KEY_WII_OVERLAY_DISABLES_CONTROLLERS = "WiiOverlayDisablesControllers";

public static final String KEY_CPU_CORE = "CPUCore";
public static final String KEY_DUAL_CORE = "CPUThread";
Expand Down Expand Up @@ -151,6 +152,8 @@ public final class SettingsFile

public static final String KEY_WIIMOTE_TYPE = "Source";
public static final String KEY_WIIMOTE_EXTENSION = "Extension";
public static final String KEY_WIIMOTE_ORIENTATION = "Options/Sideways Wiimote";
public static final String KEY_WIIMOTE_PLAYER_1 = "Wiimote1";

// Controller keys for game specific settings
public static final String KEY_WIIMOTE_G_TYPE = "WiimoteSource";
Expand Down

0 comments on commit a590204

Please sign in to comment.