diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index bcb2d7f599..cc6e9470af 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -271,6 +271,7 @@ void OMW::Engine::go() // Sets up the input system MWInput::MWInputManager input(mOgre, mEnvironment.mWorld->getPlayerPos(), *mEnvironment.mWindowManager, mDebug, *this); + mEnvironment.mInputManager = &input; focusFrameCounter = 0; diff --git a/apps/openmw/mwgui/mode.hpp b/apps/openmw/mwgui/mode.hpp new file mode 100644 index 0000000000..b18dd9f959 --- /dev/null +++ b/apps/openmw/mwgui/mode.hpp @@ -0,0 +1,43 @@ +#ifndef MWGUI_MODE_H +#define MWGUI_MODE_H + +namespace MWGui +{ + enum GuiMode + { + GM_Game, // Game mode, only HUD + GM_Inventory, // Inventory mode + GM_MainMenu, // Main menu mode + + GM_Console, // Console mode + + // None of the following are implemented yet + + GM_Dialogue, // NPC interaction + GM_Barter, + GM_Rest, + // .. more here .. + + // Startup character creation dialogs + GM_Name, + GM_Race, + GM_Birth, + GM_Class, + GM_Review + }; + + // Windows shown in inventory mode + enum GuiWindow + { + GW_None = 0, + + GW_Map = 0x01, + GW_Inventory = 0x02, + GW_Magic = 0x04, + GW_Stats = 0x08, + + GW_ALL = 0xFF + }; +} + +#endif diff --git a/apps/openmw/mwgui/window_manager.cpp b/apps/openmw/mwgui/window_manager.cpp index d2c2db218b..16c2dec213 100644 --- a/apps/openmw/mwgui/window_manager.cpp +++ b/apps/openmw/mwgui/window_manager.cpp @@ -4,6 +4,7 @@ #include "race.hpp" #include "../mwmechanics/mechanicsmanager.hpp" +#include "../mwinput/inputmanager.hpp" #include "console.hpp" @@ -136,8 +137,10 @@ void WindowManager::updateVisible() return; } - // All other modes are ignored - mode = GM_Game; + // Unsupported mode, switch back to game + // Note: The call will eventually end up this method again but + // will stop at the check if(mode == GM_Game) above. + environment.mInputManager->setGuiMode(GM_Game); } void WindowManager::setValue (const std::string& id, const MWMechanics::Stat& value) @@ -197,11 +200,11 @@ void WindowManager::onNameDialogDone() updateCharacterGeneration(); if (reviewNext) - setMode(GM_Review); + environment.mInputManager->setGuiMode(GM_Review); else if (goNext) - setMode(GM_Race); + environment.mInputManager->setGuiMode(GM_Race); else - setMode(GM_Game); + environment.mInputManager->setGuiMode(GM_Game); } void WindowManager::onRaceDialogDone() @@ -219,11 +222,11 @@ void WindowManager::onRaceDialogDone() updateCharacterGeneration(); if (reviewNext) - setMode(GM_Review); + environment.mInputManager->setGuiMode(GM_Review); else if (goNext) - setMode(GM_Class); + environment.mInputManager->setGuiMode(GM_Class); else - setMode(GM_Game); + environment.mInputManager->setGuiMode(GM_Game); } void WindowManager::onRaceDialogBack() @@ -238,5 +241,5 @@ void WindowManager::onRaceDialogBack() updateCharacterGeneration(); - setMode(GM_Name); + environment.mInputManager->setGuiMode(GM_Name); } diff --git a/apps/openmw/mwgui/window_manager.hpp b/apps/openmw/mwgui/window_manager.hpp index 31b091c78d..0192186a35 100644 --- a/apps/openmw/mwgui/window_manager.hpp +++ b/apps/openmw/mwgui/window_manager.hpp @@ -14,6 +14,7 @@ #include #include "../mwmechanics/stat.hpp" +#include "mode.hpp" namespace MyGUI { @@ -42,42 +43,6 @@ namespace MWGui class TextInputDialog; class RaceDialog; - enum GuiMode - { - GM_Game, // Game mode, only HUD - GM_Inventory, // Inventory mode - GM_MainMenu, // Main menu mode - - GM_Console, // Console mode - - // None of the following are implemented yet - - GM_Dialogue, // NPC interaction - GM_Barter, - GM_Rest, - // .. more here .. - - // Startup character creation dialogs - GM_Name, - GM_Race, - GM_Birth, - GM_Class, - GM_Review - }; - - // Windows shown in inventory mode - enum GuiWindow - { - GW_None = 0, - - GW_Map = 0x01, - GW_Inventory = 0x02, - GW_Magic = 0x04, - GW_Stats = 0x08, - - GW_ALL = 0xFF - }; - class WindowManager { MWWorld::Environment& environment; diff --git a/apps/openmw/mwinput/inputmanager.cpp b/apps/openmw/mwinput/inputmanager.cpp index f730150b0b..8dba12b7a6 100644 --- a/apps/openmw/mwinput/inputmanager.cpp +++ b/apps/openmw/mwinput/inputmanager.cpp @@ -79,34 +79,6 @@ namespace MWInput ogre.screenshot(buf); } - // Switch between gui modes. Besides controlling the Gui windows - // this also makes sure input is directed to the right place - void setGuiMode(MWGui::GuiMode mode) - { - // Tell the GUI what to show (this also takes care of the mouse - // pointer) - windows.setMode(mode); - - // Are we in GUI mode now? - if(windows.isGuiMode()) - { - // Disable mouse look - mouse->setCamera(NULL); - - // Enable GUI events - guiEvents->enabled = true; - } - else - { - // Start mouse-looking again. TODO: This should also allow - // for other ways to disable mouselook, like paralyzation. - mouse->setCamera(player.getCamera()); - - // Disable GUI events - guiEvents->enabled = false; - } - } - // Called when the user presses the button to toggle the inventory // screen. void toggleInventory() @@ -275,6 +247,34 @@ namespace MWInput return true; } + + // Switch between gui modes. Besides controlling the Gui windows + // this also makes sure input is directed to the right place + void setGuiMode(MWGui::GuiMode mode) + { + // Tell the GUI what to show (this also takes care of the mouse + // pointer) + windows.setMode(mode); + + // Are we in GUI mode now? + if(windows.isGuiMode()) + { + // Disable mouse look + mouse->setCamera(NULL); + + // Enable GUI events + guiEvents->enabled = true; + } + else + { + // Start mouse-looking again. TODO: This should also allow + // for other ways to disable mouselook, like paralyzation. + mouse->setCamera(player.getCamera()); + + // Disable GUI events + guiEvents->enabled = false; + } + } }; MWInputManager::MWInputManager(OEngine::Render::OgreRenderer &ogre, @@ -290,4 +290,9 @@ namespace MWInput { delete impl; } + + void MWInputManager::setGuiMode(MWGui::GuiMode mode) + { + impl->setGuiMode(mode); + } } diff --git a/apps/openmw/mwinput/inputmanager.hpp b/apps/openmw/mwinput/inputmanager.hpp index 554089588d..0e0c4650f0 100644 --- a/apps/openmw/mwinput/inputmanager.hpp +++ b/apps/openmw/mwinput/inputmanager.hpp @@ -1,6 +1,8 @@ #ifndef _MWINPUT_MWINPUTMANAGER_H #define _MWINPUT_MWINPUTMANAGER_H +#include "../mwgui/mode.hpp" + namespace OEngine { namespace Render @@ -45,6 +47,8 @@ namespace MWInput bool debug, OMW::Engine& engine); ~MWInputManager(); + + void setGuiMode(MWGui::GuiMode mode); }; } #endif diff --git a/apps/openmw/mwscript/guiextensions.cpp b/apps/openmw/mwscript/guiextensions.cpp index 4d389748d8..0339a11f50 100644 --- a/apps/openmw/mwscript/guiextensions.cpp +++ b/apps/openmw/mwscript/guiextensions.cpp @@ -8,6 +8,7 @@ #include #include "../mwgui/window_manager.hpp" +#include "../mwinput/inputmanager.hpp" #include "interpretercontext.hpp" @@ -47,7 +48,7 @@ namespace MWScript InterpreterContext& context = static_cast (runtime.getContext()); - context.getWindowManager().setMode(mDialogue); + context.getInputManager().setGuiMode(mDialogue); } }; diff --git a/apps/openmw/mwscript/interpretercontext.cpp b/apps/openmw/mwscript/interpretercontext.cpp index 22a5aaa702..f2f1e6e104 100644 --- a/apps/openmw/mwscript/interpretercontext.cpp +++ b/apps/openmw/mwscript/interpretercontext.cpp @@ -11,6 +11,8 @@ #include "../mwgui/window_manager.hpp" +#include "../mwinput/inputmanager.hpp" + #include "locals.hpp" #include "globalscripts.hpp" @@ -263,6 +265,11 @@ namespace MWScript return *mEnvironment.mWindowManager; } + MWInput::MWInputManager& InterpreterContext::getInputManager() + { + return *mEnvironment.mInputManager; + } + MWWorld::World& InterpreterContext::getWorld() { return *mEnvironment.mWorld; diff --git a/apps/openmw/mwscript/interpretercontext.hpp b/apps/openmw/mwscript/interpretercontext.hpp index ec3c9eb878..031820d5dd 100644 --- a/apps/openmw/mwscript/interpretercontext.hpp +++ b/apps/openmw/mwscript/interpretercontext.hpp @@ -15,6 +15,11 @@ namespace MWSound class SoundManager; } +namespace MWInput +{ + struct MWInputManager; +} + namespace MWScript { struct Locals; @@ -107,6 +112,8 @@ namespace MWScript MWGui::WindowManager& getWindowManager(); + MWInput::MWInputManager& getInputManager(); + MWWorld::Ptr getReference(); ///< Reference, that the script is running from (can be empty) }; diff --git a/apps/openmw/mwworld/environment.hpp b/apps/openmw/mwworld/environment.hpp index f9e2e8a42b..c04dfcbf10 100644 --- a/apps/openmw/mwworld/environment.hpp +++ b/apps/openmw/mwworld/environment.hpp @@ -26,6 +26,11 @@ namespace MWDialogue class DialogueManager; } +namespace MWInput +{ + struct MWInputManager; +} + namespace MWWorld { class World; @@ -36,7 +41,8 @@ namespace MWWorld public: Environment() : mWorld (0), mSoundManager (0), mGlobalScripts (0), mWindowManager (0), - mMechanicsManager (0), mDialogueManager (0), mFrameDuration (0) + mMechanicsManager (0), mDialogueManager (0), mFrameDuration (0), + mInputManager (0) {} World *mWorld; @@ -46,6 +52,9 @@ namespace MWWorld MWMechanics::MechanicsManager *mMechanicsManager; MWDialogue::DialogueManager *mDialogueManager; float mFrameDuration; + + // For setting GUI mode + MWInput::MWInputManager *mInputManager; }; }