[2280] | 1 | /* |
---|
| 2 | * ORXONOX - the hottest 3D action shooter ever to exist |
---|
| 3 | * > www.orxonox.net < |
---|
| 4 | * |
---|
| 5 | * |
---|
| 6 | * License notice: |
---|
| 7 | * |
---|
| 8 | * This program is free software; you can redistribute it and/or |
---|
| 9 | * modify it under the terms of the GNU General Public License |
---|
| 10 | * as published by the Free Software Foundation; either version 2 |
---|
| 11 | * of the License, or (at your option) any later version. |
---|
| 12 | * |
---|
| 13 | * This program is distributed in the hope that it will be useful, |
---|
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | * GNU General Public License for more details. |
---|
| 17 | * |
---|
| 18 | * You should have received a copy of the GNU General Public License |
---|
| 19 | * along with this program; if not, write to the Free Software |
---|
| 20 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
---|
| 21 | * |
---|
| 22 | * Author: |
---|
| 23 | * Damian 'Mozork' Frick |
---|
| 24 | * Co-authors: |
---|
| 25 | * ... |
---|
| 26 | * |
---|
| 27 | */ |
---|
| 28 | |
---|
| 29 | #include "OrxonoxStableHeaders.h" |
---|
| 30 | #include "NotificationManager.h" |
---|
| 31 | |
---|
| 32 | #include "core/CoreIncludes.h" |
---|
| 33 | |
---|
| 34 | #include "Notification.h" |
---|
| 35 | |
---|
| 36 | #include "NotificationQueue.h" |
---|
| 37 | |
---|
| 38 | namespace orxonox { |
---|
| 39 | |
---|
| 40 | std::list<NotificationContainer*> NotificationManager::notifications_s; |
---|
| 41 | |
---|
| 42 | NotificationManager::NotificationManager(BaseObject* creator) : BaseObject(creator) |
---|
| 43 | { |
---|
| 44 | RegisterObject(NotificationManager); |
---|
| 45 | } |
---|
| 46 | |
---|
| 47 | NotificationManager::~NotificationManager() |
---|
| 48 | { |
---|
| 49 | } |
---|
| 50 | |
---|
| 51 | void NotificationManager::tick(float dt) |
---|
| 52 | { |
---|
| 53 | bool update = false; |
---|
| 54 | |
---|
[2284] | 55 | for (std::list<NotificationContainer*>::iterator notification = notifications_s.begin(); notification != notifications_s.end(); ++notification) |
---|
[2280] | 56 | { |
---|
| 57 | NotificationContainer* container = *notification; |
---|
| 58 | if(container->remainingTime == 0) |
---|
| 59 | { |
---|
| 60 | continue; |
---|
| 61 | } |
---|
| 62 | else if(container->remainingTime - dt <= 0) |
---|
| 63 | { |
---|
| 64 | container->remainingTime = 0; |
---|
| 65 | update = true; |
---|
| 66 | } |
---|
| 67 | else |
---|
| 68 | { |
---|
| 69 | container->remainingTime = container->remainingTime -dt; |
---|
| 70 | } |
---|
| 71 | } |
---|
| 72 | |
---|
| 73 | if(update) |
---|
| 74 | updateQueue(); |
---|
| 75 | } |
---|
| 76 | |
---|
| 77 | bool NotificationManager::insertNotification(Notification* notification) |
---|
| 78 | { |
---|
| 79 | if(notification == NULL) |
---|
| 80 | return false; |
---|
| 81 | |
---|
| 82 | NotificationContainer* container = new NotificationContainer; |
---|
| 83 | container->notification = notification; |
---|
| 84 | container->remainingTime = notification->getDisplayTime(); |
---|
[2284] | 85 | notifications_s.push_front(container); |
---|
[2280] | 86 | |
---|
| 87 | updateQueue(); |
---|
| 88 | |
---|
[2284] | 89 | COUT(3) << "Notification inserted, title: " << notification->getTitle() << ", message: " << notification->getMessage() << std::endl; |
---|
[2281] | 90 | |
---|
[2280] | 91 | return true; |
---|
| 92 | } |
---|
| 93 | |
---|
| 94 | void NotificationManager::updateQueue(void) |
---|
| 95 | { |
---|
| 96 | std::string text = ""; |
---|
| 97 | |
---|
| 98 | int i = NotificationQueue::queue_s->getLength(); |
---|
[2328] | 99 | for (std::list<NotificationContainer*>::iterator notification = notifications_s.begin(); notification != notifications_s.end() && i > 0; ++notification) |
---|
[2284] | 100 | { |
---|
[2280] | 101 | i--; |
---|
| 102 | NotificationContainer* container = *notification; |
---|
[2328] | 103 | if(container->remainingTime == 0.0) |
---|
[2280] | 104 | continue; |
---|
| 105 | |
---|
[2287] | 106 | COUT(3) << "Update, title: " << container->notification->getTitle() << ", message: " << container->notification->getMessage() << std::endl; |
---|
| 107 | |
---|
[2328] | 108 | text = text + "\n\n\n------------" + container->notification->getTitle() + "\n\n" + container->notification->getMessage(); |
---|
[2284] | 109 | } |
---|
| 110 | |
---|
| 111 | COUT(3) << "Queue updated: " << text << std::endl; |
---|
[2280] | 112 | |
---|
| 113 | NotificationQueue::queue_s->setQueueText(text); |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | } |
---|