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