Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h @ 2779

Last change on this file since 2779 was 2779, checked in by dafrick, 16 years ago

Updated questsystem to current trunk. Synchronized it with my local state of things. The Notifications are not yet working, though.

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