From d2b451eb7d7d9374f36c160e043776808205d2c0 Mon Sep 17 00:00:00 2001 From: greye Date: Fri, 17 Aug 2012 23:25:29 +0400 Subject: [PATCH] entering vanity mode --- apps/openmw/mwbase/inputmanager.hpp | 2 + apps/openmw/mwinput/inputmanagerimp.cpp | 59 +++++++++++++++++++++---- apps/openmw/mwinput/inputmanagerimp.hpp | 3 +- apps/openmw/mwinput/mouselookevent.cpp | 2 + 4 files changed, 57 insertions(+), 9 deletions(-) diff --git a/apps/openmw/mwbase/inputmanager.hpp b/apps/openmw/mwbase/inputmanager.hpp index fdbab9fac0..00d7c8125a 100644 --- a/apps/openmw/mwbase/inputmanager.hpp +++ b/apps/openmw/mwbase/inputmanager.hpp @@ -31,6 +31,8 @@ namespace MWBase virtual void setDragDrop(bool dragDrop) = 0; virtual void toggleControlSwitch (const std::string& sw, bool value) = 0; + + virtual void resetIdleTime() = 0; }; } diff --git a/apps/openmw/mwinput/inputmanagerimp.cpp b/apps/openmw/mwinput/inputmanagerimp.cpp index 0945842b2a..c78643f599 100644 --- a/apps/openmw/mwinput/inputmanagerimp.cpp +++ b/apps/openmw/mwinput/inputmanagerimp.cpp @@ -92,6 +92,7 @@ namespace MWInput std::map mControlSwitch; float mPreviewPOVDelay; + float mTimeIdle; /* InputImpl Methods */ public: @@ -99,11 +100,34 @@ public: { input.adjustMouseClippingSize(width, height); } + + void resetIdleTime() + { + if (mTimeIdle < 0) { + MWBase::Environment::get().getWorld()->toggleVanityMode(false, false); + } + mTimeIdle = 0.f; + } + private: + + void updateIdleTime(float dt) + { + if (mTimeIdle >= 0.f) { + mTimeIdle += dt; + } + if (mTimeIdle > 30.f) { + MWBase::Environment::get().getWorld()->toggleVanityMode(true, false); + mTimeIdle = -1.f; + } + } + void toggleSpell() { if (windows.isGuiMode()) return; + resetIdleTime(); + MWMechanics::DrawState_ state = player.getDrawState(); if (state == MWMechanics::DrawState_Weapon || state == MWMechanics::DrawState_Nothing) { @@ -121,6 +145,8 @@ private: { if (windows.isGuiMode()) return; + resetIdleTime(); + MWMechanics::DrawState_ state = player.getDrawState(); if (state == MWMechanics::DrawState_Spell || state == MWMechanics::DrawState_Nothing) { @@ -200,18 +226,26 @@ private: void activate() { + resetIdleTime(); + mEngine.activate(); } void toggleAutoMove() { if (windows.isGuiMode()) return; + + resetIdleTime(); + player.setAutoMove (!player.getAutoMove()); } void toggleWalking() { if (windows.isGuiMode()) return; + + resetIdleTime(); + player.toggleRunning(); } @@ -243,7 +277,8 @@ private: windows(_windows), mEngine (engine), mDragDrop(false), - mPreviewPOVDelay(0.f) + mPreviewPOVDelay(0.f), + mTimeIdle(0.f) { using namespace OEngine::Input; using namespace OEngine::Render; @@ -426,6 +461,19 @@ private: } } } + // Idle time update despite of control switches + if (poller.isDown(A_MoveLeft) || + poller.isDown(A_MoveRight) || + poller.isDown(A_MoveForward) || + poller.isDown(A_MoveBackward) || + poller.isDown(A_Jump) || + poller.isDown(A_Crouch) || + poller.isDown(A_TogglePOV)) + { + resetIdleTime(); + } else { + updateIdleTime(duration); + } } // Switch between gui modes. Besides controlling the Gui windows @@ -472,11 +520,6 @@ private: mControlSwitch[sw] = value; } - bool getControlSwitch(const std::string &sw) - { - return mControlSwitch[sw]; - } - void togglePOV() { MWBase::Environment::get().getWorld()->togglePOV(); @@ -536,8 +579,8 @@ private: impl->toggleControlSwitch(sw, value); } - bool MWInputManager::getControlSwitch(const std::string &sw) + void MWInputManager::resetIdleTime() { - return impl->getControlSwitch(sw); + impl->resetIdleTime(); } } diff --git a/apps/openmw/mwinput/inputmanagerimp.hpp b/apps/openmw/mwinput/inputmanagerimp.hpp index d4ca32d2ff..868565dbbc 100644 --- a/apps/openmw/mwinput/inputmanagerimp.hpp +++ b/apps/openmw/mwinput/inputmanagerimp.hpp @@ -61,7 +61,8 @@ namespace MWInput virtual void setDragDrop(bool dragDrop); void toggleControlSwitch(const std::string &sw, bool value); - bool getControlSwitch(const std::string &sw); + + void resetIdleTime(); }; } #endif diff --git a/apps/openmw/mwinput/mouselookevent.cpp b/apps/openmw/mwinput/mouselookevent.cpp index f318ce6660..e6852d9234 100644 --- a/apps/openmw/mwinput/mouselookevent.cpp +++ b/apps/openmw/mwinput/mouselookevent.cpp @@ -1,6 +1,7 @@ #include "mouselookevent.hpp" #include "../mwbase/environment.hpp" +#include "../mwbase/inputmanager.hpp" #include "../mwbase/world.hpp" #include "../mwworld/player.hpp" @@ -17,6 +18,7 @@ void MouseLookEvent::event(Type type, int index, const void *p) if (type != EV_MouseMove || mDisabled) { return; } + MWBase::Environment::get().getInputManager()->resetIdleTime(); MouseEvent *arg = (MouseEvent*)(p);