Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Feb 14, 2011, 11:02:58 PM (14 years ago)
Author:
dafrick
Message:

Some extension of NotificationQueue, font size and color can now be specified.

Location:
code/branches/tutoriallevel/src/modules/notifications
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • code/branches/tutoriallevel/src/modules/notifications/NotificationManager.cc

    r7552 r7894  
    4040#include "network/Host.h"
    4141#include "network/NetworkFunction.h"
     42#include "util/Convert.h"
    4243#include "util/ScopedSingletonManager.h"
    4344
     
    338339    /**
    339340    @brief
     341        Fetches the newest Notifications for a specific NotificationListener and stores them in the input map.
     342    @param listener
     343        The NotificationListener the Notifications are fetched for.
     344    @param map
     345        A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated.
     346    @param numberOfNotifications
     347        The number of newest Notifications to be got.
     348    @return
     349        Returns true if successful.
     350    */
     351    void NotificationManager::getNewestNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications)
     352    {
     353        assert(listener);
     354        assert(map);
     355
     356        std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener.
     357
     358        if(!notifications->empty()) // If the list of Notifications is not empty.
     359        {
     360            std::multimap<std::time_t,Notification*>::iterator it = notifications->end();
     361            for(int i = 0; i < numberOfNotifications; i++) // Iterate through the Notifications from the newest until we have the specified number of notifications.
     362            {
     363                it--;
     364                map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map.
     365                if(it == notifications->begin())
     366                    break;
     367            }
     368        }
     369    }
     370
     371    /**
     372    @brief
    340373        Enters the edit mode of the NotificationLayer.
    341374    */
     
    381414    void NotificationManager::loadQueues(void)
    382415    {
    383         new NotificationQueue("all");
     416        NotificationQueue* allQueue = new NotificationQueue("all");
     417        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"all\", 0.5, 0, " + multi_cast<std::string>(allQueue->getMaxSize()) + ")");
     418        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"all\", 0, 10, 0.3, 0)");
     419
     420        NotificationQueue* infoQueue = new NotificationQueue("info", NotificationManager::ALL, 1, -1);
     421        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, 1.0, 1.0, 0.0, 0.8)");
     422        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")");
     423        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");
    384424    }
    385425
  • code/branches/tutoriallevel/src/modules/notifications/NotificationManager.h

    r7552 r7894  
    9898                { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); }
    9999
     100            void getNewestNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int numberOfNotifications); //!< Fetches the newest Notifications for a specific NotificationListener and stores them in the input map.
     101
    100102            void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer.
    101103
  • code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.cc

    r7489 r7894  
    159159    {
    160160        this->tickTime_ += dt; // Add the time interval that has passed to the time counter.
    161         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.
     161        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.
    162162        {
    163163            this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
     
    187187        std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
    188188        // Get the Notifications sent in the interval from now to now minus the display time.
    189         NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
     189        if(this->displayTime_ == INF)
     190            NotificationManager::getInstance().getNewestNotifications(this, notifications, this->getMaxSize());
     191        else
     192            NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_);
    190193
    191194        if(!notifications->empty())
     
    355358        Sets the maximum number of seconds a Notification is displayed.
    356359    @param time
    357         The number of seconds the Notifications is displayed.
    358     @return
    359         Returns true if successful.
    360     */
    361     void NotificationQueue::setDisplayTime(unsigned int time)
     360        The number of seconds a Notification is displayed.
     361    */
     362    void NotificationQueue::setDisplayTime(int time)
    362363    {
    363364        if(this->displayTime_ == time)
  • code/branches/tutoriallevel/src/modules/notifications/NotificationQueue.h

    r7552 r7894  
    121121                { return this->maxSize_; }
    122122
    123             void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
     123            void setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed.
    124124            /**
    125125            @brief Returns the time interval the Notification is displayed.
    126126            @return Returns the display time.
    127127            */
    128             inline unsigned int getDisplayTime() const
     128            inline int getDisplayTime() const
    129129                { return this->displayTime_; }
    130130            // tolua_end
     
    152152            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
    153153            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
     154            static const int INF = -1; //!< Constant denoting infinity.
    154155
    155156            std::string name_; //!< The name of the NotificationQueue.
     
    157158            unsigned int maxSize_; //!< The maximal number of Notifications displayed.
    158159            unsigned int size_; //!< The number of Notifications displayed.
    159             unsigned int displayTime_; //!< The time a Notification is displayed.
     160            int displayTime_; //!< The time a Notification is displayed.
    160161
    161162            bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
Note: See TracChangeset for help on using the changeset viewer.