Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/notifications/src/modules/notifications/NotificationQueue.h @ 7338

Last change on this file since 7338 was 7338, checked in by dafrick, 14 years ago

Changing from OrxonoxOverlays to CEGUI as means of displaying Notifications.
Still messy and not working completely but it's a start.

  • Property svn:eol-style set to native
File size: 8.5 KB
Line 
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
29/**
30    @file
31    @brief Definition of the NotificationQueue class.
32*/
33
34#ifndef _NotificationOueue_H__
35#define _NotificationOueue_H__
36
37#include "notifications/NotificationsPrereqs.h"
38
39#include <ctime>
40#include <map>
41#include <set>
42#include <string>
43#include <vector>
44
45#include "util/Math.h"
46#include "core/OrxonoxClass.h"
47#include "tools/interfaces/Tickable.h"
48#include "interfaces/NotificationListener.h"
49#include "NotificationManager.h"
50
51namespace orxonox
52{
53
54    //! Container to allow easy handling.
55    struct NotificationContainer
56    {
57        Notification* notification; //!< The Notification displayed by the overlay.
58        time_t time; //!< The time the Notification was sent and thus first displayed.
59    };
60
61    //! Struct to allow ordering of NotificationOverlayContainers.
62    struct NotificationContainerCompare {
63        bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
64            { return a->time < b->time; } //!< Ordered by time.
65    };
66
67    /**
68    @brief
69        Displays Notifications from specific senders.
70    @author
71        Damian 'Mozork' Frick
72    */
73
74    class _NotificationsExport NotificationQueue : public Tickable, public NotificationListener
75    {
76
77        public:
78            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 length = NotificationQueue::DEFAULT_LENGTH, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
79            virtual ~NotificationQueue();
80
81            virtual void tick(float dt); //!< To update from time to time.
82
83            void update(void); //!< Updates the queue.
84            void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.
85
86            /**
87            @brief Get the name of the NotificationQueue.
88            @return Returns the name.
89            */
90            inline const std::string& getName() const
91                { return this->name_; }
92
93            /**
94            @brief Returns the maximum number of Notifications displayed.
95            @return Returns maximum size.
96            */
97            inline unsigned int getMaxSize() const
98                { return this->maxSize_; }
99            /**
100            @brief Returns the current number of Notifications displayed.
101            @return Returns the size of the queue.
102            */
103            inline unsigned int getSize() const
104                { return this->size_; }
105            /**
106            @brief Returns the maximum length in characters a Notification message is allowed to have.
107            @return Returns the maximum Notification length.
108            */
109            inline unsigned int getNotificationLength() const
110                { return this->notificationLength_; }
111            /**
112            @brief Returns the time interval the Notification is displayed.
113            @return Returns the display time.
114            */
115            inline float getDisplayTime() const
116                { return this->displayTime_; }
117            /**
118            @brief Returns the position of the NotificationQueue.
119            @return Returns the position.
120            */
121            inline const Vector2 & getPosition() const
122                { return this->position_; }
123            /**
124            @brief Returns the font size used to display the Notifications.
125            @return  Returns the font size.
126            */
127            inline float getFontSize() const
128                { return this->fontSize_; }
129            /**
130            @brief Returns the font used to display the Notifications.
131            @return Returns the font.
132            */
133            inline const std::string & getFont() const
134                { return this->font_; }
135
136            /**
137            @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
138            @return Retuns a set of string holding the different targets.
139            */
140            inline const std::set<std::string> & getTargetsSet()
141                { return this->targets_; }
142            bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
143
144            /**
145            @brief Sets the position of the NotificationQueue.
146            @param pos The position.
147            */
148            inline void setPosition(Vector2 pos)
149                { this->position_ = pos; this->positionChanged(); }
150
151        private:
152            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
153            static const unsigned int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed.
154            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
155            static const float DEFAULT_FONT_SIZE; //!< The default font size.
156
157            static const std::string DEFAULT_FONT; //!< The default font.
158            static const Vector2 DEFAULT_POSITION; //!< the default position.
159
160            std::string name_; //!< The name of the NotificationQueue.
161
162            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
163            unsigned int size_; //!< The number of Notifications displayed.
164            unsigned int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have.
165            unsigned int displayTime_; //!< The time a Notification is displayed.
166            Vector2 position_; //!< The position of the NotificationQueue.
167
168            std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
169
170            float fontSize_; //!< The font size.
171            std::string font_; //!< The font.
172
173            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. //TODO: Would set work as well?
174            std::vector<NotificationContainer*> notifications_;
175
176            float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick.
177            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
178
179            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
180
181            void initialize(void); //!< Initializes the object.
182            void create(void);
183
184            bool setName(const std::string& name); //!< Sets the name of the NotificationQueue.
185
186            void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
187            void setNotificationLength(unsigned int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
188            void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
189
190            bool setTargets(const std::string & targets); //!< Set the targets of this queue.
191
192            bool setFontSize(float size); //!< Set the font size.
193            bool setFont(const std::string & font); //!< Set the font.
194
195            void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
196
197            void push(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
198            void pop(void);
199            void remove(NotificationContainer* container);
200
201            void clear(void); //!< Clear the queue.
202
203    };
204
205}
206
207#endif /* _NotificationOverlay_H__ */
Note: See TracBrowser for help on using the repository browser.