Index: code/branches/gamestates2/data/gui/scripts/SheetManager.lua
===================================================================
--- code/branches/gamestates2/data/gui/scripts/InitialiseGUI.lua	(revision 6722)
+++ code/branches/gamestates2/data/gui/scripts/SheetManager.lua	(revision 6737)
@@ -1,40 +1,8 @@
-winMgr   = CEGUI.WindowManager:getSingleton()
-guiMgr   = orxonox.GUIManager:getInstance()
-inputMgr = orxonox.InputManager:getInstance()
+-- SheetManager.lua
 
-local schemeMgr = CEGUI.SchemeManager:getSingleton()
-local system    = CEGUI.System:getSingleton()
-local cursor    = CEGUI.MouseCursor:getSingleton()
-
--- Load all required skins
-schemeMgr:loadScheme("TaharezGreenLook.scheme")
---schemeMgr:loadScheme("TaharezLook.scheme")
---schemeMgr:loadScheme("WindowsLook.scheme")
---schemeMgr:loadScheme("VanillaLook.scheme")
---schemeMgr:loadScheme("SleekSpaceLook.scheme")
-
--- Connect skin specific window types with our own window types
--- By loading a different file (if there is) you can change the skin
--- of the menus or the HUD independently
-schemeMgr:loadScheme("TaharezGreenMenuWidgets.scheme")
-menuImageSet = "TaharezGreenLook"
-schemeMgr:loadScheme("TaharezGreenHUDWidgets.scheme")
-hudImageSet = "TaharezGreenLook"
-
--- Just a remaining test hack
-schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
-
-system:setDefaultMouseCursor(menuImageSet, "MouseArrow")
-system:setDefaultFont("BlueHighway-12")
-system:setDefaultTooltip("MenuWidgets/Tooltip")
-
+local cursor = CEGUI.MouseCursor:getSingleton()
 local loadedSheets = {}
 local activeMenuSheets = {size = 0, topSheetTuple = nil}
---activeHUDSheets  = {size = 0, topSheetTuple = nil}
-local root = nil
-
--- Require all tools
-require("GUITools")
-
+local menuSheetsRoot = guiMgr:getMenuRootWindow()
 
 -----------------------
@@ -42,8 +10,25 @@
 -----------------------
 
+local function hideCursor()
+    if cursor:isVisible() then
+        cursor:hide()
+    end
+end
+
+local function showCursor()
+    if not cursor:isVisible() and inputMgr:isMouseExclusive() then
+        cursor:show()
+    end
+end
+
+
+------------------------
+--- Global 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)
+function loadSheet(name)
     -- Check if it has already been loaded
     local sheet = loadedSheets[name]
@@ -57,21 +42,4 @@
 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
-
-
-------------------------
---- Global functions ---
-------------------------
-
 -- ?
 function showMenuSheet(name, bHidePrevious, ptr)
@@ -83,9 +51,9 @@
 -- Shows the specified menu sheet and loads it if neccessary
 function showMenuSheet(name, bHidePrevious)
+    if name == "" then
+        return nil
+    end
     -- Get sheet (or load it)
     local menuSheet = loadSheet(name)
-    if not menuSheet then
-        return nil
-    end
 
     -- Use sheet's value if nil was provided
@@ -117,13 +85,9 @@
     activeMenuSheets.topSheetTuple = sheetTuple
 
-    if not root then
-        setBackground("")
-    end
-
     -- Add sheet to the root window
-    root:addChildWindow(menuSheet.window)
+    menuSheetsRoot:addChildWindow(menuSheet.window)
 
     -- Handle input distribution
-    orxonox.InputManager:getInstance():enterState(menuSheet.inputState)
+    inputMgr:enterState(menuSheet.inputState)
 
     -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare
@@ -177,5 +141,5 @@
 
     -- Remove sheet with its tuple from the table
-    root:removeChildWindow(sheetTuple.sheet.window)
+    menuSheetsRoot:removeChildWindow(sheetTuple.sheet.window)
     table.remove(activeMenuSheets, table.findIndex(activeMenuSheets, sheetTuple))
     activeMenuSheets[name] = nil
@@ -184,5 +148,5 @@
 
     -- Leave the input state
-    orxonox.InputManager:getInstance():leaveState(sheetTuple.sheet.inputState)
+    inputMgr:leaveState(sheetTuple.sheet.inputState)
     
     -- CURSOR SHOWING
@@ -223,29 +187,11 @@
 end
 
-function setBackground(name)
-    local newroot
-    if root ~= nil then
-        root:rename("oldRootWindow")
-    end
-    if name ~= "" then
-        newroot = winMgr:loadWindowLayout(name .. ".layout")
-        newroot:rename("AbsoluteRootWindow")
-        system:setGUISheet(newroot)
-    else
-        newroot = winMgr:createWindow("DefaultWindow", "AbsoluteRootWindow")
-        newroot:setProperty("Alpha", "0.0")
-        newroot:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))
-        system:setGUISheet(newroot)
-    end
-    if root ~= nil then
-        local child
-        while root:getChildCount()~=0 do
-            child = root:getChildAtIdx(0)
-            root:removeChildWindow(child)
-            newroot:addChildWindow(child)
-        end
-        winMgr:destroyWindow(root)
-    end
-    newroot:show()
-    root = newroot
+function setBackgroundImage(imageSet, imageName)
+    guiMgr:setBackgroundImage(imageSet, imageName)
 end
+
+----------------------
+--- Initialisation ---
+----------------------
+
+hideCursor()
