[Orxonox-commit 3988] r8662 - code/branches/presentation/src/modules/notifications

dafrick at orxonox.net dafrick at orxonox.net
Sun May 29 17:24:04 CEST 2011


Author: dafrick
Date: 2011-05-29 17:24:04 +0200 (Sun, 29 May 2011)
New Revision: 8662

Modified:
   code/branches/presentation/src/modules/notifications/NotificationQueue.cc
   code/branches/presentation/src/modules/notifications/NotificationQueue.h
   code/branches/presentation/src/modules/notifications/NotificationQueueCEGUI.cc
   code/branches/presentation/src/modules/notifications/NotificationQueueCEGUI.h
Log:
Anotehr step towards networked notifications.


Modified: code/branches/presentation/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/presentation/src/modules/notifications/NotificationQueue.cc	2011-05-29 15:01:53 UTC (rev 8661)
+++ code/branches/presentation/src/modules/notifications/NotificationQueue.cc	2011-05-29 15:24:04 UTC (rev 8662)
@@ -55,7 +55,13 @@
     {
         RegisterObject(NotificationQueue);
 
-        this->initialize();
+        this->size_ = 0;
+        this->tickTime_ = 0.0f;
+        this->maxSize_ = NotificationQueue::DEFAULT_SIZE;
+        this->displayTime_ = NotificationQueue::DEFAULT_DISPLAY_TIME;
+
+        this->creationTime_ = std::time(0);
+        
         this->registerVariables();
     }
 
@@ -95,16 +101,21 @@
 
     /**
     @brief
-        Initializes the NotificationQueue.
+        Is called when the name of the NotificationQueue has changed.
+        Clears and re-creates the NotificationQueue.
     */
-    void NotificationQueue::initialize(void)
+    void NotificationQueue::changedName(void)
     {
-        this->size_ = 0;
-        this->tickTime_ = 0.0f;
-        this->maxSize_ = NotificationQueue::DEFAULT_SIZE;
-        this->displayTime_ = NotificationQueue::DEFAULT_DISPLAY_TIME;
+        SUPER(NotificationQueue, changedName);
 
-        this->creationTime_ = std::time(0);
+        if(this->isRegistered())
+            this->clear();
+            
+        this->create();
+
+        this->targetsChanged();
+        this->maxSizeChanged();
+        this->displayTimeChanged();
     }
 
     /**
@@ -158,8 +169,6 @@
         XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlelement, mode).defaultValues(NotificationListener::ALL);
         XMLPortParam(NotificationQueue, "size", setMaxSize, getMaxSize, xmlelement, mode);
         XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlelement, mode);
-
-        this->create();
     }
     
     

Modified: code/branches/presentation/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/branches/presentation/src/modules/notifications/NotificationQueue.h	2011-05-29 15:01:53 UTC (rev 8661)
+++ code/branches/presentation/src/modules/notifications/NotificationQueue.h	2011-05-29 15:24:04 UTC (rev 8662)
@@ -98,7 +98,8 @@
 
             virtual void tick(float dt); // To update from time to time.
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            void registerVariables();
+
+            virtual void changedName(void);
             
             void update(void); // Updates the NotificationQueue.
             void update(Notification* notification, const std::time_t & time); // Updates the NotificationQueue by adding an new Notification.
@@ -158,6 +159,8 @@
             bool tidy(void); // Pops all Notifications from the NotificationQueue.
             
         protected:
+            void registerVariables();
+            
             /**
             @brief Is called when a notification was pushed.
             @param notification The Notification that was pushed.
@@ -183,9 +186,7 @@
             virtual void create(void); // Creates the NotificationQueue.
 
         private:
-            void initialize(void); // Initializes the NotificationQueue.
-
-            time_t creationTime_; // The time this NotificationQueue was created.
+            time_t creationTime_; //!< The time this NotificationQueue was created.
             
             unsigned int maxSize_; //!< The maximal number of Notifications displayed.
             unsigned int size_; //!< The number of Notifications displayed.

Modified: code/branches/presentation/src/modules/notifications/NotificationQueueCEGUI.cc
===================================================================
--- code/branches/presentation/src/modules/notifications/NotificationQueueCEGUI.cc	2011-05-29 15:01:53 UTC (rev 8661)
+++ code/branches/presentation/src/modules/notifications/NotificationQueueCEGUI.cc	2011-05-29 15:24:04 UTC (rev 8662)
@@ -64,7 +64,7 @@
     
     NotificationQueueCEGUI::~NotificationQueueCEGUI()
     {
-        if(GameMode::showsGraphics())
+        if(this->isRegistered() && GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() +  "\")");
     }
 
@@ -102,6 +102,17 @@
         registerVariable( this->displaySize_, VariableDirection::ToClient, new NetworkCallback<NotificationQueueCEGUI>(this, &NotificationQueueCEGUI::displaySizeChanged));
     }
 
+    void NotificationQueueCEGUI::changedName(void)
+    {
+        SUPER(NotificationQueueCEGUI, changedName);
+
+        this->positionChanged();
+        this->fontSizeChanged();
+        this->fontColorChanged();
+        this->alignmentChanged();
+        this->displaySizeChanged();
+    }
+
     /**
     @brief
         Destroys the NotificationQueueCEGUI.
@@ -112,7 +123,7 @@
     void NotificationQueueCEGUI::destroy(bool noGraphics)
     {
         // Remove the NotificationQueue in lua.
-        if(GameMode::showsGraphics() && !noGraphics)
+        if(this->isRegistered() && GameMode::showsGraphics() && !noGraphics)
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() +  "\")");
 
         NotificationQueue::destroy();
@@ -150,7 +161,7 @@
     */
     void NotificationQueueCEGUI::displaySizeChanged(void)
     {
-        if(GameMode::showsGraphics())
+        if(this->isRegistered() && GameMode::showsGraphics())
         {
             if(this->displaySize_.z == 0.0 && this->displaySize_.w == 0.0)
                 GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".resizeQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->displaySize_.x) + ", " + multi_cast<std::string>(this->displaySize_.y) + ")");
@@ -190,7 +201,7 @@
     */
     void NotificationQueueCEGUI::positionChanged(void)
     {
-        if(GameMode::showsGraphics())
+        if(this->isRegistered() && GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".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) + ")");
     }
 
@@ -217,7 +228,7 @@
     */
     void NotificationQueueCEGUI::alignmentChanged(void)
     {
-        if(GameMode::showsGraphics())
+        if(this->isRegistered() && GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueAlignment(\"" + this->getName() + "\", \"" + this->alignment_ + "\")");
     }
 
@@ -242,7 +253,7 @@
     */
     void NotificationQueueCEGUI::fontSizeChanged(void)
     {
-        if(GameMode::showsGraphics())
+        if(this->isRegistered() && GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontSize(\"" + this->getName() + "\", " + multi_cast<std::string>(this->fontSize_) + ")");
     }
 
@@ -273,7 +284,7 @@
             stream << std::hex << std::setw(2) << std::setfill('0') << int(this->fontColor_[(i+3)%4]*255);
         this->fontColorStr_ = stream.str();
 
-        if(GameMode::showsGraphics())
+        if(this->isRegistered() && GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".changeQueueFontColor(\"" + this->getName() + "\", \"" + this->fontColorStr_ + "\")");
     }
 
@@ -302,7 +313,7 @@
     void NotificationQueueCEGUI::notificationPushed(Notification* notification)
     {
          // Push the Notification to the GUI.
-        if(GameMode::showsGraphics())
+        if(this->isRegistered() && GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
     }
 
@@ -313,7 +324,7 @@
     void NotificationQueueCEGUI::notificationPopped(void)
     {
         // Pops the Notification from the GUI.
-        if(GameMode::showsGraphics())
+        if(this->isRegistered() && GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".popNotification(\"" + this->getName() + "\")");
     }
 
@@ -324,7 +335,7 @@
     void NotificationQueueCEGUI::notificationRemoved(unsigned int index)
     {
         // Removes the Notification from the GUI.
-        if(GameMode::showsGraphics())
+        if(this->isRegistered() && GameMode::showsGraphics())
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
     }
 
@@ -339,7 +350,7 @@
         NotificationQueue::clear(noGraphics);
 
         // Clear the NotificationQueue in the GUI.
-        if(GameMode::showsGraphics() && !noGraphics)
+        if(this->isRegistered() && GameMode::showsGraphics() && !noGraphics)
             GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".clearQueue(\"" + this->getName() + "\")");
     }
 
@@ -349,6 +360,9 @@
     */
     void NotificationQueueCEGUI::create(void)
     {
+        if(this->isRegistered() && GameMode::showsGraphics())
+            GUIManager::getInstance().getLuaState()->doString(NotificationQueueCEGUI::NOTIFICATION_LAYER + ".removeQueue(\"" + this->getName() +  "\")");
+        
         this->NotificationQueue::create();
         
         if(this->isRegistered() && GameMode::showsGraphics())

Modified: code/branches/presentation/src/modules/notifications/NotificationQueueCEGUI.h
===================================================================
--- code/branches/presentation/src/modules/notifications/NotificationQueueCEGUI.h	2011-05-29 15:01:53 UTC (rev 8661)
+++ code/branches/presentation/src/modules/notifications/NotificationQueueCEGUI.h	2011-05-29 15:24:04 UTC (rev 8662)
@@ -73,8 +73,9 @@
             virtual ~NotificationQueueCEGUI();
 
             virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode);
-            void registerVariables();
 
+            virtual void changedName(void);
+
             void destroy(bool noGraphics = false); // Destroys the NotificationQueue.
 
             void setDisplaySize(const Vector4& size); // Set the size of the window that displays the NotificationQueue.
@@ -132,6 +133,8 @@
             static NotificationQueueCEGUI* getQueue(const std::string& name); // tolua_export // Get the NotificationQueueCEGUI with the input name.
             
         protected:
+            void registerVariables();
+            
             virtual void create(void); // Creates the NotificationQueue in lua.
             
             virtual void notificationPushed(Notification* notification); // Is called by the NotificationQueue when a Notification was pushed




More information about the Orxonox-commit mailing list