mirror of
https://github.com/OpenMW/openmw.git
synced 2025-03-04 05:09: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
|
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
|
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 "actionmanager.hpp"
|
||||||
#include "controllermanager.hpp"
|
#include "controllermanager.hpp"
|
||||||
|
#include "controlswitch.hpp"
|
||||||
#include "keyboardmanager.hpp"
|
#include "keyboardmanager.hpp"
|
||||||
#include "mousemanager.hpp"
|
#include "mousemanager.hpp"
|
||||||
#include "sdlmappings.hpp"
|
#include "sdlmappings.hpp"
|
||||||
|
@ -66,13 +67,7 @@ namespace MWInput
|
||||||
mInputBinder->getChannel (i)->addListener (this);
|
mInputBinder->getChannel (i)->addListener (this);
|
||||||
}
|
}
|
||||||
|
|
||||||
mControlSwitch["playercontrols"] = true;
|
mControlSwitch = new ControlSwitch();
|
||||||
mControlSwitch["playerfighting"] = true;
|
|
||||||
mControlSwitch["playerjumping"] = true;
|
|
||||||
mControlSwitch["playerlooking"] = true;
|
|
||||||
mControlSwitch["playermagic"] = true;
|
|
||||||
mControlSwitch["playerviewswitch"] = true;
|
|
||||||
mControlSwitch["vanitymode"] = true;
|
|
||||||
|
|
||||||
mActionManager = new ActionManager(mInputBinder, screenCaptureOperation, viewer, screenCaptureHandler);
|
mActionManager = new ActionManager(mInputBinder, screenCaptureOperation, viewer, screenCaptureHandler);
|
||||||
|
|
||||||
|
@ -92,8 +87,7 @@ namespace MWInput
|
||||||
void InputManager::clear()
|
void InputManager::clear()
|
||||||
{
|
{
|
||||||
// Enable all controls
|
// Enable all controls
|
||||||
for (std::map<std::string, bool>::iterator it = mControlSwitch.begin(); it != mControlSwitch.end(); ++it)
|
mControlSwitch->clear();
|
||||||
it->second = true;
|
|
||||||
|
|
||||||
mActionManager->clear();
|
mActionManager->clear();
|
||||||
mControllerManager->clear();
|
mControllerManager->clear();
|
||||||
|
@ -109,6 +103,8 @@ namespace MWInput
|
||||||
delete mMouseManager;
|
delete mMouseManager;
|
||||||
delete mSensorManager;
|
delete mSensorManager;
|
||||||
|
|
||||||
|
delete mControlSwitch;
|
||||||
|
|
||||||
mInputBinder->save(mUserFile);
|
mInputBinder->save(mUserFile);
|
||||||
delete mInputBinder;
|
delete mInputBinder;
|
||||||
|
|
||||||
|
@ -159,7 +155,7 @@ namespace MWInput
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mControlSwitch["playercontrols"])
|
if (mControlSwitch->get("playercontrols"))
|
||||||
{
|
{
|
||||||
bool joystickUsed = mControllerManager->joystickLastUsed();
|
bool joystickUsed = mControllerManager->joystickLastUsed();
|
||||||
if (action == A_Use)
|
if (action == A_Use)
|
||||||
|
@ -278,35 +274,12 @@ namespace MWInput
|
||||||
|
|
||||||
bool InputManager::getControlSwitch (const std::string& sw)
|
bool InputManager::getControlSwitch (const std::string& sw)
|
||||||
{
|
{
|
||||||
return mControlSwitch[sw];
|
return mControlSwitch->get(sw);
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::toggleControlSwitch (const std::string& sw, bool value)
|
void InputManager::toggleControlSwitch (const std::string& sw, bool value)
|
||||||
{
|
{
|
||||||
MWWorld::Player& player = MWBase::Environment::get().getWorld()->getPlayer();
|
mControlSwitch->set(sw, value);
|
||||||
|
|
||||||
/// \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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::resetIdleTime()
|
void InputManager::resetIdleTime()
|
||||||
|
|
|
@ -21,6 +21,7 @@
|
||||||
|
|
||||||
namespace MWInput
|
namespace MWInput
|
||||||
{
|
{
|
||||||
|
class ControlSwitch;
|
||||||
class ActionManager;
|
class ActionManager;
|
||||||
class ControllerManager;
|
class ControllerManager;
|
||||||
class KeyboardManager;
|
class KeyboardManager;
|
||||||
|
@ -151,7 +152,7 @@ namespace MWInput
|
||||||
|
|
||||||
bool mDetectingKeyboard;
|
bool mDetectingKeyboard;
|
||||||
|
|
||||||
std::map<std::string, bool> mControlSwitch;
|
ControlSwitch* mControlSwitch;
|
||||||
|
|
||||||
ActionManager* mActionManager;
|
ActionManager* mActionManager;
|
||||||
ControllerManager* mControllerManager;
|
ControllerManager* mControllerManager;
|
||||||
|
|
Loading…
Reference in a new issue