Changeset 7403 for code/trunk/src/modules/notifications/NotificationQueue.h
- Timestamp:
- Sep 11, 2010, 10:20:44 AM (15 years ago)
- Location:
- code/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/notifications (added) merged: 7319,7324,7326,7338-7343,7348-7349,7351,7354-7355,7358-7360,7362,7395,7398-7400
- Property svn:mergeinfo changed
-
code/trunk/src/modules/notifications/NotificationQueue.h
r7401 r7403 28 28 29 29 /** 30 @file 30 @file NotificationQueue.h 31 31 @brief Definition of the NotificationQueue class. 32 32 */ … … 38 38 39 39 #include <ctime> 40 #include <map>41 40 #include <set> 42 41 #include <string> 42 #include <vector> 43 43 44 #include "util/Math.h"45 44 #include "tools/interfaces/Tickable.h" 46 #include "overlays/OverlayGroup.h" 45 47 46 #include "interfaces/NotificationListener.h" 47 #include "NotificationManager.h" 48 48 49 namespace orxonox 50 { 49 namespace orxonox // tolua_export 50 { // tolua_export 51 51 52 52 //! Container to allow easy handling. 53 struct Notification OverlayContainer53 struct NotificationContainer 54 54 { 55 NotificationOverlay* overlay; //!< Pointer to the NotificationOverlay, everything is about. 56 Notification* notification; //!< The Notification displayed by the overlay. 55 Notification* notification; //!< The Notification displayed. 57 56 time_t time; //!< The time the Notification was sent and thus first displayed. 58 std::string name; //!< The name of the overlay.59 57 }; 60 58 61 //! Struct to allow ordering of Notification OverlayContainers.62 struct Notification OverlayContainerCompare {63 bool operator() (const Notification OverlayContainer* const & a, const NotificationOverlayContainer* const & b) const59 //! Struct to allow ordering of NotificationContainers. 60 struct NotificationContainerCompare { 61 bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const 64 62 { return a->time < b->time; } //!< Ordered by time. 65 63 }; … … 68 66 @brief 69 67 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 @code <Level></Level> @endcode tags or bad things will happen.74 75 @code76 <NotificationQueue77 name = "SuperQueue" //Name of your OverlayQueue.78 maxSize = "5" //The maximum number of Notifications displayed. (Default is 5)79 notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 64)80 displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30)81 targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.)82 font = "VeraMono" //The font (Default is VeraMono)83 fontSize = '0.4' //The font size. (Default is 0.025)84 position = "0.0, 0.0" //The position of the NotificationQueue. (Default is 0.0,0.0)85 />86 @endcode87 68 @author 88 69 Damian 'Mozork' Frick 89 70 */ 90 91 class _NotificationsExport NotificationQueue : public OverlayGroup,public Tickable, public NotificationListener92 { 71 class _NotificationsExport NotificationQueue // tolua_export 72 : public Tickable, public NotificationListener 73 { // tolua_export 93 74 94 75 public: 95 NotificationQueue( BaseObject* creator);76 NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); 96 77 virtual ~NotificationQueue(); 97 78 98 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML. 79 /** 80 @brief Destroys the NotificationQueue. 81 Used in lua. 82 */ 83 void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export 99 84 100 85 virtual void tick(float dt); //!< To update from time to time. 101 86 102 void update(void); //!< Updates the queue.103 void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.87 void update(void); //!< Updates the NotificationQueue. 88 void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification. 104 89 90 // tolua_begin 91 /** 92 @brief Get the name of the NotificationQueue. 93 @return Returns the name. 94 */ 95 inline const std::string& getName() const 96 { return this->name_; } 97 98 void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications. 105 99 /** 106 100 @brief Returns the maximum number of Notifications displayed. 107 101 @return Returns maximum size. 108 102 */ 109 inline int getMaxSize() const103 inline unsigned int getMaxSize() const 110 104 { return this->maxSize_; } 111 /** 112 @brief Returns the current number of Notifications displayed. 113 @return Returns the size of the queue. 114 */ 115 inline int getSize() const 116 { return this->size_; } 117 /** 118 @brief Returns the maximum length in characters a Notification message is allowed to have. 119 @return Returns the maximum Notification length. 120 */ 121 inline int getNotificationLength() const 122 { return this->notificationLength_; } 105 106 void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed. 123 107 /** 124 108 @brief Returns the time interval the Notification is displayed. 125 109 @return Returns the display time. 126 110 */ 127 inline int getDisplayTime() const111 inline float getDisplayTime() const 128 112 { return this->displayTime_; } 129 /** 130 @brief Returns the position of the NotificationQueue. 131 @return Returns the position. 132 */ 133 inline const Vector2 & getPosition() const 134 { return this->position_; } 135 /** 136 @brief Returns the font size used to display the Notifications. 137 @return Returns the font size. 138 */ 139 inline float getFontSize() const 140 { return this->fontSize_; } 141 /** 142 @brief Returns the font used to display the Notifications. 143 @return Returns the font. 144 */ 145 inline const std::string & getFont() const 146 { return this->font_; } 113 // tolua_end 147 114 148 115 /** 149 @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.150 @return Retu ns a set of string holding the different targets.116 @brief Returns the current number of Notifications displayed. 117 @return Returns the size of the NotificationQueue. 151 118 */ 152 inline const std::set<std::string> & getTargetsSet() 153 { return this->targets_; } 154 bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets. 119 inline unsigned int getSize() const 120 { return this->size_; } 155 121 156 122 /** 157 @brief Sets the position of theNotificationQueue.158 @ param pos The position.123 @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue. 124 @return Returns a set of strings holding the different targets. 159 125 */ 160 inline void setPosition(Vector2 pos)161 { this->position_ = pos; this->positionChanged(); }126 inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet() 127 { return this->targets_; } 162 128 163 void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector. 129 // tolua_begin 130 void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue. 131 const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets. 132 // tolua_end 164 133 165 134 private: 166 static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. 167 static const int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed. 168 static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 169 static const float DEFAULT_FONT_SIZE; //!< The default font size. 135 static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. 136 static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 170 137 171 static const std::string DEFAULT_FONT; //!< The default font. 172 static const Vector2 DEFAULT_POSITION; //!< the default position. 138 std::string name_; //!< The name of the NotificationQueue. 173 139 174 int maxSize_; //!< The maximal number of Notifications displayed. 175 int size_; //!< The number of Notifications displayed. 176 int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have. 177 int displayTime_; //!< The time a Notification is displayed. 178 Vector2 position_; //!< The position of the NotificationQueue. 179 180 std::set<std::string> targets_; //!< The targets the Queue displays Notifications of. 181 182 float fontSize_; //!< The font size. 183 std::string font_; //!< The font. 184 185 std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare> containers_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. 186 std::map<Notification*, NotificationOverlayContainer*> overlays_; //!< Mapping notifications to their corresponding overlay containers, for easier association and finding. 187 188 float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick. 189 NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 140 unsigned int maxSize_; //!< The maximal number of Notifications displayed. 141 unsigned int size_; //!< The number of Notifications displayed. 142 unsigned int displayTime_; //!< The time a Notification is displayed. 190 143 191 144 bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already. 192 145 193 void initialize(void); //!< Initializes the object. 194 void setDefaults(void); //!< Helper method to set the default values. 146 std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the NotificationQueue displays Notifications of. 195 147 196 bool setMaxSize(int size); //!< Sets the maximum number of displayed Notifications. 197 bool setNotificationLength(int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have. 198 bool setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed. 148 std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. 149 std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue. 199 150 200 bool setTargets(const std::string & targets); //!< Set the targets of this queue. 151 float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick. 152 NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 201 153 202 bool setFontSize(float size); //!< Set the font size. 203 bool setFont(const std::string & font); //!< Set the font. 154 void create(void); //!< Creates the NotificationQueue in lua. 204 155 205 void positionChanged(void); //!< Aligns all the Notifications to the positionof the NotificationQueue.156 void setName(const std::string& name); //!< Sets the name of the NotificationQueue. 206 157 207 void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue. 208 bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue. 158 void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue. 159 void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue. 160 void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input NotificationContainer. 209 161 210 void clear(void); //!< Clear the queue.162 void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers. 211 163 212 }; 164 }; // tolua_export 213 165 214 } 166 } // tolua_export 215 167 216 168 #endif /* _NotificationOverlay_H__ */
Note: See TracChangeset
for help on using the changeset viewer.