[Orxonox-commit 2633] r7338 - in code/branches/notifications: data/gui/layouts data/gui/scripts src/libraries/core src/modules/notifications
dafrick at orxonox.net
dafrick at orxonox.net
Fri Sep 3 15:55:32 CEST 2010
Author: dafrick
Date: 2010-09-03 15:55:32 +0200 (Fri, 03 Sep 2010)
New Revision: 7338
Added:
code/branches/notifications/data/gui/layouts/NotificationLayer.layout
code/branches/notifications/data/gui/scripts/NotificationLayer.lua
Removed:
code/branches/notifications/src/modules/notifications/NotificationOverlay.cc
code/branches/notifications/src/modules/notifications/NotificationOverlay.h
Modified:
code/branches/notifications/data/gui/scripts/SheetManager.lua
code/branches/notifications/src/libraries/core/GUIManager.cc
code/branches/notifications/src/libraries/core/GUIManager.h
code/branches/notifications/src/modules/notifications/CMakeLists.txt
code/branches/notifications/src/modules/notifications/Notification.cc
code/branches/notifications/src/modules/notifications/Notification.h
code/branches/notifications/src/modules/notifications/NotificationManager.cc
code/branches/notifications/src/modules/notifications/NotificationManager.h
code/branches/notifications/src/modules/notifications/NotificationQueue.cc
code/branches/notifications/src/modules/notifications/NotificationQueue.h
code/branches/notifications/src/modules/notifications/NotificationsPrereqs.h
Log:
Changing from OrxonoxOverlays to CEGUI as means of displaying Notifications.
Still messy and not working completely but it's a start.
Added: code/branches/notifications/data/gui/layouts/NotificationLayer.layout
===================================================================
--- code/branches/notifications/data/gui/layouts/NotificationLayer.layout (rev 0)
+++ code/branches/notifications/data/gui/layouts/NotificationLayer.layout 2010-09-03 13:55:32 UTC (rev 7338)
@@ -0,0 +1,9 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<GUILayout >
+ <Window Type="DefaultWindow" Name="orxonox/NotificationLayer/Root" >
+ <Property Name="InheritsAlpha" Value="False" />
+ <Property Name="UnifiedMaxSize" Value="{{1,0},{1,0}}" />
+ <Property Name="UnifiedAreaRect" Value="{{0,0},{0,0},{1,0},{1,0}}" />
+ </Window>
+</GUILayout>
Added: code/branches/notifications/data/gui/scripts/NotificationLayer.lua
===================================================================
--- code/branches/notifications/data/gui/scripts/NotificationLayer.lua (rev 0)
+++ code/branches/notifications/data/gui/scripts/NotificationLayer.lua 2010-09-03 13:55:32 UTC (rev 7338)
@@ -0,0 +1,102 @@
+-- NotificationLayer.lua
+
+local P = createMenuSheet("NotificationLayer")
+
+P.queueList = {}
+P.nameList = {}
+
+function P.createQueue(name, size)
+ local root = winMgr:getWindow("orxonox/NotificationLayer/Root")
+ local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name)
+ 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)
+ table.insert(P.queueList, queue)
+ table.insert(P.nameList, name)
+ --TODO: Check name for uniqueness.
+end
+
+function P.removeQueue(name)
+ local queue = nil
+
+ for k,v in pairs(P.nameList) do
+ if v == name then
+ P.nameList[k] = nil
+ queue = P.queueList[k]
+ P.queueList[k] = nil
+ break
+ end
+ end
+
+ if queue ~= nil then
+ winMgr:destroyWindow(queue)
+ end
+end
+
+function P.changePosition(name, xPos, yPos)
+ local queue = P.nameToQueue(name)
+ if queue == nil then
+ cout(0, "Queue is nil!")
+ return
+ end
+ queue:setPosition(CEGUI.UVector2(CEGUI.UDim(tonumber(xPos), 0), CEGUI.UDim(tonumber(yPos), 0)))
+end
+
+function P.pushNotification(queueName, notification)
+ local queue = P.nameToQueue(queueName)
+ if queue == nil then
+ cout(0, "Queue is nil!")
+ return
+ end
+ item = CEGUI.createListboxTextItem(notification)
+ local listbox = CEGUI.toListbox(queue)
+ if listbox:getItemCount() == 0 then
+ listbox:addItem(item)
+ else
+ listbox:insertItem(item, listbox:getListboxItemFromIndex(0))
+ end
+end
+
+function P.popNotification(queueName)
+ local queue = P.nameToQueue(queueName)
+ if queue == nil then
+ cout(0, "Queue is nil!")
+ return
+ end
+ local listbox = CEGUI.toListbox(queue)
+ listbox:removeItem(listbox:getListboxItemFromIndex(listbox:getItemCount()-1))
+end
+
+function P.removeNotification(queueName, index)
+ local queue = P.nameToQueue(queueName)
+ if queue == nil then
+ cout(0, "Queue is nil!")
+ return
+ end
+ local listbox = CEGUI.toListbox(queue)
+ listbox:removeItem(listbox:getListboxItemFromIndex(tonumber(index)))
+end
+
+function P.clearQueue(name)
+ local queue = P.nameToQueue(name)
+ if queue == nil then
+ cout(0, "Queue is nil!")
+ return
+ end
+ local listbox = CEGUI.toListbox(queue)
+ CEGUI.toListbox(queue):resetList()
+end
+
+function P.nameToQueue(name)
+ local queue = nil
+ for k,v in pairs(P.nameList) do
+ if v == name then
+ queue = P.queueList[k]
+ break
+ end
+ end
+ return queue
+end
+
+return P
+
Modified: code/branches/notifications/data/gui/scripts/SheetManager.lua
===================================================================
--- code/branches/notifications/data/gui/scripts/SheetManager.lua 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/data/gui/scripts/SheetManager.lua 2010-09-03 13:55:32 UTC (rev 7338)
@@ -42,14 +42,14 @@
end
-- ?
-function showMenuSheet(name, bHidePrevious, ptr)
- local sheet = showMenuSheet(name, bHidePrevious)
+function showMenuSheet(name, bHidePrevious, bNoInput, ptr)
+ local sheet = showMenuSheet(name, bHidePrevious, bNoInput)
sheet.overlay = ptr
return sheet
end
-- Shows the specified menu sheet and loads it if neccessary
-function showMenuSheet(name, bHidePrevious)
+function showMenuSheet(name, bHidePrevious, bNoInput)
if name == "" then
return nil
end
@@ -62,6 +62,10 @@
assert(bHidePrevious ~= nil)
end
+ if bNoInput == nil then
+ bNoInput = false
+ end
+
-- Pause game control if this is the first menu to be displayed
-- HUGE HACK?
if activeMenuSheets.size == 0 then
@@ -73,11 +77,14 @@
hideMenuSheet(name)
end
+ menuSheet.tShowCursor = TriBool.Dontcare
+
-- Add the sheet in a tuple of additional information
local sheetTuple =
{
["sheet"] = menuSheet,
- ["bHidePrevious"] = bHidePrevious
+ ["bHidePrevious"] = bHidePrevious,
+ ["bNoInput"] = bNoInput
}
table.insert(activeMenuSheets, sheetTuple) -- indexed array access
activeMenuSheets[name] = sheetTuple -- name access
@@ -88,7 +95,9 @@
menuSheetsRoot:addChildWindow(menuSheet.window)
-- Handle input distribution
- inputMgr:enterState(menuSheet.inputState)
+ if bNoInput == false then
+ inputMgr:enterState(menuSheet.inputState)
+ end
-- Only change cursor situation if menuSheet.tShowCursor ~= TriBool.Dontcare
if menuSheet.tShowCursor == TriBool.True then
@@ -147,7 +156,9 @@
activeMenuSheets.topSheetTuple = activeMenuSheets[activeMenuSheets.size]
-- Leave the input state
- inputMgr:leaveState(sheetTuple.sheet.inputState)
+ if not sheetTuple.bNoInput then
+ inputMgr:leaveState(sheetTuple.sheet.inputState)
+ end
-- CURSOR SHOWING
local i = activeMenuSheets.size
@@ -177,10 +188,19 @@
function keyESC()
-- HUGE, very HUGE hacks!
- if activeMenuSheets.size == 1 and activeMenuSheets[1].sheet.name == "MainMenu" then
+
+ -- 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
+
+ -- If the first sheet that needs input is the MainMenu.
+ if counter > 0 and activeMenuSheets.size == counter and activeMenuSheets[counter].sheet.name == "MainMenu" then
orxonox.execute("exit")
- elseif activeMenuSheets.size > 0 then
- orxonox.execute("hideGUI "..activeMenuSheets.topSheetTuple.sheet.name)
+ -- If there is at least one sheet that needs input.
+ elseif counter > 0 then
+ orxonox.execute("hideGUI "..activeMenuSheets[counter].sheet.name)
else
showMenuSheet("InGameMenu")
end
Modified: code/branches/notifications/src/libraries/core/GUIManager.cc
===================================================================
--- code/branches/notifications/src/libraries/core/GUIManager.cc 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/libraries/core/GUIManager.cc 2010-09-03 13:55:32 UTC (rev 7338)
@@ -239,18 +239,18 @@
The function executes the Lua function with the same name in case the GUIManager is ready.
*/
- /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious)
+ /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious, bool bNoInput)
{
- GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ")");
+ GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")");
}
/**
@brief
Hack-ish. Needed for GUIOverlay.
*/
- void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious)
+ void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious, bool bNoInput)
{
- this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + ptr + ")");
+ this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ", " + ptr + ")");
}
/**
Modified: code/branches/notifications/src/libraries/core/GUIManager.h
===================================================================
--- code/branches/notifications/src/libraries/core/GUIManager.h 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/libraries/core/GUIManager.h 2010-09-03 13:55:32 UTC (rev 7338)
@@ -74,8 +74,8 @@
void preUpdate(const Clock& time);
void loadGUI(const std::string& name);
- static void showGUI(const std::string& name, bool bHidePrevious = false);
- void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false);
+ static void showGUI(const std::string& name, bool bHidePrevious = false, bool bNoInput = false);
+ void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false, bool bNoInput = false);
static void hideGUI(const std::string& name);
void keyESC();
void setBackgroundImage(const std::string& imageSet, const std::string imageName); // tolua_export
Modified: code/branches/notifications/src/modules/notifications/CMakeLists.txt
===================================================================
--- code/branches/notifications/src/modules/notifications/CMakeLists.txt 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/CMakeLists.txt 2010-09-03 13:55:32 UTC (rev 7338)
@@ -2,7 +2,6 @@
Notification.cc
NotificationDispatcher.cc
NotificationManager.cc
- NotificationOverlay.cc
NotificationQueue.cc
)
@@ -16,6 +15,5 @@
NotificationsPrecompiledHeaders.h
LINK_LIBRARIES
orxonox
- overlays
SOURCE_FILES ${NOTIFICATIONS_SRC_FILES}
)
Modified: code/branches/notifications/src/modules/notifications/Notification.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/Notification.cc 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/Notification.cc 2010-09-03 13:55:32 UTC (rev 7338)
@@ -93,7 +93,7 @@
{
registerVariable(this->message_);
registerVariable(this->sender_);
- registerVariable(this->sent_);
+ registerVariable(this->sent_, ObjectDirection::Bidirectional);
}
/**
@@ -107,12 +107,19 @@
bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
{
- callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, clientId, sender);
+ if(GameMode::isMaster())
+ {
+ this->sendHelper(sender);
+ }
+ else
+ {
+ callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, sender);
+ }
return true;
}
- bool Notification::sendHelper(unsigned int clientId, const std::string& sender)
+ bool Notification::sendHelper(const std::string& sender)
{
if(this->isSent()) //TODO: Needed?
return false;
Modified: code/branches/notifications/src/modules/notifications/Notification.h
===================================================================
--- code/branches/notifications/src/modules/notifications/Notification.h 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/Notification.h 2010-09-03 13:55:32 UTC (rev 7338)
@@ -57,7 +57,7 @@
virtual ~Notification();
bool send(unsigned int clientId, const std::string & sender); //!< Sends the Notification to the Notificationmanager.
- bool sendHelper(unsigned int clientId, const std::string& sender);
+ bool sendHelper(const std::string& sender);
/**
@brief Checks whether the Notification was sent.
Modified: code/branches/notifications/src/modules/notifications/NotificationManager.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationManager.cc 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/NotificationManager.cc 2010-09-03 13:55:32 UTC (rev 7338)
@@ -39,6 +39,8 @@
#include "core/CoreIncludes.h"
#include "Notification.h"
#include "interfaces/NotificationListener.h"
+#include "core/GUIManager.h"
+#include "NotificationQueue.h"
namespace orxonox
{
@@ -46,7 +48,7 @@
const std::string NotificationManager::ALL("all");
const std::string NotificationManager::NONE("none");
- ManageScopedSingleton(NotificationManager, ScopeID::Root, false);
+ ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false);
/**
@brief
@@ -57,6 +59,11 @@
RegisterRootObject(NotificationManager);
this->highestIndex_ = 0;
+
+ //TODO: What if no graphics?
+ GUIManager::getInstance().loadGUI("NotificationLayer");
+ // Create first queue:
+ NotificationQueue* queue = new NotificationQueue("general");
}
/**
Modified: code/branches/notifications/src/modules/notifications/NotificationManager.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationManager.h 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/NotificationManager.h 2010-09-03 13:55:32 UTC (rev 7338)
@@ -70,15 +70,6 @@
bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe.
/**
- @brief Fetches the Notifications for a specific NotificationListener starting at a specified time.
- @param listener The NotificationListener the Notifications are fetched for.
- @param map A multimap, in which the notifications are stored.
- @param timeFrameStart The start time the Notifications are fetched from.
- @return Returns true if successful.
- */
- bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart)
- { return this->getNotifications(listener, map, timeFrameStart, std::time(0)); }
- /**
@brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now.
@param listener The NotificationListener the Notifications are fetched for.
@param map A multimap, in which the notifications are stored.
Deleted: code/branches/notifications/src/modules/notifications/NotificationOverlay.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationOverlay.cc 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/NotificationOverlay.cc 2010-09-03 13:55:32 UTC (rev 7338)
@@ -1,136 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Damian 'Mozork' Frick
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Implementation of the NotificationOverlay class.
-*/
-
-#include "NotificationOverlay.h"
-
-#include "util/Exception.h"
-#include "core/CoreIncludes.h"
-#include "Notification.h"
-#include "NotificationQueue.h"
-
-namespace orxonox
-{
-
- /**
- @brief
- Constructor. Intializes the class.
- */
- NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator)
- {
- RegisterObject(NotificationOverlay);
- this->initialize();
- }
-
- /**
- @brief
- Constructor. Initializes the class creates a graphical representation of the input Notification for the input Queue.
- @param queue
- A pointer to the queue the NotificatonOverlay belongs to.
- @param notification
- A pointer to the Notification represented by this overlay.
- @throws Argument
- Throws an Argument-Exception if either no Notification or no NotificationQueue were input.
- */
- NotificationOverlay::NotificationOverlay(NotificationQueue* queue, Notification* notification) : OverlayText(NULL)
- {
- this->initialize();
-
- if(notification == NULL || queue == NULL) //!> If either notification or queue are not given an Exception is thrown.
- {
- ThrowException(Argument, "There were NULL-Pointer arguments in NotificationOverlay creation.");
- }
-
- this->queue_ = queue;
- this->defineOverlay();
-
- this->processNotification(notification);
- }
-
- /**
- @brief
- Initializes and Registers the object.
- */
- void NotificationOverlay::initialize(void)
- {
- this->queue_ = NULL;
- }
-
- /**
- @brief
- Set some Overlay-specific values.
- */
- void NotificationOverlay::defineOverlay(void)
- {
- this->setFont(this->queue_->getFont());
- this->setTextSize(this->queue_->getFontSize());
-
- this->setPosition(this->queue_->getPosition());
- }
-
- /**
- @brief
- Destructor.
- */
- NotificationOverlay::~NotificationOverlay()
- {
- }
-
- /**
- @brief
- Processes the input notification, resp. sees to it. that the NotificationOverlay displays the Notification message.
- @param notification
- A pointer to the notification that should be processed.
- @return
- Returns true if successful.
- */
- bool NotificationOverlay::processNotification(Notification* notification)
- {
- if(notification == NULL)
- return false;
- this->setCaption(clipMessage(notification->getMessage()));
- this->notification_ = notification;
- return true;
- }
-
- /**
- @brief
- Clips the input message so that it meets the requirements for the maximal length of Notifications given by the NotificationQueue.
- */
- std::string NotificationOverlay::clipMessage(const std::string & message)
- {
- if(message.length() <= static_cast<unsigned int>(this->queue_->getNotificationLength())) //!< If the message is not too long.
- return message;
- return message.substr(0, this->queue_->getNotificationLength());
- }
-
-}
Deleted: code/branches/notifications/src/modules/notifications/NotificationOverlay.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationOverlay.h 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/NotificationOverlay.h 2010-09-03 13:55:32 UTC (rev 7338)
@@ -1,83 +0,0 @@
-/*
- * ORXONOX - the hottest 3D action shooter ever to exist
- * > www.orxonox.net <
- *
- *
- * License notice:
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * Author:
- * Damian 'Mozork' Frick
- * Co-authors:
- * ...
- *
- */
-
-/**
- @file
- @brief Definition of the NotificationOverlay class.
-*/
-
-
-#ifndef _NotificationOverlay_H__
-#define _NotificationOverlay_H__
-
-#include "notifications/NotificationsPrereqs.h"
-
-#include <string>
-#include "overlays/OverlayText.h"
-
-namespace orxonox
-{
-
- /**
- @brief
- The NotificationOverlay is used to display single Notifications, then bundled in a NotificationQueue.
- @author
- Damian 'Mozork' Frick
- */
- class _NotificationsExport NotificationOverlay : public OverlayText
- {
-
- public:
- NotificationOverlay(BaseObject* creator);
- NotificationOverlay(NotificationQueue* queue, Notification* notification);
- virtual ~NotificationOverlay();
-
- bool processNotification(Notification* notification); //!< Processes the input Notification.
-
- /**
- @brief Sets the font size of this overlay's text.
- @param size The font size.
- */
- inline void setFontSize(float size)
- { this->setTextSize(size); }
-
- protected:
- std::string clipMessage(const std::string & message); //!< Clips the input message if too long.
-
- private:
- NotificationQueue* queue_; //!< The NotificationQeue this overlay belongs to.
- Notification* notification_; //!< The Notification this overlay displays.
-
- void initialize(void); //!< Initializes the object.
- void defineOverlay(void); //!< Sets some overlay-specific values.
-
- };
-
-}
-
-#endif /* _NotificationOverlay_H__ */
Modified: code/branches/notifications/src/modules/notifications/NotificationQueue.cc
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationQueue.cc 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.cc 2010-09-03 13:55:32 UTC (rev 7338)
@@ -36,14 +36,14 @@
#include "util/Convert.h"
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
-#include "NotificationOverlay.h"
-#include "NotificationManager.h"
+#include "Notification.h"
+#include "core/GUIManager.h"
+#include "core/LuaState.h"
+#include <algorithm>
namespace orxonox
{
- CreateFactory(NotificationQueue);
-
const std::string NotificationQueue::DEFAULT_FONT("VeraMono");
const Vector2 NotificationQueue::DEFAULT_POSITION(0.0,0.0);
const float NotificationQueue::DEFAULT_FONT_SIZE = 0.025f;
@@ -52,12 +52,27 @@
@brief
Constructor. Creates and initializes the object.
*/
- NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator)
+ NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, const Vector2& position, unsigned int length, unsigned int displayTime)
{
this->registered_ = false;
- RegisterObject(NotificationQueue);
+ RegisterRootObject(NotificationQueue);
+
this->initialize();
+
+ this->setTargets(senders);
+ this->name_ = name;
+ this->maxSize_ = size;
+ this->position_ = position;
+ this->notificationLength_ = length;
+ this->setDisplayTime(displayTime);
+
+ this->create();
+
+ NotificationManager::getInstance().registerListener(this);
+ this->registered_ = true;
+
+ COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
}
/**
@@ -82,51 +97,20 @@
{
this->size_ = 0;
this->tickTime_ = 0.0;
-
- NotificationManager::getInstance().registerListener(this);
- this->registered_ = true;
}
/**
- @brief
- Sets the defaults.
+ //TODO: Document.
*/
- void NotificationQueue::setDefaults(void)
+ void NotificationQueue::create(void)
{
- this->setMaxSize(DEFAULT_SIZE);
- this->setNotificationLength(DEFAULT_LENGTH);
- this->setDisplayTime(DEFAULT_DISPLAY_TIME);
- this->setPosition(DEFAULT_POSITION);
-
- this->setTargets(NotificationManager::ALL);
-
- this->setFontSize(DEFAULT_FONT_SIZE);
- this->setFont(DEFAULT_FONT);
+ //TODO: Also transfer font and fontsize.
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")");
+ this->positionChanged();
}
/**
@brief
- Method for creating a NotificationQueue object through XML.
- */
- void NotificationQueue::XMLPort(Element& xmlElement, XMLPort::Mode mode)
- {
- SUPER(NotificationQueue, XMLPort, xmlElement, mode);
-
- this->setDefaults();
-
- XMLPortParam(NotificationQueue, "maxSize", setMaxSize, getMaxSize, xmlElement, mode);
- XMLPortParam(NotificationQueue, "notificationLength", setNotificationLength, getNotificationLength, xmlElement, mode);
- XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlElement, mode);
- XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlElement, mode);
- XMLPortParam(NotificationQueue, "font", setFont, getFont, xmlElement, mode);
- XMLPortParam(NotificationQueue, "fontSize", setFontSize, getFontSize, xmlElement, mode);
- XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlElement, mode);
-
- COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl;
- }
-
- /**
- @brief
Updates the queue from time to time.
@param dt
The time interval that has passed since the last tick.
@@ -138,16 +122,15 @@
{
this->timeLimit_.time = std::time(0)-this->displayTime_; //!< Container containig the current time.
- std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
- it = this->containers_.begin();
- while(it != this->containers_.upper_bound(&this->timeLimit_)) //!< Iterate through all elements whose creation time is smaller than the current time minus the display 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.
{
- this->removeContainer(*it);
- this->scroll(Vector2(0.0f,-(1.1f*this->getFontSize())));
- it = this->containers_.begin(); //TODO: Needed?
+ NotificationContainer* temp = *it;
+ it++;
+ this->remove(temp);
}
- this->tickTime_ = 0.0f; //!< Reset time counter.
+ this->tickTime_ = this->tickTime_ - (int)this->tickTime_; //!< Reset time counter.
}
}
@@ -160,7 +143,7 @@
{
this->clear();
- std::multimap<std::time_t,Notification*>* notifications = new std::multimap<std::time_t,Notification*>;
+ 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.
{
COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl;
@@ -170,10 +153,8 @@
if(notifications->empty())
return;
- for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications.
- {
- this->addNotification(it->second, it->first);
- }
+ 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;
@@ -190,17 +171,24 @@
*/
void NotificationQueue::update(Notification* notification, const std::time_t & time)
{
- this->addNotification(notification, time);
+ this->push(notification, time);
- std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
- while(this->getSize() > this->getMaxSize())
- {
- it = this->containers_.begin();
- this->removeContainer(*it);
- this->scroll(Vector2(0.0f,-(1.1f*this->getFontSize())));
- }
+ COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl;
+ }
- COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notifications has been added." << std::endl;
+ /**
+ @brief
+ Sets the name of the NotificationQueue.
+ @param name
+ The name to be set.
+ @return
+ returns true if successful.
+ */
+ bool NotificationQueue::setName(const std::string& name)
+ {
+ //TODO: Test uniqueness of name.
+ this->name_ = name;
+ return true;
}
/**
@@ -211,13 +199,10 @@
@return
Returns true if successful.
*/
- bool NotificationQueue::setMaxSize(int size)
+ void NotificationQueue::setMaxSize(unsigned int size)
{
- if(size < 0)
- return false;
this->maxSize_ = size;
this->update();
- return true;
}
/**
@@ -228,13 +213,10 @@
@return
Returns true if successful.
*/
- bool NotificationQueue::setNotificationLength(int length)
+ void NotificationQueue::setNotificationLength(unsigned int length)
{
- if(length < 0)
- return false;
this->notificationLength_ = length;
this->update();
- return true;
}
/**
@@ -245,13 +227,10 @@
@return
Returns true if successful.
*/
- bool NotificationQueue::setDisplayTime(int time)
+ void NotificationQueue::setDisplayTime(unsigned int time)
{
- if(time < 0)
- return false;
this->displayTime_ = time;
this->update();
- return true;
}
/**
@@ -329,11 +308,7 @@
{
if(size <= 0)
return false;
- this->fontSize_ = size;
- for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font size for each overlay.
- {
- it->second->overlay->setFontSize(size);
- }
+
return true;
}
@@ -347,95 +322,76 @@
*/
bool NotificationQueue::setFont(const std::string & font)
{
- this->font_ = font;
- for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font for each overlay.
- {
- it->second->overlay->setFont(font);
- }
+
return true;
}
/**
@brief
- Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
- @param pos
- The vector the NotificationQueue is scrolled.
- */
- void NotificationQueue::scroll(const Vector2 pos)
- {
- for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Scroll each overlay.
- {
- it->second->overlay->scroll(pos);
- }
- }
-
- /**
- @brief
Aligns all the Notifications to the position of the NotificationQueue.
*/
void NotificationQueue::positionChanged(void)
{
- int counter = 0;
- for (std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); it != this->containers_.end(); it++) //!< Set the position for each overlay.
- {
- (*it)->overlay->setPosition(this->getPosition());
- (*it)->overlay->scroll(Vector2(0.0f,(1.1f*this->getFontSize())*counter));
- counter++;
- }
+ 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 an corresponding overlay and a container.
+ 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::addNotification(Notification* notification, const std::time_t & time)
+ void NotificationQueue::push(Notification* notification, const std::time_t & time)
{
- NotificationOverlayContainer* container = new NotificationOverlayContainer;
- container->overlay = new NotificationOverlay(this, notification);
+ NotificationContainer* container = new NotificationContainer;
container->notification = notification;
container->time = time;
- std::string timeString = std::ctime(&time);
- timeString.erase(timeString.length()-1);
- const std::string& addressString = multi_cast<std::string>(reinterpret_cast<unsigned long>(notification));
- container->name = "NotificationOverlay(" + timeString + ")&" + addressString;
+
+ // 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->containers_.insert(container);
- this->overlays_[notification] = container;
- this->addElement(container->overlay);
- this->size_= this->size_+1;
+ this->size_++;
- container->overlay->scroll(Vector2(0.0f,(1.1f*this->getFontSize())*(this->getSize()-1)));
+ 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 a container from the queue.
- @param container
- A pointer to the container.
- @return
- Returns true if successful.
+ Removes the least recently added Notification form the NotificationQueue.
*/
- bool NotificationQueue::removeContainer(NotificationOverlayContainer* container)
+ void NotificationQueue::pop(void)
{
- if(this->size_ == 0) //!< You cannot remove anything if the queue is empty.
- return false;
-
- // Unregister the NotificationQueue with the NotificationManager.
- NotificationManager::getInstance().unregisterNotification(container->notification, this);
-
- this->removeElement(container->overlay);
- this->containers_.erase(container);
- this->overlays_.erase(container->notification);
- container->overlay->destroy();
+ NotificationContainer* container = this->notifications_.back();
+ this->ordering_.erase(container);
+ this->notifications_.pop_back();
+ this->size_--;
delete container;
- this->size_= this->size_-1;
+ GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");
+ }
- return true;
+ /**
+ @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) + ")");
}
/**
@@ -444,12 +400,14 @@
*/
void NotificationQueue::clear(void)
{
- std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin();
- while(it != this->containers_.end())
+ this->ordering_.clear();
+ for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)
{
- this->removeContainer(*it);
- it = this->containers_.begin();
+ 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 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/NotificationQueue.h 2010-09-03 13:55:32 UTC (rev 7338)
@@ -40,88 +40,79 @@
#include <map>
#include <set>
#include <string>
+#include <vector>
#include "util/Math.h"
+#include "core/OrxonoxClass.h"
#include "tools/interfaces/Tickable.h"
-#include "overlays/OverlayGroup.h"
#include "interfaces/NotificationListener.h"
+#include "NotificationManager.h"
namespace orxonox
{
//! Container to allow easy handling.
- struct NotificationOverlayContainer
+ struct NotificationContainer
{
- NotificationOverlay* overlay; //!< Pointer to the NotificationOverlay, everything is about.
Notification* notification; //!< The Notification displayed by the overlay.
time_t time; //!< The time the Notification was sent and thus first displayed.
- std::string name; //!< The name of the overlay.
};
//! Struct to allow ordering of NotificationOverlayContainers.
- struct NotificationOverlayContainerCompare {
- bool operator() (const NotificationOverlayContainer* const & a, const NotificationOverlayContainer* const & b) const
+ struct NotificationContainerCompare {
+ bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const
{ return a->time < b->time; } //!< Ordered by time.
};
/**
@brief
Displays Notifications from specific senders.
- Beware! The NotificationQueue is an OverlayGruop and thus cannot be be a sub-element of an OverlayGroup (at least no for now.)
-
- Creating a NotificationQueue through XML goes as follows:
- Be aware that the NotificationQueue must be inside the <Level></Level> tags or bad things will happen.
- <NotificationQueue
- name = "SuperQueue" //Name of your OverlayQueue.
- maxSize = "5" //The maximum number of Notifications displayed. (Default is 5)
- notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 64)
- displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30)
- targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.)
- font = "VeraMono" //The font (Default is VeraMono)
- fontSize = '0.4' //The font size. (Default is 0.025)
- position = "0.0, 0.0" //The position of the NotificationQueue. (Default is 0.0,0.0)
- />
@author
Damian 'Mozork' Frick
*/
- class _NotificationsExport NotificationQueue : public OverlayGroup, public Tickable, public NotificationListener
+ class _NotificationsExport NotificationQueue : public Tickable, public NotificationListener
{
public:
- NotificationQueue(BaseObject* creator);
+ 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);
virtual ~NotificationQueue();
- virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML.
-
virtual void tick(float dt); //!< To update from time to time.
void update(void); //!< Updates the queue.
void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.
/**
+ @brief Get the name of the NotificationQueue.
+ @return Returns the name.
+ */
+ inline const std::string& getName() const
+ { return this->name_; }
+
+ /**
@brief Returns the maximum number of Notifications displayed.
@return Returns maximum size.
*/
- inline int getMaxSize() const
+ inline unsigned int getMaxSize() const
{ return this->maxSize_; }
/**
@brief Returns the current number of Notifications displayed.
@return Returns the size of the queue.
*/
- inline int getSize() const
+ 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 int getNotificationLength() const
+ inline unsigned int getNotificationLength() const
{ return this->notificationLength_; }
/**
@brief Returns the time interval the Notification is displayed.
@return Returns the display time.
*/
- inline int getDisplayTime() const
+ inline float getDisplayTime() const
{ return this->displayTime_; }
/**
@brief Returns the position of the NotificationQueue.
@@ -157,21 +148,21 @@
inline void setPosition(Vector2 pos)
{ this->position_ = pos; this->positionChanged(); }
- void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector.
-
private:
- static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed.
- static const int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed.
- static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
+ 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.
- int maxSize_; //!< The maximal number of Notifications displayed.
- int size_; //!< The number of Notifications displayed.
- int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have.
- int displayTime_; //!< The time a Notification is displayed.
+ std::string name_; //!< The name of the NotificationQueue.
+
+ unsigned int maxSize_; //!< The maximal number of Notifications displayed.
+ unsigned int size_; //!< The number of Notifications displayed.
+ unsigned int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have.
+ unsigned int displayTime_; //!< The time a Notification is displayed.
Vector2 position_; //!< The position of the NotificationQueue.
std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
@@ -179,21 +170,23 @@
float fontSize_; //!< The font size.
std::string font_; //!< The font.
- std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare> containers_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps.
- std::map<Notification*, NotificationOverlayContainer*> overlays_; //!< Mapping notifications to their corresponding overlay containers, for easier association and finding.
+ 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_;
float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick.
- NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
+ NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired.
bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already.
void initialize(void); //!< Initializes the object.
- void setDefaults(void); //!< Helper method to set the default values.
+ void create(void);
- bool setMaxSize(int size); //!< Sets the maximum number of displayed Notifications.
- bool setNotificationLength(int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.
- bool setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed.
+ 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.
@@ -201,8 +194,9 @@
void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
- void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
- bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue.
+ void push(Notification* notification, const std::time_t & time); //!< Add a notification to the queue.
+ void pop(void);
+ void remove(NotificationContainer* container);
void clear(void); //!< Clear the queue.
Modified: code/branches/notifications/src/modules/notifications/NotificationsPrereqs.h
===================================================================
--- code/branches/notifications/src/modules/notifications/NotificationsPrereqs.h 2010-09-03 13:46:21 UTC (rev 7337)
+++ code/branches/notifications/src/modules/notifications/NotificationsPrereqs.h 2010-09-03 13:55:32 UTC (rev 7338)
@@ -67,7 +67,6 @@
class Notification;
class NotificationDispatcher;
class NotificationManager;
- class NotificationOverlay;
class NotificationQueue;
//dispatchers
More information about the Orxonox-commit
mailing list