Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 11, 2010, 10:20:44 AM (14 years ago)
Author:
dafrick
Message:

Merged notifications branch back to trunk.

Location:
code/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/trunk

  • code/trunk/src/modules/notifications/NotificationQueue.h

    r7401 r7403  
    2828
    2929/**
    30     @file
     30    @file NotificationQueue.h
    3131    @brief Definition of the NotificationQueue class.
    3232*/
     
    3838
    3939#include <ctime>
    40 #include <map>
    4140#include <set>
    4241#include <string>
     42#include <vector>
    4343
    44 #include "util/Math.h"
    4544#include "tools/interfaces/Tickable.h"
    46 #include "overlays/OverlayGroup.h"
     45
    4746#include "interfaces/NotificationListener.h"
     47#include "NotificationManager.h"
    4848
    49 namespace orxonox
    50 {
     49namespace orxonox // tolua_export
     50{ // tolua_export
    5151
    5252    //! Container to allow easy handling.
    53     struct NotificationOverlayContainer
     53    struct NotificationContainer
    5454    {
    55         NotificationOverlay* overlay; //!< Pointer to the NotificationOverlay, everything is about.
    56         Notification* notification; //!< The Notification displayed by the overlay.
     55        Notification* notification; //!< The Notification displayed.
    5756        time_t time; //!< The time the Notification was sent and thus first displayed.
    58         std::string name; //!< The name of the overlay.
    5957    };
    6058
    61     //! Struct to allow ordering of NotificationOverlayContainers.
    62     struct NotificationOverlayContainerCompare {
    63         bool operator() (const NotificationOverlayContainer* const & a, const NotificationOverlayContainer* const & b) const
     59    //! Struct to allow ordering of NotificationContainers.
     60    struct NotificationContainerCompare {
     61        bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
    6462            { return a->time < b->time; } //!< Ordered by time.
    6563    };
     
    6866    @brief
    6967        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.)
    71 
    72         Creating a NotificationQueue through XML goes as follows:
    73         Be aware that the NotificationQueue must be inside the @code <Level></Level> @endcode tags or bad things will happen.
    74        
    75         @code
    76         <NotificationQueue
    77             name = "SuperQueue" //Name of your OverlayQueue.
    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)
    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)
    84             position = "0.0, 0.0" //The position of the NotificationQueue. (Default is 0.0,0.0)
    85         />
    86         @endcode
    8768    @author
    8869        Damian 'Mozork' Frick
    8970    */
    90 
    91     class _NotificationsExport NotificationQueue : public OverlayGroup, public Tickable, public NotificationListener
    92     {
     71    class _NotificationsExport NotificationQueue // tolua_export
     72        : public Tickable, public NotificationListener
     73    { // tolua_export
    9374
    9475        public:
    95             NotificationQueue(BaseObject* creator);
     76            NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
    9677            virtual ~NotificationQueue();
    9778
    98             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML.
     79            /**
     80            @brief Destroys the NotificationQueue.
     81                   Used in lua.
     82            */
     83            void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export
    9984
    10085            virtual void tick(float dt); //!< To update from time to time.
    10186
    102             void update(void); //!< Updates the queue.
    103             void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.
     87            void update(void); //!< Updates the NotificationQueue.
     88            void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification.
    10489
     90            // tolua_begin
     91            /**
     92            @brief Get the name of the NotificationQueue.
     93            @return Returns the name.
     94            */
     95            inline const std::string& getName() const
     96                { return this->name_; }
     97
     98            void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
    10599            /**
    106100            @brief Returns the maximum number of Notifications displayed.
    107101            @return Returns maximum size.
    108102            */
    109             inline int getMaxSize() const
     103            inline unsigned int getMaxSize() const
    110104                { 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_; }
     105
     106            void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
    123107            /**
    124108            @brief Returns the time interval the Notification is displayed.
    125109            @return Returns the display time.
    126110            */
    127             inline int getDisplayTime() const
     111            inline float getDisplayTime() const
    128112                { 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_; }
     113            // tolua_end
    147114
    148115            /**
    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.
     116            @brief Returns the current number of Notifications displayed.
     117            @return Returns the size of the NotificationQueue.
    151118            */
    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.
     119            inline unsigned int getSize() const
     120                { return this->size_; }
    155121
    156122            /**
    157             @brief Sets the position of the NotificationQueue.
    158             @param pos The position.
     123            @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue.
     124            @return Returns a set of strings holding the different targets.
    159125            */
    160             inline void setPosition(Vector2 pos)
    161                 { this->position_ = pos; this->positionChanged(); }
     126            inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet()
     127                { return this->targets_; }
    162128
    163             void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
     129            // tolua_begin
     130            void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
     131            const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets.
     132            // tolua_end
    164133
    165134        private:
    166             static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
    167             static const int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed.
    168             static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
    169             static const float DEFAULT_FONT_SIZE; //!< The default font size.
     135            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
     136            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
    170137
    171             static const std::string DEFAULT_FONT; //!< The default font.
    172             static const Vector2 DEFAULT_POSITION; //!< the default position.
     138            std::string name_; //!< The name of the NotificationQueue.
    173139
    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.
    179 
    180             std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
    181 
    182             float fontSize_; //!< The font size.
    183             std::string font_; //!< The font.
    184 
    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.
    187 
    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.
     140            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
     141            unsigned int size_; //!< The number of Notifications displayed.
     142            unsigned int displayTime_; //!< The time a Notification is displayed.
    190143
    191144            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
    192145
    193             void initialize(void); //!< Initializes the object.
    194             void setDefaults(void); //!< Helper method to set the default values.
     146            std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the NotificationQueue displays Notifications of.
    195147
    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.
     148            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered.
     149            std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue.
    199150
    200             bool setTargets(const std::string & targets); //!< Set the targets of this queue.
     151            float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick.
     152            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
    201153
    202             bool setFontSize(float size); //!< Set the font size.
    203             bool setFont(const std::string & font); //!< Set the font.
     154            void create(void); //!< Creates the NotificationQueue in lua.
    204155
    205             void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
     156            void setName(const std::string& name); //!< Sets the name of the NotificationQueue.
    206157
    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.
     158            void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue.
     159            void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue.
     160            void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input NotificationContainer.
    209161
    210             void clear(void); //!< Clear the queue.
     162            void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers.
    211163
    212     };
     164    }; // tolua_export
    213165
    214 }
     166} // tolua_export
    215167
    216168#endif /* _NotificationOverlay_H__ */
Note: See TracChangeset for help on using the changeset viewer.