Changeset 8636 for code/branches/tutoriallevel3/src/modules/notifications
- Timestamp:
- May 28, 2011, 4:21:14 PM (14 years ago)
- Location:
- code/branches/tutoriallevel3/src/modules/notifications
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/tutoriallevel3/src/modules/notifications/NotificationManager.cc
r8453 r8636 411 411 void NotificationManager::loadQueues(void) 412 412 { 413 NotificationQueueCEGUI* allQueue = new NotificationQueueCEGUI("all");413 /*NotificationQueueCEGUI* allQueue = new NotificationQueueCEGUI("all"); 414 414 allQueue->setDisplaySize(Vector2(0.5, 0)); 415 415 allQueue->setPosition(Vector4(0.0, 10, 0.3, 0)); … … 420 420 infoQueue->setFontColor(Vector4(1.0, 1.0, 0.0, 0.8)); 421 421 infoQueue->setAlignment("HorzCentred"); 422 infoQueue->setDisplaySize(Vector2(0.6, 0.0)); 422 infoQueue->setDisplaySize(Vector2(0.6, 0.0));*/ 423 423 } 424 424 -
code/branches/tutoriallevel3/src/modules/notifications/NotificationQueue.cc
r8453 r8636 38 38 39 39 #include "core/CoreIncludes.h" 40 #include "core/XMLPort.h" 40 41 #include "util/SubString.h" 41 42 … … 43 44 { 44 45 45 /** 46 @brief 47 Constructor. Creates and initializes the object. 46 CreateFactory(NotificationQueue); 47 48 /** 49 @brief 50 Default constructor. Registers and initializes the object. 51 @param creator 52 The creator of the NotificationQueue. 53 */ 54 NotificationQueue::NotificationQueue(BaseObject* creator) : BaseObject(creator), registered_(false) 55 { 56 RegisterObject(NotificationQueue); 57 58 this->initialize(); 59 } 60 61 // TODO move to docu. 62 /** 63 @brief 64 Constructor. Registers and initializes the object. 65 @param creator 66 The creator of the NotificationQueue 48 67 @param name 49 68 The name of the new NotificationQueue. It needs to be unique 50 69 @param senders 51 70 The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays. 52 The senders need to be sep arated by commas.71 The senders need to be seperated by commas. 53 72 @param size 54 73 The size (the maximum number of displayed Notifications) of this NotificationQueue. … … 56 75 The time during which a Notification is (at most) displayed. 57 76 */ 58 NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) 59 { 60 this->registered_ = false; 61 62 RegisterRootObject(NotificationQueue); 63 64 // Initialize. 77 78 /** 79 @brief 80 Destructor. 81 */ 82 NotificationQueue::~NotificationQueue() 83 { 84 this->targets_.clear(); 85 86 if(this->isRegistered()) // If the NotificationQueue is registered. 87 { 88 this->clear(true); 89 90 // Unregister with the NotificationManager. 91 NotificationManager::getInstance().unregisterQueue(this); 92 } 93 } 94 95 /** 96 @brief 97 Initializes the NotificationQueue. 98 */ 99 void NotificationQueue::initialize(void) 100 { 65 101 this->size_ = 0; 66 102 this->tickTime_ = 0.0f; 67 68 // Sets the input values. 69 this->setTargets(senders); 70 this->name_ = name; 71 this->maxSize_ = size; 72 this->setDisplayTime(displayTime); 73 103 this->maxSize_ = NotificationQueue::DEFAULT_SIZE; 104 this->displayTime_ = NotificationQueue::DEFAULT_DISPLAY_TIME; 105 106 this->creationTime_ = std::time(0); 107 } 108 109 /** 110 @brief 111 Creates the NotificationQueue. 112 */ 113 void NotificationQueue::create(void) 114 { 74 115 // Register the NotificationQueue with the NotificationManager. 75 116 bool queueRegistered = NotificationManager::getInstance().registerQueue(this); … … 87 128 /** 88 129 @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 NotificationManager::getInstance().unregisterQueue(this);101 }102 103 COUT(3) << "NotificationQueue '" << this->getName() << "' destroyed." << std::endl;104 }105 106 /**107 @brief108 130 Updates the queue from time to time. 109 131 @param dt … … 115 137 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. 116 138 { 117 this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containi g the current time.139 this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containing the current time. 118 140 119 141 std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin(); … … 129 151 } 130 152 153 void NotificationQueue::XMLPort(Element& xmlelement, XMLPort::Mode mode) 154 { 155 SUPER(NotificationQueue, XMLPort, xmlelement, mode); 156 157 XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlelement, mode).defaultValues(NotificationListener::ALL); 158 XMLPortParam(NotificationQueue, "size", setMaxSize, getMaxSize, xmlelement, mode); 159 XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlelement, mode); 160 161 this->create(); 162 } 163 131 164 /** 132 165 @brief … … 148 181 if(!notifications->empty()) 149 182 { 150 // Add all Notifications .183 // Add all Notifications that have been created after this NotificationQueue was created. 151 184 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) 152 this->push(it->second, it->first); 185 { 186 if(it->first >= this->creationTime_) 187 this->push(it->second, it->first); 188 } 153 189 } 154 190 … … 305 341 return; 306 342 343 if(size == 0) 344 { 345 COUT(2) << "Trying to set maximal size of NotificationQueue '" << this->getName() << "' to 0. Ignoring..." << endl; 346 return; 347 } 348 307 349 this->maxSize_ = size; 308 350 309 if(this-> registered_)351 if(this->isRegistered()) 310 352 this->update(); 311 353 } … … 322 364 return; 323 365 366 if(time != NotificationQueue::INF && time <= 0) 367 { 368 COUT(2) << "Trying to set display time of NotificationQueue '" << this->getName() << "' to non-positive value. Ignoring..." << endl; 369 } 370 324 371 this->displayTime_ = time; 325 372 326 if(this-> registered_)373 if(this->isRegistered()) 327 374 this->update(); 328 375 } … … 367 414 368 415 // TODO: Why? 369 if(this-> registered_)416 if(this->isRegistered()) 370 417 { 371 418 NotificationManager::getInstance().unregisterQueue(this); -
code/branches/tutoriallevel3/src/modules/notifications/NotificationQueue.h
r8453 r8636 45 45 #include "NotificationManager.h" 46 46 47 #include "core/BaseObject.h" 47 48 #include "tools/interfaces/Tickable.h" 48 49 … … 88 89 @ingroup Notifications 89 90 */ 90 class _NotificationsExport NotificationQueue : public Tickable91 class _NotificationsExport NotificationQueue : public BaseObject, public Tickable 91 92 { 92 93 93 94 public: 94 NotificationQueue(const std::string& name, const std::string& senders = NotificationListener::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); 95 NotificationQueue(BaseObject* creator); 96 NotificationQueue(BaseObject* creator, const std::string& name, const std::string& senders = NotificationListener::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); 95 97 virtual ~NotificationQueue(); 96 98 97 virtual void tick(float dt); //!< To update from time to time. 98 99 void update(void); //!< Updates the NotificationQueue. 100 void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification. 99 virtual void tick(float dt); // To update from time to time. 100 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 101 102 void update(void); // Updates the NotificationQueue. 103 void update(Notification* notification, const std::time_t & time); // Updates the NotificationQueue by adding an new Notification. 101 104 102 105 // tolua_begin … … 105 108 @return Returns the name. 106 109 */ 107 inline const std::string& getName( ) const108 { return this-> name_; }109 110 void setMaxSize(unsigned int size); // !<Sets the maximum number of displayed Notifications.110 inline const std::string& getName(void) const 111 { return this->BaseObject::getName(); } 112 113 void setMaxSize(unsigned int size); // Sets the maximum number of displayed Notifications. 111 114 /** 112 115 @brief Returns the maximum number of Notifications displayed. 113 116 @return Returns maximum size. 114 117 */ 115 inline unsigned int getMaxSize( ) const118 inline unsigned int getMaxSize(void) const 116 119 { return this->maxSize_; } 117 120 118 void setDisplayTime(int time); // !<Sets the maximum number of seconds a Notification is displayed.121 void setDisplayTime(int time); // Sets the maximum number of seconds a Notification is displayed. 119 122 /** 120 123 @brief Returns the time interval the Notification is displayed. 121 124 @return Returns the display time. 122 125 */ 123 inline int getDisplayTime( ) const126 inline int getDisplayTime(void) const 124 127 { return this->displayTime_; } 125 128 // tolua_end … … 129 132 @return Returns the size of the NotificationQueue. 130 133 */ 131 inline unsigned int getSize( ) const134 inline unsigned int getSize(void) const 132 135 { return this->size_; } 133 136 … … 136 139 @return Returns a set of strings holding the different targets. 137 140 */ 138 inline const std::set<std::string> & getTargetsSet( )141 inline const std::set<std::string> & getTargetsSet(void) 139 142 { return this->targets_; } 140 143 141 void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue. 142 const std::string& getTargets(void) const; //!< Returns a string consisting of the concatenation of the targets. 144 void setTargets(const std::string & targets); // Set the targets of this NotificationQueue. 145 const std::string& getTargets(void) const; // Returns a string consisting of the concatenation of the targets. 146 147 /** 148 @brief Check whether the NotificationQueue is registered with the NotificationManager. 149 @return Returns true if it is registered, false if not. 150 */ 151 inline bool isRegistered(void) 152 { return this->registered_; } 143 153 144 154 bool tidy(void); // Pops all Notifications from the NotificationQueue. … … 160 170 virtual void notificationRemoved(unsigned int index) {} 161 171 162 virtual void clear(bool noGraphics = false); // !<Clears the NotificationQueue by removing all NotificationContainers.172 virtual void clear(bool noGraphics = false); // Clears the NotificationQueue by removing all NotificationContainers. 163 173 164 174 protected: … … 167 177 static const int INF = -1; //!< Constant denoting infinity. 168 178 179 virtual void create(void); // Creates the NotificationQueue. 180 169 181 private: 170 std::string name_; //!< The name of the NotificationQueue. 171 182 void initialize(void); // Initializes the NotificationQueue. 183 184 time_t creationTime_; // The time this NotificationQueue was created. 185 172 186 unsigned int maxSize_; //!< The maximal number of Notifications displayed. 173 187 unsigned int size_; //!< The number of Notifications displayed. … … 186 200 void setName(const std::string& name); //!< Sets the name of the NotificationQueue. 187 201 188 void push(Notification* notification, const std::time_t & time); // !<Adds (pushes) a Notification to the NotificationQueue.189 void pop(void); // !<Removes (pops) the least recently added Notification form the NotificationQueue.190 void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); // !<Removes the Notification that is stored in the input NotificationContainer.202 void push(Notification* notification, const std::time_t & time); // Adds (pushes) a Notification to the NotificationQueue. 203 void pop(void); // Removes (pops) the least recently added Notification form the NotificationQueue. 204 void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); // Removes the Notification that is stored in the input NotificationContainer. 191 205 192 206 }; -
code/branches/tutoriallevel3/src/modules/notifications/NotificationQueueCEGUI.cc
r8453 r8636 47 47 { 48 48 49 CreateFactory(NotificationQueueCEGUI); 50 49 51 // Register tolua_open function when loading the library. 50 52 DeclareToluaInterface(Notifications); … … 52 54 /*static*/ const std::string NotificationQueueCEGUI::NOTIFICATION_LAYER("NotificationLayer"); 53 55 54 NotificationQueueCEGUI::NotificationQueueCEGUI( const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) : NotificationQueue(name, senders, size, displayTime)56 NotificationQueueCEGUI::NotificationQueueCEGUI(BaseObject* creator) : NotificationQueue(creator) 55 57 { 56 58 RegisterObject(NotificationQueueCEGUI); 57 59 60 this->initialize(); 61 } 62 63 NotificationQueueCEGUI::~NotificationQueueCEGUI() 64 { 65 if(GameMode::showsGraphics()) 66 GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() + "\")"); 67 } 68 69 /** 70 @brief 71 Initializes The NotificationQueueCEGUI. 72 */ 73 void NotificationQueueCEGUI::initialize(void) 74 { 58 75 this->displaySize_ = Vector4(1.0, 0.0, 0.0, 0.0); 59 76 this->position_ = Vector4(0.0, 0.0, 0.0, 0.0); … … 62 79 this->fontColor_ = Vector4(1.0, 1.0, 1.0, 1.0); 63 80 this->fontColorStr_ = "FFFFFFFF"; 64 65 // Create the NotificationQueueCEGUI in lua. 66 this->create(); 67 } 68 69 NotificationQueueCEGUI::~NotificationQueueCEGUI() 70 { 71 81 } 82 83 void NotificationQueueCEGUI::XMLPort(Element& xmlelement, XMLPort::Mode mode) 84 { 85 SUPER(NotificationQueueCEGUI, XMLPort, xmlelement, mode); 86 87 XMLPortParam(NotificationQueueCEGUI, "position", setPosition, getPosition, xmlelement, mode); 88 XMLPortParam(NotificationQueueCEGUI, "fontSize", setFontSize, getFontSize, xmlelement, mode); 89 XMLPortParam(NotificationQueueCEGUI, "fontColor", setFontColor, getFontColor, xmlelement, mode); 90 XMLPortParam(NotificationQueueCEGUI, "alignment", setAlignment, getAlignment, xmlelement, mode); 91 XMLPortParam(NotificationQueueCEGUI, "displaySize", setDisplaySize, getDisplaySize, xmlelement, mode); 72 92 } 73 93 … … 266 286 void NotificationQueueCEGUI::create(void) 267 287 { 268 if(GameMode::showsGraphics()) 288 this->NotificationQueue::create(); 289 290 if(this->isRegistered() && GameMode::showsGraphics()) 269 291 GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")"); 270 292 } -
code/branches/tutoriallevel3/src/modules/notifications/NotificationQueueCEGUI.h
r8453 r8636 70 70 71 71 public: 72 NotificationQueueCEGUI( const std::string& name, const std::string& senders = NotificationListener::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);72 NotificationQueueCEGUI(BaseObject* creator); 73 73 virtual ~NotificationQueueCEGUI(); 74 75 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); 74 76 75 77 void destroy(bool noGraphics = false); // Destroys the NotificationQueue. 76 78 77 /**78 @brief Set the size of the window that displays the NotificationQueue.79 @param size A vector whose first component is the relative width of the window (a value between 0 and 1) and whose second component is the absolute width in pixels (additional to the relative width, can be negative). The height is set such that exactly as many Notifications fit as is the maximum size of the NotificationQueue (in terms of the number of Notifications).80 */81 inline void setDisplaySize(const Vector2& size)82 { this->setDisplaySize(Vector4(size.x, size.y, 0.0, 0.0)); }83 79 void setDisplaySize(const Vector4& size); // Set the size of the window that displays the NotificationQueue. 80 84 81 /** 85 82 @brief Get the size of the window that displays the NotificationQueue. … … 130 127 131 128 protected: 129 virtual void create(void); // Creates the NotificationQueue in lua. 130 132 131 virtual void notificationPushed(Notification* notification); // Is called by the NotificationQueue when a notification was pushed 133 132 virtual void notificationPopped(void); // Is called by the NotificationQueue when a notification was popped. … … 146 145 Vector4 fontColor_; //!< The font color of the Notifications text as a vector, in RGBA form, with values from 0 to 1. 147 146 std::string fontColorStr_; //!< The font color of the Notifications text as a string with the ARGB hexadecimal values. 148 149 void create(void); // Creates the NotificationQueue in lua.147 148 void initialize(void); // Initializes The NotificationQueueCEGUI. 150 149 151 150 }; // tolua_export
Note: See TracChangeset
for help on using the changeset viewer.