[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 | /** |
---|
[3196] | 30 | @file |
---|
[2911] | 31 | @brief Definition of the NotificationQueue class. |
---|
| 32 | */ |
---|
| 33 | |
---|
[2280] | 34 | #ifndef _NotificationOueue_H__ |
---|
| 35 | #define _NotificationOueue_H__ |
---|
| 36 | |
---|
| 37 | #include "OrxonoxPrereqs.h" |
---|
[2911] | 38 | |
---|
[3196] | 39 | #include <ctime> |
---|
| 40 | #include <map> |
---|
| 41 | #include <set> |
---|
[2911] | 42 | #include <string> |
---|
[2280] | 43 | |
---|
[3196] | 44 | #include "util/Math.h" |
---|
| 45 | #include "interfaces/Tickable.h" |
---|
| 46 | #include "overlays/OverlayGroup.h" |
---|
[2280] | 47 | |
---|
[2435] | 48 | namespace orxonox |
---|
| 49 | { |
---|
[2911] | 50 | |
---|
| 51 | //! Container to allow easy handling. |
---|
| 52 | struct NotificationOverlayContainer |
---|
| 53 | { |
---|
| 54 | NotificationOverlay* overlay; //!< Pointer to the NotificationOverlay, everything is about. |
---|
| 55 | Notification* notification; //!< The Notification displayed by the overlay. |
---|
| 56 | time_t time; //!< The time the Notification was sent and thus first displayed. |
---|
| 57 | std::string name; //!< The name of the overlay. |
---|
| 58 | }; |
---|
| 59 | |
---|
| 60 | //! Struct to allow ordering of NotificationOverlayContainers. |
---|
| 61 | struct NotificationOverlayContainerCompare { |
---|
| 62 | bool operator() (const NotificationOverlayContainer* const & a, const NotificationOverlayContainer* const & b) const |
---|
| 63 | { return a->time < b->time; } //!< Ordered by time. |
---|
| 64 | }; |
---|
| 65 | |
---|
[2280] | 66 | /** |
---|
| 67 | @brief |
---|
[2911] | 68 | Displays Notifications from specific senders. |
---|
| 69 | Beware! The NotificationQueue is an OverlayGruop and thus cannot be be a sub-element of an OverlayGroup (at least no for now.) |
---|
[2501] | 70 | |
---|
[2911] | 71 | Creating a NotificationQueue through XML goes as follows: |
---|
| 72 | <NotificationQueue |
---|
| 73 | name = "SuperQueue" //Name of your OverlayQueue. |
---|
| 74 | maxSize = "5" //The maximum size of Notifications displayed. |
---|
| 75 | notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 5) |
---|
| 76 | displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30) |
---|
| 77 | targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.) |
---|
| 78 | font = "VeraMono" //The font (Default is VeraMono) |
---|
| 79 | fontSize = '0.4' //The font size. (Default is 0.025) |
---|
| 80 | position = "0.0, .0.0" //The position of the NotificationQueue. (Default is 0.0,0.0) |
---|
| 81 | /> |
---|
[2280] | 82 | @author |
---|
| 83 | Damian 'Mozork' Frick |
---|
| 84 | */ |
---|
[2911] | 85 | |
---|
| 86 | class _OrxonoxExport NotificationQueue : public OverlayGroup, public Tickable |
---|
[2280] | 87 | { |
---|
[2911] | 88 | |
---|
| 89 | public: |
---|
| 90 | NotificationQueue(BaseObject* creator); |
---|
| 91 | virtual ~NotificationQueue(); |
---|
| 92 | |
---|
| 93 | virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML. |
---|
| 94 | |
---|
| 95 | virtual void tick(float dt); //!< To update from time to time. |
---|
| 96 | |
---|
| 97 | void update(void); //!< Updates the queue. |
---|
| 98 | void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue. |
---|
| 99 | |
---|
| 100 | /** |
---|
| 101 | @brief Returns the maximum number of Notifications displayed. |
---|
| 102 | @return Returns maximum size. |
---|
| 103 | */ |
---|
| 104 | inline int getMaxSize() const |
---|
| 105 | { return this->maxSize_; } |
---|
| 106 | /** |
---|
| 107 | @brief Returns the current number of Notifications displayed. |
---|
| 108 | @return Returns the size of the queue. |
---|
| 109 | */ |
---|
| 110 | inline int getSize() const |
---|
| 111 | { return this->size_; } |
---|
| 112 | /** |
---|
| 113 | @brief Returns the maximum length in characters a Notification message is allowed to have. |
---|
| 114 | @return Returns the maximum Notification length. |
---|
| 115 | */ |
---|
| 116 | inline int getNotificationLength() const |
---|
| 117 | { return this->notificationLength_; } |
---|
| 118 | /** |
---|
| 119 | @brief Returns the time interval the Notification is displayed. |
---|
| 120 | @return Returns the display time. |
---|
| 121 | */ |
---|
| 122 | inline int getDisplayTime() const |
---|
| 123 | { return this->displayTime_; } |
---|
| 124 | /** |
---|
| 125 | @brief Returns the position of the NotificationQueue. |
---|
| 126 | @return Returns the position. |
---|
| 127 | */ |
---|
| 128 | inline const Vector2 & getPosition() const |
---|
| 129 | { return this->position_; } |
---|
| 130 | /** |
---|
| 131 | @brief Returns the font size used to display the Notifications. |
---|
| 132 | @return Returns the font size. |
---|
| 133 | */ |
---|
| 134 | inline float getFontSize() const |
---|
| 135 | { return this->fontSize_; } |
---|
| 136 | /** |
---|
| 137 | @brief Returns the font used to display the Notifications. |
---|
| 138 | @return Returns the font. |
---|
| 139 | */ |
---|
| 140 | inline const std::string & getFont() const |
---|
| 141 | { return this->font_; } |
---|
| 142 | |
---|
| 143 | /** |
---|
| 144 | @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue. |
---|
| 145 | @return Retuns a set of string holding the different targets. |
---|
| 146 | */ |
---|
| 147 | inline const std::set<std::string> & getTargetsSet() |
---|
| 148 | { return this->targets_; } |
---|
| 149 | bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets. |
---|
| 150 | |
---|
| 151 | /** |
---|
| 152 | @brief Sets the position of the NotificationQueue. |
---|
| 153 | @param pos The position. |
---|
| 154 | */ |
---|
| 155 | inline void setPosition(Vector2 pos) |
---|
| 156 | { this->position_ = pos; this->positionChanged(); } |
---|
[2501] | 157 | |
---|
[2911] | 158 | void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector. |
---|
| 159 | |
---|
| 160 | private: |
---|
| 161 | static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. |
---|
| 162 | static const int DEFAULT_LENGTH = 64; //!< The default maximum number of Notifications displayed. |
---|
| 163 | static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. |
---|
[2926] | 164 | static const float DEFAULT_FONT_SIZE; //!< The default font size. |
---|
[2501] | 165 | |
---|
[2911] | 166 | static const std::string DEFAULT_FONT; //!< The default font. |
---|
| 167 | static const Vector2 DEFAULT_POSITION; //!< the default position. |
---|
| 168 | |
---|
| 169 | int maxSize_; //!< The maximal number of Notifications displayed. |
---|
| 170 | int size_; //!< The number of Notifications displayed. |
---|
| 171 | int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have. |
---|
| 172 | int displayTime_; //!< The time a Notification is displayed. |
---|
| 173 | Vector2 position_; //!< The position of the NotificationQueue. |
---|
| 174 | |
---|
| 175 | std::set<std::string> targets_; //!< The targets the Queue displays Notifications of. |
---|
| 176 | |
---|
| 177 | float fontSize_; //!< The font size. |
---|
| 178 | std::string font_; //!< The font. |
---|
| 179 | |
---|
| 180 | std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare> containers_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. |
---|
| 181 | std::map<Notification*, NotificationOverlayContainer*> overlays_; //!< Mapping notifications to their corresponding overlay containers, for easier association and finding. |
---|
| 182 | |
---|
| 183 | float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick. |
---|
| 184 | NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. |
---|
| 185 | |
---|
| 186 | void initialize(void); //!< Initializes the object. |
---|
| 187 | void setDefaults(void); //!< Helper method to set the default values. |
---|
| 188 | |
---|
| 189 | bool setMaxSize(int size); //!< Sets the maximum number of displayed Notifications. |
---|
| 190 | bool setNotificationLength(int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have. |
---|
| 191 | bool setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed. |
---|
| 192 | |
---|
| 193 | bool setTargets(const std::string & targets); //!< Set the targets of this queue. |
---|
| 194 | |
---|
| 195 | bool setFontSize(float size); //!< Set the font size. |
---|
| 196 | bool setFont(const std::string & font); //!< Set the font. |
---|
[2501] | 197 | |
---|
[2911] | 198 | void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue. |
---|
| 199 | |
---|
| 200 | void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue. |
---|
| 201 | bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue. |
---|
| 202 | |
---|
| 203 | void clear(void); //!< Clear the queue. |
---|
| 204 | |
---|
[2280] | 205 | }; |
---|
| 206 | |
---|
| 207 | } |
---|
| 208 | |
---|
| 209 | #endif /* _NotificationOverlay_H__ */ |
---|