InputManagerCommands.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include <OgreStringConverter.h>
  2. #include "Console.h"
  3. #include "ConfigCmdManager.h"
  4. #include "ConfigVarManager.h"
  5. #include "Logger.h"
  6. #include "Utilites.h"
  7. void
  8. CmdBind( const Ogre::StringVector& params )
  9. {
  10. if( params.size() < 3 || params.size() > 4 )
  11. {
  12. Console::getSingleton().AddTextToOutput( "Usage: /bind <key1>+[key2]+[key3] \"<command line>\"" );
  13. return;
  14. }
  15. Ogre::StringVector keys = Ogre::StringUtil::split( params[ 1 ], "+" );
  16. ButtonList key_codes;
  17. for( size_t i = 0; i < keys.size(); ++i )
  18. {
  19. key_codes.push_back( StringToKey( keys[ i ] ) );
  20. }
  21. bool fail = false;
  22. for( size_t i = 0; i < key_codes.size(); ++i )
  23. {
  24. if( key_codes[ i ] == OIS::KC_UNASSIGNED )
  25. {
  26. LOG_ERROR( "Failed to bind \"" + params[ 1 ] + "\" to command \"" + params[ 2 ] + "\". Can't recognize key " + Ogre::StringConverter::toString( i ) );
  27. fail = true;
  28. }
  29. }
  30. if( fail == false )
  31. {
  32. InputManager::getSingleton().BindCommand( params[ 2 ], key_codes );
  33. LOG_TRIVIAL( "Bind \"" + params[ 1 ] + "\" to command \"" + params[ 2 ] + "\"." );
  34. }
  35. }
  36. void
  37. InputManager::InitCmd()
  38. {
  39. ConfigCmdManager::getSingleton().AddCommand( "bind", "Bind command to keys", "", CmdBind, NULL );
  40. }