Changeset 2785 for code/branches/questsystem5/src/orxonox/overlays
- Timestamp:
- Mar 15, 2009, 11:41:25 AM (16 years ago)
- Location:
- code/branches/questsystem5/src/orxonox/overlays/notifications
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/questsystem5/src/orxonox/overlays/notifications/Notification.cc
r2779 r2785 106 106 { 107 107 this->sender_ = sender; 108 bool successful = NotificationManager:: registerNotification(this);108 bool successful = NotificationManager::getInstance().registerNotification(this); 109 109 if(!successful) 110 110 return false; -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc
r2783 r2785 48 48 const std::string NotificationManager::NONE = "none"; 49 49 50 std::multimap<std::time_t,Notification*> NotificationManager::allNotificationsList_s; 51 std::map<int,std::multimap<std::time_t,Notification*>*> NotificationManager::notificationLists_s; 52 std::map<NotificationQueue*,int> NotificationManager::queueList_s; 53 54 int NotificationManager::highestIndex_s = 0; 50 NotificationManager* NotificationManager::singletonRef_s = NULL; 55 51 56 52 /** … … 58 54 Constructor. Registers the Object. 59 55 */ 60 NotificationManager::NotificationManager(BaseObject* creator) : BaseObject(creator) 61 { 62 RegisterObject(NotificationManager); 56 NotificationManager::NotificationManager() : BaseObject(this) 57 { 58 RegisterRootObject(NotificationManager); 59 60 this->highestIndex_ = 0; 63 61 } 64 62 … … 69 67 NotificationManager::~NotificationManager() 70 68 { 69 } 70 71 /** 72 @brief 73 Returns the current (and single) instance of the NotificationManager. Creates one, if there isn't one to begin with. 74 @return 75 Returns a reference to the single instance of the NotificationManager. 76 */ 77 /*static*/ NotificationManager & NotificationManager::getInstance() 78 { 79 if(singletonRef_s == NULL) 80 { 81 singletonRef_s = new NotificationManager(); 82 } 83 return *singletonRef_s; 71 84 } 72 85 … … 79 92 Returns true if successful. 80 93 */ 81 /*static*/bool NotificationManager::registerNotification(Notification* notification)94 bool NotificationManager::registerNotification(Notification* notification) 82 95 { 83 96 … … 87 100 std::time_t time = std::time(0); //TDO: Doesn't this expire? //!< Get current time. 88 101 89 allNotificationsList_s.insert(std::pair<std::time_t,Notification*>(time,notification));102 this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification)); 90 103 91 104 if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications. … … 97 110 98 111 //!< Insert the notification in all queues that have its sender as target. 99 for(std::map<NotificationQueue*,int>::iterator it = queueList_s.begin(); it != queueList_s.end(); it++) //!< Iterate through all queues.112 for(std::map<NotificationQueue*,int>::iterator it = this->queueList_.begin(); it != this->queueList_.end(); it++) //!< Iterate through all queues. 100 113 { 101 114 std::set<std::string> set = it->first->getTargetsSet(); 102 115 if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TDO: Make sure this works. 103 116 { 104 notificationLists_s[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue.117 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue. 105 118 it->first->update(notification, time); //!< Update the queue. 106 119 } … … 120 133 Returns true if successful. 121 134 */ 122 /*static*/bool NotificationManager::registerQueue(NotificationQueue* queue)123 { 124 NotificationManager::highestIndex_s+= 1;125 int index = NotificationManager::highestIndex_s;126 127 queueList_s[queue] = index; //!< Add the NotificationQueue to the list of queues.135 bool NotificationManager::registerQueue(NotificationQueue* queue) 136 { 137 this->highestIndex_ += 1; 138 int index = this->highestIndex_; 139 140 this->queueList_[queue] = index; //!< Add the NotificationQueue to the list of queues. 128 141 129 142 std::set<std::string> set = queue->getTargetsSet(); //TDO: Works this? … … 132 145 if(set.find(ALL) != set.end()) 133 146 { 134 notificationLists_s[index] = &allNotificationsList_s;147 this->notificationLists_[index] = &this->allNotificationsList_; 135 148 COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl; 136 149 return true; 137 150 } 138 151 139 notificationLists_s[index] = new std::multimap<std::time_t,Notification*>;140 std::multimap<std::time_t,Notification*> map = * notificationLists_s[index];152 this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>; 153 std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index]; 141 154 142 155 //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue. 143 for(std::multimap<std::time_t,Notification*>::iterator it = allNotificationsList_s.begin(); it != allNotificationsList_s.end(); it++)156 for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 144 157 { 145 158 if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target. … … 170 183 Make sure the map is deleted. 171 184 */ 172 /*static*/std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)173 { 174 std::multimap<std::time_t,Notification*>* notifications = NotificationManager::notificationLists_s[NotificationManager::queueList_s[queue]];185 std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd) 186 { 187 std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]]; 175 188 176 189 if(notifications == NULL) -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h
r2779 r2785 50 50 /** 51 51 @brief 52 The NotificationManager functions as a gateway between Notifications and NotificationQueues.52 The Singleton NotificationManager functions as a gateway between Notifications and NotificationQueues. 53 53 It receives, organizes Notifications and the redistributes them to the specific NotificationQueues. 54 54 @author … … 57 57 class _OrxonoxExport NotificationManager : public BaseObject 58 58 { 59 protected: 60 NotificationManager(); 61 59 62 public: 60 NotificationManager(BaseObject* creator);61 63 virtual ~NotificationManager(); 62 64 … … 64 66 static const std::string NONE; 65 67 68 static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager. 69 66 70 //TDO: Visibility? 67 staticbool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.68 staticbool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.71 bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. 72 bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager. 69 73 70 st atic 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.74 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. 71 75 72 76 /** … … 76 80 @return Returns a time-ordered list of Notifications. 77 81 */ 78 st atic std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart)79 { return NotificationManager::getNotifications(queue, timeFrameStart, std::time(0)); }82 std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart) 83 { return this->getNotifications(queue, timeFrameStart, std::time(0)); } 80 84 /** 81 85 @brief Fetches the Notifications for a specific NotificationQueue starting at a specified timespan before now. … … 84 88 @return Returns a time-ordered list of Notifications. 85 89 */ 86 st atic std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay)87 { return NotificationManager::getNotifications(queue, std::time(0)-timeDelay, std::time(0)); }90 std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay) 91 { return this->getNotifications(queue, std::time(0)-timeDelay, std::time(0)); } 88 92 89 private: 90 static int highestIndex_s; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. 93 private: 94 static NotificationManager* singletonRef_s; 95 96 int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. 91 97 92 st atic std::multimap<std::time_t,Notification*> allNotificationsList_s; //!< Container where all notifications are stored (together with their respecive timestamps).93 st atic std::map<NotificationQueue*,int> queueList_s; //!< Container where all NotificationQueues are stored with a number as identifier.94 st atic std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_s; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.98 std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored (together with their respecive timestamps). 99 std::map<NotificationQueue*,int> queueList_; //!< Container where all NotificationQueues are stored with a number as identifier. 100 std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored. 95 101 96 102 -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationOverlay.cc
r2783 r2785 74 74 this->setFont(this->queue_->getFont()); 75 75 this->setTextSize(this->queue_->getFontSize()); 76 77 this->setPosition(this->queue_->getPosition()); 76 78 } 77 79 -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc
r2783 r2785 46 46 47 47 const std::string NotificationQueue::DEFAULT_FONT = "VeraMono"; 48 const Vector2 NotificationQueue::DEFAULT_POSITION = Vector2(0.0,0.0); 48 49 49 50 /** … … 78 79 this->tickTime_ = 0.0; 79 80 80 NotificationManager:: registerQueue(this);81 NotificationManager::getInstance().registerQueue(this); 81 82 } 82 83 … … 90 91 this->setNotificationLength(DEFAULT_LENGTH); 91 92 this->setDisplayTime(DEFAULT_DISPLAY_TIME); 93 this->setPosition(DEFAULT_POSITION); 92 94 93 95 this->setTargets(NotificationManager::ALL); … … 113 115 XMLPortParam(NotificationQueue, "font", setFont, getFont, xmlElement, mode); 114 116 XMLPortParam(NotificationQueue, "fontSize", setFontSize, getFontSize, xmlElement, mode); 117 XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlElement, mode); 115 118 116 119 COUT(3) << "NotificationQueue created." << std::endl; … … 152 155 this->clear(); 153 156 154 std::multimap<std::time_t,Notification*>* notifications = NotificationManager::get Notifications(this, this->displayTime_);157 std::multimap<std::time_t,Notification*>* notifications = NotificationManager::getInstance().getNotifications(this, this->displayTime_); 155 158 156 159 if(notifications == NULL) … … 315 318 return false; 316 319 this->fontSize_ = size; 317 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Set the font size for each overlay.320 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font size for each overlay. 318 321 { 319 322 it->second->overlay->setFontSize(size); … … 333 336 { 334 337 this->font_ = font; 335 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Set the font for each overlay.338 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font for each overlay. 336 339 { 337 340 it->second->overlay->setFont(font); … … 345 348 { 346 349 it->second->overlay->scroll(pos); 350 } 351 } 352 353 void NotificationQueue::positionChanged() 354 { 355 int counter = 0; 356 for (std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); it != this->containers_.end(); it++) //!< Set the position for each overlay. 357 { 358 (*it)->overlay->setPosition(this->getPosition()); 359 (*it)->overlay->scroll(Vector2(0.0,(1.1*this->getFontSize())*counter)); 360 counter++; 347 361 } 348 362 } -
code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h
r2783 r2785 44 44 #include <map> 45 45 #include <ctime> 46 #include "util/Math.h"47 46 48 47 #include "orxonox/overlays/OverlayGroup.h" … … 114 113 inline int getDisplayTime() const 115 114 { return this->displayTime_; } 116 117 115 /** 118 @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.119 @return Retu ns a set of string holding the different targets.116 @brief Returns the position of the NotificationQueue. 117 @return Returns the position. 120 118 */ 121 inline const std::set<std::string> & getTargetsSet() 122 { return this->targets_; } 123 bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets. 124 119 inline const Vector2 & getPosition() const 120 { return this->position_; } 125 121 /** 126 122 @brief Returns the font size used to display the Notifications. … … 135 131 inline const std::string & getFont() const 136 132 { return this->font_; } 133 134 /** 135 @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue. 136 @return Retuns a set of string holding the different targets. 137 */ 138 inline const std::set<std::string> & getTargetsSet() 139 { return this->targets_; } 140 bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets. 141 142 inline void setPosition(Vector2 pos) 143 { this->position_ = pos; this->positionChanged(); } 137 144 138 145 void scroll(const Vector2 pos); … … 142 149 static const int DEFAULT_LENGTH = 64; //!< The default maximum number of Notifications displayed. 143 150 static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 144 static const float DEFAULT_FONT_SIZE = 0.02; //!< The default font size. 151 static const float DEFAULT_FONT_SIZE = 0.025; //!< The default font size. 152 145 153 static const std::string DEFAULT_FONT; //!< The default font. 154 static const Vector2 DEFAULT_POSITION; //!< the default position. 146 155 147 156 int maxSize_; //!< The maximal number of Notifications displayed. … … 149 158 int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have. 150 159 int displayTime_; //!< The time a Notification is displayed. 160 Vector2 position_; //!< The position of the NotificationQueue. 151 161 152 162 std::set<std::string> targets_; //!< The targets the Queue displays Notifications of. … … 172 182 bool setFontSize(float size); //!< Set the font size. 173 183 bool setFont(const std::string & font); //!< Set the font. 184 185 void positionChanged(); 174 186 175 187 void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
Note: See TracChangeset
for help on using the changeset viewer.