| [7193] | 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 the |
|---|
| 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 | /** |
|---|
| [7456] | 30 | @file CommandNotification.cc |
|---|
| [7193] | 31 | @brief Implementation of the CommandNotification class. |
|---|
| 32 | */ |
|---|
| 33 | |
|---|
| 34 | #include "CommandNotification.h" |
|---|
| 35 | |
|---|
| 36 | #include "core/CoreIncludes.h" |
|---|
| 37 | #include "core/XMLPort.h" |
|---|
| 38 | #include "core/input/KeyBinderManager.h" |
|---|
| 39 | #include "core/input/KeyBinder.h" |
|---|
| [7403] | 40 | #include "util/SubString.h" |
|---|
| [7193] | 41 | |
|---|
| 42 | #include <sstream> |
|---|
| 43 | |
|---|
| 44 | namespace orxonox { |
|---|
| 45 | |
|---|
| [9667] | 46 | RegisterClass(CommandNotification); |
|---|
| [7193] | 47 | |
|---|
| 48 | /** |
|---|
| 49 | @brief |
|---|
| 50 | Default Constructor. Registers the object and initializes variables. |
|---|
| 51 | */ |
|---|
| [9667] | 52 | CommandNotification::CommandNotification(Context* context) : NotificationDispatcher(context) |
|---|
| [7193] | 53 | { |
|---|
| 54 | RegisterObject(CommandNotification); |
|---|
| 55 | |
|---|
| 56 | this->setSender("commandNotification"); |
|---|
| [7474] | 57 | this->registerVariables(); |
|---|
| [7193] | 58 | } |
|---|
| 59 | |
|---|
| 60 | /** |
|---|
| 61 | @brief |
|---|
| 62 | Destructor. |
|---|
| 63 | */ |
|---|
| 64 | CommandNotification::~CommandNotification() |
|---|
| 65 | { |
|---|
| [7489] | 66 | |
|---|
| [7193] | 67 | } |
|---|
| 68 | |
|---|
| 69 | /** |
|---|
| 70 | @brief |
|---|
| 71 | Method for creating a NotificationDispatcher object through XML. |
|---|
| 72 | */ |
|---|
| 73 | void CommandNotification::XMLPort(Element& xmlelement, XMLPort::Mode mode) |
|---|
| 74 | { |
|---|
| 75 | SUPER(CommandNotification, XMLPort, xmlelement, mode); |
|---|
| 76 | |
|---|
| 77 | XMLPortParam(CommandNotification, "command", setCommand, getCommand, xmlelement, mode); |
|---|
| 78 | XMLPortParam(CommandNotification, "preMessage", setPreMessage, getPreMessage, xmlelement, mode); |
|---|
| 79 | XMLPortParam(CommandNotification, "postMessage", setPostMessage, getPostMessage, xmlelement, mode); |
|---|
| 80 | } |
|---|
| 81 | |
|---|
| [7484] | 82 | /** |
|---|
| 83 | @brief |
|---|
| 84 | Register some variables for synchronisation. |
|---|
| 85 | */ |
|---|
| [7474] | 86 | void CommandNotification::registerVariables(void) |
|---|
| 87 | { |
|---|
| 88 | registerVariable(this->command_, VariableDirection::ToClient); |
|---|
| 89 | registerVariable(this->preMessage_, VariableDirection::ToClient); |
|---|
| 90 | registerVariable(this->postMessage_, VariableDirection::ToClient); |
|---|
| 91 | } |
|---|
| 92 | |
|---|
| [7193] | 93 | /** |
|---|
| 94 | @brief |
|---|
| 95 | Composes the Notification of the preMessage the name of the key the command is mapped to and the postMessage. |
|---|
| 96 | @return |
|---|
| 97 | Returns the message to be sent in the Notification. |
|---|
| 98 | */ |
|---|
| 99 | const std::string& CommandNotification::createNotificationMessage(void) |
|---|
| 100 | { |
|---|
| 101 | std::stringstream stream; |
|---|
| 102 | stream << this->getPreMessage(); |
|---|
| [11052] | 103 | stream << KeyBinderManager::getInstance().getCurrent()->getBindingReadable(this->getCommand()); |
|---|
| [7193] | 104 | stream << this->getPostMessage(); |
|---|
| [7403] | 105 | return *(new std::string(stream.str())); |
|---|
| [7193] | 106 | } |
|---|
| [11052] | 107 | } |
|---|