Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 7342


Ignore:
Timestamp:
Sep 3, 2010, 9:17:51 PM (14 years ago)
Author:
dafrick
Message:

Some documenting, cleaning up. Also: Now the NotificationQueue has a height corresponding to its input size.

Location:
code/branches/notifications
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • code/branches/notifications/data/gui/scripts/NotificationLayer.lua

    r7338 r7342  
    99    local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
    1010    local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
     11    root:addChildWindow(queue)
     12
    1113    queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
    12     queue:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0.2, 0)))
    13     root:addChildWindow(queue)
     14    queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))
     15
    1416    table.insert(P.queueList, queue)
    1517    table.insert(P.nameList, name)
     
    3537
    3638function P.changePosition(name, xPos, yPos)
    37     local queue = P.nameToQueue(name)
     39    local queue = P.nameToQueueHelper(name)
    3840    if queue == nil then
    3941        cout(0, "Queue is nil!")
     
    4446
    4547function P.pushNotification(queueName, notification)
    46     local queue = P.nameToQueue(queueName)
     48    local queue = P.nameToQueueHelper(queueName)
    4749    if queue == nil then
    4850        cout(0, "Queue is nil!")
     
    5961
    6062function P.popNotification(queueName)
    61     local queue = P.nameToQueue(queueName)
     63    local queue = P.nameToQueueHelper(queueName)
    6264    if queue == nil then
    6365        cout(0, "Queue is nil!")
     
    6971
    7072function P.removeNotification(queueName, index)
    71     local queue = P.nameToQueue(queueName)
     73    local queue = P.nameToQueueHelper(queueName)
    7274    if queue == nil then
    7375        cout(0, "Queue is nil!")
     
    7981
    8082function P.clearQueue(name)
    81     local queue = P.nameToQueue(name)
     83    local queue = P.nameToQueueHelper(name)
    8284    if queue == nil then
    8385        cout(0, "Queue is nil!")
     
    8890end
    8991
    90 function P.nameToQueue(name)
     92function P.nameToQueueHelper(name)
    9193    local queue = nil
    9294    for k,v in pairs(P.nameList) do
     
    99101end
    100102
     103function P.queueHeightHelper(queue, size)
     104    local listbox = CEGUI.toListbox(queue)
     105    local item = CEGUI.createListboxTextItem("Text")
     106    listbox:addItem(item)
     107    local singleItemHeight = listbox:getTotalItemsHeight()
     108    local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel())
     109    local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue)
     110    local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
     111    listbox:removeItem(item)
     112    return frameHeight + singleItemHeight*size
     113end
     114
    101115return P
    102116
  • code/branches/notifications/data/gui/scripts/SheetManager.lua

    r7341 r7342  
    6969
    7070    -- Count the number of sheets that don't need input till the first that does.
    71     local counter = activeMenuSheets.size
    72     while counter > 0 and activeMenuSheets[counter].bNoInput do
    73         counter = counter - 1
    74     end
     71    local counter = noInputSheetCounter()
    7572    -- Pause game control if this is the first menu to be displayed
    7673    -- HUGE HACK?
     
    182179
    183180    -- Count the number of sheets that don't need input till the first that does.
    184     local counter = activeMenuSheets.size
    185     while counter > 0 and activeMenuSheets[counter].bNoInput do
    186         counter = counter - 1
    187     end
     181    local counter = noInputSheetCounter()
    188182    -- Resume control if the last (non-noInput) menu is hidden
    189183    if counter == 0 then
     
    204198
    205199    -- Count the number of sheets that don't need input till the first that does.
    206     local counter = activeMenuSheets.size
    207     while counter > 0 and activeMenuSheets[counter].bNoInput do
    208         counter = counter - 1
    209     end
     200    local counter = noInputSheetCounter()
    210201
    211202    -- If the first sheet that needs input is the MainMenu.
     
    224215end
    225216
     217function noInputSheetCounter()
     218    -- Count the number of sheets that don't need input till the first that does.
     219    local counter = activeMenuSheets.size
     220    while counter > 0 and activeMenuSheets[counter].bNoInput do
     221        counter = counter - 1
     222    end
     223    return counter
     224end
     225
    226226----------------------
    227227--- Initialisation ---
  • code/branches/notifications/src/libraries/core/GUIManager.cc

    r7338 r7342  
    237237    @param name
    238238        The name of the GUI
     239    @param bNoInput
     240        If true the GUI is transparent to input.
    239241
    240242        The function executes the Lua function with the same name in case the GUIManager is ready.
  • code/branches/notifications/src/modules/notifications/NotificationQueue.cc

    r7338 r7342  
    2828
    2929/**
    30     @file
     30    @file NotificationQueue.cc
    3131    @brief Implementation of the NotificationQueue class.
    3232*/
     
    3434#include "NotificationQueue.h"
    3535
     36#include <algorithm>
     37
    3638#include "util/Convert.h"
    3739#include "core/CoreIncludes.h"
    38 #include "core/XMLPort.h"
    39 #include "Notification.h"
    4040#include "core/GUIManager.h"
    4141#include "core/LuaState.h"
    42 #include <algorithm>
     42#include "Notification.h"
    4343
    4444namespace orxonox
    4545{
    4646
    47     const std::string NotificationQueue::DEFAULT_FONT("VeraMono");
    4847    const Vector2 NotificationQueue::DEFAULT_POSITION(0.0,0.0);
    49     const float NotificationQueue::DEFAULT_FONT_SIZE = 0.025f;
    5048
    5149    /**
     
    5351        Constructor. Creates and initializes the object.
    5452    */
    55     NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, const Vector2& position, unsigned int length, unsigned int displayTime)
     53    NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, const Vector2& position, unsigned int displayTime)
    5654    {
    5755        this->registered_ = false;
     
    6563        this->maxSize_ = size;
    6664        this->position_ = position;
    67         this->notificationLength_ = length;
    6865        this->setDisplayTime(displayTime);
    6966
    7067        this->create();
     68        this->positionChanged();
    7169
    7270        NotificationManager::getInstance().registerListener(this);
     
    10199
    102100    /**
    103     //TODO: Document.
     101    @brief
     102        Creates the NotificationQueue in lua.
    104103    */
    105104    void NotificationQueue::create(void)
    106105    {
    107         //TODO: Also transfer font and fontsize.
    108106        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
    109         this->positionChanged();
    110107    }
    111108
     
    118115    void NotificationQueue::tick(float dt)
    119116    {
    120         this->tickTime_ += dt; //!< Add the time interval that has passed to the time counter.
    121         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.
    122         {
    123             this->timeLimit_.time = std::time(0)-this->displayTime_; //!< Container containig the current time.
     117        this->tickTime_ += dt; // Add the time interval that has passed to the time counter.
     118        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.
     119        {
     120            this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
    124121
    125122            std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin();
    126             while(it != this->ordering_.upper_bound(&this->timeLimit_)) //!< Iterate through all elements whose creation time is smaller than the current time minus the display time.
     123            while(it != this->ordering_.upper_bound(&this->timeLimit_)) // Iterate through all elements whose creation time is smaller than the current time minus the display time.
    127124            {
    128125                NotificationContainer* temp = *it;
     
    131128            }
    132129
    133             this->tickTime_ = this->tickTime_ - (int)this->tickTime_; //!< Reset time counter.
     130            this->tickTime_ = this->tickTime_ - (int)this->tickTime_; // Reset time counter.
    134131        }
    135132    }
     
    138135    @brief
    139136        Updates the NotificationQueue.
    140         Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting the in the queue.
     137        Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue.
    141138    */
    142139    void NotificationQueue::update(void)
     
    145142
    146143        std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
    147         if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) //!< Get the Notifications sent in the interval form now to minus the display time.
     144        if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) // Get the Notifications sent in the interval form now to minus the display time.
    148145        {
    149146            COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl;
     
    154151            return;
    155152
    156         for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications.
     153        for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications.
    157154            this->push(it->second, it->first);
    158155
     
    179176    /**
    180177    @brief
     178        Adds a Notification, to the queue.
     179        It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI.
     180    @param notification
     181        The Notification.
     182    @param time
     183        The time.
     184    */
     185    void NotificationQueue::push(Notification* notification, const std::time_t & time)
     186    {
     187        NotificationContainer* container = new NotificationContainer;
     188        container->notification = notification;
     189        container->time = time;
     190
     191        // If the maximum size of the NotificationQueue has been reached the last (least recently added) Notification is removed.
     192        if(this->getSize() >= this->getMaxSize())
     193            this->pop();
     194
     195        this->size_++;
     196
     197        this->ordering_.insert(container);
     198        this->notifications_.insert(this->notifications_.begin(), container);
     199
     200        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
     201    }
     202
     203    /**
     204    @brief
     205        Removes the least recently added Notification form the NotificationQueue.
     206    */
     207    void NotificationQueue::pop(void)
     208    {
     209        NotificationContainer* container = this->notifications_.back();
     210        this->ordering_.erase(container);
     211        this->notifications_.pop_back();
     212        this->size_--;
     213        delete container;
     214        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
     215    }
     216
     217    /**
     218    @brief
     219        Removes the Notification that is stored in the input container.
     220    @param container
     221        The NotificationContainer with the Notification to be removed.
     222    */
     223    void NotificationQueue::remove(NotificationContainer* container)
     224    {
     225        std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container);
     226        std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin ();
     227        this->ordering_.erase(container);
     228        this->notifications_.erase(it);
     229        this->size_--;
     230        delete container;
     231        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
     232    }
     233
     234    /**
     235    @brief
     236        Clears the queue by removing all containers.
     237    */
     238    void NotificationQueue::clear(void)
     239    {
     240        this->ordering_.clear();
     241        for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)
     242        {
     243            delete *it;
     244        }
     245        this->notifications_.clear();
     246        this->size_ = 0;
     247        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
     248    }
     249
     250    /**
     251    @brief
    181252        Sets the name of the NotificationQueue.
    182253    @param name
     
    203274    {
    204275        this->maxSize_ = size;
    205         this->update();
    206     }
    207 
    208     /**
    209     @brief
    210         Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
    211     @param length
    212         The length to be set.
    213     @return
    214         Returns true if successful.
    215     */
    216     void NotificationQueue::setNotificationLength(unsigned int length)
    217     {
    218         this->notificationLength_ = length;
    219276        this->update();
    220277    }
     
    299356    /**
    300357    @brief
    301         Sets the font size.
    302     @param size
    303         The font size.
    304     @return
    305         Returns true if successful.
    306     */
    307     bool NotificationQueue::setFontSize(float size)
    308     {
    309         if(size <= 0)
    310             return false;
    311        
    312         return true;
    313     }
    314 
    315     /**
    316     @brief
    317         Sets the font.
    318     @param font
    319         The font.
    320     @return
    321         Returns true if successful.
    322     */
    323     bool NotificationQueue::setFont(const std::string & font)
    324     {
    325        
    326         return true;
    327     }
    328 
    329     /**
    330     @brief
    331358        Aligns all the Notifications to the position of the NotificationQueue.
    332359    */
     
    336363    }
    337364
    338     /**
    339     @brief
    340         Adds a Notification, to the queue.
    341         It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI.
    342     @param notification
    343         The Notification.
    344     @param time
    345         The time.
    346     */
    347     void NotificationQueue::push(Notification* notification, const std::time_t & time)
    348     {
    349         NotificationContainer* container = new NotificationContainer;
    350         container->notification = notification;
    351         container->time = time;
    352        
    353         // If the maximum size of the NotificationQueue has been reached the last (least recently added) Notification is removed.
    354         if(this->getSize() >= this->getMaxSize())
    355             this->pop();
    356 
    357         this->size_++;
    358 
    359         this->ordering_.insert(container);
    360         this->notifications_.insert(this->notifications_.begin(), container);
    361 
    362         //TODO: Clip message if necessary.
    363         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
    364     }
    365 
    366     /**
    367     @brief
    368         Removes the least recently added Notification form the NotificationQueue.
    369     */
    370     void NotificationQueue::pop(void)
    371     {
    372         NotificationContainer* container = this->notifications_.back();
    373         this->ordering_.erase(container);
    374         this->notifications_.pop_back();
    375         this->size_--;
    376         delete container;
    377         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
    378     }
    379 
    380     /**
    381     @brief
    382         Removes the Notification that is stored in the input container.
    383     @param container
    384         The NotificationContainer with the Notification to be removed.
    385     */
    386     void NotificationQueue::remove(NotificationContainer* container)
    387     {
    388         std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container);
    389         std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin ();
    390         this->ordering_.erase(container);
    391         this->notifications_.erase(it);
    392         this->size_--;
    393         delete container;
    394         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
    395     }
    396 
    397     /**
    398     @brief
    399         Clears the queue by removing all containers.
    400     */
    401     void NotificationQueue::clear(void)
    402     {
    403         this->ordering_.clear();
    404         for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)
    405         {
    406             delete *it;
    407         }
    408         this->notifications_.clear();
    409         this->size_ = 0;
    410         GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
    411     }
    412 
    413365}
  • code/branches/notifications/src/modules/notifications/NotificationQueue.h

    r7338 r7342  
    7676
    7777        public:
    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);
     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 displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
    7979            virtual ~NotificationQueue();
    8080
     
    104104                { return this->size_; }
    105105            /**
    106             @brief Returns the maximum length in characters a Notification message is allowed to have.
    107             @return Returns the maximum Notification length.
    108             */
    109             inline unsigned int getNotificationLength() const
    110                 { return this->notificationLength_; }
    111             /**
    112106            @brief Returns the time interval the Notification is displayed.
    113107            @return Returns the display time.
     
    121115            inline const Vector2 & getPosition() const
    122116                { return this->position_; }
    123             /**
    124             @brief Returns the font size used to display the Notifications.
    125             @return  Returns the font size.
    126             */
    127             inline float getFontSize() const
    128                 { return this->fontSize_; }
    129             /**
    130             @brief Returns the font used to display the Notifications.
    131             @return Returns the font.
    132             */
    133             inline const std::string & getFont() const
    134                 { return this->font_; }
    135117
    136118            /**
     
    151133        private:
    152134            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.
    154135            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
    155             static const float DEFAULT_FONT_SIZE; //!< The default font size.
    156136
    157             static const std::string DEFAULT_FONT; //!< The default font.
    158137            static const Vector2 DEFAULT_POSITION; //!< the default position.
    159138
     
    167146
    168147            std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
    169 
    170             float fontSize_; //!< The font size.
    171             std::string font_; //!< The font.
    172148
    173149            std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. //TODO: Would set work as well?
     
    185161
    186162            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.
    188163            void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
    189164
    190165            bool setTargets(const std::string & targets); //!< Set the targets of this queue.
    191 
    192             bool setFontSize(float size); //!< Set the font size.
    193             bool setFont(const std::string & font); //!< Set the font.
    194166
    195167            void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
Note: See TracChangeset for help on using the changeset viewer.