Index: code/branches/presentation2/src/libraries/core/CMakeLists.txt
===================================================================
--- code/branches/presentation2/src/libraries/core/CMakeLists.txt	(revision 6141)
+++ code/branches/presentation2/src/libraries/core/CMakeLists.txt	(revision 6150)
@@ -86,6 +86,8 @@
   TOLUA_FILES
     CommandExecutor.h
+    Game.h
     Loader.h
     LuaState.h
+    input/InputManager.h
   DEFINE_SYMBOL
     "CORE_SHARED_BUILD"
Index: code/branches/presentation2/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/GUIManager.cc	(revision 6141)
+++ code/branches/presentation2/src/libraries/core/GUIManager.cc	(revision 6150)
@@ -50,7 +50,11 @@
 
 #include "util/Clock.h"
+#include "util/Convert.h"
 #include "util/Debug.h"
 #include "util/Exception.h"
 #include "util/OrxAssert.h"
+#include "ConsoleCommand.h"
+#include "Core.h"
+#include "input/InputManager.h"
 #include "LuaState.h"
 #include "PathConfig.h"
@@ -85,4 +89,7 @@
     GUIManager* GUIManager::singletonPtr_s = 0;
 
+    SetConsoleCommandShortcut(GUIManager, showGUI).accessLevel(AccessLevel::User).defaultValue(1, false).defaultValue(2, true);
+    SetConsoleCommandShortcut(GUIManager, hideGUI).accessLevel(AccessLevel::User);
+
     /**
     @brief
@@ -101,4 +108,5 @@
         , resourceProvider_(0)
         , camera_(NULL)
+        , bShowIngameGUI_(false)
     {
         using namespace CEGUI;
@@ -113,4 +121,7 @@
         // setup scripting
         luaState_.reset(new LuaState());
+        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI");
+        // This is necessary to ensure that input events also use the right resource info when triggering lua functions
+        luaState_->setDefaultResourceInfo(this->rootFileInfo_);
         scriptModule_.reset(new LuaScriptModule(luaState_->getInternalLuaState()));
 
@@ -127,5 +138,4 @@
 
         // Initialise the basic Lua code
-        rootFileInfo_ = Resource::getInfo("InitialiseGUI.lua", "GUI");
         this->luaState_->doFile("InitialiseGUI.lua", "GUI", false);
 
@@ -203,7 +213,68 @@
         For more details check out loadGUI_2.lua where the function presides.
     */
-    void GUIManager::showGUI(const std::string& name)
-    {
-        this->luaState_->doString("showGUI(\"" + name + "\")", rootFileInfo_);
+    /*static*/ void GUIManager::showGUI(const std::string& name, bool hidePrevious, bool showCursor)
+    {
+        std::pair<std::set<std::string>::iterator,bool> result = GUIManager::getInstance().showingGUIs_.insert(name);
+        if(GUIManager::getInstance().showingGUIs_.size() == 1 && result.second == true) //!< If it's the first GUI.
+        {
+//             InputManager::getInstance().enterState("guiMouseOnly");
+        }
+        GUIManager::getInstance().executeCode("showGUI(\"" + name + "\", " + multi_cast<std::string>(hidePrevious) + ", " + multi_cast<std::string>(showCursor) + ")");
+    }
+
+    /**
+    @brief
+        Hack-ish. Needed for GUIOverlay.
+    */
+    void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool hidePrevious, bool showCursor)
+    {
+        std::pair<std::set<std::string>::iterator,bool> result = this->showingGUIs_.insert(name);
+        if(this->showingGUIs_.size() == 1 && result.second == true) //!< If it's the first GUI.
+        {
+//             this->executeCode("showCursor()");
+//             InputManager::getInstance().enterState("guiMouseOnly");
+        }
+        this->executeCode("showGUI(\"" + name + "\", " + multi_cast<std::string>(hidePrevious) + ", " + multi_cast<std::string>(showCursor) + ", " + ptr + ")");
+    }
+
+    /**
+    @brief
+        Hides specified GUI.
+    @param name
+        The name of the GUI.
+    */
+    /*static*/ void GUIManager::hideGUI(const std::string& name)
+    {
+        GUIManager::getInstance().showingGUIs_.erase(name);
+        GUIManager::getInstance().executeCode("hideGUI(\"" + name + "\")");
+        if(GUIManager::getInstance().showingGUIs_.size() == 0)
+        {
+//             GUIManager::getInstance().executeCode("hideCursor()");
+//             InputManager::getInstance().leaveState("guiMouseOnly");
+        }
+    }
+
+    void GUIManager::toggleIngameGUI()
+    {
+        if ( this->bShowIngameGUI_==false )
+        {
+            GUIManager::showGUI("InGameMenu");
+            this->bShowIngameGUI_ = true;
+        }
+        else
+        {
+            GUIManager::hideGUI("InGameMenu");
+            this->bShowIngameGUI_ = false;
+        }
+    }
+    
+    void GUIManager::keyESC()
+    {
+        this->executeCode("keyESC()");
+    }
+    
+    void GUIManager::setBackground(const std::string& name)
+    {
+        this->executeCode("setBackground(\"" + name + "\")");
     }
 
Index: code/branches/presentation2/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/presentation2/src/libraries/core/GUIManager.h	(revision 6141)
+++ code/branches/presentation2/src/libraries/core/GUIManager.h	(revision 6150)
@@ -34,4 +34,5 @@
 
 #include <map>
+#include <set>
 #include <string>
 #include <CEGUIForwardRefs.h>
@@ -65,8 +66,12 @@
         ~GUIManager();
 
-        void update(const Clock& time);
+        void update(const Clock& time); 
 
-        void showGUI(const std::string& name);
-        void executeCode(const std::string& str);
+        static void showGUI(const std::string& name, bool hidePrevious=false, bool showCursor=true);
+        void showGUIExtra(const std::string& name, const std::string& ptr, bool hidePrevious=false, bool showCursor=true);
+        static void hideGUI(const std::string& name);
+        void toggleIngameGUI();
+        void keyESC();
+        void setBackground(const std::string& name);
 
         void setCamera(Ogre::Camera* camera);
@@ -82,4 +87,8 @@
     private:
         GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
+
+        std::set<std::string> showingGUIs_; //!< Keeps track of all the GUIs that are currently showing.
+
+        void executeCode(const std::string& str);
 
         // keyHandler functions
@@ -105,4 +114,5 @@
 
         static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
+        bool                                 bShowIngameGUI_;
 
     };
Index: code/branches/presentation2/src/libraries/core/Game.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/Game.cc	(revision 6141)
+++ code/branches/presentation2/src/libraries/core/Game.cc	(revision 6150)
@@ -51,4 +51,5 @@
 #include "GameMode.h"
 #include "GameState.h"
+#include "GUIManager.h"
 
 namespace orxonox
@@ -57,4 +58,7 @@
         { Game::getInstance().stop(); }
     SetConsoleCommandShortcutExternAlias(stop_game, "exit");
+    static void key_esc()
+        { Game::getInstance().keyESC(); }
+    SetConsoleCommandShortcutExternAlias(key_esc, "keyESC");
     static void printFPS()
         { COUT(0) << Game::getInstance().getAvgFPS() << std::endl; }
@@ -327,4 +331,12 @@
     }
 
+    void Game::keyESC()
+    {
+        if( this->getState("mainMenu") && this->getState("mainMenu")->getActivity().active==true )
+            this->stop();
+        else
+            GUIManager::getInstance().keyESC();
+    }
+
     void Game::stop()
     {
@@ -557,5 +569,5 @@
 
         shared_ptr<GameState> state = this->getState(name);
-        state->activate();
+        state->activateInternal();
         if (!this->loadedStates_.empty())
             this->loadedStates_.back()->activity_.topState = false;
@@ -576,5 +588,5 @@
             if (!this->loadedStates_.empty())
                 this->loadedStates_.back()->activity_.topState = true;
-            state->deactivate();
+            state->deactivateInternal();
         }
         catch (...)
Index: code/branches/presentation2/src/libraries/core/Game.h
===================================================================
--- code/branches/presentation2/src/libraries/core/Game.h	(revision 6141)
+++ code/branches/presentation2/src/libraries/core/Game.h	(revision 6150)
@@ -59,7 +59,9 @@
 #define DeclareGameState(className, stateName, bIgnoreTickTime, bGraphicsMode) \
     static bool BOOST_PP_CAT(bGameStateDummy_##className, __LINE__) = orxonox::Game::declareGameState<className>(#className, stateName, bIgnoreTickTime, bGraphicsMode)
-
+// tolua_begin
 namespace orxonox
 {
+// tolua_end
+
     //! Helper object required before GameStates are being constructed
     struct GameStateInfo
@@ -77,6 +79,9 @@
         You should only create this singleton once because it owns the Core class! (see remark there)
     */
-    class _CoreExport Game : public Singleton<Game>, public OrxonoxClass
-    {
+// tolua_begin
+    class _CoreExport Game
+// tolua_end
+        : public Singleton<Game>, public OrxonoxClass
+    { // tolua_export
         friend class Singleton<Game>;
         typedef std::vector<shared_ptr<GameState> > GameStateVector;
@@ -95,8 +100,11 @@
         void run();
         void stop();
-
-        void requestState(const std::string& name);
-        void requestStates(const std::string& names);
-        void popState();
+        void keyESC();
+
+        static Game& getInstance(){ return Singleton<Game>::getInstance(); } // tolua_export
+
+        void requestState(const std::string& name); //tolua_export
+        void requestStates(const std::string& names); //tolua_export
+        void popState(); //tolua_export
 
         const Clock& getGameClock() { return *this->gameClock_; }
@@ -188,5 +196,5 @@
         static std::map<std::string, GameStateInfo> gameStateDeclarations_s;
         static Game* singletonPtr_s;        //!< Pointer to the Singleton
-    };
+    }; //tolua_export
 
     template <class T>
@@ -214,5 +222,5 @@
         return true;
     }
-}
+} //tolua_export
 
 #endif /* _Game_H__ */
Index: code/branches/presentation2/src/libraries/core/GameState.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/GameState.cc	(revision 6141)
+++ code/branches/presentation2/src/libraries/core/GameState.cc	(revision 6150)
@@ -83,5 +83,5 @@
         this->activity_.active = false;
         this->activity_.deactivating = true;
-        this->activate();
+        this->deactivate();
         this->activity_.deactivating = false;
         this->activity_.suspended = false;
Index: code/branches/presentation2/src/libraries/core/LuaState.cc
===================================================================
--- code/branches/presentation2/src/libraries/core/LuaState.cc	(revision 6141)
+++ code/branches/presentation2/src/libraries/core/LuaState.cc	(revision 6150)
@@ -116,5 +116,5 @@
     }
 
-    void LuaState::includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo)
+    void LuaState::includeString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo)
     {
         // Parse string with provided include parser (otherwise don't preparse at all)
@@ -138,5 +138,5 @@
     }
 
-    void LuaState::doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo)
+    void LuaState::doString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo)
     {
         // Save the oold source file info
@@ -164,5 +164,5 @@
             if (sourceFileInfo != NULL)
                 origin = " originating from " + sourceFileInfo_->filename;
-            COUT(2) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;
+            COUT(1) << "Error in Lua-script" << origin << ": " << lua_tostring(luaState_, -1) << std::endl;
             // return value is nil
             lua_pushnil(luaState_);
Index: code/branches/presentation2/src/libraries/core/LuaState.h
===================================================================
--- code/branches/presentation2/src/libraries/core/LuaState.h	(revision 6141)
+++ code/branches/presentation2/src/libraries/core/LuaState.h	(revision 6150)
@@ -57,8 +57,8 @@
 
         void doFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
-        void doString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
+        void doString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>());
 
         void includeFile(const std::string& filename, const std::string& resourceGroup = "General", bool bSearchOtherPaths = true); // tolua_export
-        void includeString(const std::string& code, shared_ptr<ResourceInfo> sourceFileInfo = shared_ptr<ResourceInfo>());
+        void includeString(const std::string& code, const shared_ptr<ResourceInfo>& sourceFileInfo = shared_ptr<ResourceInfo>());
 
         void luaPrint(const std::string& str); // tolua_export
@@ -71,4 +71,7 @@
         void setIncludeParser(std::string (*function)(const std::string&)) { includeParseFunction_ = function; }
         lua_State* getInternalLuaState() { return luaState_; }
+
+        void setDefaultResourceInfo(const shared_ptr<ResourceInfo>& sourceFileInfo) { this->sourceFileInfo_ = sourceFileInfo; }
+        const shared_ptr<ResourceInfo>& getDefaultResourceInfo() { return this->sourceFileInfo_; }
 
         static bool addToluaInterface(int (*function)(lua_State*), const std::string& name);
Index: code/branches/presentation2/src/libraries/core/input/InputManager.h
===================================================================
--- code/branches/presentation2/src/libraries/core/input/InputManager.h	(revision 6141)
+++ code/branches/presentation2/src/libraries/core/input/InputManager.h	(revision 6150)
@@ -41,4 +41,5 @@
 #include "InputState.h"
 
+// tolua_begin
 namespace orxonox
 {
@@ -63,6 +64,8 @@
           If the OIS::InputManager or the Keyboard fail, an exception is thrown.
     */
-    class _CoreExport InputManager : public Singleton<InputManager>, public WindowEventListener
-    {
+    class _CoreExport InputManager
+// tolua_end
+        : public Singleton<InputManager>, public WindowEventListener
+    { // tolua_export
         friend class Singleton<InputManager>;
     public:
@@ -139,5 +142,5 @@
             False if name was not found, true otherwise.
         */
-        bool enterState(const std::string& name);
+        bool enterState(const std::string& name); // tolua_export
         /**
         @brief
@@ -146,5 +149,5 @@
             False if name was not found, true otherwise.
         */
-        bool leaveState(const std::string& name);
+        bool leaveState(const std::string& name); // tolua_export
         /**
         @brief
@@ -167,4 +170,6 @@
         OIS::InputManager* getOISInputManager() { return this->oisInputManager_; }
         std::pair<int, int> getMousePosition() const;
+        
+        static InputManager& getInstance() { return *singletonPtr_s; } // tolua_export
 
     private: // functions
@@ -207,6 +212,6 @@
 
         static InputManager*                singletonPtr_s;        //!< Pointer reference to the singleton
-    };
-}
+    }; // tolua_export
+} // tolua_export
 
 #endif /* _InputManager_H__ */
