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 saveProfile(path: String)
external fun getProfileName(): String
companion object { companion object {
@JvmStatic @JvmStatic
external fun getGcPad(controllerIndex: Int): EmulatedController external fun getGcPad(controllerIndex: Int): EmulatedController

View File

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

View File

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

View File

@ -124,6 +124,13 @@ Java_org_dolphinemu_dolphinemu_features_input_model_controlleremu_EmulatedContro
ini.Save(path); 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 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)

View File

@ -118,6 +118,11 @@ std::string FreeLookController::GetName() const
return std::string("FreeLook") + char('1' + m_index); return std::string("FreeLook") + char('1' + m_index);
} }
InputConfig* FreeLookController::GetConfig() const
{
return FreeLook::GetInputConfig();
}
void FreeLookController::LoadDefaults(const ControllerInterface& ciface) void FreeLookController::LoadDefaults(const ControllerInterface& ciface)
{ {
EmulatedController::LoadDefaults(ciface); EmulatedController::LoadDefaults(ciface);

View File

@ -47,6 +47,7 @@ public:
explicit FreeLookController(unsigned int index); explicit FreeLookController(unsigned int index);
std::string GetName() const override; std::string GetName() const override;
InputConfig* GetConfig() const override;
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
ControllerEmu::ControlGroup* GetGroup(FreeLookGroup group) const; ControllerEmu::ControlGroup* GetGroup(FreeLookGroup group) const;

View File

@ -5,6 +5,8 @@
#include <fmt/format.h> #include <fmt/format.h>
#include "Core/HW/GBAPad.h"
#include "InputCommon/ControllerEmu/Control/Input.h" #include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" #include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
@ -43,6 +45,11 @@ std::string GBAPad::GetName() const
return fmt::format("GBA{}", m_index + 1); return fmt::format("GBA{}", m_index + 1);
} }
InputConfig* GBAPad::GetConfig() const
{
return Pad::GetGBAConfig();
}
ControllerEmu::ControlGroup* GBAPad::GetGroup(GBAPadGroup group) const ControllerEmu::ControlGroup* GBAPad::GetGroup(GBAPadGroup group) const
{ {
switch (group) switch (group)

View File

@ -29,6 +29,8 @@ public:
std::string GetName() const override; std::string GetName() const override;
InputConfig* GetConfig() const override;
ControllerEmu::ControlGroup* GetGroup(GBAPadGroup group) const; ControllerEmu::ControlGroup* GetGroup(GBAPadGroup group) const;
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;

View File

@ -5,6 +5,9 @@
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/GCKeyboard.h"
#include "InputCommon/ControllerEmu/Control/Input.h" #include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/ControlGroup/Buttons.h" #include "InputCommon/ControllerEmu/ControlGroup/Buttons.h"
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
@ -84,6 +87,11 @@ std::string GCKeyboard::GetName() const
return std::string("GCKeyboard") + char('1' + m_index); return std::string("GCKeyboard") + char('1' + m_index);
} }
InputConfig* GCKeyboard::GetConfig() const
{
return Keyboard::GetConfig();
}
ControllerEmu::ControlGroup* GCKeyboard::GetGroup(KeyboardGroup group) ControllerEmu::ControlGroup* GCKeyboard::GetGroup(KeyboardGroup group)
{ {
switch (group) switch (group)

View File

@ -31,6 +31,7 @@ public:
explicit GCKeyboard(unsigned int index); explicit GCKeyboard(unsigned int index);
KeyboardStatus GetInput() const; KeyboardStatus GetInput() const;
std::string GetName() const override; std::string GetName() const override;
InputConfig* GetConfig() const override;
ControllerEmu::ControlGroup* GetGroup(KeyboardGroup group); ControllerEmu::ControlGroup* GetGroup(KeyboardGroup group);
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;

View File

@ -8,6 +8,8 @@
#include "Common/Common.h" #include "Common/Common.h"
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Core/HW/GCPad.h"
#include "InputCommon/ControllerEmu/Control/Input.h" #include "InputCommon/ControllerEmu/Control/Input.h"
#include "InputCommon/ControllerEmu/Control/Output.h" #include "InputCommon/ControllerEmu/Control/Output.h"
#include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h" #include "InputCommon/ControllerEmu/ControlGroup/AnalogStick.h"
@ -15,7 +17,6 @@
#include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h" #include "InputCommon/ControllerEmu/ControlGroup/ControlGroup.h"
#include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h" #include "InputCommon/ControllerEmu/ControlGroup/MixedTriggers.h"
#include "InputCommon/ControllerEmu/StickGate.h" #include "InputCommon/ControllerEmu/StickGate.h"
#include "InputCommon/GCPadStatus.h" #include "InputCommon/GCPadStatus.h"
static const u16 button_bitmasks[] = { static const u16 button_bitmasks[] = {
@ -95,6 +96,11 @@ std::string GCPad::GetName() const
return std::string("GCPad") + char('1' + m_index); return std::string("GCPad") + char('1' + m_index);
} }
InputConfig* GCPad::GetConfig() const
{
return Pad::GetConfig();
}
ControllerEmu::ControlGroup* GCPad::GetGroup(PadGroup group) ControllerEmu::ControlGroup* GCPad::GetGroup(PadGroup group)
{ {
switch (group) switch (group)

View File

@ -43,6 +43,8 @@ public:
std::string GetName() const override; std::string GetName() const override;
InputConfig* GetConfig() const override;
ControllerEmu::ControlGroup* GetGroup(PadGroup group); ControllerEmu::ControlGroup* GetGroup(PadGroup group);
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;

View File

@ -10,6 +10,7 @@
#include "Common/CommonTypes.h" #include "Common/CommonTypes.h"
#include "Common/Inline.h" #include "Common/Inline.h"
#include "Core/HW/Wiimote.h"
#include "Core/HW/WiimoteEmu/Extension/DesiredExtensionState.h" #include "Core/HW/WiimoteEmu/Extension/DesiredExtensionState.h"
#include "Core/HW/WiimoteEmu/WiimoteEmu.h" #include "Core/HW/WiimoteEmu/WiimoteEmu.h"
@ -36,6 +37,11 @@ std::string Extension::GetDisplayName() const
return m_display_name; return m_display_name;
} }
InputConfig* Extension::GetConfig() const
{
return ::Wiimote::GetConfig();
}
None::None() : Extension("None") None::None() : Extension("None")
{ {
} }

View File

@ -27,6 +27,8 @@ public:
std::string GetName() const override; std::string GetName() const override;
std::string GetDisplayName() const override; std::string GetDisplayName() const override;
InputConfig* GetConfig() const override;
// Used by the wiimote to detect extension changes. // Used by the wiimote to detect extension changes.
// The normal extensions short this pin so it's always connected, // The normal extensions short this pin so it's always connected,
// but M+ does some tricks with it during activation. // but M+ does some tricks with it during activation.

View File

@ -324,6 +324,11 @@ std::string Wiimote::GetName() const
return fmt::format("Wiimote{}", 1 + m_index); return fmt::format("Wiimote{}", 1 + m_index);
} }
InputConfig* Wiimote::GetConfig() const
{
return ::Wiimote::GetConfig();
}
ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group) const ControllerEmu::ControlGroup* Wiimote::GetWiimoteGroup(WiimoteGroup group) const
{ {
switch (group) switch (group)

View File

@ -137,6 +137,9 @@ public:
~Wiimote(); ~Wiimote();
std::string GetName() const override; std::string GetName() const override;
InputConfig* GetConfig() const override;
void LoadDefaults(const ControllerInterface& ciface) override; void LoadDefaults(const ControllerInterface& ciface) override;
ControllerEmu::ControlGroup* GetWiimoteGroup(WiimoteGroup group) const; ControllerEmu::ControlGroup* GetWiimoteGroup(WiimoteGroup group) const;

View File

@ -383,6 +383,11 @@ std::string HotkeyManager::GetName() const
return "Hotkeys"; return "Hotkeys";
} }
InputConfig* HotkeyManager::GetConfig() const
{
return HotkeyManagerEmu::GetConfig();
}
void HotkeyManager::GetInput(HotkeyStatus* kb, bool ignore_focus) void HotkeyManager::GetInput(HotkeyStatus* kb, bool ignore_focus)
{ {
const auto lock = GetStateLock(); const auto lock = GetStateLock();

View File

@ -233,6 +233,7 @@ public:
void GetInput(HotkeyStatus* hk, bool ignore_focus); void GetInput(HotkeyStatus* hk, bool ignore_focus);
std::string GetName() const override; std::string GetName() const override;
InputConfig* GetConfig() const override;
ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group) const; ControllerEmu::ControlGroup* GetHotkeyGroup(HotkeyGroup group) const;
int FindGroupByID(int id) const; int FindGroupByID(int id) const;
int GetIndexForGroup(int group, int id) const; int GetIndexForGroup(int group, int id) const;

View File

@ -19,6 +19,7 @@
#include "InputCommon/ControllerInterface/CoreDevice.h" #include "InputCommon/ControllerInterface/CoreDevice.h"
class ControllerInterface; class ControllerInterface;
class InputConfig;
constexpr const char* DIRECTION_UP = _trans("Up"); constexpr const char* DIRECTION_UP = _trans("Up");
constexpr const char* DIRECTION_DOWN = _trans("Down"); constexpr const char* DIRECTION_DOWN = _trans("Down");
@ -180,6 +181,8 @@ public:
virtual std::string GetName() const = 0; virtual std::string GetName() const = 0;
virtual std::string GetDisplayName() const; virtual std::string GetDisplayName() const;
virtual InputConfig* GetConfig() const = 0;
virtual void LoadDefaults(const ControllerInterface& ciface); virtual void LoadDefaults(const ControllerInterface& ciface);
virtual void LoadConfig(Common::IniFile::Section* sec, const std::string& base = ""); virtual void LoadConfig(Common::IniFile::Section* sec, const std::string& base = "");