Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 2779


Ignore:
Timestamp:
Mar 12, 2009, 5:13:34 PM (15 years ago)
Author:
dafrick
Message:

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

Location:
code/branches/questsystem5/src/orxonox
Files:
4 added
45 edited

Legend:

Unmodified
Added
Removed
  • code/branches/questsystem5/src/orxonox/OrxonoxPrereqs.h

    r2710 r2779  
    129129    class QuestListener;
    130130    class QuestManager;
     131    class QuestNotification;
    131132    class Rewardable;
    132133
     
    227228    class Notification;
    228229    class NotificationManager;
     230    class NotificationOverlay;
    229231    class NotificationQueue;
    230232    class OrxonoxOverlay;
  • code/branches/questsystem5/src/orxonox/objects/quest/AddQuest.cc

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file AddQuest.cc
    3131    @brief Implementation of the AddQuest class.
    3232*/
     
    4242#include "orxonox/objects/infos/PlayerInfo.h"
    4343#include "QuestManager.h"
     44#include "QuestDescription.h";
    4445#include "Quest.h"
    4546
  • code/branches/questsystem5/src/orxonox/objects/quest/AddQuest.h

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file AddQuest.h
    3131    @brief Definition of the AddQuest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/AddQuestHint.cc

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file AddQuestHint.cc
    3131    @brief Implementation of the AddQuestHint class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/AddQuestHint.h

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file AddQuestHint.h
    3131    @brief Definition of the AddQuestHint class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/AddReward.cc

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file AddReward.cc
    3131    @brief Implementation of the AddReward class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/AddReward.h

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file AddReward.h
    3131    @brief Definition of the AddReward class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/CMakeLists.txt

    r2710 r2779  
    1616  QuestListener.cc
    1717  QuestManager.cc
     18  QuestNotification.cc
    1819  Rewardable.cc
    1920)
  • code/branches/questsystem5/src/orxonox/objects/quest/ChangeQuestStatus.cc

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file ChangeQuestStatus.cc
    3131    @brief Implementation of the ChangeQuestStatus class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/ChangeQuestStatus.h

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file ChangeQuestStatus.h
    3131    @brief Definition of the ChangeQuestStatus class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/CompleteQuest.cc

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file CompleteQuest.cc
    3131    @brief Implementation of the CompleteQuest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/CompleteQuest.h

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file CompleteQuest.h
    3131    @brief Definition of the CompleteQuest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/FailQuest.cc

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file FailQuest.cc
    3131    @brief Implementation of the FailQuest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/FailQuest.h

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file FailQuest.h
    3131    @brief Definition of the FailQuest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/GlobalQuest.cc

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file GlobalQuest.cc
    3131    @brief Implementation of the GlobalQuest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/GlobalQuest.h

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file GlobalQuest.h
    3131    @brief Definition of the GlobalQuest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/LocalQuest.cc

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file LocalQuest.cc
    3131    @brief Implementation of the LocalQuest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/LocalQuest.h

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file LocalQuest.h
    3131    @brief Definition of the LocalQuest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/Quest.cc

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file Quest.cc
    3131    @brief Implementation of the Quest class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/Quest.h

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file Quest.h
    3131    @brief Definition of the Quest class.
    3232        The Quest is the parent class of LocalQuest and GlobalQuest.
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestDescription.cc

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file QuestDescription.cc
    3131    @brief Implementation of the QuestDescription class.
    3232*/
     
    3737
    3838#include "core/CoreIncludes.h"
    39 #include "orxonox/overlays/notifications/Notification.h"
     39#include "QuestNotification.h"
    4040
    4141namespace orxonox
     
    8989    @return
    9090        Returns true if successful.
     91    @todo
     92        Make sure the messages meet the conditions.
    9193    */
    9294    bool QuestDescription::notificationHelper(const std::string & item, const std::string & status) const
    9395    {
    9496        std::string message = "";
    95         std::string title = "";
    9697        if(item == "hint")
    9798        {
    98             title = "You received a hint: '" + this->title_ + "'";
    99             message = this->description_;
     99            message = "You received a hint: '" + this->title_ + "'";
    100100        }
    101101        else if(item == "quest")
     
    103103            if(status == "start")
    104104            {
    105                 title = "You received a new quest: '" + this->title_ + "'";
    106                 message = this->description_;
     105                message = "You received a new quest: '" + this->title_ + "'";
    107106            }
    108107            else if(status == "fail")
    109108            {
    110                 title = "You failed the quest: '" + this->title_ + "'";
    111                 message = this->failMessage_;
     109                message = "You failed the quest: '" + this->title_ + "'";
    112110            }
    113111            else if(status == "complete")
    114112            {
    115                 title = "You successfully completed the quest: '" + this->title_ + "'";
    116                 message = this->completeMessage_;
     113                message = "You successfully completed the quest: '" + this->title_ + "'";
    117114            }
    118115            else
     
    128125        }
    129126       
    130         Notification* notification = new Notification(0, message, title, 30);
     127        QuestNotification* notification = new QuestNotification(message);
    131128        notification->send();
    132129        return true;
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestDescription.h

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file QuestDescription.h
    3131    @brief Definition of the QuestDescription class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestEffect.cc

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file QuestEffect.cc
    3131    @brief Implementation of the QuestEffect class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestEffect.h

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file QuestEffect.h
    3131    @brief Definition of the QuestEffect class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestEffectBeacon.cc

    r2662 r2779  
    2828
    2929/**
    30     @file
     30    @file QuestEffectBeacon.cc
    3131    @brief Implementation of the QuestEffectBeacon class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestEffectBeacon.h

    r2662 r2779  
    2828
    2929/**
    30     @file
     30    @file QuestEffectBeacon.h
    3131    @brief Definition of the QuestEffectBeacon class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestHint.cc

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file QuestHint.cc
    3131    @brief Implementation of the QuestHint class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestHint.h

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file QuestHint.h
    3131    @brief Definition of the QuestHint class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestItem.cc

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file QuestItem.cc
    3131    @brief Implementation of the QuestItem class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestItem.h

    r2710 r2779  
    2828 
    2929/**
    30     @file
     30    @file QuestItem.h
    3131    @brief Definition of the QuestItem class.
    3232        The QuestItem is the parent class of Quest and QuestHint.
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestListener.cc

    r2662 r2779  
    2828
    2929/**
    30     @file
     30    @file QuestListener.cc
    3131    @brief Implementation of the QuestListener class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestListener.h

    r2662 r2779  
    2828
    2929/**
    30     @file
     30    @file QuestListener.h
    3131    @brief Definition of the QuestListener class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestManager.cc

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file QuestManager.cc
    3131    @brief Implementation of the QuestManager class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/QuestManager.h

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file QuestManager.h
    3131    @brief Definition of the QuestManager class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/Rewardable.cc

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file Rewardable.cc
    3131    @brief Implementation of the Rewardable class.
    3232*/
  • code/branches/questsystem5/src/orxonox/objects/quest/Rewardable.h

    r2710 r2779  
    2828
    2929/**
    30     @file
     30    @file Rewardable.h
    3131    @brief Definition of the Rewardable class.
    3232*/
  • code/branches/questsystem5/src/orxonox/overlays/OverlayGroup.cc

    r2662 r2779  
    107107    void OverlayGroup::addElement(OrxonoxOverlay* element)
    108108    {
    109         if (hudElements_.find(element->getName()) != hudElements_.end())
     109        this->insertElement(element, element->getName());
     110    }
     111
     112        /**
     113    @brief
     114        Adds an element to the map.
     115    @param element
     116        The element to be added.
     117    @param name
     118        The name of the element.
     119    @remarks
     120        The names of the OrxonoxOverlays have to be unique!
     121    */
     122    void OverlayGroup::insertElement(OrxonoxOverlay* element, const std::string & name)
     123    {
     124        element->setName(name);
     125        if (hudElements_.find(name) != hudElements_.end())
    110126        {
    111127            COUT(1) << "Ambiguous names encountered while load the HUD overlays" << std::endl;
     
    113129        else
    114130        {
    115             hudElements_[element->getName()] = element;
     131            hudElements_[name] = element;
    116132            element->setVisible(this->isVisible());
    117             if (this->owner_)
     133                        if (this->owner_)
    118134                element->setOwner(this->owner_);
    119135        }
     136    }
     137
     138        /**
     139    @brief
     140        Removes an element from the map.
     141    @param name
     142        The name of the element that is removed.
     143    @return
     144        Returns true if there was such an element to remove, false if not.
     145    */
     146    bool OverlayGroup::removeElement(const std::string & name)
     147    {
     148        if(this->hudElements_.erase(name) == 0)
     149            return false;
     150        return true;
    120151    }
    121152
  • code/branches/questsystem5/src/orxonox/overlays/OverlayGroup.h

    r2662 r2779  
    8686
    8787        void addElement(OrxonoxOverlay* element);
     88                void insertElement(OrxonoxOverlay* element, const std::string & name);
     89        bool removeElement(const std::string & name);
    8890        OrxonoxOverlay* getElement(unsigned int index);
    8991
  • code/branches/questsystem5/src/orxonox/overlays/notifications/CMakeLists.txt

    r2710 r2779  
    22  Notification.cc
    33  NotificationManager.cc
     4  NotificationOverlay.cc
    45  NotificationQueue.cc
    56)
  • code/branches/questsystem5/src/orxonox/overlays/notifications/Notification.cc

    r2662 r2779  
    2727 */
    2828
     29/**
     30    @file Notification.cc
     31    @brief Implementation of the Notification class.
     32*/
     33
    2934#include "OrxonoxStableHeaders.h"
    3035#include "Notification.h"
    3136
    3237#include "core/CoreIncludes.h"
     38#include "util/Exception.h"
    3339
    3440#include "NotificationManager.h"
     
    3642namespace orxonox
    3743{
     44
     45    /**
     46    @brief
     47        Default constructor. Initializes the object.
     48    */
    3849    Notification::Notification(BaseObject* creator) : BaseObject(creator)
    3950    {
    40         RegisterObject(Notification);
     51        this->initialize();
    4152    }
    4253   
    43     Notification::Notification(BaseObject* creator, const std::string & message, const std::string & title, float time) : BaseObject(creator)
     54    /**
     55    @brief
     56        Constructor. Creates a Notification with the input message.
     57    @param message
     58        The message of the Notification.
     59    */
     60    Notification::Notification(const std::string & message) : BaseObject(this)
    4461    {
    45         this->title_ = title;
    4662        this->message_ = message;
    47         if(time > 0)
    48             this->displayTime_ = time;
    4963    }
    5064   
     65    /**
     66    @brief
     67        Destructor.
     68    */
    5169    Notification::~Notification()
    5270    {
    5371    }
    5472   
     73    /**
     74    @brief
     75        Registers the object and sets some default values.
     76    */
    5577    void Notification::initialize(void)
    5678    {
    5779        RegisterObject(Notification);
    5880       
    59         this->title_ = "";
    6081        this->message_ = "";
    61         this->displayTime_ = NOTIFICATION_DISPLAY_TIME;
     82        this->sender_ = NotificationManager::NONE;
    6283        this->sent_ = false;
    6384    }
    6485   
     86    /**
     87    @brief
     88        Sends the Notification to the Notificationmanager, with sender NetificationManager::NONE.
     89    @return
     90        Returns true if successful.
     91    */
    6592    bool Notification::send(void)
    6693    {
    67         bool successful = NotificationManager::insertNotification(this);
    68         if(successful)
    69             this->sent_ = true;
    70         return successful;
     94        return this->send(NotificationManager::NONE);
    7195    }
    7296   
    73     bool Notification::setTitle(const std::string & title)
     97    /**
     98    @brief
     99        Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
     100    @param sender
     101        The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
     102    @return
     103        Returns true if successful.
     104    */
     105    bool Notification::send(const std::string & sender)
    74106    {
    75         if(this->isSent())
     107        this->sender_ = sender;
     108        bool successful = NotificationManager::registerNotification(this);
     109        if(!successful)
    76110            return false;
    77         this->title_ = title;
     111        this->sent_ = true;
     112       
     113        COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
     114       
    78115        return true;
    79116    }
    80117   
     118    /**
     119    @brief
     120        Sets the message of the notification.
     121    @param message
     122        The message to be set.
     123    @return
     124        Returns true if successful.
     125    */
    81126    bool Notification::setMessage(const std::string & message)
    82127    {
    83         if(this->isSent())
     128        if(this->isSent()) //!< The message cannot be changed if the message has already been sent.
    84129            return false;
    85130        this->message_ = message;
    86131        return true;
    87132    }
    88    
    89     bool Notification::setDisplayTime(float time)
    90     {
    91         if(this->isSent())
    92         {
    93             return false;
    94         }
    95         if(time > 0)
    96         {
    97             this->displayTime_ = time;
    98             return true;
    99         }
    100         return false;
    101     }
     133
    102134}
  • code/branches/questsystem5/src/orxonox/overlays/notifications/Notification.h

    r2662 r2779  
    2727 */
    2828
     29/**
     30    @file Notification.h
     31    @brief Definition of the Notification class.
     32*/
     33
    2934#ifndef _Notification_H__
    3035#define _Notification_H__
     
    3843namespace orxonox
    3944{
    40     static const float NOTIFICATION_DISPLAY_TIME = 4.0;
    4145
    4246    /**
    4347    @brief
    44         This is rather temporary, so don't start relying on it, some better version will come soon but the Interface will not likely be the same.
     48        A Notification is a short message used to inform the player about something that just happened. A Notification can be sent from any part of orxonox and is then displayed in the proper NotificationQueue (depending on which senders the specific NotificationQueue accepts).
    4549    @author
    4650        Damian 'Mozork' Frick
     
    4852    class _OrxonoxExport Notification : public BaseObject
    4953    {
    50     public:
    51         Notification(BaseObject* creator);
    52         Notification(BaseObject* creator, const std::string & message, const std::string & title = "", float time = NOTIFICATION_DISPLAY_TIME);
    53         virtual ~Notification();
    54        
    55         bool send(void);
    56        
    57         inline bool isSent(void) const
    58             { return this->sent_; }
    59         inline const std::string & getTitle(void) const
    60             { return this->title_; }
    61         inline const std::string & getMessage(void) const
    62             { return this->message_; }
    63         inline const float getDisplayTime(void) const
    64             { return displayTime_; }
    65        
    66         bool setTitle(const std::string & title);
    67         bool setMessage(const std::string & message);
    68         bool setDisplayTime(float time);
    69        
    70     private:
    71         std::string title_; //!< The title of the Notification.
    72         std::string message_; //!< The Notification message.
    73         float displayTime_; //!< The time duration the Notification is displayed in seconds.
    74         bool sent_; //!< Whether Notification has been sent, if so it cannot be changed.
    75        
    76         void initialize(void);
     54        public:
     55            Notification(BaseObject* creator);
     56            Notification(const std::string & message);
     57            virtual ~Notification();
     58           
     59            bool send(void); //!< Sends the Notification to the Notificationmanager, with sender NotificationManager::NONE;
     60            bool send(const std::string & sender); //!< Sends the Notification to the Notificationmanager.
     61           
     62            /**
     63            @brief Checks whether the Notification was sent.
     64            @return Returns true if the Notification was sent already.
     65            */
     66            inline bool isSent(void) const
     67                { return this->sent_; }
     68            /**
     69            @brief Returns the message of the Notification.
     70            @return Returns the message of the Notification.
     71            */
     72            inline const std::string & getMessage(void) const
     73                { return this->message_; }
     74               
     75            inline const std::string & getSender(void) const
     76                { return this->sender_; }
     77           
     78            bool setMessage(const std::string & message); //!< Sets the message of the notification.
     79           
     80        private:
     81            std::string message_; //!< The Notification message.
     82            std::string sender_; //!< The sender of the notification.
     83            bool sent_; //!< Whether Notification has been sent, if so it cannot be changed.
     84           
     85            void initialize(void);
     86       
    7787    };
     88
    7889}
    7990
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.cc

    r2662 r2779  
    2727 */
    2828
     29/**
     30    @file NotificationManager.cc
     31    @brief Implementation of the NotificationManager class.
     32*/
     33
    2934#include "OrxonoxStableHeaders.h"
    3035#include "NotificationManager.h"
     
    3237#include "core/CoreIncludes.h"
    3338
     39#include <set>
     40
    3441#include "Notification.h"
    35 
    3642#include "NotificationQueue.h"
    3743
    3844namespace orxonox
    3945{
    40     std::list<NotificationContainer*> NotificationManager::notifications_s;
    41 
     46
     47    const std::string NotificationManager::ALL = "all";
     48    const std::string NotificationManager::NONE = "none";
     49
     50    std::multimap<std::time_t,Notification*> NotificationManager::allNotificationsList_s;
     51    std::map<int,std::multimap<std::time_t,Notification*>*> NotificationManager::notificationLists_s;
     52    std::map<NotificationQueue*,int> NotificationManager::queueList_s;
     53   
     54    int NotificationManager::highestIndex_s = 0;
     55
     56    /**
     57    @brief
     58        Constructor. Registers the Object.
     59    */
    4260    NotificationManager::NotificationManager(BaseObject* creator) : BaseObject(creator)
    4361    {
     
    4563    }
    4664
     65    /**
     66    @brief
     67        Destructor.
     68    */
    4769    NotificationManager::~NotificationManager()
    4870    {
    49         //TDO: Destroy the containers
    50     }
    51 
    52     void NotificationManager::tick(float dt)
    53     {
    54         bool update = false;
    55 
    56         for (std::list<NotificationContainer*>::iterator notification = notifications_s.begin(); notification != notifications_s.end(); ++notification)
    57         {
    58             NotificationContainer* container = *notification;
    59             if(container->remainingTime == 0)
     71    }
     72   
     73    /**
     74    @brief
     75        Registers a Notification within the NotificationManager and makes sure that the Notification is displayed in all the NotificationQueues associated with its sender.
     76    @param notification
     77        The Notification to be registered.
     78    @return
     79        Returns true if successful.
     80    */
     81    /*static*/ bool NotificationManager::registerNotification(Notification* notification)
     82    {
     83   
     84        if(notification == NULL) //!< A NULL-Notification cannot be registered.
     85            return false;
     86       
     87        std::time_t time = std::time(0); //TDO: Doesn't this expire? //!< Get current time.
     88       
     89        allNotificationsList_s.insert(std::pair<std::time_t,Notification*>(time,notification));
     90       
     91        if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications.
     92            return true;
     93       
     94        bool all = false;
     95        if(notification->getSender() == ALL) //!< If all are the sender, then the Notifications is added to every NotificationQueue.
     96            all = true;
     97       
     98        //!< Insert the notification in all queues that have its sender as target.
     99        for(std::map<NotificationQueue*,int>::iterator it = queueList_s.begin(); it != queueList_s.end(); it++)
     100        {
     101            std::set<std::string> set = it->first->getTargetsSet();
     102            if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TDO: Make sure this works.
    60103            {
    61                 continue;
     104                notificationLists_s[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue.
     105                it->first->update(notification, time); //!< Update the queue.
    62106            }
    63             else if(container->remainingTime - dt <= 0)
     107        }
     108       
     109        COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
     110       
     111        return true;
     112    }
     113   
     114    /**
     115    @brief
     116        Registers a NotificationQueue within the NotificationManager.
     117    @param queue
     118        The NotificationQueue to be registered.
     119    @return
     120        Returns true if successful.
     121    */
     122    /*static*/ bool NotificationManager::registerQueue(NotificationQueue* queue)
     123    {
     124        NotificationManager::highestIndex_s += 1;
     125        int index = NotificationManager::highestIndex_s;
     126       
     127        queueList_s[queue] = index; //!< Add the NotificationQueue to the list of queues.
     128       
     129        std::set<std::string> set = queue->getTargetsSet(); //TDO: Works this?
     130       
     131        //! If all senders are the target of the queue, then the list of notification for that specific queue is te same as the list of all Notifications.
     132        if(set.find(ALL) != set.end())
     133        {
     134            notificationLists_s[index] = &allNotificationsList_s;
     135            return true;
     136        }
     137       
     138        notificationLists_s[index] = new std::multimap<std::time_t,Notification*>;
     139        std::multimap<std::time_t,Notification*> map = *notificationLists_s[index];
     140       
     141        //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue.
     142        for(std::multimap<std::time_t,Notification*>::iterator it = allNotificationsList_s.begin(); it != allNotificationsList_s.end(); it++)
     143        {
     144            if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target.
    64145            {
    65                 container->remainingTime = 0;
    66                 update = true;
     146                map.insert(std::pair<std::time_t,Notification*>(it->first, it->second));
    67147            }
    68             else
    69             {
    70                 container->remainingTime = container->remainingTime -dt;
    71             }
    72         }
    73 
    74         if(update)
    75             updateQueue();
    76     }
    77 
    78     bool NotificationManager::insertNotification(Notification* notification)
    79     {
    80         if(notification == NULL)
    81             return false;
    82 
    83         NotificationContainer* container = new NotificationContainer;
    84         container->notification = notification;
    85         container->remainingTime = notification->getDisplayTime();
    86         notifications_s.push_front(container);
    87 
    88         updateQueue();
    89 
    90         COUT(4) << "Notification inserted. Title: " << notification->getTitle() << std::endl;
    91 
     148        }
     149       
     150        COUT(3) << "Notification registered with the NotificationManager." << std::endl;
     151       
     152        queue->update(); //!< Update the queue.
     153       
    92154        return true;
    93155    }
    94 
    95     void NotificationManager::updateQueue(void)
    96     {
    97         std::string text = "";
    98 
    99         if (!NotificationQueue::queue_s)
    100             return;
    101 
    102         int i = NotificationQueue::queue_s->getLength();
    103         for (std::list<NotificationContainer*>::iterator notification = notifications_s.begin(); notification != notifications_s.end() && i > 0; ++notification)
    104         {
    105             i--;
    106             NotificationContainer* container = *notification;
    107             if(container->remainingTime == 0.0)
    108                 continue;
    109 
    110             text = text + "\n\n\n------------\n\n" + clipMessage(container->notification->getTitle()) + "\n\n" + clipMessage(container->notification->getMessage());
    111         }
    112 
    113         NotificationQueue::queue_s->setQueueText(text);
    114     }
    115 
    116     const std::string NotificationManager::clipMessage(const std::string & str)
    117     {
    118 
    119         std::string message = str;
    120         unsigned int i = 0;
    121 
    122         unsigned int found = message.find("\\n", i);
    123         while(found != std::string::npos)
    124         {
    125             message.replace(found, 2, "\n");
    126             i = found+2;
    127             found = message.find("\\n", i);
    128         }
    129 
    130         std::string clippedMessage = "";
    131         int wordLength = 0;
    132         i = 0;
    133         int widthLeft = NotificationQueue::queue_s->getWidth();
    134         while(i < message.length())
    135         {
    136             while(i < message.length() && message[i] != ' ' && message[i] != '\n')
    137             {
    138                 i++;
    139                 wordLength++;
    140             }
    141 
    142             if(wordLength <= widthLeft)
    143             {
    144                 clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);
    145                 if(i < message.length())
    146                 {
    147                     clippedMessage = clippedMessage + message.substr(i,1);
    148                 }
    149                 widthLeft -= (wordLength+1);
    150                 if(message[i] == '\n')
    151                 {
    152                     widthLeft = NotificationQueue::queue_s->getWidth() - (wordLength+1);
    153                 }
    154                 wordLength = 0;
    155                 i++;
    156             }
    157             else
    158             {
    159                 clippedMessage.push_back('\n');
    160                 clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);
    161                 if(i < message.length())
    162                 {
    163                     clippedMessage = clippedMessage + message.substr(i,1);
    164                 }
    165                 widthLeft = NotificationQueue::queue_s->getWidth() - (wordLength+1);
    166                 i++;
    167                 wordLength = 0;
    168             }
    169         }
    170 
    171         return clippedMessage;
     156   
     157    /**
     158    @brief
     159        Fetches the Notifications for a specific NotificationQueue in a specified timeframe.
     160    @param queue
     161        The NotificationQueue the Notifications are fetched for.
     162    @param timeFrameStart
     163        The start time of the timeframe.
     164    @param timeFrameEnd
     165        The end time of the timeframe.
     166    @return
     167        Returns a time-ordered list of Notifications.
     168    @todo
     169        Make sure the map is deleted.
     170    */
     171    /*static*/ std::multimap<std::time_t,Notification*>* NotificationManager::getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
     172    {
     173        COUT(1) << "Queue: " << queue << ", timeFrameStart: " << timeFrameStart << ", timeFrameEnd: " << timeFrameEnd << std::endl;
     174   
     175        std::multimap<std::time_t,Notification*>* notifications = NotificationManager::notificationLists_s[NotificationManager::queueList_s[queue]];
     176       
     177        if(notifications == NULL)
     178            return NULL;
     179   
     180        std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
     181        itLowest = notifications->lower_bound(timeFrameStart);
     182        itHighest = notifications->upper_bound(timeFrameStart);
     183       
     184        std::multimap<std::time_t,Notification*>* map = new std::multimap<std::time_t,Notification*>();
     185       
     186        for(it = itLowest; it != itHighest; it++)
     187        {
     188            map->insert(std::pair<std::time_t,Notification*>(it->first,it->second));
     189        }
     190       
     191        if(map->size() == 0)
     192        {
     193            delete map;
     194            return NULL;
     195        }
     196       
     197        return map;
    172198    }
    173199
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationManager.h

    r2662 r2779  
    2727 */
    2828
     29/**
     30    @file NotificationManager.h
     31    @brief Definition of the NotificationManager class.
     32*/
     33
    2934#ifndef _NotificationManager_H__
    3035#define _NotificationManager_H__
     
    3439#include "core/BaseObject.h"
    3540
    36 #include <list>
     41#include <map>
    3742#include <string>
     43#include <ctime>
     44
     45#include "NotificationOverlay.h"
    3846
    3947namespace orxonox
    4048{
    41     struct NotificationContainer
    42     {
    43         Notification* notification;
    44         float remainingTime;
    45     };
    4649
    4750    /**
    4851    @brief
    49        
     52        The NotificationManager functions as a gateway between Notifications and NotificationQueues.
     53        It receives, organizes Notifications and the redistributes them to the specific NotificationQueues.
    5054    @author
    5155        Damian 'Mozork' Frick
     
    5357    class _OrxonoxExport NotificationManager : public BaseObject
    5458    {
    55    
    56     public:
    57         NotificationManager(BaseObject* creator);
    58         virtual ~NotificationManager();
     59        public:
     60            NotificationManager(BaseObject* creator);
     61            virtual ~NotificationManager();
     62               
     63            static const std::string ALL;
     64            static const std::string NONE;
     65         
     66            //TDO: Visibility?
     67            static bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
     68            static bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
     69           
     70            static std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
     71           
     72            /**
     73            @brief Fetches the Notifications for a specific NotificationQueue starting at a specified time.
     74            @param queue The NotificationQueue the Notifications are fetched for.
     75            @param timeFrameStart The start time the Notifications are fetched from.
     76            @return Returns a time-ordered list of Notifications.
     77            */
     78            static std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, const std::time_t & timeFrameStart)
     79                { return NotificationManager::getNotifications(queue, timeFrameStart, std::time(0)); }
     80            /**
     81            @brief Fetches the Notifications for a specific NotificationQueue starting at a specified timespan before now.
     82            @param queue The NotificationQueue the Notifications are fetched for.
     83            @param timeDelay The timespan.
     84            @return Returns a time-ordered list of Notifications.
     85            */
     86            static std::multimap<std::time_t,Notification*>* getNotifications(NotificationQueue* queue, int timeDelay)
     87                { return NotificationManager::getNotifications(queue, std::time(0)-timeDelay, std::time(0)); }
     88     
     89               private:
     90            static int highestIndex_s; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that  no key appears twice.
    5991       
    60         static bool insertNotification(Notification* notification);
    61        
    62         static void tick(float dt);
    63        
    64     private:
    65         static std::list<NotificationContainer*> notifications_s;
    66        
    67         static void updateQueue(void);
    68         static const std::string clipMessage(const std::string & message);
     92            static std::multimap<std::time_t,Notification*> allNotificationsList_s; //!< Container where all notifications are stored (together with their respecive timestamps).
     93            static std::map<NotificationQueue*,int> queueList_s; //!< Container where all NotificationQueues are stored with a number as identifier.
     94            static std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_s; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
     95           
    6996
    7097    };
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.cc

    r2662 r2779  
    3030#include "NotificationQueue.h"
    3131
     32#include <OgreOverlayManager.h>
     33#include <OgreTextAreaOverlayElement.h>
     34#include <list>
     35
    3236#include "core/CoreIncludes.h"
    3337#include "core/XMLPort.h"
    3438
    35 #include "NotificationManager.h"
     39#include "Notification.h"
     40#include "NotificationOverlay.h"
    3641
    3742namespace orxonox
    3843{
    39     NotificationQueue* NotificationQueue::queue_s = 0;
    40 
     44   
    4145    CreateFactory(NotificationQueue);
    42 
    43     NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayText(creator)
     46   
     47    const std::string NotificationQueue::DEFAULT_FONT = "VeraMono";
     48
     49    /**
     50    @brief
     51        Constructor. Creates and initializes the object.
     52    */
     53    NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator)
     54    {
     55        this->initialize();
     56    }
     57   
     58    /**
     59    @brief
     60        Destructor.
     61    @todo
     62        I'm pretty sure that there are some thing that have to be distroyed.
     63    */
     64    NotificationQueue::~NotificationQueue()
     65    {
     66       
     67    }
     68   
     69    /**
     70    @brief
     71        Initializes the object.
     72        Registers the object, initializes variables, sets default values and registers the queue with the NotificationManager.
     73    */
     74    void NotificationQueue::initialize(void)
    4475    {
    4576        RegisterObject(NotificationQueue);
    46         //TDO: Does this work?
    47         if(queue_s != NULL)
    48         {
    49                 COUT(2) << "There is now more than one NotificationQueue, this shouldn't happen, since only the first NotificationQueue will be targeted by the NotificationManager." << std::endl;
    50         }
    51         else
    52         {
    53                 queue_s = this;
    54         }
    55 
    56         this->length_ = 3;
    57         this->width_ = 50;
    58     }
    59 
    60     NotificationQueue::~NotificationQueue()
    61     {
    62 
    63     }
    64 
     77       
     78        this->setDefaults();
     79        this->size_ = 0;
     80        this->tickTime_ = 0.0;
     81       
     82        NotificationManager::registerQueue(this);
     83    }
     84   
     85    /**
     86    @brief
     87        Sets the defaults.
     88    */
     89    void NotificationQueue::setDefaults(void)
     90    {
     91        this->setMaxSize(DEFAULT_SIZE);
     92        this->setNotificationLength(DEFAULT_LENGTH);
     93        this->setDisplayTime(DEFAULT_DISPLAY_TIME);
     94       
     95        this->setTargets(NotificationManager::ALL);
     96       
     97        this->setFontSize(DEFAULT_FONT_SIZE);
     98        this->setFont(DEFAULT_FONT);
     99    }
     100   
     101    /**
     102    @brief
     103        Method for creating a NotificationQueue object through XML.
     104    */
    65105    void NotificationQueue::XMLPort(Element& xmlElement, XMLPort::Mode mode)
    66106    {
    67107        SUPER(NotificationQueue, XMLPort, xmlElement, mode);
    68 
    69         XMLPortParam(NotificationQueue, "length", setLength, getLength, xmlElement, mode);
    70         XMLPortParam(NotificationQueue, "width", setWidth, getWidth, xmlElement, mode);
    71     }
    72 
     108       
     109        XMLPortParam(NotificationQueue, "maxSize", setMaxSize, getMaxSize, xmlElement, mode);
     110        XMLPortParam(NotificationQueue, "notificationLength", setNotificationLength, getNotificationLength, xmlElement, mode);
     111        XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlElement, mode);
     112        XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlElement, mode);
     113        XMLPortParam(NotificationQueue, "font", setFont, getFont, xmlElement, mode);
     114        XMLPortParam(NotificationQueue, "fontSize", setFontSize, getFontSize, xmlElement, mode);
     115       
     116        COUT(3) << "NotificationQueue created." << std::endl;
     117    }
     118   
     119    /**
     120    @brief
     121        Updates the queue from time to time.
     122    @param dt
     123        The time interval that has passed since the last tick.
     124    */
    73125    void NotificationQueue::tick(float dt)
    74126    {
    75         NotificationManager::tick(dt);
    76 
    77         update();
    78     }
    79 
    80     bool NotificationQueue::setLength(int length)
    81     {
    82         if(length > 0)
    83         {
    84             this->length_ = length;
    85             return true;
    86         }
    87         return false;
    88     }
    89 
    90     bool NotificationQueue::setWidth(int width)
    91     {
    92         if(width > 0)
    93         {
    94             this->width_ = width;
    95             return true;
    96         }
    97         return false;
    98     }
    99 
    100     void NotificationQueue::setQueueText(const std::string & text)
    101     {
    102         this->queueText_ = text;
    103     }
    104 
     127        this->tickTime_ += dt; //!< Add the time interval that has passed to the time counter.
     128        if(this->tickTime_ >= 1.0) //!< If the time counter is greater than 1s all Notifications that have expired are removed, if it is smaller we wait to the next tick.
     129        {
     130            this->timeLimit_.time = std::time(0)-this->displayTime_; //!< Container containig the current time.
     131           
     132            std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
     133            it = this->containers_.begin();
     134            while(it != this->containers_.upper_bound(&this->timeLimit_)) //!< Iterate through all elements whose creation time is smaller than the current time minus the display time.
     135            {
     136                this->removeContainer(*it);
     137                it = this->containers_.begin(); //TDO: Needed?
     138            }
     139           
     140            this->tickTime_ = 0.0; //!< Reset time counter.
     141        }
     142    }
     143   
     144    /**
     145    @brief
     146        Updates the NotificationQueue.
     147        Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting the in the queue.
     148    */
    105149    void NotificationQueue::update(void)
    106150    {
    107         this->text_->setCaption(queueText_);
    108     }
     151        this->clear();
     152   
     153        std::multimap<std::time_t,Notification*>* notifications = NotificationManager::getNotifications(this, this->displayTime_);
     154       
     155        if(notifications == NULL)
     156            return;
     157       
     158        for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++)
     159        {
     160            this->addNotification(it->second, it->first);
     161        }
     162       
     163        COUT(3) << "NotificationQueue updated." << std::endl;
     164    }
     165   
     166    /**
     167    @brief
     168        Updates the NotificationQueue by adding an new Notification.
     169    @param notification
     170        Pointer to the Notification.
     171    @param time
     172        The time the Notification was sent.
     173    */
     174    void NotificationQueue::update(Notification* notification, const std::time_t & time)
     175    {
     176        this->addNotification(notification, time);
     177       
     178        //TDO: Position!
     179       
     180        std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
     181        while(this->getSize() > this->getMaxSize())
     182        {
     183            it = this->containers_.begin();
     184            this->removeContainer(*it);
     185        }
     186       
     187        COUT(3) << "NotificationQueue updated. A new Notifications has been added." << std::endl;
     188    }
     189   
     190    /**
     191    @brief
     192        Sets the maximum number of displayed Notifications.
     193    @param size
     194        The size to be set.
     195    @return
     196        Returns true if successful.
     197    */
     198    bool NotificationQueue::setMaxSize(int size)
     199    {
     200        if(size < 0)
     201            return false;
     202        this->maxSize_ = size;
     203        this->update();
     204        return true;
     205    }
     206   
     207    /**
     208    @brief
     209        Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
     210    @param length
     211        The length to be set.
     212    @return
     213        Returns true if successful.
     214    */
     215    bool NotificationQueue::setNotificationLength(int length)
     216    {
     217        if(length < 0)
     218            return false;
     219        this->notificationLength_ = length;
     220        this->update();
     221        return true;
     222    }
     223   
     224    /**
     225    @brief
     226        Sets the maximum number of seconds a Notification is displayed.
     227    @param time
     228        The number of seconds the Notifications is displayed.
     229    @return
     230        Returns true if successful.
     231    */
     232    bool NotificationQueue::setDisplayTime(int time)
     233    {
     234        if(time < 0)
     235            return false;
     236        this->displayTime_ = time;
     237        this->update();
     238        return true;
     239    }
     240   
     241    /**
     242    @brief
     243        Returns all targets concatinated as string, with kommas (',') as seperators.
     244    @return
     245        Returns all targets concatinated as string, with kommas (',') as seperators.
     246    @todo
     247        Where is the string deleted?
     248    */
     249    const std::string & NotificationQueue::getTargets() const
     250    {
     251        std::string* pTemp = new std::string("");
     252        bool first = true;
     253        for(std::set<std::string>::iterator it = this->targets_.begin(); it != this->targets_.end(); it++) //!< Iterate through the set of targets.
     254        {
     255            if(!first)
     256            {
     257                *pTemp += ",";
     258            }
     259            else
     260            {
     261                first = false;
     262            }
     263            *pTemp += *it;
     264        }
     265       
     266        return *pTemp;
     267    }
     268   
     269    /**
     270    @brief
     271        Sets the targets of the queue.
     272        The targets are the senders whose Notifications are displayed in this queue.
     273    @param targets
     274        Accepts a string of targets, each seperated by commas (','), spaces are ignored.
     275    @return
     276        Returns true if successful.
     277    */
     278    bool NotificationQueue::setTargets(const std::string & targets)
     279    {
     280        std::string* pTemp;
     281        unsigned int index = 0;
     282        while( index < targets.size() ) //!< Go through the string, character by character until the end is reached.
     283        {
     284            pTemp = new std::string("");
     285            while(targets[index] != ',' && targets[index] != ' ' && index < targets.size())
     286            {
     287                *pTemp += targets[index];
     288                index++;
     289            }
     290            this->targets_.insert(*pTemp);
     291        }
     292       
     293        return true;
     294    }
     295   
     296    /**
     297    @brief
     298        Sets the font size.
     299    @param size
     300        The font size.
     301    @return
     302        Returns true if successful.
     303    */
     304    bool NotificationQueue::setFontSize(float size)
     305    {
     306        if(size <= 0)
     307            return false;
     308        this->fontSize_ = size;
     309        for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Set the font size for each overlay.
     310        {
     311            it->second->overlay->setFontSize(size);
     312        }
     313        return true;
     314    }
     315   
     316    /**
     317    @brief
     318        Sets the font.
     319    @param font
     320        The font.
     321    @return
     322        Returns true if successful.
     323    */
     324    bool NotificationQueue::setFont(const std::string & font)
     325    {
     326        this->font_ = font;
     327        for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Set the font for each overlay.
     328        {
     329            it->second->overlay->setFont(font);
     330        }
     331        return true;
     332    }
     333   
     334    /**
     335    @brief
     336        Adds a Notification, to the queue.
     337        It inserts it into the storage containers, creates an corresponding overlay and a container.
     338    @param notification
     339        The Notification.
     340    @param time
     341        The time.
     342    */
     343    void NotificationQueue::addNotification(Notification* notification, const std::time_t & time)
     344    {
     345        NotificationOverlayContainer* container = new NotificationOverlayContainer;
     346        container->overlay = new NotificationOverlay(this, notification);
     347        container->notification = notification;
     348        container->time = time;
     349        std::string timeString = std::ctime(&time);
     350        timeString.erase(timeString.length()-1);
     351        char buffer[64]; //TDO: Very un-nice.
     352        std::sprintf(buffer,"%x",(unsigned long)notification); //TDO: Use other conversion to avoid 64bit problems.
     353        std::string addressString = buffer;
     354        container->name = "NotificationOverlay(" + timeString + ")&" + addressString;
     355       
     356        this->containers_.insert(container);
     357        this->overlays_[notification] = container;
     358        this->insertElement(container->overlay, container->name);
     359        this->size_= this->size_+1;
     360    }
     361   
     362    /**
     363    @brief
     364        Removes a container from the queue.
     365    @param container
     366        A pointer to the container.
     367    @return
     368        Returns true if successful.
     369    */
     370    bool NotificationQueue::removeContainer(NotificationOverlayContainer* container)
     371    {
     372        if(this->size_ == 0) //!< You cannot remove anything if the queue is empty.
     373            return false;
     374       
     375        this->removeElement(container->name);
     376        this->containers_.erase(container);
     377        this->overlays_.erase(container->notification);
     378        delete container->overlay;
     379        delete container;
     380        this->size_= this->size_-1;
     381       
     382        return true;
     383    }
     384   
     385    /**
     386    @brief
     387        Clears the queue by removing all containers.
     388    */
     389    void NotificationQueue::clear(void)
     390    {
     391        std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin();
     392        while(it != this->containers_.end())
     393        {
     394            this->removeContainer(*it);
     395            it = this->containers_.begin(); //TDO: Needed?
     396        }
     397    }
     398
    109399}
  • code/branches/questsystem5/src/orxonox/overlays/notifications/NotificationQueue.h

    r2662 r2779  
    2727 */
    2828
     29/**
     30    @file NotificationQueue.h
     31    @brief Definition of the NotificationQueue class.
     32*/
     33
    2934#ifndef _NotificationOueue_H__
    3035#define _NotificationOueue_H__
    3136
    3237#include "OrxonoxPrereqs.h"
     38
     39#include <string>
     40#include <set>
     41#include <OgreOverlayManager.h>
    3342#include <OgreTextAreaOverlayElement.h>
     43#include <OgrePanelOverlayElement.h>
     44#include <map>
     45#include <ctime>
    3446
    35 #include "orxonox/overlays/OverlayText.h"
     47#include "orxonox/overlays/OverlayGroup.h"
    3648#include "orxonox/objects/Tickable.h"
    3749
    38 #include <string>
     50#include "NotificationManager.h"
    3951
    4052namespace orxonox
    4153{
     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
    4270    /**
    4371    @brief
    44 
     72        Displays Notifications from specific senders.
    4573    @author
    4674        Damian 'Mozork' Frick
    4775    */
    48     class _OrxonoxExport NotificationQueue : public OverlayText, public Tickable
     76
     77    class _OrxonoxExport NotificationQueue : public OverlayGroup, public Tickable
    4978    {
    50     public:
    51         NotificationQueue(BaseObject* creator);
    52         virtual ~NotificationQueue();
    53 
    54         static NotificationQueue* queue_s; //TDO Singleton? oder im level.
    55 
    56         virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
    57 
    58         virtual void tick(float dt);
    59 
    60         void update(void);
    61 
    62         int getLength(void) const
    63                 { return this->length_; }
    64         int getWidth(void) const
    65                 { return this->width_; }
    66 
    67         void setQueueText(const std::string & text);
    68         bool setLength(int length);
    69         bool setWidth(int width);
    70 
    71     private:
    72         Ogre::UTFString queueText_;
    73         int length_;
    74         int width_;
    75 
     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   
    76177    };
    77178
Note: See TracChangeset for help on using the changeset viewer.