Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/notifications/Notification.cc @ 7375

Last change on this file since 7375 was 7193, checked in by dafrick, 14 years ago

Added NotificationDispatcher, class that can, upon being triggered, dispatch (send/display) a specified Notification.
Additionally a NotificationDispatcher called CommandNotification, that, upon being triggered, displays a Notification with a message and the name of the key that the command is mapped to. It is envisioned to be used in the, soon to be, tutorial level.
Also: Small bugfix in Notification.

  • Property svn:eol-style set to native
File size: 3.6 KB
RevLine 
[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 thes
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
[2911]29/**
[3196]30    @file
[2911]31    @brief Implementation of the Notification class.
32*/
33
[2280]34#include "Notification.h"
35
36#include "core/CoreIncludes.h"
37#include "NotificationManager.h"
38
[2435]39namespace orxonox
40{
[2911]41
[7163]42    CreateUnloadableFactory(Notification);
43
[2911]44    /**
45    @brief
46        Default constructor. Initializes the object.
47    */
[2280]48    Notification::Notification(BaseObject* creator) : BaseObject(creator)
49    {
[3196]50        RegisterObject(Notification);
[2911]51        this->initialize();
[2280]52    }
[6417]53
[2911]54    /**
55    @brief
56        Constructor. Creates a Notification with the input message.
57    @param message
58        The message of the Notification.
59    */
[7163]60    Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator)
[2280]61    {
[7193]62        RegisterObject(Notification);
63        this->initialize();
[2280]64        this->message_ = message;
65    }
[6417]66
[2911]67    /**
68    @brief
69        Destructor.
70    */
[2280]71    Notification::~Notification()
72    {
[7163]73
[2280]74    }
[6417]75
[2911]76    /**
77    @brief
78        Registers the object and sets some default values.
79    */
[2280]80    void Notification::initialize(void)
81    {
[6417]82        this->message_.clear();
[2911]83        this->sender_ = NotificationManager::NONE;
[2280]84        this->sent_ = false;
85    }
[6417]86
[2911]87    /**
88    @brief
89        Sends the Notification to the Notificationmanager, with sender NetificationManager::NONE.
90    @return
91        Returns true if successful.
92    */
[2280]93    bool Notification::send(void)
94    {
[2911]95        return this->send(NotificationManager::NONE);
[2280]96    }
[6417]97
[2911]98    /**
99    @brief
100        Sends the Notification to the Notificationmanager, which then in turn distributes it to the different NotificationQueues.
101    @param sender
102        The sender the Notification was sent by. Used by the NotificationManager to distributes the notification to the correct NotificationQueues.
103    @return
104        Returns true if successful.
105    */
106    bool Notification::send(const std::string & sender)
[2280]107    {
[7193]108        if(this->isSent()) //TODO: Needed?
109            return false;
110       
[2911]111        this->sender_ = sender;
112        bool successful = NotificationManager::getInstance().registerNotification(this);
113        if(!successful)
[2280]114            return false;
[2911]115        this->sent_ = true;
[6417]116
[2911]117        COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
[6417]118
[2435]119        return true;
[2280]120    }
[6417]121
[2911]122    /**
123    @brief
124        Sets the message of the notification.
125    @param message
126        The message to be set.
127    @return
128        Returns true if successful.
129    */
[2280]130    bool Notification::setMessage(const std::string & message)
131    {
[2911]132        if(this->isSent()) //!< The message cannot be changed if the message has already been sent.
[2280]133            return false;
[2435]134        this->message_ = message;
135        return true;
[2280]136    }
[2911]137
[2280]138}
Note: See TracBrowser for help on using the repository browser.