Changeset 7403 for code/trunk/src
- Timestamp:
- Sep 11, 2010, 10:20:44 AM (14 years ago)
- Location:
- code/trunk
- Files:
-
- 2 deleted
- 24 edited
Legend:
- Unmodified
- Added
- Removed
-
code/trunk
- Property svn:mergeinfo changed
/code/branches/notifications (added) merged: 7319,7324,7326,7338-7343,7348-7349,7351,7354-7355,7358-7360,7362,7395,7398-7400
- Property svn:mergeinfo changed
-
code/trunk/src/libraries/core/GUIManager.cc
r7401 r7403 99 99 GUIManager* GUIManager::singletonPtr_s = 0; 100 100 101 SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, true);101 SetConsoleCommand("showGUI", &GUIManager::showGUI).defaultValue(1, false).defaultValue(2, false); 102 102 SetConsoleCommand("hideGUI", &GUIManager::hideGUI); 103 103 … … 237 237 @param bHidePrevious 238 238 If true all displayed GUIs on the stack, that are below this GUI are hidden. 239 @param bNoInput 240 If true the GUI is transparent to input. 239 241 240 242 The function executes the Lua function with the same name in case the GUIManager is ready. 241 243 */ 242 /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious )243 { 244 GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + " )");244 /*static*/ void GUIManager::showGUI(const std::string& name, bool bHidePrevious, bool bNoInput) 245 { 246 GUIManager::getInstance().executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ")"); 245 247 } 246 248 … … 249 251 Hack-ish. Needed for GUIOverlay. 250 252 */ 251 void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious )252 { 253 this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + ptr + ")");253 void GUIManager::showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious, bool bNoInput) 254 { 255 this->executeCode("showMenuSheet(\"" + name + "\", " + multi_cast<std::string>(bHidePrevious) + ", " + multi_cast<std::string>(bNoInput) + ", " + ptr + ")"); 254 256 } 255 257 -
code/trunk/src/libraries/core/GUIManager.h
r7401 r7403 80 80 81 81 void loadGUI(const std::string& name); 82 static void showGUI(const std::string& name, bool bHidePrevious = false );83 void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false );82 static void showGUI(const std::string& name, bool bHidePrevious = false, bool bNoInput = false); 83 void showGUIExtra(const std::string& name, const std::string& ptr, bool bHidePrevious = false, bool bNoInput = false); 84 84 static void hideGUI(const std::string& name); 85 85 void keyESC(); -
code/trunk/src/modules/notifications/CMakeLists.txt
r7193 r7403 3 3 NotificationDispatcher.cc 4 4 NotificationManager.cc 5 NotificationOverlay.cc6 5 NotificationQueue.cc 7 6 ) … … 13 12 FIND_HEADER_FILES 14 13 TOLUA_FILES 14 NotificationManager.h 15 NotificationQueue.h 15 16 PCH_FILE 16 17 NotificationsPrecompiledHeaders.h 17 18 LINK_LIBRARIES 18 19 orxonox 19 overlays20 20 SOURCE_FILES ${NOTIFICATIONS_SRC_FILES} 21 21 ) -
code/trunk/src/modules/notifications/Notification.cc
r7401 r7403 35 35 36 36 #include "core/CoreIncludes.h" 37 #include "network/NetworkFunction.h" 37 38 #include "NotificationManager.h" 38 39 … … 42 43 CreateUnloadableFactory(Notification); 43 44 45 registerMemberNetworkFunction(Notification, sendHelper); 46 44 47 /** 45 48 @brief 46 49 Default constructor. Initializes the object. 50 @param creator 51 The object that created this Notification 47 52 */ 48 Notification::Notification(BaseObject* creator) : BaseObject(creator) 53 Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator) 49 54 { 50 55 RegisterObject(Notification); 51 56 this->initialize(); 57 this->registerVariables(); 52 58 } 53 59 … … 56 62 Constructor. Creates a Notification with the input message. 57 63 @param creator 58 The object that created this Notification64 The creator. 59 65 @param message 60 66 The message of the Notification. 61 67 */ 62 Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator) 68 Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator) 63 69 { 64 70 RegisterObject(Notification); 65 71 this->initialize(); 66 72 this->message_ = message; 73 this->registerVariables(); 67 74 } 68 75 … … 87 94 } 88 95 89 /** 90 @brief 91 Sends the Notification to the Notificationmanager, with sender NetificationManager::NONE. 92 @return 93 Returns true if successful. 94 */ 95 bool Notification::send(void) 96 void Notification::registerVariables(void) 96 97 { 97 return this->send(NotificationManager::NONE); 98 registerVariable(this->message_); 99 registerVariable(this->sender_); 100 registerVariable(this->sent_); 98 101 } 99 102 … … 106 109 Returns true if successful. 107 110 */ 108 bool Notification::send(const std::string & sender) 111 bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE) 112 { 113 114 if(GameMode::isStandalone()) 115 { 116 this->sendHelper(sender); 117 } 118 else 119 { 120 callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, sender); 121 } 122 123 return true; 124 } 125 126 bool Notification::sendHelper(const std::string& sender) 109 127 { 110 128 if(this->isSent()) //TODO: Needed? 111 129 return false; 112 130 113 131 this->sender_ = sender; 114 132 bool successful = NotificationManager::getInstance().registerNotification(this); -
code/trunk/src/modules/notifications/Notification.h
r7164 r7403 39 39 #include <string> 40 40 #include "core/BaseObject.h" 41 #include "network/synchronisable/Synchronisable.h" 41 42 42 43 namespace orxonox … … 49 50 Damian 'Mozork' Frick 50 51 */ 51 class _NotificationsExport Notification : public BaseObject 52 class _NotificationsExport Notification : public BaseObject, public Synchronisable 52 53 { 53 54 public: … … 56 57 virtual ~Notification(); 57 58 58 bool send( void); //!< Sends the Notification to the Notificationmanager, with sender NotificationManager::NONE;59 bool send (const std::string & sender); //!< Sends the Notification to the Notificationmanager.59 bool send(unsigned int clientId, const std::string & sender); //!< Sends the Notification to the Notificationmanager. 60 bool sendHelper(const std::string& sender); 60 61 61 62 /** … … 83 84 84 85 void initialize(void); 86 void registerVariables(void); 85 87 86 88 }; -
code/trunk/src/modules/notifications/NotificationDispatcher.cc
r7285 r7403 39 39 #include "Notification.h" 40 40 #include "NotificationManager.h" 41 #include "interfaces/PlayerTrigger.h" 42 #include "infos/PlayerInfo.h" 43 #include "worldentities/pawns/Pawn.h" 41 44 42 45 namespace orxonox … … 86 89 @brief 87 90 Dispatches a Notification with a message supplied by the createNotificationMessage() method, which can be overloaded. 91 @param clientId 92 The id of the client the notification should be dispatched to. 88 93 */ 89 void NotificationDispatcher::dispatch( void)94 void NotificationDispatcher::dispatch(unsigned int clientId) 90 95 { 91 96 const std::string message = this->createNotificationMessage(); 92 97 Notification* notification = new Notification(this, message); 93 98 94 notification->send( this->getSender());99 notification->send(clientId, this->getSender()); 95 100 } 96 101 … … 103 108 Returns true if the NotificationDispatcher was successfully triggered. 104 109 */ 105 bool NotificationDispatcher::trigger(bool triggered )110 bool NotificationDispatcher::trigger(bool triggered, BaseObject* trigger) 106 111 { 107 112 if(!triggered || !this->isActive()) // If the NotificationDispatcher is inactive it cannot be executed. … … 110 115 COUT(4) << "NotificationDispatcher (&" << this << ") triggered." << std::endl; 111 116 112 this->dispatch(); 117 PlayerTrigger* pTrigger = orxonox_cast<PlayerTrigger*>(trigger); 118 Pawn* pawn = NULL; 119 120 // If the trigger is a PlayerTrigger. 121 if(pTrigger != NULL) 122 { 123 if(!pTrigger->isForPlayer()) //!< The PlayerTrigger is not exclusively for Pawns which means we cannot extract one. 124 return false; 125 else 126 pawn = pTrigger->getTriggeringPlayer(); 127 } 128 else 129 return false; 130 131 if(pawn == NULL) 132 { 133 COUT(4) << "The QuestEffectBeacon was triggered by an entity other than a Pawn. (" << trigger->getIdentifier()->getName() << ")" << std::endl; 134 return false; 135 } 136 137 //! Extract the PlayerInfo from the Pawn. 138 PlayerInfo* player = pawn->getPlayer(); 139 140 if(player == NULL) 141 { 142 COUT(3) << "The PlayerInfo* is NULL." << std::endl; 143 return false; 144 } 145 146 this->dispatch(player->getClientID()); 113 147 114 148 return true; -
code/trunk/src/modules/notifications/NotificationDispatcher.h
r7285 r7403 65 65 { return this->sender_; } 66 66 67 void dispatch( void); //!< Dispatches a specific Notification.68 bool trigger(bool triggered ); //!< Is called when the NotificationDispatcher is triggered.67 void dispatch(unsigned int clientId); //!< Dispatches a specific Notification. 68 bool trigger(bool triggered, BaseObject* trigger); //!< Is called when the NotificationDispatcher is triggered. 69 69 70 70 protected: -
code/trunk/src/modules/notifications/NotificationManager.cc
r7284 r7403 28 28 29 29 /** 30 @file 30 @file NotificationManager.cc 31 31 @brief Implementation of the NotificationManager class. 32 32 */ … … 34 34 #include "NotificationManager.h" 35 35 36 #include <set> 37 36 #include "core/command/ConsoleCommand.h" 37 #include "core/CoreIncludes.h" 38 #include "core/GUIManager.h" 39 #include "core/LuaState.h" 38 40 #include "util/ScopedSingletonManager.h" 39 #include "core/CoreIncludes.h" 41 42 #include "interfaces/NotificationListener.h" 43 40 44 #include "Notification.h" 41 #include "interfaces/NotificationListener.h" 45 #include "NotificationQueue.h" 46 47 #include "ToluaBindNotifications.h" 42 48 43 49 namespace orxonox … … 47 53 const std::string NotificationManager::NONE("none"); 48 54 49 ManageScopedSingleton(NotificationManager, ScopeID::Root, false); 55 // Register tolua_open function when loading the library. 56 DeclareToluaInterface(Notifications); 57 58 ManageScopedSingleton(NotificationManager, ScopeID::Graphics, false); 59 60 SetConsoleCommand("enterEditMode", &NotificationManager::enterEditMode); 50 61 51 62 /** … … 58 69 59 70 this->highestIndex_ = 0; 71 72 ModifyConsoleCommand("enterEditMode").setObject(this); 73 74 COUT(3) << "NotificatioManager created." << std::endl; 60 75 } 61 76 … … 66 81 NotificationManager::~NotificationManager() 67 82 { 68 83 ModifyConsoleCommand("enterEditMode").setObject(NULL); 84 85 COUT(3) << "NotificationManager destroyed." << std::endl; 86 } 87 88 /** 89 @brief 90 Is called before the object is destroyed. 91 */ 92 void NotificationManager::preDestroy(void) 93 { 94 // Destroys all NotificationQueues that have been registered with the NotificationManager. 95 for(std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.begin(); it != this->queues_.end(); ) 96 { 97 NotificationQueue* queue = (*it).second; 98 it++; 99 queue->destroy(); 100 } 101 this->queues_.clear(); 69 102 } 70 103 … … 79 112 bool NotificationManager::registerNotification(Notification* notification) 80 113 { 81 82 if(notification == NULL) //!< A NULL-Notification cannot be registered. 83 return false; 114 assert(notification); 84 115 85 116 std::time_t time = std::time(0); //TODO: Doesn't this expire? //!< Get current time. 86 117 87 this->allNotificationsList_.insert(std::pair<std::time_t,Notification*>(time,notification)); 88 89 if(notification->getSender() == NONE) //!< If the sender has no specific name, then the Notification is only added to the list of all Notifications. 118 // Add the Notification to the list that holds all Notifications. 119 this->allNotificationsList_.insert(std::pair<std::time_t, Notification*>(time, notification)); 120 121 if(notification->getSender() == NotificationManager::NONE) // If the sender has no specific name, then the Notification is only added to the list of all Notifications. 90 122 return true; 91 123 92 124 bool all = false; 93 if(notification->getSender() == ALL) //!<If all are the sender, then the Notifications is added to every NotificationListener.125 if(notification->getSender() == NotificationManager::ALL) // If all are the sender, then the Notifications is added to every NotificationListener. 94 126 all = true; 95 127 96 //!< Insert the notification in all listeners that have its sender as target. 97 for(std::map<NotificationListener*,int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) //!< Iterate through all listeners. 98 { 99 std::set<std::string> set = it->first->getTargetsSet(); 100 if(all || set.find(notification->getSender()) != set.end() || set.find(ALL) != set.end()) //TODO: Make sure this works. 128 // Insert the Notification in all NotificationListeners that have its sender as target. 129 for(std::map<NotificationListener*, unsigned int>::iterator it = this->listenerList_.begin(); it != this->listenerList_.end(); it++) // Iterate through all NotificationListeners. 130 { 131 std::set<std::string, NotificationListenerStringCompare> set = it->first->getTargetsSet(); 132 bool bAll = set.find(NotificationManager::ALL) != set.end(); 133 // If either the Notification has as sender 'all', the NotificationListener displays all Notifications or the NotificationListener has the sender of the Notification as target. 134 if(all || bAll || set.find(notification->getSender()) != set.end()) 101 135 { 102 this->notificationLists_[it->second]->insert(std::pair<std::time_t,Notification*>(time,notification)); //!< Insert the Notification in the Notifications list of the current NotificationListener. 103 it->first->update(notification, time); //!< Update the listener. 104 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(notification); 105 if(counterIt == this->listenerCounter_.end()) 106 this->listenerCounter_[notification] = 1; 107 else 108 this->listenerCounter_[notification] = counterIt->second + 1; 136 if(!bAll) 137 this->notificationLists_[it->second]->insert(std::pair<std::time_t, Notification*>(time, notification)); // Insert the Notification in the notifications list of the current NotificationListener. 138 it->first->update(notification, time); // Update the NotificationListener. 109 139 } 110 140 } 111 141 112 COUT(4) << "Notification registered with the NotificationManager." << std::endl;142 COUT(4) << "Notification (&" << notification << ") registered with the NotificationManager." << std::endl; 113 143 114 144 return true; … … 117 147 /** 118 148 @brief 119 Unregisters a Notification within the NotificationManager .149 Unregisters a Notification within the NotificationManager for a given NotificationListener. 120 150 @param notification 121 151 A pointer to the Notification to be unregistered. … … 128 158 assert(listener); 129 159 130 // If the Notification was removed from the list of Notifications of the input NotificationListener, the counter for the Notification of the number of NotificationListeners it is present in is decremented. 131 if(this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second))) 132 this->listenerCounter_[notification] = this->listenerCounter_[notification] - 1; 133 134 // If the Notification is no longer present in any of the NotificationListeners it can be removed from the map of all Notifications and be destroyed. 135 if(this->listenerCounter_[notification] == (unsigned int) 0) 136 { 137 this->removeNotification(notification, this->allNotificationsList_); 138 this->listenerCounter_.erase(notification); 139 notification->destroy(); 140 } 141 142 COUT(4) << "Notification unregistered with the NotificationManager." << std::endl; 143 } 144 145 /** 146 @brief 147 Helper method that removes an input notification form an input map. 160 // Remove the Notification from the list of Notifications of the input NotificationListener. 161 this->removeNotification(notification, *(this->notificationLists_.find(this->listenerList_.find(listener)->second)->second)); 162 163 COUT(4) << "Notification (&" << notification << ") unregistered with the NotificationManager from listener (&" << listener << ")" << std::endl; 164 } 165 166 /** 167 @brief 168 Helper method that removes an input Notification form an input map. 148 169 @param notification 149 A pointer to the notification to be removed.170 A pointer to the Notification to be removed. 150 171 @param map 151 The map the notification should be removed from.172 The map the Notification should be removed from. 152 173 @return 153 174 Returns true if successful. … … 174 195 The NotificationListener to be registered. 175 196 @return 176 Returns true if successful. 197 Returns true if successful. Fales if the NotificationListener is already registered. 177 198 */ 178 199 bool NotificationManager::registerListener(NotificationListener* listener) 179 200 { 201 assert(listener); 202 203 // If the NotificationListener is already registered. 204 if(this->listenerList_.find(listener) != this->listenerList_.end()) 205 return false; 206 180 207 this->highestIndex_ += 1; 181 int index = this->highestIndex_; 182 183 this->listenerList_[listener] = index; //!< Add the NotificationListener to the list of listeners. 184 185 std::set<std::string> set = listener->getTargetsSet(); //TODO: Does this work? 186 187 //! If all senders are the target of the listener, then the list of notification for that specific listener is te same as the list of all Notifications. 188 if(set.find(ALL) != set.end()) 189 { 208 unsigned int index = this->highestIndex_; // An identifier that identifies each registered NotificationListener uniquely. 209 210 this->listenerList_[listener] = index; // Add the NotificationListener to the list of NotificationListeners. 211 212 std::set<std::string, NotificationListenerStringCompare> set = listener->getTargetsSet(); 213 214 // If all senders are the target of the NotificationListener, then the list of Notifications for that specific NotificationListener is the same as the list of all Notifications. 215 bool bAll = set.find(NotificationManager::ALL) != set.end(); 216 std::multimap<std::time_t, Notification*>* map; 217 if(bAll) 190 218 this->notificationLists_[index] = &this->allNotificationsList_; 191 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 192 return true; 193 } 194 195 this->notificationLists_[index] = new std::multimap<std::time_t,Notification*>; 196 std::multimap<std::time_t,Notification*> map = *this->notificationLists_[index]; 197 198 //! Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener. 199 for(std::multimap<std::time_t,Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 200 { 201 if(set.find(it->second->getSender()) != set.end()) //!< Checks whether the overlay has the sender of the current notification as target. 219 // Else a new list (resp. multimap) is created and added to the list of Notification lists for NotificationListeners. 220 else 221 { 222 this->notificationLists_[index] = new std::multimap<std::time_t, Notification*>; 223 map = this->notificationLists_[index]; 224 } 225 226 // Iterate through all Notifications to determine whether any of them should belong to the newly registered NotificationListener. 227 for(std::multimap<std::time_t, Notification*>::iterator it = this->allNotificationsList_.begin(); it != this->allNotificationsList_.end(); it++) 228 { 229 if(!bAll && set.find(it->second->getSender()) != set.end()) // Checks whether the listener has the sender of the current Notification as target. 230 map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 231 } 232 233 listener->update(); // Update the listener. 234 235 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 236 237 return true; 238 } 239 240 /** 241 @brief 242 Unregisters a NotificationListener within the NotificationManager. 243 @param listener 244 The NotificationListener to be unregistered. 245 */ 246 void NotificationManager::unregisterListener(NotificationListener* listener) 247 { 248 assert(listener); 249 250 //TODO: Make unsigned int. 251 unsigned int identifier = this->listenerList_.find(listener)->second; 252 std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second; 253 254 // If the map is not the map of all Notifications, make sure all Notifications are unregistered. 255 std::multimap<std::time_t, Notification*>::iterator it = map->begin(); 256 if(map != &this->allNotificationsList_) 257 { 258 while(it != map->end()) 202 259 { 203 map.insert(std::pair<std::time_t, Notification*>(it->first, it->second)); 204 std::map<Notification*, unsigned int>::iterator counterIt = this->listenerCounter_.find(it->second); 205 if(counterIt == this->listenerCounter_.end()) 206 this->listenerCounter_[it->second] = 1; 207 else 208 this->listenerCounter_[it->second] = counterIt->second + 1; 260 this->unregisterNotification(it->second, listener); 261 it = map->begin(); 209 262 } 210 } 211 212 listener->update(); //!< Update the listener. 213 214 COUT(4) << "NotificationListener registered with the NotificationManager." << std::endl; 215 216 return true; 217 } 218 219 /** 220 @brief 221 Unregisters a NotificationListener withing the NotificationManager. 222 */ 223 void NotificationManager::unregisterListener(NotificationListener* listener) 224 { 225 assert(listener); 226 227 int identifier = this->listenerList_.find(listener)->second; 228 std::multimap<std::time_t, Notification*>* map = this->notificationLists_.find(identifier)->second; 229 230 // Make sure all Notifications are removed. 231 std::multimap<std::time_t, Notification*>::iterator it = map->begin(); 232 while(it != map->end()) 233 { 234 this->unregisterNotification(it->second, listener); 235 it = map->begin(); 236 } 237 263 delete map; 264 } 265 266 // Remove the NotificationListener from the list of NotificationListeners. 238 267 this->listenerList_.erase(listener); 268 // Remove the Notifications list that was associated with the input NotificationListener. 239 269 this->notificationLists_.erase(identifier); 240 270 241 // If the map is not the map of all notifications, delete it.242 if(map != &this->allNotificationsList_)243 delete map;244 245 271 COUT(4) << "NotificationListener unregistered with the NotificationManager." << std::endl; 246 272 } … … 248 274 /** 249 275 @brief 250 Fetches the Notifications for a specific NotificationListener in a specified timeframe .276 Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map. 251 277 @param listener 252 278 The NotificationListener the Notifications are fetched for. 253 279 @param map 254 A multimap, in which the notifications are stored.280 A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. 255 281 @param timeFrameStart 256 282 The start time of the timeframe. … … 260 286 Returns true if successful. 261 287 */ 262 bool NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd) 263 { 264 if(listener == NULL || map == NULL) 265 return false; 266 267 std::multimap<std::time_t,Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; //!< The Notifications for the input NotificationListener. 268 269 if(notifications == NULL) //!< Returns NULL, if there are no Notifications. 270 return true; 288 void NotificationManager::getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd) 289 { 290 assert(listener); 291 assert(map); 292 293 std::multimap<std::time_t, Notification*>* notifications = this->notificationLists_[this->listenerList_[listener]]; // All the Notifications for the input NotificationListener. 271 294 272 295 std::multimap<std::time_t,Notification*>::iterator it, itLowest, itHighest; 296 // Iterators pointing to the bounds specified by the specified start and end times of the time frame. 273 297 itLowest = notifications->lower_bound(timeFrameStart); 274 itHighest = notifications->upper_bound(timeFrameStart); 275 276 for(it = itLowest; it != itHighest; it++) //!< Iterate through the Notifications from the start of the time Frame to the end of it. 277 { 278 map->insert(std::pair<std::time_t,Notification*>(it->first,it->second)); //!< Add the found Notifications to the map. 279 } 280 281 return true; 298 itHighest = notifications->upper_bound(timeFrameEnd); 299 300 for(it = itLowest; it != itHighest; it++) // Iterate through the Notifications from the start of the time frame to the end of it. 301 map->insert(std::pair<std::time_t, Notification*>(it->first, it->second)); // Add the found Notifications to the map. 302 } 303 304 /** 305 @brief 306 Enters the edit mode of the NotificationLayer. 307 */ 308 void NotificationManager::enterEditMode(void) 309 { 310 GUIManager::getInstance().hideGUI("NotificationLayer"); 311 GUIManager::getInstance().showGUI("NotificationLayer", false, false); 312 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.enterEditMode()"); 313 } 314 315 /** 316 @brief 317 Registers a NotificationQueue. 318 This makes sure that the NotificationQueue can be attained through lua by name. It also makes sure that the NotificationQueue is destroyed upon destruction of the NotificationManager. 319 @param queue 320 A pointer to the NotificationQueue to be registered. 321 @return 322 Returns true if successful. If e.g. the a NotificationQueue with that name already exists this returns false. 323 */ 324 bool NotificationManager::registerQueue(NotificationQueue* queue) 325 { 326 return this->queues_.insert(std::pair<const std::string, NotificationQueue*>(queue->getName(), queue)).second; 327 } 328 329 /** 330 @brief 331 Unregisters a NotificationQueue. 332 @param queue 333 A pointer to the NotificationQueue to be unregistered. 334 */ 335 void NotificationManager::unregisterQueue(NotificationQueue* queue) 336 { 337 this->queues_.erase(queue->getName()); 338 } 339 340 /** 341 @brief 342 Loads all the NotificationQueues that should exist. 343 */ 344 void NotificationManager::loadQueues(void) 345 { 346 new NotificationQueue("all"); 347 } 348 349 /** 350 @brief 351 Creates a new NotificationQueue. 352 This is used in lua. 353 @param name 354 The name of the new NotificationQueue. 355 */ 356 void NotificationManager::createQueue(const std::string& name) 357 { 358 new NotificationQueue(name); 359 } 360 361 /** 362 @brief 363 Get the NotificationQueue with the input name. 364 @param name 365 The name of the NotificationQueue. 366 @return 367 Returns a pointer to the NotificationQueue with the input name. Returns NULL if no NotificationQueue with such a name exists. 368 */ 369 NotificationQueue* NotificationManager::getQueue(const std::string & name) 370 { 371 std::map<const std::string, NotificationQueue*>::iterator it = this->queues_.find(name); 372 // Returns NULL if no such NotificationQueue exists. 373 if(it == this->queues_.end()) 374 return NULL; 375 376 return (*it).second; 282 377 } 283 378 -
code/trunk/src/modules/notifications/NotificationManager.h
r7164 r7403 28 28 29 29 /** 30 @file 30 @file NotificationManager.h 31 31 @brief Definition of the NotificationManager class. 32 32 */ … … 44 44 #include "core/OrxonoxClass.h" 45 45 46 namespace orxonox 47 { 46 namespace orxonox // tolua_export 47 { // tolua_export 48 48 49 /** 49 50 @brief … … 53 54 Damian 'Mozork' Frick 54 55 */ 55 class _NotificationsExport NotificationManager : public Singleton<NotificationManager>, public OrxonoxClass 56 { 56 class _NotificationsExport NotificationManager // tolua_export 57 : public Singleton<NotificationManager>, public OrxonoxClass 58 { // tolua_export 57 59 friend class Singleton<NotificationManager>; 58 60 public: … … 60 62 virtual ~NotificationManager(); 61 63 64 virtual void preDestroy(void); //!< Is called before the object is destroyed. 65 66 static NotificationManager& getInstance() { return Singleton<NotificationManager>::getInstance(); } // tolua_export 67 62 68 static const std::string ALL; //!< Static string to indicate a sender that sends to all NotificationListeners. 63 69 static const std::string NONE; //!< Static string to indicare a sender that sends to no specific NotificationListener. 64 70 65 71 bool registerNotification(Notification* notification); //!< Registers a Notification within the NotificationManager. 66 void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager .72 void unregisterNotification(Notification* notification, NotificationListener* listener); //!< Unregisters a Notification within the NotificationManager for a given NotificationListener. 67 73 bool registerListener(NotificationListener* listener); //!< Registers a NotificationListener within the NotificationManager. 68 74 void unregisterListener(NotificationListener* listener); //!< Unregisters a NotificationListener withing the NotificationManager. 69 75 70 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Returns the Notifications for a specific NotificationListener in a specified timeframe.76 void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, const std::time_t & timeFrameStart, const std::time_t & timeFrameEnd); //!< Fetches the Notifications for a specific NotificationListener in a specified timeframe and stores them in the input map. 71 77 72 78 /** 73 @brief Fetches the Notifications for a specific NotificationListener starting at a specified time.79 @brief Fetches the Notifications for a specific NotificationListener in a timeframe from now-timeDelay to now and stores them in the input map. 74 80 @param listener The NotificationListener the Notifications are fetched for. 75 @param map A multimap, in which the notifications are stored. 76 @param timeFrameStart The start time the Notifications are fetched from. 77 @return Returns true if successful. 78 */ 79 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, const std::time_t & timeFrameStart) 80 { return this->getNotifications(listener, map, timeFrameStart, std::time(0)); } 81 /** 82 @brief Fetches the Notifications for a specific NotificationListener starting at a specified timespan before now. 83 @param listener The NotificationListener the Notifications are fetched for. 84 @param map A multimap, in which the notifications are stored. 81 @param map A pointer to a multimap, in which the notifications are stored. The map needs to have been allocated. 85 82 @param timeDelay The timespan. 86 83 @return Returns true if successful. 87 84 */ 88 bool getNotifications(NotificationListener* listener, std::multimap<std::time_t,Notification*>* map, int timeDelay) 89 { return this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); } 85 void getNotifications(NotificationListener* listener, std::multimap<std::time_t, Notification*>* map, int timeDelay) 86 { this->getNotifications(listener, map, std::time(0)-timeDelay, std::time(0)); } 87 88 void enterEditMode(void); //!< Enters the edit mode of the NotificationLayer. 89 90 bool registerQueue(NotificationQueue* queue); //!< Registers a NotificationQueue. 91 void unregisterQueue(NotificationQueue* queue); //!< Unregisters a NotificationQueue. 92 93 // tolua_begin 94 void loadQueues(void); //!< Loads all the NotificationQueues that should exist. 95 void createQueue(const std::string& name); //!< Creates a new NotificationQueue. 96 orxonox::NotificationQueue* getQueue(const std::string & name); //!< Get the NotificationQueue with the input name. 97 // tolua_end 90 98 91 99 private: 92 100 static NotificationManager* singletonPtr_s; 93 101 94 int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice.102 unsigned int highestIndex_; //!< This variable holds the highest index (resp. key) in notificationLists_s, to secure that no key appears twice. 95 103 96 std::multimap<std::time_t,Notification*> allNotificationsList_; //!< Container where all notifications are stored. 97 std::map<NotificationListener*,int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. 98 std::map<int,std::multimap<std::time_t,Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. 99 std::map<Notification*, unsigned int> listenerCounter_; //!< A container to store the number of NotificationListeners a Notification is registered with. 104 std::multimap<std::time_t, Notification*> allNotificationsList_; //!< Container where all Notifications are stored. 105 std::map<NotificationListener*, unsigned int> listenerList_; //!< Container where all NotificationListeners are stored with a number as identifier. 106 std::map<int,std::multimap<std::time_t, Notification*>*> notificationLists_; //!< Container where all Notifications, for each identifier (associated with a NotificationListener), are stored. 100 107 101 bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input notification form an input map.108 std::map<const std::string, NotificationQueue*> queues_; //!< The list of NotificationQueues created by the NotificationManager. 102 109 103 };110 bool removeNotification(Notification* notification, std::multimap<std::time_t, Notification*>& map); //!< Helper method that removes an input Notification form an input map. 104 111 105 } 112 }; // tolua_export 113 114 } // tolua_export 106 115 107 116 #endif /* _NotificationManager_H__ */ -
code/trunk/src/modules/notifications/NotificationQueue.cc
r7401 r7403 28 28 29 29 /** 30 @file 30 @file NotificationQueue.cc 31 31 @brief Implementation of the NotificationQueue class. 32 32 */ … … 34 34 #include "NotificationQueue.h" 35 35 36 #include <map> 37 #include <sstream> 38 39 #include "core/CoreIncludes.h" 40 #include "core/GUIManager.h" 41 #include "core/LuaState.h" 36 42 #include "util/Convert.h" 37 #include "core/CoreIncludes.h" 38 #include "core/XMLPort.h" 39 #include "NotificationOverlay.h" 40 #include "NotificationManager.h" 43 #include "util/SubString.h" 44 45 #include "Notification.h" 41 46 42 47 namespace orxonox 43 48 { 44 49 45 CreateFactory(NotificationQueue);46 47 const std::string NotificationQueue::DEFAULT_FONT("VeraMono");48 const Vector2 NotificationQueue::DEFAULT_POSITION(0.0,0.0);49 const float NotificationQueue::DEFAULT_FONT_SIZE = 0.025f;50 51 50 /** 52 51 @brief 53 52 Constructor. Creates and initializes the object. 54 */ 55 NotificationQueue::NotificationQueue(BaseObject* creator) : OverlayGroup(creator) 53 @param name 54 The name of the new NotificationQueue. 55 @param senders 56 The senders that are targets of this NotificationQueue, i.e. the names of senders whose Notifications this NotificationQueue displays. 57 The senders need to be seperated by commas. 58 @param size 59 The size (the maximum number of displayed Notifications) of this NotificationQueue. 60 @param displayTime 61 The time during which a Notification is (at most) displayed. 62 */ 63 NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, unsigned int displayTime) 56 64 { 57 65 this->registered_ = false; 58 66 59 RegisterObject(NotificationQueue); 60 this->initialize(); 61 } 62 63 /** 64 @brief 65 Destructor. 66 */ 67 NotificationQueue::~NotificationQueue() 68 { 69 this->targets_.clear(); 70 this->clear(); 71 72 if(this->registered_) 73 NotificationManager::getInstance().unregisterListener(this); 74 } 75 76 /** 77 @brief 78 Initializes the object. 79 Registers the object, initializes variables, sets default values and registers the queue with the NotificationManager. 80 */ 81 void NotificationQueue::initialize(void) 82 { 67 RegisterRootObject(NotificationQueue); 68 69 // Initialize. 83 70 this->size_ = 0; 84 71 this->tickTime_ = 0.0; 85 72 86 NotificationManager::getInstance().registerListener(this); 73 // Sets the input values. 74 this->setTargets(senders); 75 this->name_ = name; 76 this->maxSize_ = size; 77 this->setDisplayTime(displayTime); 78 79 //TODO: Destroy if registration fails? 80 81 // Register the NotificationQueue with the NotificationManager. 82 bool queueRegistered = NotificationManager::getInstance().registerQueue(this); 87 83 this->registered_ = true; 88 } 89 90 /** 91 @brief 92 Sets the defaults. 93 */ 94 void NotificationQueue::setDefaults(void) 95 { 96 this->setMaxSize(DEFAULT_SIZE); 97 this->setNotificationLength(DEFAULT_LENGTH); 98 this->setDisplayTime(DEFAULT_DISPLAY_TIME); 99 this->setPosition(DEFAULT_POSITION); 100 101 this->setTargets(NotificationManager::ALL); 102 103 this->setFontSize(DEFAULT_FONT_SIZE); 104 this->setFont(DEFAULT_FONT); 105 } 106 107 /** 108 @brief 109 Method for creating a NotificationQueue object through XML. 110 */ 111 void NotificationQueue::XMLPort(Element& xmlelement, XMLPort::Mode mode) 112 { 113 SUPER(NotificationQueue, XMLPort, xmlelement, mode); 114 115 this->setDefaults(); 116 117 XMLPortParam(NotificationQueue, "maxSize", setMaxSize, getMaxSize, xmlelement, mode); 118 XMLPortParam(NotificationQueue, "notificationLength", setNotificationLength, getNotificationLength, xmlelement, mode); 119 XMLPortParam(NotificationQueue, "displayTime", setDisplayTime, getDisplayTime, xmlelement, mode); 120 XMLPortParam(NotificationQueue, "targets", setTargets, getTargets, xmlelement, mode); 121 XMLPortParam(NotificationQueue, "font", setFont, getFont, xmlelement, mode); 122 XMLPortParam(NotificationQueue, "fontSize", setFontSize, getFontSize, xmlelement, mode); 123 XMLPortParam(NotificationQueue, "position", setPosition, getPosition, xmlelement, mode); 84 if(!queueRegistered) // If the registration has failed. 85 { 86 this->registered_ = false; 87 COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl; 88 return; 89 } 90 91 this->create(); // Creates the NotificationQueue in lua. 92 93 // register the NotificationQueue as NotificationListener with the NotificationManager. 94 bool listenerRegistered = NotificationManager::getInstance().registerListener(this); 95 if(!listenerRegistered) // If the registration has failed. 96 { 97 this->registered_ = false; 98 // Remove the NotificationQueue in lua. 99 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")"); 100 NotificationManager::getInstance().unregisterQueue(this); 101 COUT(1) << "Error: Notification Queue '" << this->getName() << "' could not be registered." << std::endl; 102 return; 103 } 124 104 125 105 COUT(3) << "NotificationQueue '" << this->getName() << "' created." << std::endl; 106 } 107 108 /** 109 @brief 110 Destructor. 111 */ 112 NotificationQueue::~NotificationQueue() 113 { 114 this->targets_.clear(); 115 116 if(this->registered_) // If the 117 { 118 this->clear(); 119 120 // Unregister with the NotificationManager. 121 NotificationManager::getInstance().unregisterListener(this); 122 NotificationManager::getInstance().unregisterQueue(this); 123 124 // Remove the NotificationQueue in lua. 125 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeQueue(\"" + this->getName() + "\")"); 126 } 127 } 128 129 /** 130 @brief 131 Creates the NotificationQueue in lua. 132 */ 133 void NotificationQueue::create(void) 134 { 135 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")"); 126 136 } 127 137 … … 134 144 void NotificationQueue::tick(float dt) 135 145 { 136 this->tickTime_ += dt; // !<Add the time interval that has passed to the time counter.137 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.138 { 139 this->timeLimit_.time = std::time(0)-this->displayTime_; // !<Container containig the current time.140 141 std::multiset<Notification OverlayContainer*, NotificationOverlayContainerCompare>::iterator it;142 it = this->containers_.begin();143 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.146 this->tickTime_ += dt; // Add the time interval that has passed to the time counter. 147 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. 148 { 149 this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time. 150 151 std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin(); 152 // Iterate through all elements whose creation time is smaller than the current time minus the display time. 153 while(it != this->ordering_.upper_bound(&this->timeLimit_)) 144 154 { 145 this->removeContainer(*it);146 this->scroll(Vector2(0.0f,-(1.1f*this->getFontSize())));147 it = this->containers_.begin(); //TODO: Needed?155 NotificationContainer* temp = *it; 156 it++; 157 this->remove(temp); // Remove the Notifications that have expired. 148 158 } 149 159 150 this->tickTime_ = 0.0f; //!<Reset time counter.160 this->tickTime_ = this->tickTime_ - (int)this->tickTime_; // Reset time counter. 151 161 } 152 162 } … … 155 165 @brief 156 166 Updates the NotificationQueue. 157 Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting the inthe queue.167 Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue. 158 168 */ 159 169 void NotificationQueue::update(void) … … 161 171 this->clear(); 162 172 163 std::multimap<std::time_t,Notification*>* notifications = new std::multimap<std::time_t,Notification*>; 164 if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) //!< Get the Notifications sent in the interval form now to minus the display time. 165 { 166 COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl; 167 return; 168 } 169 170 if(notifications->empty()) 171 return; 172 173 for(std::multimap<std::time_t,Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) //!> Add all Notifications. 174 { 175 this->addNotification(it->second, it->first); 173 std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>; 174 // Get the Notifications sent in the interval from now to now minus the display time. 175 NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_); 176 177 if(!notifications->empty()) 178 { 179 // Add all Notifications. 180 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) 181 this->push(it->second, it->first); 176 182 } 177 183 … … 191 197 void NotificationQueue::update(Notification* notification, const std::time_t & time) 192 198 { 193 this->addNotification(notification, time); 194 195 std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it; 196 while(this->getSize() > this->getMaxSize()) 197 { 198 it = this->containers_.begin(); 199 this->removeContainer(*it); 200 this->scroll(Vector2(0.0f,-(1.1f*this->getFontSize()))); 201 } 202 203 COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notifications has been added." << std::endl; 199 this->push(notification, time); 200 201 COUT(4) << "NotificationQueue '" << this->getName() << "' updated. A new Notification has been added." << std::endl; 202 } 203 204 /** 205 @brief 206 Adds (pushes) a Notification to the NotificationQueue. 207 It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI. 208 @param notification 209 The Notification to be pushed. 210 @param time 211 The time when the Notification has been sent. 212 */ 213 void NotificationQueue::push(Notification* notification, const std::time_t & time) 214 { 215 NotificationContainer* container = new NotificationContainer; 216 container->notification = notification; 217 container->time = time; 218 219 // If the maximum size of the NotificationQueue has been reached the last (least recently added) Notification is removed. 220 if(this->getSize() >= this->getMaxSize()) 221 this->pop(); 222 223 this->size_++; 224 225 this->ordering_.insert(container); 226 // Insert the Notification at the begin of the list (vector, actually). 227 this->notifications_.insert(this->notifications_.begin(), container); 228 229 // Push the Notification to the GUI. 230 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); 231 } 232 233 /** 234 @brief 235 Removes (pops) the least recently added Notification form the NotificationQueue. 236 */ 237 void NotificationQueue::pop(void) 238 { 239 NotificationContainer* container = this->notifications_.back(); 240 this->ordering_.erase(container); 241 this->notifications_.pop_back(); 242 243 this->size_--; 244 245 delete container; 246 247 // Pops the Notification from the GUI. 248 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")"); 249 } 250 251 /** 252 @brief 253 Removes the Notification that is stored in the input NotificationContainer. 254 @param container 255 The NotificationContainer with the Notification to be removed. 256 */ 257 void NotificationQueue::remove(NotificationContainer* container) 258 { 259 std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container); 260 // Get the index at which the Notification is. 261 std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin (); 262 this->ordering_.erase(container); 263 this->notifications_.erase(it); 264 265 this->size_--; 266 267 delete container; 268 269 // Removes the Notification from the GUI. 270 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")"); 271 } 272 273 /** 274 @brief 275 Clears the NotificationQueue by removing all NotificationContainers. 276 */ 277 void NotificationQueue::clear(void) 278 { 279 this->ordering_.clear(); 280 // Delete all NotificationContainers in the list. 281 for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++) 282 delete *it; 283 284 this->notifications_.clear(); 285 286 this->size_ = 0; 287 288 // Clear the NotificationQueue in the GUI. 289 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")"); 290 } 291 292 /** 293 @brief 294 Sets the name of the NotificationQueue. 295 @param name 296 The name to be set. 297 */ 298 void NotificationQueue::setName(const std::string& name) 299 { 300 this->name_ = name; 204 301 } 205 302 … … 209 306 @param size 210 307 The size to be set. 211 @return 212 Returns true if successful. 213 */ 214 bool NotificationQueue::setMaxSize(int size) 215 { 216 if(size < 0) 217 return false; 308 */ 309 void NotificationQueue::setMaxSize(unsigned int size) 310 { 311 if(this->maxSize_ == size) 312 return; 313 218 314 this->maxSize_ = size; 219 this->update(); 220 return true; 221 } 222 223 /** 224 @brief 225 Sets the maximum number of characters a Notification message displayed by this queue is allowed to have. 226 @param length 227 The length to be set. 228 @return 229 Returns true if successful. 230 */ 231 bool NotificationQueue::setNotificationLength(int length) 232 { 233 if(length < 0) 234 return false; 235 this->notificationLength_ = length; 236 this->update(); 237 return true; 315 316 if(this->registered_) 317 this->update(); 238 318 } 239 319 … … 246 326 Returns true if successful. 247 327 */ 248 bool NotificationQueue::setDisplayTime(int time) 249 { 250 if(time < 0) 251 return false; 328 void NotificationQueue::setDisplayTime(unsigned int time) 329 { 330 if(this->displayTime_ == time) 331 return; 332 252 333 this->displayTime_ = time; 253 this->update(); 254 return true; 255 } 256 257 /** 258 @brief 259 Produces all targets concatinated as string, with kommas (',') as seperators. 260 @param string 261 Pointer to a string which will be used by the method to fill with the concatination of the targets. 334 335 if(this->registered_) 336 this->update(); 337 } 338 339 /** 340 @brief 341 Produces all targets of the NotificationQueue concatinated as string, with kommas (',') as seperators. 262 342 @return 263 Returns true if successful. 264 */ 265 bool NotificationQueue::getTargets(std::string* string) const 266 { 267 if(string == NULL) 268 { 269 COUT(4) << "Input string must have memory allocated." << std::endl; 270 return false; 271 } 272 string->clear(); 343 Returns the targets as a string. 344 */ 345 const std::string& NotificationQueue::getTargets(void) const 346 { 347 std::stringstream stream; 273 348 bool first = true; 274 for(std::set<std::string>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) //!< Iterate through the set of targets. 349 // Iterate through the set of targets. 350 for(std::set<std::string, NotificationListenerStringCompare>::const_iterator it = this->targets_.begin(); it != this->targets_.end(); it++) 275 351 { 276 352 if(!first) 277 { 278 *string += ','; 279 } 353 stream << ", "; 280 354 else 281 {282 355 first = false; 283 } 284 *string += *it; 285 } 286 287 return true; 288 } 289 290 /** 291 @brief 292 Sets the targets of the queue. 356 stream << *it; 357 } 358 359 return *(new std::string(stream.str())); 360 } 361 362 /** 363 @brief 364 Sets the targets of the NotificationQueue. 293 365 The targets are the senders whose Notifications are displayed in this queue. 294 366 @param targets 295 367 Accepts a string of targets, each seperated by commas (','), spaces are ignored. 296 @return 297 Returns true if successful. 298 */ 299 bool NotificationQueue::setTargets(const std::string & targets) 368 */ 369 void NotificationQueue::setTargets(const std::string & targets) 300 370 { 301 371 this->targets_.clear(); 302 372 303 std::string* pTemp; 304 unsigned int index = 0; 305 while( index < targets.size() ) //!< Go through the string, character by character until the end is reached. 306 { 307 pTemp = new std::string(); 308 while(index < targets.size() && targets[index] != ',' && targets[index] != ' ') 309 { 310 *pTemp += targets[index]; 311 index++; 312 } 313 index++; 314 this->targets_.insert(*pTemp); 315 } 316 317 return true; 318 } 319 320 /** 321 @brief 322 Sets the font size. 323 @param size 324 The font size. 325 @return 326 Returns true if successful. 327 */ 328 bool NotificationQueue::setFontSize(float size) 329 { 330 if(size <= 0) 331 return false; 332 this->fontSize_ = size; 333 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font size for each overlay. 334 { 335 it->second->overlay->setFontSize(size); 336 } 337 return true; 338 } 339 340 /** 341 @brief 342 Sets the font. 343 @param font 344 The font. 345 @return 346 Returns true if successful. 347 */ 348 bool NotificationQueue::setFont(const std::string & font) 349 { 350 this->font_ = font; 351 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); it++) //!< Set the font for each overlay. 352 { 353 it->second->overlay->setFont(font); 354 } 355 return true; 356 } 357 358 /** 359 @brief 360 Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector. 361 @param pos 362 The vector the NotificationQueue is scrolled. 363 */ 364 void NotificationQueue::scroll(const Vector2 pos) 365 { 366 for (std::map<Notification*, NotificationOverlayContainer*>::iterator it = this->overlays_.begin(); it != this->overlays_.end(); ++it) //!< Scroll each overlay. 367 { 368 it->second->overlay->scroll(pos); 369 } 370 } 371 372 /** 373 @brief 374 Aligns all the Notifications to the position of the NotificationQueue. 375 */ 376 void NotificationQueue::positionChanged(void) 377 { 378 int counter = 0; 379 for (std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); it != this->containers_.end(); it++) //!< Set the position for each overlay. 380 { 381 (*it)->overlay->setPosition(this->getPosition()); 382 (*it)->overlay->scroll(Vector2(0.0f,(1.1f*this->getFontSize())*counter)); 383 counter++; 384 } 385 } 386 387 /** 388 @brief 389 Adds a Notification, to the queue. 390 It inserts it into the storage containers, creates an corresponding overlay and a container. 391 @param notification 392 The Notification. 393 @param time 394 The time. 395 */ 396 void NotificationQueue::addNotification(Notification* notification, const std::time_t & time) 397 { 398 NotificationOverlayContainer* container = new NotificationOverlayContainer; 399 container->overlay = new NotificationOverlay(this, notification); 400 container->notification = notification; 401 container->time = time; 402 std::string timeString = std::ctime(&time); 403 timeString.erase(timeString.length()-1); 404 const std::string& addressString = multi_cast<std::string>(reinterpret_cast<unsigned long>(notification)); 405 container->name = "NotificationOverlay(" + timeString + ")&" + addressString; 406 407 this->containers_.insert(container); 408 this->overlays_[notification] = container; 409 this->addElement(container->overlay); 410 this->size_= this->size_+1; 411 412 container->overlay->scroll(Vector2(0.0f,(1.1f*this->getFontSize())*(this->getSize()-1))); 413 } 414 415 /** 416 @brief 417 Removes a container from the queue. 418 @param container 419 A pointer to the container. 420 @return 421 Returns true if successful. 422 */ 423 bool NotificationQueue::removeContainer(NotificationOverlayContainer* container) 424 { 425 if(this->size_ == 0) //!< You cannot remove anything if the queue is empty. 426 return false; 427 428 // Unregister the NotificationQueue with the NotificationManager. 429 NotificationManager::getInstance().unregisterNotification(container->notification, this); 430 431 this->removeElement(container->overlay); 432 this->containers_.erase(container); 433 this->overlays_.erase(container->notification); 434 container->overlay->destroy(); 435 delete container; 436 this->size_= this->size_-1; 437 438 return true; 439 } 440 441 /** 442 @brief 443 Clears the queue by removing all containers. 444 */ 445 void NotificationQueue::clear(void) 446 { 447 std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare>::iterator it = this->containers_.begin(); 448 while(it != this->containers_.end()) 449 { 450 this->removeContainer(*it); 451 it = this->containers_.begin(); 373 SubString string = SubString(targets, ",", " ", false); 374 for(unsigned int i = 0; i < string.size(); i++) 375 this->targets_.insert(string[i]); 376 377 if(this->registered_) 378 { 379 NotificationManager::getInstance().unregisterListener(this); 380 NotificationManager::getInstance().registerListener(this); 452 381 } 453 382 } 454 383 455 384 } 385 -
code/trunk/src/modules/notifications/NotificationQueue.h
r7401 r7403 28 28 29 29 /** 30 @file 30 @file NotificationQueue.h 31 31 @brief Definition of the NotificationQueue class. 32 32 */ … … 38 38 39 39 #include <ctime> 40 #include <map>41 40 #include <set> 42 41 #include <string> 42 #include <vector> 43 43 44 #include "util/Math.h"45 44 #include "tools/interfaces/Tickable.h" 46 #include "overlays/OverlayGroup.h" 45 47 46 #include "interfaces/NotificationListener.h" 47 #include "NotificationManager.h" 48 48 49 namespace orxonox 50 { 49 namespace orxonox // tolua_export 50 { // tolua_export 51 51 52 52 //! Container to allow easy handling. 53 struct Notification OverlayContainer53 struct NotificationContainer 54 54 { 55 NotificationOverlay* overlay; //!< Pointer to the NotificationOverlay, everything is about. 56 Notification* notification; //!< The Notification displayed by the overlay. 55 Notification* notification; //!< The Notification displayed. 57 56 time_t time; //!< The time the Notification was sent and thus first displayed. 58 std::string name; //!< The name of the overlay.59 57 }; 60 58 61 //! Struct to allow ordering of Notification OverlayContainers.62 struct Notification OverlayContainerCompare {63 bool operator() (const Notification OverlayContainer* const & a, const NotificationOverlayContainer* const & b) const59 //! Struct to allow ordering of NotificationContainers. 60 struct NotificationContainerCompare { 61 bool operator() (const NotificationContainer* const & a, const NotificationContainer* const & b) const 64 62 { return a->time < b->time; } //!< Ordered by time. 65 63 }; … … 68 66 @brief 69 67 Displays Notifications from specific senders. 70 Beware! The NotificationQueue is an OverlayGruop and thus cannot be be a sub-element of an OverlayGroup (at least no for now.)71 72 Creating a NotificationQueue through XML goes as follows:73 Be aware that the NotificationQueue must be inside the @code <Level></Level> @endcode tags or bad things will happen.74 75 @code76 <NotificationQueue77 name = "SuperQueue" //Name of your OverlayQueue.78 maxSize = "5" //The maximum number of Notifications displayed. (Default is 5)79 notificationLength = "64" //The maximum number of characters of a Notification, that are displayed. (Default is 64)80 displayTime = "30" //The time a Notification is displayed in seconds. (Default is 30)81 targets = "target1, target2" //The senders this NotificationQueue displays Notifications from. (all, if all Notifications should be displayed.)82 font = "VeraMono" //The font (Default is VeraMono)83 fontSize = '0.4' //The font size. (Default is 0.025)84 position = "0.0, 0.0" //The position of the NotificationQueue. (Default is 0.0,0.0)85 />86 @endcode87 68 @author 88 69 Damian 'Mozork' Frick 89 70 */ 90 91 class _NotificationsExport NotificationQueue : public OverlayGroup,public Tickable, public NotificationListener92 { 71 class _NotificationsExport NotificationQueue // tolua_export 72 : public Tickable, public NotificationListener 73 { // tolua_export 93 74 94 75 public: 95 NotificationQueue( BaseObject* creator);76 NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); 96 77 virtual ~NotificationQueue(); 97 78 98 virtual void XMLPort(Element& xmlelement, XMLPort::Mode mode); //!< Method for creating a NotificationQueue object through XML. 79 /** 80 @brief Destroys the NotificationQueue. 81 Used in lua. 82 */ 83 void destroy(void) { this->OrxonoxClass::destroy(); } // tolua_export 99 84 100 85 virtual void tick(float dt); //!< To update from time to time. 101 86 102 void update(void); //!< Updates the queue.103 void update(Notification* notification, const std::time_t & time); //!< Adds a Notification to the queue.87 void update(void); //!< Updates the NotificationQueue. 88 void update(Notification* notification, const std::time_t & time); //!< Updates the NotificationQueue by adding an new Notification. 104 89 90 // tolua_begin 91 /** 92 @brief Get the name of the NotificationQueue. 93 @return Returns the name. 94 */ 95 inline const std::string& getName() const 96 { return this->name_; } 97 98 void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications. 105 99 /** 106 100 @brief Returns the maximum number of Notifications displayed. 107 101 @return Returns maximum size. 108 102 */ 109 inline int getMaxSize() const103 inline unsigned int getMaxSize() const 110 104 { return this->maxSize_; } 111 /** 112 @brief Returns the current number of Notifications displayed. 113 @return Returns the size of the queue. 114 */ 115 inline int getSize() const 116 { return this->size_; } 117 /** 118 @brief Returns the maximum length in characters a Notification message is allowed to have. 119 @return Returns the maximum Notification length. 120 */ 121 inline int getNotificationLength() const 122 { return this->notificationLength_; } 105 106 void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed. 123 107 /** 124 108 @brief Returns the time interval the Notification is displayed. 125 109 @return Returns the display time. 126 110 */ 127 inline int getDisplayTime() const111 inline float getDisplayTime() const 128 112 { return this->displayTime_; } 129 /** 130 @brief Returns the position of the NotificationQueue. 131 @return Returns the position. 132 */ 133 inline const Vector2 & getPosition() const 134 { return this->position_; } 135 /** 136 @brief Returns the font size used to display the Notifications. 137 @return Returns the font size. 138 */ 139 inline float getFontSize() const 140 { return this->fontSize_; } 141 /** 142 @brief Returns the font used to display the Notifications. 143 @return Returns the font. 144 */ 145 inline const std::string & getFont() const 146 { return this->font_; } 113 // tolua_end 147 114 148 115 /** 149 @brief Returns the targets of this queue, reps. the senders which Notifications are displayed in this queue.150 @return Retu ns a set of string holding the different targets.116 @brief Returns the current number of Notifications displayed. 117 @return Returns the size of the NotificationQueue. 151 118 */ 152 inline const std::set<std::string> & getTargetsSet() 153 { return this->targets_; } 154 bool getTargets(std::string* string) const; //!< Returns a string consisting of the concatination of the targets. 119 inline unsigned int getSize() const 120 { return this->size_; } 155 121 156 122 /** 157 @brief Sets the position of theNotificationQueue.158 @ param pos The position.123 @brief Returns the targets of this NotificationQueue, reps. the senders which Notifications are displayed in this NotificationQueue. 124 @return Returns a set of strings holding the different targets. 159 125 */ 160 inline void setPosition(Vector2 pos)161 { this->position_ = pos; this->positionChanged(); }126 inline const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet() 127 { return this->targets_; } 162 128 163 void scroll(const Vector2 pos); //!< Scrolls the NotificationQueue, meaning all NotificationOverlays are moved the input vector. 129 // tolua_begin 130 void setTargets(const std::string & targets); //!< Set the targets of this NotificationQueue. 131 const std::string& getTargets(void) const; //!< Returns a string consisting of the concatination of the targets. 132 // tolua_end 164 133 165 134 private: 166 static const int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. 167 static const int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed. 168 static const int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 169 static const float DEFAULT_FONT_SIZE; //!< The default font size. 135 static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. 136 static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 170 137 171 static const std::string DEFAULT_FONT; //!< The default font. 172 static const Vector2 DEFAULT_POSITION; //!< the default position. 138 std::string name_; //!< The name of the NotificationQueue. 173 139 174 int maxSize_; //!< The maximal number of Notifications displayed. 175 int size_; //!< The number of Notifications displayed. 176 int notificationLength_; //!< The maximal number of characters a Notification-message is allowed to have. 177 int displayTime_; //!< The time a Notification is displayed. 178 Vector2 position_; //!< The position of the NotificationQueue. 179 180 std::set<std::string> targets_; //!< The targets the Queue displays Notifications of. 181 182 float fontSize_; //!< The font size. 183 std::string font_; //!< The font. 184 185 std::multiset<NotificationOverlayContainer*, NotificationOverlayContainerCompare> containers_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. 186 std::map<Notification*, NotificationOverlayContainer*> overlays_; //!< Mapping notifications to their corresponding overlay containers, for easier association and finding. 187 188 float tickTime_; //!< Helper variable, to not have to check for overlays that have been displayed too long, every tick. 189 NotificationOverlayContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 140 unsigned int maxSize_; //!< The maximal number of Notifications displayed. 141 unsigned int size_; //!< The number of Notifications displayed. 142 unsigned int displayTime_; //!< The time a Notification is displayed. 190 143 191 144 bool registered_; //!< Helper variable to remember whether the NotificationQueue is registered already. 192 145 193 void initialize(void); //!< Initializes the object. 194 void setDefaults(void); //!< Helper method to set the default values. 146 std::set<std::string, NotificationListenerStringCompare> targets_; //!< The targets the NotificationQueue displays Notifications of. 195 147 196 bool setMaxSize(int size); //!< Sets the maximum number of displayed Notifications. 197 bool setNotificationLength(int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have. 198 bool setDisplayTime(int time); //!< Sets the maximum number of seconds a Notification is displayed. 148 std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< The NotificationContainers ordered by the time they were registered. 149 std::vector<NotificationContainer*> notifications_; //!< The NotificationContainers in the order they were added to the NotificationQueue. 199 150 200 bool setTargets(const std::string & targets); //!< Set the targets of this queue. 151 float tickTime_; //!< Helper variable, to not have to check for Notifications that have been displayed too long, every tick. 152 NotificationContainer timeLimit_; //!< Helper object to check against to determine whether Notifications have expired. 201 153 202 bool setFontSize(float size); //!< Set the font size. 203 bool setFont(const std::string & font); //!< Set the font. 154 void create(void); //!< Creates the NotificationQueue in lua. 204 155 205 void positionChanged(void); //!< Aligns all the Notifications to the positionof the NotificationQueue.156 void setName(const std::string& name); //!< Sets the name of the NotificationQueue. 206 157 207 void addNotification(Notification* notification, const std::time_t & time); //!< Add a notification to the queue. 208 bool removeContainer(NotificationOverlayContainer* container); //!< Remove a container from the queue. 158 void push(Notification* notification, const std::time_t & time); //!< Adds (pushes) a Notification to the NotificationQueue. 159 void pop(void); //!< Removes (pops) the least recently added Notification form the NotificationQueue. 160 void remove(NotificationContainer* container); //!< Removes the Notification that is stored in the input NotificationContainer. 209 161 210 void clear(void); //!< Clear the queue.162 void clear(void); //!< Clears the NotificationQueue by removing all NotificationContainers. 211 163 212 }; 164 }; // tolua_export 213 165 214 } 166 } // tolua_export 215 167 216 168 #endif /* _NotificationOverlay_H__ */ -
code/trunk/src/modules/notifications/NotificationsPrereqs.h
r7285 r7403 68 68 class NotificationDispatcher; 69 69 class NotificationManager; 70 class NotificationOverlay;71 70 class NotificationQueue; 72 71 -
code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc
r7285 r7403 38 38 #include "core/input/KeyBinderManager.h" 39 39 #include "core/input/KeyBinder.h" 40 #include "util/SubString.h" 40 41 41 42 #include <sstream> … … 88 89 std::stringstream stream; 89 90 stream << this->getPreMessage(); 90 //TODO: Add niceifyer. 91 stream << KeyBinderManager::getInstance().getCurrent()->getBinding(this->getCommand()); 91 stream << this->bindingNiceifyer(KeyBinderManager::getInstance().getCurrent()->getBinding(this->getCommand())); 92 92 stream << this->getPostMessage(); 93 std::string* message = new std::string(stream.str()); 94 return *message; 93 return *(new std::string(stream.str())); 94 } 95 96 /** 97 @brief 98 Transforms the input binding into a human readable form. 99 @param binding 100 The binding to be transformed 101 @return 102 Returns a human readable version of the input binding. 103 */ 104 const std::string& CommandNotification::bindingNiceifyer(const std::string& binding) 105 { 106 SubString string = SubString(binding, "."); 107 std::string name; 108 std::string group; 109 switch(string.size()) 110 { 111 case 0: 112 return binding; 113 case 1: 114 return binding; 115 case 2: 116 group = string[0]; 117 default: 118 name = string.subSet(1, string.size()).join("."); 119 } 120 121 std::stringstream stream; 122 if(group.compare("Keys") == 0) 123 stream << "Key " << name.substr(3); 124 else if(group.compare("MouseButtons") == 0) 125 stream << "Mouse " << name; 126 else if(group.compare("JoyStickButtons") == 0) 127 stream << "Joystick " << name; 128 else if(group.compare("JoyStickAxes") == 0) 129 stream << "Joystick Axis" << name.substr(5, 6) << name.substr(name.find("Axis")+6); 130 else if(group.compare("MouseAxes") == 0) 131 stream << "Mouse " << name.substr(1,3) << " " << name.substr(0, 1) << "-Axis"; 132 else 133 return binding; 134 135 return *(new std::string(stream.str())); 95 136 } 96 137 -
code/trunk/src/modules/notifications/dispatchers/CommandNotification.h
r7285 r7403 104 104 { this->postMessage_ = message; } 105 105 106 const std::string& bindingNiceifyer(const std::string& binding); 107 106 108 }; 107 109 -
code/trunk/src/modules/objects/triggers/MultiTriggerContainer.cc
r7301 r7403 35 35 36 36 #include "core/CoreIncludes.h" 37 #include "worldentities/pawns/Pawn.h" 37 38 38 39 namespace orxonox … … 65 66 { 66 67 RegisterObject(MultiTriggerContainer); 68 69 Pawn* pawn = orxonox_cast<Pawn*>(data); 70 if(pawn != NULL) 71 { 72 this->setForPlayer(true); 73 this->setTriggeringPlayer(pawn); 74 } 67 75 } 68 76 -
code/trunk/src/modules/objects/triggers/MultiTriggerContainer.h
r7301 r7403 38 38 39 39 #include "core/BaseObject.h" 40 #include "interfaces/PlayerTrigger.h" 40 41 41 42 namespace orxonox … … 48 49 Damian 'Mozork' Frick 49 50 */ 50 class _ObjectsExport MultiTriggerContainer : public BaseObject 51 class _ObjectsExport MultiTriggerContainer : public BaseObject, public PlayerTrigger 51 52 { 52 53 … … 72 73 MultiTrigger* originator_; //!< The originator. 73 74 BaseObject* data_; //!< The data. 75 74 76 }; 75 77 -
code/trunk/src/modules/questsystem/Quest.cc
r7401 r7403 367 367 COUT(4) << "Quest {" << this->getId() << "} is failed for player: " << player << " ." <<std::endl; 368 368 369 this->getDescription()->sendFailQuestNotification( );369 this->getDescription()->sendFailQuestNotification(player); 370 370 return true; 371 371 } … … 386 386 COUT(4) << "Quest {" << this->getId() << "} is completed for player: " << player << " ." <<std::endl; 387 387 388 this->getDescription()->sendCompleteQuestNotification( );388 this->getDescription()->sendCompleteQuestNotification(player); 389 389 return true; 390 390 } … … 412 412 this->setStatus(player, QuestStatus::Active); 413 413 414 this->getDescription()->sendAddQuestNotification( );414 this->getDescription()->sendAddQuestNotification(player); 415 415 return true; 416 416 } -
code/trunk/src/modules/questsystem/QuestDescription.cc
r7163 r7403 84 84 @param status 85 85 The status the QuestDescription us for. 86 @param player 87 The player the Notification is sent to. 86 88 @return 87 89 Returns true if successful. 88 @todo89 Make sure the messages meet the conditions.90 90 */ 91 bool QuestDescription::notificationHelper(const std::string & item, const std::string & status )91 bool QuestDescription::notificationHelper(const std::string & item, const std::string & status, PlayerInfo* player) 92 92 { 93 93 std::string message; … … 123 123 124 124 QuestNotification* notification = new QuestNotification(this, message); 125 notification->send( );125 notification->send(player); 126 126 return true; 127 127 } -
code/trunk/src/modules/questsystem/QuestDescription.h
r7401 r7403 97 97 /** 98 98 @brief Sends a Notification displaying that a QuestHint was added. 99 @param player The player the Notification is sent to. 99 100 @return Returns true if successful. 100 101 */ 101 inline bool sendAddHintNotification( void)102 { return notificationHelper("hint", "" ); }102 inline bool sendAddHintNotification(PlayerInfo* player) 103 { return notificationHelper("hint", "", player); } 103 104 104 105 /** 105 106 @brief Sends a Notification displaying that a Quest was added. 107 @param player The player the Notification is sent to. 106 108 @return Returns true if successful. 107 109 */ 108 inline bool sendAddQuestNotification( void)109 { return notificationHelper("quest", "start" ); }110 inline bool sendAddQuestNotification(PlayerInfo* player) 111 { return notificationHelper("quest", "start", player); } 110 112 111 113 /** 112 114 @brief Sends a Notification displaying that a Quest was failed. 115 @param player The player the Notification is sent to. 113 116 @return Returns true if successful. 114 117 */ 115 inline bool sendFailQuestNotification( void)116 { return notificationHelper("quest", "fail" ); }118 inline bool sendFailQuestNotification(PlayerInfo* player) 119 { return notificationHelper("quest", "fail", player); } 117 120 118 121 /** 119 122 @brief Sends a Notification displaying that a Quest was completed. 123 @param player The player the Notification is sent to. 120 124 @return Returns true if successful. 121 125 */ 122 inline bool sendCompleteQuestNotification( void)123 { return notificationHelper("quest", "complete" ); }126 inline bool sendCompleteQuestNotification(PlayerInfo* player) 127 { return notificationHelper("quest", "complete", player); } 124 128 125 129 private: … … 129 133 std::string completeMessage_; //!< The message displayed when the Quest is completed. 130 134 131 bool notificationHelper(const std::string & item, const std::string & status ); //!< Helper for sending QuestDescriptions as Notifications.135 bool notificationHelper(const std::string & item, const std::string & status, PlayerInfo* player); //!< Helper for sending QuestDescriptions as Notifications. 132 136 133 137 /** -
code/trunk/src/modules/questsystem/QuestHint.cc
r7163 r7403 121 121 this->playerStatus_[player] = QuestHintStatus::Active; 122 122 123 this->getDescription()->sendAddHintNotification( );123 this->getDescription()->sendAddHintNotification(player); 124 124 return true; 125 125 } -
code/trunk/src/modules/questsystem/QuestNotification.cc
r7401 r7403 29 29 #include "QuestNotification.h" 30 30 #include "core/CoreIncludes.h" 31 #include "infos/PlayerInfo.h" 31 32 32 33 namespace orxonox { … … 70 71 @brief 71 72 Send the QuestNotification. 73 @param player 74 The player the Notification is sent to. 72 75 @return 73 76 Returns true if successful. 74 77 */ 75 bool QuestNotification::send( void)78 bool QuestNotification::send(PlayerInfo* player) 76 79 { 77 return this->Notification::send( QuestNotification::SENDER);80 return this->Notification::send(player->getClientID(), QuestNotification::SENDER); 78 81 } 79 82 -
code/trunk/src/modules/questsystem/QuestNotification.h
r7163 r7403 50 50 virtual ~QuestNotification(); //!< Destructor. 51 51 52 bool send( void); //!< Send the QuestNotification.52 bool send(PlayerInfo* player); //!< Send the QuestNotification. 53 53 54 54 private: -
code/trunk/src/orxonox/interfaces/NotificationListener.h
r7163 r7403 49 49 /** 50 50 @brief 51 Struct that overloads the compare operation between two PickupIdentifier pointers. 52 */ 53 //TODO: 54 struct NotificationListenerStringCompare 55 { 56 bool operator() (const std::string& lhs, const std::string& rhs) const 57 { return lhs.compare(rhs) < 0; } 58 }; 59 60 /** 61 @brief 51 62 NotificationListener interface. 52 63 @author … … 59 70 virtual ~NotificationListener() {} 60 71 61 virtual const std::set<std::string > & getTargetsSet() = 0;72 virtual const std::set<std::string, NotificationListenerStringCompare> & getTargetsSet() = 0; 62 73 virtual void update(void) = 0; 63 74 virtual void update(Notification* notification, const std::time_t & time) = 0;
Note: See TracChangeset
for help on using the changeset viewer.