[Orxonox-commit 88] r2785 - in branches/questsystem5/src/orxonox: objects/quest overlays/notifications
dafrick at orxonox.net
dafrick at orxonox.net
Sun Mar 15 11:41:25 CET 2009
Author: dafrick
Date: 2009-03-15 10:41:25 +0000 (Sun, 15 Mar 2009)
New Revision: 2785
Modified:
branches/questsystem5/src/orxonox/objects/quest/AddQuest.cc
branches/questsystem5/src/orxonox/objects/quest/AddQuestHint.cc
branches/questsystem5/src/orxonox/objects/quest/CompleteQuest.cc
branches/questsystem5/src/orxonox/objects/quest/FailQuest.cc
branches/questsystem5/src/orxonox/objects/quest/Quest.cc
branches/questsystem5/src/orxonox/objects/quest/QuestHint.cc
branches/questsystem5/src/orxonox/objects/quest/QuestListener.cc
branches/questsystem5/src/orxonox/objects/quest/QuestManager.cc
branches/questsystem5/src/orxonox/objects/quest/QuestManager.h
branches/questsystem5/src/orxonox/overlays/notifications/Notification.cc
branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc
branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h
branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc
branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h
Log:
Made QuestManager and NotificationManager to Singletons. Fixed/Changed som other stuff I don't remember...
Modified: branches/questsystem5/src/orxonox/objects/quest/AddQuest.cc
===================================================================
--- branches/questsystem5/src/orxonox/objects/quest/AddQuest.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/objects/quest/AddQuest.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -96,7 +96,7 @@
try
{
- Quest* quest = QuestManager::findQuest(this->getQuestId());
+ Quest* quest = QuestManager::getInstance().findQuest(this->getQuestId());
if(quest == NULL || !quest->start(player))
{
return false;
Modified: branches/questsystem5/src/orxonox/objects/quest/AddQuestHint.cc
===================================================================
--- branches/questsystem5/src/orxonox/objects/quest/AddQuestHint.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/objects/quest/AddQuestHint.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -116,7 +116,7 @@
try
{
- QuestHint* hint = QuestManager::findHint(this->hintId_);
+ QuestHint* hint = QuestManager::getInstance().findHint(this->hintId_);
if(hint == NULL || !hint->setActive(player))
{
return false;
Modified: branches/questsystem5/src/orxonox/objects/quest/CompleteQuest.cc
===================================================================
--- branches/questsystem5/src/orxonox/objects/quest/CompleteQuest.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/objects/quest/CompleteQuest.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -95,7 +95,7 @@
try
{
- quest = QuestManager::findQuest(this->getQuestId());
+ quest = QuestManager::getInstance().findQuest(this->getQuestId());
if(quest == NULL || !quest->complete(player))
{
return false;
Modified: branches/questsystem5/src/orxonox/objects/quest/FailQuest.cc
===================================================================
--- branches/questsystem5/src/orxonox/objects/quest/FailQuest.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/objects/quest/FailQuest.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -94,7 +94,7 @@
Quest* quest;
try
{
- quest = QuestManager::findQuest(this->getQuestId());
+ quest = QuestManager::getInstance().findQuest(this->getQuestId());
if(quest == NULL || !quest->fail(player))
{
return false;
Modified: branches/questsystem5/src/orxonox/objects/quest/Quest.cc
===================================================================
--- branches/questsystem5/src/orxonox/objects/quest/Quest.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/objects/quest/Quest.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -78,7 +78,7 @@
XMLPortObject(Quest, QuestEffect, "fail-effects", addFailEffect, getFailEffect, xmlelement, mode);
XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffect, xmlelement, mode);
- QuestManager::registerQuest(this); //!<Registers the Quest with the QuestManager.
+ QuestManager::getInstance().registerQuest(this); //!<Registers the Quest with the QuestManager.
}
/**
Modified: branches/questsystem5/src/orxonox/objects/quest/QuestHint.cc
===================================================================
--- branches/questsystem5/src/orxonox/objects/quest/QuestHint.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/objects/quest/QuestHint.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -72,7 +72,7 @@
{
SUPER(QuestHint, XMLPort, xmlelement, mode);
- QuestManager::registerHint(this); //!< Registers the QuestHint with the QuestManager.
+ QuestManager::getInstance().registerHint(this); //!< Registers the QuestHint with the QuestManager.
COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl;
}
Modified: branches/questsystem5/src/orxonox/objects/quest/QuestListener.cc
===================================================================
--- branches/questsystem5/src/orxonox/objects/quest/QuestListener.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/objects/quest/QuestListener.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -111,7 +111,7 @@
*/
bool QuestListener::setQuestId(const std::string & id)
{
- this->quest_ = QuestManager::findQuest(id); //!< Find the Quest corresponding to the given questId.
+ this->quest_ = QuestManager::getInstance().findQuest(id); //!< Find the Quest corresponding to the given questId.
if(this->quest_ == NULL) //!< If there is no such Quest.
{
Modified: branches/questsystem5/src/orxonox/objects/quest/QuestManager.cc
===================================================================
--- branches/questsystem5/src/orxonox/objects/quest/QuestManager.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/objects/quest/QuestManager.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -42,18 +42,19 @@
namespace orxonox
{
- //! All Quests registered by their id's.
- std::map<std::string, Quest*> QuestManager::questMap_s;
- //! All QuestHints registered by their id's.
- std::map<std::string, QuestHint*> QuestManager::hintMap_s;
+ //! Pointer to the current (and single) instance of this class.
+ QuestManager* QuestManager::singletonRef_s = NULL;
/**
@brief
Constructor. Registers the object.
+ @todo
+ Is inheriting from BaseObject proper?
*/
- QuestManager::QuestManager(BaseObject* creator) : BaseObject(creator)
+ QuestManager::QuestManager() : BaseObject(this)
{
- RegisterObject(QuestManager);
+ RegisterRootObject(QuestManager);
+
}
/**
@@ -67,6 +68,21 @@
/**
@brief
+ Returns a reference to the current (and single) instance of the QuestManager, and creates one if there isn't one to begin with.
+ @return
+ Returns a reference to the single instance of the Quest Manager.
+ */
+ /*static*/ QuestManager & QuestManager::getInstance()
+ {
+ if(singletonRef_s == NULL)
+ {
+ singletonRef_s = new QuestManager();
+ }
+ return *singletonRef_s;
+ }
+
+ /**
+ @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
@@ -74,7 +90,7 @@
@return
Returns true if successful, false if not.
*/
- /*static*/ bool QuestManager::registerQuest(Quest* quest)
+ bool QuestManager::registerQuest(Quest* quest)
{
if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers.
{
@@ -83,7 +99,7 @@
}
std::pair<std::map<std::string, Quest*>::iterator,bool> result;
- result = questMap_s.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
+ result = this->questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
if(result.second) //!< If inserting was a success.
{
@@ -106,7 +122,7 @@
@return
Returns true if successful, false if not.
*/
- /*static*/ bool QuestManager::registerHint(QuestHint* hint)
+ bool QuestManager::registerHint(QuestHint* hint)
{
if(hint == NULL) //!< Still not liking NULL-pointers.
{
@@ -115,7 +131,7 @@
}
std::pair<std::map<std::string, QuestHint*>::iterator,bool> result;
- result = hintMap_s.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
+ result = this->hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
if(result.second) //!< If inserting was a success.
{
@@ -140,7 +156,7 @@
@throws
Throws an exception if the given questId is invalid.
*/
- /*static*/ Quest* QuestManager::findQuest(const std::string & questId)
+ Quest* QuestManager::findQuest(const std::string & questId)
{
if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
{
@@ -148,8 +164,8 @@
}
Quest* quest;
- std::map<std::string, Quest*>::iterator it = questMap_s.find(questId);
- if (it != questMap_s.end()) //!< If the Quest is registered.
+ std::map<std::string, Quest*>::iterator it = this->questMap_.find(questId);
+ if (it != this->questMap_.end()) //!< If the Quest is registered.
{
quest = it->second;
}
@@ -174,7 +190,7 @@
@throws
Throws an exception if the given hintId is invalid.
*/
- /*static*/ QuestHint* QuestManager::findHint(const std::string & hintId)
+ QuestHint* QuestManager::findHint(const std::string & hintId)
{
if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
{
@@ -182,8 +198,8 @@
}
QuestHint* hint;
- std::map<std::string, QuestHint*>::iterator it = hintMap_s.find(hintId);
- if (it != hintMap_s.end()) //!< If the QuestHint is registered.
+ std::map<std::string, QuestHint*>::iterator it = this->hintMap_.find(hintId);
+ if (it != this->hintMap_.end()) //!< If the QuestHint is registered.
{
hint = it->second;
}
Modified: branches/questsystem5/src/orxonox/objects/quest/QuestManager.h
===================================================================
--- branches/questsystem5/src/orxonox/objects/quest/QuestManager.h 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/objects/quest/QuestManager.h 2009-03-15 10:41:25 UTC (rev 2785)
@@ -45,7 +45,7 @@
{
/**
@brief
- Is a static class and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()).
+ Is a Singleton and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()).
Quests (and QuestHints) are registered in the QuestManager with their id, and can be accessed in the same way.
@author
Damian 'Mozork' Frick
@@ -53,20 +53,26 @@
class _OrxonoxExport QuestManager : public BaseObject
{
+ protected:
+ QuestManager();
+
public:
- QuestManager(BaseObject* creator);
virtual ~QuestManager();
- static bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
- static bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
+ static QuestManager& getInstance(); //!< Returns a reference to the single instance of the Quest Manager.
- static Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id.
- static QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
+ 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.
+
private:
- static std::map<std::string, Quest*> questMap_s; //!< All Quests registered by their id's.
- static std::map<std::string, QuestHint*> hintMap_s; //!< All QuestHints registered by their id's.
+ static QuestManager* singletonRef_s;
+ 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.
+
};
}
Modified: branches/questsystem5/src/orxonox/overlays/notifications/Notification.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/Notification.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/overlays/notifications/Notification.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -105,7 +105,7 @@
bool Notification::send(const std::string & sender)
{
this->sender_ = sender;
- bool successful = NotificationManager::registerNotification(this);
+ bool successful = NotificationManager::getInstance().registerNotification(this);
if(!successful)
return false;
this->sent_ = true;
Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -47,19 +47,17 @@
const std::string NotificationManager::ALL = "all";
const std::string NotificationManager::NONE = "none";
- std::multimap<std::time_t,Notification*> NotificationManager::allNotificationsList_s;
- std::map<int,std::multimap<std::time_t,Notification*>*> NotificationManager::notificationLists_s;
- std::map<NotificationQueue*,int> NotificationManager::queueList_s;
-
- int NotificationManager::highestIndex_s = 0;
+ NotificationManager* NotificationManager::singletonRef_s = NULL;
/**
@brief
Constructor. Registers the Object.
*/
- NotificationManager::NotificationManager(BaseObject* creator) : BaseObject(creator)
+ NotificationManager::NotificationManager() : BaseObject(this)
{
- RegisterObject(NotificationManager);
+ RegisterRootObject(NotificationManager);
+
+ this->highestIndex_ = 0;
}
/**
@@ -69,6 +67,21 @@
NotificationManager::~NotificationManager()
{
}
+
+ /**
+ @brief
+ Returns the current (and single) instance of the NotificationManager. Creates one, if there isn't one to begin with.
+ @return
+ Returns a reference to the single instance of the NotificationManager.
+ */
+ /*static*/ NotificationManager & NotificationManager::getInstance()
+ {
+ if(singletonRef_s == NULL)
+ {
+ singletonRef_s = new NotificationManager();
+ }
+ return *singletonRef_s;
+ }
/**
@brief
@@ -78,7 +91,7 @@
@return
Returns true if successful.
*/
- /*static*/ bool NotificationManager::registerNotification(Notification* notification)
+ bool NotificationManager::registerNotification(Notification* notification)
{
if(notification == NULL) //!< A NULL-Notification cannot be registered.
@@ -86,7 +99,7 @@
std::time_t time = std::time(0); //TDO: Doesn't this expire? //!< Get current time.
- allNotificationsList_s.insert(std::pair<std::time_t,Notification*>(time,notification));
+ this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification));
if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications.
return true;
@@ -96,12 +109,12 @@
all = true;
//!< Insert the notification in all queues that have its sender as target.
- for(std::map<NotificationQueue*,int>::iterator it = queueList_s.begin(); it != queueList_s.end(); it++) //!< Iterate through all queues.
+ for(std::map<NotificationQueue*,int>::iterator it = this->queueList_.begin(); it != this->queueList_.end(); it++) //!< Iterate through all queues.
{
std::set<std::string> set = it->first->getTargetsSet();
if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TDO: Make sure this works.
{
- notificationLists_s[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue.
+ this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue.
it->first->update(notification, time); //!< Update the queue.
}
}
@@ -119,28 +132,28 @@
@return
Returns true if successful.
*/
- /*static*/ bool NotificationManager::registerQueue(NotificationQueue* queue)
+ bool NotificationManager::registerQueue(NotificationQueue* queue)
{
- NotificationManager::highestIndex_s += 1;
- int index = NotificationManager::highestIndex_s;
+ this->highestIndex_ += 1;
+ int index = this->highestIndex_;
- queueList_s[queue] = index; //!< Add the NotificationQueue to the list of queues.
+ this->queueList_[queue] = index; //!< Add the NotificationQueue to the list of queues.
std::set<std::string> set = queue->getTargetsSet(); //TDO: Works this?
//! If all senders are the target of the queue, then the list of notification for that specific queue is te same as the list of all Notifications.
if(set.find(ALL) != set.end())
{
- notificationLists_s[index] = &allNotificationsList_s;
+ this->notificationLists_[index] = &this->allNotificationsList_;
COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
return true;
}
- notificationLists_s[index] = new std::multimap<std::time_t,Notification*>;
- std::multimap<std::time_t,Notification*> map = *notificationLists_s[index];
+ this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>;
+ std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index];
//! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue.
- for(std::multimap<std::time_t,Notification*>::iterator it = allNotificationsList_s.begin(); it != allNotificationsList_s.end(); it++)
+ for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
{
if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target.
{
@@ -169,9 +182,9 @@
@todo
Make sure the map is deleted.
*/
- /*static*/ std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
+ std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
{
- std::multimap<std::time_t,Notification*>* notifications = NotificationManager::notificationLists_s[NotificationManager::queueList_s[queue]];
+ std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]];
if(notifications == NULL)
return NULL;
Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h 2009-03-15 10:41:25 UTC (rev 2785)
@@ -49,25 +49,29 @@
/**
@brief
- The NotificationManager functions as a gateway between Notifications and NotificationQueues.
+ The Singleton NotificationManager functions as a gateway between Notifications and NotificationQueues.
It receives, organizes Notifications and the redistributes them to the specific NotificationQueues.
@author
Damian 'Mozork' Frick
*/
class _OrxonoxExport NotificationManager : public BaseObject
{
+ protected:
+ NotificationManager();
+
public:
- NotificationManager(BaseObject* creator);
virtual ~NotificationManager();
static const std::string ALL;
static const std::string NONE;
+ static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager.
+
//TDO: Visibility?
- static bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
- static bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
+ bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
+ bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
- static std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
+ std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
/**
@brief Fetches the Notifications for a specific NotificationQueue starting at a specified time.
@@ -75,23 +79,25 @@
@param timeFrameStart The start time the Notifications are fetched from.
@return Returns a time-ordered list of Notifications.
*/
- static std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart)
- { return NotificationManager::getNotifications(queue, timeFrameStart, std::time(0)); }
+ std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart)
+ { return this->getNotifications(queue, timeFrameStart, std::time(0)); }
/**
@brief Fetches the Notifications for a specific NotificationQueue starting at a specified timespan before now.
@param queue The NotificationQueue the Notifications are fetched for.
@param timeDelay The timespan.
@return Returns a time-ordered list of Notifications.
*/
- static std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay)
- { return NotificationManager::getNotifications(queue, std::time(0)-timeDelay, std::time(0)); }
+ std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay)
+ { return this->getNotifications(queue, std::time(0)-timeDelay, std::time(0)); }
- private:
- static int highestIndex_s; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
+ private:
+ static NotificationManager* singletonRef_s;
+
+ int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
- static std::multimap<std::time_t,Notification*> allNotificationsList_s; //!< Container where all notifications are stored (together with their respecive timestamps).
- static std::map<NotificationQueue*,int> queueList_s; //!< Container where all NotificationQueues are stored with a number as identifier.
- static std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_s; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
+ std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored (together with their respecive timestamps).
+ std::map<NotificationQueue*,int> queueList_; //!< Container where all NotificationQueues are stored with a number as identifier.
+ std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
};
Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -73,6 +73,8 @@
{
this->setFont(this->queue_->getFont());
this->setTextSize(this->queue_->getFontSize());
+
+ this->setPosition(this->queue_->getPosition());
}
NotificationOverlay::~NotificationOverlay()
Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc 2009-03-15 10:41:25 UTC (rev 2785)
@@ -45,6 +45,7 @@
CreateFactory(NotificationQueue);
const std::string NotificationQueue::DEFAULT_FONT = "VeraMono";
+ const Vector2 NotificationQueue::DEFAULT_POSITION = Vector2(0.0,0.0);
/**
@brief
@@ -77,7 +78,7 @@
this->size_ = 0;
this->tickTime_ = 0.0;
- NotificationManager::registerQueue(this);
+ NotificationManager::getInstance().registerQueue(this);
}
/**
@@ -89,6 +90,7 @@
this->setMaxSize(DEFAULT_SIZE);
this->setNotificationLength(DEFAULT_LENGTH);
this->setDisplayTime(DEFAULT_DISPLAY_TIME);
+ this->setPosition(DEFAULT_POSITION);
this->setTargets(NotificationManager::ALL);
@@ -112,6 +114,7 @@
XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlElement, mode);
XMLPortParam(NotificationQueue, "font", setFont, getFont, xmlElement, mode);
XMLPortParam(NotificationQueue, "fontSize", setFontSize, getFontSize, xmlElement, mode);
+ XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlElement, mode);
COUT(3) << "NotificationQueue created." << std::endl;
}
@@ -151,7 +154,7 @@
{
this->clear();
- std::multimap<std::time_t,Notification*>* notifications = NotificationManager::getNotifications(this, this->displayTime_);
+ std::multimap<std::time_t,Notification*>* notifications = NotificationManager::getInstance().getNotifications(this, this->displayTime_);
if(notifications == NULL)
return;
@@ -314,7 +317,7 @@
if(size <= 0)
return false;
this->fontSize_ = size;
- for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Set the font size for each overlay.
+ for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font size for each overlay.
{
it->second->overlay->setFontSize(size);
}
@@ -332,7 +335,7 @@
bool NotificationQueue::setFont(const std::string & font)
{
this->font_ = font;
- for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Set the font for each overlay.
+ for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font for each overlay.
{
it->second->overlay->setFont(font);
}
@@ -347,6 +350,17 @@
}
}
+ void NotificationQueue::positionChanged()
+ {
+ int counter = 0;
+ for (std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); it != this->containers_.end(); it++) //!< Set the position for each overlay.
+ {
+ (*it)->overlay->setPosition(this->getPosition());
+ (*it)->overlay->scroll(Vector2(0.0,(1.1*this->getFontSize())*counter));
+ counter++;
+ }
+ }
+
/**
@brief
Adds a Notification, to the queue.
Modified: branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h
===================================================================
--- branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h 2009-03-15 00:26:23 UTC (rev 2784)
+++ branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h 2009-03-15 10:41:25 UTC (rev 2785)
@@ -43,7 +43,6 @@
#include <OgrePanelOverlayElement.h>
#include <map>
#include <ctime>
-#include "util/Math.h"
#include "orxonox/overlays/OverlayGroup.h"
#include "orxonox/objects/Tickable.h"
@@ -113,15 +112,12 @@
*/
inline int getDisplayTime() const
{ return this->displayTime_; }
-
/**
- @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
- @return Retuns a set of string holding the different targets.
+ @brief Returns the position of the NotificationQueue.
+ @return Returns the position.
*/
- inline const std::set<std::string> & getTargetsSet()
- { return this->targets_; }
- bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
-
+ inline const Vector2 & getPosition() const
+ { return this->position_; }
/**
@brief Returns the font size used to display the Notifications.
@return Returns the font size.
@@ -134,6 +130,17 @@
*/
inline const std::string & getFont() const
{ return this->font_; }
+
+ /**
+ @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
+ @return Retuns a set of string holding the different targets.
+ */
+ inline const std::set<std::string> & getTargetsSet()
+ { return this->targets_; }
+ bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
+
+ inline void setPosition(Vector2 pos)
+ { this->position_ = pos; this->positionChanged(); }
void scroll(const Vector2 pos);
@@ -141,13 +148,16 @@
static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
static const int DEFAULT_LENGTH = 64; //!< The default maximum number of Notifications displayed.
static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
- static const float DEFAULT_FONT_SIZE = 0.02; //!< The default font size.
+ static const float DEFAULT_FONT_SIZE = 0.025; //!< The default font size.
+
static const std::string DEFAULT_FONT; //!< The default font.
+ static const Vector2 DEFAULT_POSITION; //!< the default position.
int maxSize_; //!< The maximal number of Notifications displayed.
int size_; //!< The number of Notifications displayed.
int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have.
int displayTime_; //!< The time a Notification is displayed.
+ Vector2 position_; //!< The position of the NotificationQueue.
std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
@@ -171,6 +181,8 @@
bool setFontSize(float size); //!< Set the font size.
bool setFont(const std::string & font); //!< Set the font.
+
+ void positionChanged();
void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue.
More information about the Orxonox-commit
mailing list