Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Sep 3, 2010, 3:55:32 PM (14 years ago)
Author:
dafrick
Message:

Changing from OrxonoxOverlays to CEGUI as means of displaying Notifications.
Still messy and not working completely but it's a start.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • code/branches/notifications/src/modules/notifications/NotificationQueue.h

    r7164 r7338  
    4141#include <set>
    4242#include <string>
     43#include <vector>
    4344
    4445#include "util/Math.h"
     46#include "core/OrxonoxClass.h"
    4547#include "tools/interfaces/Tickable.h"
    46 #include "overlays/OverlayGroup.h"
    4748#include "interfaces/NotificationListener.h"
     49#include "NotificationManager.h"
    4850
    4951namespace orxonox
     
    5153
    5254    //! Container to allow easy handling.
    53     struct NotificationOverlayContainer
     55    struct NotificationContainer
    5456    {
    55         NotificationOverlay* overlay; //!< Pointer to the NotificationOverlay, everything is about.
    5657        Notification* notification; //!< The Notification displayed by the overlay.
    5758        time_t time; //!< The time the Notification was sent and thus first displayed.
    58         std::string name; //!< The name of the overlay.
    5959    };
    6060
    6161    //! Struct to allow ordering of NotificationOverlayContainers.
    62     struct NotificationOverlayContainerCompare {
    63         bool operator() (const NotificationOverlayContainer* const & a, const NotificationOverlayContainer* const & b) const
     62    struct NotificationContainerCompare {
     63        bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
    6464            { return a->time < b->time; } //!< Ordered by time.
    6565    };
     
    6868    @brief
    6969        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 <Level></Level> tags or bad things will happen.
    74         <NotificationQueue
    75             name = "SuperQueue" //Name of your OverlayQueue.
    76             maxSize = "5" //The maximum number of Notifications displayed. (Default is 5)
    77             notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 64)
    78             displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30)
    79             targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.)
    80             font = "VeraMono" //The font (Default is VeraMono)
    81             fontSize = '0.4' //The font size. (Default is 0.025)
    82             position = "0.0, 0.0" //The position of the NotificationQueue. (Default is 0.0,0.0)
    83         />
    8470    @author
    8571        Damian 'Mozork' Frick
    8672    */
    8773
    88     class _NotificationsExport NotificationQueue : public OverlayGroup, public Tickable, public NotificationListener
     74    class _NotificationsExport NotificationQueue : public Tickable, public NotificationListener
    8975    {
    9076
    9177        public:
    92             NotificationQueue(BaseObject* creator);
     78            NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, const Vector2& position = NotificationQueue::DEFAULT_POSITION, unsigned int length = NotificationQueue::DEFAULT_LENGTH, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
    9379            virtual ~NotificationQueue();
    94 
    95             virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML.
    9680
    9781            virtual void tick(float dt); //!< To update from time to time.
     
    10185
    10286            /**
     87            @brief Get the name of the NotificationQueue.
     88            @return Returns the name.
     89            */
     90            inline const std::string& getName() const
     91                { return this->name_; }
     92
     93            /**
    10394            @brief Returns the maximum number of Notifications displayed.
    10495            @return Returns maximum size.
    10596            */
    106             inline int getMaxSize() const
     97            inline unsigned int getMaxSize() const
    10798                { return this->maxSize_; }
    10899            /**
     
    110101            @return Returns the size of the queue.
    111102            */
    112             inline int getSize() const
     103            inline unsigned int getSize() const
    113104                { return this->size_; }
    114105            /**
     
    116107            @return Returns the maximum Notification length.
    117108            */
    118             inline int getNotificationLength() const
     109            inline unsigned int getNotificationLength() const
    119110                { return this->notificationLength_; }
    120111            /**
     
    122113            @return Returns the display time.
    123114            */
    124             inline int getDisplayTime() const
     115            inline float getDisplayTime() const
    125116                { return this->displayTime_; }
    126117            /**
     
    158149                { this->position_ = pos; this->positionChanged(); }
    159150
    160             void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
    161 
    162151        private:
    163             static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
    164             static const int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed.
    165             static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
     152            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
     153            static const unsigned int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed.
     154            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
    166155            static const float DEFAULT_FONT_SIZE; //!< The default font size.
    167156
     
    169158            static const Vector2 DEFAULT_POSITION; //!< the default position.
    170159
    171             int maxSize_; //!< The maximal number of Notifications displayed.
    172             int size_; //!< The number of Notifications displayed.
    173             int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have.
    174             int displayTime_; //!< The time a Notification is displayed.
     160            std::string name_; //!< The name of the NotificationQueue.
     161
     162            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
     163            unsigned int size_; //!< The number of Notifications displayed.
     164            unsigned int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have.
     165            unsigned int displayTime_; //!< The time a Notification is displayed.
    175166            Vector2 position_; //!< The position of the NotificationQueue.
    176167
     
    180171            std::string font_; //!< The font.
    181172
    182             std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare> containers_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps.
    183             std::map<Notification*, NotificationOverlayContainer*> overlays_; //!< Mapping notifications to their corresponding overlay containers, for easier association and finding.
     173            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. //TODO: Would set work as well?
     174            std::vector<NotificationContainer*> notifications_;
    184175
    185176            float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick.
    186             NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
     177            NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
    187178
    188179            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
    189180
    190181            void initialize(void); //!< Initializes the object.
    191             void setDefaults(void); //!< Helper method to set the default values.
    192 
    193             bool setMaxSize(int size); //!< Sets the maximum number of displayed Notifications.
    194             bool setNotificationLength(int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
    195             bool setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed.
     182            void create(void);
     183
     184            bool setName(const std::string& name); //!< Sets the name of the NotificationQueue.
     185
     186            void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
     187            void setNotificationLength(unsigned int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
     188            void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
    196189
    197190            bool setTargets(const std::string & targets); //!< Set the targets of this queue.
     
    202195            void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
    203196
    204             void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
    205             bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue.
     197            void push(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
     198            void pop(void);
     199            void remove(NotificationContainer* container);
    206200
    207201            void clear(void); //!< Clear the queue.
Note: See TracChangeset for help on using the changeset viewer.