Android: Add Default and Clear actions for controllers

This commit is contained in:
JosJuice 2022-08-14 13:05:30 +02:00
parent ea3200d4ba
commit 8b78f73e80
4 changed files with 52 additions and 0 deletions

View File

@ -31,6 +31,10 @@ public class EmulatedController
public native void updateSingleControlReference(ControlReference controlReference); public native void updateSingleControlReference(ControlReference controlReference);
public native void loadDefaultSettings();
public native void clearSettings();
public static native EmulatedController getGcPad(int controllerIndex); public static native EmulatedController getGcPad(int controllerIndex);
public static native EmulatedController getWiimote(int controllerIndex); public static native EmulatedController getWiimote(int controllerIndex);

View File

@ -1213,6 +1213,13 @@ public final class SettingsFragmentPresenter
mView.setMappingAllDevices(newValue); mView.setMappingAllDevices(newValue);
} }
}, R.string.input_device_all_devices, R.string.input_device_all_devices_description)); }, R.string.input_device_all_devices, R.string.input_device_all_devices_description));
sl.add(new RunRunnable(mContext, R.string.input_reset_to_default,
R.string.input_reset_to_default_description, R.string.input_reset_warning, 0, true,
() -> loadDefaultControllerSettings(controller)));
sl.add(new RunRunnable(mContext, R.string.input_clear, R.string.input_clear_description,
R.string.input_reset_warning, 0, true, () -> clearControllerSettings(controller)));
} }
/** /**
@ -1280,6 +1287,18 @@ public final class SettingsFragmentPresenter
} }
} }
private void loadDefaultControllerSettings(EmulatedController controller)
{
controller.loadDefaultSettings();
mView.getAdapter().notifyAllSettingsChanged();
}
private void clearControllerSettings(EmulatedController controller)
{
controller.clearSettings();
mView.getAdapter().notifyAllSettingsChanged();
}
private static int getLogVerbosityEntries() private static int getLogVerbosityEntries()
{ {
// Value obtained from LogLevel in Common/Logging/Log.h // Value obtained from LogLevel in Common/Logging/Log.h

View File

@ -30,6 +30,11 @@
<string name="input_device">Device</string> <string name="input_device">Device</string>
<string name="input_device_all_devices">Create Mappings for Other Devices</string> <string name="input_device_all_devices">Create Mappings for Other Devices</string>
<string name="input_device_all_devices_description">Detects inputs from all devices, not just the selected device.</string> <string name="input_device_all_devices_description">Detects inputs from all devices, not just the selected device.</string>
<string name="input_reset_to_default">Default</string>
<string name="input_reset_to_default_description">Reset settings for this controller to the default.</string>
<string name="input_clear">Clear</string>
<string name="input_clear_description">Clear settings for this controller.</string>
<string name="input_reset_warning">Are you sure? Your current controller settings will be deleted.</string>
<string name="input_binding">Input Binding</string> <string name="input_binding">Input Binding</string>
<string name="input_binding_description">Press or move an input to bind it to %1$s.</string> <string name="input_binding_description">Press or move an input to bind it to %1$s.</string>

View File

@ -3,6 +3,7 @@
#include <jni.h> #include <jni.h>
#include "Common/IniFile.h"
#include "Core/HW/GCPad.h" #include "Core/HW/GCPad.h"
#include "Core/HW/Wiimote.h" #include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
@ -71,6 +72,29 @@ Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedContro
g_controller_interface, ControlReferenceFromJava(env, control_reference)); g_controller_interface, ControlReferenceFromJava(env, control_reference));
} }
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_loadDefaultSettings(
JNIEnv* env, jobject obj)
{
ControllerEmu::EmulatedController* controller = EmulatedControllerFromJava(env, obj);
controller->LoadDefaults(g_controller_interface);
controller->UpdateReferences(g_controller_interface);
}
JNIEXPORT void JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_clearSettings(
JNIEnv* env, jobject obj)
{
ControllerEmu::EmulatedController* controller = EmulatedControllerFromJava(env, obj);
// Loading an empty IniFile section clears everything.
IniFile::Section section;
controller->LoadConfig(&section);
controller->UpdateReferences(g_controller_interface);
}
JNIEXPORT jobject JNICALL JNIEXPORT jobject JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGcPad( Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGcPad(
JNIEnv* env, jclass, jint controller_index) JNIEnv* env, jclass, jint controller_index)