|
|
|
@ -118,6 +118,7 @@ namespace MWInput
|
|
|
|
|
, mTimeIdle(0.f)
|
|
|
|
|
, mOverencumberedMessageDelay(0.f)
|
|
|
|
|
, mAlwaysRunActive(false)
|
|
|
|
|
, mAttemptJump(false)
|
|
|
|
|
, mControlsDisabled(false)
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
@ -165,6 +166,21 @@ namespace MWInput
|
|
|
|
|
delete mInputManager;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputManager::setPlayerControlsEnabled(bool enabled)
|
|
|
|
|
{
|
|
|
|
|
int nPlayerChannels = 17;
|
|
|
|
|
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,
|
|
|
|
|
A_QuickKey7, A_QuickKey8, A_QuickKey9, A_QuickKey10,
|
|
|
|
|
A_Use};
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < nPlayerChannels; i++) {
|
|
|
|
|
int pc = playerChannels[i];
|
|
|
|
|
mInputBinder->getChannel(pc)->setEnabled(enabled);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputManager::channelChanged(ICS::Channel* channel, float currentValue, float previousValue)
|
|
|
|
|
{
|
|
|
|
|
if (mDragDrop)
|
|
|
|
@ -179,6 +195,11 @@ namespace MWInput
|
|
|
|
|
mPlayer->getPlayer().getClass().getCreatureStats(mPlayer->getPlayer()).setAttackingOrSpell(currentValue);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (action == A_Jump)
|
|
|
|
|
{
|
|
|
|
|
mAttemptJump = (currentValue == 1.0 && previousValue == 0.0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (currentValue == 1)
|
|
|
|
|
{
|
|
|
|
|
// trigger action activated
|
|
|
|
@ -305,107 +326,107 @@ namespace MWInput
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Disable movement in Gui mode
|
|
|
|
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode()
|
|
|
|
|
|| MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_Running)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Configure player movement according to keyboard input. Actual movement will
|
|
|
|
|
// be done in the physics system.
|
|
|
|
|
if (mControlSwitch["playercontrols"])
|
|
|
|
|
if (!(MWBase::Environment::get().getWindowManager()->isGuiMode()
|
|
|
|
|
|| MWBase::Environment::get().getStateManager()->getState() != MWBase::StateManager::State_Running))
|
|
|
|
|
{
|
|
|
|
|
bool triedToMove = false;
|
|
|
|
|
if (actionIsActive(A_MoveLeft))
|
|
|
|
|
{
|
|
|
|
|
triedToMove = true;
|
|
|
|
|
mPlayer->setLeftRight (-1);
|
|
|
|
|
}
|
|
|
|
|
else if (actionIsActive(A_MoveRight))
|
|
|
|
|
// Configure player movement according to keyboard input. Actual movement will
|
|
|
|
|
// be done in the physics system.
|
|
|
|
|
if (mControlSwitch["playercontrols"])
|
|
|
|
|
{
|
|
|
|
|
triedToMove = true;
|
|
|
|
|
mPlayer->setLeftRight (1);
|
|
|
|
|
}
|
|
|
|
|
bool triedToMove = false;
|
|
|
|
|
if (actionIsActive(A_MoveLeft))
|
|
|
|
|
{
|
|
|
|
|
triedToMove = true;
|
|
|
|
|
mPlayer->setLeftRight (-1);
|
|
|
|
|
}
|
|
|
|
|
else if (actionIsActive(A_MoveRight))
|
|
|
|
|
{
|
|
|
|
|
triedToMove = true;
|
|
|
|
|
mPlayer->setLeftRight (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
else if(mPlayer->getAutoMove())
|
|
|
|
|
{
|
|
|
|
|
triedToMove = true;
|
|
|
|
|
mPlayer->setForwardBackward (1);
|
|
|
|
|
}
|
|
|
|
|
else if(mPlayer->getAutoMove())
|
|
|
|
|
{
|
|
|
|
|
triedToMove = true;
|
|
|
|
|
mPlayer->setForwardBackward (1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
mPlayer->setSneak(actionIsActive(A_Sneak));
|
|
|
|
|
mPlayer->setSneak(actionIsActive(A_Sneak));
|
|
|
|
|
|
|
|
|
|
if (actionIsActive(A_Jump) && mControlSwitch["playerjumping"])
|
|
|
|
|
{
|
|
|
|
|
mPlayer->setUpDown (1);
|
|
|
|
|
triedToMove = true;
|
|
|
|
|
}
|
|
|
|
|
if (mAttemptJump && mControlSwitch["playerjumping"])
|
|
|
|
|
{
|
|
|
|
|
mPlayer->setUpDown (1);
|
|
|
|
|
triedToMove = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mAlwaysRunActive)
|
|
|
|
|
mPlayer->setRunState(!actionIsActive(A_Run));
|
|
|
|
|
else
|
|
|
|
|
mPlayer->setRunState(actionIsActive(A_Run));
|
|
|
|
|
if (mAlwaysRunActive)
|
|
|
|
|
mPlayer->setRunState(!actionIsActive(A_Run));
|
|
|
|
|
else
|
|
|
|
|
mPlayer->setRunState(actionIsActive(A_Run));
|
|
|
|
|
|
|
|
|
|
// if player tried to start moving, but can't (due to being overencumbered), display a notification.
|
|
|
|
|
if (triedToMove)
|
|
|
|
|
{
|
|
|
|
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
|
|
|
|
|
mOverencumberedMessageDelay -= dt;
|
|
|
|
|
if (player.getClass().getEncumbrance(player) >= player.getClass().getCapacity(player))
|
|
|
|
|
// if player tried to start moving, but can't (due to being overencumbered), display a notification.
|
|
|
|
|
if (triedToMove)
|
|
|
|
|
{
|
|
|
|
|
mPlayer->setAutoMove (false);
|
|
|
|
|
if (mOverencumberedMessageDelay <= 0)
|
|
|
|
|
MWWorld::Ptr player = MWBase::Environment::get().getWorld ()->getPlayerPtr();
|
|
|
|
|
mOverencumberedMessageDelay -= dt;
|
|
|
|
|
if (player.getClass().getEncumbrance(player) >= player.getClass().getCapacity(player))
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getWindowManager ()->messageBox("#{sNotifyMessage59}");
|
|
|
|
|
mOverencumberedMessageDelay = 1.0;
|
|
|
|
|
mPlayer->setAutoMove (false);
|
|
|
|
|
if (mOverencumberedMessageDelay <= 0)
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getWindowManager ()->messageBox("#{sNotifyMessage59}");
|
|
|
|
|
mOverencumberedMessageDelay = 1.0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (mControlSwitch["playerviewswitch"]) {
|
|
|
|
|
|
|
|
|
|
// work around preview mode toggle when pressing Alt+Tab
|
|
|
|
|
if (actionIsActive(A_TogglePOV) && !mInputManager->isModifierHeld(SDL_Keymod(KMOD_ALT))) {
|
|
|
|
|
if (mPreviewPOVDelay <= 0.5 &&
|
|
|
|
|
(mPreviewPOVDelay += dt) > 0.5)
|
|
|
|
|
{
|
|
|
|
|
mPreviewPOVDelay = 1.f;
|
|
|
|
|
MWBase::Environment::get().getWorld()->togglePreviewMode(true);
|
|
|
|
|
if (mControlSwitch["playerviewswitch"]) {
|
|
|
|
|
|
|
|
|
|
// work around preview mode toggle when pressing Alt+Tab
|
|
|
|
|
if (actionIsActive(A_TogglePOV) && !mInputManager->isModifierHeld(SDL_Keymod(KMOD_ALT))) {
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
} 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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
mAttemptJump = false; // Can only jump on first frame input is on
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputManager::setDragDrop(bool dragDrop)
|
|
|
|
@ -517,13 +538,15 @@ namespace MWInput
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!mControlsDisabled)
|
|
|
|
|
mInputBinder->keyPressed (arg);
|
|
|
|
|
|
|
|
|
|
OIS::KeyCode kc = mInputManager->sdl2OISKeyCode(arg.keysym.sym);
|
|
|
|
|
|
|
|
|
|
if (kc != OIS::KC_UNASSIGNED)
|
|
|
|
|
MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(kc), 0);
|
|
|
|
|
{
|
|
|
|
|
bool guiFocus = MyGUI::InputManager::getInstance().injectKeyPress(MyGUI::KeyCode::Enum(kc), 0);
|
|
|
|
|
setPlayerControlsEnabled(!guiFocus);
|
|
|
|
|
}
|
|
|
|
|
if (!mControlsDisabled)
|
|
|
|
|
mInputBinder->keyPressed (arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputManager::textInput(const SDL_TextInputEvent &arg)
|
|
|
|
@ -536,36 +559,51 @@ namespace MWInput
|
|
|
|
|
|
|
|
|
|
void InputManager::keyReleased(const SDL_KeyboardEvent &arg )
|
|
|
|
|
{
|
|
|
|
|
mInputBinder->keyReleased (arg);
|
|
|
|
|
|
|
|
|
|
OIS::KeyCode kc = mInputManager->sdl2OISKeyCode(arg.keysym.sym);
|
|
|
|
|
|
|
|
|
|
MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::Enum(kc));
|
|
|
|
|
setPlayerControlsEnabled(!MyGUI::InputManager::getInstance().injectKeyRelease(MyGUI::KeyCode::Enum(kc)));
|
|
|
|
|
mInputBinder->keyReleased (arg);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputManager::mousePressed( const SDL_MouseButtonEvent &arg, Uint8 id )
|
|
|
|
|
{
|
|
|
|
|
mInputBinder->mousePressed (arg, id);
|
|
|
|
|
|
|
|
|
|
if (id != SDL_BUTTON_LEFT && id != SDL_BUTTON_RIGHT)
|
|
|
|
|
return; // MyGUI has no use for these events
|
|
|
|
|
bool guiMode = false;
|
|
|
|
|
|
|
|
|
|
MyGUI::InputManager::getInstance().injectMousePress(mMouseX, mMouseY, sdlButtonToMyGUI(id));
|
|
|
|
|
if (MyGUI::InputManager::getInstance ().getMouseFocusWidget () != 0)
|
|
|
|
|
if (id == SDL_BUTTON_LEFT || id == SDL_BUTTON_RIGHT) // MyGUI only uses these mouse events
|
|
|
|
|
{
|
|
|
|
|
MyGUI::Button* b = MyGUI::InputManager::getInstance ().getMouseFocusWidget ()->castType<MyGUI::Button>(false);
|
|
|
|
|
if (b && b->getEnabled())
|
|
|
|
|
guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
|
|
|
|
guiMode = MyGUI::InputManager::getInstance().injectMousePress(mMouseX, mMouseY, sdlButtonToMyGUI(id)) && guiMode;
|
|
|
|
|
if (MyGUI::InputManager::getInstance ().getMouseFocusWidget () != 0)
|
|
|
|
|
{
|
|
|
|
|
MWBase::Environment::get().getSoundManager ()->playSound ("Menu Click", 1.f, 1.f);
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setPlayerControlsEnabled(!guiMode);
|
|
|
|
|
mInputBinder->mousePressed (arg, id);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputManager::mouseReleased( const SDL_MouseButtonEvent &arg, Uint8 id )
|
|
|
|
|
{
|
|
|
|
|
mInputBinder->mouseReleased (arg, id);
|
|
|
|
|
|
|
|
|
|
MyGUI::InputManager::getInstance().injectMouseRelease(mMouseX, mMouseY, sdlButtonToMyGUI(id));
|
|
|
|
|
if(mInputBinder->detectingBindingState())
|
|
|
|
|
{
|
|
|
|
|
mInputBinder->mouseReleased (arg, id);
|
|
|
|
|
} else {
|
|
|
|
|
bool guiMode = MWBase::Environment::get().getWindowManager()->isGuiMode();
|
|
|
|
|
guiMode = MyGUI::InputManager::getInstance().injectMouseRelease(mMouseX, mMouseY, sdlButtonToMyGUI(id)) && guiMode;
|
|
|
|
|
|
|
|
|
|
if(mInputBinder->detectingBindingState()) return; // don't allow same mouseup to bind as initiated bind
|
|
|
|
|
|
|
|
|
|
setPlayerControlsEnabled(!guiMode);
|
|
|
|
|
mInputBinder->mouseReleased (arg, id);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void InputManager::mouseMoved(const SFO::MouseMotionEvent &arg )
|
|
|
|
|