[Orxonox-commit 2486] r7193 - in code/trunk: data/levels src/modules/notifications src/modules/notifications/dispatchers
dafrick at orxonox.net
dafrick at orxonox.net
Fri Aug 20 21:55:50 CEST 2010
Author: dafrick
Date: 2010-08-20 21:55:50 +0200 (Fri, 20 Aug 2010)
New Revision: 7193
Added:
code/trunk/src/modules/notifications/NotificationDispatcher.cc
code/trunk/src/modules/notifications/NotificationDispatcher.h
code/trunk/src/modules/notifications/dispatchers/
code/trunk/src/modules/notifications/dispatchers/CMakeLists.txt
code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc
code/trunk/src/modules/notifications/dispatchers/CommandNotification.h
Modified:
code/trunk/data/levels/tutorial.oxw
code/trunk/src/modules/notifications/CMakeLists.txt
code/trunk/src/modules/notifications/Notification.cc
code/trunk/src/modules/notifications/NotificationsPrereqs.h
Log:
Added NotificationDispatcher, class that can, upon being triggered, dispatch (send/display) a specified Notification.
Additionally a NotificationDispatcher called CommandNotification, that, upon being triggered, displays a Notification with a message and the name of the key that the command is mapped to. It is envisioned to be used in the, soon to be, tutorial level.
Also: Small bugfix in Notification.
Modified: code/trunk/data/levels/tutorial.oxw
===================================================================
--- code/trunk/data/levels/tutorial.oxw 2010-08-20 00:59:20 UTC (rev 7192)
+++ code/trunk/data/levels/tutorial.oxw 2010-08-20 19:55:50 UTC (rev 7193)
@@ -13,14 +13,32 @@
<Template link=lodtemplate_default />
</templates>
+ <NotificationQueue
+ name = "notification"
+ position = "0.05, 0.05"
+ font = "VeraMono"
+ textsize = 0.020
+ length = 3
+ width = 50
+ />
+
<Scene
ambientlight = "0.5, 0.5, 0.5"
skybox = "Orxonox/skypanoramagen1"
>
+ <CommandNotification preMessage="Press '" postMessage="' to fire your primary weapon." command="fire 0">
+ <events>
+ <trigger>
+ <DistanceTrigger name=trigger position="0,0,-100" distance=10 target="Pawn">
+ <attached>
+ <Billboard position="0,0,0" colour="1.0,1.0,0" material="Examples/Flare" />
+ </attached>
+ </DistanceTrigger>
+ </trigger>
+ </events>
+ </CommandNotification>
-
-
<Drone name="meineDrohne" primarythrust="80" auxilarythrust="10" rotationthrust="10" mass= "50" linearDamping = "0.9" angularDamping = "0.7">
<attached>
<Model scale="1" mesh="drone.mesh"/>
Modified: code/trunk/src/modules/notifications/CMakeLists.txt
===================================================================
--- code/trunk/src/modules/notifications/CMakeLists.txt 2010-08-20 00:59:20 UTC (rev 7192)
+++ code/trunk/src/modules/notifications/CMakeLists.txt 2010-08-20 19:55:50 UTC (rev 7193)
@@ -1,10 +1,13 @@
SET_SOURCE_FILES(NOTIFICATIONS_SRC_FILES
Notification.cc
+ NotificationDispatcher.cc
NotificationManager.cc
NotificationOverlay.cc
NotificationQueue.cc
)
+ADD_SUBDIRECTORY(dispatchers)
+
ORXONOX_ADD_LIBRARY(notifications
MODULE
FIND_HEADER_FILES
Modified: code/trunk/src/modules/notifications/Notification.cc
===================================================================
--- code/trunk/src/modules/notifications/Notification.cc 2010-08-20 00:59:20 UTC (rev 7192)
+++ code/trunk/src/modules/notifications/Notification.cc 2010-08-20 19:55:50 UTC (rev 7193)
@@ -59,6 +59,8 @@
*/
Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator)
{
+ RegisterObject(Notification);
+ this->initialize();
this->message_ = message;
}
@@ -103,6 +105,9 @@
*/
bool Notification::send(const std::string & sender)
{
+ if(this->isSent()) //TODO: Needed?
+ return false;
+
this->sender_ = sender;
bool successful = NotificationManager::getInstance().registerNotification(this);
if(!successful)
Added: code/trunk/src/modules/notifications/NotificationDispatcher.cc
===================================================================
--- code/trunk/src/modules/notifications/NotificationDispatcher.cc (rev 0)
+++ code/trunk/src/modules/notifications/NotificationDispatcher.cc 2010-08-20 19:55:50 UTC (rev 7193)
@@ -0,0 +1,117 @@
+/*
+ * 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 thes
+ * 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 NotificationDispatcher class.
+*/
+
+#include "NotificationDispatcher.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "core/EventIncludes.h"
+#include "Notification.h"
+#include "NotificationManager.h"
+
+namespace orxonox
+{
+
+ CreateUnloadableFactory(NotificationDispatcher);
+
+ /**
+ @brief
+ Default constructor. Initializes the object.
+ */
+ NotificationDispatcher::NotificationDispatcher(BaseObject* creator) : BaseObject(creator)
+ {
+ RegisterObject(NotificationDispatcher);
+
+ this->sender_ = NotificationManager::NONE;
+ }
+
+ /**
+ @brief
+ Destructor.
+ */
+ NotificationDispatcher::~NotificationDispatcher()
+ {
+
+ }
+
+ /**
+ @brief
+ Method for creating a NotificationDispatcher object through XML.
+ */
+ void NotificationDispatcher::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(NotificationDispatcher, XMLPort, xmlelement, mode);
+
+ XMLPortEventSink(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode); //TODO: Change BaseObject to MultiTrigger as soon as MultiTrigger is the base of all triggers.
+ }
+
+ void NotificationDispatcher::XMLEventPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(NotificationDispatcher, XMLEventPort, xmlelement, mode);
+
+ XMLPortEventState(NotificationDispatcher, BaseObject, "trigger", trigger, xmlelement, mode);
+ }
+
+ /**
+ @brief
+ Dispatches a Notification with a message supplied by the createNotificationMessage() method, which can be overloaded.
+ */
+ void NotificationDispatcher::dispatch(void)
+ {
+ const std::string message = this->createNotificationMessage();
+ Notification* notification = new Notification(this, message);
+
+ notification->send(this->getSender());
+ }
+
+ /**
+ @brief
+ Is called when the NotificationDispatcher is triggered.
+ @param triggered
+ Whether it has been triggered or untriggered. The NotificationDispatcher only reacts to the first kind of events.
+ @return
+ Returns true if the NotificationDispatcher was successfully triggered.
+ */
+ bool NotificationDispatcher::trigger(bool triggered)
+ {
+ if(!triggered || !this->isActive()) // If the NotificationDispatcher is inactive it cannot be executed.
+ return false;
+
+ COUT(4) << "NotificationDispatcher (&" << this << ") triggered." << std::endl;
+
+ this->dispatch();
+
+ return true;
+ }
+
+}
Added: code/trunk/src/modules/notifications/NotificationDispatcher.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationDispatcher.h (rev 0)
+++ code/trunk/src/modules/notifications/NotificationDispatcher.h 2010-08-20 19:55:50 UTC (rev 7193)
@@ -0,0 +1,92 @@
+/*
+ * 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 NotificationDispatcher class.
+*/
+
+#ifndef _NotificationDispatcher_H__
+#define _NotificationDispatcher_H__
+
+#include "notifications/NotificationsPrereqs.h"
+
+#include <string>
+#include "core/BaseObject.h"
+
+namespace orxonox
+{
+
+ /**
+ @brief
+ A NotificationDispatcher is an entity that, upon being triggered, dispatches (or sends) a specified Notification.
+ @author
+ Damian 'Mozork' Frick
+ */
+ class _NotificationsExport NotificationDispatcher : public BaseObject
+ {
+ public:
+ NotificationDispatcher(BaseObject* creator); //!< Default constructor. Initializes the object.
+ virtual ~NotificationDispatcher(); //!< Destructor.
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a NotificationDispatcher object through XML.
+ virtual void XMLEventPort(Element& xmlelement, XMLPort::Mode mode);
+
+ /**
+ @brief Get the sender of the Notification dispatched by this NotificationDispatcher.
+ @return Returns the name of the sender.
+ */
+ const std::string& getSender(void)
+ { return this->sender_; }
+
+ void dispatch(void); //!< Dispatches a specific Notification.
+ bool trigger(bool triggered); //!< Is called when the NotificationDispatcher is triggered.
+
+ protected:
+ std::string sender_; //!< The name of the sender of the Notification dispatched by this NotificationDispatcher.
+
+ /**
+ @brief Set the sender of the Notification dispatched by this NotificationDispatcher.
+ @param sender The name of the sender.
+ */
+ void setSender(const std::string& sender)
+ { this->sender_ = sender; }
+
+ /**
+ @brief Creates the notification message that should be sent upon the NotificationDispatcher triggering.
+ This method can be overloaded to customize the NotificationDispatcher.
+ @return Returns the notification message.
+ */
+ virtual const std::string& createNotificationMessage(void)
+ { return *(new std::string("")); }
+
+ };
+
+}
+
+#endif /* _NotificationDispatcher_H__ */
Modified: code/trunk/src/modules/notifications/NotificationsPrereqs.h
===================================================================
--- code/trunk/src/modules/notifications/NotificationsPrereqs.h 2010-08-20 00:59:20 UTC (rev 7192)
+++ code/trunk/src/modules/notifications/NotificationsPrereqs.h 2010-08-20 19:55:50 UTC (rev 7193)
@@ -65,9 +65,13 @@
namespace orxonox
{
class Notification;
+ class NotificationDispatcher;
class NotificationManager;
class NotificationOverlay;
class NotificationQueue;
+
+ //dispatchers
+ class CommandNotification;
}
#endif /* _NotificationsPrereqs_H__ */
Added: code/trunk/src/modules/notifications/dispatchers/CMakeLists.txt
===================================================================
--- code/trunk/src/modules/notifications/dispatchers/CMakeLists.txt (rev 0)
+++ code/trunk/src/modules/notifications/dispatchers/CMakeLists.txt 2010-08-20 19:55:50 UTC (rev 7193)
@@ -0,0 +1,3 @@
+ADD_SOURCE_FILES(NOTIFICATIONS_SRC_FILES
+ CommandNotification.cc
+)
Added: code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc
===================================================================
--- code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc (rev 0)
+++ code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc 2010-08-20 19:55:50 UTC (rev 7193)
@@ -0,0 +1,97 @@
+/*
+ * 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 CommandNotification class.
+*/
+
+#include "CommandNotification.h"
+
+#include "core/CoreIncludes.h"
+#include "core/XMLPort.h"
+#include "core/input/KeyBinderManager.h"
+#include "core/input/KeyBinder.h"
+
+#include <sstream>
+
+namespace orxonox {
+
+ CreateFactory(CommandNotification);
+
+ /**
+ @brief
+ Default Constructor. Registers the object and initializes variables.
+ */
+ CommandNotification::CommandNotification(BaseObject* creator) : NotificationDispatcher(creator)
+ {
+ RegisterObject(CommandNotification);
+
+ this->setSender("commandNotification");
+ }
+
+ /**
+ @brief
+ Destructor.
+ */
+ CommandNotification::~CommandNotification()
+ {
+
+ }
+
+ /**
+ @brief
+ Method for creating a NotificationDispatcher object through XML.
+ */
+ void CommandNotification::XMLPort(Element& xmlelement, XMLPort::Mode mode)
+ {
+ SUPER(CommandNotification, XMLPort, xmlelement, mode);
+
+ XMLPortParam(CommandNotification, "command", setCommand, getCommand, xmlelement, mode);
+ XMLPortParam(CommandNotification, "preMessage", setPreMessage, getPreMessage, xmlelement, mode);
+ XMLPortParam(CommandNotification, "postMessage", setPostMessage, getPostMessage, xmlelement, mode);
+ }
+
+ /**
+ @brief
+ Composes the Notification of the preMessage the name of the key the command is mapped to and the postMessage.
+ @return
+ Returns the message to be sent in the Notification.
+ */
+ const std::string& CommandNotification::createNotificationMessage(void)
+ {
+ std::stringstream stream;
+ stream << this->getPreMessage();
+ //TODO: Add niceifyer.
+ stream << KeyBinderManager::getInstance().getCurrent()->getBinding(this->getCommand());
+ stream << this->getPostMessage();
+ std::string* message = new std::string(stream.str());
+ return *message;
+ }
+
+}
Added: code/trunk/src/modules/notifications/dispatchers/CommandNotification.h
===================================================================
--- code/trunk/src/modules/notifications/dispatchers/CommandNotification.h (rev 0)
+++ code/trunk/src/modules/notifications/dispatchers/CommandNotification.h 2010-08-20 19:55:50 UTC (rev 7193)
@@ -0,0 +1,110 @@
+/*
+ * 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 CommandNotification class.
+*/
+
+#ifndef _CommandNotification_H__
+#define _CommandNotification_H__
+
+#include "notifications/NotificationsPrereqs.h"
+
+#include "notifications/NotificationDispatcher.h"
+#include <string>
+
+namespace orxonox {
+
+ /**
+ @brief
+ This class implements a method of displaying a Notification with information to an input command and the key the command is mapped to.
+ The message that is displayed is a string made out uf the concatenation of the preMessage, the key the specified command is mapped to and the postMessage.
+ @author
+ Damian 'Mozork' Frick
+ */
+ class _NotificationsExport CommandNotification : public NotificationDispatcher
+ {
+
+ public:
+ CommandNotification(BaseObject* creator); //!< Default Constructor.
+ virtual ~CommandNotification(); //!< Destructor.
+
+ virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a NotificationDispatcher object through XML.
+
+ /**
+ @brief Get the command, whose key is displayed.
+ @return Returns the name of the command.
+ */
+ const std::string& getCommand(void)
+ { return this->command_; }
+ /**
+ @brief Get the preMessage, the first part of the displayed message.
+ @return Returns the preMessage.
+ */
+ const std::string& getPreMessage(void)
+ { return this->preMessage_; }
+ /**
+ @brief Get the postMessage, the last part of the displayed message.
+ @return Returns the postMessage.
+ */
+ const std::string& getPostMessage(void)
+ { return this->postMessage_; }
+
+ protected:
+ virtual const std::string& createNotificationMessage(void); //!< Composes the Notification of the preMessage the name of the key the command is mapped to and the postMessage.
+
+ private:
+ std::string command_; //!< The name of the command.
+ std::string preMessage_; //!< The first part of the displayed message.
+ std::string postMessage_; //!< The last part of the displayed message.
+
+ /**
+ @brief Set the command, whose key is displayed.
+ @param command The name of the command.
+ */
+ void setCommand(const std::string& command)
+ { this->command_ = command; }
+ /**
+ @brief Set the preMessage, the first part of the displayed message.
+ @param message The preMessage.
+ */
+ void setPreMessage(const std::string& message)
+ { this->preMessage_ = message; }
+ /**
+ @brief Set the postMessage, the last part of the displayed message.
+ @param message The postMessage.
+ */
+ void setPostMessage(const std::string& message)
+ { this->postMessage_ = message; }
+
+ };
+
+}
+
+#endif // _CommandNotification_H__
More information about the Orxonox-commit
mailing list