- Timestamp:
- Apr 8, 2009, 1:07:27 AM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk/src/orxonox/overlays/notifications/NotificationQueue.h
r2662 r2909 27 27 */ 28 28 29 /** 30 @file NotificationQueue.h 31 @brief Definition of the NotificationQueue class. 32 */ 33 29 34 #ifndef _NotificationOueue_H__ 30 35 #define _NotificationOueue_H__ 31 36 32 37 #include "OrxonoxPrereqs.h" 38 39 #include <string> 40 #include <set> 41 #include <OgreOverlayManager.h> 33 42 #include <OgreTextAreaOverlayElement.h> 34 35 #include "orxonox/overlays/OverlayText.h" 43 #include <OgrePanelOverlayElement.h> 44 #include <map> 45 #include <ctime> 46 47 #include "orxonox/overlays/OverlayGroup.h" 36 48 #include "orxonox/objects/Tickable.h" 37 49 38 #include <string>50 #include "NotificationManager.h" 39 51 40 52 namespace orxonox 41 53 { 54 55 //! Container to allow easy handling. 56 struct NotificationOverlayContainer 57 { 58 NotificationOverlay* overlay; //!< Pointer to the NotificationOverlay, everything is about. 59 Notification* notification; //!< The Notification displayed by the overlay. 60 time_t time; //!< The time the Notification was sent and thus first displayed. 61 std::string name; //!< The name of the overlay. 62 }; 63 64 //! Struct to allow ordering of NotificationOverlayContainers. 65 struct NotificationOverlayContainerCompare { 66 bool operator() (const NotificationOverlayContainer* const & a, const NotificationOverlayContainer* const & b) const 67 { return a->time < b->time; } //!< Ordered by time. 68 }; 69 42 70 /** 43 71 @brief 44 72 Displays Notifications from specific senders. 73 Beware! The NotificationQueue is an OverlayGruop and thus cannot be be a sub-element of an OverlayGroup (at least no for now.) 74 75 Creating a NotificationQueue through XML goes as follows: 76 <NotificationQueue 77 name = "SuperQueue" //Name of your OverlayQueue. 78 maxSize = "5" //The maximum size of Notifications displayed. 79 notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 5) 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 /> 45 86 @author 46 87 Damian 'Mozork' Frick 47 88 */ 48 class _OrxonoxExport NotificationQueue : public OverlayText, public Tickable 89 90 class _OrxonoxExport NotificationQueue : public OverlayGroup, public Tickable 49 91 { 50 public: 51 NotificationQueue(BaseObject* creator); 52 virtual ~NotificationQueue(); 53 54 static NotificationQueue* queue_s; //TDO Singleton? oder im level. 55 56 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); 57 58 virtual void tick(float dt); 59 60 void update(void); 61 62 int getLength(void) const 63 { return this->length_; } 64 int getWidth(void) const 65 { return this->width_; } 66 67 void setQueueText(const std::string & text); 68 bool setLength(int length); 69 bool setWidth(int width); 70 71 private: 72 Ogre::UTFString queueText_; 73 int length_; 74 int width_; 75 92 93 public: 94 NotificationQueue(BaseObject* creator); 95 virtual ~NotificationQueue(); 96 97 virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML. 98 99 virtual void tick(float dt); //!< To update from time to time. 100 101 void update(void); //!< Updates the queue. 102 void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue. 103 104 /** 105 @brief Returns the maximum number of Notifications displayed. 106 @return Returns maximum size. 107 */ 108 inline int getMaxSize() const 109 { return this->maxSize_; } 110 /** 111 @brief Returns the current number of Notifications displayed. 112 @return Returns the size of the queue. 113 */ 114 inline int getSize() const 115 { return this->size_; } 116 /** 117 @brief Returns the maximum length in characters a Notification message is allowed to have. 118 @return Returns the maximum Notification length. 119 */ 120 inline int getNotificationLength() const 121 { return this->notificationLength_; } 122 /** 123 @brief Returns the time interval the Notification is displayed. 124 @return Returns the display time. 125 */ 126 inline int getDisplayTime() const 127 { return this->displayTime_; } 128 /** 129 @brief Returns the position of the NotificationQueue. 130 @return Returns the position. 131 */ 132 inline const Vector2 & getPosition() const 133 { return this->position_; } 134 /** 135 @brief Returns the font size used to display the Notifications. 136 @return Returns the font size. 137 */ 138 inline float getFontSize() const 139 { return this->fontSize_; } 140 /** 141 @brief Returns the font used to display the Notifications. 142 @return Returns the font. 143 */ 144 inline const std::string & getFont() const 145 { return this->font_; } 146 147 /** 148 @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue. 149 @return Retuns a set of string holding the different targets. 150 */ 151 inline const std::set<std::string> & getTargetsSet() 152 { return this->targets_; } 153 bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets. 154 155 /** 156 @brief Sets the position of the NotificationQueue. 157 @param pos The position. 158 */ 159 inline void setPosition(Vector2 pos) 160 { this->position_ = pos; this->positionChanged(); } 161 162 void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector. 163 164 private: 165 static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. 166 static const int DEFAULT_LENGTH = 64; //!< The default maximum number of Notifications displayed. 167 static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 168 static const float DEFAULT_FONT_SIZE = 0.025; //!< The default font size. 169 170 static const std::string DEFAULT_FONT; //!< The default font. 171 static const Vector2 DEFAULT_POSITION; //!< the default position. 172 173 int maxSize_; //!< The maximal number of Notifications displayed. 174 int size_; //!< The number of Notifications displayed. 175 int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have. 176 int displayTime_; //!< The time a Notification is displayed. 177 Vector2 position_; //!< The position of the NotificationQueue. 178 179 std::set<std::string> targets_; //!< The targets the Queue displays Notifications of. 180 181 float fontSize_; //!< The font size. 182 std::string font_; //!< The font. 183 184 std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare> containers_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. 185 std::map<Notification*, NotificationOverlayContainer*> overlays_; //!< Mapping notifications to their corresponding overlay containers, for easier association and finding. 186 187 float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick. 188 NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 189 190 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. 196 197 bool setTargets(const std::string & targets); //!< Set the targets of this queue. 198 199 bool setFontSize(float size); //!< Set the font size. 200 bool setFont(const std::string & font); //!< Set the font. 201 202 void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue. 203 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. 206 207 void clear(void); //!< Clear the queue. 208 76 209 }; 77 210
Note: See TracChangeset
for help on using the changeset viewer.