add support for some scripting player control switches

This commit is contained in:
greye 2012-08-04 11:54:42 +04:00
parent ff62770657
commit 16ad97610d
4 changed files with 67 additions and 29 deletions

View file

@ -90,6 +90,7 @@ namespace MWInput
bool mDragDrop;
std::map<std::string, bool> mControlSwitch;
/* InputImpl Methods */
public:
@ -339,6 +340,14 @@ private:
poller.bind(A_Jump, KC_E);
poller.bind(A_Crouch, KC_LCONTROL);
mControlSwitch["playercontrols"] = true;
mControlSwitch["playerfighting"] = true;
mControlSwitch["playerjumping"] = true;
mControlSwitch["playerlooking"] = true;
mControlSwitch["playermagic"] = true;
mControlSwitch["playerviewswitch"] = true;
mControlSwitch["vanitymode"] = true;
}
void setDragDrop(bool dragDrop)
@ -366,33 +375,35 @@ private:
// Configure player movement according to keyboard input. Actual movement will
// be done in the physics system.
if (poller.isDown(A_MoveLeft))
{
player.setAutoMove (false);
player.setLeftRight (1);
}
else if (poller.isDown(A_MoveRight))
{
player.setAutoMove (false);
player.setLeftRight (-1);
}
else
player.setLeftRight (0);
if (mControlSwitch["playercontrols"]) {
if (poller.isDown(A_MoveLeft))
{
player.setAutoMove (false);
player.setLeftRight (1);
}
else if (poller.isDown(A_MoveRight))
{
player.setAutoMove (false);
player.setLeftRight (-1);
}
else
player.setLeftRight (0);
if (poller.isDown(A_MoveForward))
{
player.setAutoMove (false);
player.setForwardBackward (1);
if (poller.isDown(A_MoveForward))
{
player.setAutoMove (false);
player.setForwardBackward (1);
}
else if (poller.isDown(A_MoveBackward))
{
player.setAutoMove (false);
player.setForwardBackward (-1);
}
else
player.setForwardBackward (0);
}
else if (poller.isDown(A_MoveBackward))
{
player.setAutoMove (false);
player.setForwardBackward (-1);
}
else
player.setForwardBackward (0);
if (poller.isDown(A_Jump))
if (poller.isDown(A_Jump) && mControlSwitch["playerjumping"])
player.setUpDown (1);
else if (poller.isDown(A_Crouch))
player.setUpDown (-1);
@ -423,6 +434,24 @@ private:
guiEvents->enabled = false;
}
}
void toggleControlSwitch(std::string sw, bool value)
{
if (mControlSwitch[sw] == value) {
return;
}
/// \note 7 switches at all, if-else is relevant
if (sw == "playercontrols") {
player.setLeftRight(0);
player.setForwardBackward(0);
player.setAutoMove(false);
} else if (sw == "playerjumping") {
/// \fixme maybe crouching at this time
player.setUpDown(0);
}
mControlSwitch[sw] = value;
}
};
/***CONSTRUCTOR***/
@ -471,4 +500,9 @@ private:
if (changeRes)
impl->adjustMouseRegion(Settings::Manager::getInt("resolution x", "Video"), Settings::Manager::getInt("resolution y", "Video"));
}
void MWInputManager::toggleControlSwitch(std::string sw, bool value)
{
impl->toggleControlSwitch(sw, value);
}
}

View file

@ -57,6 +57,8 @@ namespace MWInput
void processChangedSettings(const Settings::CategorySettingVector& changed);
void setDragDrop(bool dragDrop);
void toggleControlSwitch(std::string sw, bool value);
};
}
#endif

View file

@ -14,6 +14,8 @@
#include "../mwmechanics/npcstats.hpp"
#include "../mwinput/inputmanager.hpp"
#include "interpretercontext.hpp"
#include "ref.hpp"
@ -36,6 +38,10 @@ namespace MWScript
virtual void execute (Interpreter::Runtime& runtime)
{
MWBase::Environment::get()
.getInputManager()
->toggleControlSwitch(mControl, mEnable);
if (mEnable)
std::cout << "enable: " << mControl << std::endl;
else

View file

@ -18,8 +18,6 @@
#include "manualref.hpp"
#include "cellfunctors.hpp"
#include <iostream>
using namespace Ogre;
namespace
@ -1117,8 +1115,6 @@ namespace MWWorld
if (cell.data.flags & ESM::Cell::HasWater == 0) {
return false;
}
bool res = pos.z < cell.water;
std::cout << "World::isUnderwater(" << pos.z << "):" << res << std::endl;
return res;
return pos.z < cell.water;
}
}