2012-08-11 15:53:39 +00:00
# include "inputmanagerimp.hpp"
2010-07-17 17:58:15 +00:00
2012-08-10 14:21:53 +00:00
# include <OgreRoot.h>
2012-08-12 18:45:02 +00:00
# include <OgreRenderWindow.h>
2012-08-10 14:21:53 +00:00
2012-08-12 20:59:58 +00:00
# include <boost/lexical_cast.hpp>
2010-07-17 17:58:15 +00:00
2012-08-12 18:45:02 +00:00
# include <MyGUI_InputManager.h>
# include <MyGUI_RenderManager.h>
2012-08-27 08:01:53 +00:00
# include <MyGUI_Widget.h>
# include <MyGUI_Button.h>
2014-01-04 00:13:19 +00:00
# include <MyGUI_EditBox.h>
2010-07-17 17:58:15 +00:00
2012-08-12 18:45:02 +00:00
# include <openengine/ogre/renderer.hpp>
2012-08-08 20:15:52 +00:00
2010-08-05 11:36:33 +00:00
# include "../engine.hpp"
2012-08-10 13:15:48 +00:00
# include "../mwbase/world.hpp"
2012-08-12 18:45:02 +00:00
# include "../mwbase/windowmanager.hpp"
2012-08-27 08:01:53 +00:00
# include "../mwbase/soundmanager.hpp"
2013-11-16 10:07:23 +00:00
# include "../mwbase/statemanager.hpp"
2014-04-25 02:47:45 +00:00
# include "../mwbase/mechanicsmanager.hpp"
2014-02-23 19:11:05 +00:00
# include "../mwworld/player.hpp"
# include "../mwworld/class.hpp"
# include "../mwworld/inventorystore.hpp"
# include "../mwworld/esmstore.hpp"
2014-06-17 15:18:30 +00:00
# include "../mwmechanics/npcstats.hpp"
2010-07-17 17:58:15 +00:00
2014-05-27 03:13:37 +00:00
# include "../mwdialogue/dialoguemanagerimp.hpp"
2014-05-27 07:00:31 +00:00
# include "../mwgui/windowbase.hpp"
2013-01-08 10:19:05 +00:00
using namespace ICS ;
2013-06-16 17:43:59 +00:00
namespace
{
std : : vector < unsigned long > utf8ToUnicode ( const std : : string & utf8 )
{
std : : vector < unsigned long > unicode ;
size_t i = 0 ;
while ( i < utf8 . size ( ) )
{
unsigned long uni ;
size_t todo ;
unsigned char ch = utf8 [ i + + ] ;
if ( ch < = 0x7F )
{
uni = ch ;
todo = 0 ;
}
else if ( ch < = 0xBF )
{
throw std : : logic_error ( " not a UTF-8 string " ) ;
}
else if ( ch < = 0xDF )
{
uni = ch & 0x1F ;
todo = 1 ;
}
else if ( ch < = 0xEF )
{
uni = ch & 0x0F ;
todo = 2 ;
}
else if ( ch < = 0xF7 )
{
uni = ch & 0x07 ;
todo = 3 ;
}
else
{
throw std : : logic_error ( " not a UTF-8 string " ) ;
}
for ( size_t j = 0 ; j < todo ; + + j )
{
if ( i = = utf8 . size ( ) )
throw std : : logic_error ( " not a UTF-8 string " ) ;
unsigned char ch = utf8 [ i + + ] ;
if ( ch < 0x80 | | ch > 0xBF )
throw std : : logic_error ( " not a UTF-8 string " ) ;
uni < < = 6 ;
uni + = ch & 0x3F ;
}
if ( uni > = 0xD800 & & uni < = 0xDFFF )
throw std : : logic_error ( " not a UTF-8 string " ) ;
if ( uni > 0x10FFFF )
throw std : : logic_error ( " not a UTF-8 string " ) ;
unicode . push_back ( uni ) ;
}
return unicode ;
}
}
2010-07-17 17:58:15 +00:00
namespace MWInput
{
2012-08-12 18:45:02 +00:00
InputManager : : InputManager ( OEngine : : Render : : OgreRenderer & ogre ,
OMW : : Engine & engine ,
2013-11-29 19:06:54 +00:00
const std : : string & userFile , bool userFileExists , bool grab )
2012-08-12 18:45:02 +00:00
: mOgre ( ogre )
2013-08-27 13:48:13 +00:00
, mPlayer ( NULL )
2012-08-12 18:45:02 +00:00
, mEngine ( engine )
2014-03-27 18:51:48 +00:00
, mMouseLookEnabled ( false )
2012-08-12 18:45:02 +00:00
, mMouseX ( ogre . getWindow ( ) - > getWidth ( ) / 2.f )
, mMouseY ( ogre . getWindow ( ) - > getHeight ( ) / 2.f )
2013-01-03 00:07:17 +00:00
, mMouseWheel ( 0 )
2012-08-12 18:45:02 +00:00
, mDragDrop ( false )
2014-03-27 18:51:48 +00:00
, mGuiCursorEnabled ( true )
2013-02-05 18:22:08 +00:00
, mUserFile ( userFile )
, mUserFileExists ( userFileExists )
2012-08-13 00:55:22 +00:00
, mInvertY ( Settings : : Manager : : getBool ( " invert y axis " , " Input " ) )
2012-08-13 16:48:50 +00:00
, mCameraSensitivity ( Settings : : Manager : : getFloat ( " camera sensitivity " , " Input " ) )
, mUISensitivity ( Settings : : Manager : : getFloat ( " ui sensitivity " , " Input " ) )
, mCameraYMultiplier ( Settings : : Manager : : getFloat ( " camera y multiplier " , " Input " ) )
2013-12-28 23:58:48 +00:00
, mGrabCursor ( Settings : : Manager : : getBool ( " grab cursor " , " Input " ) )
2012-08-17 12:42:42 +00:00
, mPreviewPOVDelay ( 0.f )
2012-08-17 21:31:57 +00:00
, mTimeIdle ( 0.f )
2013-02-25 15:31:48 +00:00
, mOverencumberedMessageDelay ( 0.f )
2014-06-08 17:50:39 +00:00
, mAlwaysRunActive ( Settings : : Manager : : getBool ( " always run " , " Input " ) )
2014-05-27 17:12:27 +00:00
, mAttemptJump ( false )
2014-04-26 12:33:45 +00:00
, mControlsDisabled ( false )
2010-07-17 17:58:15 +00:00
{
2012-05-01 19:54:30 +00:00
2013-01-09 10:10:05 +00:00
Ogre : : RenderWindow * window = ogre . getWindow ( ) ;
2013-11-29 19:06:54 +00:00
mInputManager = new SFO : : InputWrapper ( mOgre . getSDLWindow ( ) , mOgre . getWindow ( ) , grab ) ;
2013-01-08 10:19:05 +00:00
mInputManager - > setMouseEventCallback ( this ) ;
mInputManager - > setKeyboardEventCallback ( this ) ;
2013-01-09 10:10:05 +00:00
mInputManager - > setWindowEventCallback ( this ) ;
2010-07-17 17:58:15 +00:00
2013-01-08 10:19:05 +00:00
std : : string file = userFileExists ? userFile : " " ;
2013-01-10 21:21:47 +00:00
mInputBinder = new ICS : : InputControlSystem ( file , true , this , NULL , A_Last ) ;
2012-05-13 08:18:17 +00:00
2012-08-12 18:45:02 +00:00
adjustMouseRegion ( window - > getWidth ( ) , window - > getHeight ( ) ) ;
2010-07-17 17:58:15 +00:00
2012-08-12 20:59:58 +00:00
loadKeyDefaults ( ) ;
2011-11-28 15:51:11 +00:00
2012-08-12 23:26:15 +00:00
for ( int i = 0 ; i < A_Last ; + + i )
2012-08-12 18:45:02 +00:00
{
2013-01-10 21:21:47 +00:00
mInputBinder - > getChannel ( i ) - > addListener ( this ) ;
2012-08-12 18:45:02 +00:00
}
2011-11-28 15:51:11 +00:00
2012-08-12 18:45:02 +00:00
mControlSwitch [ " playercontrols " ] = true ;
mControlSwitch [ " playerfighting " ] = true ;
mControlSwitch [ " playerjumping " ] = true ;
mControlSwitch [ " playerlooking " ] = true ;
mControlSwitch [ " playermagic " ] = true ;
mControlSwitch [ " playerviewswitch " ] = true ;
mControlSwitch [ " vanitymode " ] = true ;
2010-08-03 14:26:43 +00:00
}
2014-03-09 02:34:49 +00:00
void InputManager : : clear ( )
{
// Enable all controls
for ( std : : map < std : : string , bool > : : iterator it = mControlSwitch . begin ( ) ; it ! = mControlSwitch . end ( ) ; + + it )
it - > second = true ;
}
2012-08-12 18:45:02 +00:00
InputManager : : ~ InputManager ( )
2011-01-14 14:52:28 +00:00
{
2013-01-10 21:21:47 +00:00
mInputBinder - > save ( mUserFile ) ;
2011-01-18 14:20:36 +00:00
2013-01-10 21:21:47 +00:00
delete mInputBinder ;
2011-01-16 15:47:03 +00:00
2013-01-08 10:19:05 +00:00
delete mInputManager ;
2012-08-10 13:15:48 +00:00
}
2014-05-31 23:51:21 +00:00
void InputManager : : setPlayerControlsEnabled ( bool enabled )
{
2014-06-07 02:35:16 +00:00
int nPlayerChannels = 17 ;
2014-05-31 23:51:21 +00:00
int playerChannels [ ] = { A_Activate , A_AutoMove , A_AlwaysRun , A_ToggleWeapon ,
A_ToggleSpell , A_Rest , A_QuickKey1 , A_QuickKey2 ,
A_QuickKey3 , A_QuickKey4 , A_QuickKey5 , A_QuickKey6 ,
2014-06-07 02:35:16 +00:00
A_QuickKey7 , A_QuickKey8 , A_QuickKey9 , A_QuickKey10 ,
A_Use } ;
2014-05-31 23:51:21 +00:00
for ( int i = 0 ; i < nPlayerChannels ; i + + ) {
int pc = playerChannels [ i ] ;
mInputBinder - > getChannel ( pc ) - > setEnabled ( enabled ) ;
}
}
2012-08-12 18:45:02 +00:00
void InputManager : : channelChanged ( ICS : : Channel * channel , float currentValue , float previousValue )
2010-07-20 19:10:51 +00:00
{
2012-08-12 18:45:02 +00:00
if ( mDragDrop )
return ;
2010-07-20 19:10:51 +00:00
2012-08-19 20:09:22 +00:00
resetIdleTime ( ) ;
2010-07-17 17:58:15 +00:00
2012-08-12 18:45:02 +00:00
int action = channel - > getNumber ( ) ;
2013-07-16 14:25:41 +00:00
2014-11-28 14:54:38 +00:00
if ( mControlSwitch [ " playercontrols " ] )
2013-07-16 14:25:41 +00:00
{
2014-11-28 14:54:38 +00:00
if ( action = = A_Use )
mPlayer - > getPlayer ( ) . getClass ( ) . getCreatureStats ( mPlayer - > getPlayer ( ) ) . setAttackingOrSpell ( currentValue ) ;
else if ( action = = A_Jump )
mAttemptJump = ( currentValue = = 1.0 & & previousValue = = 0.0 ) ;
2014-05-27 17:12:27 +00:00
}
2012-08-12 18:45:02 +00:00
if ( currentValue = = 1 )
{
// trigger action activated
switch ( action )
{
case A_GameMenu :
2014-02-23 19:11:05 +00:00
if ( ! ( MWBase : : Environment : : get ( ) . getStateManager ( ) - > getState ( ) ! = MWBase : : StateManager : : State_Running
2013-12-16 13:40:47 +00:00
& & MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getMode ( ) = = MWGui : : GM_MainMenu ) )
toggleMainMenu ( ) ;
2012-08-12 18:45:02 +00:00
break ;
case A_Screenshot :
2013-07-15 00:26:22 +00:00
screenshot ( ) ;
2013-07-15 00:23:18 +00:00
break ;
2012-08-12 18:45:02 +00:00
case A_Inventory :
toggleInventory ( ) ;
break ;
case A_Console :
toggleConsole ( ) ;
break ;
case A_Activate :
2012-08-17 21:31:57 +00:00
resetIdleTime ( ) ;
2013-07-15 00:18:24 +00:00
2014-01-10 23:24:21 +00:00
if ( ! MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) )
2013-07-29 16:27:00 +00:00
activate ( ) ;
2012-08-12 18:45:02 +00:00
break ;
case A_Journal :
toggleJournal ( ) ;
break ;
case A_AutoMove :
toggleAutoMove ( ) ;
break ;
2013-03-14 19:27:16 +00:00
case A_AlwaysRun :
2012-08-12 18:45:02 +00:00
toggleWalking ( ) ;
break ;
case A_ToggleWeapon :
toggleWeapon ( ) ;
break ;
2012-09-15 15:12:42 +00:00
case A_Rest :
rest ( ) ;
break ;
2012-08-12 18:45:02 +00:00
case A_ToggleSpell :
toggleSpell ( ) ;
break ;
2012-08-26 08:52:06 +00:00
case A_QuickKey1 :
quickKey ( 1 ) ;
break ;
case A_QuickKey2 :
quickKey ( 2 ) ;
break ;
case A_QuickKey3 :
quickKey ( 3 ) ;
break ;
case A_QuickKey4 :
quickKey ( 4 ) ;
break ;
case A_QuickKey5 :
quickKey ( 5 ) ;
break ;
case A_QuickKey6 :
quickKey ( 6 ) ;
break ;
case A_QuickKey7 :
quickKey ( 7 ) ;
break ;
case A_QuickKey8 :
quickKey ( 8 ) ;
break ;
case A_QuickKey9 :
quickKey ( 9 ) ;
break ;
case A_QuickKey10 :
quickKey ( 10 ) ;
break ;
case A_QuickKeysMenu :
showQuickKeysMenu ( ) ;
break ;
2012-08-30 18:47:39 +00:00
case A_ToggleHUD :
2014-06-20 16:49:19 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > toggleGui ( ) ;
2012-08-30 18:47:39 +00:00
break ;
2014-09-28 15:57:14 +00:00
case A_ToggleDebug :
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > toggleDebugWindow ( ) ;
break ;
2014-04-24 01:02:09 +00:00
case A_QuickSave :
quickSave ( ) ;
break ;
case A_QuickLoad :
quickLoad ( ) ;
break ;
2014-12-15 14:23:03 +00:00
case A_CycleSpellLeft :
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > cycleSpell ( false ) ;
break ;
case A_CycleSpellRight :
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > cycleSpell ( true ) ;
break ;
case A_CycleWeaponLeft :
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > cycleWeapon ( false ) ;
break ;
case A_CycleWeaponRight :
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > cycleWeapon ( true ) ;
break ;
2013-02-05 19:26:13 +00:00
}
2012-08-12 18:45:02 +00:00
}
2012-05-13 08:18:17 +00:00
}
2015-01-13 03:53:49 +00:00
void InputManager : : updateCursorMode ( )
2010-07-17 17:58:15 +00:00
{
2013-11-15 02:39:25 +00:00
bool grab = ! MWBase : : Environment : : get ( ) . getWindowManager ( ) - > containsMode ( MWGui : : GM_MainMenu )
& & MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getMode ( ) ! = MWGui : : GM_Console ;
2013-01-09 13:05:47 +00:00
2013-06-16 18:39:40 +00:00
bool was_relative = mInputManager - > getMouseRelative ( ) ;
2013-08-27 13:48:13 +00:00
bool is_relative = ! MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) ;
2013-01-09 13:05:47 +00:00
2013-06-16 18:39:40 +00:00
// don't keep the pointer away from the window edge in gui mode
// stop using raw mouse motions and switch to system cursor movements
mInputManager - > setMouseRelative ( is_relative ) ;
2013-01-09 13:05:47 +00:00
2013-06-16 18:39:40 +00:00
//we let the mouse escape in the main menu
2013-12-28 23:58:48 +00:00
mInputManager - > setGrabPointer ( grab & & ( mGrabCursor | | is_relative ) ) ;
2013-06-15 13:33:47 +00:00
2013-06-16 18:39:40 +00:00
//we switched to non-relative mode, move our cursor to where the in-game
//cursor is
if ( ! is_relative & & was_relative ! = is_relative )
{
mInputManager - > warpMouse ( mMouseX , mMouseY ) ;
2013-01-09 10:10:05 +00:00
}
2015-01-13 03:53:49 +00:00
}
void InputManager : : update ( float dt , bool disableControls , bool disableEvents )
{
mControlsDisabled = disableControls ;
mInputManager - > setMouseVisible ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getCursorVisible ( ) ) ;
mInputManager - > capture ( disableEvents ) ;
// inject some fake mouse movement to force updating MyGUI's widget states
MyGUI : : InputManager : : getInstance ( ) . injectMouseMove ( int ( mMouseX ) , int ( mMouseY ) , mMouseWheel ) ;
if ( mControlsDisabled )
{
updateCursorMode ( ) ;
return ;
}
// update values of channels (as a result of pressed keys)
mInputBinder - > update ( dt ) ;
updateCursorMode ( ) ;
2013-01-09 10:10:05 +00:00
2011-02-03 11:16:59 +00:00
// Disable movement in Gui mode
2014-05-27 17:12:27 +00:00
if ( ! ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( )
| | MWBase : : Environment : : get ( ) . getStateManager ( ) - > getState ( ) ! = MWBase : : StateManager : : State_Running ) )
2012-08-12 18:45:02 +00:00
{
2014-05-27 17:12:27 +00:00
// Configure player movement according to keyboard input. Actual movement will
// be done in the physics system.
if ( mControlSwitch [ " playercontrols " ] )
2012-08-04 07:54:42 +00:00
{
2014-05-27 17:12:27 +00:00
bool triedToMove = false ;
if ( actionIsActive ( A_MoveLeft ) )
{
triedToMove = true ;
mPlayer - > setLeftRight ( - 1 ) ;
}
else if ( actionIsActive ( A_MoveRight ) )
{
triedToMove = true ;
mPlayer - > setLeftRight ( 1 ) ;
}
2012-08-04 07:54:42 +00:00
2014-05-27 17:12:27 +00:00
if ( actionIsActive ( A_MoveForward ) )
{
triedToMove = true ;
mPlayer - > setAutoMove ( false ) ;
mPlayer - > setForwardBackward ( 1 ) ;
}
else if ( actionIsActive ( A_MoveBackward ) )
{
triedToMove = true ;
mPlayer - > setAutoMove ( false ) ;
mPlayer - > setForwardBackward ( - 1 ) ;
}
2010-08-03 14:26:43 +00:00
2014-05-27 17:12:27 +00:00
else if ( mPlayer - > getAutoMove ( ) )
{
triedToMove = true ;
mPlayer - > setForwardBackward ( 1 ) ;
}
2013-04-07 17:04:30 +00:00
2014-05-27 17:12:27 +00:00
mPlayer - > setSneak ( actionIsActive ( A_Sneak ) ) ;
2010-08-03 14:26:43 +00:00
2014-05-27 17:12:27 +00:00
if ( mAttemptJump & & mControlSwitch [ " playerjumping " ] )
{
mPlayer - > setUpDown ( 1 ) ;
triedToMove = true ;
2014-12-02 17:42:13 +00:00
mOverencumberedMessageDelay = 0.f ;
2014-05-27 17:12:27 +00:00
}
2012-08-12 11:50:37 +00:00
2014-05-27 17:12:27 +00:00
if ( mAlwaysRunActive )
mPlayer - > setRunState ( ! actionIsActive ( A_Run ) ) ;
else
mPlayer - > setRunState ( actionIsActive ( A_Run ) ) ;
2013-02-07 01:51:47 +00:00
2014-05-27 17:12:27 +00:00
// if player tried to start moving, but can't (due to being overencumbered), display a notification.
if ( triedToMove )
2013-02-25 15:31:48 +00:00
{
2014-05-27 17:12:27 +00:00
MWWorld : : Ptr player = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) ;
mOverencumberedMessageDelay - = dt ;
2014-10-05 13:52:33 +00:00
if ( player . getClass ( ) . getEncumbrance ( player ) > player . getClass ( ) . getCapacity ( player ) )
2013-02-25 15:31:48 +00:00
{
2014-05-27 17:12:27 +00:00
mPlayer - > setAutoMove ( false ) ;
if ( mOverencumberedMessageDelay < = 0 )
{
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox ( " #{sNotifyMessage59} " ) ;
mOverencumberedMessageDelay = 1.0 ;
}
2013-02-25 15:31:48 +00:00
}
}
2012-08-27 17:25:30 +00:00
2014-05-27 17:12:27 +00:00
if ( mControlSwitch [ " playerviewswitch " ] ) {
2015-01-09 23:07:40 +00:00
if ( actionIsActive ( A_TogglePOV ) ) {
2014-05-27 17:12:27 +00:00
if ( mPreviewPOVDelay < = 0.5 & &
( mPreviewPOVDelay + = dt ) > 0.5 )
{
mPreviewPOVDelay = 1.f ;
MWBase : : Environment : : get ( ) . getWorld ( ) - > togglePreviewMode ( true ) ;
}
} else {
//disable preview mode
MWBase : : Environment : : get ( ) . getWorld ( ) - > togglePreviewMode ( false ) ;
if ( mPreviewPOVDelay > 0.f & & mPreviewPOVDelay < = 0.5 ) {
MWBase : : Environment : : get ( ) . getWorld ( ) - > togglePOV ( ) ;
}
mPreviewPOVDelay = 0.f ;
2012-08-19 20:09:22 +00:00
}
}
}
2014-05-27 17:12:27 +00:00
if ( actionIsActive ( A_MoveForward ) | |
actionIsActive ( A_MoveBackward ) | |
actionIsActive ( A_MoveLeft ) | |
actionIsActive ( A_MoveRight ) | |
actionIsActive ( A_Jump ) | |
actionIsActive ( A_Sneak ) | |
actionIsActive ( A_TogglePOV ) )
{
resetIdleTime ( ) ;
} else {
updateIdleTime ( dt ) ;
}
2012-08-19 20:09:22 +00:00
}
2014-05-27 17:12:27 +00:00
mAttemptJump = false ; // Can only jump on first frame input is on
2012-08-12 18:45:02 +00:00
}
void InputManager : : setDragDrop ( bool dragDrop )
{
mDragDrop = dragDrop ;
2010-07-17 17:58:15 +00:00
}
2010-09-15 12:48:19 +00:00
2012-08-12 18:45:02 +00:00
void InputManager : : changeInputMode ( bool guiMode )
2010-09-15 12:48:19 +00:00
{
2013-03-31 13:50:48 +00:00
mGuiCursorEnabled = guiMode ;
mMouseLookEnabled = ! guiMode ;
if ( guiMode )
2013-08-27 13:48:13 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > showCrosshair ( false ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > setCursorVisible ( guiMode ) ;
2013-03-31 13:50:48 +00:00
// if not in gui mode, the camera decides whether to show crosshair or not.
2012-08-12 18:45:02 +00:00
}
void InputManager : : processChangedSettings ( const Settings : : CategorySettingVector & changed )
{
for ( Settings : : CategorySettingVector : : const_iterator it = changed . begin ( ) ;
it ! = changed . end ( ) ; + + it )
{
2012-08-13 00:55:22 +00:00
if ( it - > first = = " Input " & & it - > second = = " invert y axis " )
mInvertY = Settings : : Manager : : getBool ( " invert y axis " , " Input " ) ;
2012-08-13 16:48:50 +00:00
if ( it - > first = = " Input " & & it - > second = = " camera sensitivity " )
mCameraSensitivity = Settings : : Manager : : getFloat ( " camera sensitivity " , " Input " ) ;
if ( it - > first = = " Input " & & it - > second = = " ui sensitivity " )
mUISensitivity = Settings : : Manager : : getFloat ( " ui sensitivity " , " Input " ) ;
2013-12-28 23:58:48 +00:00
if ( it - > first = = " Input " & & it - > second = = " grab cursor " )
mGrabCursor = Settings : : Manager : : getBool ( " grab cursor " , " Input " ) ;
2010-09-15 12:48:19 +00:00
}
}
2012-08-04 07:54:42 +00:00
2012-09-10 16:44:59 +00:00
bool InputManager : : getControlSwitch ( const std : : string & sw )
{
return mControlSwitch [ sw ] ;
}
2012-08-12 18:45:02 +00:00
void InputManager : : toggleControlSwitch ( const std : : string & sw , bool value )
2012-08-04 07:54:42 +00:00
{
if ( mControlSwitch [ sw ] = = value ) {
return ;
}
/// \note 7 switches at all, if-else is relevant
2012-08-09 06:55:49 +00:00
if ( sw = = " playercontrols " & & ! value ) {
2013-08-27 13:48:13 +00:00
mPlayer - > setLeftRight ( 0 ) ;
mPlayer - > setForwardBackward ( 0 ) ;
mPlayer - > setAutoMove ( false ) ;
mPlayer - > setUpDown ( 0 ) ;
2012-08-09 06:55:49 +00:00
} else if ( sw = = " playerjumping " & & ! value ) {
2012-08-04 07:54:42 +00:00
/// \fixme maybe crouching at this time
2013-08-27 13:48:13 +00:00
mPlayer - > setUpDown ( 0 ) ;
2012-08-17 09:23:02 +00:00
} else if ( sw = = " vanitymode " ) {
MWBase : : Environment : : get ( ) . getWorld ( ) - > allowVanityMode ( value ) ;
2012-08-09 06:55:49 +00:00
} else if ( sw = = " playerlooking " ) {
2012-08-17 09:23:02 +00:00
MWBase : : Environment : : get ( ) . getWorld ( ) - > togglePlayerLooking ( value ) ;
2012-08-04 07:54:42 +00:00
}
mControlSwitch [ sw ] = value ;
}
2012-08-12 18:45:02 +00:00
void InputManager : : adjustMouseRegion ( int width , int height )
{
2013-01-10 21:21:47 +00:00
mInputBinder - > adjustMouseRegion ( width , height ) ;
2012-08-12 18:45:02 +00:00
}
2012-05-28 07:19:25 +00:00
2014-02-13 14:08:40 +00:00
void InputManager : : keyPressed ( const SDL_KeyboardEvent & arg )
2012-08-12 18:45:02 +00:00
{
2014-09-10 15:58:53 +00:00
// HACK: to make Morrowind's default keybinding for the console work without printing an extra "^" upon closing
// This assumes that SDL_TextInput events always come *after* the key event
// (which is somewhat reasonable, and hopefully true for all SDL platforms)
2013-01-10 21:21:47 +00:00
OIS : : KeyCode kc = mInputManager - > sdl2OISKeyCode ( arg . keysym . sym ) ;
2014-09-10 15:58:53 +00:00
if ( mInputBinder - > getKeyBinding ( mInputBinder - > getControl ( A_Console ) , ICS : : Control : : INCREASE )
2014-09-13 18:39:32 +00:00
= = arg . keysym . scancode
2014-09-10 15:58:53 +00:00
& & MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getMode ( ) = = MWGui : : GM_Console )
SDL_StopTextInput ( ) ;
2013-01-10 21:21:47 +00:00
2014-08-25 16:55:21 +00:00
bool consumed = false ;
2013-06-16 17:43:59 +00:00
if ( kc ! = OIS : : KC_UNASSIGNED )
2014-05-31 23:51:21 +00:00
{
2014-08-25 16:55:21 +00:00
consumed = SDL_IsTextInputActive ( ) & &
( ! ( SDLK_SCANCODE_MASK & arg . keysym . sym ) & & std : : isprint ( arg . keysym . sym ) ) ; // Little trick to check if key is printable
2014-05-31 23:51:21 +00:00
bool guiFocus = MyGUI : : InputManager : : getInstance ( ) . injectKeyPress ( MyGUI : : KeyCode : : Enum ( kc ) , 0 ) ;
setPlayerControlsEnabled ( ! guiFocus ) ;
}
2014-08-25 16:55:21 +00:00
if ( ! mControlsDisabled & & ! consumed )
2014-05-31 23:58:21 +00:00
mInputBinder - > keyPressed ( arg ) ;
2012-08-12 18:45:02 +00:00
}
2012-08-04 07:54:42 +00:00
2013-06-16 17:43:59 +00:00
void InputManager : : textInput ( const SDL_TextInputEvent & arg )
{
const char * text = & arg . text [ 0 ] ;
std : : vector < unsigned long > unicode = utf8ToUnicode ( std : : string ( text ) ) ;
for ( std : : vector < unsigned long > : : iterator it = unicode . begin ( ) ; it ! = unicode . end ( ) ; + + it )
MyGUI : : InputManager : : getInstance ( ) . injectKeyPress ( MyGUI : : KeyCode : : None , * it ) ;
}
2014-02-13 14:08:40 +00:00
void InputManager : : keyReleased ( const SDL_KeyboardEvent & arg )
2012-08-04 07:54:42 +00:00
{
2013-01-10 21:21:47 +00:00
OIS : : KeyCode kc = mInputManager - > sdl2OISKeyCode ( arg . keysym . sym ) ;
2012-08-12 18:45:02 +00:00
2014-06-07 02:25:23 +00:00
setPlayerControlsEnabled ( ! MyGUI : : InputManager : : getInstance ( ) . injectKeyRelease ( MyGUI : : KeyCode : : Enum ( kc ) ) ) ;
mInputBinder - > keyReleased ( arg ) ;
2012-08-04 07:54:42 +00:00
}
2012-08-12 18:45:02 +00:00
2014-02-13 14:08:40 +00:00
void InputManager : : mousePressed ( const SDL_MouseButtonEvent & arg , Uint8 id )
2012-08-12 18:45:02 +00:00
{
2014-06-07 02:25:23 +00:00
bool guiMode = false ;
2013-06-12 13:10:04 +00:00
2014-06-08 00:08:29 +00:00
if ( id = = SDL_BUTTON_LEFT | | id = = SDL_BUTTON_RIGHT ) // MyGUI only uses these mouse events
2012-08-27 08:01:53 +00:00
{
2014-06-08 00:08:29 +00:00
guiMode = MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) ;
guiMode = MyGUI : : InputManager : : getInstance ( ) . injectMousePress ( mMouseX , mMouseY , sdlButtonToMyGUI ( id ) ) & & guiMode ;
2014-06-07 02:25:23 +00:00
if ( MyGUI : : InputManager : : getInstance ( ) . getMouseFocusWidget ( ) ! = 0 )
2012-08-27 08:01:53 +00:00
{
2014-06-07 02:25:23 +00:00
MyGUI : : Button * b = MyGUI : : InputManager : : getInstance ( ) . getMouseFocusWidget ( ) - > castType < MyGUI : : Button > ( false ) ;
if ( b & & b - > getEnabled ( ) )
{
MWBase : : Environment : : get ( ) . getSoundManager ( ) - > playSound ( " Menu Click " , 1.f , 1.f ) ;
}
2012-08-27 08:01:53 +00:00
}
}
2014-06-07 02:25:23 +00:00
setPlayerControlsEnabled ( ! guiMode ) ;
2014-09-12 18:28:08 +00:00
// Don't trigger any mouse bindings while in settings menu, otherwise rebinding controls becomes impossible
if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getMode ( ) ! = MWGui : : GM_Settings )
mInputBinder - > mousePressed ( arg , id ) ;
2012-08-12 18:45:02 +00:00
}
2014-02-13 14:08:40 +00:00
void InputManager : : mouseReleased ( const SDL_MouseButtonEvent & arg , Uint8 id )
2014-06-07 02:25:23 +00:00
{
2012-08-12 18:45:02 +00:00
2014-06-07 02:25:23 +00:00
if ( mInputBinder - > detectingBindingState ( ) )
{
mInputBinder - > mouseReleased ( arg , id ) ;
} else {
2014-06-08 00:08:29 +00:00
bool guiMode = MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) ;
guiMode = MyGUI : : InputManager : : getInstance ( ) . injectMouseRelease ( mMouseX , mMouseY , sdlButtonToMyGUI ( id ) ) & & guiMode ;
2012-08-12 18:45:02 +00:00
2014-06-07 02:25:23 +00:00
if ( mInputBinder - > detectingBindingState ( ) ) return ; // don't allow same mouseup to bind as initiated bind
setPlayerControlsEnabled ( ! guiMode ) ;
mInputBinder - > mouseReleased ( arg , id ) ;
}
2012-08-12 18:45:02 +00:00
}
2014-02-13 14:08:40 +00:00
void InputManager : : mouseMoved ( const SFO : : MouseMotionEvent & arg )
2012-08-12 18:45:02 +00:00
{
2013-01-10 21:21:47 +00:00
mInputBinder - > mouseMoved ( arg ) ;
2012-08-12 18:45:02 +00:00
2012-08-19 20:09:22 +00:00
resetIdleTime ( ) ;
2012-08-12 18:45:02 +00:00
if ( mGuiCursorEnabled )
{
const MyGUI : : IntSize & viewSize = MyGUI : : RenderManager : : getInstance ( ) . getViewSize ( ) ;
// We keep track of our own mouse position, so that moving the mouse while in
// game mode does not move the position of the GUI cursor
2013-01-11 03:29:51 +00:00
mMouseX = arg . x ;
mMouseY = arg . y ;
2013-01-09 13:05:47 +00:00
2012-08-13 19:33:53 +00:00
mMouseX = std : : max ( 0.f , std : : min ( mMouseX , float ( viewSize . width ) ) ) ;
mMouseY = std : : max ( 0.f , std : : min ( mMouseY , float ( viewSize . height ) ) ) ;
2013-01-08 10:19:05 +00:00
2013-01-10 21:59:49 +00:00
mMouseWheel = int ( arg . z ) ;
2012-08-12 18:45:02 +00:00
2013-01-03 00:07:17 +00:00
MyGUI : : InputManager : : getInstance ( ) . injectMouseMove ( int ( mMouseX ) , int ( mMouseY ) , mMouseWheel ) ;
2012-08-12 18:45:02 +00:00
}
2014-11-19 11:09:40 +00:00
if ( mMouseLookEnabled & & ! mControlsDisabled )
2012-08-12 18:45:02 +00:00
{
2012-08-17 21:31:57 +00:00
resetIdleTime ( ) ;
2013-06-12 10:34:33 +00:00
double x = arg . xrel * mCameraSensitivity * ( 1.0f / 256.f ) ;
double y = arg . yrel * mCameraSensitivity * ( 1.0f / 256.f ) * ( mInvertY ? - 1 : 1 ) * mCameraYMultiplier ;
2012-08-12 18:45:02 +00:00
2013-04-09 18:24:41 +00:00
float rot [ 3 ] ;
rot [ 0 ] = - y ;
rot [ 1 ] = 0.0f ;
2014-03-07 05:11:00 +00:00
rot [ 2 ] = - x ;
2013-09-23 13:34:52 +00:00
// Only actually turn player when we're not in vanity mode
2013-04-09 18:24:41 +00:00
if ( ! MWBase : : Environment : : get ( ) . getWorld ( ) - > vanityRotateCamera ( rot ) )
{
2014-01-29 19:29:07 +00:00
mPlayer - > yaw ( x ) ;
2014-03-07 05:11:00 +00:00
mPlayer - > pitch ( y ) ;
2013-04-09 18:24:41 +00:00
}
2012-08-12 18:45:02 +00:00
2014-11-28 14:54:38 +00:00
if ( arg . zrel & & mControlSwitch [ " playerviewswitch " ] & & mControlSwitch [ " playercontrols " ] ) //Check to make sure you are allowed to zoomout and there is a change
2013-07-16 16:38:18 +00:00
{
2013-06-12 10:34:33 +00:00
MWBase : : Environment : : get ( ) . getWorld ( ) - > changeVanityModeScale ( arg . zrel ) ;
2014-12-01 12:38:47 +00:00
if ( Settings : : Manager : : getBool ( " allow third person zoom " , " Input " ) )
MWBase : : Environment : : get ( ) . getWorld ( ) - > setCameraDistance ( arg . zrel , true , true ) ;
2013-07-16 16:38:18 +00:00
}
2012-08-12 18:45:02 +00:00
}
}
2013-07-29 00:32:08 +00:00
void InputManager : : windowFocusChange ( bool have_focus )
2013-01-09 10:10:05 +00:00
{
}
2013-07-29 00:32:08 +00:00
void InputManager : : windowVisibilityChange ( bool visible )
2013-01-09 10:10:05 +00:00
{
//TODO: Pause game?
2013-07-29 00:32:08 +00:00
}
void InputManager : : windowResized ( int x , int y )
{
mOgre . windowResized ( x , y ) ;
2013-01-09 10:10:05 +00:00
}
2013-11-05 02:02:28 +00:00
void InputManager : : windowClosed ( )
{
2013-11-16 10:07:23 +00:00
MWBase : : Environment : : get ( ) . getStateManager ( ) - > requestQuit ( ) ;
2013-11-05 02:02:28 +00:00
}
2012-08-12 18:45:02 +00:00
void InputManager : : toggleMainMenu ( )
{
2014-05-27 07:00:31 +00:00
if ( MyGUI : : InputManager : : getInstance ( ) . isModalAny ( ) ) {
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getCurrentModal ( ) - > exit ( ) ;
2013-02-25 05:57:32 +00:00
return ;
2014-05-27 07:00:31 +00:00
}
2013-02-25 05:57:32 +00:00
2014-05-27 03:13:37 +00:00
if ( ! MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) ) //No open GUIs, open up the MainMenu
2013-09-23 11:36:50 +00:00
{
2013-08-27 13:48:13 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_MainMenu ) ;
2013-09-23 11:36:50 +00:00
}
2014-05-27 03:13:37 +00:00
else //Close current GUI
{
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > exitCurrentGuiMode ( ) ;
}
2012-08-12 18:45:02 +00:00
}
2014-04-24 01:02:09 +00:00
void InputManager : : quickLoad ( ) {
2014-07-12 04:43:04 +00:00
if ( ! MyGUI : : InputManager : : getInstance ( ) . isModalAny ( ) )
MWBase : : Environment : : get ( ) . getStateManager ( ) - > quickLoad ( ) ;
2014-04-24 01:02:09 +00:00
}
void InputManager : : quickSave ( ) {
2014-07-12 04:43:04 +00:00
if ( ! MyGUI : : InputManager : : getInstance ( ) . isModalAny ( ) )
MWBase : : Environment : : get ( ) . getStateManager ( ) - > quickSave ( ) ;
2014-04-24 01:02:09 +00:00
}
2012-08-12 18:45:02 +00:00
void InputManager : : toggleSpell ( )
{
2013-08-27 13:48:13 +00:00
if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) ) return ;
2012-08-12 18:45:02 +00:00
2013-08-03 22:21:27 +00:00
// Not allowed before the magic window is accessible
2014-11-28 14:54:38 +00:00
if ( ! mControlSwitch [ " playermagic " ] | | ! mControlSwitch [ " playercontrols " ] )
2013-08-03 22:21:27 +00:00
return ;
2014-02-11 15:34:51 +00:00
// Not allowed if no spell selected
2014-05-22 18:37:22 +00:00
MWWorld : : InventoryStore & inventory = mPlayer - > getPlayer ( ) . getClass ( ) . getInventoryStore ( mPlayer - > getPlayer ( ) ) ;
2014-02-15 16:39:11 +00:00
if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getSelectedSpell ( ) . empty ( ) & &
inventory . getSelectedEnchantItem ( ) = = inventory . end ( ) )
2014-02-11 15:34:51 +00:00
return ;
2013-08-27 13:48:13 +00:00
MWMechanics : : DrawState_ state = mPlayer - > getDrawState ( ) ;
2012-08-12 18:45:02 +00:00
if ( state = = MWMechanics : : DrawState_Weapon | | state = = MWMechanics : : DrawState_Nothing )
2013-08-27 13:48:13 +00:00
mPlayer - > setDrawState ( MWMechanics : : DrawState_Spell ) ;
2012-08-12 18:45:02 +00:00
else
2013-08-27 13:48:13 +00:00
mPlayer - > setDrawState ( MWMechanics : : DrawState_Nothing ) ;
2012-08-12 18:45:02 +00:00
}
void InputManager : : toggleWeapon ( )
{
2013-08-27 13:48:13 +00:00
if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) ) return ;
2012-08-12 18:45:02 +00:00
2013-08-03 22:21:27 +00:00
// Not allowed before the inventory window is accessible
2014-11-28 14:54:38 +00:00
if ( ! mControlSwitch [ " playerfighting " ] | | ! mControlSwitch [ " playercontrols " ] )
2013-08-03 22:21:27 +00:00
return ;
2013-08-27 13:48:13 +00:00
MWMechanics : : DrawState_ state = mPlayer - > getDrawState ( ) ;
2012-08-12 18:45:02 +00:00
if ( state = = MWMechanics : : DrawState_Spell | | state = = MWMechanics : : DrawState_Nothing )
2013-08-27 13:48:13 +00:00
mPlayer - > setDrawState ( MWMechanics : : DrawState_Weapon ) ;
2012-08-12 18:45:02 +00:00
else
2013-08-27 13:48:13 +00:00
mPlayer - > setDrawState ( MWMechanics : : DrawState_Nothing ) ;
2012-08-12 18:45:02 +00:00
}
2012-09-15 15:12:42 +00:00
void InputManager : : rest ( )
{
2014-11-28 14:54:38 +00:00
if ( ! mControlSwitch [ " playercontrols " ] )
return ;
2013-08-27 13:48:13 +00:00
if ( ! MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getRestEnabled ( ) | | MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) )
2012-09-15 18:18:41 +00:00
return ;
2014-04-25 02:47:45 +00:00
if ( mPlayer - > isInCombat ( ) ) { //Check if in combat
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox ( " #{sNotifyMessage2} " ) ; //Nope,
return ;
}
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_Rest ) ; //Open rest GUI
2012-09-15 15:12:42 +00:00
}
2012-08-12 18:45:02 +00:00
void InputManager : : screenshot ( )
{
mEngine . screenshot ( ) ;
2015-01-10 22:21:39 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox ( " Screenshot saved " ) ;
2012-08-12 18:45:02 +00:00
}
void InputManager : : toggleInventory ( )
{
2014-11-28 14:54:38 +00:00
if ( ! mControlSwitch [ " playercontrols " ] )
return ;
2013-03-30 15:32:24 +00:00
if ( MyGUI : : InputManager : : getInstance ( ) . isModalAny ( ) )
return ;
2012-08-12 18:45:02 +00:00
// Toggle between game mode and inventory mode
2013-08-27 13:48:13 +00:00
if ( ! MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_Inventory ) ;
2013-02-10 04:37:45 +00:00
else
{
2013-08-27 13:48:13 +00:00
MWGui : : GuiMode mode = MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getMode ( ) ;
2013-02-10 04:37:45 +00:00
if ( mode = = MWGui : : GM_Inventory | | mode = = MWGui : : GM_Container )
2013-08-27 13:48:13 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > popGuiMode ( ) ;
2013-02-10 04:37:45 +00:00
}
2012-08-12 18:45:02 +00:00
2013-02-10 04:37:45 +00:00
// .. but don't touch any other mode, except container.
2012-08-12 18:45:02 +00:00
}
void InputManager : : toggleConsole ( )
{
2013-02-25 05:57:32 +00:00
if ( MyGUI : : InputManager : : getInstance ( ) . isModalAny ( ) )
return ;
2012-08-12 18:45:02 +00:00
// Switch to console mode no matter what mode we are currently
// in, except of course if we are already in console mode
2013-08-27 13:48:13 +00:00
if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) )
2012-08-12 18:45:02 +00:00
{
2013-08-27 13:48:13 +00:00
if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getMode ( ) = = MWGui : : GM_Console )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > popGuiMode ( ) ;
2012-08-12 18:45:02 +00:00
else
2013-08-27 13:48:13 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_Console ) ;
2012-08-12 18:45:02 +00:00
}
else
2013-08-27 13:48:13 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_Console ) ;
2012-08-12 18:45:02 +00:00
}
void InputManager : : toggleJournal ( )
{
2014-11-28 14:54:38 +00:00
if ( ! mControlSwitch [ " playercontrols " ] )
return ;
2013-03-30 15:32:24 +00:00
if ( MyGUI : : InputManager : : getInstance ( ) . isModalAny ( ) )
return ;
2014-08-01 17:40:17 +00:00
if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getMode ( ) ! = MWGui : : GM_Journal
2014-08-25 16:55:21 +00:00
& & MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getJournalAllowed ( ) )
2013-04-08 17:00:38 +00:00
{
MWBase : : Environment : : get ( ) . getSoundManager ( ) - > playSound ( " book open " , 1.0 , 1.0 ) ;
2013-08-27 13:48:13 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_Journal ) ;
2013-04-08 17:00:38 +00:00
}
2014-08-01 17:40:17 +00:00
else if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > containsMode ( MWGui : : GM_Journal ) )
2013-04-08 17:00:38 +00:00
{
2014-08-01 17:40:17 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > removeGuiMode ( MWGui : : GM_Journal ) ;
2013-04-08 17:00:38 +00:00
}
2012-08-12 18:45:02 +00:00
}
2012-08-26 08:52:06 +00:00
void InputManager : : quickKey ( int index )
{
2014-11-28 14:54:38 +00:00
if ( ! mControlSwitch [ " playercontrols " ] )
return ;
2014-06-17 15:18:30 +00:00
MWWorld : : Ptr player = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) ;
if ( player . getClass ( ) . getNpcStats ( player ) . isWerewolf ( ) )
{
// Cannot use items or spells while in werewolf form
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox ( " #{sWerewolfRefusal} " ) ;
return ;
}
2013-08-27 13:48:13 +00:00
if ( ! MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) )
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > activateQuickKey ( index ) ;
2012-08-26 08:52:06 +00:00
}
void InputManager : : showQuickKeysMenu ( )
{
2014-02-05 11:15:07 +00:00
if ( ! MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( )
& & MWBase : : Environment : : get ( ) . getWorld ( ) - > getGlobalFloat ( " chargenstate " ) = = - 1 )
2014-06-17 15:18:30 +00:00
{
MWWorld : : Ptr player = MWBase : : Environment : : get ( ) . getWorld ( ) - > getPlayerPtr ( ) ;
if ( player . getClass ( ) . getNpcStats ( player ) . isWerewolf ( ) )
{
// Cannot use items or spells while in werewolf form
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > messageBox ( " #{sWerewolfRefusal} " ) ;
return ;
}
2013-08-27 13:48:13 +00:00
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > pushGuiMode ( MWGui : : GM_QuickKeysMenu ) ;
2014-06-17 15:18:30 +00:00
}
2014-05-29 10:19:25 +00:00
else if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getMode ( ) = = MWGui : : GM_QuickKeysMenu ) {
while ( MyGUI : : InputManager : : getInstance ( ) . isModalAny ( ) ) { //Handle any open Modal windows
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > getCurrentModal ( ) - > exit ( ) ;
}
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > exitCurrentGuiMode ( ) ; //And handle the actual main window
}
2012-08-26 08:52:06 +00:00
}
2012-08-12 18:45:02 +00:00
void InputManager : : activate ( )
{
2013-02-17 02:03:41 +00:00
if ( mControlSwitch [ " playercontrols " ] )
mEngine . activate ( ) ;
2012-08-12 18:45:02 +00:00
}
void InputManager : : toggleAutoMove ( )
{
2013-08-27 13:48:13 +00:00
if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) ) return ;
2012-11-27 17:39:12 +00:00
if ( mControlSwitch [ " playercontrols " ] )
2013-08-27 13:48:13 +00:00
mPlayer - > setAutoMove ( ! mPlayer - > getAutoMove ( ) ) ;
2012-08-12 18:45:02 +00:00
}
void InputManager : : toggleWalking ( )
{
2013-08-27 13:48:13 +00:00
if ( MWBase : : Environment : : get ( ) . getWindowManager ( ) - > isGuiMode ( ) ) return ;
2013-03-14 20:08:19 +00:00
mAlwaysRunActive = ! mAlwaysRunActive ;
2014-06-08 17:50:39 +00:00
Settings : : Manager : : setBool ( " always run " , " Input " , mAlwaysRunActive ) ;
2012-08-12 18:45:02 +00:00
}
2012-08-17 21:31:57 +00:00
void InputManager : : resetIdleTime ( )
{
2013-04-27 08:24:36 +00:00
if ( mTimeIdle < 0 )
MWBase : : Environment : : get ( ) . getWorld ( ) - > toggleVanityMode ( false ) ;
2012-08-17 21:31:57 +00:00
mTimeIdle = 0.f ;
}
void InputManager : : updateIdleTime ( float dt )
{
2014-01-01 23:13:23 +00:00
static const float vanityDelay = MWBase : : Environment : : get ( ) . getWorld ( ) - > getStore ( ) . get < ESM : : GameSetting > ( )
. find ( " fVanityDelay " ) - > getFloat ( ) ;
2013-04-27 08:24:36 +00:00
if ( mTimeIdle > = 0.f )
2012-08-17 21:31:57 +00:00
mTimeIdle + = dt ;
2014-01-01 23:13:23 +00:00
if ( mTimeIdle > vanityDelay ) {
2013-04-27 08:24:36 +00:00
MWBase : : Environment : : get ( ) . getWorld ( ) - > toggleVanityMode ( true ) ;
2012-08-17 21:31:57 +00:00
mTimeIdle = - 1.f ;
}
}
2012-08-12 18:45:02 +00:00
bool InputManager : : actionIsActive ( int id )
{
2013-01-10 21:21:47 +00:00
return mInputBinder - > getChannel ( id ) - > getValue ( ) = = 1 ;
2012-08-12 18:45:02 +00:00
}
2012-08-13 00:55:22 +00:00
void InputManager : : loadKeyDefaults ( bool force )
2012-08-12 20:59:58 +00:00
{
// using hardcoded key defaults is inevitable, if we want the configuration files to stay valid
// across different versions of OpenMW (in the case where another input action is added)
2014-09-13 18:39:32 +00:00
std : : map < int , SDL_Scancode > defaultKeyBindings ;
2012-08-12 20:59:58 +00:00
2014-04-20 04:34:58 +00:00
//Gets the Keyvalue from the Scancode; gives the button in the same place reguardless of keyboard format
2014-09-13 18:39:32 +00:00
defaultKeyBindings [ A_Activate ] = SDL_SCANCODE_SPACE ;
defaultKeyBindings [ A_MoveBackward ] = SDL_SCANCODE_S ;
defaultKeyBindings [ A_MoveForward ] = SDL_SCANCODE_W ;
defaultKeyBindings [ A_MoveLeft ] = SDL_SCANCODE_A ;
defaultKeyBindings [ A_MoveRight ] = SDL_SCANCODE_D ;
defaultKeyBindings [ A_ToggleWeapon ] = SDL_SCANCODE_F ;
defaultKeyBindings [ A_ToggleSpell ] = SDL_SCANCODE_R ;
2014-12-15 14:23:03 +00:00
defaultKeyBindings [ A_CycleSpellLeft ] = SDL_SCANCODE_MINUS ;
defaultKeyBindings [ A_CycleSpellRight ] = SDL_SCANCODE_EQUALS ;
defaultKeyBindings [ A_CycleWeaponLeft ] = SDL_SCANCODE_LEFTBRACKET ;
defaultKeyBindings [ A_CycleWeaponRight ] = SDL_SCANCODE_RIGHTBRACKET ;
2014-09-13 18:39:32 +00:00
defaultKeyBindings [ A_QuickKeysMenu ] = SDL_SCANCODE_F1 ;
defaultKeyBindings [ A_Console ] = SDL_SCANCODE_GRAVE ;
defaultKeyBindings [ A_Run ] = SDL_SCANCODE_LSHIFT ;
defaultKeyBindings [ A_Sneak ] = SDL_SCANCODE_LCTRL ;
defaultKeyBindings [ A_AutoMove ] = SDL_SCANCODE_Q ;
defaultKeyBindings [ A_Jump ] = SDL_SCANCODE_E ;
defaultKeyBindings [ A_Journal ] = SDL_SCANCODE_J ;
defaultKeyBindings [ A_Rest ] = SDL_SCANCODE_T ;
defaultKeyBindings [ A_GameMenu ] = SDL_SCANCODE_ESCAPE ;
defaultKeyBindings [ A_TogglePOV ] = SDL_SCANCODE_TAB ;
defaultKeyBindings [ A_QuickKey1 ] = SDL_SCANCODE_1 ;
defaultKeyBindings [ A_QuickKey2 ] = SDL_SCANCODE_2 ;
defaultKeyBindings [ A_QuickKey3 ] = SDL_SCANCODE_3 ;
defaultKeyBindings [ A_QuickKey4 ] = SDL_SCANCODE_4 ;
defaultKeyBindings [ A_QuickKey5 ] = SDL_SCANCODE_5 ;
defaultKeyBindings [ A_QuickKey6 ] = SDL_SCANCODE_6 ;
defaultKeyBindings [ A_QuickKey7 ] = SDL_SCANCODE_7 ;
defaultKeyBindings [ A_QuickKey8 ] = SDL_SCANCODE_8 ;
defaultKeyBindings [ A_QuickKey9 ] = SDL_SCANCODE_9 ;
defaultKeyBindings [ A_QuickKey10 ] = SDL_SCANCODE_0 ;
defaultKeyBindings [ A_Screenshot ] = SDL_SCANCODE_F12 ;
defaultKeyBindings [ A_ToggleHUD ] = SDL_SCANCODE_F11 ;
2014-09-28 15:57:14 +00:00
defaultKeyBindings [ A_ToggleDebug ] = SDL_SCANCODE_F10 ;
2014-09-13 18:39:32 +00:00
defaultKeyBindings [ A_AlwaysRun ] = SDL_SCANCODE_CAPSLOCK ;
defaultKeyBindings [ A_QuickSave ] = SDL_SCANCODE_F5 ;
defaultKeyBindings [ A_QuickLoad ] = SDL_SCANCODE_F9 ;
2012-08-12 20:59:58 +00:00
std : : map < int , int > defaultMouseButtonBindings ;
2013-01-08 10:19:05 +00:00
defaultMouseButtonBindings [ A_Inventory ] = SDL_BUTTON_RIGHT ;
defaultMouseButtonBindings [ A_Use ] = SDL_BUTTON_LEFT ;
2012-08-12 20:59:58 +00:00
2012-08-12 23:26:15 +00:00
for ( int i = 0 ; i < A_Last ; + + i )
2012-08-12 20:59:58 +00:00
{
2012-08-13 00:55:22 +00:00
ICS : : Control * control ;
2013-01-10 21:21:47 +00:00
bool controlExists = mInputBinder - > getChannel ( i ) - > getControlsCount ( ) ! = 0 ;
2012-08-13 00:55:22 +00:00
if ( ! controlExists )
{
control = new ICS : : Control ( boost : : lexical_cast < std : : string > ( i ) , false , true , 0 , ICS : : ICS_MAX , ICS : : ICS_MAX ) ;
2013-01-10 21:21:47 +00:00
mInputBinder - > addControl ( control ) ;
control - > attachChannel ( mInputBinder - > getChannel ( i ) , ICS : : Channel : : DIRECT ) ;
2012-08-13 00:55:22 +00:00
}
else
{
2013-01-10 21:21:47 +00:00
control = mInputBinder - > getChannel ( i ) - > getAttachedControls ( ) . front ( ) . control ;
2012-08-13 00:55:22 +00:00
}
2012-08-27 13:51:01 +00:00
if ( ! controlExists | | force | |
2014-09-13 18:39:32 +00:00
( mInputBinder - > getKeyBinding ( control , ICS : : Control : : INCREASE ) = = SDL_SCANCODE_UNKNOWN
2013-01-10 21:21:47 +00:00
& & mInputBinder - > getMouseButtonBinding ( control , ICS : : Control : : INCREASE ) = = ICS_MAX_DEVICE_BUTTONS
2012-08-27 13:51:01 +00:00
) )
2012-08-12 20:59:58 +00:00
{
2012-08-13 00:55:22 +00:00
clearAllBindings ( control ) ;
2012-08-12 20:59:58 +00:00
2014-10-01 15:54:18 +00:00
if ( defaultKeyBindings . find ( i ) ! = defaultKeyBindings . end ( )
& & ! mInputBinder - > isKeyBound ( defaultKeyBindings [ i ] ) )
2014-09-13 18:39:32 +00:00
mInputBinder - > addKeyBinding ( control , defaultKeyBindings [ i ] , ICS : : Control : : INCREASE ) ;
2014-10-01 15:54:18 +00:00
else if ( defaultMouseButtonBindings . find ( i ) ! = defaultMouseButtonBindings . end ( )
& & ! mInputBinder - > isMouseButtonBound ( defaultMouseButtonBindings [ i ] ) )
2013-01-10 21:21:47 +00:00
mInputBinder - > addMouseButtonBinding ( control , defaultMouseButtonBindings [ i ] , ICS : : Control : : INCREASE ) ;
2012-08-12 20:59:58 +00:00
}
}
}
2012-08-12 23:26:15 +00:00
std : : string InputManager : : getActionDescription ( int action )
{
std : : map < int , std : : string > descriptions ;
2013-07-31 18:24:44 +00:00
if ( action = = A_Screenshot )
return " Screenshot " ;
2013-05-19 16:40:37 +00:00
descriptions [ A_Use ] = " sUse " ;
2012-08-12 23:26:15 +00:00
descriptions [ A_Activate ] = " sActivate " ;
descriptions [ A_MoveBackward ] = " sBack " ;
descriptions [ A_MoveForward ] = " sForward " ;
descriptions [ A_MoveLeft ] = " sLeft " ;
descriptions [ A_MoveRight ] = " sRight " ;
descriptions [ A_ToggleWeapon ] = " sReady_Weapon " ;
descriptions [ A_ToggleSpell ] = " sReady_Magic " ;
2014-12-15 14:23:03 +00:00
descriptions [ A_CycleSpellLeft ] = " sPrevSpell " ;
descriptions [ A_CycleSpellRight ] = " sNextSpell " ;
descriptions [ A_CycleWeaponLeft ] = " sPrevWeapon " ;
descriptions [ A_CycleWeaponRight ] = " sNextWeapon " ;
2012-08-12 23:26:15 +00:00
descriptions [ A_Console ] = " sConsoleTitle " ;
2013-02-07 01:51:47 +00:00
descriptions [ A_Run ] = " sRun " ;
2013-03-06 15:58:56 +00:00
descriptions [ A_Sneak ] = " sCrouch_Sneak " ;
2012-08-12 23:26:15 +00:00
descriptions [ A_AutoMove ] = " sAuto_Run " ;
descriptions [ A_Jump ] = " sJump " ;
descriptions [ A_Journal ] = " sJournal " ;
descriptions [ A_Rest ] = " sRestKey " ;
descriptions [ A_Inventory ] = " sInventory " ;
2012-08-19 20:09:22 +00:00
descriptions [ A_TogglePOV ] = " sTogglePOVCmd " ;
2012-08-26 08:52:06 +00:00
descriptions [ A_QuickKeysMenu ] = " sQuickMenu " ;
descriptions [ A_QuickKey1 ] = " sQuick1Cmd " ;
descriptions [ A_QuickKey2 ] = " sQuick2Cmd " ;
descriptions [ A_QuickKey3 ] = " sQuick3Cmd " ;
descriptions [ A_QuickKey4 ] = " sQuick4Cmd " ;
descriptions [ A_QuickKey5 ] = " sQuick5Cmd " ;
descriptions [ A_QuickKey6 ] = " sQuick6Cmd " ;
descriptions [ A_QuickKey7 ] = " sQuick7Cmd " ;
descriptions [ A_QuickKey8 ] = " sQuick8Cmd " ;
descriptions [ A_QuickKey9 ] = " sQuick9Cmd " ;
descriptions [ A_QuickKey10 ] = " sQuick10Cmd " ;
2013-03-14 19:27:16 +00:00
descriptions [ A_AlwaysRun ] = " sAlways_Run " ;
2014-04-24 01:02:09 +00:00
descriptions [ A_QuickSave ] = " sQuickSaveCmd " ;
descriptions [ A_QuickLoad ] = " sQuickLoadCmd " ;
2012-08-12 23:26:15 +00:00
if ( descriptions [ action ] = = " " )
return " " ; // not configurable
return " #{ " + descriptions [ action ] + " } " ;
}
std : : string InputManager : : getActionBindingName ( int action )
{
2013-01-10 21:21:47 +00:00
if ( mInputBinder - > getChannel ( action ) - > getControlsCount ( ) = = 0 )
2012-08-12 23:26:15 +00:00
return " #{sNone} " ;
2013-01-10 21:21:47 +00:00
ICS : : Control * c = mInputBinder - > getChannel ( action ) - > getAttachedControls ( ) . front ( ) . control ;
2012-08-12 23:26:15 +00:00
2014-09-13 18:39:32 +00:00
if ( mInputBinder - > getKeyBinding ( c , ICS : : Control : : INCREASE ) ! = SDL_SCANCODE_UNKNOWN )
return mInputBinder - > scancodeToString ( mInputBinder - > getKeyBinding ( c , ICS : : Control : : INCREASE ) ) ;
2013-01-10 21:21:47 +00:00
else if ( mInputBinder - > getMouseButtonBinding ( c , ICS : : Control : : INCREASE ) ! = ICS_MAX_DEVICE_BUTTONS )
return " #{sMouse} " + boost : : lexical_cast < std : : string > ( mInputBinder - > getMouseButtonBinding ( c , ICS : : Control : : INCREASE ) ) ;
2012-08-12 23:26:15 +00:00
else
return " #{sNone} " ;
}
std : : vector < int > InputManager : : getActionSorting ( )
{
std : : vector < int > ret ;
ret . push_back ( A_MoveForward ) ;
ret . push_back ( A_MoveBackward ) ;
ret . push_back ( A_MoveLeft ) ;
ret . push_back ( A_MoveRight ) ;
2012-08-19 20:09:22 +00:00
ret . push_back ( A_TogglePOV ) ;
2013-02-07 01:51:47 +00:00
ret . push_back ( A_Run ) ;
2013-03-14 19:27:16 +00:00
ret . push_back ( A_AlwaysRun ) ;
2013-03-06 15:58:56 +00:00
ret . push_back ( A_Sneak ) ;
2012-08-12 23:26:15 +00:00
ret . push_back ( A_Activate ) ;
2013-05-19 16:40:37 +00:00
ret . push_back ( A_Use ) ;
2012-08-12 23:26:15 +00:00
ret . push_back ( A_ToggleWeapon ) ;
2012-08-13 00:55:22 +00:00
ret . push_back ( A_ToggleSpell ) ;
2014-12-15 14:23:03 +00:00
ret . push_back ( A_CycleSpellLeft ) ;
ret . push_back ( A_CycleSpellRight ) ;
ret . push_back ( A_CycleWeaponLeft ) ;
ret . push_back ( A_CycleWeaponRight ) ;
2012-08-12 23:26:15 +00:00
ret . push_back ( A_AutoMove ) ;
ret . push_back ( A_Jump ) ;
ret . push_back ( A_Inventory ) ;
ret . push_back ( A_Journal ) ;
ret . push_back ( A_Rest ) ;
ret . push_back ( A_Console ) ;
2014-04-24 01:02:09 +00:00
ret . push_back ( A_QuickSave ) ;
ret . push_back ( A_QuickLoad ) ;
2013-07-31 18:24:44 +00:00
ret . push_back ( A_Screenshot ) ;
2012-08-26 08:52:06 +00:00
ret . push_back ( A_QuickKeysMenu ) ;
ret . push_back ( A_QuickKey1 ) ;
ret . push_back ( A_QuickKey2 ) ;
ret . push_back ( A_QuickKey3 ) ;
ret . push_back ( A_QuickKey4 ) ;
ret . push_back ( A_QuickKey5 ) ;
ret . push_back ( A_QuickKey6 ) ;
ret . push_back ( A_QuickKey7 ) ;
ret . push_back ( A_QuickKey8 ) ;
ret . push_back ( A_QuickKey9 ) ;
ret . push_back ( A_QuickKey10 ) ;
2012-08-12 23:26:15 +00:00
return ret ;
}
void InputManager : : enableDetectingBindingMode ( int action )
{
2013-01-10 21:21:47 +00:00
ICS : : Control * c = mInputBinder - > getChannel ( action ) - > getAttachedControls ( ) . front ( ) . control ;
2012-08-12 23:26:15 +00:00
2013-01-10 21:21:47 +00:00
mInputBinder - > enableDetectingBindingState ( c , ICS : : Control : : INCREASE ) ;
2012-08-12 23:26:15 +00:00
}
void InputManager : : mouseAxisBindingDetected ( ICS : : InputControlSystem * ICS , ICS : : Control * control
, ICS : : InputControlSystem : : NamedAxis axis , ICS : : Control : : ControlChangingDirection direction )
{
// we don't want mouse movement bindings
return ;
}
void InputManager : : keyBindingDetected ( ICS : : InputControlSystem * ICS , ICS : : Control * control
2014-09-13 18:39:32 +00:00
, SDL_Scancode key , ICS : : Control : : ControlChangingDirection direction )
2012-08-12 23:26:15 +00:00
{
2013-06-15 11:22:29 +00:00
//Disallow binding escape key
2014-09-13 18:39:32 +00:00
if ( key = = SDL_SCANCODE_ESCAPE )
2013-06-15 11:22:29 +00:00
return ;
2013-05-03 10:44:27 +00:00
2012-08-12 23:26:15 +00:00
clearAllBindings ( control ) ;
ICS : : DetectingBindingListener : : keyBindingDetected ( ICS , control , key , direction ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > notifyInputActionBound ( ) ;
}
void InputManager : : mouseButtonBindingDetected ( ICS : : InputControlSystem * ICS , ICS : : Control * control
, unsigned int button , ICS : : Control : : ControlChangingDirection direction )
{
clearAllBindings ( control ) ;
ICS : : DetectingBindingListener : : mouseButtonBindingDetected ( ICS , control , button , direction ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > notifyInputActionBound ( ) ;
}
void InputManager : : joystickAxisBindingDetected ( ICS : : InputControlSystem * ICS , ICS : : Control * control
, int deviceId , int axis , ICS : : Control : : ControlChangingDirection direction )
{
clearAllBindings ( control ) ;
ICS : : DetectingBindingListener : : joystickAxisBindingDetected ( ICS , control , deviceId , axis , direction ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > notifyInputActionBound ( ) ;
}
void InputManager : : joystickButtonBindingDetected ( ICS : : InputControlSystem * ICS , ICS : : Control * control
, int deviceId , unsigned int button , ICS : : Control : : ControlChangingDirection direction )
{
clearAllBindings ( control ) ;
ICS : : DetectingBindingListener : : joystickButtonBindingDetected ( ICS , control , deviceId , button , direction ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > notifyInputActionBound ( ) ;
}
void InputManager : : joystickPOVBindingDetected ( ICS : : InputControlSystem * ICS , ICS : : Control * control
, int deviceId , int pov , ICS : : InputControlSystem : : POVAxis axis , ICS : : Control : : ControlChangingDirection direction )
{
clearAllBindings ( control ) ;
ICS : : DetectingBindingListener : : joystickPOVBindingDetected ( ICS , control , deviceId , pov , axis , direction ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > notifyInputActionBound ( ) ;
}
void InputManager : : joystickSliderBindingDetected ( ICS : : InputControlSystem * ICS , ICS : : Control * control
, int deviceId , int slider , ICS : : Control : : ControlChangingDirection direction )
{
clearAllBindings ( control ) ;
ICS : : DetectingBindingListener : : joystickSliderBindingDetected ( ICS , control , deviceId , slider , direction ) ;
MWBase : : Environment : : get ( ) . getWindowManager ( ) - > notifyInputActionBound ( ) ;
}
void InputManager : : clearAllBindings ( ICS : : Control * control )
{
// right now we don't really need multiple bindings for the same action, so remove all others first
2014-09-13 18:39:32 +00:00
if ( mInputBinder - > getKeyBinding ( control , ICS : : Control : : INCREASE ) ! = SDL_SCANCODE_UNKNOWN )
2013-01-10 21:21:47 +00:00
mInputBinder - > removeKeyBinding ( mInputBinder - > getKeyBinding ( control , ICS : : Control : : INCREASE ) ) ;
if ( mInputBinder - > getMouseButtonBinding ( control , ICS : : Control : : INCREASE ) ! = ICS_MAX_DEVICE_BUTTONS )
mInputBinder - > removeMouseButtonBinding ( mInputBinder - > getMouseButtonBinding ( control , ICS : : Control : : INCREASE ) ) ;
2012-08-12 23:26:15 +00:00
/// \todo add joysticks here once they are added
}
2012-08-13 00:55:22 +00:00
void InputManager : : resetToDefaultBindings ( )
{
loadKeyDefaults ( true ) ;
}
2013-01-09 02:14:30 +00:00
MyGUI : : MouseButton InputManager : : sdlButtonToMyGUI ( Uint8 button )
{
//The right button is the second button, according to MyGUI
if ( button = = SDL_BUTTON_RIGHT )
button = SDL_BUTTON_MIDDLE ;
else if ( button = = SDL_BUTTON_MIDDLE )
button = SDL_BUTTON_RIGHT ;
//MyGUI's buttons are 0 indexed
return MyGUI : : MouseButton : : Enum ( button - 1 ) ;
}
2010-07-17 17:58:15 +00:00
}