Index: data/media/gui/scripts/loadGUI.lua
===================================================================
--- data/media/gui/scripts/loadGUI.lua	(revision 5414)
+++ data/media/gui/scripts/loadGUI.lua	(revision 5427)
@@ -3,74 +3,86 @@
 local logger = CEGUI.Logger:getSingleton()
 local system = CEGUI.System:getSingleton()
+local cursor = CEGUI.MouseCursor:getSingleton()
 
 schemeMgr:loadScheme("TaharezLookSkin.scheme")
+-- load scheme with our own images
+schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
+
 system:setDefaultMouseCursor("TaharezLook", "MouseArrow")
 system:setDefaultFont("BlueHighway-12")
 
+local current = nil
+local loadedGUIs = {}
+local showing
+-- we cannot directly call functions with parameters and so need this as a global variable, which sucks of course
+filename = ""
+datapath = "" -- points to media-folder (set after loading the script)
 
-local mainmenu =  winMgr:loadWindowLayout("MainMenu.layout")
-
-local backgroundImage = CEGUI.ImagesetManager:getSingleton():createImagesetFromImageFile("GUI/Background", "main_menu_1.jpg")
-local background = winMgr:createWindow("TaharezLook/StaticImage", "orxonox/Background")
-background:setProperty("FrameEnabled", "set: true")
-background:setProperty("BackgroundEnabled", "set: false")
-background:setProperty("Image", "set: GUI/Background image:full_image")
-
-background:addChildWindow(mainmenu)
-
-
-function button_quit_clicked(e)
-  hideGUI()
-  orxonox.CommandExecutor:execute("exit")
+-- function to add a reference to list of reference of loaded GUIs
+loadedGUIs.addGUI = function (gui)
+    loadedGUIs[#loadedGUIs+1] = gui
 end
 
-function button_standalone_clicked(e)
-  orxonox.CommandExecutor:execute("selectGameState standalone")
-  hideGUI()
+-- function which returns a GUI by name
+loadedGUIs.getGUIbyName = function (str)
+    for i = 1, #loadedGUIs, 1 do
+        if str == loadedGUIs[i].filename then
+            return loadedGUIs[i]
+        end
+    end
+    return nil
 end
 
-function button_server_clicked(e)
-  orxonox.CommandExecutor:execute("selectGameState server")
-  hideGUI()
+-- loads the GUI with the specified filename
+-- be sure to set the global variable "filename" before calling this function
+function loadGUI()
+    -- check if it already exists
+    newlyLoaded = loadedGUIs:getGUIbyName(filename)
+    if newlyLoaded == nil then
+        dofile(datapath .. "gui/scripts/" .. filename)
+        newlyLoaded = winMgr:loadWindowLayout(layoutPath)
+        newlyLoaded.filename = filename
+        loadedGUIs:addGUI(newlyLoaded)
+        -- if there has no GUI been loaded yet, set new GUI as current
+        if #loadedGUIs == 1 then
+            current = loadedGUIs[1]
+            showing = false
+        end
+        -- hide new GUI as we do not want to show it accidentially
+        newlyLoaded:hide()
+    end
+    return newlyLoaded
 end
 
-function button_dedicated_clicked(e)
-  orxonox.CommandExecutor:execute("selectGameState dedicated")
-  hideGUI()
+-- shows the specified and loads it if not loaded already
+-- be sure to set the global variable "filename" before calling this function
+function showGUI()
+    if current == nil or current.filename ~= filename then
+        current = loadedGUIs.getGUIbyName(filename)
+        if current == nil then
+            current = loadGUI(filename)
+        end
+        system:setGUISheet(current)
+    end
+    current:show()
+    cursor:show()
+    showing = true
 end
-
-function button_client_clicked(e)
-  orxonox.CommandExecutor:execute("selectGameState client")
-  hideGUI()
-end
-
-showBackground = true
-
-function showMainMenu()
-  if showBackground == true then
-    system:setGUISheet(background)
-  else
-    orxonox.GUIManager:getInstance():testOutput("set new Menu")
-    system:setGUISheet(mainmenu)
-  end
-  return 0;
-end
-
-showing = true
 
 function toggleGUI()
     if showing == true then
-        mainmenu:hide()
+        current:hide()
+        cursor:hide()
         showing = false
-        orxonox.GUIManager:getInstance():testOutput("hiding Menu")
     else
-        mainmenu:show()
+        current:show()
+        cursor:show()
         showing = true
-        orxonox.GUIManager:getInstance():testOutput("showing Menu")
     end
+    return showing
 end
 
 function hideGUI()
-  --system:setGUISheet(nil)
-  --orxonox.GUIManager:getInstance():hideGUI()
+    current:hide()
+    showing = false
 end
