Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 1213


Ignore:
Timestamp:
May 1, 2008, 8:33:53 PM (16 years ago)
Author:
rgrieder
Message:
  • Key bindings can now be stored in keybindings.ini
  • doesn't work for move movement yet, but for the buttons.
Location:
code/branches/input
Files:
1 added
6 edited

Legend:

Unmodified
Added
Removed
  • code/branches/input/src/core/InputHandler.cc

    r1205 r1213  
    3434#include "InputHandler.h"
    3535#include "Debug.h"
     36#include "ConfigValueIncludes.h"
     37#include "CoreIncludes.h"
    3638#include "util/Convert.h"
    3739#include "core/CommandExecutor.h"
     
    4850  KeyBinder::KeyBinder()
    4951  {
     52    RegisterObject(KeyBinder);
    5053    clearBindings();
     54
     55    std::string keyNames[] = {
     56    "UNASSIGNED",
     57                "ESCAPE",
     58                "1",
     59                "2",
     60                "3",
     61                "4",
     62                "5",
     63                "6",
     64                "7",
     65                "8",
     66                "9",
     67                "0",
     68                "MINUS",
     69                "EQUALS",
     70                "BACK",
     71                "TAB",
     72                "Q",
     73                "W",
     74                "E",
     75                "R",
     76                "T",
     77                "Y",
     78                "U",
     79                "I",
     80                "O",
     81                "P",
     82                "LBRACKET",
     83                "RBRACKET",
     84                "RETURN",
     85                "LCONTROL",
     86                "A",
     87                "S",
     88                "D",
     89                "F",
     90                "G",
     91                "H",
     92                "J",
     93                "K",
     94                "L",
     95                "SEMICOLON",
     96                "APOSTROPHE",
     97                "GRAVE",
     98                "LSHIFT",
     99                "BACKSLASH",
     100                "Z",
     101                "X",
     102                "C",
     103                "V",
     104                "B",
     105                "N",
     106                "M",
     107                "COMMA",
     108                "PERIOD",
     109                "SLASH",
     110                "RSHIFT",
     111                "MULTIPLY",
     112                "LMENU",
     113                "SPACE",
     114                "CAPITAL",
     115                "F1",
     116                "F2",
     117                "F3",
     118                "F4",
     119                "F5",
     120                "F6",
     121                "F7",
     122                "F8",
     123                "F9",
     124                "F10",
     125                "NUMLOCK",
     126                "SCROLL",
     127                "NUMPAD7",
     128                "NUMPAD8",
     129                "NUMPAD9",
     130                "SUBTRACT",
     131                "NUMPAD4",
     132                "NUMPAD5",
     133                "NUMPAD6",
     134                "ADD",
     135                "NUMPAD1",
     136                "NUMPAD2",
     137                "NUMPAD3",
     138                "NUMPAD0",
     139                "DECIMAL",
     140    "","",
     141                "OEM_102",
     142                "F11",
     143                "F12",
     144    "","","","","","","","","","","",
     145                "F13",
     146                "F14",
     147                "F15",
     148    "","","","","","","","","","",
     149                "KANA",
     150    "","",
     151                "ABNT_C1",
     152    "","","","","",
     153                "CONVERT",
     154    "",
     155                "NOCONVERT",
     156    "",
     157                "YEN",
     158                "ABNT_C2",
     159    "","","","","","","","","","","","","","",
     160                "NUMPADEQUALS",
     161    "","",
     162                "PREVTRACK",
     163                "AT",
     164                "COLON",
     165                "UNDERLINE",
     166                "KANJI",
     167                "STOP",
     168                "AX",
     169                "UNLABELED",
     170                "NEXTTRACK",
     171    "","",
     172                "NUMPADENTER",
     173                "RCONTROL",
     174    "","",
     175                "MUTE",
     176                "CALCULATOR",
     177                "PLAYPAUSE",
     178    "",
     179                "MEDIASTOP",
     180    "","","","","","","","","",
     181                "VOLUMEDOWN",
     182    "",
     183                "VOLUMEUP",
     184    "",
     185                "WEBHOME",
     186                "NUMPADCOMMA",
     187    "",
     188                "DIVIDE",
     189    "",
     190                "SYSRQ",
     191                "RMENU",
     192    "","","","","","","","","","","","",
     193                "PAUSE",
     194    "",
     195                "HOME",
     196                "UP",
     197                "PGUP",
     198    "",
     199                "LEFT",
     200    "",
     201                "RIGHT",
     202    "",
     203                "END",
     204                "DOWN",
     205                "PGDOWN",
     206                "INSERT",
     207                "DELETE",
     208    "","","","","","","",
     209                "LWIN",
     210                "RWIN",
     211                "APPS",
     212                "POWER",
     213                "SLEEP",
     214    "","","",
     215                "WAKE",
     216    "",
     217                "WEBSEARCH",
     218                "WEBFAVORITES",
     219                "WEBREFRESH",
     220                "WEBSTOP",
     221                "WEBFORWARD",
     222                "WEBBACK",
     223                "MYCOMPUTER",
     224                "MAIL",
     225                "MEDIASELECT"
     226    };
     227    for (int i = 0; i < numberOfKeys_s; i++)
     228      keyNames_[i] = keyNames[i];
     229
     230    std::string mouseButtonNames[] = {
     231    "MouseLeft", "MouseRight", "MouseMiddle",
     232    "MouseButton3", "MouseButton4", "MouseButton5",
     233    "MouseButton6", "MouseButton7" };
     234    for (int i = 0; i < numberOfMouseButtons_s; i++)
     235      mouseButtonNames_[i] = mouseButtonNames[i];
     236
     237    for (int i = 0; i < numberOfJoyStickButtons_s; i++)
     238      joyStickButtonNames_[i] = "JoyStick" + getConvertedValue<int, std::string>(i);
    51239  }
    52240
     
    56244  KeyBinder::~KeyBinder()
    57245  {
     246  }
     247
     248  /**
     249    @brief Loader for the key bindings, managed by config values.
     250  */
     251  void KeyBinder::setConfigValues()
     252  {
     253    ConfigValueContainer* cont;
     254    std::string modes[] = {"P_", "R_", "H_"};
     255
     256    // keys
     257    for (int i = 0; i < numberOfKeys_s; i++)
     258    {
     259      for (int j = 0; j < 3; j++)
     260      {
     261        cont = getIdentifier()->getConfigValueContainer(modes[j] + keyNames_[i]);
     262        if (!cont)
     263        {
     264          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + keyNames_[i], "");
     265          getIdentifier()->addConfigValueContainer(modes[j] + keyNames_[i], cont);
     266        }
     267        switch (j)
     268        {
     269          case 0:
     270            cont->getValue(bindingsKeyPress_ + i);
     271            break;
     272          case 1:
     273            cont->getValue(bindingsKeyRelease_ + i);
     274            break;
     275          case 2:
     276            cont->getValue(bindingsKeyHold_ + i);
     277        }
     278      }
     279    }
     280
     281    // mouse buttons
     282    for (int i = 0; i < numberOfMouseButtons_s; i++)
     283    {
     284      for (int j = 0; j < 3; j++)
     285      {
     286        cont = getIdentifier()->getConfigValueContainer(modes[j] + mouseButtonNames_[i]);
     287        if (!cont)
     288        {
     289          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + mouseButtonNames_[i], "");
     290          getIdentifier()->addConfigValueContainer(modes[j] + mouseButtonNames_[i], cont);
     291        }
     292        switch (j)
     293        {
     294          case 0:
     295            cont->getValue(bindingsMouseButtonPress_ + i);
     296            break;
     297          case 1:
     298            cont->getValue(bindingsMouseButtonRelease_ + i);
     299            break;
     300          case 2:
     301            cont->getValue(bindingsMouseButtonHold_ + i);
     302        }
     303      }
     304    }
     305
     306    // joy stick buttons
     307    for (int i = 0; i < numberOfJoyStickButtons_s; i++)
     308    {
     309      for (int j = 0; j < 3; j++)
     310      {
     311        cont = getIdentifier()->getConfigValueContainer(modes[j] + joyStickButtonNames_[i]);
     312        if (!cont)
     313        {
     314          cont = new ConfigValueContainer(CFT_Keybindings, getIdentifier(), modes[j] + joyStickButtonNames_[i], "");
     315          getIdentifier()->addConfigValueContainer(modes[j] + joyStickButtonNames_[i], cont);
     316        }
     317        switch (j)
     318        {
     319          case 0:
     320            cont->getValue(bindingsJoyStickButtonPress_ + i);
     321            break;
     322          case 1:
     323            cont->getValue(bindingsJoyStickButtonRelease_ + i);
     324            break;
     325          case 2:
     326            cont->getValue(bindingsJoyStickButtonHold_ + i);
     327        }
     328      }
     329    }
    58330  }
    59331
     
    91363    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings..." << std::endl;
    92364
    93     // clear all the bindings at first.
    94     clearBindings();
    95 
    96     // TODO: Insert the code to load the bindings from file.
    97     bindingsKeyPress_[OIS::KC_NUMPADENTER] = "activateConsole";
    98     bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
    99     bindingsKeyHold_ [OIS::KC_U] = "exec disco.txt";
     365    ConfigFileManager::getSingleton()->setFile(CFT_Keybindings, "keybindings.ini");
     366    setConfigValues();
    100367
    101368    COUT(ORX_DEBUG) << "KeyBinder: Loading key bindings done." << std::endl;
     
    110377  bool KeyBinder::keyPressed(const OIS::KeyEvent &e)
    111378  {
     379    COUT(3) << "Key: " << e.key << std::endl;
    112380    // find the appropriate key binding
    113381    std::string cmdStr = bindingsKeyPress_[int(e.key)];
  • code/branches/input/src/core/InputHandler.h

    r1203 r1213  
    3939#include <string>
    4040#include "ois/OIS.h"
     41#include "OrxonoxClass.h"
    4142
    4243namespace orxonox
     
    8586           Manages the key bindings.
    8687  */
    87   class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler
     88  class _CoreExport KeyBinder : public KeyHandler, public MouseHandler, public JoyStickHandler, public OrxonoxClass
    8889  {
    8990  public:
     
    9394    bool loadBindings();
    9495    void clearBindings();
     96
     97    void setConfigValues();
     98
     99    std::string testtest;
    95100
    96101  private: // functions
     
    112117
    113118  private: // variables
    114     /** denotes the maximum number of different keys there are in OIS.
    115         256 should be ok since the highest number in the OIS enum is 237. */
    116     static const int numberOfKeys_s = 256;
     119
     120    //! denotes the number of different keys there are in OIS.
     121    static const int numberOfKeys_s = 0xEE;
    117122    //! Array of input events for every pressed key
    118123    std::string bindingsKeyPress_  [numberOfKeys_s];
    119124    //! Array of input events for every released key
    120125    std::string bindingsKeyRelease_[numberOfKeys_s];
    121     //!Array of input events for every held key
     126    //! Array of input events for every held key
    122127    std::string bindingsKeyHold_   [numberOfKeys_s];
     128    //! Names of the keys as strings
     129    std::string keyNames_[numberOfKeys_s];
    123130
    124     /** denotes the maximum number of different buttons there are in OIS.
    125         16 should be ok since the highest number in the OIS enum is 7. */
    126     static const int numberOfMouseButtons_s = 16;
     131    //! denotes the number of different mouse buttons there are in OIS.
     132    static const int numberOfMouseButtons_s = 8;
    127133    //! Array of input events for every pressed mouse button
    128134    std::string bindingsMouseButtonPress_  [numberOfMouseButtons_s];
     
    131137    //! Array of input events for every held mouse button
    132138    std::string bindingsMouseButtonHold_   [numberOfMouseButtons_s];
     139    //! Names of the mouse buttons as strings
     140    std::string mouseButtonNames_[numberOfMouseButtons_s];
    133141
    134     /** denotes the maximum number of different buttons there are in OIS.
    135         32 should be ok. */
     142    //! denotes the number of different joy stick buttons there are in OIS.
    136143    static const int numberOfJoyStickButtons_s = 32;
    137144    //! Array of input events for every pressed joy stick button
     
    141148    //! Array of input events for every held joy stick button
    142149    std::string bindingsJoyStickButtonHold_   [numberOfJoyStickButtons_s];
     150    //! Names of the joy stick buttons as strings
     151    std::string joyStickButtonNames_[numberOfJoyStickButtons_s];
    143152
    144153  };
  • code/branches/input/src/core/InputManager.cc

    r1204 r1213  
    822822    {
    823823      if ((*it) == (*mapIt).second)
     824      {
     825        _getSingleton().stateRequest_ = IS_CUSTOM;
    824826        return true;
     827      }
    825828    }
    826829    _getSingleton().activeKeyHandlers_.push_back((*mapIt).second);
     830    _getSingleton().stateRequest_ = IS_CUSTOM;
    827831    return true;
    828832  }
     
    846850      {
    847851        _getSingleton().activeKeyHandlers_.erase(it);
     852        _getSingleton().stateRequest_ = IS_CUSTOM;
    848853        return true;
    849854      }
    850855    }
     856    _getSingleton().stateRequest_ = IS_CUSTOM;
    851857    return true;
    852858  }
     
    942948    {
    943949      if ((*it) == (*mapIt).second)
     950      {
     951        _getSingleton().stateRequest_ = IS_CUSTOM;
    944952        return true;
     953      }
    945954    }
    946955    _getSingleton().activeMouseHandlers_.push_back((*mapIt).second);
     956    _getSingleton().stateRequest_ = IS_CUSTOM;
    947957    return true;
    948958  }
     
    966976      {
    967977        _getSingleton().activeMouseHandlers_.erase(it);
     978        _getSingleton().stateRequest_ = IS_CUSTOM;
    968979        return true;
    969980      }
    970981    }
     982    _getSingleton().stateRequest_ = IS_CUSTOM;
    971983    return true;
    972984  }
     
    10711083    {
    10721084      if ((*it) == (*handlerIt).second)
     1085      {
     1086        _getSingleton().stateRequest_ = IS_CUSTOM;
    10731087        return true;
     1088      }
    10741089    }
    10751090    _getSingleton().activeJoyStickHandlers_[id].push_back((*handlerIt).second);
     1091    _getSingleton().stateRequest_ = IS_CUSTOM;
    10761092    return true;
    10771093  }
     
    11011117      {
    11021118        _getSingleton().activeJoyStickHandlers_[id].erase(it);
     1119        _getSingleton().stateRequest_ = IS_CUSTOM;
    11031120        return true;
    11041121      }
    11051122    }
     1123    _getSingleton().stateRequest_ = IS_CUSTOM;
    11061124    return true;
    11071125  }
  • code/branches/input/src/orxonox/Orxonox.cc

    r1208 r1213  
    398398          ogre_->getWindowWidth(), ogre_->getWindowHeight()))
    399399      abortImmediateForce();
    400     InputManager::setInputState(InputManager::IS_NORMAL);
     400    InputManager::setInputState(InputManager::IS_CUSTOM);
     401    InputManager::enableKeyHandler("keybinder");
     402    InputManager::enableMouseHandler("keybinder");
     403    InputManager::enableJoyStickHandler("keybinder", 0);
    401404  }
    402405
  • code/branches/input/src/orxonox/objects/SpaceShip.cc

    r1195 r1213  
    428428    void SpaceShip::tick(float dt)
    429429    {
    430       if (InputManager::getMouse()->getEventCallback() != this)
    431         {
    432             if (InputManager::getMouse())
    433             {
    434                 InputManager::getMouse()->setEventCallback(this);
    435                 this->setMouseEventCallback_ = true;
    436             }
     430        if (!setMouseEventCallback_)
     431        {
     432          InputManager::addMouseHandler(this, "SpaceShip");
     433          InputManager::enableMouseHandler("SpaceShip");
     434          setMouseEventCallback_ = true;
    437435        }
    438436
     
    458456
    459457        OIS::Keyboard* mKeyboard = InputManager::getKeyboard();
    460         //FIXME: variable never used
    461         //OIS::Mouse* mMouse = InputManager::getSingleton().getMouse();
    462458
    463459
  • code/branches/input/src/orxonox/objects/SpaceShip.h

    r1195 r1213  
    3434#include <OgrePrerequisites.h>
    3535
    36 #include "ois/OISMouse.h"
     36#include "core/InputHandler.h"
    3737#include "Model.h"
    3838#include "../tools/BillboardSet.h"
     
    4040namespace orxonox
    4141{
    42     class _OrxonoxExport SpaceShip : public Model, public OIS::MouseListener
     42    class _OrxonoxExport SpaceShip : public Model, public MouseHandler
    4343    {
    4444        public:
     
    6868            bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
    6969            bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);
     70            bool mouseHeld(const OIS::MouseEvent &e, OIS::MouseButtonID id) { return true; }
    7071
    7172
Note: See TracChangeset for help on using the changeset viewer.