Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/notifications/src/modules/notifications/Notification.cc @ 7348

Last change on this file since 7348 was 7348, checked in by dafrick, 10 years ago

Small change such that the server doesn't automatically display all Notifications instead of just the ones that are meant for him.

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