[Orxonox-commit 1314] r6032 - in code/branches/menu: data/gui/layouts data/gui/scripts src/libraries/core src/orxonox/gamestates

scheusso at orxonox.net scheusso at orxonox.net
Wed Nov 4 17:30:38 CET 2009


Author: scheusso
Date: 2009-11-04 17:30:38 +0100 (Wed, 04 Nov 2009)
New Revision: 6032

Modified:
   code/branches/menu/data/gui/layouts/MainMenu.layout
   code/branches/menu/data/gui/scripts/InitialiseGUI.lua
   code/branches/menu/src/libraries/core/GUIManager.cc
   code/branches/menu/src/libraries/core/GUIManager.h
   code/branches/menu/src/orxonox/gamestates/GSMainMenu.cc
Log:
partially working hiding


Modified: code/branches/menu/data/gui/layouts/MainMenu.layout
===================================================================
--- code/branches/menu/data/gui/layouts/MainMenu.layout	2009-11-04 15:03:03 UTC (rev 6031)
+++ code/branches/menu/data/gui/layouts/MainMenu.layout	2009-11-04 16:30:38 UTC (rev 6032)
@@ -1,12 +1,7 @@
 <?xml version="1.0" ?>
 <GUILayout>
-    <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"/>
-    <Property Name="FrameEnabled" Value="set:true"/>
-    <Property Name="BackgroundEnabled" Value="set:false"/>
-    <Property Name="InheritsAlpha" Value="False" />
- 
+    <Window Type="DefaultWindow" Name="orxonox/MainMenuRootWindow">
+    <Property Name="InheritsAlpha" Value="false"/>
         <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}}"/>

Modified: code/branches/menu/data/gui/scripts/InitialiseGUI.lua
===================================================================
--- code/branches/menu/data/gui/scripts/InitialiseGUI.lua	2009-11-04 15:03:03 UTC (rev 6031)
+++ code/branches/menu/data/gui/scripts/InitialiseGUI.lua	2009-11-04 16:30:38 UTC (rev 6032)
@@ -18,6 +18,7 @@
 nrOfActiveSheets = 0
 root = nil
 bShowsCursor = false
+bHidePrevious = {}
 
 -- loads the GUI with the specified filename
 -- be sure to set the global variable "filename" before calling this function
@@ -31,7 +32,6 @@
         -- if there has no GUI been loaded yet, set new GUI as current
         if table.getn(loadedGUIs) == 1 then
             current = loadedGUIs[1]
-            showing = false
         end
         -- hide new GUI as we do not want to show it accidentially
         loadedGui:hide()
@@ -39,24 +39,20 @@
     return loadedGui
 end
 
-function showGUI(filename, bCursorVisible, ptr)
-    gui = showGUI(filename, bCursorVisible)
+function showGUI(filename, hidePrevious, bCursorVisible, ptr)
+    gui = showGUI(filename, hidePrevious, bCursorVisible)
     gui.overlay = ptr
 end
 
 -- shows the specified and loads it if not loaded already
 -- be sure to set the global variable "filename" before calling this function
-function showGUI(filename, bCursorVisible)
---     bCursorVisibile=false
+function showGUI(filename, hidePrevious, bCursorVisible)
     if bCursorVisible == nil then
-        cursorVisibility= true
+        bCursorVisible = true
     end
 
     if root == nil then
-        root = winMgr:createWindow("TaharezLook/StaticImage", "AbsoluteRootWindow")
-        root:setProperty("Alpha", "0.0")
-        root:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))
-        system:setGUISheet(root)
+        setBackground("")
     end
 
     local currentGUI = loadedGUIs[filename]
@@ -64,7 +60,11 @@
         currentGUI = loadGUI(filename)
     end
 
+    debug("test")
+    debug(currentGUI.window:getName())
+    debug(root:isChild(currentGUI.window))
     if(root:isChild(currentGUI.window)) then
+        debug("removing window")
         root:removeChildWindow(currentGUI.window)
     end
     root:addChildWindow(currentGUI.window)
@@ -74,14 +74,23 @@
     else
         hideCursor()
     end
-    cursorVisibility[filename]=bCursorVisible
     
+    if find( activeSheets, filename ) ~= nil then
+        table.remove( activeSheets, find( activeSheets, filename ) )
+        nrOfActiveSheets = nrOfActiveSheets - 1
+    end
     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()
-    showing = true
     return currentGUI
 end
 
@@ -105,9 +114,19 @@
         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
+            end
+        end
+    end
     root:removeChildWindow(currentGUI.window)
-    showing = false
-    i=1
+    local i=1
     while activeSheets[i] do
         if activeSheets[i+1] == nil then
             if activeSheets[i-1] ~= nil then
@@ -128,4 +147,45 @@
         end
     end
     cursorVisibility[filename] = nil -- remove the cursor visibility of the current gui from the table
+    bHidePrevious[filename] = nil
 end
+
+function setBackground(filename)
+    local newroot
+    if root ~= nil then
+        root:rename("oldRootWindow")
+    end
+    if filename ~= "" then
+        newroot = winMgr:loadWindowLayout(filename .. ".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
+        for i=0,root:getChildCount()-1 do
+            child = root:getChildAtIdx(i)
+            root:removeChildWindow(child)
+            newroot:addChildWindow(child)
+        end
+        winMgr:destroyWindow(root)
+    end
+    newroot:show()
+    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

Modified: code/branches/menu/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/menu/src/libraries/core/GUIManager.cc	2009-11-04 15:03:03 UTC (rev 6031)
+++ code/branches/menu/src/libraries/core/GUIManager.cc	2009-11-04 16:30:38 UTC (rev 6032)
@@ -88,7 +88,7 @@
 
     GUIManager* GUIManager::singletonPtr_s = 0;
 
-    SetConsoleCommandShortcut(GUIManager, showGUI).accessLevel(AccessLevel::User).defaultValue(1, true);
+    SetConsoleCommandShortcut(GUIManager, showGUI).accessLevel(AccessLevel::User).defaultValue(1, false).defaultValue(2, true);
     SetConsoleCommandShortcut(GUIManager, hideGUI).accessLevel(AccessLevel::User);
 
     /**
@@ -209,7 +209,7 @@
         The function executes the Lua function with the same name in case the GUIManager is ready.
         For more details check out loadGUI_2.lua where the function presides.
     */
-    /*static*/ void GUIManager::showGUI(const std::string& name, bool showCursor)
+    /*static*/ void GUIManager::showGUI(const std::string& name, bool hidePrevious, bool showCursor)
     {
         std::pair<std::set<std::string>::iterator,bool> result = GUIManager::getInstance().showingGUIs_.insert(name);
         if(result.second == false) //!< GUI already showing.
@@ -219,14 +219,15 @@
 //             GUIManager::getInstance().executeCode("showCursor()");
             InputManager::getInstance().enterState("guiMouseOnly");
         }
-        GUIManager::getInstance().executeCode("showGUI(\"" + name + "\", " + multi_cast<std::string>(showCursor) + ")");
+        COUT(0) << "showGUI" << endl;
+        GUIManager::getInstance().executeCode("showGUI(\"" + name + "\", " + multi_cast<std::string>(hidePrevious) + ", " + multi_cast<std::string>(showCursor) + ")");
     }
 
     /**
     @brief
         Hack-ish. Needed for GUIOverlay.
     */
-    void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool showCursor)
+    void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool hidePrevious, bool showCursor)
     {
         std::pair<std::set<std::string>::iterator,bool> result = this->showingGUIs_.insert(name);
         if(result.second == false) //!< GUI already showing.
@@ -236,7 +237,7 @@
             this->executeCode("showCursor()");
             InputManager::getInstance().enterState("guiMouseOnly");
         }
-        this->executeCode("showGUI(\"" + name + "\", " + multi_cast<std::string>(showCursor) + ", " + ptr + ")");
+        this->executeCode("showGUI(\"" + name + "\", " + multi_cast<std::string>(hidePrevious) + ", " + multi_cast<std::string>(showCursor) + ", " + ptr + ")");
     }
 
     /**
@@ -257,6 +258,17 @@
             InputManager::getInstance().leaveState("guiMouseOnly");
         }
     }
+    
+    void GUIManager::setToggleMode(const bool& mode)
+    {
+        this->bToggleMode_ = mode;
+        this->executeCode("setToggleMode(" + multi_cast<std::string>(mode) + ")");
+    }
+    
+    void GUIManager::setBackground(const std::string& name)
+    {
+        this->executeCode("setBackground(\"" + name + "\")");
+    }
 
     void GUIManager::keyPressed(const KeyEvent& evt)
     {

Modified: code/branches/menu/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/menu/src/libraries/core/GUIManager.h	2009-11-04 15:03:03 UTC (rev 6031)
+++ code/branches/menu/src/libraries/core/GUIManager.h	2009-11-04 16:30:38 UTC (rev 6032)
@@ -67,9 +67,11 @@
 
         void update(const Clock& time); 
 
-        static void showGUI(const std::string& name, bool showCursor=true);
-        void showGUIExtra(const std::string& name, const std::string& ptr, bool showCursor=true);
+        static void showGUI(const std::string& name, bool hidePrevious=false, bool showCursor=true);
+        void showGUIExtra(const std::string& name, const std::string& ptr, bool hidePrevious=false, bool showCursor=true);
         static void hideGUI(const std::string& name);
+        void setToggleMode(const bool& mode);
+        void setBackground(const std::string& name);
 
         void setCamera(Ogre::Camera* camera);
         Ogre::Camera* getCamera() { return this->camera_; }
@@ -110,6 +112,7 @@
         Ogre::Camera*                        camera_;           //!< Camera used to render the scene with the GUI
 
         static GUIManager*                   singletonPtr_s;    //!< Singleton reference to GUIManager
+        bool                                 bToggleMode_;
 
     };
 }

Modified: code/branches/menu/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/menu/src/orxonox/gamestates/GSMainMenu.cc	2009-11-04 15:03:03 UTC (rev 6031)
+++ code/branches/menu/src/orxonox/gamestates/GSMainMenu.cc	2009-11-04 16:30:38 UTC (rev 6032)
@@ -81,8 +81,10 @@
     void GSMainMenu::activate()
     {
         // show main menu
-        GUIManager::getInstance().showGUI("MainMenu", false);
+        GUIManager::getInstance().showGUI("MainMenu", true, false);
         GUIManager::getInstance().setCamera(this->camera_);
+        GUIManager::getInstance().setBackground("MainMenuBackground");
+//         GUIManager::getInstance().setBackground("");
         GraphicsManager::getInstance().setCamera(this->camera_);
 
         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSMainMenu::startStandalone), "startGame"));
@@ -112,6 +114,7 @@
         InputManager::getInstance().leaveState("mainMenu");
 
         GUIManager::getInstance().setCamera(0);
+        GUIManager::getInstance().setBackground("");
         GUIManager::hideGUI("MainMenu");
         GraphicsManager::getInstance().setCamera(0);
     }




More information about the Orxonox-commit mailing list