[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 | /** |
---|
[7403] | 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> |
---|
[7403] | 42 | #include <vector> |
---|
[2280] | 43 | |
---|
[5633] | 44 | #include "tools/interfaces/Tickable.h" |
---|
[7403] | 45 | |
---|
[5619] | 46 | #include "interfaces/NotificationListener.h" |
---|
[7403] | 47 | #include "NotificationManager.h" |
---|
[2280] | 48 | |
---|
[7403] | 49 | namespace orxonox // tolua_export |
---|
| 50 | { // tolua_export |
---|
[2911] | 51 | |
---|
| 52 | //! Container to allow easy handling. |
---|
[7403] | 53 | struct NotificationContainer |
---|
[2911] | 54 | { |
---|
[7403] | 55 | Notification* notification; //!< The Notification displayed. |
---|
[2911] | 56 | time_t time; //!< The time the Notification was sent and thus first displayed. |
---|
| 57 | }; |
---|
[5619] | 58 | |
---|
[7403] | 59 | //! Struct to allow ordering of NotificationContainers. |
---|
| 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 | */ |
---|
[7403] | 71 | class _NotificationsExport NotificationQueue // tolua_export |
---|
| 72 | : public Tickable, public NotificationListener |
---|
| 73 | { // tolua_export |
---|
[2911] | 74 | |
---|
| 75 | public: |
---|
[7403] | 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); |
---|
[2911] | 77 | virtual ~NotificationQueue(); |
---|
[5619] | 78 | |
---|
[7403] | 79 | /** |
---|
| 80 | @brief Destroys the NotificationQueue. |
---|
| 81 | Used in lua. |
---|
| 82 | */ |
---|
| 83 | void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export |
---|
[5619] | 84 | |
---|
[2911] | 85 | virtual void tick(float dt); //!< To update from time to time. |
---|
[5619] | 86 | |
---|
[7403] | 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. |
---|
[5619] | 89 | |
---|
[7403] | 90 | // tolua_begin |
---|
[2911] | 91 | /** |
---|
[7403] | 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. |
---|
| 99 | /** |
---|
[2911] | 100 | @brief Returns the maximum number of Notifications displayed. |
---|
| 101 | @return Returns maximum size. |
---|
| 102 | */ |
---|
[7403] | 103 | inline unsigned int getMaxSize() const |
---|
[2911] | 104 | { return this->maxSize_; } |
---|
[7403] | 105 | |
---|
| 106 | void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed. |
---|
[2911] | 107 | /** |
---|
| 108 | @brief Returns the time interval the Notification is displayed. |
---|
| 109 | @return Returns the display time. |
---|
| 110 | */ |
---|
[7410] | 111 | inline unsigned int getDisplayTime() const |
---|
[2911] | 112 | { return this->displayTime_; } |
---|
[7403] | 113 | // tolua_end |
---|
| 114 | |
---|
[2911] | 115 | /** |
---|
[7403] | 116 | @brief Returns the current number of Notifications displayed. |
---|
| 117 | @return Returns the size of the NotificationQueue. |
---|
[2911] | 118 | */ |
---|
[7403] | 119 | inline unsigned int getSize() const |
---|
| 120 | { return this->size_; } |
---|
[5619] | 121 | |
---|
[2911] | 122 | /** |
---|
[7403] | 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. |
---|
[2911] | 125 | */ |
---|
[7417] | 126 | inline const std::set<std::string> & getTargetsSet() |
---|
[2911] | 127 | { return this->targets_; } |
---|
[5619] | 128 | |
---|
[7403] | 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 |
---|
[2501] | 133 | |
---|
[2911] | 134 | private: |
---|
[7403] | 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. |
---|
[2501] | 137 | |
---|
[7403] | 138 | std::string name_; //!< The name of the NotificationQueue. |
---|
[5619] | 139 | |
---|
[7403] | 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. |
---|
[5619] | 143 | |
---|
[7163] | 144 | bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already. |
---|
| 145 | |
---|
[7417] | 146 | std::set<std::string> targets_; //!< The targets the NotificationQueue displays Notifications of. |
---|
[5619] | 147 | |
---|
[7403] | 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. |
---|
[5619] | 150 | |
---|
[7403] | 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. |
---|
[5619] | 153 | |
---|
[7403] | 154 | void create(void); //!< Creates the NotificationQueue in lua. |
---|
[2501] | 155 | |
---|
[7403] | 156 | void setName(const std::string& name); //!< Sets the name of the NotificationQueue. |
---|
[5619] | 157 | |
---|
[7403] | 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. |
---|
[7412] | 160 | void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); //!< Removes the Notification that is stored in the input NotificationContainer. |
---|
[5619] | 161 | |
---|
[7403] | 162 | void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers. |
---|
[5619] | 163 | |
---|
[7403] | 164 | }; // tolua_export |
---|
[2280] | 165 | |
---|
[7403] | 166 | } // tolua_export |
---|
[2280] | 167 | |
---|
| 168 | #endif /* _NotificationOverlay_H__ */ |
---|