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