diff --git a/Source/Core/DolphinWX/Src/Android/ButtonManager.cpp b/Source/Core/DolphinWX/Src/Android/ButtonManager.cpp index b33148338d..5fa7bc799a 100644 --- a/Source/Core/DolphinWX/Src/Android/ButtonManager.cpp +++ b/Source/Core/DolphinWX/Src/Android/ButtonManager.cpp @@ -28,7 +28,7 @@ namespace ButtonManager std::map, Button*> m_buttons; std::map, Axis*> m_axises; std::unordered_map m_controllers; - const char *configStrings[] = { "InputA", + const char* configStrings[] = { "InputA", "InputB", "InputStart", "InputX", @@ -94,29 +94,34 @@ namespace ButtonManager ini.Load(File::GetUserPath(D_CONFIG_IDX) + std::string("Dolphin.ini")); for (int a = 0; a < configStringNum; ++a) { - BindType type; - int bindnum; - char dev[128]; - bool hasbind = false; - char modifier = 0; - std::string value; - ini.Get("Android", configStrings[a], &value, "None"); - if (value == "None") - continue; - if (std::string::npos != value.find("Axis")) + for (int padID = 0; padID < 4; ++padID) { - hasbind = true; - type = BIND_AXIS; - sscanf(value.c_str(), "Device '%[^\']'-Axis %d%c", dev, &bindnum, &modifier); + std::ostringstream config; + config << configStrings[a] << "_" << padID; + BindType type; + int bindnum; + char dev[128]; + bool hasbind = false; + char modifier = 0; + std::string value; + ini.Get("Android", config.str().c_str(), &value, "None"); + if (value == "None") + continue; + if (std::string::npos != value.find("Axis")) + { + hasbind = true; + type = BIND_AXIS; + sscanf(value.c_str(), "Device '%[^\']'-Axis %d%c", dev, &bindnum, &modifier); + } + else if (std::string::npos != value.find("Button")) + { + hasbind = true; + type = BIND_BUTTON; + sscanf(value.c_str(), "Device '%[^\']'-Button %d", dev, &bindnum); + } + if (hasbind) + AddBind(std::string(dev), new sBind(padID, (ButtonType)a, type, bindnum, modifier == '-' ? -1.0f : 1.0f)); } - else if (std::string::npos != value.find("Button")) - { - hasbind = true; - type = BIND_BUTTON; - sscanf(value.c_str(), "Device '%[^\']'-Button %d", dev, &bindnum); - } - if (hasbind) - AddBind(std::string(dev), new sBind((ButtonType)a, type, bindnum, modifier == '-' ? -1.0f : 1.0f)); } } @@ -126,7 +131,7 @@ namespace ButtonManager pressed = m_buttons[std::make_pair(padID, button)]->Pressed(); for (auto it = m_controllers.begin(); it != m_controllers.end(); ++it) - pressed |= it->second->ButtonValue(button); + pressed |= it->second->ButtonValue(padID, button); return pressed; } @@ -138,7 +143,7 @@ namespace ButtonManager auto it = m_controllers.begin(); if (it == m_controllers.end()) return value; - return it->second->AxisValue(axis); + return it->second->AxisValue(padID, axis); } void TouchEvent(int padID, int button, int action) { @@ -148,7 +153,7 @@ namespace ButtonManager { m_axises[std::make_pair(padID, axis)]->SetValue(value); } - void GamepadEvent(std::string dev, int button, int action) + void GamepadEvent(std::string dev, ButtonType button, int action) { auto it = m_controllers.find(dev); if (it != m_controllers.end()) @@ -159,7 +164,7 @@ namespace ButtonManager m_controllers[dev] = new InputDevice(dev); m_controllers[dev]->PressEvent(button, action); } - void GamepadAxisEvent(std::string dev, int axis, float value) + void GamepadAxisEvent(std::string dev, ButtonType axis, float value) { auto it = m_controllers.find(dev); if (it != m_controllers.end()) @@ -181,31 +186,35 @@ namespace ButtonManager } // InputDevice - void InputDevice::PressEvent(int button, int action) + void InputDevice::PressEvent(ButtonType button, int action) { - m_buttons[button] = action == 0 ? true : false; + m_buttons[m_binds[button]->m_bind] = action == 0 ? true : false; } - void InputDevice::AxisEvent(int axis, float value) + void InputDevice::AxisEvent(ButtonType axis, float value) { - m_axises[axis] = value; + m_axises[m_binds[axis]->m_bind] = value; } - bool InputDevice::ButtonValue(ButtonType button) + bool InputDevice::ButtonValue(int padID, ButtonType button) { auto it = m_binds.find(button); if (it == m_binds.end()) return false; + if (it->second->m_padID != padID) + return false; if (it->second->m_bindtype == BIND_BUTTON) return m_buttons[it->second->m_bind]; else - return AxisValue(button); + return AxisValue(padID, button); } - float InputDevice::AxisValue(ButtonType axis) + float InputDevice::AxisValue(int padID, ButtonType axis) { auto it = m_binds.find(axis); if (it == m_binds.end()) return 0.0f; + if (it->second->m_padID != padID) + return 0.0f; if (it->second->m_bindtype == BIND_BUTTON) - return ButtonValue(axis); + return ButtonValue(padID, axis); else return m_axises[it->second->m_bind] * it->second->m_neg; } diff --git a/Source/Core/DolphinWX/Src/Android/ButtonManager.h b/Source/Core/DolphinWX/Src/Android/ButtonManager.h index f94b3596bc..e6ce2ff8e0 100644 --- a/Source/Core/DolphinWX/Src/Android/ButtonManager.h +++ b/Source/Core/DolphinWX/Src/Android/ButtonManager.h @@ -85,12 +85,13 @@ namespace ButtonManager struct sBind { + const int m_padID; const ButtonType m_buttontype; const BindType m_bindtype; const int m_bind; const float m_neg; - sBind(ButtonType buttontype, BindType bindtype, int bind, float neg) - : m_buttontype(buttontype), m_bindtype(bindtype), m_bind(bind), m_neg(neg) + sBind(int padID, ButtonType buttontype, BindType bindtype, int bind, float neg) + : m_padID(padID), m_buttontype(buttontype), m_bindtype(bindtype), m_bind(bind), m_neg(neg) {} }; @@ -113,10 +114,10 @@ namespace ButtonManager delete it->second; } void AddBind(sBind *bind) { m_binds[bind->m_buttontype] = bind; } - void PressEvent(int button, int action); - void AxisEvent(int axis, float value); - bool ButtonValue(ButtonType button); - float AxisValue(ButtonType axis); + void PressEvent(ButtonType button, int action); + void AxisEvent(ButtonType axis, float value); + bool ButtonValue(int padID, ButtonType button); + float AxisValue(int padID, ButtonType axis); }; void Init(); @@ -124,7 +125,7 @@ namespace ButtonManager float GetAxisValue(int padID, ButtonType axis); void TouchEvent(int padID, int button, int action); void TouchAxisEvent(int padID, int axis, float value); - void GamepadEvent(std::string dev, int button, int action); - void GamepadAxisEvent(std::string dev, int axis, float value); + void GamepadEvent(std::string dev, ButtonType button, int action); + void GamepadAxisEvent(std::string dev, ButtonType axis, float value); void Shutdown(); } diff --git a/Source/Core/DolphinWX/Src/MainAndroid.cpp b/Source/Core/DolphinWX/Src/MainAndroid.cpp index 949724bcf6..c0421d99e3 100644 --- a/Source/Core/DolphinWX/Src/MainAndroid.cpp +++ b/Source/Core/DolphinWX/Src/MainAndroid.cpp @@ -249,14 +249,14 @@ JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadEve { const char *Device = env->GetStringUTFChars(jDevice, NULL); std::string strDevice = std::string(Device); - ButtonManager::GamepadEvent(strDevice, Button, Action); + ButtonManager::GamepadEvent(strDevice, (ButtonManager::ButtonType)Button, Action); env->ReleaseStringUTFChars(jDevice, Device); } JNIEXPORT void JNICALL Java_org_dolphinemu_dolphinemu_NativeLibrary_onGamePadMoveEvent(JNIEnv *env, jobject obj, jstring jDevice, jint Axis, jfloat Value) { const char *Device = env->GetStringUTFChars(jDevice, NULL); std::string strDevice = std::string(Device); - ButtonManager::GamepadAxisEvent(strDevice, Axis, Value); + ButtonManager::GamepadAxisEvent(strDevice, (ButtonManager::ButtonType)Axis, Value); env->ReleaseStringUTFChars(jDevice, Device); }