- Timestamp:
- Sep 3, 2010, 3:55:32 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.
Note: See TracChangeset
for help on using the changeset viewer.