Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 6003


Ignore:
Timestamp:
Oct 28, 2009, 5:58:11 PM (14 years ago)
Author:
dafrick
Message:

Implemented support for multiple simultaniously showing GUIs. What happens now, in essence, is, that every root-window of a gui, that is to be showed, is attached to a global root window, which is always displayed and therefore needs to be fully transparent (alpha = 0.0). To not inherit the transparency (and thus be fully transparent as well) each root-window of a gui must (or should) set the property 'InheritsAlpha' to false.

Location:
code/branches/ingamemenu
Files:
12 edited

Legend:

Unmodified
Added
Removed
  • code/branches/ingamemenu/data/gui/layouts/MainMenu.layout

    r5781 r6003  
    66    <Property Name="FrameEnabled" Value="set:true"/>
    77    <Property Name="BackgroundEnabled" Value="set:false"/>
     8    <Property Name="InheritsAlpha" Value="False" />
    89 
    910        <Window Type="TaharezLook/Button" Name="orxonox/StandaloneButton">
  • code/branches/ingamemenu/data/gui/layouts/QuestGUI.layout

    r5781 r6003  
    66    <Property Name="FrameEnabled" Value="set:true"/>
    77    <Property Name="BackgroundEnabled" Value="set:false"/>
     8    <Property Name="InheritsAlpha" Value="False" />
    89
    910        <Window Type="TaharezLook/Titlebar" Name="orxonox/QuestGUI/Title">
  • code/branches/ingamemenu/data/gui/scripts/InitialiseGUI.lua

    r5781 r6003  
    1414
    1515loadedGUIs = {}
     16root = nil;
    1617
    1718-- loads the GUI with the specified filename
     
    4344-- be sure to set the global variable "filename" before calling this function
    4445function showGUI(filename)
    45     if current == nil or current.filename ~= filename then
    46         current = loadedGUIs[filename]
    47         if current == nil then
    48             current = loadGUI(filename)
    49         end
    50         system:setGUISheet(current.window)
     46    if root == nil then
     47        root = winMgr:createWindow("TaharezLook/StaticImage", "AbsoluteRootWindow")
     48        root:setProperty("Alpha", "0.0")
     49        root:setSize(CEGUI.UVector2(CEGUI.UDim(1.0,0),CEGUI.UDim(1.0,0)))
     50        system:setGUISheet(root)
    5151    end
    52     current:show()
     52
     53    local currentGUI = loadedGUIs[filename]
     54    if(currentGUI == nil) then
     55        currentGUI = loadGUI(filename)
     56    end
     57
     58    if(root:isChild(currentGUI.window)) then
     59        root:removeChildWindow(currentGUI.window)
     60    end
     61    root:addChildWindow(currentGUI.window)
     62
     63    currentGUI:show()
    5364    showing = true
    54     return current
    55 end
    56 
    57 function toggleGUI()
    58     if showing == true then
    59         current:hide()
    60         cursor:hide()
    61         showing = false
    62     else
    63         current:show()
    64         cursor:show()
    65         showing = true
    66     end
    67     return showing
     65    return currentGUI
    6866end
    6967
     
    7775
    7876function hideGUI(filename)
    79     current = loadedGUIs[filename]
    80     if current ~= nil then
    81         current:hide()
     77    local currentGUI = loadedGUIs[filename]
     78    if currentGUI ~= nil then
     79        currentGUI:hide()
     80        root:removeChildWindow(currentGUI.window)
    8281        showing = false
    8382    end
  • code/branches/ingamemenu/src/libraries/core/GUIManager.cc

    r5929 r6003  
    5353#include "util/Exception.h"
    5454#include "util/OrxAssert.h"
     55#include "ConsoleCommand.h"
    5556#include "Core.h"
     57#include "input/InputManager.h"
    5658#include "LuaState.h"
    5759#include "PathConfig.h"
     
    8688    GUIManager* GUIManager::singletonPtr_s = 0;
    8789
     90    SetConsoleCommandShortcut(GUIManager, showGUI).accessLevel(AccessLevel::User);
     91    SetConsoleCommandShortcut(GUIManager, hideGUI).accessLevel(AccessLevel::User);
     92
    8893    /**
    8994    @brief
     
    204209        For more details check out loadGUI_2.lua where the function presides.
    205210    */
    206     void GUIManager::showGUI(const std::string& name)
    207     {
    208         this->luaState_->doString("showGUI(\"" + name + "\")", rootFileInfo_);
     211    /*static*/ void GUIManager::showGUI(const std::string& name)
     212    {
     213        std::pair<std::set<std::string>::iterator,bool> result = GUIManager::getInstance().showingGUIs_.insert(name);
     214        if(result.second == false) //!< GUI already showing.
     215            return;
     216        if(GUIManager::getInstance().showingGUIs_.size() == 1 && result.second == true) //!< If it's the first GUI.
     217        {
     218            GUIManager::getInstance().executeCode("showCursor()");
     219            InputManager::getInstance().enterState("guiMouseOnly");
     220        }
     221        GUIManager::getInstance().executeCode("showGUI(\"" + name + "\")");
     222    }
     223
     224    /**
     225    @brief
     226        Hack-ish. Needed for GUIOverlay.
     227    */
     228    void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr)
     229    {
     230        std::pair<std::set<std::string>::iterator,bool> result = this->showingGUIs_.insert(name);
     231        if(result.second == false) //!< GUI already showing.
     232            return;
     233        if(this->showingGUIs_.size() == 1 && result.second == true) //!< If it's the first GUI.
     234        {
     235            this->executeCode("showCursor()");
     236            InputManager::getInstance().enterState("guiMouseOnly");
     237        }
     238        this->executeCode("showGUI(\"" + name + "\", " + ptr + ")");
     239    }
     240
     241    /**
     242    @brief
     243        Hides specified GUI.
     244    @param name
     245        The name of the GUI.
     246    */
     247    /*static*/ void GUIManager::hideGUI(const std::string& name)
     248    {
     249        bool present = GUIManager::getInstance().showingGUIs_.erase(name);
     250        if(!present) //!< If there was nothing to erase.
     251            return;
     252        GUIManager::getInstance().executeCode("hideGUI(\"" + name + "\")");
     253        if(GUIManager::getInstance().showingGUIs_.size() == 0)
     254        {
     255            GUIManager::getInstance().executeCode("hideCursor()");
     256            InputManager::getInstance().leaveState("guiMouseOnly");
     257        }
    209258    }
    210259
  • code/branches/ingamemenu/src/libraries/core/GUIManager.h

    r5929 r6003  
    3434
    3535#include <map>
     36#include <set>
    3637#include <string>
    3738#include <CEGUIForwardRefs.h>
     
    6566        ~GUIManager();
    6667
    67         void update(const Clock& time);
     68        void update(const Clock& time); 
    6869
    69         void showGUI(const std::string& name);
    70         void executeCode(const std::string& str);
     70        static void showGUI(const std::string& name);
     71        void showGUIExtra(const std::string& name, const std::string& ptr);
     72        static void hideGUI(const std::string& name);
    7173
    7274        void setCamera(Ogre::Camera* camera);
     
    8284    private:
    8385        GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
     86
     87        std::set<std::string> showingGUIs_; //!< Keeps track of all the GUIs that are currently showing.
     88
     89        void executeCode(const std::string& str);
    8490
    8591        // keyHandler functions
  • code/branches/ingamemenu/src/modules/overlays/GUIOverlay.cc

    r5980 r6003  
    7373            out << reinterpret_cast<long>(this);
    7474            str = out.str();
    75             GUIManager::getInstance().executeCode("showCursor()");
    76             InputManager::getInstance().enterState("guiMouseOnly");
    77             GUIManager::getInstance().executeCode("showGUI(\"" + this->guiName_ + "\", " + str + ")");
     75            COUT(1) << "GUIManager ptr: " << str << std::endl;
     76            GUIManager::getInstance().showGUIExtra(this->guiName_, str);
    7877
    7978            COUT(3) << "Showing GUI " << this->guiName_ << std::endl;
     
    8180        else
    8281        {
    83             GUIManager::getInstance().executeCode("hideGUI(\"" + this->guiName_ + "\")");
    84             GUIManager::getInstance().executeCode("hideCursor()");
    85             InputManager::getInstance().leaveState("guiMouseOnly");
     82            GUIManager::hideGUI(this->guiName_);
    8683            COUT(3) << "Hiding GUI " << this->guiName_ << std::endl;
    8784        }
  • code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.cc

    r5929 r6003  
    6464    void GSGraphics::activate()
    6565    {
    66         // add console command to toggle GUI
    67         CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI"));
     66       
    6867    }
    6968
     
    7877    }
    7978
    80     /**
    81     @brief
    82         Toggles the visibility of the current GUI
    83 
    84         This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
    85         For more details on this function check out the Lua code.
    86     */
    87     void GSGraphics::toggleGUI()
    88     {
    89         GUIManager::getInstance().executeCode("toggleGUI()");
    90     }
    91 
    9279    void GSGraphics::update(const Clock& time)
    9380    {
  • code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.h

    r5929 r6003  
    5757        void update(const Clock& time);
    5858
    59         void toggleGUI();
    60 
    6159    private:
    6260    };
  • code/branches/ingamemenu/src/orxonox/gamestates/GSLevel.cc

    r5966 r6003  
    101101        if (show)
    102102        {
    103             GUIManager::getInstance().showGUI("inGameTest");
    104             GUIManager::getInstance().executeCode("showCursor()");
    105             InputManager::getInstance().enterState("guiMouseOnly");
     103            GUIManager::showGUI("inGameTest");
    106104        }
    107105        else
    108106        {
    109             GUIManager::getInstance().executeCode("hideGUI(\"inGameTest\")");
    110             GUIManager::getInstance().executeCode("hideCursor()");
    111             InputManager::getInstance().leaveState("guiMouseOnly");
     107            GUIManager::hideGUI("inGameTest");
    112108        }
    113109    }
  • code/branches/ingamemenu/src/orxonox/gamestates/GSMainMenu.cc

    r5929 r6003  
    8282    {
    8383        // show main menu
    84         GUIManager::getInstance().showGUI("MainMenu");
     84        GUIManager::showGUI("MainMenu");
    8585        GUIManager::getInstance().setCamera(this->camera_);
    8686        GraphicsManager::getInstance().setCamera(this->camera_);
     
    111111
    112112        InputManager::getInstance().leaveState("mainMenu");
     113        GUIManager::hideGUI("MainMenu");
    113114
    114115        GUIManager::getInstance().setCamera(0);
  • code/branches/ingamemenu/src/orxonox/pickup/PickupInventory.cc

    r5781 r6003  
    8686    {
    8787        if(PickupInventory::getSingleton()->isVisible()) {
    88             GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
    89             GUIManager::getInstance().executeCode("hideCursor()");
    90             InputManager::getInstance().leaveState("guiMouseOnly");
    91         }
    92         else
    93         {
    94             GUIManager::getInstance().showGUI("PickupInventory");
    95             GUIManager::getInstance().executeCode("showCursor()");
    96             InputManager::getInstance().enterState("guiMouseOnly");
     88            GUIManager::hideGUI("PickupInventory");
     89        }
     90        else
     91        {
     92            GUIManager::showGUI("PickupInventory");
    9793        }
    9894        PickupInventory::getSingleton()->setVisible(!PickupInventory::getSingleton()->isVisible());
  • code/branches/ingamemenu/src/orxonox/pickup/PickupSpawner.cc

    r5929 r6003  
    9696        //  & load the GUI itself too, along with some empty windows
    9797        //   = even less delays
    98         GUIManager::getInstance().showGUI("PickupInventory");
    99         GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
     98        GUIManager::showGUI("PickupInventory");
     99        GUIManager::hideGUI("PickupInventory");
    100100        PickupInventory::getSingleton();
    101101    }
Note: See TracChangeset for help on using the changeset viewer.