Orxonox  0.0.5 Codename: Arcturus
NotificationQueue.h
Go to the documentation of this file.
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 
35 #ifndef _NotificationOueue_H__
36 #define _NotificationOueue_H__
37 
39 
40 #include <ctime>
41 #include <set>
42 #include <string>
43 #include <vector>
44 
45 #include "NotificationManager.h"
46 
47 #include "core/BaseObject.h"
50 
51 namespace orxonox
52 {
53 
61  {
63  time_t time;
64  };
65 
73  bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
74  { return a->time < b->time; }
75  };
76 
93  {
94 
95  public:
96  NotificationQueue(Context* context);
97  virtual ~NotificationQueue();
98 
99  virtual void tick(float dt) override; // To update from time to time.
100  virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode) override;
101 
102  virtual void changedName(void) override;
103 
104  void update(void); // Updates the NotificationQueue.
105  void update(Notification* notification, const std::time_t & time); // Updates the NotificationQueue by adding an new Notification.
106 
107  // tolua_begin
112  inline const std::string& getName(void) const
113  { return this->BaseObject::getName(); }
114 
115  void setMaxSize(unsigned int size); // Sets the maximum number of displayed Notifications.
120  inline unsigned int getMaxSize(void) const
121  { return this->maxSize_; }
122 
123  void setDisplayTime(int time); // Sets the maximum number of seconds a Notification is displayed.
128  inline int getDisplayTime(void) const
129  { return this->displayTime_; }
130  // tolua_end
131  void maxSizeChanged(void); // Is called when the maximum number of displayed Notifications has changed.
132  void displayTimeChanged(void);
133 
138  inline unsigned int getSize(void) const
139  { return this->size_; }
140 
145  inline const std::set<std::string> & getTargetsSet(void)
146  { return this->targets_; }
147 
148  void setTargets(const std::string & targets); // Set the targets of this NotificationQueue.
149  const std::string& getTargets(void) const; // Returns a string consisting of the concatenation of the targets.
150  void targetsChanged(void); // Is called when the NotificationQueue's targets have changed.
151 
156  inline bool isRegistered(void)
157  { return this->registered_; }
158 
159  bool tidy(void); // Pops all Notifications from the NotificationQueue.
160 
161  protected:
162  void registerVariables();
163 
168  virtual void notificationPushed(Notification* notification) {}
172  virtual void notificationPopped(void) {}
177  virtual void notificationRemoved(unsigned int index) {}
178 
179  virtual void clear(bool noGraphics = false); // Clears the NotificationQueue by removing all NotificationContainers.
180 
181  protected:
182  static const unsigned int DEFAULT_SIZE = 5;
183  static const unsigned int DEFAULT_DISPLAY_TIME = 30;
184  static const int INF = -1;
185 
186  virtual void create(void); // Creates the NotificationQueue.
187 
188  private:
189  time_t creationTime_;
190 
191  unsigned int maxSize_;
192  unsigned int size_;
194 
195  bool registered_;
196 
197  std::set<std::string> targets_;
198 
199  std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_;
200  std::vector<NotificationContainer*> notifications_;
201 
202  float tickTime_;
204 
205  void setName(const std::string& name);
206 
207  void push(Notification* notification, const std::time_t & time); // Adds (pushes) a Notification to the NotificationQueue.
208  void pop(void); // Removes (pops) the least recently added Notification form the NotificationQueue.
209  void remove(const std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator& containerIterator); // Removes the Notification that is stored in the input NotificationContainer.
210 
211  };
212 
213 }
214 
215 #endif /* _NotificationQueue_H__ */
The BaseObject is the parent of all classes representing an instance in the game. ...
Definition: BaseObject.h:63
Container to allow easy handling of the Notifications.
Definition: NotificationQueue.h:60
int getDisplayTime(void) const
Returns the time interval the Notification is displayed.
Definition: NotificationQueue.h:128
std::multiset< NotificationContainer *, NotificationContainerCompare > ordering_
The NotificationContainers ordered by the time they were registered.
Definition: NotificationQueue.h:199
This class is the base class of all the Objects in the universe that need to be synchronised over the...
Definition: Synchronisable.h:142
Declaration of the Tickable interface.
int displayTime_
The time a Notification is displayed.
Definition: NotificationQueue.h:193
const std::set< std::string > & getTargetsSet(void)
Returns the targets of this NotificationQueue, reps.
Definition: NotificationQueue.h:145
::std::string string
Definition: gtest-port.h:756
virtual void notificationRemoved(unsigned int index)
Is called when a notification was removed.
Definition: NotificationQueue.h:177
#define _NotificationsExport
Definition: NotificationsPrereqs.h:60
unsigned int size_
The number of Notifications displayed.
Definition: NotificationQueue.h:192
Displays Notifications from specific senders.
Definition: NotificationQueue.h:92
virtual void notificationPushed(Notification *notification)
Is called when a notification was pushed.
Definition: NotificationQueue.h:168
Definition of the NotificationManager class.
std::vector< NotificationContainer * > notifications_
The NotificationContainers in the order they were added to the NotificationQueue. ...
Definition: NotificationQueue.h:200
NotificationContainer timeLimit_
Helper object to check against to determine whether Notifications have expired.
Definition: NotificationQueue.h:203
xmlelement
Definition: Super.h:519
unsigned int maxSize_
The maximal number of Notifications displayed.
Definition: NotificationQueue.h:191
const std::string & getName() const
Returns the name of the object.
Definition: BaseObject.h:96
unsigned int getMaxSize(void) const
Returns the maximum number of Notifications displayed.
Definition: NotificationQueue.h:120
std::set< std::string > targets_
The targets the NotificationQueue displays Notifications of.
Definition: NotificationQueue.h:197
bool registered_
Helper variable to remember whether the NotificationQueue is registered already.
Definition: NotificationQueue.h:195
float tickTime_
Helper variable, to not have to check for Notifications that have been displayed too long...
Definition: NotificationQueue.h:202
Die Wagnis Klasse hat die folgenden Aufgaben:
Definition: ApplicationPaths.cc:66
Shared library macros, enums, constants and forward declarations for the questsystem module ...
Mode
Definition: CorePrereqs.h:102
time_t creationTime_
The time this NotificationQueue was created.
Definition: NotificationQueue.h:189
Declaration of BaseObject, the base class of all objects in Orxonox.
Definition: Context.h:45
const std::string & getName(void) const
Get the name of the NotificationQueue.
Definition: NotificationQueue.h:112
bool isRegistered(void)
Check whether the NotificationQueue is registered with the NotificationManager.
Definition: NotificationQueue.h:156
A Notification represents a short message used to inform the player about something that just happene...
Definition: NotificationManager.h:61
Notification * notification
The Notification displayed.
Definition: NotificationQueue.h:62
The Tickable interface provides a tick(dt) function, that gets called every frame.
Definition: Tickable.h:52
time_t time
The time the Notification was sent and thus first displayed.
Definition: NotificationQueue.h:63
Struct to allow ordering of NotificationContainers.
Definition: NotificationQueue.h:72
unsigned int getSize(void) const
Returns the current number of Notifications displayed.
Definition: NotificationQueue.h:138
virtual void notificationPopped(void)
Is called when a notification was popped.
Definition: NotificationQueue.h:172