1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-05 15:15:33 +00:00

The game mode is now properly restored once a dialog is finished. Previously the game mode was only set in the window manager but it has to go through the input manager firs to get correct input state. Also updated the gui script commands to also use the input manager and not the window manager.

At some point the gui mode code should be moved to a class that handles all game mode (engine?).
This commit is contained in:
Jan Borsodi 2010-09-15 14:48:19 +02:00
parent 30e0d713ed
commit 1907aeb6c6
10 changed files with 120 additions and 75 deletions

View file

@ -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;

View file

@ -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

View file

@ -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<int>& 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);
}

View file

@ -14,6 +14,7 @@
#include <vector>
#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;

View file

@ -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);
}
}

View file

@ -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

View file

@ -8,6 +8,7 @@
#include <components/interpreter/opcodes.hpp>
#include "../mwgui/window_manager.hpp"
#include "../mwinput/inputmanager.hpp"
#include "interpretercontext.hpp"
@ -47,7 +48,7 @@ namespace MWScript
InterpreterContext& context =
static_cast<InterpreterContext&> (runtime.getContext());
context.getWindowManager().setMode(mDialogue);
context.getInputManager().setGuiMode(mDialogue);
}
};

View file

@ -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;

View file

@ -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)
};

View file

@ -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;
};
}