diff --git a/RetroFE/Source/Control/JoyAxisHandler.cpp b/RetroFE/Source/Control/JoyAxisHandler.cpp index 67b37d5..5f2677b 100644 --- a/RetroFE/Source/Control/JoyAxisHandler.cpp +++ b/RetroFE/Source/Control/JoyAxisHandler.cpp @@ -1,7 +1,8 @@ #include "JoyAxisHandler.h" -JoyAxisHandler::JoyAxisHandler(Uint8 axis, Sint16 min, Sint16 max) -: axis_(axis) +JoyAxisHandler::JoyAxisHandler(SDL_JoystickID joyid, Uint8 axis, Sint16 min, Sint16 max) +: joyid_(joyid) +, axis_(axis) , min_(min) , max_(max) , pressed_(false) @@ -15,7 +16,7 @@ void JoyAxisHandler::reset() bool JoyAxisHandler::update(SDL_Event &e) { - if(e.type != SDL_JOYAXISMOTION || e.jaxis.axis != axis_) return false; + if(e.type != SDL_JOYAXISMOTION || e.jaxis.which != joyid_ || e.jaxis.axis != axis_) return false; pressed_ = (min_ <= e.jaxis.value && e.jaxis.value <= max_); return true; diff --git a/RetroFE/Source/Control/JoyAxisHandler.h b/RetroFE/Source/Control/JoyAxisHandler.h index dd5255b..55bee04 100644 --- a/RetroFE/Source/Control/JoyAxisHandler.h +++ b/RetroFE/Source/Control/JoyAxisHandler.h @@ -5,12 +5,13 @@ class JoyAxisHandler : public InputHandler { public: - JoyAxisHandler(Uint8 axis, Sint16 min, Sint16 max); + JoyAxisHandler(SDL_JoystickID joyid, Uint8 axis, Sint16 min, Sint16 max); bool update(SDL_Event &e); bool pressed(); void reset(); private: + SDL_JoystickID joyid_; Uint8 axis_; Sint16 min_; Sint16 max_; diff --git a/RetroFE/Source/Control/JoyButtonHandler.cpp b/RetroFE/Source/Control/JoyButtonHandler.cpp index e33354e..ff3e3ed 100644 --- a/RetroFE/Source/Control/JoyButtonHandler.cpp +++ b/RetroFE/Source/Control/JoyButtonHandler.cpp @@ -1,7 +1,8 @@ #include "JoyButtonHandler.h" -JoyButtonHandler::JoyButtonHandler(Uint8 button) -: button_(button) +JoyButtonHandler::JoyButtonHandler(SDL_JoystickID joynum, Uint8 button) +: joynum_(joynum) +, button_(button) , pressed_(false) { } @@ -15,7 +16,7 @@ bool JoyButtonHandler::update(SDL_Event &e) { if(e.type != SDL_JOYBUTTONUP && e.type != SDL_JOYBUTTONDOWN) return false; - if(e.jbutton.button == button_) + if(e.jbutton.which == joynum_ && e.jbutton.button == button_) { pressed_ = (e.type == SDL_JOYBUTTONDOWN) ? true : false; return true; diff --git a/RetroFE/Source/Control/JoyButtonHandler.h b/RetroFE/Source/Control/JoyButtonHandler.h index 13523ee..adee958 100644 --- a/RetroFE/Source/Control/JoyButtonHandler.h +++ b/RetroFE/Source/Control/JoyButtonHandler.h @@ -5,12 +5,13 @@ class JoyButtonHandler : public InputHandler { public: - JoyButtonHandler(Uint8 button); + JoyButtonHandler(SDL_JoystickID joynum, Uint8 button); bool update(SDL_Event &e); bool pressed(); void reset(); private: + SDL_JoystickID joynum_; Uint8 button_; bool pressed_; }; diff --git a/RetroFE/Source/Control/JoyHatHandler.cpp b/RetroFE/Source/Control/JoyHatHandler.cpp index 95e13ec..5b8c3c8 100644 --- a/RetroFE/Source/Control/JoyHatHandler.cpp +++ b/RetroFE/Source/Control/JoyHatHandler.cpp @@ -1,7 +1,9 @@ #include "JoyHatHandler.h" -JoyHatHandler::JoyHatHandler(Uint8 direction) -: direction_(direction) +JoyHatHandler::JoyHatHandler(SDL_JoystickID joynum, Uint8 hatnum, Uint8 direction) +: joynum_(joynum) +, hatnum_(hatnum) +, direction_(direction) , pressed_(false) { } @@ -13,7 +15,7 @@ void JoyHatHandler::reset() bool JoyHatHandler::update(SDL_Event &e) { - if(e.type != SDL_JOYHATMOTION) return false; + if(e.type != SDL_JOYHATMOTION || e.jhat.which != joynum_ || e.jhat.hat != hatnum_) return false; pressed_ = (e.jhat.value == direction_); return true; diff --git a/RetroFE/Source/Control/JoyHatHandler.h b/RetroFE/Source/Control/JoyHatHandler.h index e82c0df..ad249db 100644 --- a/RetroFE/Source/Control/JoyHatHandler.h +++ b/RetroFE/Source/Control/JoyHatHandler.h @@ -5,12 +5,14 @@ class JoyHatHandler : public InputHandler { public: - JoyHatHandler(Uint8 direction); + JoyHatHandler(SDL_JoystickID joynum, Uint8 hatnum, Uint8 direction); bool update(SDL_Event &e); bool pressed(); void reset(); private: + SDL_JoystickID joynum_; + Uint8 hatnum_; Uint8 direction_; bool pressed_; }; diff --git a/RetroFE/Source/Control/UserInput.cpp b/RetroFE/Source/Control/UserInput.cpp index b9c1ede..b9eca67 100644 --- a/RetroFE/Source/Control/UserInput.cpp +++ b/RetroFE/Source/Control/UserInput.cpp @@ -128,13 +128,20 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key) else if(description.find("joy") == 0) { std::string joydesc = Utils::replace(Utils::toLower(description), "joy", ""); + std::stringstream ssjoy; + ssjoy << joydesc.at(0); + int joynum; + ssjoy >> joynum; + joydesc = joydesc.erase(0, 1); + + if(joydesc.find("button") == 0) { unsigned int button; std::stringstream ss; ss << Utils::replace(joydesc, "button", ""); ss >> button; - keyHandlers_[key] = new JoyButtonHandler(button); + keyHandlers_[key] = new JoyButtonHandler(joynum, button); Logger::write(Logger::ZONE_INFO, "Input", "Binding joypad button " + ss.str() ); return true; } @@ -143,6 +150,12 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key) Uint8 hat; joydesc = Utils::replace(joydesc, "hat", ""); + std::stringstream sshat; + sshat << joydesc.at(0); + int hatnum; + ssjoy >> hatnum; + joydesc = joydesc.erase(0, 1); + if(joydesc == "leftup") hat = SDL_HAT_LEFTUP; else if(joydesc == "left") hat = SDL_HAT_LEFT; else if(joydesc == "leftdown") hat = SDL_HAT_LEFTDOWN; @@ -153,7 +166,7 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key) else if(joydesc == "right") hat = SDL_HAT_RIGHT; else if(joydesc == "rightdown") hat = SDL_HAT_RIGHTDOWN; - keyHandlers_[key] = new JoyHatHandler(hat); + keyHandlers_[key] = new JoyHatHandler(joynum, hatnum, hat); Logger::write(Logger::ZONE_INFO, "Input", "Binding joypad hat " + joydesc ); return true; } @@ -184,7 +197,7 @@ bool UserInput::MapKey(std::string keyDescription, KeyCode_E key) ss << joydesc; ss >> axis; Logger::write(Logger::ZONE_INFO, "Input", "Binding joypad axis " + ss.str() ); - keyHandlers_[key] = new JoyAxisHandler(axis, min, max); + keyHandlers_[key] = new JoyAxisHandler(joynum, axis, min, max); return true; } }