mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-03 20:45:33 +00:00
Refactor: InputManager no longer depends on Engine
This commit is contained in:
parent
1402a16702
commit
05498ad592
6 changed files with 44 additions and 56 deletions
|
@ -483,8 +483,7 @@ void OMW::Engine::prepareEngine (Settings::Manager & settings)
|
||||||
else
|
else
|
||||||
gameControllerdb = ""; //if it doesn't exist, pass in an empty string
|
gameControllerdb = ""; //if it doesn't exist, pass in an empty string
|
||||||
|
|
||||||
// FIXME: shouldn't depend on Engine
|
MWInput::InputManager* input = new MWInput::InputManager (mWindow, mViewer, mScreenCaptureHandler, keybinderUser, keybinderUserExists, gameControllerdb, mGrab);
|
||||||
MWInput::InputManager* input = new MWInput::InputManager (mWindow, mViewer, *this, keybinderUser, keybinderUserExists, gameControllerdb, mGrab);
|
|
||||||
mEnvironment.setInputManager (input);
|
mEnvironment.setInputManager (input);
|
||||||
|
|
||||||
std::string myguiResources = (mResDir / "mygui").string();
|
std::string myguiResources = (mResDir / "mygui").string();
|
||||||
|
@ -717,41 +716,6 @@ void OMW::Engine::go()
|
||||||
std::cout << "Quitting peacefully." << std::endl;
|
std::cout << "Quitting peacefully." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
void OMW::Engine::activate()
|
|
||||||
{
|
|
||||||
if (mEnvironment.getWindowManager()->isGuiMode())
|
|
||||||
return;
|
|
||||||
|
|
||||||
MWWorld::Ptr player = mEnvironment.getWorld()->getPlayerPtr();
|
|
||||||
const MWMechanics::NpcStats &playerStats = player.getClass().getNpcStats(player);
|
|
||||||
if (playerStats.isParalyzed() || playerStats.getKnockedDown())
|
|
||||||
return;
|
|
||||||
|
|
||||||
MWWorld::Ptr ptr = mEnvironment.getWorld()->getFacedObject();
|
|
||||||
|
|
||||||
if (ptr.isEmpty())
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ptr.getClass().getName(ptr) == "") // objects without name presented to user can never be activated
|
|
||||||
return;
|
|
||||||
|
|
||||||
if (ptr.getClass().isActor())
|
|
||||||
{
|
|
||||||
MWMechanics::CreatureStats &stats = ptr.getClass().getCreatureStats(ptr);
|
|
||||||
|
|
||||||
if (stats.getAiSequence().isInCombat() && !stats.isDead())
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
mEnvironment.getWorld()->activate(ptr, mEnvironment.getWorld()->getPlayerPtr());
|
|
||||||
}
|
|
||||||
|
|
||||||
void OMW::Engine::screenshot()
|
|
||||||
{
|
|
||||||
mScreenCaptureHandler->setFramesToCapture(1);
|
|
||||||
mScreenCaptureHandler->captureNextFrame(*mViewer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void OMW::Engine::setCompileAll (bool all)
|
void OMW::Engine::setCompileAll (bool all)
|
||||||
{
|
{
|
||||||
mCompileAll = all;
|
mCompileAll = all;
|
||||||
|
|
|
@ -169,12 +169,6 @@ namespace OMW
|
||||||
/// Initialise and enter main loop.
|
/// Initialise and enter main loop.
|
||||||
void go();
|
void go();
|
||||||
|
|
||||||
/// Activate the focussed object.
|
|
||||||
void activate();
|
|
||||||
|
|
||||||
/// Write screenshot to file.
|
|
||||||
void screenshot();
|
|
||||||
|
|
||||||
/// Compile all scripts (excludign dialogue scripts) at startup?
|
/// Compile all scripts (excludign dialogue scripts) at startup?
|
||||||
void setCompileAll (bool all);
|
void setCompileAll (bool all);
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,8 @@
|
||||||
|
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
|
||||||
|
#include <osgViewer/ViewerEventHandlers>
|
||||||
|
|
||||||
#include <MyGUI_InputManager.h>
|
#include <MyGUI_InputManager.h>
|
||||||
#include <MyGUI_RenderManager.h>
|
#include <MyGUI_RenderManager.h>
|
||||||
#include <MyGUI_Widget.h>
|
#include <MyGUI_Widget.h>
|
||||||
|
@ -15,12 +17,11 @@
|
||||||
#include <components/sdlutil/sdlinputwrapper.hpp>
|
#include <components/sdlutil/sdlinputwrapper.hpp>
|
||||||
#include <components/sdlutil/sdlvideowrapper.hpp>
|
#include <components/sdlutil/sdlvideowrapper.hpp>
|
||||||
|
|
||||||
#include "../engine.hpp"
|
|
||||||
|
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
#include "../mwbase/windowmanager.hpp"
|
#include "../mwbase/windowmanager.hpp"
|
||||||
#include "../mwbase/soundmanager.hpp"
|
#include "../mwbase/soundmanager.hpp"
|
||||||
#include "../mwbase/statemanager.hpp"
|
#include "../mwbase/statemanager.hpp"
|
||||||
|
#include "../mwbase/environment.hpp"
|
||||||
|
|
||||||
#include "../mwworld/player.hpp"
|
#include "../mwworld/player.hpp"
|
||||||
#include "../mwworld/class.hpp"
|
#include "../mwworld/class.hpp"
|
||||||
|
@ -37,15 +38,15 @@ namespace MWInput
|
||||||
InputManager::InputManager(
|
InputManager::InputManager(
|
||||||
SDL_Window* window,
|
SDL_Window* window,
|
||||||
osg::ref_ptr<osgViewer::Viewer> viewer,
|
osg::ref_ptr<osgViewer::Viewer> viewer,
|
||||||
OMW::Engine& engine,
|
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler,
|
||||||
const std::string& userFile, bool userFileExists,
|
const std::string& userFile, bool userFileExists,
|
||||||
const std::string& controllerBindingsFile, bool grab)
|
const std::string& controllerBindingsFile, bool grab)
|
||||||
: mWindow(window)
|
: mWindow(window)
|
||||||
, mWindowVisible(true)
|
, mWindowVisible(true)
|
||||||
, mViewer(viewer)
|
, mViewer(viewer)
|
||||||
|
, mScreenCaptureHandler(screenCaptureHandler)
|
||||||
, mJoystickLastUsed(false)
|
, mJoystickLastUsed(false)
|
||||||
, mPlayer(NULL)
|
, mPlayer(NULL)
|
||||||
, mEngine(engine)
|
|
||||||
, mInputManager(NULL)
|
, mInputManager(NULL)
|
||||||
, mVideoWrapper(NULL)
|
, mVideoWrapper(NULL)
|
||||||
, mUserFile(userFile)
|
, mUserFile(userFile)
|
||||||
|
@ -952,7 +953,8 @@ namespace MWInput
|
||||||
|
|
||||||
void InputManager::screenshot()
|
void InputManager::screenshot()
|
||||||
{
|
{
|
||||||
mEngine.screenshot();
|
mScreenCaptureHandler->setFramesToCapture(1);
|
||||||
|
mScreenCaptureHandler->captureNextFrame(*mViewer);
|
||||||
|
|
||||||
MWBase::Environment::get().getWindowManager()->messageBox ("Screenshot saved");
|
MWBase::Environment::get().getWindowManager()->messageBox ("Screenshot saved");
|
||||||
}
|
}
|
||||||
|
@ -1058,7 +1060,7 @@ namespace MWInput
|
||||||
void InputManager::activate()
|
void InputManager::activate()
|
||||||
{
|
{
|
||||||
if (mControlSwitch["playercontrols"])
|
if (mControlSwitch["playercontrols"])
|
||||||
mEngine.activate();
|
mPlayer->activate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::toggleAutoMove()
|
void InputManager::toggleAutoMove()
|
||||||
|
|
|
@ -25,11 +25,6 @@ namespace MWBase
|
||||||
class WindowManager;
|
class WindowManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace OMW
|
|
||||||
{
|
|
||||||
class Engine;
|
|
||||||
}
|
|
||||||
|
|
||||||
namespace ICS
|
namespace ICS
|
||||||
{
|
{
|
||||||
class InputControlSystem;
|
class InputControlSystem;
|
||||||
|
@ -54,6 +49,7 @@ namespace SDLUtil
|
||||||
namespace osgViewer
|
namespace osgViewer
|
||||||
{
|
{
|
||||||
class Viewer;
|
class Viewer;
|
||||||
|
class ScreenCaptureHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct SDL_Window;
|
struct SDL_Window;
|
||||||
|
@ -77,7 +73,7 @@ namespace MWInput
|
||||||
InputManager(
|
InputManager(
|
||||||
SDL_Window* window,
|
SDL_Window* window,
|
||||||
osg::ref_ptr<osgViewer::Viewer> viewer,
|
osg::ref_ptr<osgViewer::Viewer> viewer,
|
||||||
OMW::Engine& engine,
|
osg::ref_ptr<osgViewer::ScreenCaptureHandler> screenCaptureHandler,
|
||||||
const std::string& userFile, bool userFileExists,
|
const std::string& userFile, bool userFileExists,
|
||||||
const std::string& controllerBindingsFile, bool grab);
|
const std::string& controllerBindingsFile, bool grab);
|
||||||
|
|
||||||
|
@ -157,10 +153,10 @@ namespace MWInput
|
||||||
SDL_Window* mWindow;
|
SDL_Window* mWindow;
|
||||||
bool mWindowVisible;
|
bool mWindowVisible;
|
||||||
osg::ref_ptr<osgViewer::Viewer> mViewer;
|
osg::ref_ptr<osgViewer::Viewer> mViewer;
|
||||||
|
osg::ref_ptr<osgViewer::ScreenCaptureHandler> mScreenCaptureHandler;
|
||||||
|
|
||||||
bool mJoystickLastUsed;
|
bool mJoystickLastUsed;
|
||||||
MWWorld::Player* mPlayer;
|
MWWorld::Player* mPlayer;
|
||||||
OMW::Engine& mEngine;
|
|
||||||
|
|
||||||
ICS::InputControlSystem* mInputBinder;
|
ICS::InputControlSystem* mInputBinder;
|
||||||
|
|
||||||
|
|
|
@ -205,6 +205,35 @@ namespace MWWorld
|
||||||
return ptr.getClass().getNpcStats(ptr).getDrawState();
|
return ptr.getClass().getNpcStats(ptr).getDrawState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Player::activate()
|
||||||
|
{
|
||||||
|
if (MWBase::Environment::get().getWindowManager()->isGuiMode())
|
||||||
|
return;
|
||||||
|
|
||||||
|
MWWorld::Ptr player = getPlayer();
|
||||||
|
const MWMechanics::NpcStats &playerStats = player.getClass().getNpcStats(player);
|
||||||
|
if (playerStats.isParalyzed() || playerStats.getKnockedDown())
|
||||||
|
return;
|
||||||
|
|
||||||
|
MWWorld::Ptr toActivate = MWBase::Environment::get().getWorld()->getFacedObject();
|
||||||
|
|
||||||
|
if (toActivate.isEmpty())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (toActivate.getClass().getName(toActivate) == "") // objects without name presented to user can never be activated
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (toActivate.getClass().isActor())
|
||||||
|
{
|
||||||
|
MWMechanics::CreatureStats &stats = toActivate.getClass().getCreatureStats(toActivate);
|
||||||
|
|
||||||
|
if (stats.getAiSequence().isInCombat() && !stats.isDead())
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
MWBase::Environment::get().getWorld()->activate(toActivate, player);
|
||||||
|
}
|
||||||
|
|
||||||
bool Player::wasTeleported() const
|
bool Player::wasTeleported() const
|
||||||
{
|
{
|
||||||
return mTeleported;
|
return mTeleported;
|
||||||
|
|
|
@ -82,6 +82,9 @@ namespace MWWorld
|
||||||
void setDrawState (MWMechanics::DrawState_ state);
|
void setDrawState (MWMechanics::DrawState_ state);
|
||||||
MWMechanics::DrawState_ getDrawState(); /// \todo constness
|
MWMechanics::DrawState_ getDrawState(); /// \todo constness
|
||||||
|
|
||||||
|
/// Activate the object under the crosshair, if any
|
||||||
|
void activate();
|
||||||
|
|
||||||
bool getAutoMove() const;
|
bool getAutoMove() const;
|
||||||
void setAutoMove (bool enable);
|
void setAutoMove (bool enable);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue