Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 24, 2008, 9:40:23 PM (16 years ago)
Author:
rgrieder
Message:
  • InputManager works so far, but has to be largely extended
File:
1 edited

Legend:

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

    r1066 r1182  
    3838#include "InputEvent.h"
    3939#include "InputManager.h"
     40#include "core/CommandExecutor.h"
    4041
    4142namespace orxonox
     
    6869    {
    6970      // simply write the key number (i) in the string
    70       this->bindingsKeyPressed_[i] = getConvertedValue<int, std::string>(i);
    71       this->bindingsKeyReleased_[i] = getConvertedValue<int, std::string>(i);
    72     }
     71      this->bindingsKeyPress_[i] = "";
     72      this->bindingsKeyRelease_[i] = "";
     73    }
     74    this->bindingsKeyPress_[OIS::KC_NUMPADENTER] = "setInputMode " + getConvertedValue<int, std::string>(IM_KEYBOARD);
     75    this->bindingsKeyPress_[OIS::KC_ESCAPE] = "exit";
     76    this->bindingsKeyHold_[OIS::KC_U] = "exec disco.txt";
    7377    return true;
    7478  }
     
    8084  bool InputHandlerGame::keyPressed(const OIS::KeyEvent &e)
    8185  {
    82     if (e.key == OIS::KC_ESCAPE)
    83     {
    84       InputEvent e = {1, true, 0, 0, 0};
    85       InputHandlerGame::callListeners(e);
    86     }
    87     else if (e.key == OIS::KC_NUMPADENTER)
    88     {
    89       InputManager::getSingleton().setInputMode(IM_KEYBOARD);
    90     }
    91     else
     86    this->keysDown_.push_back(e.key);
     87    // find the appropriate key binding
     88    std::string cmdStr = bindingsKeyPress_[int(e.key)];
     89    if (cmdStr != "")
     90    {
     91      CommandExecutor::execute(cmdStr);
     92      COUT(3) << "Executing command: " << cmdStr << std::endl;
     93    }
     94    return true;
     95  }
     96
     97  /**
     98    @brief Event handler for the keyReleased Event.
     99    @param e Event information
     100  */
     101  bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e)
     102  {
     103    // remove the key from the keysDown_ list
     104    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
     105    {
     106      if (*it == e.key)
     107      {
     108        keysDown_.erase(it);
     109        break;
     110      }
     111    }
     112
     113    // find the appropriate key binding
     114    std::string cmdStr = bindingsKeyRelease_[int(e.key)];
     115    if (cmdStr != "")
     116    {
     117      CommandExecutor::execute(cmdStr);
     118      COUT(3) << "Executing command: " << cmdStr << std::endl;
     119    }
     120    return true;
     121  }
     122
     123  /**
     124    @brief Event handler for the mouseMoved Event.
     125    @param e Event information
     126  */
     127  bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e)
     128  {
     129    return true;
     130  }
     131
     132  /**
     133    @brief Event handler for the mousePressed Event.
     134    @param e Event information
     135    @param id The ID of the mouse button
     136  */
     137  bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     138  {
     139    return true;
     140  }
     141
     142  /**
     143    @brief Event handler for the mouseReleased Event.
     144    @param e Event information
     145    @param id The ID of the mouse button
     146  */
     147  bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
     148  {
     149    return true;
     150  }
     151
     152  /**
     153    @brief Tick method to do additional calculations.
     154    @param dt Delta time.
     155  */
     156  void InputHandlerGame::tick(float dt)
     157  {
     158    // iterate through all the pressed keys
     159    for (std::list<OIS::KeyCode>::iterator it = keysDown_.begin(); it != keysDown_.end(); it++)
    92160    {
    93161      // find the appropriate key binding
    94       std::string cmdStr = bindingsKeyPressed_[int(e.key)];
    95       //COUT(3) << cmdStr << " pressed" << std::endl;
    96     }
    97     return true;
    98   }
    99 
    100   /**
    101     @brief Event handler for the keyReleased Event.
    102     @param e Event information
    103   */
    104   bool InputHandlerGame::keyReleased(const OIS::KeyEvent &e)
    105   {
    106     // find the appropriate key binding
    107     std::string cmdStr = bindingsKeyReleased_[int(e.key)];
    108     //COUT(3) << cmdStr << " released" << std::endl;
    109     return true;
    110   }
    111 
    112   /**
    113     @brief Event handler for the mouseMoved Event.
    114     @param e Event information
    115   */
    116   bool InputHandlerGame::mouseMoved(const OIS::MouseEvent &e)
    117   {
    118     return true;
    119   }
    120 
    121   /**
    122     @brief Event handler for the mousePressed Event.
    123     @param e Event information
    124     @param id The ID of the mouse button
    125   */
    126   bool InputHandlerGame::mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    127   {
    128     return true;
    129   }
    130 
    131   /**
    132     @brief Event handler for the mouseReleased Event.
    133     @param e Event information
    134     @param id The ID of the mouse button
    135   */
    136   bool InputHandlerGame::mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id)
    137   {
    138     return true;
     162      std::string cmdStr = bindingsKeyHold_[*it];
     163      if (cmdStr != "")
     164      {
     165        CommandExecutor::execute(cmdStr);
     166        COUT(3) << "Executing command: " << cmdStr << std::endl;
     167      }
     168    }
    139169  }
    140170
     
    226256  }
    227257
     258  /**
     259    @brief Tick method to do additional calculations.
     260    @param dt Delta time.
     261  */
     262  void InputHandlerGUI::tick(float dt)
     263  {
     264   
     265  }
     266
    228267}
Note: See TracChangeset for help on using the changeset viewer.