[2280] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Damian 'Mozork' Frick |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
[2911] | 29 | /** |
---|
[7343] | 30 | @file NotificationQueue.h |
---|
[2911] | 31 | @brief Definition of the NotificationQueue class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[2280] | 34 | #ifndef _NotificationOueue_H__ |
---|
| 35 | #define _NotificationOueue_H__ |
---|
| 36 | |
---|
[7164] | 37 | #include "notifications/NotificationsPrereqs.h" |
---|
[2911] | 38 | |
---|
[3196] | 39 | #include <ctime> |
---|
| 40 | #include <set> |
---|
[2911] | 41 | #include <string> |
---|
[7338] | 42 | #include <vector> |
---|
[2280] | 43 | |
---|
[7349] | 44 | #include "tools/interfaces/Tickable.h" |
---|
[3196] | 45 | #include "util/Math.h" |
---|
[5619] | 46 | #include "interfaces/NotificationListener.h" |
---|
[7338] | 47 | #include "NotificationManager.h" |
---|
[2280] | 48 | |
---|
[2435] | 49 | namespace orxonox |
---|
| 50 | { |
---|
[2911] | 51 | |
---|
| 52 | //! Container to allow easy handling. |
---|
[7338] | 53 | struct NotificationContainer |
---|
[2911] | 54 | { |
---|
[7343] | 55 | Notification* notification; //!< The Notification displayed. |
---|
[2911] | 56 | time_t time; //!< The time the Notification was sent and thus first displayed. |
---|
| 57 | }; |
---|
[5619] | 58 | |
---|
[7343] | 59 | //! Struct to allow ordering of NotificationContainers. |
---|
[7338] | 60 | struct NotificationContainerCompare { |
---|
| 61 | bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const |
---|
[2911] | 62 | { return a->time < b->time; } //!< Ordered by time. |
---|
| 63 | }; |
---|
| 64 | |
---|
[2280] | 65 | /** |
---|
| 66 | @brief |
---|
[2911] | 67 | Displays Notifications from specific senders. |
---|
[2280] | 68 | @author |
---|
| 69 | Damian 'Mozork' Frick |
---|
| 70 | */ |
---|
[7338] | 71 | class _NotificationsExport NotificationQueue : public Tickable, public NotificationListener |
---|
[2280] | 72 | { |
---|
[5619] | 73 | |
---|
[2911] | 74 | public: |
---|
[7342] | 75 | 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 displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); |
---|
[2911] | 76 | virtual ~NotificationQueue(); |
---|
[5619] | 77 | |
---|
[2911] | 78 | virtual void tick(float dt); //!< To update from time to time. |
---|
[5619] | 79 | |
---|
[2911] | 80 | void update(void); //!< Updates the queue. |
---|
| 81 | void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue. |
---|
[5619] | 82 | |
---|
[2911] | 83 | /** |
---|
[7338] | 84 | @brief Get the name of the NotificationQueue. |
---|
| 85 | @return Returns the name. |
---|
| 86 | */ |
---|
| 87 | inline const std::string& getName() const |
---|
| 88 | { return this->name_; } |
---|
| 89 | |
---|
| 90 | /** |
---|
[2911] | 91 | @brief Returns the maximum number of Notifications displayed. |
---|
| 92 | @return Returns maximum size. |
---|
| 93 | */ |
---|
[7338] | 94 | inline unsigned int getMaxSize() const |
---|
[2911] | 95 | { return this->maxSize_; } |
---|
| 96 | /** |
---|
| 97 | @brief Returns the current number of Notifications displayed. |
---|
| 98 | @return Returns the size of the queue. |
---|
| 99 | */ |
---|
[7338] | 100 | inline unsigned int getSize() const |
---|
[2911] | 101 | { return this->size_; } |
---|
| 102 | /** |
---|
| 103 | @brief Returns the time interval the Notification is displayed. |
---|
| 104 | @return Returns the display time. |
---|
| 105 | */ |
---|
[7338] | 106 | inline float getDisplayTime() const |
---|
[2911] | 107 | { return this->displayTime_; } |
---|
| 108 | /** |
---|
| 109 | @brief Returns the position of the NotificationQueue. |
---|
| 110 | @return Returns the position. |
---|
| 111 | */ |
---|
| 112 | inline const Vector2 & getPosition() const |
---|
| 113 | { return this->position_; } |
---|
[5619] | 114 | |
---|
[2911] | 115 | /** |
---|
| 116 | @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue. |
---|
| 117 | @return Retuns a set of string holding the different targets. |
---|
| 118 | */ |
---|
| 119 | inline const std::set<std::string> & getTargetsSet() |
---|
| 120 | { return this->targets_; } |
---|
| 121 | bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets. |
---|
[5619] | 122 | |
---|
[2911] | 123 | /** |
---|
| 124 | @brief Sets the position of the NotificationQueue. |
---|
| 125 | @param pos The position. |
---|
| 126 | */ |
---|
[5619] | 127 | inline void setPosition(Vector2 pos) |
---|
[2911] | 128 | { this->position_ = pos; this->positionChanged(); } |
---|
[2501] | 129 | |
---|
[2911] | 130 | private: |
---|
[7338] | 131 | static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. |
---|
| 132 | static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. |
---|
[2911] | 133 | static const Vector2 DEFAULT_POSITION; //!< the default position. |
---|
[5619] | 134 | |
---|
[7338] | 135 | std::string name_; //!< The name of the NotificationQueue. |
---|
| 136 | |
---|
| 137 | unsigned int maxSize_; //!< The maximal number of Notifications displayed. |
---|
| 138 | unsigned int size_; //!< The number of Notifications displayed. |
---|
| 139 | unsigned int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have. |
---|
| 140 | unsigned int displayTime_; //!< The time a Notification is displayed. |
---|
[2911] | 141 | Vector2 position_; //!< The position of the NotificationQueue. |
---|
[5619] | 142 | |
---|
[2911] | 143 | std::set<std::string> targets_; //!< The targets the Queue displays Notifications of. |
---|
[5619] | 144 | |
---|
[7343] | 145 | std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. //TODO: Would set work as well? |
---|
| 146 | std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue. |
---|
[5619] | 147 | |
---|
[7343] | 148 | float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick. |
---|
[7338] | 149 | NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. |
---|
[5619] | 150 | |
---|
[7163] | 151 | bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already. |
---|
| 152 | |
---|
[2911] | 153 | void initialize(void); //!< Initializes the object. |
---|
[7343] | 154 | void create(void); //!< Creates the NotificationQueue in lua. |
---|
[5619] | 155 | |
---|
[7338] | 156 | bool setName(const std::string& name); //!< Sets the name of the NotificationQueue. |
---|
[5619] | 157 | |
---|
[7338] | 158 | void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications. |
---|
| 159 | void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed. |
---|
| 160 | |
---|
[7343] | 161 | bool setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue. |
---|
[5619] | 162 | |
---|
[2911] | 163 | void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue. |
---|
[7343] | 164 | void sizeChanged(void); //!< Adjusts the NotificationQueue, when the maximum size has changed. |
---|
[5619] | 165 | |
---|
[7343] | 166 | void push(Notification* notification, const std::time_t & time); //!< Add a Notification to the NotificationQueue. |
---|
| 167 | void pop(void); //!< Removes the least recently added Notification form the NotificationQueue. |
---|
| 168 | void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input container. |
---|
[5619] | 169 | |
---|
[7343] | 170 | void clear(void); //!< Clears the queue by removing all Notifications. |
---|
[5619] | 171 | |
---|
[2280] | 172 | }; |
---|
| 173 | |
---|
| 174 | } |
---|
| 175 | |
---|
| 176 | #endif /* _NotificationOverlay_H__ */ |
---|