Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9272 from Ebola16/AWP
Android: Expand WiimoteProfileSetting to more setting types
  • Loading branch information
JMC47 committed Dec 10, 2020
2 parents c9e8386 + bd02cab commit cca04d3
Show file tree
Hide file tree
Showing 5 changed files with 187 additions and 122 deletions.
Expand Up @@ -8,6 +8,7 @@
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsActivityView;
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
import org.dolphinemu.dolphinemu.services.GameFileCacheService;
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
import org.dolphinemu.dolphinemu.utils.IniFile;

import java.io.Closeable;
Expand Down Expand Up @@ -57,7 +58,8 @@ public class Settings implements Closeable
private static final String[] configFiles = new String[]{FILE_DOLPHIN, FILE_GFX, FILE_LOGGER,
FILE_WIIMOTE};

private HashMap<String, IniFile> mIniFiles = new HashMap<>();
private Map<String, IniFile> mIniFiles = new HashMap<>();
private final Map<String, IniFile> mWiimoteProfileFiles = new HashMap<>();

private boolean mLoadedRecursiveIsoPathsValue = false;

Expand Down Expand Up @@ -87,6 +89,50 @@ public boolean isGameSpecific()
return !TextUtils.isEmpty(mGameId);
}

public IniFile getWiimoteProfile(String profile, int padID)
{
IniFile wiimoteProfileIni = mWiimoteProfileFiles.computeIfAbsent(profile, profileComputed ->
{
IniFile newIni = new IniFile();
newIni.load(SettingsFile.getWiiProfile(profileComputed), false);
return newIni;
});

if (!wiimoteProfileIni.exists(SECTION_PROFILE))
{
String defaultWiiProfilePath = DirectoryInitialization.getUserDirectory() +
"/Config/Profiles/Wiimote/WiimoteProfile.ini";

wiimoteProfileIni.load(defaultWiiProfilePath, false);

wiimoteProfileIni
.setString(SECTION_PROFILE, "Device", "Android/" + (padID + 4) + "/Touchscreen");
}

return wiimoteProfileIni;
}

public void enableWiimoteProfile(Settings settings, String profile, String profileKey)
{
getWiimoteControlsSection(settings).setString(profileKey, profile);
}

public boolean disableWiimoteProfile(Settings settings, String profileKey)
{
return getWiimoteControlsSection(settings).delete(profileKey);
}

public boolean isWiimoteProfileEnabled(Settings settings, String profile,
String profileKey)
{
return profile.equals(getWiimoteControlsSection(settings).getString(profileKey, ""));
}

private IniFile.Section getWiimoteControlsSection(Settings settings)
{
return settings.getSection(GAME_SETTINGS_PLACEHOLDER_FILE_NAME, SECTION_CONTROLS);
}

public int getWriteLayer()
{
return isGameSpecific() ? NativeConfig.LAYER_LOCAL_GAME : NativeConfig.LAYER_BASE_OR_CURRENT;
Expand Down Expand Up @@ -184,6 +230,11 @@ public void saveSettings(SettingsActivityView view, Context context)

NativeConfig.save(NativeConfig.LAYER_LOCAL_GAME);
}

for (Map.Entry<String, IniFile> entry : mWiimoteProfileFiles.entrySet())
{
entry.getValue().save(SettingsFile.getWiiProfile(entry.getKey()));
}
}

public void clearSettings()
Expand Down
@@ -0,0 +1,66 @@
package org.dolphinemu.dolphinemu.features.settings.model;

import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;

// This stuff is pretty ugly. It's a kind of workaround for certain controller settings
// not actually being available as game-specific settings.
public class WiimoteProfileBooleanSetting implements AbstractBooleanSetting
{
private final int mPadID;

private final String mSection;
private final String mKey;
private final boolean mDefaultValue;

private final String mProfileKey;

private final String mProfile;

public WiimoteProfileBooleanSetting(String gameID, int padID, String section, String key,
boolean defaultValue)
{
mPadID = padID;
mSection = section;
mKey = key;
mDefaultValue = defaultValue;

mProfileKey = SettingsFile.KEY_WIIMOTE_PROFILE + (padID + 1);

mProfile = gameID + "_Wii" + padID;
}

@Override
public boolean isOverridden(Settings settings)
{
return settings.isWiimoteProfileEnabled(settings, mProfile, mProfileKey);
}

@Override
public boolean isRuntimeEditable()
{
return false;
}

@Override
public boolean delete(Settings settings)
{
return settings.disableWiimoteProfile(settings, mProfileKey);
}

@Override
public boolean getBoolean(Settings settings)
{
if (settings.isWiimoteProfileEnabled(settings, mProfile, mProfileKey))
return settings.getWiimoteProfile(mProfile, mPadID).getBoolean(mSection, mKey, mDefaultValue);
else
return mDefaultValue;
}

@Override
public void setBoolean(Settings settings, boolean newValue)
{
settings.getWiimoteProfile(mProfile, mPadID).setBoolean(mSection, mKey, newValue);

settings.enableWiimoteProfile(settings, mProfile, mProfileKey);
}
}

This file was deleted.

@@ -0,0 +1,66 @@
package org.dolphinemu.dolphinemu.features.settings.model;

import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;

// This stuff is pretty ugly. It's a kind of workaround for certain controller settings
// not actually being available as game-specific settings.
public class WiimoteProfileStringSetting implements AbstractStringSetting
{
private final int mPadID;

private final String mSection;
private final String mKey;
private final String mDefaultValue;

private final String mProfileKey;

private final String mProfile;

public WiimoteProfileStringSetting(String gameID, int padID, String section, String key,
String defaultValue)
{
mPadID = padID;
mSection = section;
mKey = key;
mDefaultValue = defaultValue;

mProfileKey = SettingsFile.KEY_WIIMOTE_PROFILE + (padID + 1);

mProfile = gameID + "_Wii" + padID;
}

@Override
public boolean isOverridden(Settings settings)
{
return settings.isWiimoteProfileEnabled(settings, mProfile, mProfileKey);
}

@Override
public boolean isRuntimeEditable()
{
return false;
}

@Override
public boolean delete(Settings settings)
{
return settings.disableWiimoteProfile(settings, mProfileKey);
}

@Override
public String getString(Settings settings)
{
if (settings.isWiimoteProfileEnabled(settings, mProfile, mProfileKey))
return settings.getWiimoteProfile(mProfile, mPadID).getString(mSection, mKey, mDefaultValue);
else
return mDefaultValue;
}

@Override
public void setString(Settings settings, String newValue)
{
settings.getWiimoteProfile(mProfile, mPadID).setString(mSection, mKey, newValue);

settings.enableWiimoteProfile(settings, mProfile, mProfileKey);
}
}
Expand Up @@ -17,7 +17,7 @@
import org.dolphinemu.dolphinemu.features.settings.model.LegacyStringSetting;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
import org.dolphinemu.dolphinemu.features.settings.model.WiimoteProfileSetting;
import org.dolphinemu.dolphinemu.features.settings.model.WiimoteProfileStringSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.CheckBoxSetting;
import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker;
import org.dolphinemu.dolphinemu.features.settings.model.view.HeaderSetting;
Expand Down Expand Up @@ -793,8 +793,8 @@ private void addWiimoteSubSettings(ArrayList<SettingsItem> sl, int wiimoteNumber
}
else
{
extension = new WiimoteProfileSetting(mGameID, wiimoteNumber - 4, Settings.SECTION_PROFILE,
SettingsFile.KEY_WIIMOTE_EXTENSION, defaultExtension);
extension = new WiimoteProfileStringSetting(mGameID, wiimoteNumber - 4,
Settings.SECTION_PROFILE, SettingsFile.KEY_WIIMOTE_EXTENSION, defaultExtension);
}

sl.add(new StringSingleChoiceSetting(extension, R.string.wiimote_extensions, 0,
Expand Down

0 comments on commit cca04d3

Please sign in to comment.