mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-03 23:39:40 +00:00
Move control switches to the separate file
This commit is contained in:
parent
f990150c49
commit
8512133bb1
5 changed files with 90 additions and 37 deletions
|
@ -25,7 +25,7 @@ add_openmw_dir (mwrender
|
|||
)
|
||||
|
||||
add_openmw_dir (mwinput
|
||||
actions actionmanager controllermanager inputmanagerimp mousemanager keyboardmanager sdlmappings sensormanager
|
||||
actions actionmanager controllermanager controlswitch inputmanagerimp mousemanager keyboardmanager sdlmappings sensormanager
|
||||
)
|
||||
|
||||
add_openmw_dir (mwgui
|
||||
|
|
58
apps/openmw/mwinput/controlswitch.cpp
Normal file
58
apps/openmw/mwinput/controlswitch.cpp
Normal file
|
@ -0,0 +1,58 @@
|
|||
#include "controlswitch.hpp"
|
||||
|
||||
#include "../mwbase/environment.hpp"
|
||||
#include "../mwbase/world.hpp"
|
||||
|
||||
#include "../mwworld/player.hpp"
|
||||
|
||||
namespace MWInput
|
||||
{
|
||||
ControlSwitch::ControlSwitch()
|
||||
{
|
||||
clear();
|
||||
}
|
||||
|
||||
void ControlSwitch::clear()
|
||||
{
|
||||
mSwitches["playercontrols"] = true;
|
||||
mSwitches["playerfighting"] = true;
|
||||
mSwitches["playerjumping"] = true;
|
||||
mSwitches["playerlooking"] = true;
|
||||
mSwitches["playermagic"] = true;
|
||||
mSwitches["playerviewswitch"] = true;
|
||||
mSwitches["vanitymode"] = true;
|
||||
}
|
||||
|
||||
bool ControlSwitch::get(const std::string& key)
|
||||
{
|
||||
return mSwitches[key];
|
||||
}
|
||||
|
||||
void ControlSwitch::set(const std::string& key, bool value)
|
||||
{
|
||||
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
|
||||
|
||||
/// \note 7 switches at all, if-else is relevant
|
||||
if (key == "playercontrols" && !value)
|
||||
{
|
||||
player.setLeftRight(0);
|
||||
player.setForwardBackward(0);
|
||||
player.setAutoMove(false);
|
||||
player.setUpDown(0);
|
||||
}
|
||||
else if (key == "playerjumping" && !value)
|
||||
{
|
||||
/// \fixme maybe crouching at this time
|
||||
player.setUpDown(0);
|
||||
}
|
||||
else if (key == "vanitymode")
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->allowVanityMode(value);
|
||||
}
|
||||
else if (key == "playerlooking" && !value)
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->rotateObject(player.getPlayer(), 0.f, 0.f, 0.f);
|
||||
}
|
||||
mSwitches[key] = value;
|
||||
}
|
||||
}
|
21
apps/openmw/mwinput/controlswitch.hpp
Normal file
21
apps/openmw/mwinput/controlswitch.hpp
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef MWINPUT_CONTROLSWITCH_H
|
||||
#define MWINPUT_CONTROLSWITCH_H
|
||||
|
||||
#include <map>
|
||||
|
||||
namespace MWInput
|
||||
{
|
||||
class ControlSwitch
|
||||
{
|
||||
public:
|
||||
ControlSwitch();
|
||||
|
||||
bool get(const std::string& key);
|
||||
void set(const std::string& key, bool value);
|
||||
void clear();
|
||||
|
||||
private:
|
||||
std::map<std::string, bool> mSwitches;
|
||||
};
|
||||
}
|
||||
#endif
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
#include "actionmanager.hpp"
|
||||
#include "controllermanager.hpp"
|
||||
#include "controlswitch.hpp"
|
||||
#include "keyboardmanager.hpp"
|
||||
#include "mousemanager.hpp"
|
||||
#include "sdlmappings.hpp"
|
||||
|
@ -66,13 +67,7 @@ namespace MWInput
|
|||
mInputBinder->getChannel (i)->addListener (this);
|
||||
}
|
||||
|
||||
mControlSwitch["playercontrols"] = true;
|
||||
mControlSwitch["playerfighting"] = true;
|
||||
mControlSwitch["playerjumping"] = true;
|
||||
mControlSwitch["playerlooking"] = true;
|
||||
mControlSwitch["playermagic"] = true;
|
||||
mControlSwitch["playerviewswitch"] = true;
|
||||
mControlSwitch["vanitymode"] = true;
|
||||
mControlSwitch = new ControlSwitch();
|
||||
|
||||
mActionManager = new ActionManager(mInputBinder, screenCaptureOperation, viewer, screenCaptureHandler);
|
||||
|
||||
|
@ -92,8 +87,7 @@ namespace MWInput
|
|||
void InputManager::clear()
|
||||
{
|
||||
// Enable all controls
|
||||
for (std::map<std::string, bool>::iterator it = mControlSwitch.begin(); it != mControlSwitch.end(); ++it)
|
||||
it->second = true;
|
||||
mControlSwitch->clear();
|
||||
|
||||
mActionManager->clear();
|
||||
mControllerManager->clear();
|
||||
|
@ -109,6 +103,8 @@ namespace MWInput
|
|||
delete mMouseManager;
|
||||
delete mSensorManager;
|
||||
|
||||
delete mControlSwitch;
|
||||
|
||||
mInputBinder->save(mUserFile);
|
||||
delete mInputBinder;
|
||||
|
||||
|
@ -159,7 +155,7 @@ namespace MWInput
|
|||
return;
|
||||
}
|
||||
|
||||
if (mControlSwitch["playercontrols"])
|
||||
if (mControlSwitch->get("playercontrols"))
|
||||
{
|
||||
bool joystickUsed = mControllerManager->joystickLastUsed();
|
||||
if (action == A_Use)
|
||||
|
@ -278,35 +274,12 @@ namespace MWInput
|
|||
|
||||
bool InputManager::getControlSwitch (const std::string& sw)
|
||||
{
|
||||
return mControlSwitch[sw];
|
||||
return mControlSwitch->get(sw);
|
||||
}
|
||||
|
||||
void InputManager::toggleControlSwitch (const std::string& sw, bool value)
|
||||
{
|
||||
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
|
||||
|
||||
/// \note 7 switches at all, if-else is relevant
|
||||
if (sw == "playercontrols" && !value)
|
||||
{
|
||||
player.setLeftRight(0);
|
||||
player.setForwardBackward(0);
|
||||
player.setAutoMove(false);
|
||||
player.setUpDown(0);
|
||||
}
|
||||
else if (sw == "playerjumping" && !value)
|
||||
{
|
||||
/// \fixme maybe crouching at this time
|
||||
player.setUpDown(0);
|
||||
}
|
||||
else if (sw == "vanitymode")
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->allowVanityMode(value);
|
||||
}
|
||||
else if (sw == "playerlooking" && !value)
|
||||
{
|
||||
MWBase::Environment::get().getWorld()->rotateObject(player.getPlayer(), 0.f, 0.f, 0.f);
|
||||
}
|
||||
mControlSwitch[sw] = value;
|
||||
mControlSwitch->set(sw, value);
|
||||
}
|
||||
|
||||
void InputManager::resetIdleTime()
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
|
||||
namespace MWInput
|
||||
{
|
||||
class ControlSwitch;
|
||||
class ActionManager;
|
||||
class ControllerManager;
|
||||
class KeyboardManager;
|
||||
|
@ -151,7 +152,7 @@ namespace MWInput
|
|||
|
||||
bool mDetectingKeyboard;
|
||||
|
||||
std::map<std::string, bool> mControlSwitch;
|
||||
ControlSwitch* mControlSwitch;
|
||||
|
||||
ActionManager* mActionManager;
|
||||
ControllerManager* mControllerManager;
|
||||
|
|
Loading…
Reference in a new issue