OpenMW
apps/openmw/mwinput/inputmanagerimp.hpp
Go to the documentation of this file.
00001 #ifndef _MWINPUT_MWINPUTMANAGERIMP_H
00002 #define _MWINPUT_MWINPUTMANAGERIMP_H
00003 
00004 #include "../mwgui/mode.hpp"
00005 
00006 #include <components/settings/settings.hpp>
00007 
00008 #include "../mwbase/inputmanager.hpp"
00009 #include <extern/sdl4ogre/sdlinputwrapper.hpp>
00010 
00011 namespace OEngine
00012 {
00013     namespace Render
00014     {
00015         class OgreRenderer;
00016     }
00017 }
00018 
00019 namespace MWWorld
00020 {
00021     class Player;
00022 }
00023 
00024 namespace MWBase
00025 {
00026     class WindowManager;
00027 }
00028 
00029 namespace OMW
00030 {
00031     class Engine;
00032 }
00033 
00034 namespace ICS
00035 {
00036     class InputControlSystem;
00037 }
00038 
00039 namespace MyGUI
00040 {
00041     class MouseButton;
00042 }
00043 
00044 #include <extern/oics/ICSChannelListener.h>
00045 #include <extern/oics/ICSInputControlSystem.h>
00046 
00047 namespace MWInput
00048 {
00049 
00053     class InputManager :
00054             public MWBase::InputManager,
00055             public SFO::KeyListener,
00056             public SFO::MouseListener,
00057             public SFO::WindowListener,
00058             public ICS::ChannelListener,
00059             public ICS::DetectingBindingListener
00060     {
00061     public:
00062         InputManager(OEngine::Render::OgreRenderer &_ogre,
00063             OMW::Engine& engine,
00064             const std::string& userFile, bool userFileExists, bool grab);
00065 
00066         virtual ~InputManager();
00067 
00068         virtual void update(float dt, bool loading);
00069 
00070         void setPlayer (MWWorld::Player* player) { mPlayer = player; }
00071 
00072         virtual void changeInputMode(bool guiMode);
00073 
00074         virtual void processChangedSettings(const Settings::CategorySettingVector& changed);
00075 
00076         virtual void setDragDrop(bool dragDrop);
00077 
00078         virtual void toggleControlSwitch (const std::string& sw, bool value);
00079         virtual bool getControlSwitch (const std::string& sw);
00080 
00081         virtual std::string getActionDescription (int action);
00082         virtual std::string getActionBindingName (int action);
00083         virtual int getNumActions() { return A_Last; }
00084         virtual std::vector<int> getActionSorting ();
00085         virtual void enableDetectingBindingMode (int action);
00086         virtual void resetToDefaultBindings();
00087 
00088     public:
00089         virtual bool keyPressed(const SDL_KeyboardEvent &arg );
00090         virtual bool keyReleased( const SDL_KeyboardEvent &arg );
00091         virtual void textInput (const SDL_TextInputEvent &arg);
00092 
00093         virtual bool mousePressed( const SDL_MouseButtonEvent &arg, Uint8 id );
00094         virtual bool mouseReleased( const SDL_MouseButtonEvent &arg, Uint8 id );
00095         virtual bool mouseMoved( const SFO::MouseMotionEvent &arg );
00096 
00097         virtual void windowVisibilityChange( bool visible );
00098         virtual void windowFocusChange( bool have_focus );
00099         virtual void windowResized (int x, int y);
00100         virtual void windowClosed ();
00101 
00102         virtual void channelChanged(ICS::Channel* channel, float currentValue, float previousValue);
00103 
00104         virtual void mouseAxisBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
00105             , ICS::InputControlSystem::NamedAxis axis, ICS::Control::ControlChangingDirection direction);
00106 
00107         virtual void keyBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
00108             , SDL_Keycode key, ICS::Control::ControlChangingDirection direction);
00109 
00110         virtual void mouseButtonBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
00111             , unsigned int button, ICS::Control::ControlChangingDirection direction);
00112 
00113         virtual void joystickAxisBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
00114             , int deviceId, int axis, ICS::Control::ControlChangingDirection direction);
00115 
00116         virtual void joystickButtonBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
00117             , int deviceId, unsigned int button, ICS::Control::ControlChangingDirection direction);
00118 
00119         virtual void joystickPOVBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
00120             , int deviceId, int pov,ICS:: InputControlSystem::POVAxis axis, ICS::Control::ControlChangingDirection direction);
00121 
00122         virtual void joystickSliderBindingDetected(ICS::InputControlSystem* ICS, ICS::Control* control
00123             , int deviceId, int slider, ICS::Control::ControlChangingDirection direction);
00124 
00125         void clearAllBindings (ICS::Control* control);
00126 
00127     private:
00128         OEngine::Render::OgreRenderer &mOgre;
00129         MWWorld::Player* mPlayer;
00130         OMW::Engine& mEngine;
00131 
00132         ICS::InputControlSystem* mInputBinder;
00133 
00134 
00135         SFO::InputWrapper* mInputManager;
00136 
00137         std::string mUserFile;
00138 
00139         bool mDragDrop;
00140 
00141         bool mGrabCursor;
00142 
00143         bool mInvertY;
00144 
00145         float mCameraSensitivity;
00146         float mUISensitivity;
00147         float mCameraYMultiplier;
00148         float mPreviewPOVDelay;
00149         float mTimeIdle;
00150 
00151         bool mMouseLookEnabled;
00152         bool mGuiCursorEnabled;
00153 
00154         float mOverencumberedMessageDelay;
00155 
00156         float mMouseX;
00157         float mMouseY;
00158         int mMouseWheel;
00159         bool mUserFileExists;
00160         bool mAlwaysRunActive;
00161 
00162         std::map<std::string, bool> mControlSwitch;
00163 
00164     private:
00165         void adjustMouseRegion(int width, int height);
00166         MyGUI::MouseButton sdlButtonToMyGUI(Uint8 button);
00167 
00168         void resetIdleTime();
00169         void updateIdleTime(float dt);
00170 
00171     private:
00172         void toggleMainMenu();
00173         void toggleSpell();
00174         void toggleWeapon();
00175         void toggleInventory();
00176         void toggleContainer();
00177         void toggleConsole();
00178         void screenshot();
00179         void toggleJournal();
00180         void activate();
00181         void toggleWalking();
00182         void toggleAutoMove();
00183         void rest();
00184 
00185         void quickKey (int index);
00186         void showQuickKeysMenu();
00187 
00188         bool actionIsActive (int id);
00189 
00190         void loadKeyDefaults(bool force = false);
00191 
00192     private:
00193         enum Actions
00194         {
00195             // please add new actions at the bottom, in order to preserve the channel IDs in the key configuration files
00196 
00197             A_GameMenu,
00198 
00199             A_Unused,
00200 
00201             A_Screenshot,     // Take a screenshot
00202 
00203             A_Inventory,      // Toggle inventory screen
00204 
00205             A_Console,        // Toggle console screen
00206 
00207             A_MoveLeft,       // Move player left / right
00208             A_MoveRight,
00209             A_MoveForward,    // Forward / Backward
00210             A_MoveBackward,
00211 
00212             A_Activate,
00213 
00214             A_Use,        //Use weapon, spell, etc.
00215             A_Jump,
00216             A_AutoMove,   //Toggle Auto-move forward
00217             A_Rest,       //Rest
00218             A_Journal,    //Journal
00219             A_Weapon,     //Draw/Sheath weapon
00220             A_Spell,      //Ready/Unready Casting
00221             A_Run,        //Run when held
00222             A_CycleSpellLeft, //cycling through spells
00223             A_CycleSpellRight,
00224             A_CycleWeaponLeft,//Cycling through weapons
00225             A_CycleWeaponRight,
00226             A_ToggleSneak,    //Toggles Sneak
00227             A_AlwaysRun, //Toggle Walking/Running
00228             A_Sneak,
00229 
00230             A_QuickSave,
00231             A_QuickLoad,
00232             A_QuickMenu,
00233             A_ToggleWeapon,
00234             A_ToggleSpell,
00235 
00236             A_TogglePOV,
00237 
00238             A_QuickKey1,
00239             A_QuickKey2,
00240             A_QuickKey3,
00241             A_QuickKey4,
00242             A_QuickKey5,
00243             A_QuickKey6,
00244             A_QuickKey7,
00245             A_QuickKey8,
00246             A_QuickKey9,
00247             A_QuickKey10,
00248 
00249             A_QuickKeysMenu,
00250 
00251             A_ToggleHUD,
00252 
00253             A_Last            // Marker for the last item
00254         };
00255     };
00256 }
00257 #endif