Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/questsystem3/src/orxonox/overlays/notifications/NotificationManager.cc @ 2281

Last change on this file since 2281 was 2281, checked in by dafrick, 16 years ago

Fixed a bug, inserted some debug output.

File size: 3.4 KB
Line 
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
38namespace 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   
55        for (std::list<NotificationContainer*>::iterator notification = NotificationManager::notifications_s.begin(); notification != NotificationManager::notifications_s.end(); ++notification)
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();
85        NotificationManager::notifications_s.push_front(container);
86       
87        updateQueue();
88       
89        COUT(3) << "Notification inserted, title: " << notification->getTitle() << std::endl;
90       
91        return true;
92    }
93   
94    void NotificationManager::updateQueue(void)
95    {
96        std::string text = "";
97       
98        int i = NotificationQueue::queue_s->getLength();
99        for (std::list<NotificationContainer*>::iterator notification = NotificationManager::notifications_s.begin(); notification != NotificationManager::notifications_s.end() || i <= 0; ++notification)
100        {
101            i--;
102            NotificationContainer* container = *notification;
103            if(container->remainingTime == 0)
104                continue;
105           
106            text = text + "\n\n------------" + container->notification->getTitle(); + "\n" + container->notification->getMessage();
107        }
108       
109        COUT(3) << "Queue updated: " << std::endl;
110       
111        NotificationQueue::queue_s->setQueueText(text);
112    }
113
114}
Note: See TracBrowser for help on using the repository browser.