Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 2346 was 2346, checked in by dafrick, 15 years ago
  • QuestListener works now.
  • Rearranged the places Notifications are sent from, and also created actually meaningfull Notification messages
  • Done some changes to Notifications
File size: 4.5 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 = notifications_s.begin(); notification != 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        notifications_s.push_front(container);
86       
87        updateQueue();
88       
89        COUT(4) << "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 = notifications_s.begin(); notification != notifications_s.end() && i > 0; ++notification)
100        {
101            i--;
102            NotificationContainer* container = *notification;
103            if(container->remainingTime == 0.0)
104                continue;
105           
106            text = text + "\n\n\n------------\n\n" + container->notification->getTitle() + "\n\n" + container->notification->getMessage();
107        }
108       
109        NotificationQueue::queue_s->setQueueText(text);
110    }
111   
112    const std::string & NotificationManager::clipMessage(const std::string & message)
113    {
114        std::string* clippedMessageP = new std::string();
115        std::string clippedMessage = *clippedMessageP;
116        clippedMessage = "";
117        std::string tempWord = "";
118        int wordLength = 0;
119        signed int i = 0;
120        int widthLeft = NotificationQueue::queue_s->getWidth();
121        while(i < message.length())
122        {
123            while(i < message.length() && message[i] != ' ' && message[i] != '\n')
124            {
125                tempWord = tempWord + message[i];
126                i++;
127                wordLength++;
128            }
129           
130            if(wordLength <= widthLeft)
131            {
132                clippedMessage = clippedMessage + tempWord + message[i];
133                widthLeft -= (wordLength+1);
134                wordLength = 0;
135                tempWord = "";
136                i++;
137            }
138            else
139            {
140                clippedMessage = clippedMessage + '\n' + tempWord + message[i];
141                widthLeft = NotificationQueue::queue_s->getWidth() - (wordLength+1);
142                i++;
143                wordLength = 0;
144                tempWord = "";
145            }
146        }
147       
148        return clippedMessage;
149    }
150
151}
Note: See TracBrowser for help on using the repository browser.