Android: Implement enabling/disabling control groups

All this code for just a single checkbox... Ah well, it has to be done
This commit is contained in:
JosJuice 2022-04-18 18:54:58 +02:00
parent a78dca5fb0
commit 2113bf5e3a
5 changed files with 89 additions and 0 deletions

View File

@ -0,0 +1,50 @@
// SPDX-License-Identifier: GPL-2.0-or-later
package org.dolphinemu.dolphinemu.features.input.model;
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.ControlGroup;
import org.dolphinemu.dolphinemu.features.settings.model.AbstractBooleanSetting;
import org.dolphinemu.dolphinemu.features.settings.model.Settings;
public class ControlGroupEnabledSetting implements AbstractBooleanSetting
{
private final ControlGroup mControlGroup;
public ControlGroupEnabledSetting(ControlGroup controlGroup)
{
mControlGroup = controlGroup;
}
@Override
public boolean getBoolean(Settings settings)
{
return mControlGroup.getEnabled();
}
@Override
public void setBoolean(Settings settings, boolean newValue)
{
mControlGroup.setEnabled(newValue);
}
@Override
public boolean isOverridden(Settings settings)
{
return false;
}
@Override
public boolean isRuntimeEditable()
{
return true;
}
@Override
public boolean delete(Settings settings)
{
boolean newValue = mControlGroup.getDefaultEnabledValue() != ControlGroup.DEFAULT_ENABLED_NO;
mControlGroup.setEnabled(newValue);
return true;
}
}

View File

@ -27,6 +27,10 @@ public class ControlGroup
public static final int TYPE_IMU_GYROSCOPE = 12; public static final int TYPE_IMU_GYROSCOPE = 12;
public static final int TYPE_IMU_CURSOR = 13; public static final int TYPE_IMU_CURSOR = 13;
public static final int DEFAULT_ENABLED_ALWAYS = 0;
public static final int DEFAULT_ENABLED_YES = 1;
public static final int DEFAULT_ENABLED_NO = 2;
@Keep @Keep
private final long mPointer; private final long mPointer;
@ -40,6 +44,12 @@ public class ControlGroup
public native int getGroupType(); public native int getGroupType();
public native int getDefaultEnabledValue();
public native boolean getEnabled();
public native void setEnabled(boolean value);
public native int getControlCount(); public native int getControlCount();
public native Control getControl(int i); public native Control getControl(int i);

View File

@ -19,6 +19,7 @@ import org.dolphinemu.dolphinemu.features.input.model.InputMappingBooleanSetting
import org.dolphinemu.dolphinemu.features.input.model.InputMappingDoubleSetting; import org.dolphinemu.dolphinemu.features.input.model.InputMappingDoubleSetting;
import org.dolphinemu.dolphinemu.features.input.model.InputMappingIntSetting; import org.dolphinemu.dolphinemu.features.input.model.InputMappingIntSetting;
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.ControlGroup; import org.dolphinemu.dolphinemu.features.input.model.controlleremu.ControlGroup;
import org.dolphinemu.dolphinemu.features.input.model.ControlGroupEnabledSetting;
import org.dolphinemu.dolphinemu.features.input.model.controlleremu.EmulatedController; 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.controlleremu.NumericSetting;
import org.dolphinemu.dolphinemu.features.input.model.view.InputMappingControlSetting; import org.dolphinemu.dolphinemu.features.input.model.view.InputMappingControlSetting;
@ -1178,6 +1179,12 @@ public final class SettingsFragmentPresenter
sl.add(new HeaderSetting(group.getUiName(), "")); sl.add(new HeaderSetting(group.getUiName(), ""));
if (group.getDefaultEnabledValue() != ControlGroup.DEFAULT_ENABLED_ALWAYS)
{
sl.add(new SwitchSetting(mContext, new ControlGroupEnabledSetting(group), R.string.enabled,
0));
}
int controlCount = group.getControlCount(); int controlCount = group.getControlCount();
for (int j = 0; j < controlCount; j++) for (int j = 0; j < controlCount; j++)
{ {

View File

@ -585,6 +585,7 @@ It can efficiently compress both junk data and encrypted Wii data.
<string name="unavailable_paths">Dolphin does not have permission to access one or more configured paths. Would you like to fix this before starting?</string> <string name="unavailable_paths">Dolphin does not have permission to access one or more configured paths. Would you like to fix this before starting?</string>
<!-- Misc --> <!-- Misc -->
<string name="enabled">Enabled</string>
<string name="pitch">Total Pitch</string> <string name="pitch">Total Pitch</string>
<string name="yaw">Total Yaw</string> <string name="yaw">Total Yaw</string>
<string name="vertical_offset">Vertical Offset</string> <string name="vertical_offset">Vertical Offset</string>

View File

@ -44,6 +44,27 @@ Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlGroup_g
return static_cast<jint>(GetPointer(env, obj)->type); return static_cast<jint>(GetPointer(env, obj)->type);
} }
JNIEXPORT jint JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlGroup_getDefaultEnabledValue(
JNIEnv* env, jobject obj)
{
return static_cast<jint>(GetPointer(env, obj)->default_value);
}
JNIEXPORT jboolean JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlGroup_getEnabled(
JNIEnv* env, jobject obj)
{
return static_cast<jboolean>(GetPointer(env, obj)->enabled);
}
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlGroup_setEnabled(
JNIEnv* env, jobject obj, jboolean value)
{
GetPointer(env, obj)->enabled = value;
}
JNIEXPORT jint JNICALL JNIEXPORT jint JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlGroup_getControlCount( Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_ControlGroup_getControlCount(
JNIEnv* env, jobject obj) JNIEnv* env, jobject obj)