Changeset 7342 for code/branches/notifications
- Timestamp:
- Sep 3, 2010, 9:17:51 PM (14 years ago)
- Location:
- code/branches/notifications
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
code/branches/notifications/data/gui/scripts/NotificationLayer.lua
r7338 r7342 9 9 local root = winMgr:getWindow("orxonox/NotificationLayer/Root") 10 10 local queue = winMgr:createWindow("MenuWidgets/Listbox", "orxonox/NotificationLayer/Root/Queue/" .. name) 11 root:addChildWindow(queue) 12 11 13 queue:setPosition(CEGUI.UVector2(CEGUI.UDim(0, 0), CEGUI.UDim(0, 0))) 12 queue:setSize(CEGUI.UVector2(CEGUI.UDim(1 , 0), CEGUI.UDim(0.2, 0)))13 root:addChildWindow(queue) 14 queue:setSize(CEGUI.UVector2(CEGUI.UDim(1.0, 0), CEGUI.UDim(0, P.queueHeightHelper(queue, size)))) 15 14 16 table.insert(P.queueList, queue) 15 17 table.insert(P.nameList, name) … … 35 37 36 38 function P.changePosition(name, xPos, yPos) 37 local queue = P.nameToQueue (name)39 local queue = P.nameToQueueHelper(name) 38 40 if queue == nil then 39 41 cout(0, "Queue is nil!") … … 44 46 45 47 function P.pushNotification(queueName, notification) 46 local queue = P.nameToQueue (queueName)48 local queue = P.nameToQueueHelper(queueName) 47 49 if queue == nil then 48 50 cout(0, "Queue is nil!") … … 59 61 60 62 function P.popNotification(queueName) 61 local queue = P.nameToQueue (queueName)63 local queue = P.nameToQueueHelper(queueName) 62 64 if queue == nil then 63 65 cout(0, "Queue is nil!") … … 69 71 70 72 function P.removeNotification(queueName, index) 71 local queue = P.nameToQueue (queueName)73 local queue = P.nameToQueueHelper(queueName) 72 74 if queue == nil then 73 75 cout(0, "Queue is nil!") … … 79 81 80 82 function P.clearQueue(name) 81 local queue = P.nameToQueue (name)83 local queue = P.nameToQueueHelper(name) 82 84 if queue == nil then 83 85 cout(0, "Queue is nil!") … … 88 90 end 89 91 90 function P.nameToQueue (name)92 function P.nameToQueueHelper(name) 91 93 local queue = nil 92 94 for k,v in pairs(P.nameList) do … … 99 101 end 100 102 103 function P.queueHeightHelper(queue, size) 104 local listbox = CEGUI.toListbox(queue) 105 local item = CEGUI.createListboxTextItem("Text") 106 listbox:addItem(item) 107 local singleItemHeight = listbox:getTotalItemsHeight() 108 local lookAndFeel = CEGUI.WidgetLookManager:getSingleton():getWidgetLook(queue:getLookNFeel()) 109 local formattedArea = lookAndFeel:getNamedArea("ItemRenderingArea"):getArea():getPixelRect(queue) 110 local frameHeight = queue:getUnclippedPixelRect():getHeight() - formattedArea:getHeight() 111 listbox:removeItem(item) 112 return frameHeight + singleItemHeight*size 113 end 114 101 115 return P 102 116 -
code/branches/notifications/data/gui/scripts/SheetManager.lua
r7341 r7342 69 69 70 70 -- Count the number of sheets that don't need input till the first that does. 71 local counter = activeMenuSheets.size 72 while counter > 0 and activeMenuSheets[counter].bNoInput do 73 counter = counter - 1 74 end 71 local counter = noInputSheetCounter() 75 72 -- Pause game control if this is the first menu to be displayed 76 73 -- HUGE HACK? … … 182 179 183 180 -- Count the number of sheets that don't need input till the first that does. 184 local counter = activeMenuSheets.size 185 while counter > 0 and activeMenuSheets[counter].bNoInput do 186 counter = counter - 1 187 end 181 local counter = noInputSheetCounter() 188 182 -- Resume control if the last (non-noInput) menu is hidden 189 183 if counter == 0 then … … 204 198 205 199 -- Count the number of sheets that don't need input till the first that does. 206 local counter = activeMenuSheets.size 207 while counter > 0 and activeMenuSheets[counter].bNoInput do 208 counter = counter - 1 209 end 200 local counter = noInputSheetCounter() 210 201 211 202 -- If the first sheet that needs input is the MainMenu. … … 224 215 end 225 216 217 function noInputSheetCounter() 218 -- Count the number of sheets that don't need input till the first that does. 219 local counter = activeMenuSheets.size 220 while counter > 0 and activeMenuSheets[counter].bNoInput do 221 counter = counter - 1 222 end 223 return counter 224 end 225 226 226 ---------------------- 227 227 --- Initialisation --- -
code/branches/notifications/src/libraries/core/GUIManager.cc
r7338 r7342 237 237 @param name 238 238 The name of the GUI 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. -
code/branches/notifications/src/modules/notifications/NotificationQueue.cc
r7338 r7342 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 <algorithm> 37 36 38 #include "util/Convert.h" 37 39 #include "core/CoreIncludes.h" 38 #include "core/XMLPort.h"39 #include "Notification.h"40 40 #include "core/GUIManager.h" 41 41 #include "core/LuaState.h" 42 #include <algorithm>42 #include "Notification.h" 43 43 44 44 namespace orxonox 45 45 { 46 46 47 const std::string NotificationQueue::DEFAULT_FONT("VeraMono");48 47 const Vector2 NotificationQueue::DEFAULT_POSITION(0.0,0.0); 49 const float NotificationQueue::DEFAULT_FONT_SIZE = 0.025f;50 48 51 49 /** … … 53 51 Constructor. Creates and initializes the object. 54 52 */ 55 NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, const Vector2& position, unsigned int length, unsigned intdisplayTime)53 NotificationQueue::NotificationQueue(const std::string& name, const std::string& senders, unsigned int size, const Vector2& position, unsigned int displayTime) 56 54 { 57 55 this->registered_ = false; … … 65 63 this->maxSize_ = size; 66 64 this->position_ = position; 67 this->notificationLength_ = length;68 65 this->setDisplayTime(displayTime); 69 66 70 67 this->create(); 68 this->positionChanged(); 71 69 72 70 NotificationManager::getInstance().registerListener(this); … … 101 99 102 100 /** 103 //TODO: Document. 101 @brief 102 Creates the NotificationQueue in lua. 104 103 */ 105 104 void NotificationQueue::create(void) 106 105 { 107 //TODO: Also transfer font and fontsize.108 106 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.createQueue(\"" + this->getName() + "\", " + multi_cast<std::string>(this->getMaxSize()) + ")"); 109 this->positionChanged();110 107 } 111 108 … … 118 115 void NotificationQueue::tick(float dt) 119 116 { 120 this->tickTime_ += dt; // !<Add the time interval that has passed to the time counter.121 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.122 { 123 this->timeLimit_.time = std::time(0)-this->displayTime_; // !<Container containig the current time.117 this->tickTime_ += dt; // Add the time interval that has passed to the time counter. 118 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. 119 { 120 this->timeLimit_.time = std::time(0)-this->displayTime_; // Container containig the current time. 124 121 125 122 std::multiset<NotificationContainer*, NotificationContainerCompare>::iterator it = this->ordering_.begin(); 126 while(it != this->ordering_.upper_bound(&this->timeLimit_)) // !<Iterate through all elements whose creation time is smaller than the current time minus the display time.123 while(it != this->ordering_.upper_bound(&this->timeLimit_)) // Iterate through all elements whose creation time is smaller than the current time minus the display time. 127 124 { 128 125 NotificationContainer* temp = *it; … … 131 128 } 132 129 133 this->tickTime_ = this->tickTime_ - (int)this->tickTime_; // !<Reset time counter.130 this->tickTime_ = this->tickTime_ - (int)this->tickTime_; // Reset time counter. 134 131 } 135 132 } … … 138 135 @brief 139 136 Updates the NotificationQueue. 140 Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting the inthe queue.137 Updates by clearing the queue and requesting all relevant Notifications from the NotificationManager and inserting them into the queue. 141 138 */ 142 139 void NotificationQueue::update(void) … … 145 142 146 143 std::multimap<std::time_t, Notification*>* notifications = new std::multimap<std::time_t, Notification*>; 147 if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) // !<Get the Notifications sent in the interval form now to minus the display time.144 if(!NotificationManager::getInstance().getNotifications(this, notifications, this->displayTime_)) // Get the Notifications sent in the interval form now to minus the display time. 148 145 { 149 146 COUT(1) << "NotificationQueue update failed due to undetermined cause." << std::endl; … … 154 151 return; 155 152 156 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // !>Add all Notifications.153 for(std::multimap<std::time_t, Notification*>::iterator it = notifications->begin(); it != notifications->end(); it++) // Add all Notifications. 157 154 this->push(it->second, it->first); 158 155 … … 179 176 /** 180 177 @brief 178 Adds a Notification, to the queue. 179 It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI. 180 @param notification 181 The Notification. 182 @param time 183 The time. 184 */ 185 void NotificationQueue::push(Notification* notification, const std::time_t & time) 186 { 187 NotificationContainer* container = new NotificationContainer; 188 container->notification = notification; 189 container->time = time; 190 191 // If the maximum size of the NotificationQueue has been reached the last (least recently added) Notification is removed. 192 if(this->getSize() >= this->getMaxSize()) 193 this->pop(); 194 195 this->size_++; 196 197 this->ordering_.insert(container); 198 this->notifications_.insert(this->notifications_.begin(), container); 199 200 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")"); 201 } 202 203 /** 204 @brief 205 Removes the least recently added Notification form the NotificationQueue. 206 */ 207 void NotificationQueue::pop(void) 208 { 209 NotificationContainer* container = this->notifications_.back(); 210 this->ordering_.erase(container); 211 this->notifications_.pop_back(); 212 this->size_--; 213 delete container; 214 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")"); 215 } 216 217 /** 218 @brief 219 Removes the Notification that is stored in the input container. 220 @param container 221 The NotificationContainer with the Notification to be removed. 222 */ 223 void NotificationQueue::remove(NotificationContainer* container) 224 { 225 std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container); 226 std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin (); 227 this->ordering_.erase(container); 228 this->notifications_.erase(it); 229 this->size_--; 230 delete container; 231 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")"); 232 } 233 234 /** 235 @brief 236 Clears the queue by removing all containers. 237 */ 238 void NotificationQueue::clear(void) 239 { 240 this->ordering_.clear(); 241 for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++) 242 { 243 delete *it; 244 } 245 this->notifications_.clear(); 246 this->size_ = 0; 247 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")"); 248 } 249 250 /** 251 @brief 181 252 Sets the name of the NotificationQueue. 182 253 @param name … … 203 274 { 204 275 this->maxSize_ = size; 205 this->update();206 }207 208 /**209 @brief210 Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.211 @param length212 The length to be set.213 @return214 Returns true if successful.215 */216 void NotificationQueue::setNotificationLength(unsigned int length)217 {218 this->notificationLength_ = length;219 276 this->update(); 220 277 } … … 299 356 /** 300 357 @brief 301 Sets the font size.302 @param size303 The font size.304 @return305 Returns true if successful.306 */307 bool NotificationQueue::setFontSize(float size)308 {309 if(size <= 0)310 return false;311 312 return true;313 }314 315 /**316 @brief317 Sets the font.318 @param font319 The font.320 @return321 Returns true if successful.322 */323 bool NotificationQueue::setFont(const std::string & font)324 {325 326 return true;327 }328 329 /**330 @brief331 358 Aligns all the Notifications to the position of the NotificationQueue. 332 359 */ … … 336 363 } 337 364 338 /**339 @brief340 Adds a Notification, to the queue.341 It inserts it into the storage containers, creates a corresponding container and pushes the Notification message to the GUI.342 @param notification343 The Notification.344 @param time345 The time.346 */347 void NotificationQueue::push(Notification* notification, const std::time_t & time)348 {349 NotificationContainer* container = new NotificationContainer;350 container->notification = notification;351 container->time = time;352 353 // If the maximum size of the NotificationQueue has been reached the last (least recently added) Notification is removed.354 if(this->getSize() >= this->getMaxSize())355 this->pop();356 357 this->size_++;358 359 this->ordering_.insert(container);360 this->notifications_.insert(this->notifications_.begin(), container);361 362 //TODO: Clip message if necessary.363 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.pushNotification(\"" + this->getName() + "\", \"" + notification->getMessage() + "\")");364 }365 366 /**367 @brief368 Removes the least recently added Notification form the NotificationQueue.369 */370 void NotificationQueue::pop(void)371 {372 NotificationContainer* container = this->notifications_.back();373 this->ordering_.erase(container);374 this->notifications_.pop_back();375 this->size_--;376 delete container;377 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.popNotification(\"" + this->getName() + "\")");378 }379 380 /**381 @brief382 Removes the Notification that is stored in the input container.383 @param container384 The NotificationContainer with the Notification to be removed.385 */386 void NotificationQueue::remove(NotificationContainer* container)387 {388 std::vector<NotificationContainer*>::iterator it = std::find(this->notifications_.begin(), this->notifications_.end(), container);389 std::vector<NotificationContainer*>::difference_type index = it - this->notifications_.begin ();390 this->ordering_.erase(container);391 this->notifications_.erase(it);392 this->size_--;393 delete container;394 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.removeNotification(\"" + this->getName() + "\", " + multi_cast<std::string>(index) + ")");395 }396 397 /**398 @brief399 Clears the queue by removing all containers.400 */401 void NotificationQueue::clear(void)402 {403 this->ordering_.clear();404 for(std::vector<NotificationContainer*>::iterator it = this->notifications_.begin(); it != this->notifications_.end(); it++)405 {406 delete *it;407 }408 this->notifications_.clear();409 this->size_ = 0;410 GUIManager::getInstance().getLuaState()->doString("NotificationLayer.clearQueue(\"" + this->getName() + "\")");411 }412 413 365 } -
code/branches/notifications/src/modules/notifications/NotificationQueue.h
r7338 r7342 76 76 77 77 public: 78 NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, const Vector2& position = NotificationQueue::DEFAULT_POSITION, unsigned int length = NotificationQueue::DEFAULT_LENGTH, unsigned intdisplayTime = NotificationQueue::DEFAULT_DISPLAY_TIME);78 NotificationQueue(const std::string& name, const std::string& senders = NotificationManager::ALL, unsigned int size = NotificationQueue::DEFAULT_SIZE, const Vector2& position = NotificationQueue::DEFAULT_POSITION, unsigned int displayTime = NotificationQueue::DEFAULT_DISPLAY_TIME); 79 79 virtual ~NotificationQueue(); 80 80 … … 104 104 { return this->size_; } 105 105 /** 106 @brief Returns the maximum length in characters a Notification message is allowed to have.107 @return Returns the maximum Notification length.108 */109 inline unsigned int getNotificationLength() const110 { return this->notificationLength_; }111 /**112 106 @brief Returns the time interval the Notification is displayed. 113 107 @return Returns the display time. … … 121 115 inline const Vector2 & getPosition() const 122 116 { return this->position_; } 123 /**124 @brief Returns the font size used to display the Notifications.125 @return Returns the font size.126 */127 inline float getFontSize() const128 { return this->fontSize_; }129 /**130 @brief Returns the font used to display the Notifications.131 @return Returns the font.132 */133 inline const std::string & getFont() const134 { return this->font_; }135 117 136 118 /** … … 151 133 private: 152 134 static const unsigned int DEFAULT_SIZE = 5; //!< The default maximum number of Notifications displayed. 153 static const unsigned int DEFAULT_LENGTH = 64; //!< The default maximum number of characters displayed.154 135 static const unsigned int DEFAULT_DISPLAY_TIME = 30; //!< The default display time. 155 static const float DEFAULT_FONT_SIZE; //!< The default font size.156 136 157 static const std::string DEFAULT_FONT; //!< The default font.158 137 static const Vector2 DEFAULT_POSITION; //!< the default position. 159 138 … … 167 146 168 147 std::set<std::string> targets_; //!< The targets the Queue displays Notifications of. 169 170 float fontSize_; //!< The font size.171 std::string font_; //!< The font.172 148 173 149 std::multiset<NotificationContainer*, NotificationContainerCompare> ordering_; //!< Multiset, because the ordering is based on, not necessarily unique, timestamps. //TODO: Would set work as well? … … 185 161 186 162 void setMaxSize(unsigned int size); //!< Sets the maximum number of displayed Notifications. 187 void setNotificationLength(unsigned int length); //!< Sets the maximum number of characters a Notification message displayed by this queue is allowed to have.188 163 void setDisplayTime(unsigned int time); //!< Sets the maximum number of seconds a Notification is displayed. 189 164 190 165 bool setTargets(const std::string & targets); //!< Set the targets of this queue. 191 192 bool setFontSize(float size); //!< Set the font size.193 bool setFont(const std::string & font); //!< Set the font.194 166 195 167 void positionChanged(void); //!< Aligns all the Notifications to the position of the NotificationQueue.
Note: See TracChangeset
for help on using the changeset viewer.