Changeset 7338 for code/branches/notifications
- Timestamp:
- Sep 3, 2010, 3:55:32 PM (14 years ago)
- Location:
- code/branches/notifications
- Files:
-
- 2 added
- 2 deleted
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/notifications/data/gui/scripts/SheetManager.lua
r6746 r7338 43 43 44 44 -- ? 45 function showMenuSheet(name, bHidePrevious, ptr)46 local sheet = showMenuSheet(name, bHidePrevious )45 function showMenuSheet(name, bHidePrevious, bNoInput, ptr) 46 local sheet = showMenuSheet(name, bHidePrevious, bNoInput) 47 47 sheet.overlay = ptr 48 48 return sheet … … 50 50 51 51 -- Shows the specified menu sheet and loads it if neccessary 52 function showMenuSheet(name, bHidePrevious )52 function showMenuSheet(name, bHidePrevious, bNoInput) 53 53 if name == "" then 54 54 return nil … … 63 63 end 64 64 65 if bNoInput == nil then 66 bNoInput = false 67 end 68 65 69 -- Pause game control if this is the first menu to be displayed 66 70 -- HUGE HACK? … … 74 78 end 75 79 80 menuSheet.tShowCursor = TriBool.Dontcare 81 76 82 -- Add the sheet in a tuple of additional information 77 83 local sheetTuple = 78 84 { 79 85 ["sheet"] = menuSheet, 80 ["bHidePrevious"] = bHidePrevious 86 ["bHidePrevious"] = bHidePrevious, 87 ["bNoInput"] = bNoInput 81 88 } 82 89 table.insert(activeMenuSheets, sheetTuple) -- indexed array access … … 89 96 90 97 -- Handle input distribution 91 inputMgr:enterState(menuSheet.inputState) 98 if bNoInput == false then 99 inputMgr:enterState(menuSheet.inputState) 100 end 92 101 93 102 -- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare … … 148 157 149 158 -- Leave the input state 150 inputMgr:leaveState(sheetTuple.sheet.inputState) 159 if not sheetTuple.bNoInput then 160 inputMgr:leaveState(sheetTuple.sheet.inputState) 161 end 151 162 152 163 -- CURSOR SHOWING … … 178 189 function keyESC() 179 190 -- HUGE, very HUGE hacks! 180 if activeMenuSheets.size == 1 and activeMenuSheets[1].sheet.name == "MainMenu" then 191 192 -- Count the number of sheets that don't need input till the first that does. 193 local counter = activeMenuSheets.size 194 while counter > 0 and activeMenuSheets[counter].bNoInput do 195 counter = counter - 1 196 end 197 198 -- If the first sheet that needs input is the MainMenu. 199 if counter > 0 and activeMenuSheets.size == counter and activeMenuSheets[counter].sheet.name == "MainMenu" then 181 200 orxonox.execute("exit") 182 elseif activeMenuSheets.size > 0 then 183 orxonox.execute("hideGUI "..activeMenuSheets.topSheetTuple.sheet.name) 201 -- If there is at least one sheet that needs input. 202 elseif counter > 0 then 203 orxonox.execute("hideGUI "..activeMenuSheets[counter].sheet.name) 184 204 else 185 205 showMenuSheet("InGameMenu") -
code/branches/notifications/src/libraries/core/GUIManager.cc
r7284 r7338 240 240 The function executes the Lua function with the same name in case the GUIManager is ready. 241 241 */ 242 /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious )243 { 244 GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + " )");242 /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious, bool bNoInput) 243 { 244 GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")"); 245 245 } 246 246 … … 249 249 Hack-ish. Needed for GUIOverlay. 250 250 */ 251 void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious )252 { 253 this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + ptr + ")");251 void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious, bool bNoInput) 252 { 253 this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ", " + ptr + ")"); 254 254 } 255 255 -
code/branches/notifications/src/libraries/core/GUIManager.h
r7163 r7338 75 75 76 76 void loadGUI(const std::string& name); 77 static void showGUI(const std::string& name, bool bHidePrevious = false );78 void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false );77 static void showGUI(const std::string& name, bool bHidePrevious = false, bool bNoInput = false); 78 void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false, bool bNoInput = false); 79 79 static void hideGUI(const std::string& name); 80 80 void keyESC(); -
code/branches/notifications/src/modules/notifications/CMakeLists.txt
r7326 r7338 3 3 NotificationDispatcher.cc 4 4 NotificationManager.cc 5 NotificationOverlay.cc6 5 NotificationQueue.cc 7 6 ) … … 17 16 LINK_LIBRARIES 18 17 orxonox 19 overlays20 18 SOURCE_FILES ${NOTIFICATIONS_SRC_FILES} 21 19 ) -
code/branches/notifications/src/modules/notifications/Notification.cc
r7326 r7338 94 94 registerVariable(this->message_); 95 95 registerVariable(this->sender_); 96 registerVariable(this->sent_ );96 registerVariable(this->sent_, ObjectDirection::Bidirectional); 97 97 } 98 98 … … 108 108 { 109 109 110 callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, clientId, sender); 110 if(GameMode::isMaster()) 111 { 112 this->sendHelper(sender); 113 } 114 else 115 { 116 callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, sender); 117 } 111 118 112 119 return true; 113 120 } 114 121 115 bool Notification::sendHelper( unsigned int clientId,const std::string& sender)122 bool Notification::sendHelper(const std::string& sender) 116 123 { 117 124 if(this->isSent()) //TODO: Needed? -
code/branches/notifications/src/modules/notifications/Notification.h
r7326 r7338 58 58 59 59 bool send(unsigned int clientId, const std::string & sender); //!< Sends the Notification to the Notificationmanager. 60 bool sendHelper( unsigned int clientId,const std::string& sender);60 bool sendHelper(const std::string& sender); 61 61 62 62 /** -
code/branches/notifications/src/modules/notifications/NotificationManager.cc
r7284 r7338 40 40 #include "Notification.h" 41 41 #include "interfaces/NotificationListener.h" 42 #include "core/GUIManager.h" 43 #include "NotificationQueue.h" 42 44 43 45 namespace orxonox … … 47 49 const std::string NotificationManager::NONE("none"); 48 50 49 ManageScopedSingleton(NotificationManager, ScopeID:: Root, false);51 ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false); 50 52 51 53 /** … … 58 60 59 61 this->highestIndex_ = 0; 62 63 //TODO: What if no graphics? 64 GUIManager::getInstance().loadGUI("NotificationLayer"); 65 // Create first queue: 66 NotificationQueue* queue = new NotificationQueue("general"); 60 67 } 61 68 -
code/branches/notifications/src/modules/notifications/NotificationManager.h
r7164 r7338 71 71 72 72 /** 73 @brief Fetches the Notifications for a specific NotificationListener starting at a specified time.74 @param listener The NotificationListener the Notifications are fetched for.75 @param map A multimap, in which the notifications are stored.76 @param timeFrameStart The start time the Notifications are fetched from.77 @return Returns true if successful.78 */79 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart)80 { return this->getNotifications(listener, map, timeFrameStart, std::time(0)); }81 /**82 73 @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now. 83 74 @param listener The NotificationListener the Notifications are fetched for. -
code/branches/notifications/src/modules/notifications/NotificationQueue.cc
r7163 r7338 37 37 #include "core/CoreIncludes.h" 38 38 #include "core/XMLPort.h" 39 #include "NotificationOverlay.h" 40 #include "NotificationManager.h" 39 #include "Notification.h" 40 #include "core/GUIManager.h" 41 #include "core/LuaState.h" 42 #include <algorithm> 41 43 42 44 namespace orxonox 43 45 { 44 45 CreateFactory(NotificationQueue);46 46 47 47 const std::string NotificationQueue::DEFAULT_FONT("VeraMono"); … … 53 53 Constructor. Creates and initializes the object. 54 54 */ 55 NotificationQueue::NotificationQueue( BaseObject* creator) : OverlayGroup(creator)55 NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, const Vector2& position, unsigned int length, unsigned int displayTime) 56 56 { 57 57 this->registered_ = false; 58 58 59 RegisterObject(NotificationQueue); 59 RegisterRootObject(NotificationQueue); 60 60 61 this->initialize(); 62 63 this->setTargets(senders); 64 this->name_ = name; 65 this->maxSize_ = size; 66 this->position_ = position; 67 this->notificationLength_ = length; 68 this->setDisplayTime(displayTime); 69 70 this->create(); 71 72 NotificationManager::getInstance().registerListener(this); 73 this->registered_ = true; 74 75 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; 61 76 } 62 77 … … 83 98 this->size_ = 0; 84 99 this->tickTime_ = 0.0; 85 86 NotificationManager::getInstance().registerListener(this); 87 this->registered_ = true; 88 } 89 90 /** 91 @brief 92 Sets the defaults. 93 */ 94 void NotificationQueue::setDefaults(void) 95 { 96 this->setMaxSize(DEFAULT_SIZE); 97 this->setNotificationLength(DEFAULT_LENGTH); 98 this->setDisplayTime(DEFAULT_DISPLAY_TIME); 99 this->setPosition(DEFAULT_POSITION); 100 101 this->setTargets(NotificationManager::ALL); 102 103 this->setFontSize(DEFAULT_FONT_SIZE); 104 this->setFont(DEFAULT_FONT); 105 } 106 107 /** 108 @brief 109 Method for creating a NotificationQueue object through XML. 110 */ 111 void NotificationQueue::XMLPort(Element& xmlElement, XMLPort::Mode mode) 112 { 113 SUPER(NotificationQueue, XMLPort, xmlElement, mode); 114 115 this->setDefaults(); 116 117 XMLPortParam(NotificationQueue, "maxSize", setMaxSize, getMaxSize, xmlElement, mode); 118 XMLPortParam(NotificationQueue, "notificationLength", setNotificationLength, getNotificationLength, xmlElement, mode); 119 XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlElement, mode); 120 XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlElement, mode); 121 XMLPortParam(NotificationQueue, "font", setFont, getFont, xmlElement, mode); 122 XMLPortParam(NotificationQueue, "fontSize", setFontSize, getFontSize, xmlElement, mode); 123 XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlElement, mode); 124 125 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; 100 } 101 102 /** 103 //TODO: Document. 104 */ 105 void NotificationQueue::create(void) 106 { 107 //TODO: Also transfer font and fontsize. 108 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")"); 109 this->positionChanged(); 126 110 } 127 111 … … 139 123 this->timeLimit_.time = std::time(0)-this->displayTime_; //!< Container containig the current time. 140 124 141 std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it; 142 it = this->containers_.begin(); 143 while(it != this->containers_.upper_bound(&this->timeLimit_)) //!< Iterate through all elements whose creation time is smaller than the current time minus the display time. 125 std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin(); 126 while(it != this->ordering_.upper_bound(&this->timeLimit_)) //!< Iterate through all elements whose creation time is smaller than the current time minus the display time. 144 127 { 145 this->removeContainer(*it);146 this->scroll(Vector2(0.0f,-(1.1f*this->getFontSize())));147 it = this->containers_.begin(); //TODO: Needed?128 NotificationContainer* temp = *it; 129 it++; 130 this->remove(temp); 148 131 } 149 132 150 this->tickTime_ = 0.0f; //!< Reset time counter.133 this->tickTime_ = this->tickTime_ - (int)this->tickTime_; //!< Reset time counter. 151 134 } 152 135 } … … 161 144 this->clear(); 162 145 163 std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t,Notification*>;146 std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>; 164 147 if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) //!< Get the Notifications sent in the interval form now to minus the display time. 165 148 { … … 171 154 return; 172 155 173 for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications. 174 { 175 this->addNotification(it->second, it->first); 176 } 156 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications. 157 this->push(it->second, it->first); 177 158 178 159 delete notifications; … … 191 172 void NotificationQueue::update(Notification* notification, const std::time_t & time) 192 173 { 193 this->addNotification(notification, time); 194 195 std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it; 196 while(this->getSize() > this->getMaxSize()) 197 { 198 it = this->containers_.begin(); 199 this->removeContainer(*it); 200 this->scroll(Vector2(0.0f,-(1.1f*this->getFontSize()))); 201 } 202 203 COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notifications has been added." << std::endl; 174 this->push(notification, time); 175 176 COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; 177 } 178 179 /** 180 @brief 181 Sets the name of the NotificationQueue. 182 @param name 183 The name to be set. 184 @return 185 returns true if successful. 186 */ 187 bool NotificationQueue::setName(const std::string& name) 188 { 189 //TODO: Test uniqueness of name. 190 this->name_ = name; 191 return true; 204 192 } 205 193 … … 212 200 Returns true if successful. 213 201 */ 214 bool NotificationQueue::setMaxSize(int size) 215 { 216 if(size < 0) 217 return false; 202 void NotificationQueue::setMaxSize(unsigned int size) 203 { 218 204 this->maxSize_ = size; 219 205 this->update(); 220 return true;221 206 } 222 207 … … 229 214 Returns true if successful. 230 215 */ 231 bool NotificationQueue::setNotificationLength(int length) 232 { 233 if(length < 0) 234 return false; 216 void NotificationQueue::setNotificationLength(unsigned int length) 217 { 235 218 this->notificationLength_ = length; 236 219 this->update(); 237 return true;238 220 } 239 221 … … 246 228 Returns true if successful. 247 229 */ 248 bool NotificationQueue::setDisplayTime(int time) 249 { 250 if(time < 0) 251 return false; 230 void NotificationQueue::setDisplayTime(unsigned int time) 231 { 252 232 this->displayTime_ = time; 253 233 this->update(); 254 return true;255 234 } 256 235 … … 330 309 if(size <= 0) 331 310 return false; 332 this->fontSize_ = size; 333 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font size for each overlay. 334 { 335 it->second->overlay->setFontSize(size); 336 } 311 337 312 return true; 338 313 } … … 348 323 bool NotificationQueue::setFont(const std::string & font) 349 324 { 350 this->font_ = font; 351 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font for each overlay. 352 { 353 it->second->overlay->setFont(font); 354 } 325 355 326 return true; 356 327 } … … 358 329 /** 359 330 @brief 360 Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.361 @param pos362 The vector the NotificationQueue is scrolled.363 */364 void NotificationQueue::scroll(const Vector2 pos)365 {366 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Scroll each overlay.367 {368 it->second->overlay->scroll(pos);369 }370 }371 372 /**373 @brief374 331 Aligns all the Notifications to the position of the NotificationQueue. 375 332 */ 376 333 void NotificationQueue::positionChanged(void) 377 334 { 378 int counter = 0; 379 for (std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); it != this->containers_.end(); it++) //!< Set the position for each overlay. 380 { 381 (*it)->overlay->setPosition(this->getPosition()); 382 (*it)->overlay->scroll(Vector2(0.0f,(1.1f*this->getFontSize())*counter)); 383 counter++; 384 } 335 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changePosition(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getPosition().x) + ", " + multi_cast<std::string>(this->getPosition().y) + ")"); 385 336 } 386 337 … … 388 339 @brief 389 340 Adds a Notification, to the queue. 390 It inserts it into the storage containers, creates a n corresponding overlay and a container.341 It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI. 391 342 @param notification 392 343 The Notification. … … 394 345 The time. 395 346 */ 396 void NotificationQueue::addNotification(Notification* notification, const std::time_t & time) 397 { 398 NotificationOverlayContainer* container = new NotificationOverlayContainer; 399 container->overlay = new NotificationOverlay(this, notification); 347 void NotificationQueue::push(Notification* notification, const std::time_t & time) 348 { 349 NotificationContainer* container = new NotificationContainer; 400 350 container->notification = notification; 401 351 container->time = time; 402 std::string timeString = std::ctime(&time); 403 timeString.erase(timeString.length()-1); 404 const std::string& addressString = multi_cast<std::string>(reinterpret_cast<unsigned long>(notification)); 405 container->name = "NotificationOverlay(" + timeString + ")&" + addressString; 406 407 this->containers_.insert(container); 408 this->overlays_[notification] = container; 409 this->addElement(container->overlay); 410 this->size_= this->size_+1; 411 412 container->overlay->scroll(Vector2(0.0f,(1.1f*this->getFontSize())*(this->getSize()-1))); 413 } 414 415 /** 416 @brief 417 Removes a container from the queue. 352 353 // If the maximum size of the NotificationQueue has been reached the last (least recently added) Notification is removed. 354 if(this->getSize() >= this->getMaxSize()) 355 this->pop(); 356 357 this->size_++; 358 359 this->ordering_.insert(container); 360 this->notifications_.insert(this->notifications_.begin(), container); 361 362 //TODO: Clip message if necessary. 363 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); 364 } 365 366 /** 367 @brief 368 Removes the least recently added Notification form the NotificationQueue. 369 */ 370 void NotificationQueue::pop(void) 371 { 372 NotificationContainer* container = this->notifications_.back(); 373 this->ordering_.erase(container); 374 this->notifications_.pop_back(); 375 this->size_--; 376 delete container; 377 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")"); 378 } 379 380 /** 381 @brief 382 Removes the Notification that is stored in the input container. 418 383 @param container 419 A pointer to the container. 420 @return 421 Returns true if successful. 422 */ 423 bool NotificationQueue::removeContainer(NotificationOverlayContainer* container) 424 { 425 if(this->size_ == 0) //!< You cannot remove anything if the queue is empty. 426 return false; 427 428 // Unregister the NotificationQueue with the NotificationManager. 429 NotificationManager::getInstance().unregisterNotification(container->notification, this); 430 431 this->removeElement(container->overlay); 432 this->containers_.erase(container); 433 this->overlays_.erase(container->notification); 434 container->overlay->destroy(); 384 The NotificationContainer with the Notification to be removed. 385 */ 386 void NotificationQueue::remove(NotificationContainer* container) 387 { 388 std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container); 389 std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin (); 390 this->ordering_.erase(container); 391 this->notifications_.erase(it); 392 this->size_--; 435 393 delete container; 436 this->size_= this->size_-1; 437 438 return true; 394 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")"); 439 395 } 440 396 … … 445 401 void NotificationQueue::clear(void) 446 402 { 447 std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); 448 while(it != this->containers_.end()) 449 { 450 this->removeContainer(*it); 451 it = this->containers_.begin(); 452 } 403 this->ordering_.clear(); 404 for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++) 405 { 406 delete *it; 407 } 408 this->notifications_.clear(); 409 this->size_ = 0; 410 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")"); 453 411 } 454 412 -
code/branches/notifications/src/modules/notifications/NotificationQueue.h
r7164 r7338 41 41 #include <set> 42 42 #include <string> 43 #include <vector> 43 44 44 45 #include "util/Math.h" 46 #include "core/OrxonoxClass.h" 45 47 #include "tools/interfaces/Tickable.h" 46 #include "overlays/OverlayGroup.h"47 48 #include "interfaces/NotificationListener.h" 49 #include "NotificationManager.h" 48 50 49 51 namespace orxonox … … 51 53 52 54 //! Container to allow easy handling. 53 struct Notification OverlayContainer55 struct NotificationContainer 54 56 { 55 NotificationOverlay* overlay; //!< Pointer to the NotificationOverlay, everything is about.56 57 Notification* notification; //!< The Notification displayed by the overlay. 57 58 time_t time; //!< The time the Notification was sent and thus first displayed. 58 std::string name; //!< The name of the overlay.59 59 }; 60 60 61 61 //! Struct to allow ordering of NotificationOverlayContainers. 62 struct Notification OverlayContainerCompare {63 bool operator() (const Notification OverlayContainer* const & a, const NotificationOverlayContainer* const & b) const62 struct NotificationContainerCompare { 63 bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const 64 64 { return a->time < b->time; } //!< Ordered by time. 65 65 }; … … 68 68 @brief 69 69 Displays Notifications from specific senders. 70 Beware! The NotificationQueue is an OverlayGruop and thus cannot be be a sub-element of an OverlayGroup (at least no for now.)71 72 Creating a NotificationQueue through XML goes as follows:73 Be aware that the NotificationQueue must be inside the <Level></Level> tags or bad things will happen.74 <NotificationQueue75 name = "SuperQueue" //Name of your OverlayQueue.76 maxSize = "5" //The maximum number of Notifications displayed. (Default is 5)77 notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 64)78 displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30)79 targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.)80 font = "VeraMono" //The font (Default is VeraMono)81 fontSize = '0.4' //The font size. (Default is 0.025)82 position = "0.0, 0.0" //The position of the NotificationQueue. (Default is 0.0,0.0)83 />84 70 @author 85 71 Damian 'Mozork' Frick 86 72 */ 87 73 88 class _NotificationsExport NotificationQueue : public OverlayGroup, publicTickable, public NotificationListener74 class _NotificationsExport NotificationQueue : public Tickable, public NotificationListener 89 75 { 90 76 91 77 public: 92 NotificationQueue( BaseObject* creator);78 NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, const Vector2& position = NotificationQueue::DEFAULT_POSITION, unsigned int length = NotificationQueue::DEFAULT_LENGTH, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); 93 79 virtual ~NotificationQueue(); 94 95 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML.96 80 97 81 virtual void tick(float dt); //!< To update from time to time. … … 101 85 102 86 /** 87 @brief Get the name of the NotificationQueue. 88 @return Returns the name. 89 */ 90 inline const std::string& getName() const 91 { return this->name_; } 92 93 /** 103 94 @brief Returns the maximum number of Notifications displayed. 104 95 @return Returns maximum size. 105 96 */ 106 inline int getMaxSize() const97 inline unsigned int getMaxSize() const 107 98 { return this->maxSize_; } 108 99 /** … … 110 101 @return Returns the size of the queue. 111 102 */ 112 inline int getSize() const103 inline unsigned int getSize() const 113 104 { return this->size_; } 114 105 /** … … 116 107 @return Returns the maximum Notification length. 117 108 */ 118 inline int getNotificationLength() const109 inline unsigned int getNotificationLength() const 119 110 { return this->notificationLength_; } 120 111 /** … … 122 113 @return Returns the display time. 123 114 */ 124 inline int getDisplayTime() const115 inline float getDisplayTime() const 125 116 { return this->displayTime_; } 126 117 /** … … 158 149 { this->position_ = pos; this->positionChanged(); } 159 150 160 void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.161 162 151 private: 163 static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.164 static const int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed.165 static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.152 static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. 153 static const unsigned int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed. 154 static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 166 155 static const float DEFAULT_FONT_SIZE; //!< The default font size. 167 156 … … 169 158 static const Vector2 DEFAULT_POSITION; //!< the default position. 170 159 171 int maxSize_; //!< The maximal number of Notifications displayed. 172 int size_; //!< The number of Notifications displayed. 173 int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have. 174 int displayTime_; //!< The time a Notification is displayed. 160 std::string name_; //!< The name of the NotificationQueue. 161 162 unsigned int maxSize_; //!< The maximal number of Notifications displayed. 163 unsigned int size_; //!< The number of Notifications displayed. 164 unsigned int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have. 165 unsigned int displayTime_; //!< The time a Notification is displayed. 175 166 Vector2 position_; //!< The position of the NotificationQueue. 176 167 … … 180 171 std::string font_; //!< The font. 181 172 182 std::multiset<Notification OverlayContainer*, NotificationOverlayContainerCompare> containers_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps.183 std:: map<Notification*, NotificationOverlayContainer*> overlays_; //!< Mapping notifications to their corresponding overlay containers, for easier association and finding.173 std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. //TODO: Would set work as well? 174 std::vector<NotificationContainer*> notifications_; 184 175 185 176 float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick. 186 Notification OverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.177 NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 187 178 188 179 bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already. 189 180 190 181 void initialize(void); //!< Initializes the object. 191 void setDefaults(void); //!< Helper method to set the default values. 192 193 bool setMaxSize(int size); //!< Sets the maximum number of displayed Notifications. 194 bool setNotificationLength(int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have. 195 bool setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed. 182 void create(void); 183 184 bool setName(const std::string& name); //!< Sets the name of the NotificationQueue. 185 186 void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications. 187 void setNotificationLength(unsigned int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have. 188 void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed. 196 189 197 190 bool setTargets(const std::string & targets); //!< Set the targets of this queue. … … 202 195 void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue. 203 196 204 void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue. 205 bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue. 197 void push(Notification* notification, const std::time_t & time); //!< Add a notification to the queue. 198 void pop(void); 199 void remove(NotificationContainer* container); 206 200 207 201 void clear(void); //!< Clear the queue. -
code/branches/notifications/src/modules/notifications/NotificationsPrereqs.h
r7285 r7338 68 68 class NotificationDispatcher; 69 69 class NotificationManager; 70 class NotificationOverlay;71 70 class NotificationQueue; 72 71
Note: See TracChangeset
for help on using the changeset viewer.