Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7371 was 7298, checked in by landauf, 14 years ago

XML code has to be enclosed in @code and @endcode tags or Doxygen will complain

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