- Timestamp:
- May 12, 2011, 12:31:23 AM (13 years ago)
- Location:
- code/branches/tutoriallevel3
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/tutoriallevel3
- Property svn:mergeinfo changed
/code/branches/tutoriallevel (added) merged: 7828-7831,7894,8370 /code/branches/tutoriallevel2 (added) merged: 8371,8374,8376-8378,8444-8451
- Property svn:mergeinfo changed
-
code/branches/tutoriallevel3/src/modules/notifications/NotificationQueue.cc
r8079 r8453 38 38 39 39 #include "core/CoreIncludes.h" 40 #include "core/GameMode.h"41 #include "core/GUIManager.h"42 #include "core/LuaState.h"43 #include "util/Convert.h"44 40 #include "util/SubString.h" 45 46 #include "Notification.h"47 41 48 42 namespace orxonox … … 56 50 @param senders 57 51 The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays. 58 The senders need to be sep erated by commas.52 The senders need to be separated by commas. 59 53 @param size 60 54 The size (the maximum number of displayed Notifications) of this NotificationQueue. … … 88 82 } 89 83 90 this->create(); // Creates the NotificationQueue in lua. 91 92 // Register the NotificationQueue as NotificationListener with the NotificationManager. 93 bool listenerRegistered = NotificationManager::getInstance().registerListener(this); 94 if(!listenerRegistered) // If the registration has failed. 95 { 96 this->registered_ = false; 97 // Remove the NotificationQueue in lua. 98 if(GameMode::showsGraphics()) 99 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")"); 84 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; 85 } 86 87 /** 88 @brief 89 Destructor. 90 */ 91 NotificationQueue::~NotificationQueue() 92 { 93 this->targets_.clear(); 94 95 if(this->registered_) // If the NotificationQueue is registered. 96 { 97 this->clear(true); 98 99 // Unregister with the NotificationManager. 100 100 NotificationManager::getInstance().unregisterQueue(this); 101 COUT(1) << "Error: NotificationQueue '" << this->getName() << "' could not be registered." << std::endl; 102 return; 103 } 104 105 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; 106 } 107 108 /** 109 @brief 110 Destructor. 111 */ 112 NotificationQueue::~NotificationQueue() 113 { 114 this->targets_.clear(); 115 116 if(this->registered_) // If the NotificationQueue is registered. 117 { 118 this->clear(true); 119 120 // Unregister with the NotificationManager. 121 NotificationManager::getInstance().unregisterListener(this); 122 NotificationManager::getInstance().unregisterQueue(this); 123 } 124 } 125 126 /** 127 @brief 128 Destroys the NotificationQueue. 129 Used in lua and NotificationManager. 130 @param noGraphics 131 If this is set to true (false is default), then the queue is not removed in lua. This is used to destroy the queue, after the GUIManager has been destroyed. 132 */ 133 void NotificationQueue::destroy(bool noGraphics) 134 { 135 // Remove the NotificationQueue in lua. 136 if(GameMode::showsGraphics() && !noGraphics) 137 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")"); 138 101 } 102 139 103 COUT(3) << "NotificationQueue '" << this->getName() << "' destroyed." << std::endl; 140 141 this->OrxonoxClass::destroy();142 }143 144 /**145 @brief146 Creates the NotificationQueue in lua.147 */148 void NotificationQueue::create(void)149 {150 if(GameMode::showsGraphics())151 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");152 104 } 153 105 … … 161 113 { 162 114 this->tickTime_ += dt; // Add the time interval that has passed to the time counter. 163 if(this-> tickTime_ >= 1.0) // If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick.115 if(this->displayTime_ != INF && this->tickTime_ >= 1.0) // If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick. 164 116 { 165 117 this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time. … … 181 133 Updates the NotificationQueue. 182 134 Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue. 135 This is called by the NotificationManager when the Notifications have changed so much, that the NotificationQueue may have to re-initialize his operations. 183 136 */ 184 137 void NotificationQueue::update(void) … … 188 141 std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>; 189 142 // Get the Notifications sent in the interval from now to now minus the display time. 190 NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_); 143 if(this->displayTime_ == INF) 144 NotificationManager::getInstance().getNewestNotifications(this, notifications, this->getMaxSize()); 145 else 146 NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_); 191 147 192 148 if(!notifications->empty()) … … 246 202 this->notifications_.insert(this->notifications_.begin(), container); 247 203 248 // Push the Notification to the GUI. 249 if(GameMode::showsGraphics()) 250 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); 204 // Inform that a Notification was pushed. 205 this->notificationPushed(notification); 251 206 252 207 COUT(5) << "Notification \"" << notification->getMessage() << "\" pushed to NotificationQueue '" << this->getName() << "'" << endl; 208 COUT(3) << "NotificationQueue \"" << this->getName() << "\": " << notification->getMessage() << endl; 253 209 } 254 210 … … 279 235 delete container; 280 236 281 // Pops the Notification from the GUI. 282 if(GameMode::showsGraphics()) 283 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")"); 237 // Inform that a Notification was popped. 238 this->notificationPopped(); 284 239 } 285 240 … … 305 260 delete *containerIterator; 306 261 307 // Removes the Notification from the GUI.308 if(GameMode::showsGraphics())309 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");262 // TODO: index automatically cast? 263 // Inform that a Notification was removed. 264 this->notificationRemoved(index); 310 265 } 311 266 … … 314 269 Clears the NotificationQueue by removing all NotificationContainers. 315 270 @param noGraphics 316 If this is eset to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.271 If this is set to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally. 317 272 */ 318 273 void NotificationQueue::clear(bool noGraphics) … … 326 281 this->notifications_.clear(); 327 282 this->size_ = 0; 328 329 // Clear the NotificationQueue in the GUI.330 if(GameMode::showsGraphics() && !noGraphics)331 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");332 283 } 333 284 … … 364 315 Sets the maximum number of seconds a Notification is displayed. 365 316 @param time 366 The number of seconds the Notifications is displayed. 367 @return 368 Returns true if successful. 369 */ 370 void NotificationQueue::setDisplayTime(unsigned int time) 317 The number of seconds a Notification is displayed. 318 */ 319 void NotificationQueue::setDisplayTime(int time) 371 320 { 372 321 if(this->displayTime_ == time) … … 381 330 /** 382 331 @brief 383 Produces all targets of the NotificationQueue concat inated as string, with commas (',') as seperators.332 Produces all targets of the NotificationQueue concatenated as string, with commas (',') as separators. 384 333 @return 385 334 Returns the targets as a string. … … 407 356 The targets are the senders whose Notifications are displayed in this queue. 408 357 @param targets 409 Accepts a string of targets, each sep erated by commas (','), spaces are ignored.358 Accepts a string of targets, each separated by commas (','), spaces are ignored. 410 359 */ 411 360 void NotificationQueue::setTargets(const std::string & targets) … … 417 366 this->targets_.insert(string[i]); 418 367 368 // TODO: Why? 419 369 if(this->registered_) 420 370 { 421 NotificationManager::getInstance().unregisterListener(this); 422 NotificationManager::getInstance().registerListener(this); 423 } 371 NotificationManager::getInstance().unregisterQueue(this); 372 NotificationManager::getInstance().registerQueue(this); 373 } 374 } 375 376 /** 377 @brief 378 Pops all Notifications from the NotificationQueue. 379 @return 380 Returns true if successful, false if not. 381 */ 382 bool NotificationQueue::tidy(void) 383 { 384 while(this->size_ > 0) 385 this->pop(); 386 return true; 424 387 } 425 388
Note: See TracChangeset
for help on using the changeset viewer.