[Orxonox-commit 1285] r6003 - in code/branches/ingamemenu: data/gui/layouts data/gui/scripts src/libraries/core src/modules/overlays src/orxonox/gamestates src/orxonox/pickup
dafrick at orxonox.net
dafrick at orxonox.net
Wed Oct 28 17:58:11 CET 2009
Author: dafrick
Date: 2009-10-28 17:58:11 +0100 (Wed, 28 Oct 2009)
New Revision: 6003
Modified:
code/branches/ingamemenu/data/gui/layouts/MainMenu.layout
code/branches/ingamemenu/data/gui/layouts/QuestGUI.layout
code/branches/ingamemenu/data/gui/scripts/InitialiseGUI.lua
code/branches/ingamemenu/src/libraries/core/GUIManager.cc
code/branches/ingamemenu/src/libraries/core/GUIManager.h
code/branches/ingamemenu/src/modules/overlays/GUIOverlay.cc
code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.cc
code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.h
code/branches/ingamemenu/src/orxonox/gamestates/GSLevel.cc
code/branches/ingamemenu/src/orxonox/gamestates/GSMainMenu.cc
code/branches/ingamemenu/src/orxonox/pickup/PickupInventory.cc
code/branches/ingamemenu/src/orxonox/pickup/PickupSpawner.cc
Log:
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.
Modified: code/branches/ingamemenu/data/gui/layouts/MainMenu.layout
===================================================================
--- code/branches/ingamemenu/data/gui/layouts/MainMenu.layout 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/data/gui/layouts/MainMenu.layout 2009-10-28 16:58:11 UTC (rev 6003)
@@ -5,6 +5,7 @@
<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="TaharezLook/Button" Name="orxonox/StandaloneButton">
<Property Name="UnifiedPosition" Value="{{0.11,0},{0.3,0}}"/>
Modified: code/branches/ingamemenu/data/gui/layouts/QuestGUI.layout
===================================================================
--- code/branches/ingamemenu/data/gui/layouts/QuestGUI.layout 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/data/gui/layouts/QuestGUI.layout 2009-10-28 16:58:11 UTC (rev 6003)
@@ -5,6 +5,7 @@
<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="TaharezLook/Titlebar" Name="orxonox/QuestGUI/Title">
<Property Name="UnifiedPosition" Value="{{0.05,0},{0.05,0}}"/>
Modified: code/branches/ingamemenu/data/gui/scripts/InitialiseGUI.lua
===================================================================
--- code/branches/ingamemenu/data/gui/scripts/InitialiseGUI.lua 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/data/gui/scripts/InitialiseGUI.lua 2009-10-28 16:58:11 UTC (rev 6003)
@@ -13,6 +13,7 @@
system:setDefaultTooltip("TaharezLook/Tooltip")
loadedGUIs = {}
+root = nil;
-- loads the GUI with the specified filename
-- be sure to set the global variable "filename" before calling this function
@@ -42,29 +43,26 @@
-- 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)
- if current == nil or current.filename ~= filename then
- current = loadedGUIs[filename]
- if current == nil then
- current = loadGUI(filename)
- end
- system:setGUISheet(current.window)
+ 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)
end
- current:show()
- showing = true
- return current
-end
-function toggleGUI()
- if showing == true then
- current:hide()
- cursor:hide()
- showing = false
- else
- current:show()
- cursor:show()
- showing = true
+ local currentGUI = loadedGUIs[filename]
+ if(currentGUI == nil) then
+ currentGUI = loadGUI(filename)
end
- return showing
+
+ if(root:isChild(currentGUI.window)) then
+ root:removeChildWindow(currentGUI.window)
+ end
+ root:addChildWindow(currentGUI.window)
+
+ currentGUI:show()
+ showing = true
+ return currentGUI
end
function hideCursor()
@@ -76,9 +74,10 @@
end
function hideGUI(filename)
- current = loadedGUIs[filename]
- if current ~= nil then
- current:hide()
+ local currentGUI = loadedGUIs[filename]
+ if currentGUI ~= nil then
+ currentGUI:hide()
+ root:removeChildWindow(currentGUI.window)
showing = false
end
end
Modified: code/branches/ingamemenu/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/ingamemenu/src/libraries/core/GUIManager.cc 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/src/libraries/core/GUIManager.cc 2009-10-28 16:58:11 UTC (rev 6003)
@@ -52,7 +52,9 @@
#include "util/Debug.h"
#include "util/Exception.h"
#include "util/OrxAssert.h"
+#include "ConsoleCommand.h"
#include "Core.h"
+#include "input/InputManager.h"
#include "LuaState.h"
#include "PathConfig.h"
#include "Resource.h"
@@ -85,6 +87,9 @@
GUIManager* GUIManager::singletonPtr_s = 0;
+ SetConsoleCommandShortcut(GUIManager, showGUI).accessLevel(AccessLevel::User);
+ SetConsoleCommandShortcut(GUIManager, hideGUI).accessLevel(AccessLevel::User);
+
/**
@brief
Constructs the GUIManager by starting up CEGUI
@@ -203,11 +208,55 @@
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.
*/
- void GUIManager::showGUI(const std::string& name)
+ /*static*/ void GUIManager::showGUI(const std::string& name)
{
- this->luaState_->doString("showGUI(\"" + name + "\")", rootFileInfo_);
+ std::pair<std::set<std::string>::iterator,bool> result = GUIManager::getInstance().showingGUIs_.insert(name);
+ if(result.second == false) //!< GUI already showing.
+ return;
+ if(GUIManager::getInstance().showingGUIs_.size() == 1 && result.second == true) //!< If it's the first GUI.
+ {
+ GUIManager::getInstance().executeCode("showCursor()");
+ InputManager::getInstance().enterState("guiMouseOnly");
+ }
+ GUIManager::getInstance().executeCode("showGUI(\"" + name + "\")");
}
+ /**
+ @brief
+ Hack-ish. Needed for GUIOverlay.
+ */
+ void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr)
+ {
+ std::pair<std::set<std::string>::iterator,bool> result = this->showingGUIs_.insert(name);
+ if(result.second == false) //!< GUI already showing.
+ return;
+ if(this->showingGUIs_.size() == 1 && result.second == true) //!< If it's the first GUI.
+ {
+ this->executeCode("showCursor()");
+ InputManager::getInstance().enterState("guiMouseOnly");
+ }
+ this->executeCode("showGUI(\"" + name + "\", " + ptr + ")");
+ }
+
+ /**
+ @brief
+ Hides specified GUI.
+ @param name
+ The name of the GUI.
+ */
+ /*static*/ void GUIManager::hideGUI(const std::string& name)
+ {
+ bool present = GUIManager::getInstance().showingGUIs_.erase(name);
+ if(!present) //!< If there was nothing to erase.
+ return;
+ GUIManager::getInstance().executeCode("hideGUI(\"" + name + "\")");
+ if(GUIManager::getInstance().showingGUIs_.size() == 0)
+ {
+ GUIManager::getInstance().executeCode("hideCursor()");
+ InputManager::getInstance().leaveState("guiMouseOnly");
+ }
+ }
+
void GUIManager::keyPressed(const KeyEvent& evt)
{
guiSystem_->injectKeyDown(evt.getKeyCode());
Modified: code/branches/ingamemenu/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/ingamemenu/src/libraries/core/GUIManager.h 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/src/libraries/core/GUIManager.h 2009-10-28 16:58:11 UTC (rev 6003)
@@ -33,6 +33,7 @@
#include "CorePrereqs.h"
#include <map>
+#include <set>
#include <string>
#include <CEGUIForwardRefs.h>
#include <boost/scoped_ptr.hpp>
@@ -64,10 +65,11 @@
GUIManager(Ogre::RenderWindow* renderWindow, const std::pair<int, int>& mousePosition, bool bFullScreen);
~GUIManager();
- void update(const Clock& time);
+ void update(const Clock& time);
- void showGUI(const std::string& name);
- void executeCode(const std::string& str);
+ static void showGUI(const std::string& name);
+ void showGUIExtra(const std::string& name, const std::string& ptr);
+ static void hideGUI(const std::string& name);
void setCamera(Ogre::Camera* camera);
Ogre::Camera* getCamera() { return this->camera_; }
@@ -82,6 +84,10 @@
private:
GUIManager(const GUIManager& instance); //!< private and undefined copy c'tor (this is a singleton class)
+ std::set<std::string> showingGUIs_; //!< Keeps track of all the GUIs that are currently showing.
+
+ void executeCode(const std::string& str);
+
// keyHandler functions
void keyPressed (const KeyEvent& evt);
void keyReleased(const KeyEvent& evt);
Modified: code/branches/ingamemenu/src/modules/overlays/GUIOverlay.cc
===================================================================
--- code/branches/ingamemenu/src/modules/overlays/GUIOverlay.cc 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/src/modules/overlays/GUIOverlay.cc 2009-10-28 16:58:11 UTC (rev 6003)
@@ -72,17 +72,14 @@
std::stringstream out;
out << reinterpret_cast<long>(this);
str = out.str();
- GUIManager::getInstance().executeCode("showCursor()");
- InputManager::getInstance().enterState("guiMouseOnly");
- GUIManager::getInstance().executeCode("showGUI(\"" + this->guiName_ + "\", " + str + ")");
+ COUT(1) << "GUIManager ptr: " << str << std::endl;
+ GUIManager::getInstance().showGUIExtra(this->guiName_, str);
COUT(3) << "Showing GUI " << this->guiName_ << std::endl;
}
else
{
- GUIManager::getInstance().executeCode("hideGUI(\"" + this->guiName_ + "\")");
- GUIManager::getInstance().executeCode("hideCursor()");
- InputManager::getInstance().leaveState("guiMouseOnly");
+ GUIManager::hideGUI(this->guiName_);
COUT(3) << "Hiding GUI " << this->guiName_ << std::endl;
}
}
Modified: code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.cc
===================================================================
--- code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.cc 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.cc 2009-10-28 16:58:11 UTC (rev 6003)
@@ -63,8 +63,7 @@
*/
void GSGraphics::activate()
{
- // add console command to toggle GUI
- CommandExecutor::addConsoleCommandShortcut(createConsoleCommand(createFunctor(&GSGraphics::toggleGUI, this), "toggleGUI"));
+
}
/**
@@ -77,18 +76,6 @@
Map::hackDestroyMap();
}
- /**
- @brief
- Toggles the visibility of the current GUI
-
- This function just executes a Lua function in the main script of the GUI by accessing the GUIManager.
- For more details on this function check out the Lua code.
- */
- void GSGraphics::toggleGUI()
- {
- GUIManager::getInstance().executeCode("toggleGUI()");
- }
-
void GSGraphics::update(const Clock& time)
{
if (this->getActivity().topState)
Modified: code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.h
===================================================================
--- code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.h 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/src/orxonox/gamestates/GSGraphics.h 2009-10-28 16:58:11 UTC (rev 6003)
@@ -56,8 +56,6 @@
void deactivate();
void update(const Clock& time);
- void toggleGUI();
-
private:
};
}
Modified: code/branches/ingamemenu/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- code/branches/ingamemenu/src/orxonox/gamestates/GSLevel.cc 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/src/orxonox/gamestates/GSLevel.cc 2009-10-28 16:58:11 UTC (rev 6003)
@@ -100,15 +100,11 @@
{
if (show)
{
- GUIManager::getInstance().showGUI("inGameTest");
- GUIManager::getInstance().executeCode("showCursor()");
- InputManager::getInstance().enterState("guiMouseOnly");
+ GUIManager::showGUI("inGameTest");
}
else
{
- GUIManager::getInstance().executeCode("hideGUI(\"inGameTest\")");
- GUIManager::getInstance().executeCode("hideCursor()");
- InputManager::getInstance().leaveState("guiMouseOnly");
+ GUIManager::hideGUI("inGameTest");
}
}
Modified: code/branches/ingamemenu/src/orxonox/gamestates/GSMainMenu.cc
===================================================================
--- code/branches/ingamemenu/src/orxonox/gamestates/GSMainMenu.cc 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/src/orxonox/gamestates/GSMainMenu.cc 2009-10-28 16:58:11 UTC (rev 6003)
@@ -81,7 +81,7 @@
void GSMainMenu::activate()
{
// show main menu
- GUIManager::getInstance().showGUI("MainMenu");
+ GUIManager::showGUI("MainMenu");
GUIManager::getInstance().setCamera(this->camera_);
GraphicsManager::getInstance().setCamera(this->camera_);
@@ -110,6 +110,7 @@
}
InputManager::getInstance().leaveState("mainMenu");
+ GUIManager::hideGUI("MainMenu");
GUIManager::getInstance().setCamera(0);
GraphicsManager::getInstance().setCamera(0);
Modified: code/branches/ingamemenu/src/orxonox/pickup/PickupInventory.cc
===================================================================
--- code/branches/ingamemenu/src/orxonox/pickup/PickupInventory.cc 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/src/orxonox/pickup/PickupInventory.cc 2009-10-28 16:58:11 UTC (rev 6003)
@@ -85,15 +85,11 @@
void PickupInventory::toggleInventory()
{
if(PickupInventory::getSingleton()->isVisible()) {
- GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
- GUIManager::getInstance().executeCode("hideCursor()");
- InputManager::getInstance().leaveState("guiMouseOnly");
+ GUIManager::hideGUI("PickupInventory");
}
else
{
- GUIManager::getInstance().showGUI("PickupInventory");
- GUIManager::getInstance().executeCode("showCursor()");
- InputManager::getInstance().enterState("guiMouseOnly");
+ GUIManager::showGUI("PickupInventory");
}
PickupInventory::getSingleton()->setVisible(!PickupInventory::getSingleton()->isVisible());
}
Modified: code/branches/ingamemenu/src/orxonox/pickup/PickupSpawner.cc
===================================================================
--- code/branches/ingamemenu/src/orxonox/pickup/PickupSpawner.cc 2009-10-28 13:38:51 UTC (rev 6002)
+++ code/branches/ingamemenu/src/orxonox/pickup/PickupSpawner.cc 2009-10-28 16:58:11 UTC (rev 6003)
@@ -95,8 +95,8 @@
// & load the GUI itself too, along with some empty windows
// = even less delays
- GUIManager::getInstance().showGUI("PickupInventory");
- GUIManager::getInstance().executeCode("hideGUI(\"PickupInventory\")");
+ GUIManager::showGUI("PickupInventory");
+ GUIManager::hideGUI("PickupInventory");
PickupInventory::getSingleton();
}
/**
More information about the Orxonox-commit
mailing list