Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Making NotificationQueue XML-loadable. Adding notifications to all levels.

  • Property svn:eol-style set to native
File size: 8.7 KB
RevLine 
[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.
[7456]32    @ingroup Notifications
[2911]33*/
34
[2280]35#ifndef _NotificationOueue_H__
36#define _NotificationOueue_H__
37
[7164]38#include "notifications/NotificationsPrereqs.h"
[2911]39
[3196]40#include <ctime>
41#include <set>
[2911]42#include <string>
[7403]43#include <vector>
[2280]44
[7489]45#include "NotificationManager.h"
46
[8636]47#include "core/BaseObject.h"
[5633]48#include "tools/interfaces/Tickable.h"
[2280]49
[8453]50namespace orxonox
51{
[2911]52
[7552]53    /**
54    @brief
55        Container to allow easy handling of the @ref orxonox::Notification "Notifications".
56
57    @ingroup Notifications
58    */
[7403]59    struct NotificationContainer
[2911]60    {
[7489]61        Notification* notification; //!< The Notification displayed.
62        time_t time; //!< The time the Notification was sent and thus first displayed.
[2911]63    };
[5619]64
[7552]65    /**
66    @brief
67        Struct to allow ordering of @ref orxonox::NotificationContainer "NotificationContainers".
68
69    @ingroup Notifications
70    */
[7403]71    struct NotificationContainerCompare {
72        bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
[7489]73            { return a->time < b->time; } //!< Ordering by time.
[2911]74    };
75
[2280]76    /**
77    @brief
[7484]78        Displays @ref orxonox::Notification "Notifications" from specific senders.
79
[8453]80        There are quite some parameters that influence the behavior of the NotificationQueue:
[7488]81        - @b name The name of the NotificationQueue. It needs to be unique.
82        - @b senders The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
83        - @b size The size of the NotificationQueue, it specifies how many @ref orxonox::Notification "Notifications" are displayed at once at the most.
84        - @b displayTime The time a @ref orxonox::Notification "Notification" is displayed with this NotificationQueue.
[7486]85
[2280]86    @author
87        Damian 'Mozork' Frick
[7552]88
89    @ingroup Notifications
[2280]90    */
[8636]91    class _NotificationsExport NotificationQueue : public BaseObject, public Tickable
[8453]92    {
[2911]93
94        public:
[8636]95            NotificationQueue(BaseObject* creator);
96            NotificationQueue(BaseObject* creator, const std::string& name, const std::string& senders = NotificationListener::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
[2911]97            virtual ~NotificationQueue();
[5619]98
[8636]99            virtual void tick(float dt); // To update from time to time.
100            virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
[5619]101
[8636]102            void update(void); // Updates the NotificationQueue.
103            void update(Notification* notification, const std::time_t & time); // Updates the NotificationQueue by adding an new Notification.
[5619]104
[7403]105            // tolua_begin
[2911]106            /**
[7403]107            @brief Get the name of the NotificationQueue.
108            @return Returns the name.
109            */
[8636]110            inline const std::string& getName(void) const
111                { return this->BaseObject::getName(); }
[7403]112
[8636]113            void setMaxSize(unsigned int size); // Sets the maximum number of displayed Notifications.
[7403]114            /**
[2911]115            @brief Returns the maximum number of Notifications displayed.
116            @return Returns maximum size.
117            */
[8636]118            inline unsigned int getMaxSize(void) const
[2911]119                { return this->maxSize_; }
[7403]120
[8636]121            void setDisplayTime(int time); // Sets the maximum number of seconds a Notification is displayed.
[2911]122            /**
123            @brief Returns the time interval the Notification is displayed.
124            @return Returns the display time.
125            */
[8636]126            inline int getDisplayTime(void) const
[2911]127                { return this->displayTime_; }
[7403]128            // tolua_end
129
[2911]130            /**
[7403]131            @brief Returns the current number of Notifications displayed.
132            @return Returns the size of the NotificationQueue.
[2911]133            */
[8636]134            inline unsigned int getSize(void) const
[7403]135                { return this->size_; }
[5619]136
[2911]137            /**
[7403]138            @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue.
139            @return Returns a set of strings holding the different targets.
[2911]140            */
[8636]141            inline const std::set<std::string> & getTargetsSet(void)
[2911]142                { return this->targets_; }
[5619]143
[8636]144            void setTargets(const std::string & targets); // Set the targets of this NotificationQueue.
145            const std::string& getTargets(void) const; // Returns a string consisting of the concatenation of the targets.
[2501]146
[8636]147            /**
148            @brief Check whether the NotificationQueue is registered with the NotificationManager.
149            @return Returns true if it is registered, false if not.
150            */
151            inline bool isRegistered(void)
152                { return this->registered_; }
153
[8453]154            bool tidy(void); // Pops all Notifications from the NotificationQueue.
155           
156        protected:
157            /**
158            @brief Is called when a notification was pushed.
159            @param notification The Notification that was pushed.
160            */
161            virtual void notificationPushed(Notification* notification) {}
162            /**
163            @brief Is called when a notification was popped.
164            */
165            virtual void notificationPopped(void) {}
166            /**
167            @brief Is called when a notification was removed.
168            @param index The index the removed notification was at.
169            */
170            virtual void notificationRemoved(unsigned int index) {}
171           
[8636]172            virtual void clear(bool noGraphics = false); // Clears the NotificationQueue by removing all NotificationContainers.
[8453]173
174        protected:
[7403]175            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
176            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
[8453]177            static const int INF = -1; //!< Constant denoting infinity.
[2501]178
[8636]179            virtual void create(void); // Creates the NotificationQueue.
180
[8453]181        private:
[8636]182            void initialize(void); // Initializes the NotificationQueue.
[5619]183
[8636]184            time_t creationTime_; // The time this NotificationQueue was created.
185           
[7403]186            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
187            unsigned int size_; //!< The number of Notifications displayed.
[8453]188            int displayTime_; //!< The time a Notification is displayed.
[5619]189
[7163]190            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
191
[7417]192            std::set<std::string> targets_; //!< The targets the NotificationQueue displays Notifications of.
[5619]193
[7403]194            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered.
195            std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.
[5619]196
[7403]197            float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick.
198            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
[5619]199
[7403]200            void setName(const std::string& name); //!< Sets the name of the NotificationQueue.
[5619]201
[8636]202            void push(Notification* notification, const std::time_t & time); // Adds (pushes) a Notification to the NotificationQueue.
203            void pop(void); // Removes (pops) the least recently added Notification form the NotificationQueue.
204            void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); // Removes the Notification that is stored in the input NotificationContainer.
[5619]205
[8453]206    };
[5619]207
[8453]208}
[2280]209
[8453]210#endif /* _NotificationQueue_H__ */
Note: See TracBrowser for help on using the repository browser.