[Orxonox-commit 3768] r8448 - in code/branches/tutoriallevel2: data/gui/scripts src/modules/notifications src/orxonox/interfaces

dafrick at orxonox.net dafrick at orxonox.net
Wed May 11 22:45:56 CEST 2011


Author: dafrick
Date: 2011-05-11 22:45:56 +0200 (Wed, 11 May 2011)
New Revision: 8448

Modified:
   code/branches/tutoriallevel2/data/gui/scripts/NotificationLayer.lua
   code/branches/tutoriallevel2/src/modules/notifications/Notification.cc
   code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc
   code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h
   code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc
   code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h
   code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.cc
   code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.h
   code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.cc
   code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h
Log:
Extending NotificationQueueCEGUI.


Modified: code/branches/tutoriallevel2/data/gui/scripts/NotificationLayer.lua
===================================================================
--- code/branches/tutoriallevel2/data/gui/scripts/NotificationLayer.lua	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/data/gui/scripts/NotificationLayer.lua	2011-05-11 20:45:56 UTC (rev 8448)
@@ -26,7 +26,7 @@
     {
         ["window"]    = queue,
         ["name"]      = name,
-        ["edit"]      = nil,
+        ["maxSize"]      = size,
         ["visible"]   = false,
         ["fontSize"]  = 12,
         ["fontColor"] = "FFFFFFFF",
@@ -182,51 +182,64 @@
 
 -- Change the size of the queue.
 -- The parameters are (in order) 'name of the queue', 'relative width', 'absolute width in pixel', 'relative height', 'absolute heigth in pixel'.
--- Additionally the last parameter can be ommitted and relativeHeight can be set to the size (i.e. the maximal number of notifications displayed) of the queue, which leads to the height being set such that all notifications can be displayed.
+-- Additionally the last two parameters can be ommitted, which leads to the height being set such that all notifications can be displayed. using the size of the queue.
 function P.resizeQueue(queueName, relativeWidth, absoluteWidth, relativeHeight, absoluteHeigth)
-    local queueWindow = P.queueList[queueName].window
+    local queue = P.queueList[queueName]
+    local queueWindow = queue.window
     if queueWindow == nil then
         return
     end
     if absoluteHeigth == nil then
-        absoluteHeigth = P.queueHeightHelper(P.queueList[queueName], relativeHeight)
+        absoluteHeigth = P.queueHeightHelper(queue, queue.maxSize)
         relativeHeight = 0
     end
     queueWindow:setSize(CEGUI.UVector2(CEGUI.UDim(relativeWidth, absoluteWidth), CEGUI.UDim(relativeHeight, absoluteHeigth)))
 end
 
--- Change the font size and font color of all notifications in a queueHeightHelper
--- The parameters are (in order) 'name of the queue', 'font size', 'ARGB of the font color in hex notation'.
-function P.changeQueueFont(queueName, size, color)
+-- Change the horizontal alignment of the displayed notifications.
+-- The parameters are the name of the queue and the alignment parameter,
+function P.changeQueueAlignment(queueName, alignment)
     local queue = P.queueList[queueName]
     local queueWindow = queue.window
     if queueWindow == nil then
         return
     end
 
+    queue.alignment = alignment
+    local item = nil
+    for i=queue.first,queue.last-1 do
+        item = queue.items[i]
+        item:setProperty("HorzFormatting", queue.alignment)
+    end
+end
+
+-- Change the font size  of all notifications in a queue.
+-- The parameters are (in order) 'name of the queue', 'font size'.
+function P.changeQueueFontSize(queueName, size)
+    local queue = P.queueList[queueName]
+    local queueWindow = queue.window
+    if queueWindow == nil then
+        return
+    end
+
     queue.fontSize = size
-    local changeColor = false
-    if color ~= nil then
-        queue.fontColor = color
-        changeColor = true
-    end
     for i=queue.first,queue.last-1 do
-        P.setItemFontHelper(queue.items[i], queue, changeColor)
+        P.setItemFontHelper(queue.items[i], queue, false)
     end
 end
 
-function P.changeQueueAlignment(queueName, alignment)
+-- Change the font color of all notifications in a queue.
+-- The parameters are (in order) 'name of the queue', 'ARGB of the font color in hex notation'.
+function P.changeQueueFontColor(queueName, color)
     local queue = P.queueList[queueName]
     local queueWindow = queue.window
     if queueWindow == nil then
         return
     end
-    
-    queue.alignment = alignment
-    local item = nil
+
+    queue.fontColor = color
     for i=queue.first,queue.last-1 do
-        item = queue.items[i]
-        item:setProperty("HorzFormatting", queue.alignment)
+        P.setItemFontHelper(queue.items[i], queue, true)
     end
 end
 

Modified: code/branches/tutoriallevel2/src/modules/notifications/Notification.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/Notification.cc	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/src/modules/notifications/Notification.cc	2011-05-11 20:45:56 UTC (rev 8448)
@@ -46,6 +46,8 @@
         The message of the Notification.
     @param sender
         The sender of the Notification.
+    @param type
+        The type of the Notification.
     */
     Notification::Notification(const std::string& message, const std::string& sender, notificationMessageType::Value type)
     {

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.cc	2011-05-11 20:45:56 UTC (rev 8448)
@@ -35,10 +35,7 @@
 
 #include "core/command/ConsoleCommand.h"
 #include "core/CoreIncludes.h"
-#include "core/GameMode.h"
-#include "core/GUIManager.h"
 #include "core/LuaState.h"
-#include "util/Convert.h"
 #include "util/ScopedSingletonManager.h"
 
 #include "interfaces/NotificationListener.h"
@@ -47,14 +44,9 @@
 #include "NotificationQueue.h"
 #include "NotificationQueueCEGUI.h"
 
-#include "ToluaBindNotifications.h"
-
 namespace orxonox
 {
 
-    // Register tolua_open function when loading the library.
-    DeclareToluaInterface(Notifications);
-
     ManageScopedSingleton(NotificationManager, ScopeID::Root, false);
 
     /**
@@ -107,6 +99,8 @@
         The message of the new Notification.
     @param sender
         The name of the entity (of the collective) that sent the new Notification.
+    @param type
+        The type of the new Notification.
     @return
         Returns true if successful.
     */
@@ -125,16 +119,22 @@
         The command to be executed,
     @param sender
         The The name of the entity (of the collective) that sent the command.
+    @return
+        Returns true if the command was successfully executed.
     */
     bool NotificationManager::executeCommand(notificationCommand::Value command, const std::string& sender)
     {
+        bool commandExecuted = false;
         if(command == notificationCommand::clear)
         {
-            this->commandClear(sender);
-            return true;
+            if(this->commandClear(sender))
+                commandExecuted = true;
         }
 
-        return false;
+        if(commandExecuted)
+            COUT(3) << "Notification command \"" << NotificationListener::command2Str(command) << "\" executed." << endl;
+
+        return commandExecuted;
     }
 
     /**
@@ -142,18 +142,23 @@
         The clear command. Clears all NotificationQueues that have its sender as a target.
     @param sender
         The sender of the clear command.
+    @return
+        Returns true if the command was successfully executed by at least one NotificationQueue, false if it was not executed.
     */
-    void NotificationManager::commandClear(const std::string& sender)
+    bool NotificationManager::commandClear(const std::string& sender)
     {
         bool all = (sender == NotificationListener::ALL);
+        bool executed = false;
         // Clear all NotificationQueues that have the input sender as target.
         for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); it++) // Iterate through all NotificationQueues.
         {
             const std::set<std::string>& set = it->second->getTargetsSet();
             // If either the sender is 'all', the NotificationQueue has as target all or the NotificationQueue has the input sender as a target.
             if(all || set.find(NotificationListener::ALL) != set.end() || set.find(sender) != set.end())
-                it->second->tidy();
+                executed = it->second->tidy() || executed;
         }
+
+        return executed;
     }
     
     /**
@@ -384,35 +389,6 @@
 
     /**
     @brief
-        Loads all the NotificationQueues that should exist.
-    */
-    void NotificationManager::loadQueues(void)
-    {
-        NotificationQueue* allQueue = new NotificationQueueCEGUI("all");
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"all\", 0.5, 0, " + multi_cast<std::string>(allQueue->getMaxSize()) + ")");
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"all\", 0, 10, 0.3, 0)");
-
-        NotificationQueue* infoQueue = new NotificationQueueCEGUI("info", NotificationListener::ALL, 1, -1);
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFont(\"info\", 24, \"CCFFFF00\")");
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"info\", 0.6, 0, " + multi_cast<std::string>(infoQueue->getMaxSize()) + ")");
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"info\", 0.2, 0, 0.8, 0)");
-        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueAlignment(\"info\", \"HorzCentred\")");
-    }
-
-    /**
-    @brief
-        Creates a new NotificationQueue.
-        This is used in lua.
-    @param name
-        The name of the new NotificationQueue.
-    */
-    void NotificationManager::createQueue(const std::string& name)
-    {
-        new NotificationQueue(name);
-    }
-
-    /**
-    @brief
         Get the NotificationQueue with the input name.
     @param name
         The name of the NotificationQueue.
@@ -429,4 +405,22 @@
         return (*it).second;
     }
 
+    /**
+    @brief
+        Loads all the NotificationQueues that should exist.
+    */
+    void NotificationManager::loadQueues(void)
+    {
+        NotificationQueueCEGUI* allQueue = new NotificationQueueCEGUI("all");
+        allQueue->setDisplaySize(Vector2(0.5, 0));
+        allQueue->setPosition(Vector4(0.0, 10, 0.3, 0));
+
+        NotificationQueueCEGUI* infoQueue = new NotificationQueueCEGUI("info", NotificationListener::ALL, 1, -1);
+        infoQueue->setPosition(Vector4(0.2, 0, 0.8, 0));
+        infoQueue->setFontSize(24);
+        infoQueue->setFontColor(Vector4(1.0, 1.0, 0.0, 0.8));
+        infoQueue->setAlignment("HorzCentred");
+        infoQueue->setDisplaySize(Vector2(0.6, 0.0));
+    }
+
 }

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationManager.h	2011-05-11 20:45:56 UTC (rev 8448)
@@ -49,8 +49,8 @@
 
     /**
     @brief
-        The Singleton NotificationManager is a NotificationListener and functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationQueues "NotificationQueues".
-        It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationLQueue "NotificationQueues".
+        The Singleton NotificationManager is a NotificationListener and functions as a gateway between @ref orxonox::Notification "Notifications" and @ref orxonox::NotificationQueue "NotificationQueues".
+        It receives, organizes @ref orxonox::Notification "Notifications" and the redistributes them to the specific @ref orxonox::NotificationQueue "NotificationQueues".
         It also works as a liaison between the @ref orxonox::NotificationQueue "NotificationQueues" and the GUI that displays notification, called NotificationLayer.
 
     @author
@@ -97,12 +97,10 @@
             bool registerQueue(NotificationQueue* queue); // Registers a NotificationQueue.
             void unregisterQueue(NotificationQueue* queue); // Unregisters a NotificationQueue.
 
-            // tolua_begin
-            void loadQueues(void); // Loads all the NotificationQueues that should exist.
-            void createQueue(const std::string& name); // Creates a new NotificationQueue.
-            orxonox::NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name.
-            // tolua_end
+            void loadQueues(void); // tolua_export // Loads all the NotificationQueues that should exist.
 
+            NotificationQueue* getQueue(const std::string & name); // Get the NotificationQueue with the input name.
+
         private:
             static NotificationManager* singletonPtr_s;
 
@@ -114,7 +112,7 @@
             bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); // Helper method that removes an input Notification form an input map.
             
             // Commands
-            void commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target.
+            bool commandClear(const std::string& sender); // The clear command. Clears all NotificationQueues that have its sender as a target.
 
     }; // tolua_export
 

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.cc	2011-05-11 20:45:56 UTC (rev 8448)
@@ -207,6 +207,7 @@
         this->notificationPushed(notification);
 
         COUT(5) << "Notification \"" << notification->getMessage() << "\" pushed to NotificationQueue '" << this->getName() << "'" << endl;
+        COUT(3) << "NotificationQueue \"" << this->getName() << "\": " << notification->getMessage() << endl;
     }
 
     /**
@@ -373,11 +374,18 @@
             NotificationManager::getInstance().registerQueue(this);
         }
     }
-    
-    void NotificationQueue::tidy(void)
+
+    /**
+    @brief
+        Pops all Notifications from the NotificationQueue.
+    @return
+        Returns true if successful, false if not.
+    */
+    bool NotificationQueue::tidy(void)
     {
         while(this->size_ > 0)
             this->pop();
+        return true;
     }
 
 }

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueue.h	2011-05-11 20:45:56 UTC (rev 8448)
@@ -141,13 +141,9 @@
             void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue.
             const std::string& getTargets(void) const; //!< Returns a string consisting of the concatenation of the targets.
 
-            void tidy(void);
+            bool tidy(void); // Pops all Notifications from the NotificationQueue.
             
         protected:
-            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
-            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
-            static const int INF = -1; //!< Constant denoting infinity.
-        
             /**
             @brief Is called when a notification was pushed.
             @param notification The Notification that was pushed.
@@ -165,6 +161,10 @@
             
             virtual void clear(bool noGraphics = false); //!< Clears the NotificationQueue by removing all NotificationContainers.
 
+        protected:
+            static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
+            static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
+            static const int INF = -1; //!< Constant denoting infinity.
 
         private:
             std::string name_; //!< The name of the NotificationQueue.

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.cc
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.cc	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.cc	2011-05-11 20:45:56 UTC (rev 8448)
@@ -33,6 +33,8 @@
 
 #include "NotificationQueueCEGUI.h"
 
+#include <sstream>
+
 #include "core/CoreIncludes.h"
 #include "core/GameMode.h"
 #include "core/GUIManager.h"
@@ -41,12 +43,24 @@
 
 #include "Notification.h"
 
+#include "ToluaBindNotifications.h"
+
 namespace orxonox
 {
 
+    // Register tolua_open function when loading the library.
+    DeclareToluaInterface(Notifications);
+
     NotificationQueueCEGUI::NotificationQueueCEGUI(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) : NotificationQueue(name, senders, size, displayTime)
     {
         RegisterObject(NotificationQueueCEGUI);
+
+        this->displaySize_ = Vector4(1.0, 0.0, 0.0, 0.0);
+        this->position_ = Vector4(0.0, 0.0, 0.0, 0.0);
+        this->alignment_ = "LeftAligned";
+        this->fontSize_ = 12;
+        this->fontColor_ = Vector4(1.0, 1.0, 1.0, 1.0);
+        this->fontColorStr_ = "FFFFFFFF";
         
         // Create the NotificationQueueCEGUI in lua.
         this->create();
@@ -72,9 +86,131 @@
 
         NotificationQueue::destroy();
     }
-    
+
     /**
     @brief
+        Set the size of the window that displays the NotificationQueue.
+    @param size
+        The size is a vector with components:
+        - The relative width of the window. (A value between 0 and 1)
+        - The absolute width in pixels. (Additional to the relative width, can be negative)
+        - The relative height of the window. (A value between 0 and 1)
+        - The absolute height in pixels. (Additional to the relative width, can be negative.)
+        If both the 3rd and 4th component of size are set to 0 the height is set such that exactly as many Notifications fit as is the maximum size of the NotificationQueue (in terms of the number of Notifications).
+    */
+    void NotificationQueueCEGUI::setDisplaySize(const Vector4& size)
+    {
+        if(this->displaySize_ == size)
+            return;
+
+        if(size.x < 0.0 || size.x > 1.0 || size.z < 0.0 || size.z > 1.0)
+        {
+            COUT(2) << "The display size of the NotificationQueueCEGUI " << this->getName() << " was trying to be set, but the relative size was not in [0,1]. Aborting..." << endl;
+            return;
+        }
+
+        this->displaySize_ = size;
+        if(size.z == 0.0 && size.w == 0.0)
+            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ")");
+        else
+            GUIManager::getInstance().getLuaState()->doString("NotificationLayer.resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ", " + multi_cast<std::string>(this->displaySize_.z) + ", " + multi_cast<std::string>(this->displaySize_.w) + ")");
+    }
+
+    /**
+    @brief
+        Set the position of the window that displays the NotificationQueue.
+    @param position
+        The position is a vector with components:
+        - The relative x-position of the window. (A value between 0 and 1)
+        - The absolute x-position in pixels. (Additional to the relative x-position, can be negative)
+        - The relative y-position of the window. (A value between 0 and 1)
+        - The absolute y-position in pixels. (Additional to the relative y-position, can be negative.)
+    */
+    void NotificationQueueCEGUI::setPosition(const Vector4& position)
+    {
+        if(this->position_ == position)
+            return;
+
+        if(position.x < 0.0 || position.x > 1.0 || position.z < 0.0 || position.z > 1.0)
+        {
+            COUT(2) << "The position the NotificationQueueCEGUI " << this->getName() << " was trying to be set, but the relative position was not in [0,1]. Aborting..." << endl;
+            return;
+        }
+
+        this->position_ = position;
+        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.moveQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->position_.x) + ", " + multi_cast<std::string>(this->position_.y) + ", " + multi_cast<std::string>(this->position_.z) + ", " + multi_cast<std::string>(this->position_.w) + ")");
+    }
+
+    /**
+    @brief
+        Set the horizontal alignment of the Notifications text.
+    @param alignment
+        The alignment of the Notifications, they are the possible string that the CEGUI Falagard StaticText HorzFormatting property can take.
+    @see http://cegui.org.uk/api_reference/classCEGUI_1_1FalagardStaticTextProperties_1_1HorzFormatting.html
+    */
+    void NotificationQueueCEGUI::setAlignment(const std::string& alignment)
+    {
+        if(this->alignment_ == alignment)
+            return;
+
+        // TODO: Check whether the alignment string is correct?
+        this->alignment_ = alignment;
+        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueAlignment(\"" + this->getName() + "\", \"" + this->alignment_ + "\")");
+    }
+
+    /**
+    @brief
+        Set the font size of the text displayed by this NotificationQueue.
+    @param size
+        The font size.
+    */
+    void NotificationQueueCEGUI::setFontSize(unsigned int size)
+    {
+        if(this->fontSize_ == size)
+            return;
+
+        this->fontSize_ = size;
+        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFontSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->fontSize_) + ")");
+    }
+
+    /**
+    @brief
+        Set the font color if the text displayed by this NotificationQueue.
+    @param color
+        The color is a vector with the components being RGBA and taking values from 0 to 1.
+    */
+    void NotificationQueueCEGUI::setFontColor(const Vector4& color)
+    {
+        if(this->fontColor_ == color)
+            return;
+
+        this->fontColor_ = color;
+        // Convert to ARGB format.
+        std::stringstream stream;
+        for(unsigned int i = 0; i < 4; i++)
+            stream << std::hex << std::setw(2) << std::setfill('0') << int(this->fontColor_[(i+3)%4]*255);
+        this->fontColorStr_ = stream.str();
+        GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changeQueueFontColor(\"" + this->getName() + "\", \"" + this->fontColorStr_ + "\")");
+    }
+
+    /**
+    @brief
+        Get the NotificationQueueCEGUI with the input name.
+    @param name
+        The name of the NotificationQueueCEGUI to be got.
+    @return
+        Returns a pointer to the NotificationQueueCEGUI, or NULL if it doesn't exist.
+    */
+    /*static*/ NotificationQueueCEGUI* NotificationQueueCEGUI::getQueue(const std::string& name)
+    {
+        NotificationQueue* queue = NotificationManager::getInstance().getQueue(name);
+        if(queue == NULL || !queue->isA(Class(NotificationQueueCEGUI)))
+            return NULL;
+        return static_cast<NotificationQueueCEGUI*>(queue);
+    }
+
+    /**
+    @brief
         Is called by the NotificationQueue when a notification was pushed.
     @param notification
         The Notification that was pushed.
@@ -85,7 +221,7 @@
         if(GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
     }
-    
+
     /**
     @brief
         Is called by the NotificationQueue when a notification was popped.
@@ -96,7 +232,7 @@
         if(GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
     }
-    
+
     /**
     @brief Is called when a notification was removed.
     @param index The index the removed notification was at.
@@ -107,7 +243,7 @@
         if(GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
     }
-    
+
     /**
     @brief
         Clears the NotificationQueue by removing all NotificationContainers.
@@ -117,12 +253,12 @@
     void NotificationQueueCEGUI::clear(bool noGraphics)
     {
         NotificationQueue::clear(noGraphics);
-        
+
         // Clear the NotificationQueue in the GUI.
         if(GameMode::showsGraphics() && !noGraphics)
             GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
     }
-    
+
     /**
     @brief
         Creates the NotificationQueue in lua.

Modified: code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.h
===================================================================
--- code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.h	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/src/modules/notifications/NotificationQueueCEGUI.h	2011-05-11 20:45:56 UTC (rev 8448)
@@ -38,27 +38,30 @@
 #include "notifications/NotificationsPrereqs.h"
 
 #include <string>
+#include "util/Math.h"
 
 #include "NotificationManager.h"
+
 #include "NotificationQueue.h"
 
 namespace orxonox // tolua_export
 { // tolua_export
 
-    //TODO: Update.
     /**
     @brief
-        Displays @ref orxonox::Notification "Notifications" from specific senders.
+        Displays @ref orxonox::Notification "Notifications" using CEGUI.
 
-        There are quite some parameters that influence the behavior of the NotificationQueue:
-        - @b name The name of the NotificationQueue. It needs to be unique.
-        - @b senders The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays.
-        - @b size The size of the NotificationQueue, it specifies how many @ref orxonox::Notification "Notifications" are displayed at once at the most.
-        - @b displayTime The time a @ref orxonox::Notification "Notification" is displayed with this NotificationQueue.
+        Apart form the parameters inherited by the @ref orxonox::NotificationQueue "NotificationQueue", there are some more parameters that influence the behavior of the NotificationQueueCEGUI:
+        - @b displaySize The size of the window that displays the NotificationQueue.
+        - @b position The position if the window that displays the NotificationQueue.
+        - @b alignment The horizontal alignment of the displayed Notifications.
+        - @b fontSize The font size of the displayed Notifications.
+        - @b fontColor The font color of the displayed Notifications.
 
     @author
         Damian 'Mozork' Frick
 
+    @see NotificationQueue
     @ingroup Notifications
     */
     class _NotificationsExport NotificationQueueCEGUI // tolua_export
@@ -69,8 +72,61 @@
             NotificationQueueCEGUI(const std::string& name, const std::string& senders = NotificationListener::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);
             virtual ~NotificationQueueCEGUI();
 
-            //! Destroys the NotificationQueue.
-            void destroy(bool noGraphics = false); // tolua_export
+            void destroy(bool noGraphics = false); // Destroys the NotificationQueue.
+
+            /**
+            @brief Set the size of the window that displays the NotificationQueue.
+            @param size A vector whose first component is the relative width of the window (a value between 0 and 1) and whose second component is the absolute width in pixels (additional to the relative width, can be negative). The height is set such that exactly as many Notifications fit as is the maximum size of the NotificationQueue (in terms of the number of Notifications).
+            */
+            inline void setDisplaySize(const Vector2& size)
+                { this->setDisplaySize(Vector4(size.x, size.y, 0.0, 0.0)); }
+            void setDisplaySize(const Vector4& size); // Set the size of the window that displays the NotificationQueue.
+            /**
+            @brief Get the size of the window that displays the NotificationQueue.
+            @return Returns a vector with the display size.
+            */
+            inline const Vector4& getDisplaySize(void) const
+                { return this->displaySize_; }
+
+            void setPosition(const Vector4& position); // Set the position of the window that displays the NotificationQueue.
+            /**
+            @brief Get the position of the window that displays the NotificationQueue.
+            @return Returns a vector with the position.
+            */
+            inline const Vector4& getPosition(void) const
+                { return this->position_; }
+
+            void setAlignment(const std::string& alignment); // Set the horizontal alignment of the Notifications text.
+            /**
+            @brief Get the horizontal alignment of the Notifications text.
+            @return Returns a string with the horizontal alignment property.
+            */
+            inline const std::string& getAlignment(void)
+                { return this->alignment_; }
+
+            void setFontSize(unsigned int size); // Set the font size of the text displayed by this NotificationQueue.
+            /**
+            @brief Get the font size of the text displayed by this NotificationQueue.
+            @return Returns the font size.
+            */
+            inline unsigned int getFontSize(void)
+                { return this->fontSize_; }
+
+            void setFontColor(const Vector4& color); // Set the font color if the text displayed by this NotificationQueue.
+            /**
+            @brief Get the font color of the text displayed by this NotificationQueue.
+            @return Returns a vector with the components being RGBA, with values from 0 to 1.
+            */
+            inline const Vector4& getFontColor(void) const
+                { return this->fontColor_; }
+            /**
+            @brief Get the font color of the text displayed by this NotificationQueue.
+            @return Returns a string with the ARGB values in hexadecimal format.
+            */
+            inline const std::string& getFontColorStr(void) const
+                { return this->fontColorStr_; }
+
+            static NotificationQueueCEGUI* getQueue(const std::string& name); // tolua_export
             
         protected:
             virtual void notificationPushed(Notification* notification); // Is called by the NotificationQueue when a notification was pushed
@@ -80,7 +136,14 @@
             virtual void clear(bool noGraphics = false); // Clears the NotificationQueue by removing all NotificationContainers.
             
         private:
-            void create(void); // Creates the NotificationQueue in lua.            
+            Vector4 displaySize_; //!< The size of the window that displays the NotificationQueue.
+            Vector4 position_; //!< The position of the window that displays the NotificationQueue.
+            std::string alignment_; //!< The horizontal alignment of the Notifications text.
+            unsigned int fontSize_; //!< The font size of the Notifications text.
+            Vector4 fontColor_; //!< The font color of the Notifications text as a vector, in RGBA form, with values from 0 to 1.
+            std::string fontColorStr_; //!< The font color of the Notifications text as a string with the ARGB hexadecimal values.
+            
+            void create(void); // Creates the NotificationQueue in lua.
 
     }; // tolua_export
 

Modified: code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.cc
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.cc	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.cc	2011-05-11 20:45:56 UTC (rev 8448)
@@ -46,6 +46,7 @@
     
     // Commands
     /*static*/ const std::string NotificationListener::COMMAND_CLEAR("clear");
+    /*static*/ const std::string NotificationListener::COMMAND_NONE("none");
     
     registerStaticNetworkFunction(NotificationListener::sendHelper);
     
@@ -107,15 +108,15 @@
         for(ObjectList<NotificationListener>::iterator it = ObjectList<NotificationListener>::begin(); it != ObjectList<NotificationListener>::end(); ++it)
         {
             // If the notification is a message.
-            if(!isCommand && it->registerNotification(message, sender, notificationMessageType::Value(messageType)))
-                COUT(3) << "Notification \"" << message << "\" sent." << std::endl;
+            if(!isCommand)
+                it->registerNotification(message, sender, notificationMessageType::Value(messageType));
 
             // If the notification is a command.
             if(isCommand)
             {
                 notificationCommand::Value command = str2Command(message);
-                if(command != notificationCommand::none && it->executeCommand(command, sender))
-                    COUT(3) << "Command \"" << message << "\" executed." << std::endl;
+                if(command != notificationCommand::none)
+                    it->executeCommand(command, sender);
             }
         }
     }
@@ -137,5 +138,24 @@
 
         return command;
     }
+
+    /**
+    @brief
+        Helper method. Converts a command enum into its corresponding string.
+    @param command
+        The command to be converted.
+    @return
+        Returns the corresponding string.
+    */
+    /*static*/ const std::string& NotificationListener::command2Str(notificationCommand::Value command)
+    {
+        switch(command)
+        {
+            case notificationCommand::clear:
+                return NotificationListener::COMMAND_CLEAR;
+            default:
+                return NotificationListener::COMMAND_NONE;
+        }
+    }
     
 }
\ No newline at end of file

Modified: code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h
===================================================================
--- code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h	2011-05-11 20:44:25 UTC (rev 8447)
+++ code/branches/tutoriallevel2/src/orxonox/interfaces/NotificationListener.h	2011-05-11 20:45:56 UTC (rev 8448)
@@ -107,7 +107,7 @@
                 { NotificationListener::sendNetworkHelper(message, sender, sendMode, clientId, false, messageType); }
             /**
             @brief Sends a specified command to the specified client from the specified sender.
-            @param message The command that should be sent (and later executed).
+            @param command The command that should be sent (and later executed).
             @param sender The sender that sent the notification. Default is 'none'.
             @param sendMode The mode in which the command is sent, can be 'local' to send the command to the client where this function is executed, 'network' if the command is to be sent to the client with the specified clientID, or 'broadcast' if the command should be sent to all hosts. Default is notificationSendMode::local.
             @param clientId The id of the client the command should be sent to. Default is 0.
@@ -137,17 +137,21 @@
             @return Returns true if the command was successfully executed, false if not.
             */
             virtual bool executeCommand(notificationCommand::Value command, const std::string& sender) { return false; }
+
+        public:
             
             static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationQueues.
             static const std::string NONE; //!< Static string to indicate a sender that sends to no specific NotificationQueues.
             
             //! Commands
             static const std::string COMMAND_CLEAR;
+            static const std::string COMMAND_NONE;
             
         protected:
             static void sendNetworkHelper(const std::string& message, const std::string& sender, notificationSendMode::Value sendMode, unsigned int clientId, bool isCommand = false, notificationMessageType::Value messageType = notificationMessageType::info); // Helper method to send both notifications and commands over the network.
-            
+
             static notificationCommand::Value str2Command(const std::string& string); // Helper method. Converts a string into the enum for a command.
+            static const std::string& command2Str(notificationCommand::Value command); // Helper method. Converts a command enum into its corresponding string.
     };
 }
 




More information about the Orxonox-commit mailing list