Index: code/branches/gamestates2/data/gui/scripts/AudioMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/AudioMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/AudioMenu.lua	(revision 6662)
@@ -1,13 +1,7 @@
 -- AudioMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("AudioMenu")
-if _REQUIREDNAME == nil then
-    AudioMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("AudioMenu")
 
-function P:init()
+function P.init()
     soundMgr = orxonox.SoundManager:getInstance()
     block = false
Index: code/branches/gamestates2/data/gui/scripts/BasicGUI.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/BasicGUI.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/BasicGUI.lua	(revision 6662)
@@ -1,10 +1,6 @@
--- gui.lua
+-- BasicGUI.lua
 
 local P = {}
-if _REQUIREDNAME == nil then
-    BasicGUI = P
-else
-    _G[_REQUIREDNAME] = P
-end
+_G[_REQUIREDNAME or "BasicGUI"] = P
 
 -- useless, even wrong? P is the class, not the object..
@@ -27,5 +23,6 @@
 end
 
--- Override this function if you need to
+-- Override this function if you want to change one of the three input parameters:
+-- showCursor = true, useKeyboard = true and blockJoyStick = false
 -- But don't forget to stick to the naming convention ("GUI_" .. self.filename)
 function P:createInputState()
Index: code/branches/gamestates2/data/gui/scripts/ControlsMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/ControlsMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/ControlsMenu.lua	(revision 6662)
@@ -1,11 +1,5 @@
 -- ControlsMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("ControlsMenu")
-if _REQUIREDNAME == nil then
-    ControlsMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("ControlsMenu")
 
 function P.ControlsMouseControlsButton_clicked(e)
Index: code/branches/gamestates2/data/gui/scripts/CreditsMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/CreditsMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/CreditsMenu.lua	(revision 6662)
@@ -1,11 +1,8 @@
 -- CreditsMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("CreditsMenu")
-if _REQUIREDNAME == nil then
-    CreditsMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local sheetName = _REQUIREDNAME or "CreditsMenu"
+-- Create object of type BasicGUI and make it global
+local P = require("BasicGUI"):new(sheetName)
+_G[sheetName] = P
 
 function P.CreditsBackButton_clicked(e)
Index: code/branches/gamestates2/data/gui/scripts/DecisionPopup.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/DecisionPopup.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/DecisionPopup.lua	(revision 6662)
@@ -1,11 +1,5 @@
 -- DecisionPopup.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("DecisionPopup")
-if _REQUIREDNAME == nil then
-    DecisionPopup = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("DecisionPopup")
 
 function P.setCallback(functionPtr)
Index: code/branches/gamestates2/data/gui/scripts/GUITools.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/GUITools.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/GUITools.lua	(revision 6662)
@@ -1,2 +1,9 @@
+function createSheet(sheetName)
+    -- Create object of type BasicGUI and make it global
+    local sheet = require("BasicGUI"):new(sheetName)
+    _G[sheetName] = sheet
+    return sheet
+end
+
 function openDecisionPopup( text, callbackPtr )
     showGUI("DecisionPopup", false, true)
Index: code/branches/gamestates2/data/gui/scripts/GameplayMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/GameplayMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/GameplayMenu.lua	(revision 6662)
@@ -1,13 +1,7 @@
 -- GameplayMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("GameplayMenu")
-if _REQUIREDNAME == nil then
-    GameplayMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("GameplayMenu")
 
-function P:init()
+function P.init()
     dropdown = winMgr:getWindow("orxonox/ThemeCombobox")
     local themeList = {}
@@ -24,20 +18,20 @@
 function P.GameplayThemeCombobox_changed(e)
     -- theme
-    debug("event: theme")
+    logMessage(0, "event: theme")
 end
 
 function P.GameplayDifficultyEasyButton_clicked(e)
     -- difficulty easy
-    debug("event: easy")
+    logMessage(0, "event: easy")
 end
 
 function P.GameplayDifficultyNormalButton_clicked(e)
     -- difficulty normal
-    debug("event: normal")
+    logMessage(0, "event: normal")
 end
 
 function P.GameplayDifficultyHardButton_clicked(e)
     -- difficulty hard
-    debug("event: hard")
+    logMessage(0, "event: hard")
 end
 
Index: code/branches/gamestates2/data/gui/scripts/GraphicsMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/GraphicsMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/GraphicsMenu.lua	(revision 6662)
@@ -1,13 +1,7 @@
 -- GraphicsMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("GraphicsMenu")
-if _REQUIREDNAME == nil then
-    GraphicsMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("GraphicsMenu")
 
-function P:init()
+function P.init()
     block = true
     file = orxonox.PathConfig:getConfigPathString() .. orxonox.getConfig("GraphicsManager", "ogreConfigFile_")
@@ -149,5 +143,5 @@
     if scrollbar_active == false then
         -- brightness
-        debug("event: brightness")
+        logMessage(0, "event: brightness")
     end
 end
@@ -159,5 +153,5 @@
 function P.GraphicsBrightnessScrollbar_ended(e)
     -- brightness
-    debug("event: brightness")
+    logMessage(0, "event: brightness")
     scrollbar_active = false
 end
Index: code/branches/gamestates2/data/gui/scripts/InGameMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/InGameMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/InGameMenu.lua	(revision 6662)
@@ -1,11 +1,5 @@
 -- InGameMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("InGameMenu")
-if _REQUIREDNAME == nil then
-    InGameMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("InGameMenu")
 
 -- events for ingamemenu
Index: code/branches/gamestates2/data/gui/scripts/InfoPopup.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/InfoPopup.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/InfoPopup.lua	(revision 6662)
@@ -1,12 +1,5 @@
 -- InfoPopup.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("InfoPopup")
-
-if _REQUIREDNAME == nil then
-    InfoPopup = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("InfoPopup")
 
 function P.execute(functionPtr, arguments)
Index: code/branches/gamestates2/data/gui/scripts/InitialiseGUI.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/InitialiseGUI.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/InitialiseGUI.lua	(revision 6662)
@@ -29,67 +29,108 @@
 system:setDefaultTooltip("MenuWidgets/Tooltip")
 
-loadedGUIs = {}
-cursorVisibility = {}
-activeSheets = {}
-nrOfActiveSheets = 0
-root = nil
-bShowsCursor = false
-bHidePrevious = {}
+local loadedSheets = {}
+local activeMenuSheets = {size = 0, topSheet = nil}
+--activeHUDSheets  = {size = 0, topSheet = nil}
+local root = nil
 
 -- Require all tools
 require("GUITools")
 
--- loads the GUI with the specified filename
--- be sure to set the global variable "filename" before calling this function
-function loadGUI(filename)
-    -- check if it already exists
-    loadedGui = loadedGUIs[filename]
-    if loadedGui == nil then
-        loadedGuiNS = require(filename)
-        if loadedGuiNS == nil then
+
+-----------------------
+--- Local functions ---
+-----------------------
+
+-- Loads the GUI with the specified name
+-- The name corresponds to the filename of the *.lua and *.layout files
+-- but without the extension
+local function loadSheet(name)
+    -- Check if it has already been loaded
+    local sheet = loadedSheets[name]
+    if sheet == nil then
+        -- Load the sheet
+        sheet = require(name)
+        if sheet == nil then
             return
         end
-        loadedGui = loadedGuiNS:load()
-        loadedGUIs[filename] = loadedGui
-        -- if there has no GUI been loaded yet, set new GUI as current
-        if table.getn(loadedGUIs) == 1 then
-            current = loadedGUIs[1]
-        end
-        -- hide new GUI as we do not want to show it accidentially
-        loadedGui:hide()
-    end
-    return loadedGui
-end
-
-function showGUI(filename, hidePrevious, bCursorVisible, ptr)
-    gui = showGUI(filename, hidePrevious, bCursorVisible)
+        sheet:load()
+        loadedSheets[name] = sheet
+        -- Hide new GUI as we do not want to show it accidentally
+        sheet:hide()
+    end
+    return sheet
+end
+
+local function hideCursor()
+    if cursor:isVisible() then
+        cursor:hide()
+    end
+end
+
+local function showCursor()
+    if not cursor:isVisible() and orxonox.InputManager:getInstance():isMouseExclusive() then
+        cursor:show()
+    end
+end
+
+local function find(table, value)
+    for i, v in ipairs(table) do
+        if v == value then
+            return i
+        end
+    end
+    return nil
+end
+
+
+------------------------
+--- Global functions ---
+------------------------
+
+-- ?
+function showGUI(name, bHidePrevious, bShowCursor, ptr)
+    gui = showGUI(name, bHidePrevious, bShowCursor)
     gui.overlay = ptr
 end
 
--- shows the specified GUI sheet and loads it if not loaded already
-function showGUI(filename, hidePrevious, bCursorVisible)
-    if bCursorVisible == nil then
-        if nrOfActiveSheets > 0 then
-            bCursorVisible = cursorVisibility[activeSheets[nrOfActiveSheets]]
+-- Shows the specified menu sheet and loads it if neccessary
+function showGUI(name, bHidePrevious, bShowCursor)
+    -- Handle default value for bShowCursor
+    if bShowCursor == nil then
+        if activeMenuSheets.size > 0 then
+            bShowCursor = activeMenuSheets.topSheet.bShowCursor
         else
-            bCursorVisible = true
-        end
-    end
-
-    if root == nil then
+            bShowCursor = true
+        end
+    end
+
+    -- Hide if already displayed (to make sure it is up front in the end)
+    if activeMenuSheets[name] ~= nil then
+        hideGUI(name)
+    end
+
+    if not root then
         setBackground("")
     end
 
-    local currentGUI = loadedGUIs[filename]
-    if(currentGUI == nil) then
-        currentGUI = loadGUI(filename)
-    end
-
-    if(root:isChild(currentGUI.window)) then
-        root:removeChildWindow(currentGUI.window)
-    end
-    root:addChildWindow(currentGUI.window)
-
-    if bCursorVisible then
+    -- Get sheet (or load it)
+    local menuSheet = loadSheet(name)
+    if not menuSheet then
+        return
+    end
+
+    -- Add sheet to the root window
+    root:addChildWindow(menuSheet.window)
+
+    -- Pause game control if this is the first menu to be displayed
+    -- HUGE HACK?
+    if activeMenuSheets.size == 0 then
+        orxonox.HumanController:pauseControl()
+    end
+
+    -- Handle input distribution
+    orxonox.InputManager:getInstance():enterState(menuSheet.inputState)
+
+    if bShowCursor then
         showCursor()
     else
@@ -97,103 +138,95 @@
     end
 
-    if find( activeSheets, filename ) ~= nil then
-        table.remove( activeSheets, find( activeSheets, filename ) )
-        nrOfActiveSheets = nrOfActiveSheets - 1
-    else
-        if nrOfActiveSheets == 0 then
-            --orxonox.InputManager:getInstance():enterState("guiMouseOnly")
-            orxonox.HumanController:pauseControl()
-        end
-    end
-    orxonox.InputManager:getInstance():enterState(currentGUI.inputState)
-
-    nrOfActiveSheets = nrOfActiveSheets + 1
-    table.insert(activeSheets, filename)
-    activeSheets[nrOfActiveSheets] = filename
-    bHidePrevious[filename]=hidePrevious
-    cursorVisibility[filename] = bCursorVisible
-
-    if hidePrevious == true then
-        for i=1,nrOfActiveSheets-1 do
-            loadedGUIs[ activeSheets[i] ]:hide()
-        end
-    end
-    currentGUI:show()
-    return currentGUI
-end
-
-function hideCursor()
-    if bShowsCursor==true then
-        bShowsCursor=false
-        cursor:hide()
-    end
-end
-
-function showCursor()
-    if bShowsCursor==false then
-        bShowsCursor=true
-        cursor:show()
-    end
-end
-
-function hideGUI(filename)
-    local currentGUI = loadedGUIs[filename]
-    if currentGUI == nil then
+    -- Add the sheet in a tuple of additional information
+    local sheetTuple =
+    {
+        ["menuSheet"]      = menuSheet,
+        ["name"]           = name,
+        ["bShowCursor"]    = bShowCursor,
+        ["bHidePrevious"]  = bHidePrevious
+    }
+    table.insert(activeMenuSheets, sheetTuple) -- indexed array access
+    activeMenuSheets[name] = sheetTuple -- name access
+    activeMenuSheets.size = activeMenuSheets.size + 1
+    activeMenuSheets.topSheet = sheetTuple
+
+    -- Hide all previous sheets if necessary
+    if bHidePrevious then
+        for i = 1, activeMenuSheets.size - 1 do
+            activeMenuSheets[i].menuSheet:hide()
+        end
+    end
+
+    menuSheet:show()
+    return menuSheet
+end
+
+function hideGUI(name)
+    local sheetTuple = activeMenuSheets[name]
+    if sheetTuple == nil then
         return
     end
-    currentGUI:hide()
-    if bHidePrevious[filename] == true then
-        local i = nrOfActiveSheets-1
-        while i>0 do
-            loadedGUIs[ activeSheets[i] ]:show()
-            if bHidePrevious[filename]==true then
-                break
-            else
-                i=i-1
+
+    -- Hide the sheet
+    sheetTuple.menuSheet:hide()
+
+    -- Show sheets that were hidden by the sheet to be removed
+    local i = activeMenuSheets.size
+    -- Only do something if all sheets on top of sheetTuple
+    -- have bHidePrevious == false and sheetTuple.bHidePrevious == true
+    while i > 0 do
+        if activeMenuSheets[i].bHidePrevious == true then
+            if activeMenuSheets[i] == sheetTuple then
+                i = i - 1
+                while i > 0 do
+                    activeMenuSheets[i].menuSheet:show()
+                    if activeMenuSheets[i].bHidePrevious == true then
+                        break
+                    end
+                    i = i - 1
+                end
             end
-        end
-    end
-    root:removeChildWindow(currentGUI.window)
-    local i=1
-    while activeSheets[i] do
-        if activeSheets[i+1] == nil then
-            if activeSheets[i-1] ~= nil then
-                if cursorVisibility[ activeSheets[i-1] ] == true then
-                    showCursor()
-                else
-                    hideCursor()
-                end
-            else
-                hideCursor()
-            end
-        end
-        if activeSheets[i] == filename then
-            table.remove( activeSheets, i )
-            nrOfActiveSheets = nrOfActiveSheets-1
-        else
-            i = i+1
-        end
-    end
-    cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table
-    bHidePrevious[filename] = nil
-    if nrOfActiveSheets == 0 then
-        --orxonox.InputManager:getInstance():leaveState("guiMouseOnly")
+            break
+        end
+        i = i - 1
+    end
+
+    -- Remove sheet with its tuple from the table
+    root:removeChildWindow(sheetTuple.menuSheet.window)
+    table.remove(activeMenuSheets, find(activeMenuSheets, sheetTuple))
+    activeMenuSheets[name] = nil
+    activeMenuSheets.size = activeMenuSheets.size - 1
+    activeMenuSheets.topSheet = activeMenuSheets[activeMenuSheets.size]
+
+    -- Leave the input state
+    orxonox.InputManager:getInstance():leaveState(sheetTuple.menuSheet.inputState)
+    
+    -- See whether to show or hide cursor
+    if activeMenuSheets.size > 0 and activeMenuSheets.topSheet.bShowCursor then
+        showCursor()
+    else
+        hideCursor()
+    end
+
+    -- Resume control if the last menu is hidden
+    if activeMenuSheets.size == 0 then
         orxonox.HumanController:resumeControl()
         hideCursor()
     end
-    orxonox.InputManager:getInstance():leaveState(currentGUI.inputState)
-end
-
+end
+
+-- Hides all menu GUI sheets
 function hideAllGUIs()
-    while nrOfActiveSheets ~= 0 do
-        hideGUI(activeSheets[nrOfActiveSheets])
+    while activeMenuSheets.size ~= 0 do
+        hideGUI(activeMenuSheets.topSheet.name)
     end
 end
 
 function keyESC()
-    if nrOfActiveSheets == 1 and activeSheets[1] == "MainMenu" then
+    -- HUGE, very HUGE hacks!
+    if activeMenuSheets.size == 1 and activeMenuSheets[1].name == "MainMenu" then
         orxonox.execute("exit")
-    elseif nrOfActiveSheets > 0 then
-        orxonox.execute("hideGUI "..activeSheets[nrOfActiveSheets])
+    elseif activeMenuSheets.size > 0 then
+        orxonox.execute("hideGUI "..activeMenuSheets.topSheet.name)
     else
         showGUI("InGameMenu")
@@ -201,11 +234,11 @@
 end
 
-function setBackground(filename)
+function setBackground(name)
     local newroot
     if root ~= nil then
         root:rename("oldRootWindow")
     end
-    if filename ~= "" then
-        newroot = winMgr:loadWindowLayout(filename .. ".layout")
+    if name ~= "" then
+        newroot = winMgr:loadWindowLayout(name .. ".layout")
         newroot:rename("AbsoluteRootWindow")
         system:setGUISheet(newroot)
@@ -228,18 +261,2 @@
     root = newroot
 end
-
-function find(table, value)
-    local i=0
-    while table[i] ~= nil do
-        if table[i]==value then
-            return i
-        else
-            i=i+1
-        end
-    end
-    return nil
-end
-
-function test(e)
-    debug(0, "Blubb")
-end
Index: code/branches/gamestates2/data/gui/scripts/KeyBindMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/KeyBindMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/KeyBindMenu.lua	(revision 6662)
@@ -1,14 +1,7 @@
 -- KeyBindMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("KeyBindMenu")
-
-if _REQUIREDNAME == nil then
-    KeyBindMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
-
-function P:init()
+local P = createSheet("KeyBindMenu")
+
+function P.init()
 
     commandList = {}
Index: code/branches/gamestates2/data/gui/scripts/MainMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/MainMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/MainMenu.lua	(revision 6662)
@@ -1,11 +1,5 @@
 -- MainMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("MainMenu")
-if _REQUIREDNAME == nil then
-    MainMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("MainMenu")
 
 -- events for MainMenu
Index: code/branches/gamestates2/data/gui/scripts/MouseControlsMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/MouseControlsMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/MouseControlsMenu.lua	(revision 6662)
@@ -1,13 +1,7 @@
 -- MouseControlsMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("MouseControlsMenu")
-if _REQUIREDNAME == nil then
-    MouseControlsMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("MouseControlsMenu")
 
-function P:init()
+function P.init()
     block = false
     mousenormalscrollbarwindow = tolua.cast(winMgr:getWindow("orxonox/MouseNormalScrollbar"),"CEGUI::Scrollbar")
Index: code/branches/gamestates2/data/gui/scripts/MultiplayerMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/MultiplayerMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/MultiplayerMenu.lua	(revision 6662)
@@ -1,13 +1,7 @@
 -- MultiplayerMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("MultiplayerMenu")
-if _REQUIREDNAME == nil then
-    MultiplayerMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("MultiplayerMenu")
 
-function P:init()
+function P.init()
     listbox = winMgr:getWindow("orxonox/MultiplayerLevelListbox")
     preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
Index: code/branches/gamestates2/data/gui/scripts/MultiplayerOptionsMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/MultiplayerOptionsMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/MultiplayerOptionsMenu.lua	(revision 6662)
@@ -1,11 +1,5 @@
 -- MultiplayerOptionsMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("MultiplayerOptionsMenu")
-if _REQUIREDNAME == nil then
-    MultiplayerOptionsMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("MultiplayerOptionsMenu")
 
 function P.MultiplayerOptionsBackButton_clicked(e)
Index: code/branches/gamestates2/data/gui/scripts/PickupInventory.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/PickupInventory.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/PickupInventory.lua	(revision 6662)
@@ -1,11 +1,5 @@
 -- PickupInventory.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("PickupInventory")
-if _REQUIREDNAME == nil then
-    PickupInventory = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("PickupInventory")
 
 P.lastEquipmentCount_ = 0
@@ -14,10 +8,10 @@
 
 -- events
-function P:frmUpdate(e)
+function P.frmUpdate(e)
     local equipCount = orxonox.PickupInventory:getEquipmentCount()
     local usableCount = orxonox.PickupInventory:getUsableCount()
 
-    if equipCount ~= self.lastEquipmentCount_ or usableCount ~= self.lastUsableCount_ then
-        self:updateTabs()
+    if equipCount ~= P.lastEquipmentCount_ or usableCount ~= P.lastUsableCount_ then
+        P.updateTabs()
     end
 end
@@ -31,5 +25,5 @@
 end
 
-function P:mItemClicked(e)
+function P.mItemClicked(e)
     local w = CEGUI.toWindowEventArgs(e).window
     local name = w:getName()
@@ -42,9 +36,9 @@
 
     if t == "use" then
-        if self.currentUsableID_ >= 0 then
-            winMgr:getWindow("orxonox/Inventory/Title/use/" .. self.currentUsableID_):setProperty("TextColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF")
+        if P.currentUsableID_ >= 0 then
+            winMgr:getWindow("orxonox/Inventory/Title/use/" .. P.currentUsableID_):setProperty("TextColours", "tl:FFFFFFFF tr:FFFFFFFF bl:FFFFFFFF br:FFFFFFFF")
         end
         orxonox.PickupInventory:selectUsable(tonumber(i))
-        self.currentUsableID_ = tonumber(i)
+        P.currentUsableID_ = tonumber(i)
         winMgr:getWindow("orxonox/Inventory/Title/use/" .. i):setProperty("TextColours", "tl:FFFF4444 tr:FFFF4444 bl:FFFF4444 br:FFFF4444")
     end
@@ -52,5 +46,5 @@
 
 -- methods
-function P:updateTabs()
+function P.updateTabs()
     local eqWin = winMgr:getWindow("orxonox/Inventory/TabControl/TabEquipment")
     local usWin = winMgr:getWindow("orxonox/Inventory/TabControl/TabUsable")
@@ -58,7 +52,7 @@
     orxonox.PickupInventory:getSingleton():updateTabs(winMgr, eqWin, usWin)
 
-    self.currentUsableID_ = orxonox.PickupInventory:getCurrentUsableIndex()
-    self.lastEquipmentCount_ = orxonox.PickupInventory:getEquipmentCount()
-    self.lastUsableCount_ = orxonox.PickupInventory:getUsableCount()
+    P.currentUsableID_ = orxonox.PickupInventory:getCurrentUsableIndex()
+    P.lastEquipmentCount_ = orxonox.PickupInventory:getEquipmentCount()
+    P.lastUsableCount_ = orxonox.PickupInventory:getUsableCount()
 end
 
Index: code/branches/gamestates2/data/gui/scripts/QuestGUI.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/QuestGUI.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/QuestGUI.lua	(revision 6662)
@@ -1,13 +1,9 @@
-gui = require("BasicGUI")
-local P = BasicGUI:new("QuestGUI")
-if _REQUIREDNAME == nil then
-    QuestGUI = P
-else
-    _G[_REQUIREDNAME] = P
-end
+-- QuestGUI.lua
 
-function P:show()
-    self.window:show() -- TDO: Do this through parent...
-    self.visible = true
+local P = createSheet("QuestGUI")
+
+function P.show()
+    P.window:show() -- TDO: Do this through parent...
+    P.visible = true
 
     local questManager = orxonox.QuestManager:getInstance()
Index: code/branches/gamestates2/data/gui/scripts/SettingsMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/SettingsMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/SettingsMenu.lua	(revision 6662)
@@ -1,11 +1,5 @@
 -- SettingsMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("SettingsMenu")
-if _REQUIREDNAME == nil then
-    SettingsMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("SettingsMenu")
 
 function P.SettingsGameplayButton_clicked(e)
@@ -31,5 +25,5 @@
 function P.SettingsResetSettingsButton_clicked(e)
     -- reset settings
-    debug("event: reset settings")
+    logMessage(0, "event: reset settings")
 end
 
Index: code/branches/gamestates2/data/gui/scripts/SingleplayerMenu.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/SingleplayerMenu.lua	(revision 6595)
+++ code/branches/gamestates2/data/gui/scripts/SingleplayerMenu.lua	(revision 6662)
@@ -1,13 +1,7 @@
 -- SingleplayerMenu.lua
 
-BasicGUI = require("BasicGUI")
-local P = BasicGUI:new("SingleplayerMenu")
-if _REQUIREDNAME == nil then
-    SingleplayerMenu = P
-else
-    _G[_REQUIREDNAME] = P
-end
+local P = createSheet("SingleplayerMenu")
 
-function P:init()
+function P.init()
     listbox = winMgr:getWindow("orxonox/SingleplayerLevelListbox")
     preselect = orxonox.LevelManager:getInstance():getDefaultLevel()
