Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

Changing from OrxonoxOverlays to CEGUI as means of displaying Notifications.
Still messy and not working completely but it's a start.

  • Property svn:eol-style set to native
File size: 4.1 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"
[7324]37#include "network/NetworkFunction.h"
[2280]38#include "NotificationManager.h"
39
[2435]40namespace orxonox
41{
[2911]42
[7163]43    CreateUnloadableFactory(Notification);
44
[7326]45    registerMemberNetworkFunction(Notification, sendHelper);
[7324]46
[2911]47    /**
48    @brief
49        Default constructor. Initializes the object.
50    */
[7324]51    Notification::Notification(BaseObject* creator) : BaseObject(creator), Synchronisable(creator)
[2280]52    {
[3196]53        RegisterObject(Notification);
[2911]54        this->initialize();
[7324]55        this->registerVariables();
[2280]56    }
[6417]57
[2911]58    /**
59    @brief
60        Constructor. Creates a Notification with the input message.
61    @param message
62        The message of the Notification.
63    */
[7324]64    Notification::Notification(BaseObject* creator, const std::string & message) : BaseObject(creator), Synchronisable(creator)
[2280]65    {
[7193]66        RegisterObject(Notification);
67        this->initialize();
[2280]68        this->message_ = message;
[7324]69        this->registerVariables();
[2280]70    }
[6417]71
[2911]72    /**
73    @brief
74        Destructor.
75    */
[2280]76    Notification::~Notification()
77    {
[7163]78
[2280]79    }
[6417]80
[2911]81    /**
82    @brief
83        Registers the object and sets some default values.
84    */
[2280]85    void Notification::initialize(void)
86    {
[6417]87        this->message_.clear();
[2911]88        this->sender_ = NotificationManager::NONE;
[2280]89        this->sent_ = false;
90    }
[6417]91
[7324]92    void Notification::registerVariables(void)
[2280]93    {
[7324]94        registerVariable(this->message_);
95        registerVariable(this->sender_);
[7338]96        registerVariable(this->sent_, ObjectDirection::Bidirectional);
[2280]97    }
[6417]98
[2911]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    */
[7324]107    bool Notification::send(unsigned int clientId, const std::string & sender = NotificationManager::NONE)
[2280]108    {
[6417]109
[7338]110        if(GameMode::isMaster())
111        {
112            this->sendHelper(sender);
113        }
114        else
115        {
116            callMemberNetworkFunction(Notification, sendHelper, this->getObjectID(), clientId, sender);
117        }
[6417]118
[7326]119        return true;
120    }
[7324]121
[7338]122    bool Notification::sendHelper(const std::string& sender)
[7326]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
[2435]135        return true;
[2280]136    }
[6417]137
[2911]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    */
[2280]146    bool Notification::setMessage(const std::string & message)
147    {
[2911]148        if(this->isSent()) //!< The message cannot be changed if the message has already been sent.
[2280]149            return false;
[2435]150        this->message_ = message;
151        return true;
[2280]152    }
[2911]153
[2280]154}
Note: See TracBrowser for help on using the repository browser.