Skip to content

Commit

Permalink
Android: wiiController to INI and associated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ebola16 committed Oct 28, 2020
1 parent dcc5d67 commit 903933c
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 87 deletions.
Expand Up @@ -190,13 +190,6 @@ public static void stopIgnoringLaunchRequests()
sIgnoreLaunchRequests = false;
}

public static void clearWiimoteNewIniLinkedPreferences(Context context)
{
SharedPreferences.Editor editor = PreferenceManager.getDefaultSharedPreferences(context).edit();
editor.remove("wiiController");
editor.apply();
}

@Override
protected void onCreate(Bundle savedInstanceState)
{
Expand Down Expand Up @@ -657,6 +650,9 @@ private void toggleRumble(boolean state)

private void editControlsPlacement()
{
if (overlayControllerWithoutButtons(IntSetting.MAIN_WII_OVERLAY_CONTROLLER.getInt(mSettings)))
return;

if (mEmulationFragment.isConfiguringControls())
{
mEmulationFragment.stopConfiguringControls();
Expand Down Expand Up @@ -697,11 +693,14 @@ public boolean dispatchKeyEvent(KeyEvent event)

private void toggleControls()
{
final int wiiController = IntSetting.MAIN_WII_OVERLAY_CONTROLLER.getInt(mSettings);

if (overlayControllerWithoutButtons(wiiController))
return;

AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DolphinDialogBase);
builder.setTitle(R.string.emulation_toggle_controls);
if (!NativeLibrary.IsEmulatingWii() ||
mPreferences.getInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK) ==
InputOverlay.OVERLAY_GAMECUBE)
if (!NativeLibrary.IsEmulatingWii() || wiiController == InputOverlay.OVERLAY_GAMECUBE)
{
boolean[] gcEnabledButtons = new boolean[11];
String gcSettingBase = "MAIN_BUTTON_TOGGLE_GC_";
Expand All @@ -714,8 +713,7 @@ private void toggleControls()
(dialog, indexSelected, isChecked) -> BooleanSetting
.valueOf(gcSettingBase + indexSelected).setBoolean(mSettings, isChecked));
}
else if (mPreferences.getInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK) ==
InputOverlay.OVERLAY_WIIMOTE_CLASSIC)
else if (wiiController == InputOverlay.OVERLAY_WIIMOTE_CLASSIC)
{
boolean[] wiiClassicEnabledButtons = new boolean[14];
String classicSettingBase = "MAIN_BUTTON_TOGGLE_CLASSIC_";
Expand All @@ -739,8 +737,7 @@ else if (mPreferences.getInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCH
{
wiiEnabledButtons[i] = BooleanSetting.valueOf(wiiSettingBase + i).getBoolean(mSettings);
}
if (mPreferences.getInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK) ==
InputOverlay.OVERLAY_WIIMOTE_NUNCHUK)
if (wiiController == InputOverlay.OVERLAY_WIIMOTE_NUNCHUK)
{
builder.setMultiChoiceItems(R.array.nunchukButtons, wiiEnabledButtons,
(dialog, indexSelected, isChecked) -> BooleanSetting
Expand All @@ -765,8 +762,7 @@ public void chooseDoubleTapButton()
{
AlertDialog.Builder builder = new AlertDialog.Builder(this, R.style.DolphinDialogBase);

int currentController =
mPreferences.getInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK);
int currentController = IntSetting.MAIN_WII_OVERLAY_CONTROLLER.getInt(mSettings);

int currentValue = IntSetting.MAIN_DOUBLE_TAP_BUTTON.getInt(mSettings);

Expand All @@ -791,6 +787,9 @@ public void chooseDoubleTapButton()

private void adjustScale()
{
if (overlayControllerWithoutButtons(IntSetting.MAIN_WII_OVERLAY_CONTROLLER.getInt(mSettings)))
return;

LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.dialog_seekbar, null);

Expand Down Expand Up @@ -841,16 +840,16 @@ 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);
builder.setSingleChoiceItems(R.array.controllersEntries,
mPreferences.getInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK),
IntSetting.MAIN_WII_OVERLAY_CONTROLLER.getInt(mSettings),
(dialog, indexSelected) ->
{
editor.putInt("wiiController", indexSelected);
IntSetting.MAIN_WII_OVERLAY_CONTROLLER.setInt(mSettings, indexSelected);

handleWiiOverlayDisablesControllersSetting(indexSelected, false);
handleWiiOverlayDisablesControllersSetting(getApplicationContext(), indexSelected,
false, false);

File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
Expand All @@ -871,15 +870,26 @@ SettingsFile.KEY_WIIMOTE_EXTENSION, getResources()
});
builder.setPositiveButton(R.string.ok, (dialogInterface, i) ->
{
editor.apply();
if (IntSetting.MAIN_WII_OVERLAY_CONTROLLER.getIntGlobal() ==
InputOverlay.OVERLAY_WIIMOTE_REAL &&
!BooleanSetting.MAIN_WIIMOTE_CONTINUOUS_SCANNING.getBooleanGlobal())
{
BooleanSetting.MAIN_WIIMOTE_CONTINUOUS_SCANNING.setBoolean(mSettings, true);

// Immediately save settings so native code can respond to the enabled scanning thread.
mSettings.saveSettings(null, null);
Toast.makeText(this, R.string.wiimote_scanning_enabled, Toast.LENGTH_SHORT).show();
}

mEmulationFragment.refreshInputOverlay();
});

builder.show();
}

// TODO: Make this setting work with custom GameSettings and update setting description.
public static void handleWiiOverlayDisablesControllersSetting(int selection, boolean isFirstRun)
public static void handleWiiOverlayDisablesControllersSetting(Context context, int selection,
boolean emulationStart, boolean freshWiimoteNewIni)
{
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);
Expand All @@ -903,6 +913,19 @@ public static void handleWiiOverlayDisablesControllersSetting(int selection, boo

case InputOverlay.OVERLAY_WIIMOTE_VERTICAL:
case InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL:
NativeLibrary.SetSIDevice(InputOverlay.DISABLED_GAMECUBE_CONTROLLER, 0);
wiimoteNewIni.setInt(SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_TYPE,
SettingsActivityPresenter.WIIMOTE_EMULATED);

if (freshWiimoteNewIni)
{
wiimoteNewIni
.setBoolean(SettingsFile.KEY_WIIMOTE_PLAYER_1,
SettingsFile.KEY_WIIMOTE_ORIENTATION,
selection == InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL);
}
break;

case InputOverlay.OVERLAY_WIIMOTE_NUNCHUK:
case InputOverlay.OVERLAY_WIIMOTE_CLASSIC:
NativeLibrary.SetSIDevice(InputOverlay.DISABLED_GAMECUBE_CONTROLLER, 0);
Expand All @@ -917,8 +940,8 @@ public static void handleWiiOverlayDisablesControllersSetting(int selection, boo
break;
}
}
// The following code is unnecessary on first run.
else if (!isFirstRun)
// The following code is unnecessary on emulation start.
else if (!emulationStart)
{
switch (selection)
{
Expand All @@ -932,6 +955,18 @@ else if (!isFirstRun)

case InputOverlay.OVERLAY_WIIMOTE_VERTICAL:
case InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL:
wiimoteNewIni.setInt(SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_TYPE,
SettingsActivityPresenter.WIIMOTE_EMULATED);

if (freshWiimoteNewIni)
{
wiimoteNewIni
.setBoolean(SettingsFile.KEY_WIIMOTE_PLAYER_1,
SettingsFile.KEY_WIIMOTE_ORIENTATION,
selection == InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL);
}
break;

case InputOverlay.OVERLAY_WIIMOTE_NUNCHUK:
case InputOverlay.OVERLAY_WIIMOTE_CLASSIC:
wiimoteNewIni.setInt(SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_TYPE,
Expand All @@ -944,6 +979,13 @@ else if (!isFirstRun)
break;
}
}

if (freshWiimoteNewIni)
{
wiimoteNewIni.setString(SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_EXTENSION,
context.getResources().getStringArray(R.array.controllersValues)[selection]);
}

wiimoteNewIni.save(wiimoteNewFile);
NativeLibrary.UpdateGCAdapterScanThread();
}
Expand Down Expand Up @@ -1265,4 +1307,18 @@ public void initInputPointer()
if (mDeviceHasTouchScreen)
mEmulationFragment.initInputPointer();
}

private boolean overlayControllerWithoutButtons(int controller)
{
final boolean noButtons = controller == InputOverlay.OVERLAY_GAMECUBE_ADAPTER ||
controller == InputOverlay.OVERLAY_WIIMOTE_REAL ||
controller == InputOverlay.OVERLAY_NONE;

if (noButtons)
{
Toast.makeText(this, R.string.emulation_no_buttons, Toast.LENGTH_SHORT).show();
}

return noButtons;
}
}
@@ -1,6 +1,7 @@
package org.dolphinemu.dolphinemu.features.settings.model;

import org.dolphinemu.dolphinemu.NativeLibrary;
import org.dolphinemu.dolphinemu.overlay.InputOverlay;
import org.dolphinemu.dolphinemu.overlay.InputOverlayPointer;

import java.util.Arrays;
Expand All @@ -22,6 +23,8 @@ public enum IntSetting implements AbstractIntSetting
MAIN_CONTROL_SCALE(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "ControlScale", 50),
MAIN_LAST_PLATFORM_TAB(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "LastPlatformTab", 0),
MAIN_MOTION_CONTROLS(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID, "MotionControls", 1),
MAIN_WII_OVERLAY_CONTROLLER(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID,
"WiiOverlayController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK),

MAIN_DOUBLE_TAP_BUTTON(Settings.FILE_DOLPHIN, Settings.SECTION_INI_ANDROID_OVERLAY_BUTTONS,
"DoubleTapButton",
Expand Down
@@ -1,12 +1,12 @@
package org.dolphinemu.dolphinemu.features.settings.ui;

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

import org.dolphinemu.dolphinemu.R;
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.overlay.InputOverlay;
Expand All @@ -32,7 +32,7 @@ public final class SettingsActivityPresenter

private static final String KEY_SHOULD_SAVE = "should_save";

private SettingsActivityView mView;
private final SettingsActivityView mView;

private Settings mSettings;

Expand Down Expand Up @@ -164,26 +164,23 @@ public void saveState(Bundle outState)

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
{
switch (value)
{
case InputOverlay.DISABLED_GAMECUBE_CONTROLLER:
editor.putInt("wiiController", InputOverlay.OVERLAY_NONE);
IntSetting.MAIN_WII_OVERLAY_CONTROLLER.setInt(mSettings, InputOverlay.OVERLAY_NONE);
break;

case InputOverlay.EMULATED_GAMECUBE_CONTROLLER:
editor.putInt("wiiController", InputOverlay.OVERLAY_GAMECUBE);
IntSetting.MAIN_WII_OVERLAY_CONTROLLER.setInt(mSettings, InputOverlay.OVERLAY_GAMECUBE);
break;

case InputOverlay.GAMECUBE_ADAPTER:
editor.putInt("wiiController", InputOverlay.OVERLAY_GAMECUBE_ADAPTER);
IntSetting.MAIN_WII_OVERLAY_CONTROLLER
.setInt(mSettings, InputOverlay.OVERLAY_GAMECUBE_ADAPTER);
break;
}
editor.commit();
}

if (value != InputOverlay.DISABLED_GAMECUBE_CONTROLLER)
Expand All @@ -196,8 +193,6 @@ 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();
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);

Expand All @@ -210,18 +205,18 @@ public void onWiimoteSettingChanged(MenuTag menuTag, int value)
switch (value)
{
case WIIMOTE_DISABLED:
editor.putInt("wiiController", InputOverlay.OVERLAY_NONE);
IntSetting.MAIN_WII_OVERLAY_CONTROLLER.setInt(mSettings, InputOverlay.OVERLAY_NONE);
break;

case WIIMOTE_EMULATED:
setWiiOverlayControllerByExtension(context, extension);
setWiiOverlayControllerByExtension(mSettings, extension);
break;

case WIIMOTE_REAL:
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_REAL);
IntSetting.MAIN_WII_OVERLAY_CONTROLLER
.setInt(mSettings, InputOverlay.OVERLAY_WIIMOTE_REAL);
break;
}
editor.commit();
}

switch (value)
Expand All @@ -231,7 +226,11 @@ public void onWiimoteSettingChanged(MenuTag menuTag, int value)
break;

case WIIMOTE_REAL:
mView.showToastMessage("Please make sure Continuous Scanning is enabled in Core Settings.");
if (!BooleanSetting.MAIN_WIIMOTE_CONTINUOUS_SCANNING.getBooleanGlobal())
{
BooleanSetting.MAIN_WIIMOTE_CONTINUOUS_SCANNING.setBoolean(mSettings, true);
mView.showToastMessage(context.getString(R.string.wiimote_scanning_enabled));
}
break;
}
}
Expand All @@ -256,17 +255,15 @@ public void onExtensionSettingChanged(MenuTag menuTag, int value)
menuTag.getSubType() - 4);
}

setWiiOverlayControllerByExtension(context, extension);
setWiiOverlayControllerByExtension(mSettings, extension);

Bundle bundle = new Bundle();
bundle.putInt(SettingsFragmentPresenter.ARG_CONTROLLER_TYPE, value);
mView.showSettingsFragment(menuTag, bundle, true, gameId);
}

public static void setWiiOverlayControllerByExtension(Context context, String extension)
public static void setWiiOverlayControllerByExtension(Settings settings, String extension)
{
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);
final SharedPreferences.Editor editor = preferences.edit();
File wiimoteNewFile = SettingsFile.getSettingsFile(Settings.FILE_WIIMOTE);
IniFile wiimoteNewIni = new IniFile(wiimoteNewFile);

Expand All @@ -277,22 +274,25 @@ public static void setWiiOverlayControllerByExtension(Context context, String ex
.getBoolean(SettingsFile.KEY_WIIMOTE_PLAYER_1, SettingsFile.KEY_WIIMOTE_ORIENTATION,
false))
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL);
IntSetting.MAIN_WII_OVERLAY_CONTROLLER
.setInt(settings, InputOverlay.OVERLAY_WIIMOTE_HORIZONTAL);
}
else
{
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_VERTICAL);
IntSetting.MAIN_WII_OVERLAY_CONTROLLER
.setInt(settings, InputOverlay.OVERLAY_WIIMOTE_VERTICAL);
}
break;

case "Nunchuk":
editor.putInt("wiiController", InputOverlay.OVERLAY_WIIMOTE_NUNCHUK);
IntSetting.MAIN_WII_OVERLAY_CONTROLLER
.setInt(settings, InputOverlay.OVERLAY_WIIMOTE_NUNCHUK);
break;

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

0 comments on commit 903933c

Please sign in to comment.