[Orxonox-commit 2637] r7342 - in code/branches/notifications: data/gui/scripts src/libraries/core src/modules/notifications
dafrick at orxonox.net
dafrick at orxonox.net
Fri Sep 3 21:17:52 CEST 2010
Author: dafrick
Date: 2010-09-03 21:17:51 +0200 (Fri, 03 Sep 2010)
New Revision: 7342
Modified:
code/branches/notifications/data/gui/scripts/NotificationLayer.lua
code/branches/notifications/data/gui/scripts/SheetManager.lua
code/branches/notifications/src/libraries/core/GUIManager.cc
code/branches/notifications/src/modules/notifications/NotificationQueue.cc
code/branches/notifications/src/modules/notifications/NotificationQueue.h
Log:
Some documenting, cleaning up. Also: Now the NotificationQueue has a height corresponding to its input size.
Modified: code/branches/notifications/data/gui/scripts/NotificationLayer.lua
===================================================================
--- code/branches/notifications/data/gui/scripts/NotificationLayer.lua 2010-09-03 14:53:51 UTC (rev 7341)
+++ code/branches/notifications/data/gui/scripts/NotificationLayer.lua 2010-09-03 19:17:51 UTC (rev 7342)
@@ -8,9 +8,11 @@
function P.createQueue(name, size)
local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
+ root:addChildWindow(queue)
+
queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0)))
- queue:setSize(CEGUI.UVector2(CEGUI.UDim(1, 0), CEGUI.UDim(0.2, 0)))
- root:addChildWindow(queue)
+ queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size))))
+
table.insert(P.queueList, queue)
table.insert(P.nameList, name)
--TODO: Check name for uniqueness.
@@ -34,7 +36,7 @@
end
function P.changePosition(name, xPos, yPos)
- local queue = P.nameToQueue(name)
+ local queue = P.nameToQueueHelper(name)
if queue == nil then
cout(0, "Queue is nil!")
return
@@ -43,7 +45,7 @@
end
function P.pushNotification(queueName, notification)
- local queue = P.nameToQueue(queueName)
+ local queue = P.nameToQueueHelper(queueName)
if queue == nil then
cout(0, "Queue is nil!")
return
@@ -58,7 +60,7 @@
end
function P.popNotification(queueName)
- local queue = P.nameToQueue(queueName)
+ local queue = P.nameToQueueHelper(queueName)
if queue == nil then
cout(0, "Queue is nil!")
return
@@ -68,7 +70,7 @@
end
function P.removeNotification(queueName, index)
- local queue = P.nameToQueue(queueName)
+ local queue = P.nameToQueueHelper(queueName)
if queue == nil then
cout(0, "Queue is nil!")
return
@@ -78,7 +80,7 @@
end
function P.clearQueue(name)
- local queue = P.nameToQueue(name)
+ local queue = P.nameToQueueHelper(name)
if queue == nil then
cout(0, "Queue is nil!")
return
@@ -87,7 +89,7 @@
CEGUI.toListbox(queue):resetList()
end
-function P.nameToQueue(name)
+function P.nameToQueueHelper(name)
local queue = nil
for k,v in pairs(P.nameList) do
if v == name then
@@ -98,5 +100,17 @@
return queue
end
+function P.queueHeightHelper(queue, size)
+ local listbox = CEGUI.toListbox(queue)
+ local item = CEGUI.createListboxTextItem("Text")
+ listbox:addItem(item)
+ local singleItemHeight = listbox:getTotalItemsHeight()
+ local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel())
+ local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue)
+ local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight()
+ listbox:removeItem(item)
+ return frameHeight + singleItemHeight*size
+end
+
return P
Modified: code/branches/notifications/data/gui/scripts/SheetManager.lua
===================================================================
--- code/branches/notifications/data/gui/scripts/SheetManager.lua 2010-09-03 14:53:51 UTC (rev 7341)
+++ code/branches/notifications/data/gui/scripts/SheetManager.lua 2010-09-03 19:17:51 UTC (rev 7342)
@@ -68,10 +68,7 @@
end
-- Count the number of sheets that don't need input till the first that does.
- local counter = activeMenuSheets.size
- while counter > 0 and activeMenuSheets[counter].bNoInput do
- counter = counter - 1
- end
+ local counter = noInputSheetCounter()
-- Pause game control if this is the first menu to be displayed
-- HUGE HACK?
if bNoInput == false and counter == 0 then
@@ -181,10 +178,7 @@
end
-- Count the number of sheets that don't need input till the first that does.
- local counter = activeMenuSheets.size
- while counter > 0 and activeMenuSheets[counter].bNoInput do
- counter = counter - 1
- end
+ local counter = noInputSheetCounter()
-- Resume control if the last (non-noInput) menu is hidden
if counter == 0 then
orxonox.HumanController:resumeControl()
@@ -203,10 +197,7 @@
-- HUGE, very HUGE hacks!
-- Count the number of sheets that don't need input till the first that does.
- local counter = activeMenuSheets.size
- while counter > 0 and activeMenuSheets[counter].bNoInput do
- counter = counter - 1
- end
+ local counter = noInputSheetCounter()
-- If the first sheet that needs input is the MainMenu.
if counter == 1 and activeMenuSheets[1].sheet.name == "MainMenu" then
@@ -223,6 +214,15 @@
guiMgr:setBackgroundImage(imageSet, imageName)
end
+function noInputSheetCounter()
+ -- Count the number of sheets that don't need input till the first that does.
+ local counter = activeMenuSheets.size
+ while counter > 0 and activeMenuSheets[counter].bNoInput do
+ counter = counter - 1
+ end
+ return counter
+end
+
----------------------
--- Initialisation ---
----------------------
Modified: code/branches/notifications/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/notifications/src/libraries/core/GUIManager.cc 2010-09-03 14:53:51 UTC (rev 7341)
+++ code/branches/notifications/src/libraries/core/GUIManager.cc 2010-09-03 19:17:51 UTC (rev 7342)
@@ -236,6 +236,8 @@
Displays specified GUI on screen
@param name
The name of the GUI
+ @param bNoInput
+ If true the GUI is transparent to input.
The function executes the Lua function with the same name in case the GUIManager is ready.
*/
Modified: code/branches/notifications/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationQueue.cc 2010-09-03 14:53:51 UTC (rev 7341)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.cc 2010-09-03 19:17:51 UTC (rev 7342)
@@ -27,32 +27,30 @@
*/
/**
- @file
+ @file NotificationQueue.cc
@brief Implementation of the NotificationQueue class.
*/
#include "NotificationQueue.h"
+#include <algorithm>
+
#include "util/Convert.h"
#include "core/CoreIncludes.h"
-#include "core/XMLPort.h"
-#include "Notification.h"
#include "core/GUIManager.h"
#include "core/LuaState.h"
-#include <algorithm>
+#include "Notification.h"
namespace orxonox
{
- const std::string NotificationQueue::DEFAULT_FONT("VeraMono");
const Vector2 NotificationQueue::DEFAULT_POSITION(0.0,0.0);
- const float NotificationQueue::DEFAULT_FONT_SIZE = 0.025f;
/**
@brief
Constructor. Creates and initializes the object.
*/
- NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, const Vector2& position, unsigned int length, unsigned int displayTime)
+ NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, const Vector2& position, unsigned int displayTime)
{
this->registered_ = false;
@@ -64,10 +62,10 @@
this->name_ = name;
this->maxSize_ = size;
this->position_ = position;
- this->notificationLength_ = length;
this->setDisplayTime(displayTime);
this->create();
+ this->positionChanged();
NotificationManager::getInstance().registerListener(this);
this->registered_ = true;
@@ -100,13 +98,12 @@
}
/**
- //TODO: Document.
+ @brief
+ Creates the NotificationQueue in lua.
*/
void NotificationQueue::create(void)
{
- //TODO: Also transfer font and fontsize.
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
- this->positionChanged();
}
/**
@@ -117,34 +114,34 @@
*/
void NotificationQueue::tick(float dt)
{
- this->tickTime_ += dt; //!< Add the time interval that has passed to the time counter.
- 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.
+ this->tickTime_ += dt; // Add the time interval that has passed to the time counter.
+ 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.
{
- this->timeLimit_.time = std::time(0)-this->displayTime_; //!< Container containig the current time.
+ this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time.
std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin();
- 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.
+ 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.
{
NotificationContainer* temp = *it;
it++;
this->remove(temp);
}
- this->tickTime_ = this->tickTime_ - (int)this->tickTime_; //!< Reset time counter.
+ this->tickTime_ = this->tickTime_ - (int)this->tickTime_; // Reset time counter.
}
}
/**
@brief
Updates the NotificationQueue.
- Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting the in the queue.
+ Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue.
*/
void NotificationQueue::update(void)
{
this->clear();
std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>;
- if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) //!< Get the Notifications sent in the interval form now to minus the display time.
+ if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) // Get the Notifications sent in the interval form now to minus the display time.
{
COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl;
return;
@@ -153,7 +150,7 @@
if(notifications->empty())
return;
- for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications.
+ for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications.
this->push(it->second, it->first);
delete notifications;
@@ -178,6 +175,80 @@
/**
@brief
+ Adds a Notification, to the queue.
+ It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI.
+ @param notification
+ The Notification.
+ @param time
+ The time.
+ */
+ void NotificationQueue::push(Notification* notification, const std::time_t & time)
+ {
+ NotificationContainer* container = new NotificationContainer;
+ container->notification = notification;
+ container->time = time;
+
+ // If the maximum size of the NotificationQueue has been reached the last (least recently added) Notification is removed.
+ if(this->getSize() >= this->getMaxSize())
+ this->pop();
+
+ this->size_++;
+
+ this->ordering_.insert(container);
+ this->notifications_.insert(this->notifications_.begin(), container);
+
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
+ }
+
+ /**
+ @brief
+ Removes the least recently added Notification form the NotificationQueue.
+ */
+ void NotificationQueue::pop(void)
+ {
+ NotificationContainer* container = this->notifications_.back();
+ this->ordering_.erase(container);
+ this->notifications_.pop_back();
+ this->size_--;
+ delete container;
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
+ }
+
+ /**
+ @brief
+ Removes the Notification that is stored in the input container.
+ @param container
+ The NotificationContainer with the Notification to be removed.
+ */
+ void NotificationQueue::remove(NotificationContainer* container)
+ {
+ std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container);
+ std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin ();
+ this->ordering_.erase(container);
+ this->notifications_.erase(it);
+ this->size_--;
+ delete container;
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
+ }
+
+ /**
+ @brief
+ Clears the queue by removing all containers.
+ */
+ void NotificationQueue::clear(void)
+ {
+ this->ordering_.clear();
+ for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)
+ {
+ delete *it;
+ }
+ this->notifications_.clear();
+ this->size_ = 0;
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
+ }
+
+ /**
+ @brief
Sets the name of the NotificationQueue.
@param name
The name to be set.
@@ -207,20 +278,6 @@
/**
@brief
- Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
- @param length
- The length to be set.
- @return
- Returns true if successful.
- */
- void NotificationQueue::setNotificationLength(unsigned int length)
- {
- this->notificationLength_ = length;
- this->update();
- }
-
- /**
- @brief
Sets the maximum number of seconds a Notification is displayed.
@param time
The number of seconds the Notifications is displayed.
@@ -298,36 +355,6 @@
/**
@brief
- Sets the font size.
- @param size
- The font size.
- @return
- Returns true if successful.
- */
- bool NotificationQueue::setFontSize(float size)
- {
- if(size <= 0)
- return false;
-
- return true;
- }
-
- /**
- @brief
- Sets the font.
- @param font
- The font.
- @return
- Returns true if successful.
- */
- bool NotificationQueue::setFont(const std::string & font)
- {
-
- return true;
- }
-
- /**
- @brief
Aligns all the Notifications to the position of the NotificationQueue.
*/
void NotificationQueue::positionChanged(void)
@@ -335,79 +362,4 @@
GUIManager::getInstance().getLuaState()->doString("NotificationLayer.changePosition(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getPosition().x) + ", " + multi_cast<std::string>(this->getPosition().y) + ")");
}
- /**
- @brief
- Adds a Notification, to the queue.
- It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI.
- @param notification
- The Notification.
- @param time
- The time.
- */
- void NotificationQueue::push(Notification* notification, const std::time_t & time)
- {
- NotificationContainer* container = new NotificationContainer;
- container->notification = notification;
- container->time = time;
-
- // If the maximum size of the NotificationQueue has been reached the last (least recently added) Notification is removed.
- if(this->getSize() >= this->getMaxSize())
- this->pop();
-
- this->size_++;
-
- this->ordering_.insert(container);
- this->notifications_.insert(this->notifications_.begin(), container);
-
- //TODO: Clip message if necessary.
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");
- }
-
- /**
- @brief
- Removes the least recently added Notification form the NotificationQueue.
- */
- void NotificationQueue::pop(void)
- {
- NotificationContainer* container = this->notifications_.back();
- this->ordering_.erase(container);
- this->notifications_.pop_back();
- this->size_--;
- delete container;
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
- }
-
- /**
- @brief
- Removes the Notification that is stored in the input container.
- @param container
- The NotificationContainer with the Notification to be removed.
- */
- void NotificationQueue::remove(NotificationContainer* container)
- {
- std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container);
- std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin ();
- this->ordering_.erase(container);
- this->notifications_.erase(it);
- this->size_--;
- delete container;
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");
- }
-
- /**
- @brief
- Clears the queue by removing all containers.
- */
- void NotificationQueue::clear(void)
- {
- this->ordering_.clear();
- for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)
- {
- delete *it;
- }
- this->notifications_.clear();
- this->size_ = 0;
- GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");
- }
-
}
Modified: code/branches/notifications/src/modules/notifications/NotificationQueue.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationQueue.h 2010-09-03 14:53:51 UTC (rev 7341)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.h 2010-09-03 19:17:51 UTC (rev 7342)
@@ -75,7 +75,7 @@
{
public:
- 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);
+ 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);
virtual ~NotificationQueue();
virtual void tick(float dt); //!< To update from time to time.
@@ -103,12 +103,6 @@
inline unsigned int getSize() const
{ return this->size_; }
/**
- @brief Returns the maximum length in characters a Notification message is allowed to have.
- @return Returns the maximum Notification length.
- */
- inline unsigned int getNotificationLength() const
- { return this->notificationLength_; }
- /**
@brief Returns the time interval the Notification is displayed.
@return Returns the display time.
*/
@@ -120,18 +114,6 @@
*/
inline const Vector2 & getPosition() const
{ return this->position_; }
- /**
- @brief Returns the font size used to display the Notifications.
- @return Returns the font size.
- */
- inline float getFontSize() const
- { return this->fontSize_; }
- /**
- @brief Returns the font used to display the Notifications.
- @return Returns the font.
- */
- inline const std::string & getFont() const
- { return this->font_; }
/**
@brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.
@@ -150,11 +132,8 @@
private:
static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
- static const unsigned int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed.
static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
- static const float DEFAULT_FONT_SIZE; //!< The default font size.
- static const std::string DEFAULT_FONT; //!< The default font.
static const Vector2 DEFAULT_POSITION; //!< the default position.
std::string name_; //!< The name of the NotificationQueue.
@@ -167,9 +146,6 @@
std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
- float fontSize_; //!< The font size.
- std::string font_; //!< The font.
-
std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. //TODO: Would set work as well?
std::vector<NotificationContainer*> notifications_;
@@ -184,14 +160,10 @@
bool setName(const std::string& name); //!< Sets the name of the NotificationQueue.
void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications.
- void setNotificationLength(unsigned int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed.
bool setTargets(const std::string & targets); //!< Set the targets of this queue.
- bool setFontSize(float size); //!< Set the font size.
- bool setFont(const std::string & font); //!< Set the font.
-
void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
void push(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
More information about the Orxonox-commit
mailing list