mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-23 06:09:50 -06:00
Android: Add NumericSetting support
This commit is contained in:
@ -0,0 +1,48 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.input.model;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.NumericSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AbstractBooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
public class InputMappingBooleanSetting implements AbstractBooleanSetting
|
||||
{
|
||||
private final NumericSetting mNumericSetting;
|
||||
|
||||
public InputMappingBooleanSetting(NumericSetting numericSetting)
|
||||
{
|
||||
mNumericSetting = numericSetting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean getBoolean(Settings settings)
|
||||
{
|
||||
return mNumericSetting.getBooleanValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setBoolean(Settings settings, boolean newValue)
|
||||
{
|
||||
mNumericSetting.setBooleanValue(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverridden(Settings settings)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRuntimeEditable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Settings settings)
|
||||
{
|
||||
mNumericSetting.setBooleanValue(mNumericSetting.getBooleanDefaultValue());
|
||||
return true;
|
||||
}
|
||||
}
|
@ -0,0 +1,49 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.input.model;
|
||||
|
||||
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.NumericSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AbstractFloatSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
|
||||
|
||||
// Yes, floats are not the same thing as doubles... They're close enough, though
|
||||
public class InputMappingDoubleSetting implements AbstractFloatSetting
|
||||
{
|
||||
private final NumericSetting mNumericSetting;
|
||||
|
||||
public InputMappingDoubleSetting(NumericSetting numericSetting)
|
||||
{
|
||||
mNumericSetting = numericSetting;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getFloat(Settings settings)
|
||||
{
|
||||
return (float) mNumericSetting.getDoubleValue();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setFloat(Settings settings, float newValue)
|
||||
{
|
||||
mNumericSetting.setDoubleValue(newValue);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOverridden(Settings settings)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isRuntimeEditable()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean delete(Settings settings)
|
||||
{
|
||||
mNumericSetting.setDoubleValue(mNumericSetting.getDoubleDefaultValue());
|
||||
return true;
|
||||
}
|
||||
}
|
@ -26,4 +26,8 @@ public class ControlGroup
|
||||
public native int getControlCount();
|
||||
|
||||
public native Control getControl(int i);
|
||||
|
||||
public native int getNumericSettingCount();
|
||||
|
||||
public native NumericSetting getNumericSetting(int i);
|
||||
}
|
||||
|
@ -0,0 +1,89 @@
|
||||
// SPDX-License-Identifier: GPL-2.0-or-later
|
||||
|
||||
package org.dolphinemu.dolphinemu.features.input.model.controlleremu;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
/**
|
||||
* Represents a C++ ControllerEmu::NumericSetting.
|
||||
*
|
||||
* The lifetime of this class is managed by C++ code. Calling methods on it after it's destroyed
|
||||
* in C++ is undefined behavior!
|
||||
*/
|
||||
public class NumericSetting
|
||||
{
|
||||
public static final int TYPE_INT = 0;
|
||||
public static final int TYPE_DOUBLE = 1;
|
||||
public static final int TYPE_BOOLEAN = 2;
|
||||
|
||||
@Keep
|
||||
private final long mPointer;
|
||||
|
||||
@Keep
|
||||
private NumericSetting(long pointer)
|
||||
{
|
||||
mPointer = pointer;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return The name used in the UI.
|
||||
*/
|
||||
public native String getUiName();
|
||||
|
||||
/**
|
||||
* @return A string applied to the number in the UI (unit of measure).
|
||||
*/
|
||||
public native String getUiSuffix();
|
||||
|
||||
/**
|
||||
* @return Detailed description of the setting.
|
||||
*/
|
||||
public native String getUiDescription();
|
||||
|
||||
/**
|
||||
* @return TYPE_INT, TYPE_DOUBLE or TYPE_BOOLEAN
|
||||
*/
|
||||
public native int getType();
|
||||
|
||||
public native ControlReference getControlReference();
|
||||
|
||||
/**
|
||||
* If the type is TYPE_DOUBLE, gets the current value. Otherwise, undefined behavior!
|
||||
*/
|
||||
public native double getDoubleValue();
|
||||
|
||||
/**
|
||||
* If the type is TYPE_DOUBLE, sets the current value. Otherwise, undefined behavior!
|
||||
*/
|
||||
public native void setDoubleValue(double value);
|
||||
|
||||
/**
|
||||
* If the type is TYPE_DOUBLE, gets the default value. Otherwise, undefined behavior!
|
||||
*/
|
||||
public native double getDoubleDefaultValue();
|
||||
|
||||
/**
|
||||
* If the type is TYPE_DOUBLE, returns the minimum valid value. Otherwise, undefined behavior!
|
||||
*/
|
||||
public native double getDoubleMin();
|
||||
|
||||
/**
|
||||
* If the type is TYPE_DOUBLE, returns the maximum valid value. Otherwise, undefined behavior!
|
||||
*/
|
||||
public native double getDoubleMax();
|
||||
|
||||
/**
|
||||
* If the type is TYPE_BOOLEAN, gets the current value. Otherwise, undefined behavior!
|
||||
*/
|
||||
public native boolean getBooleanValue();
|
||||
|
||||
/**
|
||||
* If the type is TYPE_BOOLEAN, sets the current value. Otherwise, undefined behavior!
|
||||
*/
|
||||
public native void setBooleanValue(boolean value);
|
||||
|
||||
/**
|
||||
* If the type is TYPE_BOOLEAN, gets the default value. Otherwise, undefined behavior!
|
||||
*/
|
||||
public native boolean getBooleanDefaultValue();
|
||||
}
|
@ -19,6 +19,13 @@ public class FloatSliderSetting extends SliderSetting
|
||||
mSetting = setting;
|
||||
}
|
||||
|
||||
public FloatSliderSetting(AbstractFloatSetting setting, CharSequence name,
|
||||
CharSequence description, int min, int max, String units)
|
||||
{
|
||||
super(name, description, min, max, units);
|
||||
mSetting = setting;
|
||||
}
|
||||
|
||||
public int getSelectedValue(Settings settings)
|
||||
{
|
||||
return Math.round(mSetting.getFloat(settings));
|
||||
|
@ -23,6 +23,14 @@ public abstract class SliderSetting extends SettingsItem
|
||||
mStepSize = stepSize;
|
||||
}
|
||||
|
||||
public SliderSetting(CharSequence name, CharSequence description, int min, int max, String units)
|
||||
{
|
||||
super(name, description);
|
||||
mMin = min;
|
||||
mMax = max;
|
||||
mUnits = units;
|
||||
}
|
||||
|
||||
public abstract int getSelectedValue(Settings settings);
|
||||
|
||||
public int getMin()
|
||||
|
@ -14,8 +14,11 @@ import androidx.appcompat.app.AppCompatActivity;
|
||||
import org.dolphinemu.dolphinemu.NativeLibrary;
|
||||
import org.dolphinemu.dolphinemu.R;
|
||||
import org.dolphinemu.dolphinemu.activities.UserDataActivity;
|
||||
import org.dolphinemu.dolphinemu.features.input.model.InputMappingBooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.input.model.InputMappingDoubleSetting;
|
||||
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.ControlGroup;
|
||||
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.EmulatedController;
|
||||
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.NumericSetting;
|
||||
import org.dolphinemu.dolphinemu.features.input.model.view.InputMappingControlSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AbstractBooleanSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.AbstractIntSetting;
|
||||
@ -30,6 +33,7 @@ import org.dolphinemu.dolphinemu.features.settings.model.StringSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.DateTimeChoiceSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.SwitchSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.FilePicker;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.FloatSliderSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.HeaderSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.HyperLinkHeaderSetting;
|
||||
import org.dolphinemu.dolphinemu.features.settings.model.view.InputStringSetting;
|
||||
@ -1112,6 +1116,28 @@ public final class SettingsFragmentPresenter
|
||||
{
|
||||
sl.add(new InputMappingControlSetting(group.getControl(j), controller));
|
||||
}
|
||||
|
||||
int numericSettingCount = group.getNumericSettingCount();
|
||||
for (int j = 0; j < numericSettingCount; j++)
|
||||
{
|
||||
addNumericSetting(sl, group.getNumericSetting(j));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void addNumericSetting(ArrayList<SettingsItem> sl, NumericSetting setting)
|
||||
{
|
||||
switch (setting.getType())
|
||||
{
|
||||
case NumericSetting.TYPE_DOUBLE:
|
||||
sl.add(new FloatSliderSetting(new InputMappingDoubleSetting(setting), setting.getUiName(),
|
||||
"", (int) Math.ceil(setting.getDoubleMin()),
|
||||
(int) Math.floor(setting.getDoubleMax()), setting.getUiSuffix()));
|
||||
break;
|
||||
case NumericSetting.TYPE_BOOLEAN:
|
||||
sl.add(new SwitchSetting(new InputMappingBooleanSetting(setting), setting.getUiName(),
|
||||
setting.getUiDescription()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user