[Orxonox-commit 253] r2909 - in trunk/src: core orxonox orxonox/gamestates orxonox/objects/quest orxonox/overlays orxonox/overlays/notifications
dafrick at orxonox.net
dafrick at orxonox.net
Wed Apr 8 01:07:28 CEST 2009
Author: dafrick
Date: 2009-04-08 01:07:27 +0200 (Wed, 08 Apr 2009)
New Revision: 2909
Added:
trunk/src/core/RootGameState.cc
trunk/src/core/RootGameState.h
trunk/src/orxonox/GraphicsEngine.cc
trunk/src/orxonox/GraphicsEngine.h
trunk/src/orxonox/gamestates/GSGUI.cc
trunk/src/orxonox/gamestates/GSGUI.h
trunk/src/orxonox/objects/quest/QuestNotification.cc
trunk/src/orxonox/objects/quest/QuestNotification.h
trunk/src/orxonox/overlays/notifications/NotificationOverlay.cc
trunk/src/orxonox/overlays/notifications/NotificationOverlay.h
Modified:
trunk/src/orxonox/OrxonoxPrereqs.h
trunk/src/orxonox/gamestates/GSLevel.cc
trunk/src/orxonox/gamestates/GSLevel.h
trunk/src/orxonox/objects/quest/AddQuest.cc
trunk/src/orxonox/objects/quest/AddQuest.h
trunk/src/orxonox/objects/quest/AddQuestHint.cc
trunk/src/orxonox/objects/quest/AddQuestHint.h
trunk/src/orxonox/objects/quest/AddReward.cc
trunk/src/orxonox/objects/quest/AddReward.h
trunk/src/orxonox/objects/quest/CMakeLists.txt
trunk/src/orxonox/objects/quest/ChangeQuestStatus.cc
trunk/src/orxonox/objects/quest/ChangeQuestStatus.h
trunk/src/orxonox/objects/quest/CompleteQuest.cc
trunk/src/orxonox/objects/quest/CompleteQuest.h
trunk/src/orxonox/objects/quest/FailQuest.cc
trunk/src/orxonox/objects/quest/FailQuest.h
trunk/src/orxonox/objects/quest/GlobalQuest.cc
trunk/src/orxonox/objects/quest/GlobalQuest.h
trunk/src/orxonox/objects/quest/LocalQuest.cc
trunk/src/orxonox/objects/quest/LocalQuest.h
trunk/src/orxonox/objects/quest/Quest.cc
trunk/src/orxonox/objects/quest/Quest.h
trunk/src/orxonox/objects/quest/QuestDescription.cc
trunk/src/orxonox/objects/quest/QuestDescription.h
trunk/src/orxonox/objects/quest/QuestEffect.cc
trunk/src/orxonox/objects/quest/QuestEffect.h
trunk/src/orxonox/objects/quest/QuestEffectBeacon.cc
trunk/src/orxonox/objects/quest/QuestEffectBeacon.h
trunk/src/orxonox/objects/quest/QuestHint.cc
trunk/src/orxonox/objects/quest/QuestHint.h
trunk/src/orxonox/objects/quest/QuestItem.cc
trunk/src/orxonox/objects/quest/QuestItem.h
trunk/src/orxonox/objects/quest/QuestListener.cc
trunk/src/orxonox/objects/quest/QuestListener.h
trunk/src/orxonox/objects/quest/QuestManager.cc
trunk/src/orxonox/objects/quest/QuestManager.h
trunk/src/orxonox/objects/quest/Rewardable.cc
trunk/src/orxonox/objects/quest/Rewardable.h
trunk/src/orxonox/overlays/OverlayGroup.cc
trunk/src/orxonox/overlays/OverlayGroup.h
trunk/src/orxonox/overlays/notifications/CMakeLists.txt
trunk/src/orxonox/overlays/notifications/Notification.cc
trunk/src/orxonox/overlays/notifications/Notification.h
trunk/src/orxonox/overlays/notifications/NotificationManager.cc
trunk/src/orxonox/overlays/notifications/NotificationManager.h
trunk/src/orxonox/overlays/notifications/NotificationQueue.cc
trunk/src/orxonox/overlays/notifications/NotificationQueue.h
Log:
Merging the QuestSystem branch to the trunk. Let's hope, this isn't a 'third time's the charm'-thing...
Added: trunk/src/core/RootGameState.cc
===================================================================
--- trunk/src/core/RootGameState.cc (rev 0)
+++ trunk/src/core/RootGameState.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,178 @@
+/*
+ * 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:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "RootGameState.h"
+
+#include "util/Debug.h"
+#include "util/Exception.h"
+#include "Clock.h"
+#include "CommandLine.h"
+
+namespace orxonox
+{
+ SetCommandLineArgument(state, "gui").shortcut("s");
+
+ RootGameState::RootGameState(const std::string& name)
+ : GameState<GameStateBase>(name)
+ , stateRequest_("")
+ {
+ }
+
+ RootGameState::~RootGameState()
+ {
+ }
+
+ /**
+ @brief
+ Internal method that actually makes the state transition. Since it is internal,
+ the method can assume certain things to be granted (like 'this' is always active).
+ */
+ void RootGameState::makeTransition(GameStateBase* source, GameStateBase* destination)
+ {
+ if (source != 0)
+ {
+ // transition was not initiated by root itself
+ this->activeChild_ = 0;
+ }
+
+ if (destination == this)
+ {
+ // this marks the end of the game.
+ return;
+ }
+
+ // Check for 'destination' in the children map first
+ std::map<GameStateBase*, GameStateBase*>::const_iterator it
+ = this->grandchildrenToChildren_.find(destination);
+ if (it != this->grandchildrenToChildren_.end())
+ {
+ OrxAssert(dynamic_cast<GameStateBase*>(it->second) != 0,
+ "There was a mix with RootGameState and GameState, could not cast.");
+ GameStateBase* child = static_cast<GameStateBase*>(it->second);
+ // child state. Don't use 'state', might be a grandchild!
+ this->activeChild_ = child;
+ child->makeTransition(this, destination);
+ }
+ else
+ {
+ // root doesn't have a parent..
+ OrxAssert(false, "GameState '" + destination->getName() + "' not found in children list of Root.");
+ }
+ }
+
+ void RootGameState::gotoState(const std::string& name)
+ {
+ GameStateBase* request = getState(name);
+ if (request)
+ {
+ GameStateBase* current = getCurrentState();
+ if (current)
+ {
+ current->makeTransition(0, request);
+ }
+ else
+ {
+ // Root is not yet active. This is a violation.
+ ThrowException(GameState, "Activate Root before requesting a state.");
+ }
+ }
+ else
+ {
+ COUT(2) << "Warning: GameState '" << name << "' doesn't exist." << std::endl;
+ }
+ }
+
+ /**
+ @brief
+ Makes a state transition according to the state tree. You can choose any state
+ in the tree to do the call. The function finds the current state on its own.
+ @param state
+ The state to be entered, has to exist in the tree.
+ */
+ void RootGameState::requestState(const std::string& name)
+ {
+ this->stateRequest_ = name;
+ }
+
+ /**
+ @brief
+ Main loop of the orxonox game.
+ Starts the game. The little 'while' denotes the main loop.
+ Whenever the root state is selected, the game ends.
+ @param name
+ State to start with (usually main menu or specified by command line)
+ @note
+ We use the Ogre::Timer to measure time since it uses the most precise
+ method an a platform (however the windows timer lacks time when under
+ heavy kernel load!).
+ */
+ void RootGameState::start()
+ {
+ // Don't catch errors when having a debugger in msvc
+#if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG)
+ try
+ {
+#endif
+ // start global orxonox time
+ Clock clock;
+
+ this->activate();
+
+ // get initial state from command line
+ gotoState(CommandLine::getValue("state"));
+
+ while (this->activeChild_)
+ {
+ clock.capture();
+
+ this->tick(clock);
+
+ if (this->stateRequest_ != "")
+ gotoState(stateRequest_);
+ }
+
+ this->deactivate();
+#if !defined(ORXONOX_COMPILER_MSVC) || defined(NDEBUG)
+ }
+ // Note: These are all unhandled exceptions that should not have made its way here!
+ // almost complete game catch block to display the messages appropriately.
+ catch (std::exception& ex)
+ {
+ COUT(0) << ex.what() << std::endl;
+ COUT(0) << "Program aborted." << std::endl;
+ abort();
+ }
+ // anything that doesn't inherit from std::exception
+ catch (...)
+ {
+ COUT(0) << "An unidentifiable exception has occured. Program aborted." << std::endl;
+ abort();
+ }
+#endif
+ }
+}
Added: trunk/src/core/RootGameState.h
===================================================================
--- trunk/src/core/RootGameState.h (rev 0)
+++ trunk/src/core/RootGameState.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,54 @@
+/*
+ * 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:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _RootGameState_H__
+#define _RootGameState_H__
+
+#include "CorePrereqs.h"
+#include "GameState.h"
+
+namespace orxonox
+{
+ class _CoreExport RootGameState : public GameState<GameStateBase>
+ {
+ public:
+ RootGameState(const std::string& name);
+ ~RootGameState();
+
+ void requestState(const std::string& name);
+ void start();
+
+ private:
+ void makeTransition(GameStateBase* source, GameStateBase* destination);
+ void gotoState(const std::string& name);
+
+ std::string stateRequest_;
+ };
+}
+
+#endif /* _RootGameState_H__ */
Added: trunk/src/orxonox/GraphicsEngine.cc
===================================================================
--- trunk/src/orxonox/GraphicsEngine.cc (rev 0)
+++ trunk/src/orxonox/GraphicsEngine.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,106 @@
+/*
+ * 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:
+ * Reto Grieder
+ * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
+ * Co-authors:
+ * Felix Schulthess
+ *
+ */
+
+/**
+ at file
+ at brief
+ Implementation of an partial interface to Ogre.
+*/
+
+#include "OrxonoxStableHeaders.h"
+#include "GraphicsEngine.h"
+
+#include <OgreRenderWindow.h>
+
+#include "core/CoreIncludes.h"
+#include "core/ConfigValueIncludes.h"
+#include "util/Debug.h"
+
+#include "tools/ParticleInterface.h"
+
+namespace orxonox
+{
+ //SetConsoleCommand(GraphicsEngine, printScreen, true).setKeybindMode(KeybindMode::OnPress);
+
+ GraphicsEngine* GraphicsEngine::singletonRef_s = 0;
+
+ /**
+ @brief
+ Returns the singleton instance.
+ @return
+ The only instance of GraphicsEngine.
+ */
+ /*static*/ GraphicsEngine& GraphicsEngine::getInstance()
+ {
+ assert(singletonRef_s);
+ return *singletonRef_s;
+ }
+
+ /**
+ @brief
+ Non-initialising constructor.
+ */
+ GraphicsEngine::GraphicsEngine()
+// : root_(0)
+// , renderWindow_(0)
+// , viewport_(0)
+ {
+ RegisterObject(GraphicsEngine);
+
+ assert(singletonRef_s == 0);
+ singletonRef_s = this;
+
+ this->viewport_ = 0;
+
+ this->detailLevelParticle_ = 0;
+
+ this->setConfigValues();
+ CCOUT(4) << "Constructed" << std::endl;
+ }
+
+ void GraphicsEngine::setConfigValues()
+ {
+ SetConfigValue(detailLevelParticle_, 2).description("O: off, 1: low, 2: normal, 3: high").callback(this, &GraphicsEngine::detailLevelParticleChanged);
+ }
+
+ void GraphicsEngine::detailLevelParticleChanged()
+ {
+ for (ObjectList<ParticleInterface>::iterator it = ObjectList<ParticleInterface>::begin(); it; ++it)
+ it->detailLevelChanged(this->detailLevelParticle_);
+ }
+
+ /**
+ @brief
+ Destroys all the Ogre related objects
+ */
+ GraphicsEngine::~GraphicsEngine()
+ {
+ singletonRef_s = 0;
+ }
+}
Added: trunk/src/orxonox/GraphicsEngine.h
===================================================================
--- trunk/src/orxonox/GraphicsEngine.h (rev 0)
+++ trunk/src/orxonox/GraphicsEngine.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,96 @@
+/*
+ * 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:
+ * Reto Grieder
+ * Benjamin Knecht <beni_at_orxonox.net>, (C) 2007
+ * Co-authors:
+ * Felix Schulthess
+ *
+ */
+
+/**
+ @file
+ @brief Declaration of GraphicsEngine Singleton.
+ @author Benjamin Knecht <beni_at_orxonox.net>
+ */
+
+#ifndef _GraphicsEngine_H__
+#define _GraphicsEngine_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <string>
+
+#include <OgrePrerequisites.h>
+#include "core/OrxonoxClass.h"
+
+namespace orxonox
+{
+ /**
+ @brief Graphics engine manager class
+ */
+ class _OrxonoxExport GraphicsEngine : public OrxonoxClass
+ {
+ // HACK: temporary means
+ friend class GSGraphics;
+
+ public:
+ GraphicsEngine();
+ ~GraphicsEngine();
+
+ void setConfigValues();
+ void detailLevelParticleChanged();
+
+ float getAverageFramesPerSecond() const { return this->avgFramesPerSecond_; }
+ float getAverageTickTime() const { return this->avgTickTime_; }
+ void setAverageTickTime(float tickTime) { this->avgTickTime_ = tickTime; }
+ void setAverageFramesPerSecond(float fps) { this->avgFramesPerSecond_ = fps; }
+
+ inline unsigned int getDetailLevelParticle() const
+ { return this->detailLevelParticle_; }
+
+ static GraphicsEngine& getInstance();
+ static GraphicsEngine* getInstancePtr() { return singletonRef_s; }
+
+ inline void setViewport(Ogre::Viewport* viewport)
+ { this->viewport_ = viewport; }
+ inline Ogre::Viewport* getViewport() const
+ { return this->viewport_; }
+
+ private:
+ // don't mess with singletons
+ GraphicsEngine(GraphicsEngine&);
+
+ Ogre::Viewport* viewport_; //!< default full size viewport
+
+ // stats
+ float avgTickTime_; //!< time in ms to tick() one frame
+ float avgFramesPerSecond_; //!< number of frames processed in one second
+
+ // config values
+ unsigned int detailLevelParticle_; //!< Detail level of particle effects (0: off, 1: low, 2: normal, 3: high)
+
+ static GraphicsEngine* singletonRef_s; //!< Pointer to the Singleton
+ };
+}
+
+#endif /* _GraphicsEngine_H__ */
Modified: trunk/src/orxonox/OrxonoxPrereqs.h
===================================================================
--- trunk/src/orxonox/OrxonoxPrereqs.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/OrxonoxPrereqs.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -128,6 +128,7 @@
class QuestItem;
class QuestListener;
class QuestManager;
+ class QuestNotification;
class Rewardable;
class WorldEntity;
@@ -237,6 +238,7 @@
class InGameConsole;
class Notification;
class NotificationManager;
+ class NotificationOverlay;
class NotificationQueue;
class OrxonoxOverlay;
class OverlayGroup;
Added: trunk/src/orxonox/gamestates/GSGUI.cc
===================================================================
--- trunk/src/orxonox/gamestates/GSGUI.cc (rev 0)
+++ trunk/src/orxonox/gamestates/GSGUI.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,69 @@
+/*
+ * 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:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "GSGUI.h"
+
+#include <OgreViewport.h>
+#include "core/input/InputManager.h"
+#include "core/input/SimpleInputState.h"
+#include "gui/GUIManager.h"
+
+namespace orxonox
+{
+ GSGUI::GSGUI()
+ : GameState<GSGraphics>("gui")
+ {
+ }
+
+ GSGUI::~GSGUI()
+ {
+ }
+
+ void GSGUI::enter()
+ {
+ guiManager_ = getParent()->getGUIManager();
+
+ // show main menu
+ guiManager_->showGUI("MainMenu", 0);
+ getParent()->getViewport()->setCamera(guiManager_->getCamera());
+ }
+
+ void GSGUI::leave()
+ {
+ guiManager_->hideGUI();
+ }
+
+ void GSGUI::ticked(const Clock& time)
+ {
+ // tick CEGUI
+ guiManager_->tick(time.getDeltaTime());
+
+ this->tickChild(time);
+ }
+}
Added: trunk/src/orxonox/gamestates/GSGUI.h
===================================================================
--- trunk/src/orxonox/gamestates/GSGUI.h (rev 0)
+++ trunk/src/orxonox/gamestates/GSGUI.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,53 @@
+/*
+ * 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:
+ * Reto Grieder
+ * Co-authors:
+ * ...
+ *
+ */
+
+#ifndef _GSGUI_H__
+#define _GSGUI_H__
+
+#include "OrxonoxPrereqs.h"
+#include "core/GameState.h"
+#include "GSGraphics.h"
+
+namespace orxonox
+{
+ class _OrxonoxExport GSGUI : public GameState<GSGraphics>
+ {
+ public:
+ GSGUI();
+ ~GSGUI();
+
+ private:
+ void enter();
+ void leave();
+ void ticked(const Clock& time);
+
+ GUIManager* guiManager_;
+ };
+}
+
+#endif /* _GSGUI_H__ */
Modified: trunk/src/orxonox/gamestates/GSLevel.cc
===================================================================
--- trunk/src/orxonox/gamestates/GSLevel.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/gamestates/GSLevel.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -49,6 +49,8 @@
#include "GraphicsManager.h"
#include "LevelManager.h"
#include "PlayerManager.h"
+#include "orxonox/objects/quest/QuestManager.h"
+#include "orxonox/overlays/notifications/NotificationManager.h"
#include "gui/GUIManager.h"
namespace orxonox
@@ -110,6 +112,10 @@
this->playerManager_ = new PlayerManager();
+ this->questManager_ = new QuestManager();
+
+ this->notificationManager_ = new NotificationManager();
+
if (GameMode::isMaster())
{
// create the global LevelManager
@@ -204,6 +210,18 @@
this->playerManager_ = 0;
}
+ if (this->questManager_)
+ {
+ delete this->questManager_;
+ this->questManager_ = NULL;
+ }
+
+ if (this->notificationManager_)
+ {
+ delete this->notificationManager_;
+ this->notificationManager_ = NULL;
+ }
+
if (GameMode::showsGraphics())
{
gameInputState_->setHandler(0);
Modified: trunk/src/orxonox/gamestates/GSLevel.h
===================================================================
--- trunk/src/orxonox/gamestates/GSLevel.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/gamestates/GSLevel.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -66,6 +66,8 @@
CameraManager* cameraManager_; //!< camera manager for this level
LevelManager* levelManager_; //!< global level manager
PlayerManager* playerManager_; //!< player manager for this level
+ QuestManager* questManager_; //!< quest manager for this level
+ NotificationManager* notificationManager_; //!< notification manager for this level
//##### ConfigValues #####
std::string keyDetectorCallbackCode_;
Modified: trunk/src/orxonox/objects/quest/AddQuest.cc
===================================================================
--- trunk/src/orxonox/objects/quest/AddQuest.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/AddQuest.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file AddQuest.cc
@brief Implementation of the AddQuest class.
*/
@@ -41,6 +41,7 @@
#include "orxonox/objects/infos/PlayerInfo.h"
#include "QuestManager.h"
+#include "QuestDescription.h"
#include "Quest.h"
namespace orxonox
@@ -95,7 +96,7 @@
try
{
- Quest* quest = QuestManager::findQuest(this->getQuestId());
+ Quest* quest = QuestManager::getInstance().findQuest(this->getQuestId());
if(quest == NULL || !quest->start(player))
{
return false;
Modified: trunk/src/orxonox/objects/quest/AddQuest.h
===================================================================
--- trunk/src/orxonox/objects/quest/AddQuest.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/AddQuest.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file AddQuest.h
@brief Definition of the AddQuest class.
*/
Modified: trunk/src/orxonox/objects/quest/AddQuestHint.cc
===================================================================
--- trunk/src/orxonox/objects/quest/AddQuestHint.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/AddQuestHint.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file AddQuestHint.cc
@brief Implementation of the AddQuestHint class.
*/
@@ -116,7 +116,7 @@
try
{
- QuestHint* hint = QuestManager::findHint(this->hintId_);
+ QuestHint* hint = QuestManager::getInstance().findHint(this->hintId_);
if(hint == NULL || !hint->setActive(player))
{
return false;
Modified: trunk/src/orxonox/objects/quest/AddQuestHint.h
===================================================================
--- trunk/src/orxonox/objects/quest/AddQuestHint.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/AddQuestHint.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file AddQuestHint.h
@brief Definition of the AddQuestHint class.
*/
Modified: trunk/src/orxonox/objects/quest/AddReward.cc
===================================================================
--- trunk/src/orxonox/objects/quest/AddReward.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/AddReward.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file AddReward.cc
@brief Implementation of the AddReward class.
*/
Modified: trunk/src/orxonox/objects/quest/AddReward.h
===================================================================
--- trunk/src/orxonox/objects/quest/AddReward.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/AddReward.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file AddReward.h
@brief Definition of the AddReward class.
*/
Modified: trunk/src/orxonox/objects/quest/CMakeLists.txt
===================================================================
--- trunk/src/orxonox/objects/quest/CMakeLists.txt 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/CMakeLists.txt 2009-04-07 23:07:27 UTC (rev 2909)
@@ -15,5 +15,6 @@
QuestItem.cc
QuestListener.cc
QuestManager.cc
+ QuestNotification.cc
Rewardable.cc
)
Modified: trunk/src/orxonox/objects/quest/ChangeQuestStatus.cc
===================================================================
--- trunk/src/orxonox/objects/quest/ChangeQuestStatus.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/ChangeQuestStatus.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file ChangeQuestStatus.cc
@brief Implementation of the ChangeQuestStatus class.
*/
Modified: trunk/src/orxonox/objects/quest/ChangeQuestStatus.h
===================================================================
--- trunk/src/orxonox/objects/quest/ChangeQuestStatus.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/ChangeQuestStatus.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file ChangeQuestStatus.h
@brief Definition of the ChangeQuestStatus class.
*/
Modified: trunk/src/orxonox/objects/quest/CompleteQuest.cc
===================================================================
--- trunk/src/orxonox/objects/quest/CompleteQuest.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/CompleteQuest.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file CompleteQuest.cc
@brief Implementation of the CompleteQuest class.
*/
@@ -95,7 +95,7 @@
try
{
- quest = QuestManager::findQuest(this->getQuestId());
+ quest = QuestManager::getInstance().findQuest(this->getQuestId());
if(quest == NULL || !quest->complete(player))
{
return false;
Modified: trunk/src/orxonox/objects/quest/CompleteQuest.h
===================================================================
--- trunk/src/orxonox/objects/quest/CompleteQuest.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/CompleteQuest.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file CompleteQuest.h
@brief Definition of the CompleteQuest class.
*/
Modified: trunk/src/orxonox/objects/quest/FailQuest.cc
===================================================================
--- trunk/src/orxonox/objects/quest/FailQuest.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/FailQuest.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file FailQuest.cc
@brief Implementation of the FailQuest class.
*/
@@ -94,7 +94,7 @@
Quest* quest;
try
{
- quest = QuestManager::findQuest(this->getQuestId());
+ quest = QuestManager::getInstance().findQuest(this->getQuestId());
if(quest == NULL || !quest->fail(player))
{
return false;
Modified: trunk/src/orxonox/objects/quest/FailQuest.h
===================================================================
--- trunk/src/orxonox/objects/quest/FailQuest.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/FailQuest.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file FailQuest.h
@brief Definition of the FailQuest class.
*/
Modified: trunk/src/orxonox/objects/quest/GlobalQuest.cc
===================================================================
--- trunk/src/orxonox/objects/quest/GlobalQuest.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/GlobalQuest.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file GlobalQuest.cc
@brief Implementation of the GlobalQuest class.
*/
Modified: trunk/src/orxonox/objects/quest/GlobalQuest.h
===================================================================
--- trunk/src/orxonox/objects/quest/GlobalQuest.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/GlobalQuest.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file GlobalQuest.h
@brief Definition of the GlobalQuest class.
*/
Modified: trunk/src/orxonox/objects/quest/LocalQuest.cc
===================================================================
--- trunk/src/orxonox/objects/quest/LocalQuest.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/LocalQuest.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file LocalQuest.cc
@brief Implementation of the LocalQuest class.
*/
Modified: trunk/src/orxonox/objects/quest/LocalQuest.h
===================================================================
--- trunk/src/orxonox/objects/quest/LocalQuest.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/LocalQuest.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file LocalQuest.h
@brief Definition of the LocalQuest class.
*/
Modified: trunk/src/orxonox/objects/quest/Quest.cc
===================================================================
--- trunk/src/orxonox/objects/quest/Quest.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/Quest.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file Quest.cc
@brief Implementation of the Quest class.
*/
@@ -78,7 +78,7 @@
XMLPortObject(Quest, QuestEffect, "fail-effects", addFailEffect, getFailEffect, xmlelement, mode);
XMLPortObject(Quest, QuestEffect, "complete-effects", addCompleteEffect, getCompleteEffect, xmlelement, mode);
- QuestManager::registerQuest(this); //!<Registers the Quest with the QuestManager.
+ QuestManager::getInstance().registerQuest(this); //!<Registers the Quest with the QuestManager.
}
/**
Modified: trunk/src/orxonox/objects/quest/Quest.h
===================================================================
--- trunk/src/orxonox/objects/quest/Quest.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/Quest.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file Quest.h
@brief Definition of the Quest class.
The Quest is the parent class of LocalQuest and GlobalQuest.
*/
Modified: trunk/src/orxonox/objects/quest/QuestDescription.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestDescription.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestDescription.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestDescription.cc
@brief Implementation of the QuestDescription class.
*/
@@ -36,7 +36,7 @@
#include "QuestDescription.h"
#include "core/CoreIncludes.h"
-#include "orxonox/overlays/notifications/Notification.h"
+#include "QuestNotification.h"
namespace orxonox
{
@@ -88,32 +88,29 @@
The status the QuestDescription us for.
@return
Returns true if successful.
+ @todo
+ Make sure the messages meet the conditions.
*/
bool QuestDescription::notificationHelper(const std::string & item, const std::string & status) const
{
std::string message = "";
- std::string title = "";
if(item == "hint")
{
- title = "You received a hint: '" + this->title_ + "'";
- message = this->description_;
+ message = "You received a hint: '" + this->title_ + "'";
}
else if(item == "quest")
{
if(status == "start")
{
- title = "You received a new quest: '" + this->title_ + "'";
- message = this->description_;
+ message = "You received a new quest: '" + this->title_ + "'";
}
else if(status == "fail")
{
- title = "You failed the quest: '" + this->title_ + "'";
- message = this->failMessage_;
+ message = "You failed the quest: '" + this->title_ + "'";
}
else if(status == "complete")
{
- title = "You successfully completed the quest: '" + this->title_ + "'";
- message = this->completeMessage_;
+ message = "You successfully completed the quest: '" + this->title_ + "'";
}
else
{
@@ -127,7 +124,7 @@
return false;
}
- Notification* notification = new Notification(0, message, title, 30);
+ QuestNotification* notification = new QuestNotification(message);
notification->send();
return true;
}
Modified: trunk/src/orxonox/objects/quest/QuestDescription.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestDescription.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestDescription.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestDescription.h
@brief Definition of the QuestDescription class.
*/
Modified: trunk/src/orxonox/objects/quest/QuestEffect.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestEffect.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestEffect.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestEffect.cc
@brief Implementation of the QuestEffect class.
*/
Modified: trunk/src/orxonox/objects/quest/QuestEffect.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestEffect.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestEffect.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestEffect.h
@brief Definition of the QuestEffect class.
*/
Modified: trunk/src/orxonox/objects/quest/QuestEffectBeacon.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestEffectBeacon.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestEffectBeacon.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestEffectBeacon.cc
@brief Implementation of the QuestEffectBeacon class.
*/
Modified: trunk/src/orxonox/objects/quest/QuestEffectBeacon.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestEffectBeacon.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestEffectBeacon.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestEffectBeacon.h
@brief Definition of the QuestEffectBeacon class.
*/
Modified: trunk/src/orxonox/objects/quest/QuestHint.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestHint.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestHint.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestHint.cc
@brief Implementation of the QuestHint class.
*/
@@ -72,7 +72,7 @@
{
SUPER(QuestHint, XMLPort, xmlelement, mode);
- QuestManager::registerHint(this); //!< Registers the QuestHint with the QuestManager.
+ QuestManager::getInstance().registerHint(this); //!< Registers the QuestHint with the QuestManager.
COUT(3) << "New QuestHint {" << this->getId() << "} created." << std::endl;
}
Modified: trunk/src/orxonox/objects/quest/QuestHint.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestHint.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestHint.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestHint.h
@brief Definition of the QuestHint class.
*/
Modified: trunk/src/orxonox/objects/quest/QuestItem.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestItem.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestItem.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestItem.cc
@brief Implementation of the QuestItem class.
*/
Modified: trunk/src/orxonox/objects/quest/QuestItem.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestItem.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestItem.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestItem.h
@brief Definition of the QuestItem class.
The QuestItem is the parent class of Quest and QuestHint.
*/
Modified: trunk/src/orxonox/objects/quest/QuestListener.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestListener.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestListener.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestListener.cc
@brief Implementation of the QuestListener class.
*/
@@ -111,7 +111,7 @@
*/
bool QuestListener::setQuestId(const std::string & id)
{
- this->quest_ = QuestManager::findQuest(id); //!< Find the Quest corresponding to the given questId.
+ this->quest_ = QuestManager::getInstance().findQuest(id); //!< Find the Quest corresponding to the given questId.
if(this->quest_ == NULL) //!< If there is no such Quest.
{
Modified: trunk/src/orxonox/objects/quest/QuestListener.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestListener.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestListener.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestListener.h
@brief Definition of the QuestListener class.
*/
Modified: trunk/src/orxonox/objects/quest/QuestManager.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestManager.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestManager.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestManager.cc
@brief Implementation of the QuestManager class.
*/
@@ -42,18 +42,21 @@
namespace orxonox
{
- //! All Quests registered by their id's.
- std::map<std::string, Quest*> QuestManager::questMap_s;
- //! All QuestHints registered by their id's.
- std::map<std::string, QuestHint*> QuestManager::hintMap_s;
+ //! Pointer to the current (and single) instance of this class.
+ QuestManager* QuestManager::singletonRef_s = NULL;
/**
@brief
Constructor. Registers the object.
+ @todo
+ Is inheriting from BaseObject proper?
*/
- QuestManager::QuestManager(BaseObject* creator) : BaseObject(creator)
+ QuestManager::QuestManager()
{
- RegisterObject(QuestManager);
+ RegisterRootObject(QuestManager);
+
+ assert(singletonRef_s == 0);
+ singletonRef_s = this;
}
/**
@@ -67,6 +70,18 @@
/**
@brief
+ Returns a reference to the current (and single) instance of the QuestManager, and creates one if there isn't one to begin with.
+ @return
+ Returns a reference to the single instance of the Quest Manager.
+ */
+ /*static*/ QuestManager & QuestManager::getInstance()
+ {
+ assert(singletonRef_s);
+ return *singletonRef_s;
+ }
+
+ /**
+ @brief
Registers a Quest with the QuestManager to make it globally accessable.
Uses it's id to make sure to be able to be identify and retrieve it later.
@param quest
@@ -74,7 +89,7 @@
@return
Returns true if successful, false if not.
*/
- /*static*/ bool QuestManager::registerQuest(Quest* quest)
+ bool QuestManager::registerQuest(Quest* quest)
{
if(quest == NULL) //!< Doh! Just as if there were actual quests behind NULL-pointers.
{
@@ -83,7 +98,7 @@
}
std::pair<std::map<std::string, Quest*>::iterator,bool> result;
- result = questMap_s.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
+ result = this->questMap_.insert( std::pair<std::string,Quest*>(quest->getId(),quest) ); //!< Inserting the Quest.
if(result.second) //!< If inserting was a success.
{
@@ -106,7 +121,7 @@
@return
Returns true if successful, false if not.
*/
- /*static*/ bool QuestManager::registerHint(QuestHint* hint)
+ bool QuestManager::registerHint(QuestHint* hint)
{
if(hint == NULL) //!< Still not liking NULL-pointers.
{
@@ -115,7 +130,7 @@
}
std::pair<std::map<std::string, QuestHint*>::iterator,bool> result;
- result = hintMap_s.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
+ result = this->hintMap_.insert ( std::pair<std::string,QuestHint*>(hint->getId(),hint) ); //!< Inserting the QuestHSint.
if(result.second) //!< If inserting was a success.
{
@@ -140,7 +155,7 @@
@throws
Throws an exception if the given questId is invalid.
*/
- /*static*/ Quest* QuestManager::findQuest(const std::string & questId)
+ Quest* QuestManager::findQuest(const std::string & questId)
{
if(!QuestItem::isId(questId)) //!< Check vor validity of the given id.
{
@@ -148,8 +163,8 @@
}
Quest* quest;
- std::map<std::string, Quest*>::iterator it = questMap_s.find(questId);
- if (it != questMap_s.end()) //!< If the Quest is registered.
+ std::map<std::string, Quest*>::iterator it = this->questMap_.find(questId);
+ if (it != this->questMap_.end()) //!< If the Quest is registered.
{
quest = it->second;
}
@@ -174,7 +189,7 @@
@throws
Throws an exception if the given hintId is invalid.
*/
- /*static*/ QuestHint* QuestManager::findHint(const std::string & hintId)
+ QuestHint* QuestManager::findHint(const std::string & hintId)
{
if(!QuestItem::isId(hintId)) //!< Check vor validity of the given id.
{
@@ -182,8 +197,8 @@
}
QuestHint* hint;
- std::map<std::string, QuestHint*>::iterator it = hintMap_s.find(hintId);
- if (it != hintMap_s.end()) //!< If the QuestHint is registered.
+ std::map<std::string, QuestHint*>::iterator it = this->hintMap_.find(hintId);
+ if (it != this->hintMap_.end()) //!< If the QuestHint is registered.
{
hint = it->second;
}
Modified: trunk/src/orxonox/objects/quest/QuestManager.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestManager.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/QuestManager.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file QuestManager.h
@brief Definition of the QuestManager class.
*/
@@ -39,34 +39,37 @@
#include <map>
#include <string>
-#include "core/BaseObject.h"
+#include "core/OrxonoxClass.h"
namespace orxonox
{
/**
@brief
- Is a static class and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()).
+ Is a Singleton and manages Quests, by registering every Quest/QuestHint (through registerX()) and making them globally accessable (through findX()).
Quests (and QuestHints) are registered in the QuestManager with their id, and can be accessed in the same way.
@author
Damian 'Mozork' Frick
*/
- class _OrxonoxExport QuestManager : public BaseObject
+ class _OrxonoxExport QuestManager : public OrxonoxClass
{
-
public:
- QuestManager(BaseObject* creator);
+ QuestManager();
virtual ~QuestManager();
- static bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
- static bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
+ static QuestManager& getInstance(); //!< Returns a reference to the single instance of the Quest Manager.
- static Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id.
- static QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
+ bool registerQuest(Quest* quest); //!< Registers a Quest in the QuestManager.
+ bool registerHint(QuestHint* quest); //!< Registers a QuestHint in the QuestManager.
+ Quest* findQuest(const std::string & questId); //!< Returns the Quest with the input id.
+ QuestHint* findHint(const std::string & hintId); //!< Returns the QuestHint with the input id.
+
private:
- static std::map<std::string, Quest*> questMap_s; //!< All Quests registered by their id's.
- static std::map<std::string, QuestHint*> hintMap_s; //!< All QuestHints registered by their id's.
+ static QuestManager* singletonRef_s;
+ std::map<std::string, Quest*> questMap_; //!< All Quests registered by their id's.
+ std::map<std::string, QuestHint*> hintMap_; //!< All QuestHints registered by their id's.
+
};
}
Added: trunk/src/orxonox/objects/quest/QuestNotification.cc
===================================================================
--- trunk/src/orxonox/objects/quest/QuestNotification.cc (rev 0)
+++ trunk/src/orxonox/objects/quest/QuestNotification.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,66 @@
+/*
+ * 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:
+ * ...
+ *
+ */
+
+#include "OrxonoxStableHeaders.h"
+#include "QuestNotification.h"
+
+#include "core/CoreIncludes.h"
+
+#include "orxonox/overlays/notifications/Notification.h"
+
+namespace orxonox {
+
+ const std::string QuestNotification::SENDER = "questsystem";
+
+ QuestNotification::QuestNotification(BaseObject* creator) : Notification(creator)
+ {
+ this->initialize();
+ }
+
+ QuestNotification::QuestNotification(const std::string & message) : Notification(message)
+ {
+ this->initialize();
+ }
+
+ QuestNotification::~QuestNotification()
+ {
+
+ }
+
+ bool QuestNotification::send(void)
+ {
+ return this->Notification::send(QuestNotification::SENDER);
+ }
+
+ void QuestNotification::initialize(void)
+ {
+ RegisterObject(QuestNotification);
+ }
+
+
+}
Added: trunk/src/orxonox/objects/quest/QuestNotification.h
===================================================================
--- trunk/src/orxonox/objects/quest/QuestNotification.h (rev 0)
+++ trunk/src/orxonox/objects/quest/QuestNotification.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,64 @@
+/*
+ * 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:
+ * ...
+ *
+ */
+
+#ifndef _QuestNotification_H__
+#define _QuestNotification_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include <string>
+
+#include "orxonox/overlays/notifications/Notification.h"
+
+namespace orxonox {
+
+ /**
+ @brief
+
+ @author
+ Damian 'Mozork' Frick
+ */
+ class _OrxonoxExport QuestNotification : public Notification
+ {
+ public:
+ QuestNotification(BaseObject* creator);
+ QuestNotification(const std::string & message);
+ virtual ~QuestNotification();
+
+ bool send(void);
+
+ private:
+ static const std::string SENDER;
+
+ void initialize(void);
+
+ };
+
+}
+
+#endif /* _QuestNotification_H__ */
Modified: trunk/src/orxonox/objects/quest/Rewardable.cc
===================================================================
--- trunk/src/orxonox/objects/quest/Rewardable.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/Rewardable.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file Rewardable.cc
@brief Implementation of the Rewardable class.
*/
Modified: trunk/src/orxonox/objects/quest/Rewardable.h
===================================================================
--- trunk/src/orxonox/objects/quest/Rewardable.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/objects/quest/Rewardable.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -27,7 +27,7 @@
*/
/**
- @file
+ @file Rewardable.h
@brief Definition of the Rewardable class.
*/
Modified: trunk/src/orxonox/overlays/OverlayGroup.cc
===================================================================
--- trunk/src/orxonox/overlays/OverlayGroup.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/overlays/OverlayGroup.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -112,6 +112,21 @@
element->setOwner(this->owner_);
}
+ /**
+ @brief
+ Removes an element from the map.
+ @param element
+ The element that is to be removed.
+ @return
+ Returns true if there was such an element to remove, false if not.
+ */
+ bool OverlayGroup::removeElement(OrxonoxOverlay* element)
+ {
+ if(this->hudElements_.erase(element) == 0)
+ return false;
+ return true;
+ }
+
//! Returns a different element as long as index < hudElements_.size().
OrxonoxOverlay* OverlayGroup::getElement(unsigned int index)
{
Modified: trunk/src/orxonox/overlays/OverlayGroup.h
===================================================================
--- trunk/src/orxonox/overlays/OverlayGroup.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/overlays/OverlayGroup.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -37,6 +37,7 @@
#include "OrxonoxPrereqs.h"
#include <set>
+#include <string>
#include <OgrePrerequisites.h>
#include "core/BaseObject.h"
#include "util/Math.h"
@@ -85,6 +86,7 @@
Vector2 getScroll() const { return this->scale_; }
void addElement(OrxonoxOverlay* element);
+ bool removeElement(OrxonoxOverlay* element);
OrxonoxOverlay* getElement(unsigned int index);
private:
Modified: trunk/src/orxonox/overlays/notifications/CMakeLists.txt
===================================================================
--- trunk/src/orxonox/overlays/notifications/CMakeLists.txt 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/overlays/notifications/CMakeLists.txt 2009-04-07 23:07:27 UTC (rev 2909)
@@ -1,5 +1,6 @@
ADD_SOURCE_FILES(ORXONOX_SRC_FILES
Notification.cc
NotificationManager.cc
+ NotificationOverlay.cc
NotificationQueue.cc
)
Modified: trunk/src/orxonox/overlays/notifications/Notification.cc
===================================================================
--- trunk/src/orxonox/overlays/notifications/Notification.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/overlays/notifications/Notification.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -26,77 +26,109 @@
*
*/
+/**
+ @file Notification.cc
+ @brief Implementation of the Notification class.
+*/
+
#include "OrxonoxStableHeaders.h"
#include "Notification.h"
#include "core/CoreIncludes.h"
+#include "util/Exception.h"
#include "NotificationManager.h"
namespace orxonox
{
+
+ /**
+ @brief
+ Default constructor. Initializes the object.
+ */
Notification::Notification(BaseObject* creator) : BaseObject(creator)
{
- RegisterObject(Notification);
+ this->initialize();
}
- Notification::Notification(BaseObject* creator, const std::string & message, const std::string & title, float time) : BaseObject(creator)
+ /**
+ @brief
+ Constructor. Creates a Notification with the input message.
+ @param message
+ The message of the Notification.
+ */
+ Notification::Notification(const std::string & message) : BaseObject(this)
{
- this->title_ = title;
this->message_ = message;
- if(time > 0)
- this->displayTime_ = time;
}
+ /**
+ @brief
+ Destructor.
+ */
Notification::~Notification()
{
}
+ /**
+ @brief
+ Registers the object and sets some default values.
+ */
void Notification::initialize(void)
{
RegisterObject(Notification);
- this->title_ = "";
this->message_ = "";
- this->displayTime_ = NOTIFICATION_DISPLAY_TIME;
+ this->sender_ = NotificationManager::NONE;
this->sent_ = false;
}
+ /**
+ @brief
+ Sends the Notification to the Notificationmanager, with sender NetificationManager::NONE.
+ @return
+ Returns true if successful.
+ */
bool Notification::send(void)
{
- bool successful = NotificationManager::insertNotification(this);
- if(successful)
- this->sent_ = true;
- return successful;
+ return this->send(NotificationManager::NONE);
}
- bool Notification::setTitle(const std::string & title)
+ /**
+ @brief
+ Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
+ @param sender
+ The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
+ @return
+ Returns true if successful.
+ */
+ bool Notification::send(const std::string & sender)
{
- if(this->isSent())
+ this->sender_ = sender;
+ bool successful = NotificationManager::getInstance().registerNotification(this);
+ if(!successful)
return false;
- this->title_ = title;
+ this->sent_ = true;
+
+ COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
+
return true;
}
+ /**
+ @brief
+ Sets the message of the notification.
+ @param message
+ The message to be set.
+ @return
+ Returns true if successful.
+ */
bool Notification::setMessage(const std::string & message)
{
- if(this->isSent())
+ if(this->isSent()) //!< The message cannot be changed if the message has already been sent.
return false;
this->message_ = message;
return true;
}
-
- bool Notification::setDisplayTime(float time)
- {
- if(this->isSent())
- {
- return false;
- }
- if(time > 0)
- {
- this->displayTime_ = time;
- return true;
- }
- return false;
- }
+
}
Modified: trunk/src/orxonox/overlays/notifications/Notification.h
===================================================================
--- trunk/src/orxonox/overlays/notifications/Notification.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/overlays/notifications/Notification.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -26,6 +26,11 @@
*
*/
+/**
+ @file Notification.h
+ @brief Definition of the Notification class.
+*/
+
#ifndef _Notification_H__
#define _Notification_H__
@@ -37,44 +42,50 @@
namespace orxonox
{
- static const float NOTIFICATION_DISPLAY_TIME = 4.0;
/**
@brief
- This is rather temporary, so don't start relying on it, some better version will come soon but the Interface will not likely be the same.
+ A Notification is a short message used to inform the player about something that just happened. A Notification can be sent from any part of orxonox and is then displayed in the proper NotificationQueue (depending on which senders the specific NotificationQueue accepts).
@author
Damian 'Mozork' Frick
*/
class _OrxonoxExport Notification : public BaseObject
{
- public:
- Notification(BaseObject* creator);
- Notification(BaseObject* creator, const std::string & message, const std::string & title = "", float time = NOTIFICATION_DISPLAY_TIME);
- virtual ~Notification();
-
- bool send(void);
-
- inline bool isSent(void) const
- { return this->sent_; }
- inline const std::string & getTitle(void) const
- { return this->title_; }
- inline const std::string & getMessage(void) const
- { return this->message_; }
- inline const float getDisplayTime(void) const
- { return displayTime_; }
-
- bool setTitle(const std::string & title);
- bool setMessage(const std::string & message);
- bool setDisplayTime(float time);
-
- private:
- std::string title_; //!< The title of the Notification.
- std::string message_; //!< The Notification message.
- float displayTime_; //!< The time duration the Notification is displayed in seconds.
- bool sent_; //!< Whether Notification has been sent, if so it cannot be changed.
-
- void initialize(void);
+ public:
+ Notification(BaseObject* creator);
+ Notification(const std::string & message);
+ virtual ~Notification();
+
+ bool send(void); //!< Sends the Notification to the Notificationmanager, with sender NotificationManager::NONE;
+ bool send(const std::string & sender); //!< Sends the Notification to the Notificationmanager.
+
+ /**
+ @brief Checks whether the Notification was sent.
+ @return Returns true if the Notification was sent already.
+ */
+ inline bool isSent(void) const
+ { return this->sent_; }
+ /**
+ @brief Returns the message of the Notification.
+ @return Returns the message of the Notification.
+ */
+ inline const std::string & getMessage(void) const
+ { return this->message_; }
+
+ inline const std::string & getSender(void) const
+ { return this->sender_; }
+
+ bool setMessage(const std::string & message); //!< Sets the message of the notification.
+
+ private:
+ std::string message_; //!< The Notification message.
+ std::string sender_; //!< The sender of the notification.
+ bool sent_; //!< Whether Notification has been sent, if so it cannot be changed.
+
+ void initialize(void);
+
};
+
}
#endif /* _Notification_H__ */
Modified: trunk/src/orxonox/overlays/notifications/NotificationManager.cc
===================================================================
--- trunk/src/orxonox/overlays/notifications/NotificationManager.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/overlays/notifications/NotificationManager.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -26,149 +26,182 @@
*
*/
+/**
+ @file NotificationManager.cc
+ @brief Implementation of the NotificationManager class.
+*/
+
#include "OrxonoxStableHeaders.h"
#include "NotificationManager.h"
#include "core/CoreIncludes.h"
+#include <set>
+
#include "Notification.h"
-
#include "NotificationQueue.h"
namespace orxonox
{
- std::list<NotificationContainer*> NotificationManager::notifications_s;
- NotificationManager::NotificationManager(BaseObject* creator) : BaseObject(creator)
+ const std::string NotificationManager::ALL = "all";
+ const std::string NotificationManager::NONE = "none";
+
+ NotificationManager* NotificationManager::singletonRef_s = NULL;
+
+ /**
+ @brief
+ Constructor. Registers the Object.
+ */
+ NotificationManager::NotificationManager()
{
- RegisterObject(NotificationManager);
+ RegisterRootObject(NotificationManager);
+
+ assert(singletonRef_s == 0);
+ singletonRef_s = this;
+
+ this->highestIndex_ = 0;
}
+ /**
+ @brief
+ Destructor.
+ */
NotificationManager::~NotificationManager()
{
- //TDO: Destroy the containers
}
- void NotificationManager::tick(float dt)
+ /**
+ @brief
+ Returns the current (and single) instance of the NotificationManager. Creates one, if there isn't one to begin with.
+ @return
+ Returns a reference to the single instance of the NotificationManager.
+ */
+ /*static*/ NotificationManager & NotificationManager::getInstance()
{
- bool update = false;
-
- for (std::list<NotificationContainer*>::iterator notification = notifications_s.begin(); notification != notifications_s.end(); ++notification)
+ assert(singletonRef_s);
+ return *singletonRef_s;
+ }
+
+ /**
+ @brief
+ Registers a Notification within the NotificationManager and makes sure that the Notification is displayed in all the NotificationQueues associated with its sender.
+ @param notification
+ The Notification to be registered.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationManager::registerNotification(Notification* notification)
+ {
+
+ if(notification == NULL) //!< A NULL-Notification cannot be registered.
+ return false;
+
+ std::time_t time = std::time(0); //TDO: Doesn't this expire? //!< Get current time.
+
+ this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification));
+
+ if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications.
+ return true;
+
+ bool all = false;
+ if(notification->getSender() == ALL) //!< If all are the sender, then the Notifications is added to every NotificationQueue.
+ all = true;
+
+ //!< Insert the notification in all queues that have its sender as target.
+ for(std::map<NotificationQueue*,int>::iterator it = this->queueList_.begin(); it != this->queueList_.end(); it++) //!< Iterate through all queues.
{
- NotificationContainer* container = *notification;
- if(container->remainingTime == 0)
+ std::set<std::string> set = it->first->getTargetsSet();
+ if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TDO: Make sure this works.
{
- continue;
+ this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationQueue.
+ it->first->update(notification, time); //!< Update the queue.
}
- else if(container->remainingTime - dt <= 0)
- {
- container->remainingTime = 0;
- update = true;
- }
- else
- {
- container->remainingTime = container->remainingTime -dt;
- }
}
-
- if(update)
- updateQueue();
- }
-
- bool NotificationManager::insertNotification(Notification* notification)
- {
- if(notification == NULL)
- return false;
-
- NotificationContainer* container = new NotificationContainer;
- container->notification = notification;
- container->remainingTime = notification->getDisplayTime();
- notifications_s.push_front(container);
-
- updateQueue();
-
- COUT(4) << "Notification inserted. Title: " << notification->getTitle() << std::endl;
-
+
+ COUT(3) << "Notification registered with the NotificationManager." << std::endl;
+
return true;
}
-
- void NotificationManager::updateQueue(void)
+
+ /**
+ @brief
+ Registers a NotificationQueue within the NotificationManager.
+ @param queue
+ The NotificationQueue to be registered.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationManager::registerQueue(NotificationQueue* queue)
{
- std::string text = "";
-
- if (!NotificationQueue::queue_s)
- return;
-
- int i = NotificationQueue::queue_s->getLength();
- for (std::list<NotificationContainer*>::iterator notification = notifications_s.begin(); notification != notifications_s.end() && i > 0; ++notification)
+ this->highestIndex_ += 1;
+ int index = this->highestIndex_;
+
+ this->queueList_[queue] = index; //!< Add the NotificationQueue to the list of queues.
+
+ std::set<std::string> set = queue->getTargetsSet(); //TDO: Works this?
+
+ //! If all senders are the target of the queue, then the list of notification for that specific queue is te same as the list of all Notifications.
+ if(set.find(ALL) != set.end())
{
- i--;
- NotificationContainer* container = *notification;
- if(container->remainingTime == 0.0)
- continue;
-
- text = text + "\n\n\n------------\n\n" + clipMessage(container->notification->getTitle()) + "\n\n" + clipMessage(container->notification->getMessage());
+ this->notificationLists_[index] = &this->allNotificationsList_;
+ COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
+ return true;
}
+
+ this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>;
+ std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index];
+
+ //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationQueue.
+ for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++)
+ {
+ if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target.
+ {
+ map.insert(std::pair<std::time_t,Notification*>(it->first, it->second));
+ }
+ }
+
+ queue->update(); //!< Update the queue.
- NotificationQueue::queue_s->setQueueText(text);
+ COUT(3) << "NotificationQueue registered with the NotificationManager." << std::endl;
+
+ return true;
}
-
- const std::string NotificationManager::clipMessage(const std::string & str)
+
+ /**
+ @brief
+ Fetches the Notifications for a specific NotificationQueue in a specified timeframe.
+ @param queue
+ The NotificationQueue the Notifications are fetched for.
+ @param map
+ A multimap, in which the notifications are stored.
+ @param timeFrameStart
+ The start time of the timeframe.
+ @param timeFrameEnd
+ The end time of the timeframe.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationManager::getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd)
{
+ if(queue == NULL || map == NULL)
+ return false;
- std::string message = str;
- unsigned int i = 0;
-
- unsigned int found = message.find("\\n", i);
- while(found != std::string::npos)
+ std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->queueList_[queue]]; //!< The Notifications for the input NotificationQueue.
+
+ if(notifications == NULL) //!< Returns NULL, if there are no Notifications.
+ return true;
+
+ std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest;
+ itLowest = notifications->lower_bound(timeFrameStart);
+ itHighest = notifications->upper_bound(timeFrameStart);
+
+ for(it = itLowest; it != itHighest; it++) //!< Iterate through the Notifications from the start of the time Frame to the end of it.
{
- message.replace(found, 2, "\n");
- i = found+2;
- found = message.find("\\n", i);
+ map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); //!< Add the found Notifications to the map.
}
-
- std::string clippedMessage = "";
- int wordLength = 0;
- i = 0;
- int widthLeft = NotificationQueue::queue_s->getWidth();
- while(i < message.length())
- {
- while(i < message.length() && message[i] != ' ' && message[i] != '\n')
- {
- i++;
- wordLength++;
- }
-
- if(wordLength <= widthLeft)
- {
- clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);
- if(i < message.length())
- {
- clippedMessage = clippedMessage + message.substr(i,1);
- }
- widthLeft -= (wordLength+1);
- if(message[i] == '\n')
- {
- widthLeft = NotificationQueue::queue_s->getWidth() - (wordLength+1);
- }
- wordLength = 0;
- i++;
- }
- else
- {
- clippedMessage.push_back('\n');
- clippedMessage = clippedMessage + message.substr(i-wordLength, wordLength);
- if(i < message.length())
- {
- clippedMessage = clippedMessage + message.substr(i,1);
- }
- widthLeft = NotificationQueue::queue_s->getWidth() - (wordLength+1);
- i++;
- wordLength = 0;
- }
- }
-
- return clippedMessage;
+
+ return true;
}
}
Modified: trunk/src/orxonox/overlays/notifications/NotificationManager.h
===================================================================
--- trunk/src/orxonox/overlays/notifications/NotificationManager.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/overlays/notifications/NotificationManager.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -26,46 +26,78 @@
*
*/
+/**
+ @file NotificationManager.h
+ @brief Definition of the NotificationManager class.
+*/
+
#ifndef _NotificationManager_H__
#define _NotificationManager_H__
#include "OrxonoxPrereqs.h"
-#include "core/BaseObject.h"
+#include "core/OrxonoxClass.h"
-#include <list>
+#include <map>
#include <string>
+#include <ctime>
+#include "NotificationOverlay.h"
+
namespace orxonox
{
- struct NotificationContainer
- {
- Notification* notification;
- float remainingTime;
- };
/**
@brief
-
+ The Singleton NotificationManager functions as a gateway between Notifications and NotificationQueues.
+ It receives, organizes Notifications and the redistributes them to the specific NotificationQueues.
@author
Damian 'Mozork' Frick
*/
- class _OrxonoxExport NotificationManager : public BaseObject
+ class _OrxonoxExport NotificationManager : public OrxonoxClass
{
-
- public:
- NotificationManager(BaseObject* creator);
- virtual ~NotificationManager();
+ public:
+ NotificationManager();
+ virtual ~NotificationManager();
+
+ static const std::string ALL;
+ static const std::string NONE;
+
+ static NotificationManager & getInstance(); //! Returns a reference to the single instance of the NotificationManager.
+
+ bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager.
+ bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue within the NotificationManager.
+
+ bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationQueue in a specified timeframe.
+
+ /**
+ @brief Fetches the Notifications for a specific NotificationQueue starting at a specified time.
+ @param queue The NotificationQueue 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(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart)
+ { return this->getNotifications(queue, map, timeFrameStart, std::time(0)); }
+ /**
+ @brief Fetches the Notifications for a specific NotificationQueue starting at a specified timespan before now.
+ @param queue The NotificationQueue the Notifications are fetched for.
+ @param map A multimap, in which the notifications are stored.
+ @param timeDelay The timespan.
+ @return Returns true if successful.
+ */
+ bool getNotifications(NotificationQueue* queue, std::multimap<std::time_t,Notification*>* map, int timeDelay)
+ { return this->getNotifications(queue, map, std::time(0)-timeDelay, std::time(0)); }
+
+ private:
+ static NotificationManager* singletonRef_s;
+
+ int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.
- static bool insertNotification(Notification* notification);
-
- static void tick(float dt);
-
- private:
- static std::list<NotificationContainer*> notifications_s;
-
- static void updateQueue(void);
- static const std::string clipMessage(const std::string & message);
+ std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored (together with their respecive timestamps).
+ std::map<NotificationQueue*,int> queueList_; //!< Container where all NotificationQueues are stored with a number as identifier.
+ std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationQueue), are stored.
+
};
Added: trunk/src/orxonox/overlays/notifications/NotificationOverlay.cc
===================================================================
--- trunk/src/orxonox/overlays/notifications/NotificationOverlay.cc (rev 0)
+++ trunk/src/orxonox/overlays/notifications/NotificationOverlay.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,143 @@
+/*
+ * 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 NotificationOverlay.cc
+ @brief Implementation of the NotificationOverlay class.
+*/
+
+#include "OrxonoxStableHeaders.h"
+#include "NotificationOverlay.h"
+
+#include <OgreOverlayManager.h>
+#include <OgreTextAreaOverlayElement.h>
+#include <OgrePanelOverlayElement.h>
+
+#include "core/CoreIncludes.h"
+#include "util/Exception.h"
+
+#include "Notification.h"
+#include "NotificationQueue.h"
+
+namespace orxonox
+{
+
+ /**
+ @brief
+ Constructor. Intializes the class.
+ */
+ NotificationOverlay::NotificationOverlay(BaseObject* creator) : OverlayText(creator)
+ {
+ this->initialize();
+ }
+
+ /**
+ @brief
+ Constructor. Initilaizes 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(this)
+ {
+ 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)
+ {
+ RegisterObject(NotificationOverlay);
+
+ 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.
+ */
+ const std::string NotificationOverlay::clipMessage(const std::string & message)
+ {
+ if(message.length() <= (unsigned int)this->queue_->getNotificationLength()) //!< If the message is not too long.
+ return message;
+ return message.substr(0, this->queue_->getNotificationLength());
+ }
+
+}
Added: trunk/src/orxonox/overlays/notifications/NotificationOverlay.h
===================================================================
--- trunk/src/orxonox/overlays/notifications/NotificationOverlay.h (rev 0)
+++ trunk/src/orxonox/overlays/notifications/NotificationOverlay.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -0,0 +1,87 @@
+/*
+ * 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 NotificationOverlay.h
+ @brief Definition of the NotificationOverlay class.
+*/
+
+
+#ifndef _NotificationOverlay_H__
+#define _NotificationOverlay_H__
+
+#include "OrxonoxPrereqs.h"
+
+#include "orxonox/overlays/OverlayText.h"
+
+#include <string>
+#include <set>
+#include <OgrePrerequisites.h>
+#include <OgreTextAreaOverlayElement.h>
+
+namespace orxonox
+{
+
+ /**
+ @brief
+ The NotificationOverlay is used to display single Notifications, then bundled in a NotificationQUeue.
+ @author
+ Damian 'Mozork' Frick
+ */
+ class _OrxonoxExport 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:
+ const 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: trunk/src/orxonox/overlays/notifications/NotificationQueue.cc
===================================================================
--- trunk/src/orxonox/overlays/notifications/NotificationQueue.cc 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/overlays/notifications/NotificationQueue.cc 2009-04-07 23:07:27 UTC (rev 2909)
@@ -26,84 +26,430 @@
*
*/
+/**
+ @file NotificationQueue.cc
+ @brief Implementation of the NotificationQueue class.
+*/
+
#include "OrxonoxStableHeaders.h"
#include "NotificationQueue.h"
+#include <OgreOverlayManager.h>
+#include <OgreTextAreaOverlayElement.h>
+#include <list>
+#include <iostream>
+#include <sstream>
+
#include "core/CoreIncludes.h"
#include "core/XMLPort.h"
-#include "NotificationManager.h"
+#include "Notification.h"
+#include "NotificationOverlay.h"
namespace orxonox
{
- NotificationQueue* NotificationQueue::queue_s = 0;
-
+
CreateFactory(NotificationQueue);
+
+ const std::string NotificationQueue::DEFAULT_FONT = "VeraMono";
+ const Vector2 NotificationQueue::DEFAULT_POSITION = Vector2(0.0,0.0);
- NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayText(creator)
+ /**
+ @brief
+ Constructor. Creates and initializes the object.
+ */
+ NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator)
{
- RegisterObject(NotificationQueue);
- //TDO: Does this work?
- if(queue_s != NULL)
- {
- COUT(2) << "There is now more than one NotificationQueue, this shouldn't happen, since only the first NotificationQueue will be targeted by the NotificationManager." << std::endl;
- }
- else
- {
- queue_s = this;
- }
-
- this->length_ = 3;
- this->width_ = 50;
+ this->initialize();
}
-
+
+ /**
+ @brief
+ Destructor.
+ */
NotificationQueue::~NotificationQueue()
{
-
+ this->targets_.clear();
+ this->clear();
}
-
+
+ /**
+ @brief
+ Initializes the object.
+ Registers the object, initializes variables, sets default values and registers the queue with the NotificationManager.
+ */
+ void NotificationQueue::initialize(void)
+ {
+ RegisterObject(NotificationQueue);
+
+ this->size_ = 0;
+ this->tickTime_ = 0.0;
+
+ NotificationManager::getInstance().registerQueue(this);
+ }
+
+ /**
+ @brief
+ Sets the defaults.
+ */
+ void NotificationQueue::setDefaults(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);
+ }
+
+ /**
+ @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, "length", setLength, getLength, xmlElement, mode);
- XMLPortParam(NotificationQueue, "width", setWidth, getWidth, xmlElement, mode);
+ 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 created." << std::endl;
}
-
+
+ /**
+ @brief
+ Updates the queue from time to time.
+ @param dt
+ The time interval that has passed since the last tick.
+ */
void NotificationQueue::tick(float dt)
{
- NotificationManager::tick(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->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.
+ {
+ this->removeContainer(*it);
+ this->scroll(Vector2(0.0,-(1.1*this->getFontSize())));
+ it = this->containers_.begin(); //TDO: Needed?
+ }
+
+ this->tickTime_ = 0.0; //!< 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.
+ */
+ 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.
+ {
+ COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl;
+ return;
+ }
+
+ 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);
+ }
+
+ delete notifications;
+
+ COUT(3) << "NotificationQueue updated." << std::endl;
+ }
+
+ /**
+ @brief
+ Updates the NotificationQueue by adding an new Notification.
+ @param notification
+ Pointer to the Notification.
+ @param time
+ The time the Notification was sent.
+ */
+ void NotificationQueue::update(Notification* notification, const std::time_t & time)
+ {
+ this->addNotification(notification, time);
+
+ std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it;
+ while(this->getSize() > this->getMaxSize())
+ {
+ it = this->containers_.begin();
+ this->removeContainer(*it);
+ this->scroll(Vector2(0.0,-(1.1*this->getFontSize())));
+ }
+
+ COUT(3) << "NotificationQueue updated. A new Notifications has been added." << std::endl;
+ }
+
+ /**
+ @brief
+ Sets the maximum number of displayed Notifications.
+ @param size
+ The size to be set.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationQueue::setMaxSize(int size)
+ {
+ if(size < 0)
+ return false;
+ this->maxSize_ = size;
+ this->update();
+ return true;
+ }
+
+ /**
+ @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.
+ */
+ bool NotificationQueue::setNotificationLength(int length)
+ {
+ if(length < 0)
+ return false;
+ this->notificationLength_ = length;
+ this->update();
+ return true;
+ }
+
+ /**
+ @brief
+ Sets the maximum number of seconds a Notification is displayed.
+ @param time
+ The number of seconds the Notifications is displayed.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationQueue::setDisplayTime(int time)
+ {
+ if(time < 0)
+ return false;
+ this->displayTime_ = time;
+ this->update();
+ return true;
+ }
+
+ /**
+ @brief
+ Produces all targets concatinated as string, with kommas (',') as seperators.
+ @param string
+ Pointer to a string which will be used by the method to fill with the concatination of the targets.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationQueue::getTargets(std::string* string) const
+ {
+ if(string == NULL)
+ {
+ COUT(4) << "Input string must have memory allocated." << std::endl;
+ return false;
+ }
+ string->clear();
+ bool first = true;
+ for(std::set<std::string>::iterator it = this->targets_.begin(); it != this->targets_.end(); it++) //!< Iterate through the set of targets.
+ {
+ if(!first)
+ {
+ *string += ",";
+ }
+ else
+ {
+ first = false;
+ }
+ *string += *it;
+ }
+
+ return true;
+ }
+
+ /**
+ @brief
+ Sets the targets of the queue.
+ The targets are the senders whose Notifications are displayed in this queue.
+ @param targets
+ Accepts a string of targets, each seperated by commas (','), spaces are ignored.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationQueue::setTargets(const std::string & targets)
+ {
+ this->targets_.clear();
- update();
+ std::string* pTemp;
+ unsigned int index = 0;
+ while( index < targets.size() ) //!< Go through the string, character by character until the end is reached.
+ {
+ pTemp = new std::string("");
+ while(index < targets.size() && targets[index] != ',' && targets[index] != ' ')
+ {
+ *pTemp += targets[index];
+ index++;
+ }
+ index++;
+ this->targets_.insert(*pTemp);
+ }
+
+ return true;
}
-
- bool NotificationQueue::setLength(int length)
+
+ /**
+ @brief
+ Sets the font size.
+ @param size
+ The font size.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationQueue::setFontSize(float size)
{
- if(length > 0)
+ 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.
{
- this->length_ = length;
- return true;
+ it->second->overlay->setFontSize(size);
}
- return false;
+ return true;
}
+
+ /**
+ @brief
+ Sets the font.
+ @param font
+ The font.
+ @return
+ Returns true if successful.
+ */
+ 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;
+ }
- bool NotificationQueue::setWidth(int width)
+ /**
+ @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)
{
- if(width > 0)
+ for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Scroll each overlay.
{
- this->width_ = width;
- return true;
+ it->second->overlay->scroll(pos);
}
- return false;
}
- void NotificationQueue::setQueueText(const std::string & text)
+ /**
+ @brief
+ Aligns all the Notifications to the position of the NotificationQueue.
+ */
+ void NotificationQueue::positionChanged(void)
{
- this->queueText_ = text;
+ 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.0,(1.1*this->getFontSize())*counter));
+ counter++;
+ }
}
- void NotificationQueue::update(void)
+ /**
+ @brief
+ Adds a Notification, to the queue.
+ It inserts it into the storage containers, creates an corresponding overlay and a container.
+ @param notification
+ The Notification.
+ @param time
+ The time.
+ */
+ void NotificationQueue::addNotification(Notification* notification, const std::time_t & time)
{
- this->text_->setCaption(queueText_);
+ NotificationOverlayContainer* container = new NotificationOverlayContainer;
+ container->overlay = new NotificationOverlay(this, notification);
+ container->notification = notification;
+ container->time = time;
+ std::string timeString = std::ctime(&time);
+ timeString.erase(timeString.length()-1);
+ std::ostringstream stream;
+ stream << (unsigned long)notification;
+ std::string addressString = stream.str() ;
+ container->name = "NotificationOverlay(" + timeString + ")&" + addressString;
+
+ this->containers_.insert(container);
+ this->overlays_[notification] = container;
+ this->addElement(container->overlay);
+ this->size_= this->size_+1;
+
+ container->overlay->scroll(Vector2(0.0,(1.1*this->getFontSize())*(this->getSize()-1)));
}
+
+ /**
+ @brief
+ Removes a container from the queue.
+ @param container
+ A pointer to the container.
+ @return
+ Returns true if successful.
+ */
+ bool NotificationQueue::removeContainer(NotificationOverlayContainer* container)
+ {
+ if(this->size_ == 0) //!< You cannot remove anything if the queue is empty.
+ return false;
+
+ this->removeElement(container->overlay);
+ this->containers_.erase(container);
+ this->overlays_.erase(container->notification);
+ delete container->overlay;
+ delete container;
+ this->size_= this->size_-1;
+
+ return true;
+ }
+
+ /**
+ @brief
+ Clears the queue by removing all containers.
+ */
+ void NotificationQueue::clear(void)
+ {
+ std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin();
+ while(it != this->containers_.end())
+ {
+ this->removeContainer(*it);
+ it = this->containers_.begin(); //TDO: Needed?
+ }
+ }
+
}
Modified: trunk/src/orxonox/overlays/notifications/NotificationQueue.h
===================================================================
--- trunk/src/orxonox/overlays/notifications/NotificationQueue.h 2009-04-07 22:58:47 UTC (rev 2908)
+++ trunk/src/orxonox/overlays/notifications/NotificationQueue.h 2009-04-07 23:07:27 UTC (rev 2909)
@@ -26,53 +26,186 @@
*
*/
+/**
+ @file NotificationQueue.h
+ @brief Definition of the NotificationQueue class.
+*/
+
#ifndef _NotificationOueue_H__
#define _NotificationOueue_H__
#include "OrxonoxPrereqs.h"
+
+#include <string>
+#include <set>
+#include <OgreOverlayManager.h>
#include <OgreTextAreaOverlayElement.h>
+#include <OgrePanelOverlayElement.h>
+#include <map>
+#include <ctime>
-#include "orxonox/overlays/OverlayText.h"
+#include "orxonox/overlays/OverlayGroup.h"
#include "orxonox/objects/Tickable.h"
-#include <string>
+#include "NotificationManager.h"
namespace orxonox
{
+
+ //! Container to allow easy handling.
+ struct NotificationOverlayContainer
+ {
+ 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
+ { 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:
+ <NotificationQueue
+ name = "SuperQueue" //Name of your OverlayQueue.
+ maxSize = "5" //The maximum size of Notifications displayed.
+ notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 5)
+ 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 _OrxonoxExport NotificationQueue : public OverlayText, public Tickable
+
+ class _OrxonoxExport NotificationQueue : public OverlayGroup, public Tickable
{
- public:
- NotificationQueue(BaseObject* creator);
- virtual ~NotificationQueue();
+
+ public:
+ NotificationQueue(BaseObject* creator);
+ 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 Returns the maximum number of Notifications displayed.
+ @return Returns maximum size.
+ */
+ inline 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
+ { 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
+ { return this->notificationLength_; }
+ /**
+ @brief Returns the time interval the Notification is displayed.
+ @return Returns the display time.
+ */
+ inline int getDisplayTime() const
+ { return this->displayTime_; }
+ /**
+ @brief Returns the position of the NotificationQueue.
+ @return Returns the position.
+ */
+ 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.
+ @return Retuns a set of string holding the different targets.
+ */
+ inline const std::set<std::string> & getTargetsSet()
+ { return this->targets_; }
+ bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets.
+
+ /**
+ @brief Sets the position of the NotificationQueue.
+ @param pos The position.
+ */
+ inline void setPosition(Vector2 pos)
+ { this->position_ = pos; this->positionChanged(); }
- static NotificationQueue* queue_s; //TDO Singleton? oder im level.
+ 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 Notifications displayed.
+ static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time.
+ static const float DEFAULT_FONT_SIZE = 0.025; //!< The default font size.
- virtual void XMLPort(Element& xmlElement, XMLPort::Mode mode);
+ 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.
+ Vector2 position_; //!< The position of the NotificationQueue.
+
+ std::set<std::string> targets_; //!< The targets the Queue displays Notifications of.
+
+ 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.
+
+ 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.
+
+ void initialize(void); //!< Initializes the object.
+ void setDefaults(void); //!< Helper method to set the default values.
+
+ 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 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.
- virtual void tick(float dt);
-
- void update(void);
-
- int getLength(void) const
- { return this->length_; }
- int getWidth(void) const
- { return this->width_; }
-
- void setQueueText(const std::string & text);
- bool setLength(int length);
- bool setWidth(int width);
-
- private:
- Ogre::UTFString queueText_;
- int length_;
- int width_;
-
+ 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 clear(void); //!< Clear the queue.
+
};
}
More information about the Orxonox-commit
mailing list