| 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 | /** | 
|---|
| 30 |     @file | 
|---|
| 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" | 
|---|
| 40 |  | 
|---|
| 41 | #include <sstream> | 
|---|
| 42 |  | 
|---|
| 43 | namespace orxonox { | 
|---|
| 44 |  | 
|---|
| 45 |     CreateFactory(CommandNotification); | 
|---|
| 46 |  | 
|---|
| 47 |     /** | 
|---|
| 48 |     @brief | 
|---|
| 49 |         Default Constructor. Registers the object and initializes variables. | 
|---|
| 50 |     */ | 
|---|
| 51 |     CommandNotification::CommandNotification(BaseObject* creator) : NotificationDispatcher(creator) | 
|---|
| 52 |     { | 
|---|
| 53 |         RegisterObject(CommandNotification); | 
|---|
| 54 |  | 
|---|
| 55 |         this->setSender("commandNotification"); | 
|---|
| 56 |     } | 
|---|
| 57 |  | 
|---|
| 58 |     /** | 
|---|
| 59 |     @brief | 
|---|
| 60 |         Destructor. | 
|---|
| 61 |     */ | 
|---|
| 62 |     CommandNotification::~CommandNotification() | 
|---|
| 63 |     { | 
|---|
| 64 |          | 
|---|
| 65 |     } | 
|---|
| 66 |  | 
|---|
| 67 |     /** | 
|---|
| 68 |     @brief | 
|---|
| 69 |         Method for creating a NotificationDispatcher object through XML. | 
|---|
| 70 |     */ | 
|---|
| 71 |     void CommandNotification::XMLPort(Element& xmlelement, XMLPort::Mode mode) | 
|---|
| 72 |     { | 
|---|
| 73 |         SUPER(CommandNotification, XMLPort, xmlelement, mode); | 
|---|
| 74 |  | 
|---|
| 75 |         XMLPortParam(CommandNotification, "command", setCommand, getCommand, xmlelement, mode); | 
|---|
| 76 |         XMLPortParam(CommandNotification, "preMessage", setPreMessage, getPreMessage, xmlelement, mode); | 
|---|
| 77 |         XMLPortParam(CommandNotification, "postMessage", setPostMessage, getPostMessage, xmlelement, mode); | 
|---|
| 78 |     } | 
|---|
| 79 |  | 
|---|
| 80 |     /** | 
|---|
| 81 |     @brief | 
|---|
| 82 |         Composes the Notification of the preMessage the name of the key the command is mapped to and the postMessage. | 
|---|
| 83 |     @return | 
|---|
| 84 |         Returns the message to be sent in the Notification. | 
|---|
| 85 |     */ | 
|---|
| 86 |     const std::string& CommandNotification::createNotificationMessage(void) | 
|---|
| 87 |     { | 
|---|
| 88 |         std::stringstream stream; | 
|---|
| 89 |         stream << this->getPreMessage(); | 
|---|
| 90 |         //TODO: Add niceifyer. | 
|---|
| 91 |         stream << KeyBinderManager::getInstance().getCurrent()->getBinding(this->getCommand()); | 
|---|
| 92 |         stream << this->getPostMessage(); | 
|---|
| 93 |         std::string* message = new std::string(stream.str()); | 
|---|
| 94 |         return *message; | 
|---|
| 95 |     } | 
|---|
| 96 |      | 
|---|
| 97 | } | 
|---|