mirror of
https://github.com/izzy2lost/dolphin.git
synced 2026-06-19 01:16:48 -07:00
Android: Replace Java INI parser with C++ INI parser
Fixes https://bugs.dolphin-emu.org/issues/12096.
This commit is contained in:
+2
-5
@@ -32,7 +32,6 @@ import android.widget.Toast;
|
||||
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
import org.dolphinemu.dolphinemu.fragments.EmulationFragment;
|
||||
@@ -521,10 +520,8 @@ public final class EmulationActivity extends AppCompatActivity
|
||||
showUnpauseEmulationButton();
|
||||
}
|
||||
|
||||
BooleanSetting enableSaveStates =
|
||||
(BooleanSetting) mSettings.getSection(Settings.SECTION_INI_CORE)
|
||||
.getSetting(SettingsFile.KEY_ENABLE_SAVE_STATES);
|
||||
if (enableSaveStates != null && enableSaveStates.getValue())
|
||||
if (mSettings.getSection(SettingsFile.FILE_NAME_DOLPHIN, Settings.SECTION_INI_CORE)
|
||||
.getBoolean(SettingsFile.KEY_ENABLE_SAVE_STATES, false))
|
||||
{
|
||||
menu.findItem(R.id.menu_quicksave).setVisible(true);
|
||||
menu.findItem(R.id.menu_quickload).setVisible(true);
|
||||
|
||||
+7
-4
@@ -9,6 +9,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.InputBindingSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
|
||||
import org.dolphinemu.dolphinemu.utils.ControllerMappingHelper;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
import org.dolphinemu.dolphinemu.utils.TvUtil;
|
||||
@@ -27,6 +28,7 @@ public final class MotionAlertDialog extends AlertDialog
|
||||
private final ArrayList<Float> mPreviousValues = new ArrayList<>();
|
||||
private int mPrevDeviceId = 0;
|
||||
private boolean mWaitingForEvent = true;
|
||||
private SettingsAdapter mAdapter;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
@@ -34,11 +36,12 @@ public final class MotionAlertDialog extends AlertDialog
|
||||
* @param context The current {@link Context}.
|
||||
* @param setting The Preference to show this dialog for.
|
||||
*/
|
||||
public MotionAlertDialog(Context context, InputBindingSetting setting)
|
||||
public MotionAlertDialog(Context context, InputBindingSetting setting, SettingsAdapter adapter)
|
||||
{
|
||||
super(context);
|
||||
|
||||
this.setting = setting;
|
||||
mAdapter = adapter;
|
||||
}
|
||||
|
||||
public boolean onKeyEvent(int keyCode, KeyEvent event)
|
||||
@@ -48,7 +51,7 @@ public final class MotionAlertDialog extends AlertDialog
|
||||
{
|
||||
if (!ControllerMappingHelper.shouldKeyBeIgnored(event.getDevice(), keyCode))
|
||||
{
|
||||
setting.onKeyInput(event);
|
||||
setting.onKeyInput(mAdapter.getSettings(), event);
|
||||
dismiss();
|
||||
}
|
||||
// Even if we ignore the key, we still consume it. Thus return true regardless.
|
||||
@@ -63,7 +66,7 @@ public final class MotionAlertDialog extends AlertDialog
|
||||
// Option to clear by long back is only needed on the TV interface
|
||||
if (TvUtil.isLeanback(getContext()) && keyCode == KeyEvent.KEYCODE_BACK)
|
||||
{
|
||||
setting.clearValue();
|
||||
setting.clearValue(mAdapter.getSettings());
|
||||
dismiss();
|
||||
return true;
|
||||
}
|
||||
@@ -158,7 +161,7 @@ public final class MotionAlertDialog extends AlertDialog
|
||||
if (numMovedAxis == 1)
|
||||
{
|
||||
mWaitingForEvent = false;
|
||||
setting.onMotionInput(input, lastMovedRange, lastMovedDir);
|
||||
setting.onMotionInput(mAdapter.getSettings(), input, lastMovedRange, lastMovedDir);
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
public final class BooleanSetting extends Setting
|
||||
{
|
||||
private boolean mValue;
|
||||
|
||||
public BooleanSetting(String key, String section, boolean value)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public boolean getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setValue(boolean value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString()
|
||||
{
|
||||
return mValue ? "True" : "False";
|
||||
}
|
||||
}
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
public final class FloatSetting extends Setting
|
||||
{
|
||||
private float mValue;
|
||||
|
||||
public FloatSetting(String key, String section, float value)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public float getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setValue(float value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString()
|
||||
{
|
||||
return Float.toString(mValue);
|
||||
}
|
||||
}
|
||||
-44
@@ -1,44 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
||||
|
||||
public final class IntSetting extends Setting
|
||||
{
|
||||
private int mValue;
|
||||
private MenuTag menuTag;
|
||||
|
||||
public IntSetting(String key, String section, int value)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public IntSetting(String key, String section, int value, MenuTag menuTag)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
this.menuTag = menuTag;
|
||||
}
|
||||
|
||||
public int getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setValue(int value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString()
|
||||
{
|
||||
return Integer.toString(mValue);
|
||||
}
|
||||
|
||||
public MenuTag getMenuTag()
|
||||
{
|
||||
return menuTag;
|
||||
}
|
||||
|
||||
}
|
||||
-46
@@ -1,46 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
/**
|
||||
* Abstraction for a setting item as read from / written to Dolphin's configuration ini files.
|
||||
* These files generally consist of a key/value pair, though the type of value is ambiguous and
|
||||
* must be inferred at read-time. The type of value determines which child of this class is used
|
||||
* to represent the Setting.
|
||||
*/
|
||||
public abstract class Setting
|
||||
{
|
||||
private String mKey;
|
||||
private String mSection;
|
||||
|
||||
/**
|
||||
* Base constructor.
|
||||
*
|
||||
* @param key Everything to the left of the = in a line from the ini file.
|
||||
* @param section The corresponding recent section header; e.g. [Core] or [Enhancements] without the brackets.
|
||||
*/
|
||||
public Setting(String key, String section)
|
||||
{
|
||||
mKey = key;
|
||||
mSection = section;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The identifier used to write this setting to the ini file.
|
||||
*/
|
||||
public String getKey()
|
||||
{
|
||||
return mKey;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The name of the header under which this Setting should be written in the ini file.
|
||||
*/
|
||||
public String getSection()
|
||||
{
|
||||
return mSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A representation of this Setting's backing value converted to a String (e.g. for serialization).
|
||||
*/
|
||||
public abstract String getValueAsString();
|
||||
}
|
||||
-63
@@ -1,63 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* A semantically-related group of Settings objects. These Settings are
|
||||
* internally stored as a HashMap.
|
||||
*/
|
||||
public final class SettingSection
|
||||
{
|
||||
private String mName;
|
||||
|
||||
private HashMap<String, Setting> mSettings = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Create a new SettingSection with no Settings in it.
|
||||
*
|
||||
* @param name The header of this section; e.g. [Core] or [Enhancements] without the brackets.
|
||||
*/
|
||||
public SettingSection(String name)
|
||||
{
|
||||
mName = name;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
return mName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method; inserts a value directly into the backing HashMap.
|
||||
*
|
||||
* @param setting The Setting to be inserted.
|
||||
*/
|
||||
public void putSetting(Setting setting)
|
||||
{
|
||||
mSettings.put(setting.getKey(), setting);
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method; gets a value directly from the backing HashMap.
|
||||
*
|
||||
* @param key Used to retrieve the Setting.
|
||||
* @return A Setting object (you should probably cast this before using)
|
||||
*/
|
||||
public Setting getSetting(String key)
|
||||
{
|
||||
return mSettings.get(key);
|
||||
}
|
||||
|
||||
public HashMap<String, Setting> getSettings()
|
||||
{
|
||||
return mSettings;
|
||||
}
|
||||
|
||||
public void mergeSection(SettingSection settingSection)
|
||||
{
|
||||
for (Setting setting : settingSection.mSettings.values())
|
||||
{
|
||||
putSetting(setting);
|
||||
}
|
||||
}
|
||||
}
|
||||
+39
-95
@@ -48,73 +48,45 @@ public class Settings
|
||||
|
||||
public static final String SECTION_ANALYTICS = "Analytics";
|
||||
|
||||
public static final String GAME_SETTINGS_PLACEHOLDER_FILE_NAME = "";
|
||||
|
||||
private String gameId;
|
||||
|
||||
private static final Map<String, List<String>> configFileSectionsMap = new HashMap<>();
|
||||
private static final String[] configFiles = new String[]{SettingsFile.FILE_NAME_DOLPHIN,
|
||||
SettingsFile.FILE_NAME_GFX, SettingsFile.FILE_NAME_LOGGER,
|
||||
SettingsFile.FILE_NAME_WIIMOTE};
|
||||
|
||||
static
|
||||
private HashMap<String, IniFile> mIniFiles = new HashMap<>();
|
||||
|
||||
private IniFile getGameSpecificFile()
|
||||
{
|
||||
configFileSectionsMap.put(SettingsFile.FILE_NAME_DOLPHIN,
|
||||
Arrays
|
||||
.asList(SECTION_INI_ANDROID, SECTION_INI_GENERAL, SECTION_INI_CORE,
|
||||
SECTION_INI_INTERFACE,
|
||||
SECTION_INI_DSP, SECTION_BINDINGS, SECTION_ANALYTICS, SECTION_DEBUG));
|
||||
configFileSectionsMap.put(SettingsFile.FILE_NAME_GFX,
|
||||
Arrays.asList(SECTION_GFX_SETTINGS, SECTION_GFX_ENHANCEMENTS, SECTION_GFX_HACKS,
|
||||
SECTION_STEREOSCOPY));
|
||||
configFileSectionsMap.put(SettingsFile.FILE_NAME_LOGGER,
|
||||
Arrays.asList(SECTION_LOGGER_LOGS, SECTION_LOGGER_OPTIONS));
|
||||
configFileSectionsMap.put(SettingsFile.FILE_NAME_WIIMOTE,
|
||||
Arrays.asList(SECTION_WIIMOTE + 1, SECTION_WIIMOTE + 2, SECTION_WIIMOTE + 3,
|
||||
SECTION_WIIMOTE + 4));
|
||||
if (TextUtils.isEmpty(gameId) || mIniFiles.size() != 1)
|
||||
throw new IllegalStateException();
|
||||
|
||||
return mIniFiles.get(GAME_SETTINGS_PLACEHOLDER_FILE_NAME);
|
||||
}
|
||||
|
||||
/**
|
||||
* A HashMap<String, SettingSection> that constructs a new SettingSection instead of returning null
|
||||
* when getting a key not already in the map
|
||||
*/
|
||||
public static final class SettingsSectionMap extends HashMap<String, SettingSection>
|
||||
public IniFile.Section getSection(String fileName, String sectionName)
|
||||
{
|
||||
@Override
|
||||
public SettingSection get(Object key)
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
{
|
||||
if (!(key instanceof String))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
String stringKey = (String) key;
|
||||
|
||||
if (!super.containsKey(stringKey))
|
||||
{
|
||||
SettingSection section = new SettingSection(stringKey);
|
||||
super.put(stringKey, section);
|
||||
return section;
|
||||
}
|
||||
return super.get(key);
|
||||
return mIniFiles.get(fileName).getOrCreateSection(sectionName);
|
||||
}
|
||||
else
|
||||
{
|
||||
return getGameSpecificFile()
|
||||
.getOrCreateSection(SettingsFile.mapSectionNameFromIni(sectionName));
|
||||
}
|
||||
}
|
||||
|
||||
private HashMap<String, SettingSection> sections = new Settings.SettingsSectionMap();
|
||||
|
||||
public SettingSection getSection(String sectionName)
|
||||
{
|
||||
return sections.get(sectionName);
|
||||
}
|
||||
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return sections.isEmpty();
|
||||
}
|
||||
|
||||
public HashMap<String, SettingSection> getSections()
|
||||
{
|
||||
return sections;
|
||||
return mIniFiles.isEmpty();
|
||||
}
|
||||
|
||||
public void loadSettings(SettingsActivityView view)
|
||||
{
|
||||
sections = new Settings.SettingsSectionMap();
|
||||
mIniFiles = new HashMap<>();
|
||||
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
{
|
||||
@@ -128,46 +100,24 @@ public class Settings
|
||||
|
||||
private void loadDolphinSettings(SettingsActivityView view)
|
||||
{
|
||||
for (Map.Entry<String, List<String>> entry : configFileSectionsMap.entrySet())
|
||||
for (String fileName : configFiles)
|
||||
{
|
||||
String fileName = entry.getKey();
|
||||
sections.putAll(SettingsFile.readFile(fileName, view));
|
||||
IniFile ini = new IniFile();
|
||||
SettingsFile.readFile(fileName, ini, view);
|
||||
mIniFiles.put(fileName, ini);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadGenericGameSettings(String gameId, SettingsActivityView view)
|
||||
{
|
||||
// generic game settings
|
||||
mergeSections(SettingsFile.readGenericGameSettings(gameId, view));
|
||||
mergeSections(SettingsFile.readGenericGameSettingsForAllRegions(gameId, view));
|
||||
}
|
||||
|
||||
private void loadCustomGameSettings(String gameId, SettingsActivityView view)
|
||||
{
|
||||
// custom game settings
|
||||
mergeSections(SettingsFile.readCustomGameSettings(gameId, view));
|
||||
IniFile ini = new IniFile();
|
||||
SettingsFile.readCustomGameSettings(gameId, ini, view);
|
||||
mIniFiles.put(GAME_SETTINGS_PLACEHOLDER_FILE_NAME, ini);
|
||||
}
|
||||
|
||||
public void loadWiimoteProfile(String gameId, String padId)
|
||||
public void loadWiimoteProfile(String gameId, int padId)
|
||||
{
|
||||
mergeSections(SettingsFile.readWiimoteProfile(gameId, padId));
|
||||
}
|
||||
|
||||
private void mergeSections(HashMap<String, SettingSection> updatedSections)
|
||||
{
|
||||
for (Map.Entry<String, SettingSection> entry : updatedSections.entrySet())
|
||||
{
|
||||
if (sections.containsKey(entry.getKey()))
|
||||
{
|
||||
SettingSection originalSection = sections.get(entry.getKey());
|
||||
SettingSection updatedSection = entry.getValue();
|
||||
originalSection.mergeSection(updatedSection);
|
||||
}
|
||||
else
|
||||
{
|
||||
sections.put(entry.getKey(), entry.getValue());
|
||||
}
|
||||
}
|
||||
SettingsFile.readWiimoteProfile(gameId, getGameSpecificFile(), padId);
|
||||
}
|
||||
|
||||
public void loadSettings(String gameId, SettingsActivityView view)
|
||||
@@ -182,17 +132,9 @@ public class Settings
|
||||
{
|
||||
view.showToastMessage("Saved settings to INI files");
|
||||
|
||||
for (Map.Entry<String, List<String>> entry : configFileSectionsMap.entrySet())
|
||||
for (Map.Entry<String, IniFile> entry : mIniFiles.entrySet())
|
||||
{
|
||||
String fileName = entry.getKey();
|
||||
List<String> sectionNames = entry.getValue();
|
||||
TreeMap<String, SettingSection> iniSections = new TreeMap<>();
|
||||
for (String section : sectionNames)
|
||||
{
|
||||
iniSections.put(section, sections.get(section));
|
||||
}
|
||||
|
||||
SettingsFile.saveFile(fileName, iniSections, view);
|
||||
SettingsFile.saveFile(entry.getKey(), entry.getValue(), view);
|
||||
}
|
||||
|
||||
if (modifiedSettings.contains(SettingsFile.KEY_DSP_ENGINE))
|
||||
@@ -240,13 +182,16 @@ public class Settings
|
||||
{
|
||||
// custom game settings
|
||||
view.showToastMessage("Saved settings for " + gameId);
|
||||
SettingsFile.saveCustomGameSettings(gameId, sections);
|
||||
SettingsFile.saveCustomGameSettings(gameId, getGameSpecificFile());
|
||||
}
|
||||
}
|
||||
|
||||
public void clearSettings()
|
||||
{
|
||||
sections.clear();
|
||||
for (String fileName : mIniFiles.keySet())
|
||||
{
|
||||
mIniFiles.put(fileName, new IniFile());
|
||||
}
|
||||
}
|
||||
|
||||
public boolean gameIniContainsJunk()
|
||||
@@ -272,7 +217,6 @@ public class Settings
|
||||
if (TextUtils.isEmpty(gameId))
|
||||
return false;
|
||||
|
||||
SettingSection interfaceSection = sections.get("Interface");
|
||||
return interfaceSection != null && interfaceSection.getSetting("ThemeName") != null;
|
||||
return getSection(SettingsFile.FILE_NAME_DOLPHIN, SECTION_INI_INTERFACE).exists("ThemeName");
|
||||
}
|
||||
}
|
||||
|
||||
-28
@@ -1,28 +0,0 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model;
|
||||
|
||||
public final class StringSetting extends Setting
|
||||
{
|
||||
private String mValue;
|
||||
|
||||
public StringSetting(String key, String section, String value)
|
||||
{
|
||||
super(key, section);
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
|
||||
public void setValue(String value)
|
||||
{
|
||||
mValue = value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValueAsString()
|
||||
{
|
||||
return mValue;
|
||||
}
|
||||
}
|
||||
+21
-33
@@ -1,51 +1,39 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.BooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
|
||||
public final class CheckBoxSetting extends SettingsItem
|
||||
{
|
||||
private boolean mDefaultValue;
|
||||
|
||||
public CheckBoxSetting(String key, String section, int titleId, int descriptionId,
|
||||
boolean defaultValue, Setting setting)
|
||||
public CheckBoxSetting(String file, String section, String key, int titleId, int descriptionId,
|
||||
boolean defaultValue)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mDefaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public boolean isChecked()
|
||||
public boolean isChecked(Settings settings)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof BooleanSetting))
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
|
||||
BooleanSetting setting = (BooleanSetting) getSetting();
|
||||
return setting.getValue();
|
||||
return invertIfNeeded(settings.getSection(getFile(), getSection())
|
||||
.getBoolean(getKey(), invertIfNeeded(mDefaultValue)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing boolean. If that boolean was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param checked Pretty self explanatory.
|
||||
* @return null if overwritten successfully; otherwise, a newly created BooleanSetting.
|
||||
*/
|
||||
public BooleanSetting setChecked(boolean checked)
|
||||
public void setChecked(Settings settings, boolean checked)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof BooleanSetting))
|
||||
{
|
||||
BooleanSetting setting = new BooleanSetting(getKey(), getSection(), checked);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
BooleanSetting setting = (BooleanSetting) getSetting();
|
||||
setting.setValue(checked);
|
||||
return null;
|
||||
}
|
||||
settings.getSection(getFile(), getSection()).setBoolean(getKey(), invertIfNeeded(checked));
|
||||
}
|
||||
|
||||
private boolean invertIfNeeded(boolean x)
|
||||
{
|
||||
return isInverted() ? !x : x;
|
||||
}
|
||||
|
||||
private boolean isInverted()
|
||||
{
|
||||
return getKey().equals(SettingsFile.KEY_SKIP_EFB) ||
|
||||
getKey().equals(SettingsFile.KEY_IGNORE_FORMAT);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+6
-25
@@ -1,42 +1,23 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
|
||||
import java.io.File;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
public final class FilePicker extends SettingsItem
|
||||
{
|
||||
private String mFile;
|
||||
private String mDefaultValue;
|
||||
private int mRequestType;
|
||||
|
||||
public FilePicker(String file, String key, String section, int titleId, int descriptionId,
|
||||
String defaultVault, int requestType, Setting setting)
|
||||
public FilePicker(String file, String section, String key, int titleId, int descriptionId,
|
||||
String defaultVault, int requestType)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
mFile = file;
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mDefaultValue = defaultVault;
|
||||
mRequestType = requestType;
|
||||
}
|
||||
|
||||
public File getFile()
|
||||
public String getSelectedValue(Settings settings)
|
||||
{
|
||||
return SettingsFile.getSettingsFile(mFile);
|
||||
}
|
||||
|
||||
public String getSelectedValue()
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
return setting.getValue();
|
||||
}
|
||||
return settings.getSection(getFile(), getSection()).getString(getKey(), mDefaultValue);
|
||||
}
|
||||
|
||||
public int getRequestType()
|
||||
|
||||
+39
@@ -0,0 +1,39 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
|
||||
public final class FloatSliderSetting extends SliderSetting
|
||||
{
|
||||
private float mDefaultValue;
|
||||
|
||||
public FloatSliderSetting(String file, String section, String key, int titleId, int descriptionId,
|
||||
int max, String units, float defaultValue)
|
||||
{
|
||||
super(file, section, key, titleId, descriptionId, max, units);
|
||||
mDefaultValue = defaultValue;
|
||||
|
||||
if (isPercentSetting())
|
||||
mDefaultValue /= 100;
|
||||
}
|
||||
|
||||
public int getSelectedValue(Settings settings)
|
||||
{
|
||||
float value = settings.getSection(getFile(), getSection()).getFloat(getKey(), mDefaultValue);
|
||||
return Math.round(isPercentSetting() ? value * 100 : value);
|
||||
}
|
||||
|
||||
public void setSelectedValue(Settings settings, float selection)
|
||||
{
|
||||
if (isPercentSetting())
|
||||
selection /= 100;
|
||||
|
||||
settings.getSection(getFile(), getSection()).setFloat(getKey(), selection);
|
||||
}
|
||||
|
||||
private boolean isPercentSetting()
|
||||
{
|
||||
return getKey().equals(SettingsFile.KEY_OVERCLOCK_PERCENT)
|
||||
|| getKey().equals(SettingsFile.KEY_SPEED_LIMIT);
|
||||
}
|
||||
}
|
||||
+2
-4
@@ -1,12 +1,10 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
|
||||
public final class HeaderSetting extends SettingsItem
|
||||
{
|
||||
public HeaderSetting(String key, Setting setting, int titleId, int descriptionId)
|
||||
public HeaderSetting(String key, int titleId, int descriptionId)
|
||||
{
|
||||
super(key, null, setting, titleId, descriptionId);
|
||||
super(null, null, key, titleId, descriptionId);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+14
-40
@@ -6,29 +6,21 @@ import android.view.InputDevice;
|
||||
import android.view.KeyEvent;
|
||||
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
public class InputBindingSetting extends SettingsItem
|
||||
{
|
||||
private String gameId;
|
||||
|
||||
public InputBindingSetting(String key, String section, int titleId, Setting setting,
|
||||
String gameId)
|
||||
public InputBindingSetting(String file, String section, String key, int titleId, String gameId)
|
||||
{
|
||||
super(key, section, setting, titleId, 0);
|
||||
super(file, section, key, titleId, 0);
|
||||
this.gameId = gameId;
|
||||
}
|
||||
|
||||
public String getValue()
|
||||
public String getValue(Settings settings)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
return setting.getValue();
|
||||
return settings.getSection(getFile(), getSection()).getString(getKey(), "");
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -37,12 +29,12 @@ public class InputBindingSetting extends SettingsItem
|
||||
*
|
||||
* @param keyEvent KeyEvent of this key press.
|
||||
*/
|
||||
public void onKeyInput(KeyEvent keyEvent)
|
||||
public void onKeyInput(Settings settings, KeyEvent keyEvent)
|
||||
{
|
||||
InputDevice device = keyEvent.getDevice();
|
||||
String bindStr = "Device '" + device.getDescriptor() + "'-Button " + keyEvent.getKeyCode();
|
||||
String uiString = device.getName() + ": Button " + keyEvent.getKeyCode();
|
||||
setValue(bindStr, uiString);
|
||||
setValue(settings, bindStr, uiString);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -53,23 +45,16 @@ public class InputBindingSetting extends SettingsItem
|
||||
* @param motionRange MotionRange of the movement
|
||||
* @param axisDir Either '-' or '+'
|
||||
*/
|
||||
public void onMotionInput(InputDevice device, InputDevice.MotionRange motionRange,
|
||||
char axisDir)
|
||||
public void onMotionInput(Settings settings, InputDevice device,
|
||||
InputDevice.MotionRange motionRange, char axisDir)
|
||||
{
|
||||
String bindStr =
|
||||
"Device '" + device.getDescriptor() + "'-Axis " + motionRange.getAxis() + axisDir;
|
||||
String uiString = device.getName() + ": Axis " + motionRange.getAxis() + axisDir;
|
||||
setValue(bindStr, uiString);
|
||||
setValue(settings, bindStr, uiString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing string. If that string was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param bind The input that will be bound
|
||||
* @return null if overwritten successfully; otherwise, a newly created StringSetting.
|
||||
*/
|
||||
public StringSetting setValue(String bind, String ui)
|
||||
public void setValue(Settings settings, String bind, String ui)
|
||||
{
|
||||
SharedPreferences
|
||||
preferences =
|
||||
@@ -78,23 +63,12 @@ public class InputBindingSetting extends SettingsItem
|
||||
editor.putString(getKey() + gameId, ui);
|
||||
editor.apply();
|
||||
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
StringSetting setting = new StringSetting(getKey(), getSection(), bind);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
setting.setValue(bind);
|
||||
return null;
|
||||
}
|
||||
settings.getSection(getFile(), getSection()).setString(getKey(), bind);
|
||||
}
|
||||
|
||||
public void clearValue()
|
||||
public void clearValue(Settings settings)
|
||||
{
|
||||
setValue("", "");
|
||||
setValue(settings, "", "");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
public final class IntSliderSetting extends SliderSetting
|
||||
{
|
||||
private int mDefaultValue;
|
||||
|
||||
public IntSliderSetting(String file, String section, String key, int titleId, int descriptionId,
|
||||
int max, String units, int defaultValue)
|
||||
{
|
||||
super(file, section, key, titleId, descriptionId, max, units);
|
||||
mDefaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public int getSelectedValue(Settings settings)
|
||||
{
|
||||
return settings.getSection(getFile(), getSection()).getInt(getKey(), mDefaultValue);
|
||||
}
|
||||
|
||||
public void setSelectedValue(Settings settings, int selection)
|
||||
{
|
||||
settings.getSection(getFile(), getSection()).setInt(getKey(), selection);
|
||||
}
|
||||
}
|
||||
+11
-27
@@ -6,62 +6,46 @@ import android.view.KeyEvent;
|
||||
|
||||
import org.dolphinemu.dolphinemu.DolphinApplication;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.utils.Rumble;
|
||||
|
||||
public class RumbleBindingSetting extends InputBindingSetting
|
||||
{
|
||||
|
||||
public RumbleBindingSetting(String key, String section, int titleId, Setting setting,
|
||||
String gameId)
|
||||
public RumbleBindingSetting(String file, String section, String key, int titleId, String gameId)
|
||||
{
|
||||
super(key, section, titleId, setting, gameId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getValue()
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof StringSetting))
|
||||
{
|
||||
return "";
|
||||
}
|
||||
|
||||
StringSetting setting = (StringSetting) getSetting();
|
||||
return setting.getValue();
|
||||
super(file, section, key, titleId, gameId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Just need the device when saving rumble.
|
||||
*/
|
||||
@Override
|
||||
public void onKeyInput(KeyEvent keyEvent)
|
||||
public void onKeyInput(Settings settings, KeyEvent keyEvent)
|
||||
{
|
||||
saveRumble(keyEvent.getDevice());
|
||||
saveRumble(settings, keyEvent.getDevice());
|
||||
}
|
||||
|
||||
/**
|
||||
* Just need the device when saving rumble.
|
||||
*/
|
||||
@Override
|
||||
public void onMotionInput(InputDevice device,
|
||||
InputDevice.MotionRange motionRange,
|
||||
char axisDir)
|
||||
public void onMotionInput(Settings settings, InputDevice device,
|
||||
InputDevice.MotionRange motionRange, char axisDir)
|
||||
{
|
||||
saveRumble(device);
|
||||
saveRumble(settings, device);
|
||||
}
|
||||
|
||||
private void saveRumble(InputDevice device)
|
||||
private void saveRumble(Settings settings, InputDevice device)
|
||||
{
|
||||
Vibrator vibrator = device.getVibrator();
|
||||
if (vibrator != null && vibrator.hasVibrator())
|
||||
{
|
||||
setValue(device.getDescriptor(), device.getName());
|
||||
setValue(settings, device.getDescriptor(), device.getName());
|
||||
Rumble.doRumble(vibrator);
|
||||
}
|
||||
else
|
||||
{
|
||||
setValue("",
|
||||
setValue(settings, "",
|
||||
DolphinApplication.getAppContext().getString(R.string.rumble_not_found));
|
||||
}
|
||||
}
|
||||
|
||||
+28
-45
@@ -1,14 +1,11 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.SettingsAdapter;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
|
||||
/**
|
||||
* ViewModel abstraction for an Item in the RecyclerView powering SettingsFragments.
|
||||
* Each one corresponds to a {@link Setting} object, so this class's subclasses
|
||||
* should vaguely correspond to those subclasses. There are a few with multiple analogues
|
||||
* and a few with none (Headers, for example, do not correspond to anything in the ini
|
||||
* file.)
|
||||
* Most of them correspond to a single line in an INI file, but there are a few with multiple
|
||||
* analogues and a few with none (Headers, for example, do not correspond to anything on disk.)
|
||||
*/
|
||||
public abstract class SettingsItem
|
||||
{
|
||||
@@ -24,36 +21,50 @@ public abstract class SettingsItem
|
||||
public static final int TYPE_FILE_PICKER = 9;
|
||||
public static final int TYPE_CONFIRM_RUNNABLE = 10;
|
||||
|
||||
private String mKey;
|
||||
private String mFile;
|
||||
private String mSection;
|
||||
|
||||
private Setting mSetting;
|
||||
private String mKey;
|
||||
|
||||
private int mNameId;
|
||||
private int mDescriptionId;
|
||||
|
||||
/**
|
||||
* Base constructor. Takes a key / section name in case the third parameter, the Setting,
|
||||
* is null; in which case, one can be constructed and saved using the key / section.
|
||||
* Base constructor.
|
||||
*
|
||||
* @param key Identifier for the Setting represented by this Item.
|
||||
* @param file File to which the Setting belongs.
|
||||
* @param section Section to which the Setting belongs.
|
||||
* @param setting A possibly-null backing Setting, to be modified on UI events.
|
||||
* @param key Identifier for the Setting represented by this Item.
|
||||
* @param nameId Resource ID for a text string to be displayed as this setting's name.
|
||||
* @param descriptionId Resource ID for a text string to be displayed as this setting's description.
|
||||
*/
|
||||
|
||||
public SettingsItem(String key, String section, Setting setting, int nameId, int descriptionId)
|
||||
public SettingsItem(String file, String section, String key, int nameId, int descriptionId)
|
||||
{
|
||||
mKey = key;
|
||||
mFile = file;
|
||||
mSection = section;
|
||||
mSetting = setting;
|
||||
mKey = key;
|
||||
mNameId = nameId;
|
||||
mDescriptionId = descriptionId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The identifier for the backing Setting.
|
||||
* @return The file in which the backing setting belongs.
|
||||
*/
|
||||
public String getFile()
|
||||
{
|
||||
return mFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The header under which the backing setting belongs.
|
||||
*/
|
||||
public String getSection()
|
||||
{
|
||||
return mSection;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The identifier for the backing setting.
|
||||
*/
|
||||
public String getKey()
|
||||
{
|
||||
@@ -61,35 +72,7 @@ public abstract class SettingsItem
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The header under which the backing Setting belongs.
|
||||
*/
|
||||
public String getSection()
|
||||
{
|
||||
return mSection;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return The backing Setting, possibly null.
|
||||
*/
|
||||
public Setting getSetting()
|
||||
{
|
||||
return mSetting;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the backing setting with a new one. Generally used in cases where
|
||||
* the backing setting is null.
|
||||
*
|
||||
* @param setting A non-null Setting.
|
||||
*/
|
||||
public void setSetting(Setting setting)
|
||||
{
|
||||
mSetting = setting;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return A resource ID for a text string representing this Setting's name.
|
||||
* @return A resource ID for a text string representing this setting's name.
|
||||
*/
|
||||
public int getNameId()
|
||||
{
|
||||
|
||||
+11
-38
@@ -1,7 +1,6 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
||||
|
||||
public final class SingleChoiceSetting extends SettingsItem
|
||||
@@ -12,20 +11,20 @@ public final class SingleChoiceSetting extends SettingsItem
|
||||
private int mValuesId;
|
||||
private MenuTag menuTag;
|
||||
|
||||
public SingleChoiceSetting(String key, String section, int titleId, int descriptionId,
|
||||
int choicesId, int valuesId, int defaultValue, Setting setting, MenuTag menuTag)
|
||||
public SingleChoiceSetting(String file, String section, String key, int titleId,
|
||||
int descriptionId, int choicesId, int valuesId, int defaultValue, MenuTag menuTag)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mValuesId = valuesId;
|
||||
mChoicesId = choicesId;
|
||||
mDefaultValue = defaultValue;
|
||||
this.menuTag = menuTag;
|
||||
}
|
||||
|
||||
public SingleChoiceSetting(String key, String section, int titleId, int descriptionId,
|
||||
int choicesId, int valuesId, int defaultValue, Setting setting)
|
||||
public SingleChoiceSetting(String file, String section, String key, int titleId,
|
||||
int descriptionId, int choicesId, int valuesId, int defaultValue)
|
||||
{
|
||||
this(key, section, titleId, descriptionId, choicesId, valuesId, defaultValue, setting, null);
|
||||
this(file, section, key, titleId, descriptionId, choicesId, valuesId, defaultValue, null);
|
||||
}
|
||||
|
||||
public int getChoicesId()
|
||||
@@ -38,17 +37,9 @@ public final class SingleChoiceSetting extends SettingsItem
|
||||
return mValuesId;
|
||||
}
|
||||
|
||||
public int getSelectedValue()
|
||||
public int getSelectedValue(Settings settings)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
return setting.getValue();
|
||||
}
|
||||
return settings.getSection(getFile(), getSection()).getInt(getKey(), mDefaultValue);
|
||||
}
|
||||
|
||||
public MenuTag getMenuTag()
|
||||
@@ -56,27 +47,9 @@ public final class SingleChoiceSetting extends SettingsItem
|
||||
return menuTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing int. If that int was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param selection New value of the int.
|
||||
* @return null if overwritten successfully otherwise; a newly created IntSetting.
|
||||
*/
|
||||
public IntSetting setSelectedValue(int selection)
|
||||
public void setSelectedValue(Settings settings, int selection)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
setting.setValue(selection);
|
||||
return null;
|
||||
}
|
||||
settings.getSection(getFile(), getSection()).setInt(getKey(), selection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+14
-43
@@ -1,7 +1,6 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.ui.MenuTag;
|
||||
|
||||
public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
||||
@@ -14,12 +13,11 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
||||
private int mDescriptionValuesId;
|
||||
private MenuTag menuTag;
|
||||
|
||||
public SingleChoiceSettingDynamicDescriptions(String key, String section, int titleId,
|
||||
int descriptionId,
|
||||
int choicesId, int valuesId, int descriptionChoicesId, int descriptionValuesId,
|
||||
int defaultValue, Setting setting, MenuTag menuTag)
|
||||
public SingleChoiceSettingDynamicDescriptions(String file, String section, String key,
|
||||
int titleId, int descriptionId, int choicesId, int valuesId, int descriptionChoicesId,
|
||||
int descriptionValuesId, int defaultValue, MenuTag menuTag)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, titleId, descriptionId);
|
||||
mValuesId = valuesId;
|
||||
mChoicesId = choicesId;
|
||||
mDescriptionChoicesId = descriptionChoicesId;
|
||||
@@ -28,13 +26,12 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
||||
this.menuTag = menuTag;
|
||||
}
|
||||
|
||||
public SingleChoiceSettingDynamicDescriptions(String key, String section, int titleId,
|
||||
int descriptionId,
|
||||
int choicesId, int valuesId, int descriptionChoicesId, int descriptionValuesId,
|
||||
int defaultValue, Setting setting)
|
||||
public SingleChoiceSettingDynamicDescriptions(String file, String section, String key,
|
||||
int titleId, int descriptionId, int choicesId, int valuesId, int descriptionChoicesId,
|
||||
int descriptionValuesId, int defaultValue)
|
||||
{
|
||||
this(key, section, titleId, descriptionId, choicesId, valuesId, descriptionChoicesId,
|
||||
descriptionValuesId, defaultValue, setting, null);
|
||||
this(file, section, key, titleId, descriptionId, choicesId, valuesId, descriptionChoicesId,
|
||||
descriptionValuesId, defaultValue, null);
|
||||
}
|
||||
|
||||
public int getChoicesId()
|
||||
@@ -57,17 +54,9 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
||||
return mDescriptionValuesId;
|
||||
}
|
||||
|
||||
public int getSelectedValue()
|
||||
public int getSelectedValue(Settings settings)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
return setting.getValue();
|
||||
}
|
||||
return settings.getSection(getFile(), getSection()).getInt(getKey(), mDefaultValue);
|
||||
}
|
||||
|
||||
public MenuTag getMenuTag()
|
||||
@@ -75,27 +64,9 @@ public final class SingleChoiceSettingDynamicDescriptions extends SettingsItem
|
||||
return menuTag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing int. If that int was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param selection New value of the int.
|
||||
* @return null if overwritten successfully otherwise; a newly created IntSetting.
|
||||
*/
|
||||
public IntSetting setSelectedValue(int selection)
|
||||
public void setSelectedValue(Settings settings, int selection)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
setting.setValue(selection);
|
||||
return null;
|
||||
}
|
||||
settings.getSection(getFile(), getSection()).setInt(getKey(), selection);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+7
-96
@@ -1,117 +1,28 @@
|
||||
package org.dolphinemu.dolphinemu.features.settings.model.view;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.FloatSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.IntSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Setting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
import org.dolphinemu.dolphinemu.features.settings.utils.SettingsFile;
|
||||
import org.dolphinemu.dolphinemu.utils.Log;
|
||||
|
||||
public final class SliderSetting extends SettingsItem
|
||||
public abstract class SliderSetting extends SettingsItem
|
||||
{
|
||||
private int mMax;
|
||||
private int mDefaultValue;
|
||||
|
||||
private String mUnits;
|
||||
|
||||
public SliderSetting(String key, String section, int titleId, int descriptionId, int max,
|
||||
String units, int defaultValue, Setting setting)
|
||||
public SliderSetting(String file, String section, String key, int nameId, int descriptionId,
|
||||
int max, String units)
|
||||
{
|
||||
super(key, section, setting, titleId, descriptionId);
|
||||
super(file, section, key, nameId, descriptionId);
|
||||
mMax = max;
|
||||
mUnits = units;
|
||||
mDefaultValue = defaultValue;
|
||||
}
|
||||
|
||||
public abstract int getSelectedValue(Settings settings);
|
||||
|
||||
public int getMax()
|
||||
{
|
||||
return mMax;
|
||||
}
|
||||
|
||||
public int getSelectedValue()
|
||||
{
|
||||
Setting setting = getSetting();
|
||||
|
||||
if (setting == null)
|
||||
{
|
||||
return mDefaultValue;
|
||||
}
|
||||
|
||||
if (setting instanceof IntSetting)
|
||||
{
|
||||
IntSetting intSetting = (IntSetting) setting;
|
||||
return intSetting.getValue();
|
||||
}
|
||||
else if (setting instanceof FloatSetting)
|
||||
{
|
||||
FloatSetting floatSetting = (FloatSetting) setting;
|
||||
if (isPercentSetting())
|
||||
{
|
||||
return Math.round(floatSetting.getValue() * 100);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Math.round(floatSetting.getValue());
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.error("[SliderSetting] Error casting setting type.");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPercentSetting()
|
||||
{
|
||||
return getKey().equals(SettingsFile.KEY_OVERCLOCK_PERCENT)
|
||||
|| getKey().equals(SettingsFile.KEY_SPEED_LIMIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing int. If that int was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param selection New value of the int.
|
||||
* @return null if overwritten successfully otherwise; a newly created IntSetting.
|
||||
*/
|
||||
public IntSetting setSelectedValue(int selection)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof IntSetting))
|
||||
{
|
||||
IntSetting setting = new IntSetting(getKey(), getSection(), selection);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
IntSetting setting = (IntSetting) getSetting();
|
||||
setting.setValue(selection);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write a value to the backing float. If that float was previously null,
|
||||
* initializes a new one and returns it, so it can be added to the Hashmap.
|
||||
*
|
||||
* @param selection New value of the float.
|
||||
* @return null if overwritten successfully otherwise; a newly created FloatSetting.
|
||||
*/
|
||||
public FloatSetting setSelectedValue(float selection)
|
||||
{
|
||||
if (getSetting() == null || !(getSetting() instanceof FloatSetting))
|
||||
{
|
||||
FloatSetting setting = new FloatSetting(getKey(), getSection(), selection);
|
||||
setSetting(setting);
|
||||
return setting;
|
||||
}
|
||||
else
|
||||
{
|
||||
FloatSetting setting = (FloatSetting) getSetting();
|
||||
setting.setValue(selection);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public String getUnits()
|
||||
{
|
||||
return mUnits;
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user