Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Finished EditMode, needs some polish (no not the language…) though.
Took better advantage of lua tables in NotificationLayer.lua
Fixed a lot of bugs, it really is a miracle that the Notifications worked as well as they did.

  • Property svn:eol-style set to native
File size: 6.8 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 NotificationQueue.h
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 <set>
41#include <string>
42#include <vector>
43
44#include "tools/interfaces/Tickable.h"
45#include "interfaces/NotificationListener.h"
46#include "NotificationManager.h"
47
48namespace orxonox // tolua_export
49{ // tolua_export
50
51    //! Container to allow easy handling.
52    struct NotificationContainer
53    {
54        Notification* notification; //!< The Notification displayed.
55        time_t time; //!< The time the Notification was sent and thus first displayed.
56    };
57
58    //! Struct to allow ordering of NotificationContainers.
59    struct NotificationContainerCompare {
60        bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
61            { return a->time < b->time; } //!< Ordered by time.
62    };
63
64    /**
65    @brief
66        Displays Notifications from specific senders.
67    @author
68        Damian 'Mozork' Frick
69    */
70    class _NotificationsExport NotificationQueue // tolua_export
71        : public Tickable, public NotificationListener
72    { // tolua_export
73
74        public:
75            NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
76            virtual ~NotificationQueue();
77
78            virtual void tick(float dt); //!< To update from time to time.
79
80            void update(void); //!< Updates the queue.
81            void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.
82
83            // tolua_begin
84            /**
85            @brief Get the name of the NotificationQueue.
86            @return Returns the name.
87            */
88            inline const std::string& getName() const
89                { return this->name_; }
90
91            void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
92            /**
93            @brief Returns the maximum number of Notifications displayed.
94            @return Returns maximum size.
95            */
96            inline unsigned int getMaxSize() const
97                { return this->maxSize_; }
98
99            void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
100            /**
101            @brief Returns the time interval the Notification is displayed.
102            @return Returns the display time.
103            */
104            inline float getDisplayTime() const
105                { return this->displayTime_; }
106            // tolua_end
107
108            /**
109            @brief Returns the current number of Notifications displayed.
110            @return Returns the size of the queue.
111            */
112            inline unsigned int getSize() const
113                { return this->size_; }
114
115            /**
116            @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
117            @return Retuns a set of string holding the different targets.
118            */
119            inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet()
120                { return this->targets_; }
121
122            // tolua_begin
123            bool setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
124            const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
125            // tolua_end
126
127        private:
128            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
129            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
130
131            std::string name_; //!< The name of the NotificationQueue.
132
133            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
134            unsigned int size_; //!< The number of Notifications displayed.
135            unsigned int displayTime_; //!< The time a Notification is displayed.
136
137            std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the Queue displays Notifications of.
138
139            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. //TODO: Would set work as well?
140            std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.
141
142            float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick.
143            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
144
145            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
146
147            void initialize(void); //!< Initializes the object.
148            void create(void); //!< Creates the NotificationQueue in lua.
149
150            bool setName(const std::string& name); //!< Sets the name of the NotificationQueue.
151
152            void sizeChanged(void); //!< Adjusts the NotificationQueue, when the maximum size has changed.
153
154            void push(Notification* notification, const std::time_t & time); //!< Add a Notification to the NotificationQueue.
155            void pop(void); //!< Removes the least recently added Notification form the NotificationQueue.
156            void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input container.
157
158            void clear(void); //!< Clears the queue by removing all Notifications.
159
160    }; // tolua_export
161
162} // tolua_export
163
164#endif /* _NotificationOverlay_H__ */
Note: See TracBrowser for help on using the repository browser.