[Orxonox-commit 409] r2993 - in trunk/src/orxonox: objects/quest overlays
dafrick at orxonox.net
dafrick at orxonox.net
Wed May 20 00:23:51 CEST 2009
Author: dafrick
Date: 2009-05-20 00:23:51 +0200 (Wed, 20 May 2009)
New Revision: 2993
Modified:
trunk/src/orxonox/objects/quest/QuestManager.cc
trunk/src/orxonox/objects/quest/QuestManager.h
trunk/src/orxonox/overlays/OrxonoxOverlay.cc
trunk/src/orxonox/overlays/OrxonoxOverlay.h
Log:
Small changes in QuestManager for the GUI. Added toggleVisibility command to OrxonoxOverlay.
Modified: trunk/src/orxonox/objects/quest/QuestManager.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestManager.cc 2009-05-19 20:05:30 UTC (rev 2992)
+++ trunk/src/orxonox/objects/quest/QuestManager.cc 2009-05-19 22:23:51 UTC (rev 2993)
@@ -37,10 +37,10 @@
#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 "objects/infos/PlayerInfo.h"
#include "Quest.h"
#include "QuestHint.h"
@@ -48,10 +48,7 @@
{
//! Pointer to the current (and single) instance of this class.
/*static*/ QuestManager* QuestManager::singletonRef_s = NULL;
- /*static*/ bool QuestManager::GUIOpen = false;
- SetConsoleCommand(QuestManager, toggleQuestGUI, true);
-
/**
@brief
Constructor. Registers the object.
@@ -219,6 +216,12 @@
}
+ /**
+ @brief
+
+ @param name
+ @return
+ */
QuestContainer* QuestManager::getQuestTree(std::string & name)
{
GUIOverlay* gui = GUIManager::getInstance().getOverlay(name);
@@ -226,29 +229,27 @@
PlayerInfo* player;
if(gui == NULL)
{
- COUT(1) << "Something BAD happened." << std::endl;
+ COUT(1) << "Error: No GUIOverlay with the given name '" << name << "' present." << std::endl;
return NULL;
}
- COUT(1) << player << std::endl;
- ConverterExplicit<BaseObject, PlayerInfo>::convert(player, *(gui->getOwner()));
+ BaseObject* obj = gui->getOwner();
+ if(obj == NULL)
+ {
+ COUT(1) << "Error: GUIOverlay has no owner. " << std::endl;
+ return NULL;
+ }
+ player = dynamic_cast<PlayerInfo*>(obj);
QuestContainer* root = NULL;
QuestContainer* current = NULL;
- std::list<Quest*>* pRootQuests = new std::list<Quest*>();
- std::list<Quest*> rootQuests = *pRootQuests;
- getRootQuests(player, rootQuests);
+ std::list<Quest*>* rootQuests = new std::list<Quest*>();
+ getRootQuests(player, *rootQuests);
- for(std::list<Quest*>::iterator it = rootQuests.begin(); it != rootQuests.end(); it++)
+ for(std::list<Quest*>::iterator it = rootQuests->begin(); it != rootQuests->end(); it++)
{
- Quest* quest = *it;
-
- QuestContainer* container = new QuestContainer;
+ QuestContainer* container = addSubQuest(*it, player);
- container->description = quest->getDescription();
- addHints(container, quest, player);
- addSubQuests(container, quest, player);
-
if(root == NULL)
{
root = container;
@@ -264,11 +265,18 @@
if(current != NULL)
current->next = NULL;
- delete pRootQuests;
+ delete rootQuests;
return root;
}
+ /**
+ @brief
+
+ @param player
+ @param list
+ @return
+ */
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++)
@@ -281,43 +289,77 @@
}
}
- void QuestManager::addSubQuests(QuestContainer* container, Quest* quest, const PlayerInfo* player)
+ /**
+ @brief
+
+ @param quest
+ @param player
+ @return
+ */
+ QuestContainer* QuestManager::addSubQuest(Quest* quest, const PlayerInfo* player)
{
+ if(quest == NULL)
+ 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 occured. A Quest of un-specified status wanted to be displayed." << std::endl;
+ }
+
+ std::list<Quest*> quests = quest->getSubQuestList();
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;
+ QuestContainer* subContainer = addSubQuest(subQuest, player);
- subQuestContainer->description = subQuest->getDescription();
- addHints(subQuestContainer, subQuest, player);
- addSubQuests(subQuestContainer, subQuest, player);
-
if(first == NULL)
{
- first = subQuestContainer;
+ first = subContainer;
}
else
{
- current->next = subQuestContainer;
+ current->next = subContainer;
}
- current = subQuestContainer;
+ current = subContainer;
}
}
-
if(current != NULL)
current->next = NULL;
container->subQuests = first;
+ return container;
}
- void QuestManager::addHints(QuestContainer* container, Quest* quest, const PlayerInfo* player)
+ /**
+ @brief
+
+ @param quest
+ @param player
+ @return
+ */
+ HintContainer* QuestManager::addHints(Quest* quest, const PlayerInfo* player)
{
HintContainer* current = NULL;
HintContainer* first = NULL;
@@ -345,27 +387,8 @@
if(current != NULL)
current->next = NULL;
- container->hint = first;
+ return 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-19 20:05:30 UTC (rev 2992)
+++ trunk/src/orxonox/objects/quest/QuestManager.h 2009-05-19 22:23:51 UTC (rev 2993)
@@ -54,6 +54,7 @@
struct QuestContainer
{
const QuestDescription* description;
+ std::string status;
HintContainer* hint;
QuestContainer* subQuests;
QuestContainer* next;
@@ -92,18 +93,15 @@
QuestContainer* getQuestTree(std::string & name); // tolua_export
- static void toggleQuestGUI(void); //!< Opens the GUI.
-
private:
static QuestManager* singletonRef_s;
- static bool GUIOpen;
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);
+ HintContainer* addHints(Quest* quest, const PlayerInfo* player);
+ QuestContainer* addSubQuest(Quest* quest, const PlayerInfo* player);
}; // tolua_export
Modified: trunk/src/orxonox/overlays/OrxonoxOverlay.cc
===================================================================
--- trunk/src/orxonox/overlays/OrxonoxOverlay.cc 2009-05-19 20:05:30 UTC (rev 2992)
+++ trunk/src/orxonox/overlays/OrxonoxOverlay.cc 2009-05-19 22:23:51 UTC (rev 2993)
@@ -56,6 +56,7 @@
SetConsoleCommand(OrxonoxOverlay, scaleOverlay, false).accessLevel(AccessLevel::User);
SetConsoleCommand(OrxonoxOverlay, scrollOverlay, false).accessLevel(AccessLevel::User);
+ SetConsoleCommand(OrxonoxOverlay, toggleVisibility, false).accessLevel(AccessLevel::User);
SetConsoleCommand(OrxonoxOverlay, rotateOverlay, false).accessLevel(AccessLevel::User);
OrxonoxOverlay::OrxonoxOverlay(BaseObject* creator)
@@ -310,6 +311,26 @@
/**
@brief
+ Toggles the visibility of an Overlay by it's name.
+ @param name
+ The name of the overlay defined BaseObject::setName() (usually done with the "name"
+ attribute in the xml file).
+ */
+ /*static*/ void OrxonoxOverlay::toggleVisibility(const std::string& name)
+ {
+ std::map<std::string, OrxonoxOverlay*>::const_iterator it = overlays_s.find(name);
+ if (it != overlays_s.end())
+ {
+ OrxonoxOverlay* overlay= (*it).second;
+ if(overlay->isVisible())
+ overlay->hide();
+ else
+ overlay->show();
+ }
+ }
+
+ /**
+ @brief
Scrolls an overlay by its name.
@param name
The name of the overlay defined BaseObject::setName() (usually done with the "name"
Modified: trunk/src/orxonox/overlays/OrxonoxOverlay.h
===================================================================
--- trunk/src/orxonox/overlays/OrxonoxOverlay.h 2009-05-19 20:05:30 UTC (rev 2992)
+++ trunk/src/orxonox/overlays/OrxonoxOverlay.h 2009-05-19 22:23:51 UTC (rev 2993)
@@ -148,6 +148,7 @@
static void scaleOverlay(const std::string& name, float scale);
//! ConsoleCommand: Accesses the overlay by its name and scrolls it.
static void scrollOverlay(const std::string& name, const Vector2& scroll);
+ static void toggleVisibility(const std::string& name);
//! ConsoleCommand: Accesses the overlay by its name and rotates it.
static void rotateOverlay(const std::string& name, const Degree& angle);
More information about the Orxonox-commit
mailing list