[Orxonox-commit 1024] r5745 - code/trunk/src/modules/questsystem
dafrick at orxonox.net
dafrick at orxonox.net
Sun Sep 13 15:04:03 CEST 2009
Author: dafrick
Date: 2009-09-13 15:04:02 +0200 (Sun, 13 Sep 2009)
New Revision: 5745
Modified:
code/trunk/src/modules/questsystem/CMakeLists.txt
code/trunk/src/modules/questsystem/QuestManager.cc
code/trunk/src/modules/questsystem/QuestManager.h
code/trunk/src/modules/questsystem/QuestsystemPrereqs.h
Log:
QuestGUI almost working...
Modified: code/trunk/src/modules/questsystem/CMakeLists.txt
===================================================================
--- code/trunk/src/modules/questsystem/CMakeLists.txt 2009-09-12 15:39:07 UTC (rev 5744)
+++ code/trunk/src/modules/questsystem/CMakeLists.txt 2009-09-13 13:04:02 UTC (rev 5745)
@@ -11,6 +11,8 @@
QuestDescription.cc
QuestEffect.cc
QuestEffectBeacon.cc
+ QuestGUINode.cc
+ QuestGUI.cc
QuestHint.cc
QuestItem.cc
QuestListener.cc
Modified: code/trunk/src/modules/questsystem/QuestManager.cc
===================================================================
--- code/trunk/src/modules/questsystem/QuestManager.cc 2009-09-12 15:39:07 UTC (rev 5744)
+++ code/trunk/src/modules/questsystem/QuestManager.cc 2009-09-13 13:04:02 UTC (rev 5745)
@@ -36,11 +36,15 @@
#include "util/Exception.h"
#include "core/CoreIncludes.h"
#include "core/GUIManager.h"
+#include "core/ConsoleCommand.h"
+#include "core/input/InputManager.h" //TDO: Necessary?
+#include <CEGUIWindow.h>
+#include "overlays/GUIOverlay.h"
#include "infos/PlayerInfo.h"
#include "Quest.h"
#include "QuestHint.h"
-#include "QuestItem.h"
+#include "QuestItem.h" //TDO: Necessary?
namespace orxonox
{
@@ -64,10 +68,26 @@
*/
QuestManager::~QuestManager()
{
+ for(std::map<PlayerInfo*, QuestGUI*>::iterator it = this->questGUIs_.begin(); it != this->questGUIs_.end(); it++)
+ {
+ delete (*it).second;
+ }
+ this->questGUIs_.clear();
}
/**
@brief
+ Retreive all Quests.
+ @return
+ Returns a map with all Quests indexed by their id's.
+ */
+ std::map<std::string, Quest*> & QuestManager::getQuests(void)
+ {
+ return this->questMap_;
+ }
+
+ /**
+ @brief
Registers a Quest with the QuestManager to make it globally accessable.
Uses it's id to make sure to be able to be identify and retrieve it later.
@param quest
@@ -200,168 +220,43 @@
/**
@brief
-
- @param name
+ Retreive the main window for the GUI.
+ This is for the use in the lua script tu start the QuestGUI.
+ @param guiName
+ The name of the GUI.
@return
+ Returns a CEGUI Window.
*/
- QuestContainer* QuestManager::getQuestTree(std::string & name)
+ CEGUI::Window* QuestManager::getQuestGUI(const std::string & guiName)
{
- PlayerInfo* player = GUIManager::getInstance().getPlayer(name);
- if(player == NULL)
- {
- COUT(1) << "Error: GUIOverlay with name '" << name << "' has no player." << std::endl;
- return NULL;
- }
+ PlayerInfo* player = this->retreivePlayer(guiName);
- QuestContainer* root = NULL;
- QuestContainer* current = NULL;
+ if(this->questGUIs_.find(player) == this->questGUIs_.end()) //!< Create a new GUI, if there is none, yet.
+ this->questGUIs_[player] = new QuestGUI(player);
- std::list<Quest*>* rootQuests = new std::list<Quest*>();
- getRootQuests(player, *rootQuests);
-
- for(std::list<Quest*>::iterator it = rootQuests->begin(); it != rootQuests->end(); it++)
- {
- QuestContainer* container = addSubQuest(*it, player);
-
- if(root == NULL)
- {
- root = container;
- }
- else
- {
- current->next = container;
- }
-
- current = container;
-
- }
- if(current != NULL)
- current->next = NULL;
-
- delete rootQuests;
-
- return root;
+ return this->questGUIs_[player]->getGUI();
}
/**
@brief
-
- @param player
- @param list
+ Retrieve the player for a certain GUI.
+ @param guiName
+ The name of the GUI the player is retrieved for.
@return
+ Returns the player.
+ @todo
+ This very well might be outdated. So: Check if still needed, and update if necessary.
*/
- void QuestManager::getRootQuests(const PlayerInfo* player, std::list<Quest*> & list)
+ PlayerInfo* QuestManager::retreivePlayer(const std::string & guiName)
{
- for(std::map<std::string, Quest*>::iterator it=this->questMap_.begin(); it!=this->questMap_.end(); it++)
+ PlayerInfo* player = GUIManager::getInstance().getPlayer(guiName);
+ if(player == NULL)
{
- Quest* quest = (*it).second;
- if(quest->getParentQuest() == NULL && !quest->isInactive(player))
- {
- list.push_back(quest);
- }
- }
- }
-
- /**
- @brief
-
- @param quest
- @param player
- @return
- */
- QuestContainer* QuestManager::addSubQuest(Quest* quest, const PlayerInfo* player)
- {
- if(quest == NULL)
+ COUT(1) << "Error: GUIOverlay with name '" << guiName << "' has no player." << std::endl;
return NULL;
-
- QuestContainer* container = new QuestContainer;
- container->description = quest->getDescription();
- container->hint = addHints(quest, player);
-
- if(quest->isActive(player))
- {
- container->status = "active";
}
- else if(quest->isCompleted(player))
- {
- container->status = "completed";
- }
- else if(quest->isFailed(player))
- {
- container->status = "failed";
- }
- else
- {
- container->status = "";
- COUT(1) << "An error occurred. A Quest of un-specified status wanted to be displayed." << std::endl;
- }
- std::list<Quest*> quests = quest->getSubQuestList();
- QuestContainer* current = NULL;
- QuestContainer* first = NULL;
- for(std::list<Quest*>::iterator it = quests.begin(); it != quests.end(); it++)
- {
- Quest* subQuest = *it;
- if(!subQuest->isInactive(player))
- {
- QuestContainer* subContainer = addSubQuest(subQuest, player);
-
- if(first == NULL)
- {
- first = subContainer;
- }
- else
- {
- current->next = subContainer;
- }
-
- current = subContainer;
- }
- }
- if(current != NULL)
- current->next = NULL;
- container->subQuests = first;
-
- return container;
+ return player;
}
- /**
- @brief
-
- @param quest
- @param player
- @return
- */
- HintContainer* QuestManager::addHints(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;
- return first;
- }
-
-
}
Modified: code/trunk/src/modules/questsystem/QuestManager.h
===================================================================
--- code/trunk/src/modules/questsystem/QuestManager.h 2009-09-12 15:39:07 UTC (rev 5744)
+++ code/trunk/src/modules/questsystem/QuestManager.h 2009-09-13 13:04:02 UTC (rev 5745)
@@ -35,6 +35,7 @@
#define _QuestManager_H__
#include "questsystem/QuestsystemPrereqs.h"
+#include <CEGUIForwardRefs.h>
#include <list>
#include <map>
@@ -43,28 +44,12 @@
#include "util/ScopedSingleton.h"
#include "core/OrxonoxClass.h"
+#include "QuestGUI.h"
+
// tolua_begin
namespace orxonox
{
- struct QuestContainer;
- struct HintContainer;
-
- struct QuestContainer
- {
- const QuestDescription* description;
- std::string status;
- HintContainer* hint;
- QuestContainer* subQuests;
- QuestContainer* next;
- };
-
- struct HintContainer
- {
- const QuestDescription* description;
- HintContainer* next;
- };
-
typedef ScopedSingleton<QuestManager, ScopeID::GSLevel> ScopedSingletonQuestManagerGSLevel; // workaround for tolua
/**
@@ -77,7 +62,11 @@
class _QuestsystemExport QuestManager : public ScopedSingletonQuestManagerGSLevel, public orxonox::OrxonoxClass
{
// tolua_end
+
friend class ScopedSingleton<QuestManager, ScopeID::GSLevel>;
+ friend class QuestGUI; //TDO: better solution.
+ //friend std::map<std::string, Quest*> & QuestGUI::getQuests(void);
+
public:
QuestManager();
virtual ~QuestManager();
@@ -85,23 +74,27 @@
//! Returns a reference to the single instance of the Quest Manager.
static QuestManager& getInstance() { return ScopedSingleton<QuestManager, ScopeID::GSLevel>::getInstance(); } // tolua_export
+ //! Retreive the main window for the GUI.
+ CEGUI::Window* getQuestGUI(const std::string & guiName); // tolua_export
+
bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
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.
- QuestContainer* getQuestTree(std::string & name); // tolua_export
+ protected:
+ std::map<std::string, Quest*> & getQuests(void); //!< Retreive all Quests.
private:
static QuestManager* singletonPtr_s;
+ PlayerInfo* retreivePlayer(const std::string & guiName); //!< Retrieve the player for a certain GUI.
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);
- HintContainer* addHints(Quest* quest, const PlayerInfo* player);
- QuestContainer* addSubQuest(Quest* quest, const PlayerInfo* player);
+ //TDO: Call destructor of QuestGUI's on destruction of QuestManager?
+ std::map<PlayerInfo*, QuestGUI*> questGUIs_; //!< All GUI's registered by the players.
}; // tolua_export
Modified: code/trunk/src/modules/questsystem/QuestsystemPrereqs.h
===================================================================
--- code/trunk/src/modules/questsystem/QuestsystemPrereqs.h 2009-09-12 15:39:07 UTC (rev 5744)
+++ code/trunk/src/modules/questsystem/QuestsystemPrereqs.h 2009-09-13 13:04:02 UTC (rev 5745)
@@ -75,6 +75,8 @@
class QuestDescription;
class QuestEffect;
class QuestEffectBeacon;
+ class QuestGUINode;
+ class QuestGUI;
class QuestHint;
class QuestItem;
class QuestListener;
More information about the Orxonox-commit
mailing list