Index: code/branches/gamestate/data/gui/scripts/BasicGUI.lua
===================================================================
--- code/branches/gamestate/data/gui/scripts/BasicGUI.lua	(revision 6459)
+++ code/branches/gamestate/data/gui/scripts/BasicGUI.lua	(revision 6537)
@@ -8,9 +8,9 @@
 end
 
--- useless?
+-- useless, even wrong? P is the class, not the object..
 P.overlay = nil
 
 -- constructor of the GUI
-function P:new(_filename, _visible, _gui)
+function P:new(_filename, _gui, _visible)
     local newElement = {
         filename = _filename,
@@ -23,6 +23,12 @@
 end
 
+-- Override this function if you need to
 function P:init()
--- this function is empty and intended for inheriting GUIs to use
+end
+
+-- Override this function if you need to
+-- But don't forget to stick to the naming convention ("GUI_" .. self.filename)
+function P:createInputState()
+    self.inputState = guiMgr:createInputState("GUI_" .. self.filename)
 end
 
@@ -41,4 +47,5 @@
 function P:load()
     self.window = winMgr:loadWindowLayout(self.filename .. ".layout")
+    self:createInputState()
     self:init()
     return self
Index: code/branches/gamestate/data/gui/scripts/DecisionPopup.lua
===================================================================
--- code/branches/gamestate/data/gui/scripts/DecisionPopup.lua	(revision 6459)
+++ code/branches/gamestate/data/gui/scripts/DecisionPopup.lua	(revision 6537)
@@ -7,7 +7,4 @@
 else
     _G[_REQUIREDNAME] = P
-end
-
-function P:init()
 end
 
Index: code/branches/gamestate/data/gui/scripts/InGameMenu.lua
===================================================================
--- code/branches/gamestate/data/gui/scripts/InGameMenu.lua	(revision 6459)
+++ code/branches/gamestate/data/gui/scripts/InGameMenu.lua	(revision 6537)
@@ -8,9 +8,4 @@
     _G[_REQUIREDNAME] = P
 end
-
-
-function P:init()
-end
-
 
 -- events for ingamemenu
Index: code/branches/gamestate/data/gui/scripts/InfoPopup.lua
===================================================================
--- code/branches/gamestate/data/gui/scripts/InfoPopup.lua	(revision 6459)
+++ code/branches/gamestate/data/gui/scripts/InfoPopup.lua	(revision 6537)
@@ -8,7 +8,4 @@
 else
     _G[_REQUIREDNAME] = P
-end
-
-function P:init()
 end
 
@@ -23,5 +20,5 @@
 end
 
-function P.setText( text )
+function P.setText(text)
     winMgr:getWindow("orxonox/InfoPopup_text"):setText( text )
 end
@@ -39,5 +36,5 @@
 -- events for ingamemenu
 function P.close(e)
-    hideGUI("InfoPopup")
+    hideGUI(P.filename)
 end
 
Index: code/branches/gamestate/data/gui/scripts/InitialiseGUI.lua
===================================================================
--- code/branches/gamestate/data/gui/scripts/InitialiseGUI.lua	(revision 6459)
+++ code/branches/gamestate/data/gui/scripts/InitialiseGUI.lua	(revision 6537)
@@ -1,7 +1,9 @@
+winMgr   = CEGUI.WindowManager:getSingleton()
+guiMgr   = orxonox.GUIManager:getInstance()
+inputMgr = orxonox.InputManager:getInstance()
+
 local schemeMgr = CEGUI.SchemeManager:getSingleton()
-winMgr = CEGUI.WindowManager:getSingleton()
-local logger = CEGUI.Logger:getSingleton()
-local system = CEGUI.System:getSingleton()
-local cursor = CEGUI.MouseCursor:getSingleton()
+local system    = CEGUI.System:getSingleton()
+local cursor    = CEGUI.MouseCursor:getSingleton()
 
 schemeMgr:loadScheme("TaharezLookSkin.scheme")
@@ -87,8 +89,10 @@
     else
         if nrOfActiveSheets == 0 then
-            orxonox.InputManager:getInstance():enterState("guiMouseOnly")
+            --orxonox.InputManager:getInstance():enterState("guiMouseOnly")
             orxonox.HumanController:pauseControl()
         end
     end
+    orxonox.InputManager:getInstance():enterState(currentGUI.inputState)
+
     nrOfActiveSheets = nrOfActiveSheets + 1
     table.insert(activeSheets, filename)
@@ -161,8 +165,9 @@
     bHidePrevious[filename] = nil
     if nrOfActiveSheets == 0 then
-        orxonox.InputManager:getInstance():leaveState("guiMouseOnly")
+        --orxonox.InputManager:getInstance():leaveState("guiMouseOnly")
         orxonox.HumanController:resumeControl()
         hideCursor()
     end
+    orxonox.InputManager:getInstance():leaveState(currentGUI.inputState)
 end
 
Index: code/branches/gamestate/src/libraries/core/Core.cc
===================================================================
--- code/branches/gamestate/src/libraries/core/Core.cc	(revision 6459)
+++ code/branches/gamestate/src/libraries/core/Core.cc	(revision 6537)
@@ -225,6 +225,5 @@
 
         // Load the CEGUI interface
-        guiManager_.reset(new GUIManager(graphicsManager_->getRenderWindow(),
-            inputManager_->getMousePosition(), graphicsManager_->isFullScreen()));
+        guiManager_.reset(new GUIManager(inputManager_->getMousePosition()));
 
         bGraphicsLoaded_ = true;
Index: code/branches/gamestate/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/gamestate/src/libraries/core/GUIManager.cc	(revision 6459)
+++ code/branches/gamestate/src/libraries/core/GUIManager.cc	(revision 6537)
@@ -57,7 +57,11 @@
 #include "ConsoleCommand.h"
 #include "Core.h"
+#include "GraphicsManager.h"
 #include "LuaState.h"
 #include "PathConfig.h"
 #include "Resource.h"
+#include "input/InputManager.h"
+#include "input/InputState.h"
+#include "input/KeyBinderManager.h"
 
 namespace orxonox
@@ -108,9 +112,7 @@
     @return true if success, otherwise false
     */
-    GUIManager::GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen)
-        : renderWindow_(renderWindow)
-        , resourceProvider_(0)
+    GUIManager::GUIManager(const std::pair<int, int>& mousePosition)
+        : resourceProvider_(NULL)
         , camera_(NULL)
-        , bShowIngameGUI_(false)
     {
         using namespace CEGUI;
@@ -119,5 +121,5 @@
 
         // Note: No SceneManager specified yet
-        guiRenderer_.reset(new OgreCEGUIRenderer(renderWindow_, Ogre::RENDER_QUEUE_OVERLAY, false, 3000));
+        guiRenderer_.reset(new OgreCEGUIRenderer(GraphicsManager::getInstance().getRenderWindow(), Ogre::RENDER_QUEUE_OVERLAY, false, 3000));
         resourceProvider_ = guiRenderer_->createResourceProvider();
         resourceProvider_->setDefaultResourceGroup("GUI");
@@ -141,13 +143,13 @@
         guiSystem_.reset(new System(guiRenderer_.get(), resourceProvider_, 0, scriptModule_.get()));
 
+        // Align CEGUI mouse with OIS mouse
+        guiSystem_->injectMousePosition(mousePosition.first, mousePosition.second);
+
+        // Hide the mouse cursor unless playing in full screen mode
+        if (!GraphicsManager::getInstance().isFullScreen())
+            CEGUI::MouseCursor::getSingleton().hide();
+
         // Initialise the basic Lua code
         this->luaState_->doFile("InitialiseGUI.lua");
-
-        // Align CEGUI mouse with OIS mouse
-        guiSystem_->injectMousePosition(mousePosition.first, mousePosition.second);
-
-        // Hide the mouse cursor unless playing in full screen mode
-        if (!bFullScreen)
-            CEGUI::MouseCursor::getSingleton().hide();
     }
 
@@ -251,4 +253,30 @@
     }
 
+    const std::string& GUIManager::createInputState(const std::string& name, TriBool::Value showMouse, TriBool::Value useKeyboard, bool bBlockJoyStick)
+    {
+        InputState* state = InputManager::getInstance().createInputState(name);
+
+        if (GraphicsManager::getInstance().isFullScreen() && showMouse == TriBool::True ||
+           !GraphicsManager::getInstance().isFullScreen() && showMouse == TriBool::False)
+            state->setMouseExclusive(TriBool::True);
+        else
+            state->setMouseExclusive(TriBool::Dontcare);
+
+        if (showMouse == TriBool::True)
+            state->setMouseHandler(this);
+        else if (showMouse == TriBool::False)
+            state->setMouseHandler(&InputHandler::EMPTY);
+
+        if (useKeyboard == TriBool::True)
+            state->setKeyHandler(this);
+        else if (useKeyboard == TriBool::False)
+            state->setKeyHandler(&InputHandler::EMPTY);
+
+        if (bBlockJoyStick)
+            state->setJoyStickHandler(&InputHandler::EMPTY);
+
+        return state->getName();
+    }
+
     void GUIManager::keyESC()
     {
Index: code/branches/gamestate/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/gamestate/src/libraries/core/GUIManager.h	(revision 6459)
+++ code/branches/gamestate/src/libraries/core/GUIManager.h	(revision 6537)
@@ -41,6 +41,12 @@
 
 #include "util/OgreForwardRefs.h"
+#include "util/TriBool.h"
 #include "util/Singleton.h"
 #include "input/InputHandler.h"
+
+// Tolua includes (have to be relative to the current directory)
+/*
+$cfile "../util/TriBool.h" // tolua_export
+*/
 
 namespace orxonox // tolua_export
@@ -54,5 +60,4 @@
 
         The GUIManager is a singleton and can be called anywhere when access on the GUI is needed.
-        Creation of the GUIManager is therefore not possible and the cunstructor is private.
 
         Since the GUI needs user input, the GUIManager implements the functions needed to act as a key and/or mouse handler.
@@ -64,5 +69,5 @@
         friend class Singleton<GUIManager>;
     public:
-        GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen);
+        GUIManager(const std::pair<int, int>& mousePosition);
         ~GUIManager();
 
@@ -76,8 +81,8 @@
         void setBackground(const std::string& name);
 
+        const std::string& createInputState(const std::string& name, TriBool::Value showMouse = TriBool::True, TriBool::Value useKeyboard = TriBool::True, bool bBlockJoyStick = false); // tolua_export
+
         void setCamera(Ogre::Camera* camera);
         Ogre::Camera* getCamera() { return this->camera_; }
-
-        static GUIManager* getInstancePtr() { return singletonPtr_s; }
 
         inline void setPlayer(const std::string& guiname, PlayerInfo* player)
@@ -88,4 +93,6 @@
         // TODO: Temporary hack because the tolua exported CEGUI method does not seem to work
         static void subscribeEventHelper(CEGUI::Window* window, const std::string& event, const std::string& function); //tolua_export
+
+        static GUIManager& getInstance() { return Singleton<GUIManager>::getInstance(); } // tolua_export
 
     private:
@@ -103,5 +110,4 @@
         void mouseMoved    (IntVector2 abs, IntVector2 rel, IntVector2 clippingSize);
         void mouseScrolled (int abs, int rel);
-
         scoped_ptr<CEGUI::OgreCEGUIRenderer> guiRenderer_;      //!< CEGUI's interface to the Ogre Engine
         scoped_ptr<LuaState>                 luaState_;         //!< LuaState, access point to the Lua engine
@@ -109,12 +115,10 @@
         scoped_ptr<CEGUI::System>            guiSystem_;        //!< CEGUI's main system
         shared_ptr<ResourceInfo>             rootFileInfo_;     //!< Resource information about the root script
-        Ogre::RenderWindow*                  renderWindow_;     //!< Ogre's render window to give CEGUI access to it
         CEGUI::ResourceProvider*             resourceProvider_; //!< CEGUI's resource provider
         CEGUI::Logger*                       ceguiLogger_;      //!< CEGUI's logger to be able to log CEGUI errors in our log
-        std::map<std::string, PlayerInfo*>   players_;          //!< Stores the player (owner) for each gui
+        std::map<std::string, PlayerInfo*>   players_;          //!< Stores the player (owner) for each GUI
         Ogre::Camera*                        camera_;           //!< Camera used to render the scene with the GUI
 
         static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
-        bool                                 bShowIngameGUI_;
 
     }; // tolua_export
Index: code/branches/gamestate/src/libraries/core/input/InputManager.cc
===================================================================
--- code/branches/gamestate/src/libraries/core/input/InputManager.cc	(revision 6459)
+++ code/branches/gamestate/src/libraries/core/input/InputManager.cc	(revision 6537)
@@ -87,5 +87,5 @@
         , oisInputManager_(0)
         , devices_(2)
-        , mouseMode_(MouseMode::Nonexclusive)
+        , exclusiveMouse_(TriBool::False)
         , emptyState_(0)
         , calibratorCallbackHandler_(0)
@@ -98,5 +98,5 @@
 
         if (GraphicsManager::getInstance().isFullScreen())
-            mouseMode_ = MouseMode::Exclusive;
+            exclusiveMouse_ = TriBool::True;
         this->loadDevices();
 
@@ -155,5 +155,5 @@
         paramList.insert(std::make_pair("w32_keyboard", "DISCL_FOREGROUND"));
         paramList.insert(std::make_pair("w32_mouse", "DISCL_FOREGROUND"));
-        if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen())
+        if (exclusiveMouse_ == TriBool::True || GraphicsManager::getInstance().isFullScreen())
         {
             // Disable Windows key plus special keys (like play, stop, next, etc.)
@@ -168,5 +168,5 @@
         paramList.insert(std::make_pair("XAutoRepeatOn", "true"));
 
-        if (mouseMode_ == MouseMode::Exclusive || GraphicsManager::getInstance().isFullScreen())
+        if (exclusiveMouse_ == TriBool::True || GraphicsManager::getInstance().isFullScreen())
         {
             if (CommandLineParser::getValue("keyboard_no_grab").getBool())
@@ -504,13 +504,13 @@
 
         // Check whether we have to change the mouse mode
-        MouseMode::Value requestedMode = MouseMode::Dontcare;
+        TriBool::Value requestedMode = TriBool::Dontcare;
         std::vector<InputState*>& mouseStates = devices_[InputDeviceEnumerator::Mouse]->getStateListRef();
         if (mouseStates.empty())
-            requestedMode = MouseMode::Nonexclusive;
+            requestedMode = TriBool::False;
         else
-            requestedMode = mouseStates.front()->getMouseMode();
-        if (requestedMode != MouseMode::Dontcare && mouseMode_ != requestedMode)
-        {
-            mouseMode_ = requestedMode;
+            requestedMode = mouseStates.front()->getMouseExclusive();
+        if (requestedMode != TriBool::Dontcare && exclusiveMouse_ != requestedMode)
+        {
+            exclusiveMouse_ = requestedMode;
             if (!GraphicsManager::getInstance().isFullScreen())
                 this->reloadInternal();
Index: code/branches/gamestate/src/libraries/core/input/InputManager.h
===================================================================
--- code/branches/gamestate/src/libraries/core/input/InputManager.h	(revision 6459)
+++ code/branches/gamestate/src/libraries/core/input/InputManager.h	(revision 6537)
@@ -38,4 +38,5 @@
 
 #include "util/Singleton.h"
+#include "util/TriBool.h"
 #include "core/WindowEventListener.h"
 #include "InputState.h"
@@ -159,5 +160,5 @@
             - The removal process is being postponed if InputManager::preUpdate() is currently running.
         */
-        bool destroyState(const std::string& name);
+        bool destroyState(const std::string& name); // tolua_export
 
         //-------------------------------
@@ -196,5 +197,5 @@
         OIS::InputManager*                  oisInputManager_;      //!< OIS input manager
         std::vector<InputDevice*>           devices_;              //!< List of all input devices (keyboard, mouse, joy sticks)
-        MouseMode::Value                    mouseMode_;            //!< Currently applied mouse mode
+        TriBool::Value                      exclusiveMouse_;       //!< Currently applied mouse mode
 
         // some internally handled states and handlers
Index: code/branches/gamestate/src/libraries/core/input/InputState.cc
===================================================================
--- code/branches/gamestate/src/libraries/core/input/InputState.cc	(revision 6459)
+++ code/branches/gamestate/src/libraries/core/input/InputState.cc	(revision 6537)
@@ -37,5 +37,5 @@
         , bAlwaysGetsInput_(bAlwaysGetsInput)
         , bTransparent_(bTransparent)
-        , mouseMode_(MouseMode::Dontcare)
+        , exclusiveMouse_(TriBool::Dontcare)
         , bExpired_(true)
         , handlers_(2)
Index: code/branches/gamestate/src/libraries/core/input/InputState.h
===================================================================
--- code/branches/gamestate/src/libraries/core/input/InputState.h	(revision 6459)
+++ code/branches/gamestate/src/libraries/core/input/InputState.h	(revision 6537)
@@ -37,4 +37,5 @@
 
 #include "util/OrxEnum.h"
+#include "util/TriBool.h"
 #include "InputHandler.h"
 #include "JoyStickQuantityListener.h"
@@ -56,13 +57,4 @@
     };
 
-    namespace MouseMode
-    {
-        enum Value
-        {
-            Exclusive,
-            Nonexclusive,
-            Dontcare
-        };
-    }
 
     /**
@@ -73,5 +65,5 @@
         that stack and only the top one gets the input events. This is done for
         every device (keyboard, mouse, all joy sticks) separately to allow
-        for intance keyboard input capturing for the console while you can still
+        for instance keyboard input capturing for the console while you can still
         steer a ship with the mouse.
         There are two exceptions to this behaviour though:
@@ -83,5 +75,5 @@
           the state will always receive input as long as it is activated.
         - Note: If you mark an InputState with both parameters on, then it will
-          not influence ony other InputState at all.
+          not influence only other InputState at all.
 
     @par Priorities
@@ -95,5 +87,5 @@
     @par Exclusive/Non-Exclusive mouse Mode
         You can select a specific mouse mode that tells whether the application
-        should have exclusive accessto it or not.
+        should have exclusive access to it or not.
         When in non-exclusive mode, you can move the mouse out of the window
         like with any other normal window (only for windowed mode!).
@@ -130,6 +122,6 @@
         void setHandler        (InputHandler* handler);
 
-        void setMouseMode(MouseMode::Value value) { mouseMode_ = value; this->bExpired_ = true; }
-        MouseMode::Value getMouseMode() const { return mouseMode_; }
+        void setMouseExclusive(TriBool::Value value) { exclusiveMouse_ = value; this->bExpired_ = true; }
+        TriBool::Value getMouseExclusive() const { return exclusiveMouse_; }
 
         //! Returns the name of the state (which is unique!)
@@ -184,5 +176,5 @@
         const bool                  bAlwaysGetsInput_;      //!< See class declaration for explanation
         const bool                  bTransparent_;          //!< See class declaration for explanation
-        MouseMode::Value            mouseMode_;             //!< See class declaration for explanation
+        TriBool::Value              exclusiveMouse_;        //!< See class declaration for explanation
         int                         priority_;              //!< Current priority (might change)
         bool                        bExpired_;              //!< See hasExpired()
Index: code/branches/gamestate/src/libraries/util/TriBool.h
===================================================================
--- code/branches/gamestate/src/libraries/util/TriBool.h	(revision 6537)
+++ code/branches/gamestate/src/libraries/util/TriBool.h	(revision 6537)
@@ -0,0 +1,49 @@
+/*
+ *   ORXONOX - the hottest 3D action shooter ever to exist
+ *                    > www.orxonox.net <
+ *
+ *
+ *   License notice:
+ *
+ *   This program is free software; you can redistribute it and/or
+ *   modify it under the terms of the GNU General Public License
+ *   as published by the Free Software Foundation; either version 2
+ *   of the License, or (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, write to the Free Software
+ *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ *
+ *   Author:
+ *      Reto Grieder
+ *   Co-authors:
+ *      ...
+ *
+ */
+
+#ifndef _TriBool_H__
+#define _TriBool_H__
+
+#include "UtilPrereqs.h"
+
+// tolua_begin
+namespace orxonox
+{
+    namespace TriBool
+    {
+        enum Value
+        {
+            False    =  0,
+            True     =  1,
+            Dontcare =  2
+        };
+    }
+}
+// tolua_end
+
+#endif /* _TriBool_H__ */
Index: code/branches/gamestate/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/gamestate/src/orxonox/gamestates/GSLevel.cc	(revision 6459)
+++ code/branches/gamestate/src/orxonox/gamestates/GSLevel.cc	(revision 6537)
@@ -69,14 +69,14 @@
         {
             gameInputState_ = InputManager::getInstance().createInputState("game");
-            gameInputState_->setMouseMode(MouseMode::Exclusive);
+            gameInputState_->setMouseExclusive(TriBool::True);
             gameInputState_->setHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
             KeyBinderManager::getInstance().setToDefault();
 
             guiMouseOnlyInputState_ = InputManager::getInstance().createInputState("guiMouseOnly");
-            guiMouseOnlyInputState_->setMouseMode(MouseMode::Exclusive);
-            guiMouseOnlyInputState_->setMouseHandler(GUIManager::getInstancePtr());
+            guiMouseOnlyInputState_->setMouseExclusive(TriBool::True);
+            guiMouseOnlyInputState_->setMouseHandler(&GUIManager::getInstance());
 
             guiKeysOnlyInputState_ = InputManager::getInstance().createInputState("guiKeysOnly");
-            guiKeysOnlyInputState_->setKeyHandler(GUIManager::getInstancePtr());
+            guiKeysOnlyInputState_->setKeyHandler(&GUIManager::getInstance());
         }
 
Index: code/branches/gamestate/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/gamestate/src/orxonox/gamestates/GSMainMenu.cc	(revision 6459)
+++ code/branches/gamestate/src/orxonox/gamestates/GSMainMenu.cc	(revision 6537)
@@ -53,6 +53,6 @@
         RegisterRootObject(GSMainMenu);
         inputState_ = InputManager::getInstance().createInputState("mainMenu");
-        inputState_->setMouseMode(MouseMode::Nonexclusive);
-        inputState_->setHandler(GUIManager::getInstancePtr());
+        inputState_->setMouseExclusive(TriBool::False);
+        inputState_->setHandler(&GUIManager::getInstance());
         inputState_->setKeyHandler(KeyBinderManager::getInstance().getDefaultAsHandler());
         inputState_->setJoyStickHandler(&InputHandler::EMPTY);
@@ -101,5 +101,5 @@
 
         KeyBinderManager::getInstance().setToDefault();
-        InputManager::getInstance().enterState("mainMenu");
+        //InputManager::getInstance().enterState("mainMenu");
 
         this->setConfigValues();
@@ -119,5 +119,5 @@
         }
 
-        InputManager::getInstance().leaveState("mainMenu");
+        //InputManager::getInstance().leaveState("mainMenu");
 
         GUIManager::getInstance().setCamera(0);
