Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
May 12, 2011, 12:31:23 AM (13 years ago)
Author:
dafrick
Message:

Merging tutoriallevel2 branch into tutoriallevel3 branch.

Location:
code/branches/tutoriallevel3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel3

  • code/branches/tutoriallevel3/src/modules/notifications/NotificationQueue.cc

    r8079 r8453  
    3838
    3939#include "core/CoreIncludes.h"
    40 #include "core/GameMode.h"
    41 #include "core/GUIManager.h"
    42 #include "core/LuaState.h"
    43 #include "util/Convert.h"
    4440#include "util/SubString.h"
    45 
    46 #include "Notification.h"
    4741
    4842namespace orxonox
     
    5650    @param senders
    5751        The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
    58         The senders need to be seperated by commas.
     52        The senders need to be separated by commas.
    5953    @param size
    6054        The size (the maximum number of displayed Notifications) of this NotificationQueue.
     
    8882        }
    8983
    90         this->create(); // Creates the NotificationQueue in lua.
    91 
    92         // Register the NotificationQueue as NotificationListener with the NotificationManager.
    93         bool listenerRegistered = NotificationManager::getInstance().registerListener(this);
    94         if(!listenerRegistered) // If the registration has failed.
    95         {
    96             this->registered_ = false;
    97             // Remove the NotificationQueue in lua.
    98             if(GameMode::showsGraphics())
    99                 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
     84        COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
     85    }
     86
     87    /**
     88    @brief
     89        Destructor.
     90    */
     91    NotificationQueue::~NotificationQueue()
     92    {
     93        this->targets_.clear();
     94
     95        if(this->registered_) // If the NotificationQueue is registered.
     96        {
     97            this->clear(true);
     98
     99            // Unregister with the NotificationManager.
    100100            NotificationManager::getInstance().unregisterQueue(this);
    101             COUT(1) << "Error: NotificationQueue '" << this->getName() << "' could not be registered." << std::endl;
    102             return;
    103         }
    104 
    105         COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
    106     }
    107 
    108     /**
    109     @brief
    110         Destructor.
    111     */
    112     NotificationQueue::~NotificationQueue()
    113     {
    114         this->targets_.clear();
    115 
    116         if(this->registered_) // If the NotificationQueue is registered.
    117         {
    118             this->clear(true);
    119 
    120             // Unregister with the NotificationManager.
    121             NotificationManager::getInstance().unregisterListener(this);
    122             NotificationManager::getInstance().unregisterQueue(this);
    123         }
    124     }
    125 
    126     /**
    127     @brief
    128         Destroys the NotificationQueue.
    129         Used in lua and NotificationManager.
    130     @param noGraphics
    131         If this is set to true (false is default), then the queue is not removed in lua. This is used to destroy the queue, after the GUIManager has been destroyed.
    132     */
    133     void NotificationQueue::destroy(bool noGraphics)
    134     {
    135         // Remove the NotificationQueue in lua.
    136         if(GameMode::showsGraphics() && !noGraphics)
    137             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() +  "\")");
    138 
     101        }
     102       
    139103        COUT(3) << "NotificationQueue '" << this->getName() << "' destroyed." << std::endl;
    140 
    141         this->OrxonoxClass::destroy();
    142     }
    143 
    144     /**
    145     @brief
    146         Creates the NotificationQueue in lua.
    147     */
    148     void NotificationQueue::create(void)
    149     {
    150         if(GameMode::showsGraphics())
    151             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() +  "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
    152104    }
    153105
     
    161113    {
    162114        this->tickTime_ += dt; // Add the time interval that has passed to the time counter.
    163         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.
     115        if(this->displayTime_ != INF && 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.
    164116        {
    165117            this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
     
    181133        Updates the NotificationQueue.
    182134        Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue.
     135        This is called by the NotificationManager when the Notifications have changed so much, that the NotificationQueue may have to re-initialize his operations.
    183136    */
    184137    void NotificationQueue::update(void)
     
    188141        std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
    189142        // Get the Notifications sent in the interval from now to now minus the display time.
    190         NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
     143        if(this->displayTime_ == INF)
     144            NotificationManager::getInstance().getNewestNotifications(this, notifications, this->getMaxSize());
     145        else
     146            NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
    191147
    192148        if(!notifications->empty())
     
    246202        this->notifications_.insert(this->notifications_.begin(), container);
    247203
    248         // Push the Notification to the GUI.
    249         if(GameMode::showsGraphics())
    250             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
     204        // Inform that a Notification was pushed.
     205        this->notificationPushed(notification);
    251206
    252207        COUT(5) << "Notification \"" << notification->getMessage() << "\" pushed to NotificationQueue '" << this->getName() << "'" << endl;
     208        COUT(3) << "NotificationQueue \"" << this->getName() << "\": " << notification->getMessage() << endl;
    253209    }
    254210
     
    279235        delete container;
    280236
    281         // Pops the Notification from the GUI.
    282         if(GameMode::showsGraphics())
    283             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
     237        // Inform that a Notification was popped.
     238        this->notificationPopped();
    284239    }
    285240
     
    305260        delete *containerIterator;
    306261
    307         // Removes the Notification from the GUI.
    308         if(GameMode::showsGraphics())
    309             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
     262        // TODO: index automatically cast?
     263        // Inform that a Notification was removed.
     264        this->notificationRemoved(index);
    310265    }
    311266
     
    314269        Clears the NotificationQueue by removing all NotificationContainers.
    315270    @param noGraphics
    316         If this is eset to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
     271        If this is set to true the GUI is not informed of the clearing of the NotificationQueue. This is needed only internally.
    317272    */
    318273    void NotificationQueue::clear(bool noGraphics)
     
    326281        this->notifications_.clear();
    327282        this->size_ = 0;
    328 
    329         // Clear the NotificationQueue in the GUI.
    330         if(GameMode::showsGraphics() && !noGraphics)
    331             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
    332283    }
    333284
     
    364315        Sets the maximum number of seconds a Notification is displayed.
    365316    @param time
    366         The number of seconds the Notifications is displayed.
    367     @return
    368         Returns true if successful.
    369     */
    370     void NotificationQueue::setDisplayTime(unsigned int time)
     317        The number of seconds a Notification is displayed.
     318    */
     319    void NotificationQueue::setDisplayTime(int time)
    371320    {
    372321        if(this->displayTime_ == time)
     
    381330    /**
    382331    @brief
    383         Produces all targets of the NotificationQueue concatinated as string, with commas (',') as seperators.
     332        Produces all targets of the NotificationQueue concatenated as string, with commas (',') as separators.
    384333    @return
    385334        Returns the targets as a string.
     
    407356        The targets are the senders whose Notifications are displayed in this queue.
    408357    @param targets
    409         Accepts a string of targets, each seperated by commas (','), spaces are ignored.
     358        Accepts a string of targets, each separated by commas (','), spaces are ignored.
    410359    */
    411360    void NotificationQueue::setTargets(const std::string & targets)
     
    417366            this->targets_.insert(string[i]);
    418367
     368        // TODO: Why?
    419369        if(this->registered_)
    420370        {
    421             NotificationManager::getInstance().unregisterListener(this);
    422             NotificationManager::getInstance().registerListener(this);
    423         }
     371            NotificationManager::getInstance().unregisterQueue(this);
     372            NotificationManager::getInstance().registerQueue(this);
     373        }
     374    }
     375
     376    /**
     377    @brief
     378        Pops all Notifications from the NotificationQueue.
     379    @return
     380        Returns true if successful, false if not.
     381    */
     382    bool NotificationQueue::tidy(void)
     383    {
     384        while(this->size_ > 0)
     385            this->pop();
     386        return true;
    424387    }
    425388
Note: See TracChangeset for help on using the changeset viewer.