[Orxonox-commit 159] r2052 - in media/gui: imagesets layouts schemes scripts

bknecht at orxonox.net bknecht at orxonox.net
Wed Mar 25 11:13:58 CET 2009


Author: bknecht
Date: 2009-03-25 10:13:58 +0000 (Wed, 25 Mar 2009)
New Revision: 2052

Added:
   media/gui/imagesets/MainMenuBackground.imageset
   media/gui/schemes/OrxonoxGUIScheme.scheme
   media/gui/scripts/mainmenu.lua
Modified:
   media/gui/layouts/MainMenu.layout
   media/gui/scripts/loadGUI.lua
Log:
CEGUI code structure is now set. Images are loaded into imagesets(XML), those are loaded via schemes(XML), which are loaded in lua scripts. Each gui should now be able to be loaded via a seperate lua-script which itself loads its own layout(XML).

Added: media/gui/imagesets/MainMenuBackground.imageset
===================================================================
--- media/gui/imagesets/MainMenuBackground.imageset	                        (rev 0)
+++ media/gui/imagesets/MainMenuBackground.imageset	2009-03-25 10:13:58 UTC (rev 2052)
@@ -0,0 +1,4 @@
+<?xml version="1.0" ?>
+<Imageset Name="MainMenuBackground" Imagefile="main_menu_1.jpg" NativeHorzRes="1400" NativeVerzRes="1050" AutoScaled="true">
+    <Image Name="Background" XPos="0" YPos="0" Width="1400" Height="1050"/>
+</Imageset>

Modified: media/gui/layouts/MainMenu.layout
===================================================================
--- media/gui/layouts/MainMenu.layout	2009-03-25 02:26:43 UTC (rev 2051)
+++ media/gui/layouts/MainMenu.layout	2009-03-25 10:13:58 UTC (rev 2052)
@@ -1,41 +1,42 @@
 <?xml version="1.0" ?>
 <GUILayout>
-    <Window Type="DefaultGUISheet" Name="orxonox/RootSheet">
+    <Window Type="TaharezLook/StaticImage" Name="orxonox/Background">
+    <Property Name="UnifiedSize" Value="{{1.0,0},{1.0,0}}"/>
+    <Property Name="Image" Value="set:MainMenuBackground image:Background"/>
+    
         <Window Type="TaharezLook/Button" Name="orxonox/StandaloneButton">
             <Property Name="UnifiedPosition" Value="{{0.11,0},{0.3,0}}"/>
             <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
             <Property Name="Text" Value="Standalone"/>
             <Event Name="Clicked" Function="button_standalone_clicked"/>
         </Window>
+        
         <Window Type="TaharezLook/Button" Name="orxonox/DedicatedButton">
             <Property Name="UnifiedPosition" Value="{{0.11,0},{0.376,0}}"/>
             <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
             <Property Name="Text" Value="Dedicated"/>
             <Event Name="Clicked" Function="button_dedicated_clicked"/>
         </Window>
+        
         <Window Type="TaharezLook/Button" Name="orxonox/ServerButton">
             <Property Name="UnifiedPosition" Value="{{0.11,0},{0.452,0}}"/>
             <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
             <Property Name="Text" Value="Server"/>
             <Event Name="Clicked" Function="button_server_clicked"/>
         </Window>
+        
         <Window Type="TaharezLook/Button" Name="orxonox/ClientButton">
             <Property Name="UnifiedPosition" Value="{{0.11,0},{0.528,0}}"/>
             <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
             <Property Name="Text" Value="Client"/>
             <Event Name="Clicked" Function="button_client_clicked"/>
         </Window>
+        
         <Window Type="TaharezLook/Button" Name="orxonox/QuitButton">
             <Property Name="UnifiedPosition" Value="{{0.11,0},{0.528,0}}"/>
             <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
             <Property Name="Text" Value="Quit"/>
             <Event Name="Clicked" Function="button_quit_clicked"/>
         </Window>
-        <Window Type="TaharezLook/Button" Name="orxonox/TestButton">
-            <Property Name="UnifiedPosition" Value="{{0.11,0},{0.604,0}}"/>
-            <Property Name="UnifiedSize" Value="{{0.15,0},{0.05,0}}"/>
-            <Property Name="Text" Value="Hide"/>
-            <Event Name="Clicked" Function="toggleGUI"/>
-        </Window>
     </Window>
 </GUILayout>

Added: media/gui/schemes/OrxonoxGUIScheme.scheme
===================================================================
--- media/gui/schemes/OrxonoxGUIScheme.scheme	                        (rev 0)
+++ media/gui/schemes/OrxonoxGUIScheme.scheme	2009-03-25 10:13:58 UTC (rev 2052)
@@ -0,0 +1,4 @@
+<?xml version="1.0" ?>
+<OrxonoxGUIScheme Name="OrxonoxGUI">
+    <Imageset Name="MainMenuBackground" Filename="MainMenuBackground.imageset" ResourceGroup="General"/>
+</OrxonoxGUIScheme>

Modified: media/gui/scripts/loadGUI.lua
===================================================================
--- media/gui/scripts/loadGUI.lua	2009-03-25 02:26:43 UTC (rev 2051)
+++ media/gui/scripts/loadGUI.lua	2009-03-25 10:13:58 UTC (rev 2052)
@@ -1,76 +1,88 @@
 local schemeMgr = CEGUI.SchemeManager:getSingleton()
 local winMgr = CEGUI.WindowManager:getSingleton()
 local logger = CEGUI.Logger:getSingleton()
-local system = CEGUI.System:getSingleton()
+local system = CEGUI.System:getSingleton()
+local cursor = CEGUI.MouseCursor:getSingleton()
 
-schemeMgr:loadScheme("TaharezLookSkin.scheme")
+schemeMgr:loadScheme("TaharezLookSkin.scheme")
+-- load scheme with our own images
+schemeMgr:loadScheme("OrxonoxGUIScheme.scheme")
+
 system:setDefaultMouseCursor("TaharezLook", "MouseArrow")
 system:setDefaultFont("BlueHighway-12")
-
 
-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")
+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)
+
+-- function to add a reference to list of reference of loaded GUIs
+loadedGUIs.addGUI = function (gui)
+    loadedGUIs[#loadedGUIs+1] = gui
+end
+
+-- 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_standalone_clicked(e)
-  orxonox.CommandExecutor:execute("selectGameState standalone")
-  hideGUI()
-end
-
-function button_server_clicked(e)
-  orxonox.CommandExecutor:execute("selectGameState server")
-  hideGUI()
-end
-
-function button_dedicated_clicked(e)
-  orxonox.CommandExecutor:execute("selectGameState dedicated")
-  hideGUI()
-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;
+
+-- 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
 
-showing = true
+-- 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 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()
+function hideGUI()
+    current:hide()
+    showing = false
 end

Added: media/gui/scripts/mainmenu.lua
===================================================================
--- media/gui/scripts/mainmenu.lua	                        (rev 0)
+++ media/gui/scripts/mainmenu.lua	2009-03-25 10:13:58 UTC (rev 2052)
@@ -0,0 +1,27 @@
+layoutPath = "MainMenu.layout"
+
+-- events for mainmenu
+function button_quit_clicked(e)
+  hideGUI()
+  orxonox.CommandExecutor:execute("exit")
+end
+
+function button_standalone_clicked(e)
+  orxonox.CommandExecutor:execute("selectGameState standalone")
+  toggleGUI()
+end
+
+function button_server_clicked(e)
+  orxonox.CommandExecutor:execute("selectGameState server")
+  hideGUI()
+end
+
+function button_dedicated_clicked(e)
+  orxonox.CommandExecutor:execute("selectGameState dedicated")
+  hideGUI()
+end
+
+function button_client_clicked(e)
+  orxonox.CommandExecutor:execute("selectGameState client")
+  hideGUI()
+end




More information about the Orxonox-commit mailing list