Android: Expand WiimoteProfileSetting to more setting types
This commit is contained in:
parent
c9e83867a1
commit
bd02caba4b
|
@ -8,6 +8,7 @@ import org.dolphinemu.dolphinemu.NativeLibrary;
|
|||
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;
|
||||
|
@ -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;
|
||||
|
||||
|
@ -87,6 +89,50 @@ public class Settings implements Closeable
|
|||
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;
|
||||
|
@ -184,6 +230,11 @@ public class Settings implements Closeable
|
|||
|
||||
NativeConfig.save(NativeConfig.LAYER_LOCAL_GAME);
|
||||
}
|
||||
|
||||
for (Map.Entry<String, IniFile> entry : mWiimoteProfileFiles.entrySet())
|
||||
{
|
||||
entry.getValue().save(SettingsFile.getWiiProfile(entry.getKey()));
|
||||
}
|
||||
}
|
||||
|
||||
public void clearSettings()
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -1,118 +0,0 @@
|
|||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
import org.dolphinemu.dolphinemu.utils.DirectoryInitialization;
|
||||
import org.dolphinemu.dolphinemu.utils.IniFile;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
// This stuff is pretty ugly. It's a kind of workaround for certain controller settings
|
||||
// not actually being available as game-specific settings.
|
||||
//
|
||||
// Warning: The current implementation of this should only be used for one setting at a time.
|
||||
// Because each instance of this class keeps an IniFile around in memory, saving one profile
|
||||
// setting to disk might overwrite changes that were made to other profile settings earlier.
|
||||
// This system shouldn't be used for new settings anyway since the approach is fundamentally messy.
|
||||
public class WiimoteProfileSetting 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;
|
||||
private final File mProfileFile;
|
||||
private final IniFile mProfileIni;
|
||||
|
||||
public WiimoteProfileSetting(String gameID, int padID, String section, String key,
|
||||
String defaultValue)
|
||||
{
|
||||
mPadID = padID;
|
||||
mSection = section;
|
||||
mKey = key;
|
||||
mDefaultValue = defaultValue;
|
||||
|
||||
mProfileKey = SettingsFile.KEY_WIIMOTE_PROFILE + (mPadID + 1);
|
||||
|
||||
mProfile = gameID + "_Wii" + padID;
|
||||
mProfileFile = SettingsFile.getWiiProfile(mProfile);
|
||||
mProfileIni = loadProfile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverridden(Settings settings)
|
||||
{
|
||||
return isProfileEnabled(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRuntimeEditable()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Settings settings)
|
||||
{
|
||||
return disableProfile(settings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getString(Settings settings)
|
||||
{
|
||||
if (isProfileEnabled(settings))
|
||||
return mProfileIni.getString(mSection, mKey, mDefaultValue);
|
||||
else
|
||||
return mDefaultValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setString(Settings settings, String newValue)
|
||||
{
|
||||
mProfileIni.setString(mSection, mKey, newValue);
|
||||
|
||||
mProfileIni.save(mProfileFile);
|
||||
enableProfile(settings);
|
||||
}
|
||||
|
||||
private IniFile loadProfile()
|
||||
{
|
||||
IniFile profileIni = new IniFile();
|
||||
|
||||
if (!profileIni.load(mProfileFile, false))
|
||||
{
|
||||
String defaultWiiProfilePath = DirectoryInitialization.getUserDirectory() +
|
||||
"/Config/Profiles/Wiimote/WiimoteProfile.ini";
|
||||
|
||||
profileIni.load(defaultWiiProfilePath, false);
|
||||
|
||||
profileIni.setString(Settings.SECTION_PROFILE, "Device",
|
||||
"Android/" + (mPadID + 4) + "/Touchscreen");
|
||||
}
|
||||
|
||||
return profileIni;
|
||||
}
|
||||
|
||||
private void enableProfile(Settings settings)
|
||||
{
|
||||
getControlsSection(settings).setString(mProfileKey, mProfile);
|
||||
}
|
||||
|
||||
private boolean disableProfile(Settings settings)
|
||||
{
|
||||
return getControlsSection(settings).delete(mProfileKey);
|
||||
}
|
||||
|
||||
private boolean isProfileEnabled(Settings settings)
|
||||
{
|
||||
return mProfile.equals(getControlsSection(settings).getString(mProfileKey, ""));
|
||||
}
|
||||
|
||||
private IniFile.Section getControlsSection(Settings s)
|
||||
{
|
||||
return s.getSection(Settings.GAME_SETTINGS_PLACEHOLDER_FILE_NAME, Settings.SECTION_CONTROLS);
|
||||
}
|
||||
}
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.LegacyIntSetting;
|
|||
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;
|
||||
|
@ -793,8 +793,8 @@ public final class SettingsFragmentPresenter
|
|||
}
|
||||
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,
|
||||
|
|
Loading…
Reference in New Issue