[Orxonox-commit 352] r2963 - in trunk/src/orxonox: . gui objects/quest overlays
dafrick at orxonox.net
dafrick at orxonox.net
Sun May 10 23:41:48 CEST 2009
Author: dafrick
Date: 2009-05-10 23:41:48 +0200 (Sun, 10 May 2009)
New Revision: 2963
Modified:
trunk/src/orxonox/CMakeLists.txt
trunk/src/orxonox/gui/GUIManager.cc
trunk/src/orxonox/objects/quest/Quest.cc
trunk/src/orxonox/objects/quest/Quest.h
trunk/src/orxonox/objects/quest/QuestDescription.h
trunk/src/orxonox/objects/quest/QuestManager.cc
trunk/src/orxonox/objects/quest/QuestManager.h
trunk/src/orxonox/overlays/GUIOverlay.cc
Log:
Some Quest stuff, and the rest for the GUIOverlay I failed to commit before.
Modified: trunk/src/orxonox/CMakeLists.txt
===================================================================
--- trunk/src/orxonox/CMakeLists.txt 2009-05-10 21:38:28 UTC (rev 2962)
+++ trunk/src/orxonox/CMakeLists.txt 2009-05-10 21:41:48 UTC (rev 2963)
@@ -34,7 +34,7 @@
SET(ORXONOX_FILES ${ORXONOX_SRC_FILES} ${ORXONOX_HDR_FILES})
GENERATE_SOURCE_GROUPS(${ORXONOX_FILES})
-GENERATE_TOLUA_BINDINGS(Orxonox ORXONOX_FILES INPUTFILES gui/GUIManager.h)
+GENERATE_TOLUA_BINDINGS(Orxonox ORXONOX_FILES INPUTFILES gui/GUIManager.h objects/quest/QuestManager.h objects/quest/QuestDescription.h)
# Not using precompiled header files: Avoid dependencies
INCLUDE_DIRECTORIES(pch/nopch)
Modified: trunk/src/orxonox/gui/GUIManager.cc
===================================================================
--- trunk/src/orxonox/gui/GUIManager.cc 2009-05-10 21:38:28 UTC (rev 2962)
+++ trunk/src/orxonox/gui/GUIManager.cc 2009-05-10 21:41:48 UTC (rev 2963)
@@ -241,6 +241,34 @@
/**
@brief
+ Registers a GUIOverlay with the GUIManager so that the GUIOverlay can be accessed by it's name through the GUIManager.
+ @param name
+ The name of the GUI.
+ @param overlay
+ A pointer to the GUIOverlay of the GUI.
+ @return
+ Returns false if the Overlay was already present.
+ */
+ bool GUIManager::registerOverlay(std::string name, GUIOverlay* overlay)
+ {
+ return (this->guiOverlays_.insert(std::pair<std::string, GUIOverlay*>(name, overlay))).second;
+ }
+
+ /**
+ @brief
+ Get the GUIOverlay of the GUI with the given name.
+ @param name
+ The name of the GUI.
+ @return
+ Returns a pointer to the GUIOverlay.
+ */
+ GUIOverlay* GUIManager::getOverlay(std::string name)
+ {
+ return (this->guiOverlays_.find(name))->second;
+ }
+
+ /**
+ @brief
Tells the GUIManager which SceneManager to use
@param camera
The current camera on which the GUI should be displayed on.
Modified: trunk/src/orxonox/objects/quest/Quest.cc
===================================================================
--- trunk/src/orxonox/objects/quest/Quest.cc 2009-05-10 21:38:28 UTC (rev 2962)
+++ trunk/src/orxonox/objects/quest/Quest.cc 2009-05-10 21:41:48 UTC (rev 2963)
@@ -196,17 +196,6 @@
/**
@brief
- Returns the parentquest of the Quest.
- @return
- Returns a pointer to the parentquest of the Quest.
- */
- const Quest* Quest::getParentQuest(void)
- {
- return this->parentQuest_;
- }
-
- /**
- @brief
Returns the subquest at the given index.
@param
The index.
Modified: trunk/src/orxonox/objects/quest/Quest.h
===================================================================
--- trunk/src/orxonox/objects/quest/Quest.h 2009-05-10 21:38:28 UTC (rev 2962)
+++ trunk/src/orxonox/objects/quest/Quest.h 2009-05-10 21:41:48 UTC (rev 2963)
@@ -117,7 +117,6 @@
virtual bool isFailable(const PlayerInfo* player) const = 0; //!< Checks whether the Quest can be failed.
virtual bool isCompletable(const PlayerInfo* player) const = 0; //!< Checks whether the Quest can be completed.
- const Quest* getParentQuest(void); //!< Returns the parentquest of the Quest.
const Quest* getSubQuest(unsigned int index) const; //!<Returns the subquest at the given index.
const QuestHint* getHint(unsigned int index) const; //!< Returns the QuestHint at the given index.
const QuestEffect* getFailEffect(unsigned int index) const; //!< Returns the fail QuestEffect at the given index.
Modified: trunk/src/orxonox/objects/quest/QuestDescription.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestDescription.h 2009-05-10 21:38:28 UTC (rev 2962)
+++ trunk/src/orxonox/objects/quest/QuestDescription.h 2009-05-10 21:41:48 UTC (rev 2963)
@@ -41,6 +41,7 @@
#include "core/BaseObject.h"
#include "core/XMLPort.h"
+// tolua_begin
namespace orxonox
{
/**
@@ -54,14 +55,17 @@
@author
Damian 'Mozork' Frick
*/
- class _OrxonoxExport QuestDescription : public BaseObject
- {
+ class _OrxonoxExport QuestDescription
+// tolua_end
+ : public BaseObject
+ { // tolua_export
public:
QuestDescription(BaseObject* creator);
virtual ~QuestDescription();
virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a QuestDescription object through XML.
+// tolua_begin
/**
@brief Returns the title.
@return Returns a string containing the title of the QuestDescription.
@@ -75,6 +79,7 @@
*/
inline const std::string & getDescription(void) const
{ return this->description_; }
+// tolua_end
/**
@brief Returns the fail message.
@@ -154,8 +159,8 @@
inline void setCompleteMessage(const std::string & message)
{ this->completeMessage_ = message; }
- };
+ }; // tolua_export
-}
+} // tolua_export
#endif /* _QuestDescription_H__ */
Modified: trunk/src/orxonox/objects/quest/QuestManager.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestManager.cc 2009-05-10 21:38:28 UTC (rev 2962)
+++ trunk/src/orxonox/objects/quest/QuestManager.cc 2009-05-10 21:41:48 UTC (rev 2963)
@@ -35,16 +35,23 @@
#include "QuestManager.h"
#include "core/CoreIncludes.h"
+#include "core/ConsoleCommand.h"
+#include "core/input/InputManager.h"
+#include "util/Convert.h"
#include "util/Exception.h"
+#include "gui/GUIManager.h"
#include "Quest.h"
#include "QuestHint.h"
namespace orxonox
{
//! Pointer to the current (and single) instance of this class.
- QuestManager* QuestManager::singletonRef_s = NULL;
+ /*static*/ QuestManager* QuestManager::singletonRef_s = NULL;
+ /*static*/ bool QuestManager::GUIOpen = false;
+ SetConsoleCommand(QuestManager, toggleQuestGUI, true);
+
/**
@brief
Constructor. Registers the object.
@@ -212,5 +219,153 @@
}
+ QuestContainer* QuestManager::getQuestTree(std::string & name)
+ {
+ GUIOverlay* gui = GUIManager::getInstance().getOverlay(name);
+ PlayerInfo* player;
+ if(gui == NULL)
+ {
+ COUT(1) << "Something BAD happened." << std::endl;
+ return NULL;
+ }
+ COUT(1) << player << std::endl;
+ ConverterExplicit<BaseObject, PlayerInfo>::convert(player, *(gui->getOwner()));
+
+ QuestContainer* root = NULL;
+ QuestContainer* current = NULL;
+
+ std::list<Quest*>* pRootQuests = new std::list<Quest*>();
+ std::list<Quest*> rootQuests = *pRootQuests;
+ getRootQuests(player, rootQuests);
+
+ for(std::list<Quest*>::iterator it = rootQuests.begin(); it != rootQuests.end(); it++)
+ {
+ Quest* quest = *it;
+
+ QuestContainer* container = new QuestContainer;
+
+ container->description = quest->getDescription();
+ addHints(container, quest, player);
+ addSubQuests(container, quest, player);
+
+ if(root == NULL)
+ {
+ root = container;
+ }
+ else
+ {
+ current->next = container;
+ }
+
+ current = container;
+
+ }
+ if(current != NULL)
+ current->next = NULL;
+
+ delete pRootQuests;
+
+ return root;
+ }
+
+ void QuestManager::getRootQuests(const PlayerInfo* player, std::list<Quest*> & list)
+ {
+ for(std::map<std::string, Quest*>::iterator it=this->questMap_.begin(); it!=this->questMap_.end(); it++)
+ {
+ Quest* quest = (*it).second;
+ if(quest->getParentQuest() == NULL && !quest->isInactive(player))
+ {
+ list.push_back(quest);
+ }
+ }
+ }
+
+ void QuestManager::addSubQuests(QuestContainer* container, Quest* quest, const PlayerInfo* player)
+ {
+ QuestContainer* current = NULL;
+ QuestContainer* first = NULL;
+
+ std::list<Quest*> quests = quest->getSubQuestList();
+ for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
+ {
+ Quest* subQuest = *it;
+ if(!subQuest->isInactive(player))
+ {
+ QuestContainer* subQuestContainer = new QuestContainer;
+
+ subQuestContainer->description = subQuest->getDescription();
+ addHints(subQuestContainer, subQuest, player);
+ addSubQuests(subQuestContainer, subQuest, player);
+
+ if(first == NULL)
+ {
+ first = subQuestContainer;
+ }
+ else
+ {
+ current->next = subQuestContainer;
+ }
+
+ current = subQuestContainer;
+ }
+ }
+
+ if(current != NULL)
+ current->next = NULL;
+ container->subQuests = first;
+
+ }
+
+ void QuestManager::addHints(QuestContainer* container, Quest* quest, const PlayerInfo* player)
+ {
+ HintContainer* current = NULL;
+ HintContainer* first = NULL;
+
+ std::list<QuestHint*> hints = quest->getHintsList();
+ for(std::list<QuestHint*>::iterator it = hints.begin(); it != hints.end(); it++)
+ {
+ if((*it)->isActive(player))
+ {
+ HintContainer* hint = new HintContainer;
+ hint->description = (*it)->getDescription();
+
+ if(first == NULL)
+ {
+ first = hint;
+ }
+ else
+ {
+ current->next = hint;
+ }
+
+ current = hint;
+ }
+ }
+
+ if(current != NULL)
+ current->next = NULL;
+ container->hint = first;
+ }
+
+ /*static*/ void QuestManager::toggleQuestGUI(void)
+ {
+ if (!QuestManager::GUIOpen)
+ {
+ GUIManager::getInstancePtr()->showGUI("QuestGUI");
+ GUIManager::getInstancePtr()->executeCode("showCursor()");
+ InputManager::getInstance().requestEnterState("guiMouseOnly");
+ GUIManager::getInstancePtr()->executeCode("loadQuestsList()");
+ GUIOpen = true;
+ }
+ else
+ {
+ GUIManager::getInstancePtr()->executeCode("hideGUI(\"QuestGUI\")");
+ GUIManager::getInstancePtr()->executeCode("hideCursor()");
+ InputManager::getInstance().requestLeaveState("guiMouseOnly");
+ GUIOpen = false;
+ }
+ }
+
+
}
Modified: trunk/src/orxonox/objects/quest/QuestManager.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestManager.h 2009-05-10 21:38:28 UTC (rev 2962)
+++ trunk/src/orxonox/objects/quest/QuestManager.h 2009-05-10 21:41:48 UTC (rev 2963)
@@ -37,23 +37,34 @@
#include "OrxonoxPrereqs.h"
#include <map>
+#include <list>
#include <string>
#include "core/OrxonoxClass.h"
#include "orxonox/objects/infos/PlayerInfo.h"
+#include "overlays/GUIOverlay.h"
// tolua_begin
namespace orxonox
{
-// tolua_end
- struct RootQuest
+ struct QuestContainer;
+ struct HintContainer;
+
+ struct QuestContainer
{
- Quest* quest;
- RootQuest* next;
+ const QuestDescription* description;
+ HintContainer* hint;
+ QuestContainer* subQuests;
+ QuestContainer* next;
};
-// tolua_begin
+ struct HintContainer
+ {
+ const QuestDescription* description;
+ HintContainer* next;
+ };
+
/**
@brief
Is a Singleton and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()).
@@ -79,7 +90,7 @@
Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id.
QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
- RootQuest* getQuests(const PlayerInfo & player);
+ QuestContainer* getQuestTree(std::string & name); // tolua_export
static void toggleQuestGUI(void); //!< Opens the GUI.
@@ -90,6 +101,10 @@
std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's.
std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's.
+ void getRootQuests(const PlayerInfo* player, std::list<Quest*> & list);
+ void addHints(QuestContainer* container, Quest* quest, const PlayerInfo* player);
+ void addSubQuests(QuestContainer* container, Quest* quest, const PlayerInfo* player);
+
}; // tolua_export
} // tolua_export
Modified: trunk/src/orxonox/overlays/GUIOverlay.cc
===================================================================
--- trunk/src/orxonox/overlays/GUIOverlay.cc 2009-05-10 21:38:28 UTC (rev 2962)
+++ trunk/src/orxonox/overlays/GUIOverlay.cc 2009-05-10 21:41:48 UTC (rev 2963)
@@ -52,6 +52,8 @@
SUPER(GUIOverlay, XMLPort, xmlElement, mode);
XMLPortParam(GUIOverlay, "guiname", setGUIName, getGUIName, xmlElement, mode);
+
+ GUIManager::getInstancePtr()->registerOverlay(this->guiName_, this);
}
void GUIOverlay::changedVisibility()
More information about the Orxonox-commit
mailing list