Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Hiding MultiTrigger behind PlayerTrigger for consistency of use.
Trying some things out with notifications.

  • Property svn:eol-style set to native
File size: 4.0 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, send);
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        if(GameMode::isMaster())
110        {
111            if(this->isSent()) //TODO: Needed?
112                return false;
113
114            this->sender_ = sender;
115            bool successful = NotificationManager::getInstance().registerNotification(this);
116            if(!successful)
117                return false;
118            this->sent_ = true;
119
120            COUT(3) << "Notification \"" << this->getMessage() << "\" sent." << std::endl;
121        }
122        else
123        {
124            callMemberNetworkFunction(Notification, send, this->getObjectID(), clientId, clientId, sender);
125        }
126
127        return true;
128    }
129
130    /**
131    @brief
132        Sets the message of the notification.
133    @param message
134        The message to be set.
135    @return
136        Returns true if successful.
137    */
138    bool Notification::setMessage(const std::string & message)
139    {
140        if(this->isSent()) //!< The message cannot be changed if the message has already been sent.
141            return false;
142        this->message_ = message;
143        return true;
144    }
145
146}
Note: See TracBrowser for help on using the repository browser.