Android: Get profile name from core

To avoid duplicating information between Kotlin and C++.
This commit is contained in:
JosJuice
2023-10-01 18:35:01 +02:00
parent b2e016f012
commit d6c0f8e749
19 changed files with 75 additions and 10 deletions

View File

@ -30,6 +30,8 @@ class EmulatedController private constructor(private val pointer: Long) {
external fun saveProfile(path: String)
external fun getProfileName(): String
companion object {
@JvmStatic
external fun getGcPad(controllerIndex: Int): EmulatedController

View File

@ -100,15 +100,14 @@ class ProfileDialogPresenter {
.show()
}
private val profileDirectoryName: String
get() = if (menuTag.isGCPadMenu) "GCPad" else if (menuTag.isWiimoteMenu) "Wiimote" else throw UnsupportedOperationException()
private fun getProfileDirectoryPath(stock: Boolean): String =
if (stock) {
private fun getProfileDirectoryPath(stock: Boolean): String {
val profileDirectoryName = menuTag.correspondingEmulatedController.getProfileName()
return if (stock) {
"${DirectoryInitialization.getSysDirectory()}/Profiles/$profileDirectoryName/"
} else {
"${DirectoryInitialization.getUserDirectory()}/Config/Profiles/$profileDirectoryName/"
}
}
private fun getProfilePath(profileName: String, stock: Boolean): String =
getProfileDirectoryPath(stock) + profileName + EXTENSION

View File

@ -2076,7 +2076,7 @@ class SettingsFragmentPresenter(
val gcPad = EmulatedController.getGcPad(gcPadNumber)
if (!TextUtils.isEmpty(gameId)) {
addControllerPerGameSettings(sl, "Pad", gcPadNumber)
addControllerPerGameSettings(sl, gcPad, gcPadNumber)
} else {
addControllerMetaSettings(sl, gcPad)
addControllerMappingSettings(sl, gcPad, null)
@ -2106,7 +2106,7 @@ class SettingsFragmentPresenter(
val wiimote = EmulatedController.getWiimote(wiimoteNumber)
if (!TextUtils.isEmpty(gameId)) {
addControllerPerGameSettings(sl, "Wiimote", wiimoteNumber)
addControllerPerGameSettings(sl, wiimote, wiimoteNumber)
} else {
addControllerMetaSettings(sl, wiimote)
@ -2202,11 +2202,11 @@ class SettingsFragmentPresenter(
*/
private fun addControllerPerGameSettings(
sl: ArrayList<SettingsItem>,
profileString: String,
controller: EmulatedController,
controllerNumber: Int
) {
val profiles = ProfileDialogPresenter(menuTag).getProfileNames(false)
val profileKey = profileString + "Profile" + (controllerNumber + 1)
val profileKey = controller.getProfileName() + "Profile" + (controllerNumber + 1)
sl.add(
StringSingleChoiceSetting(
context,

View File

@ -124,6 +124,13 @@ Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedContro
ini.Save(path);
}
JNIEXPORT jstring JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getProfileName(
JNIEnv* env, jobject obj)
{
return ToJString(env, EmulatedControllerFromJava(env, obj)->GetConfig()->GetProfileName());
}
JNIEXPORT jobject JNICALL
Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedController_getGcPad(
JNIEnv* env, jclass, jint controller_index)