diff --git a/CMakeLists.txt b/CMakeLists.txt index 5a923c631..d8872e162 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -379,6 +379,9 @@ configure_file(${OpenMW_SOURCE_DIR}/files/opencs.ini configure_file(${OpenMW_SOURCE_DIR}/files/opencs/defaultfilters "${OpenMW_BINARY_DIR}/resources/defaultfilters" COPYONLY) +configure_file(${OpenMW_SOURCE_DIR}/files/gamecontrollerdb.txt + "${OpenMW_BINARY_DIR}/gamecontrollerdb.txt") + if (NOT WIN32 AND NOT APPLE) configure_file(${OpenMW_SOURCE_DIR}/files/openmw.desktop "${OpenMW_BINARY_DIR}/openmw.desktop") diff --git a/apps/openmw/mwbase/inputmanager.hpp b/apps/openmw/mwbase/inputmanager.hpp index 3ffa7148a..59b4e3b77 100644 --- a/apps/openmw/mwbase/inputmanager.hpp +++ b/apps/openmw/mwbase/inputmanager.hpp @@ -46,10 +46,14 @@ namespace MWBase ///Actions available for binding to controller buttons virtual std::vector getActionControllerSorting() = 0; virtual int getNumActions() = 0; - ///If keyboard is true, only pay attention to keyboard events. If false, only pay attention to cntroller events (excluding esc) + ///If keyboard is true, only pay attention to keyboard events. If false, only pay attention to controller events (excluding esc) virtual void enableDetectingBindingMode (int action, bool keyboard) = 0; virtual void resetToDefaultKeyBindings() = 0; virtual void resetToDefaultControllerBindings() = 0; + + /// Returns if the last used input device was a joystick or a keyboard + /// @return true if joystick, false otherwise + virtual bool joystickLastUsed() = 0; }; } diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 3d1239f54..180d371cf 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -124,6 +124,7 @@ namespace MWInput , mAttemptJump(false) , mControlsDisabled(false) , mJoystickLastUsed(false) + , mDetectingKeyboard(false) { Ogre::RenderWindow* window = ogre.getWindow (); @@ -135,8 +136,7 @@ namespace MWInput mInputManager->setControllerEventCallback(this); std::string file = userFileExists ? userFile : ""; - std::string controllerdb = Settings::Manager::getString("gamecontrollerdb file", "Input"); - mInputBinder = new ICS::InputControlSystem(file, true, this, NULL, controllerdb, A_Last); + mInputBinder = new ICS::InputControlSystem(file, true, this, NULL, A_Last); adjustMouseRegion (window->getWidth(), window->getHeight()); loadKeyDefaults(); @@ -154,6 +154,42 @@ namespace MWInput mControlSwitch["playermagic"] = true; mControlSwitch["playerviewswitch"] = true; mControlSwitch["vanitymode"] = true; + + /* Joystick Init */ + + //Load controller mappings +#if SDL_VERSION_ATLEAST(2,0,2) + Files::ConfigurationManager cfgMgr; + std::string db = cfgMgr.getLocalPath().string() + "/gamecontrollerdb.txt"; + if(boost::filesystem::exists(db)) + { + int res = SDL_GameControllerAddMappingsFromFile(db.c_str()); + if(res == -1) + { + //ICS_LOG(std::string("Error loading controller bindings: ")+SDL_GetError()); + } + else + { + //ICS_LOG(std::string("Loaded ")+boost::lexical_cast(res)+" Game controller bindings"); + } + } +#endif + + //Open all presently connected sticks + int numSticks = SDL_NumJoysticks(); + for(int i = 0; i < numSticks; i++) + { + if(SDL_IsGameController(i)) + { + SDL_ControllerDeviceEvent evt; + evt.which = i; + controllerAdded(evt); + } + else + { + //ICS_LOG(std::string("Unusable controller plugged in: ")+SDL_JoystickNameForIndex(i)); + } + } } void InputManager::clear() diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index 61dbf18f8..df490ea00 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -4,6 +4,7 @@ #include "../mwgui/mode.hpp" #include +#include #include "../mwbase/inputmanager.hpp" #include @@ -41,6 +42,11 @@ namespace MyGUI class MouseButton; } +namespace Files +{ + struct ConfigurationManager; +} + #include #include @@ -85,8 +91,6 @@ namespace MWInput virtual std::string getActionDescription (int action); virtual std::string getActionKeyBindingName (int action); virtual std::string getActionControllerBindingName (int action); - virtual std::string sdlControllerAxisToString(int axis); - virtual std::string sdlControllerButtonToString(int button); virtual int getNumActions() { return A_Last; } virtual std::vector getActionKeySorting(); virtual std::vector getActionControllerSorting(); @@ -94,6 +98,8 @@ namespace MWInput virtual void resetToDefaultKeyBindings(); virtual void resetToDefaultControllerBindings(); + virtual bool joystickLastUsed() {return mJoystickLastUsed;} + public: virtual void keyPressed(const SDL_KeyboardEvent &arg ); virtual void keyReleased( const SDL_KeyboardEvent &arg ); @@ -181,6 +187,9 @@ namespace MWInput void adjustMouseRegion(int width, int height); MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button); + virtual std::string sdlControllerAxisToString(int axis); + virtual std::string sdlControllerButtonToString(int button); + void resetIdleTime(); void updateIdleTime(float dt); @@ -201,8 +210,6 @@ namespace MWInput void quickLoad(); void quickSave(); - bool isAReverse(int action); - void quickKey (int index); void showQuickKeysMenu(); diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index b71e92555..f4e637a59 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -268,15 +268,21 @@ namespace MWScript std::string InterpreterContext::getActionBinding(const std::string& action) const { - std::vector actions = MWBase::Environment::get().getInputManager()->getActionKeySorting (); + MWBase::InputManager* input = MWBase::Environment::get().getInputManager(); + std::vector actions = input->getActionKeySorting (); for (std::vector::const_iterator it = actions.begin(); it != actions.end(); ++it) { - std::string desc = MWBase::Environment::get().getInputManager()->getActionDescription (*it); + std::string desc = input->getActionDescription (*it); if(desc == "") continue; if(desc == action) - return MWBase::Environment::get().getInputManager()->getActionKeyBindingName (*it); + { + if(input->joystickLastUsed()) + return input->getActionControllerBindingName(*it); + else + return input->getActionKeyBindingName (*it); + } } return "None"; diff --git a/extern/oics/ICSInputControlSystem.cpp b/extern/oics/ICSInputControlSystem.cpp index a8efd54bc..a38b46e98 100644 --- a/extern/oics/ICSInputControlSystem.cpp +++ b/extern/oics/ICSInputControlSystem.cpp @@ -30,7 +30,7 @@ namespace ICS { InputControlSystem::InputControlSystem(std::string file, bool active , DetectingBindingListener* detectingBindingListener - , InputControlSystemLog* log, std::string controllerdb, size_t channelCount) + , InputControlSystemLog* log, size_t channelCount) : mFileName(file) , mDetectingBindingListener(detectingBindingListener) , mDetectingBindingControl(NULL) @@ -273,40 +273,6 @@ namespace ICS } delete xmlDoc; - } - - /* Joystick Init */ - - //Load controller mappings -#if SDL_VERSION_ATLEAST(2,0,2) - if(!controllerdb.empty()) - { - int res = SDL_GameControllerAddMappingsFromFile(controllerdb.c_str()); - if(res == -1) - { - ICS_LOG(std::string("Error loading controller bindings: ")+SDL_GetError()); - } - else - { - ICS_LOG(std::string("Loaded ")+boost::lexical_cast(res)+" Game controller bindings"); - } - } -#endif - - //Open all presently connected sticks - int numSticks = SDL_NumJoysticks(); - for(int i = 0; i < numSticks; i++) - { - if(SDL_IsGameController(i)) - { - SDL_ControllerDeviceEvent evt; - evt.which = i; - controllerAdded(evt); - } - else - { - ICS_LOG(std::string("Unusable controller plugged in: ")+SDL_JoystickNameForIndex(i)); - } } ICS_LOG(" - InputControlSystem Created - "); diff --git a/extern/oics/ICSInputControlSystem.h b/extern/oics/ICSInputControlSystem.h index f58d242fc..0bdd67b34 100644 --- a/extern/oics/ICSInputControlSystem.h +++ b/extern/oics/ICSInputControlSystem.h @@ -74,8 +74,7 @@ namespace ICS InputControlSystem(std::string file = "", bool active = true , DetectingBindingListener* detectingBindingListener = NULL - , InputControlSystemLog* log = NULL, std::string controllerdb = "" - , size_t channelCount = 16); + , InputControlSystemLog* log = NULL, size_t channelCount = 16); ~InputControlSystem(); std::string getFileName(){ return mFileName; }; diff --git a/files/CMakeLists.txt b/files/CMakeLists.txt index 4635cbfa4..9b2325744 100644 --- a/files/CMakeLists.txt +++ b/files/CMakeLists.txt @@ -49,12 +49,6 @@ set(MATERIAL_FILES mygui.shaderset ) -set(ETC_FILES - gamecontrollerdb.txt -) - copy_all_files(${CMAKE_CURRENT_SOURCE_DIR}/water "${OpenMW_BINARY_DIR}/resources/water/" "${WATER_FILES}") copy_all_files(${CMAKE_CURRENT_SOURCE_DIR}/materials "${OpenMW_BINARY_DIR}/resources/materials/" "${MATERIAL_FILES}") - -copy_all_files(${CMAKE_CURRENT_SOURCE_DIR} "${OpenMW_BINARY_DIR}/resources/" "${ETC_FILES}")