Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/trunk/src/modules/notifications/dispatchers/CommandNotification.cc @ 7456

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

Reviewing documentation fo Questsystem, moving documentation fully into doxygen.
Added some files to modules they belong to.

  • Property svn:eol-style set to native
File size: 4.2 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 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 CommandNotification.cc
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#include "util/SubString.h"
41
42#include <sstream>
43
44namespace orxonox {
45
46    CreateFactory(CommandNotification);
47
48    /**
49    @brief
50        Default Constructor. Registers the object and initializes variables.
51    */
52    CommandNotification::CommandNotification(BaseObject* creator) : NotificationDispatcher(creator)
53    {
54        RegisterObject(CommandNotification);
55
56        this->setSender("commandNotification");
57    }
58
59    /**
60    @brief
61        Destructor.
62    */
63    CommandNotification::~CommandNotification()
64    {
65       
66    }
67
68    /**
69    @brief
70        Method for creating a NotificationDispatcher object through XML.
71    */
72    void CommandNotification::XMLPort(Element& xmlelement, XMLPort::Mode mode)
73    {
74        SUPER(CommandNotification, XMLPort, xmlelement, mode);
75
76        XMLPortParam(CommandNotification, "command", setCommand, getCommand, xmlelement, mode);
77        XMLPortParam(CommandNotification, "preMessage", setPreMessage, getPreMessage, xmlelement, mode);
78        XMLPortParam(CommandNotification, "postMessage", setPostMessage, getPostMessage, xmlelement, mode);
79    }
80
81    /**
82    @brief
83        Composes the Notification of the preMessage the name of the key the command is mapped to and the postMessage.
84    @return
85        Returns the message to be sent in the Notification.
86    */
87    const std::string& CommandNotification::createNotificationMessage(void)
88    {
89        std::stringstream stream;
90        stream << this->getPreMessage();
91        stream << this->bindingNiceifyer(KeyBinderManager::getInstance().getCurrent()->getBinding(this->getCommand()));
92        stream << this->getPostMessage();
93        return *(new std::string(stream.str()));
94    }
95
96    /**
97    @brief
98        Transforms the input binding into a human readable form.
99    @param binding
100        The binding to be transformed
101    @return
102        Returns a human readable version of the input binding.
103    */
104    const std::string& CommandNotification::bindingNiceifyer(const std::string& binding)
105    {
106        SubString string = SubString(binding, ".");
107        std::string name;
108        std::string group;
109        switch(string.size())
110        {
111            case 0:
112                return binding;
113            case 1:
114                return binding;
115            case 2:
116                group = string[0];
117            default:
118                name = string.subSet(1, string.size()).join(".");
119        }
120
121        std::stringstream stream;
122        if(group.compare("Keys") == 0)
123            stream << "Key " << name.substr(3);
124        else if(group.compare("MouseButtons") == 0)
125            stream << "Mouse " << name;
126        else if(group.compare("JoyStickButtons") == 0)
127            stream << "Joystick " << name;
128        else if(group.compare("JoyStickAxes") == 0)
129            stream << "Joystick Axis" << name.substr(5, 6) << name.substr(name.find("Axis")+6);
130        else if(group.compare("MouseAxes") == 0)
131            stream << "Mouse " << name.substr(1,3) << " " << name.substr(0, 1) << "-Axis";
132        else
133            return binding;
134
135        return *(new std::string(stream.str()));
136    }
137   
138}
Note: See TracBrowser for help on using the repository browser.