SuperTuxKart
Loading...
Searching...
No Matches
device_config.hpp
1//
2// SuperTuxKart - a fun racing game with go-kart
3// Copyright (C) 2010-2015 SuperTuxKart-Team
4//
5// This program is free software; you can redistribute it and/or
6// modify it under the terms of the GNU General Public License
7// as published by the Free Software Foundation; either version 3
8// of the License, or (at your option) any later version.
9//
10// This program is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with this program; if not, write to the Free Software
17// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18
19#ifndef HEADER_DEVICE_CONFIG_HPP
20#define HEADER_DEVICE_CONFIG_HPP
21
22#include "input/binding.hpp"
23#include "input/input.hpp"
24#include "utils/no_copy.hpp"
25
26#include <assert.h>
27#include <iosfwd>
28#include <irrString.h>
29#include <string>
30
35//==== D E V I C E C O N F I G =================================================
36
41class DeviceConfig : public NoCopy
42{
43
44private:
48
51
53 std::string m_name;
54
56 irr::core::stringw m_config_name;
57
58protected:
59
60 Binding m_bindings[PA_COUNT];
61
63
64 bool doGetAction(Input::InputType type,
65 const int id,
66 int* value, /* inout */
67 const PlayerAction firstActionToCheck,
68 const PlayerAction lastActionToCheck,
69 PlayerAction* action /* out */ );
70protected:
72 friend class GamePadDevice;
73 friend class KeyboardDevice;
74 bool getGameAction(Input::InputType type,
75 const int id,
76 int* value, /* inout */
77 PlayerAction* action /* out */);
78
79public:
80
81 virtual ~DeviceConfig() {}
82
83 static DeviceConfig* create(const XMLNode *config);
84 irr::core::stringw toString();
85 bool hasBindingFor(const int buttonID) const;
86 bool hasBindingFor(const int buttonID, PlayerAction from,
87 PlayerAction to) const;
88 void setBinding(const PlayerAction action,
89 const Input::InputType type,
90 const int id,
91 Input::AxisDirection direction = Input::AD_NEUTRAL,
92 Input::AxisRange range = Input::AR_HALF);
93 bool getMenuAction(Input::InputType type,
94 const int id,
95 int* value,
96 PlayerAction* action /* out */);
97 irr::core::stringw getMappingIdString (const PlayerAction action) const;
98 virtual irr::core::stringw getBindingAsString(const PlayerAction action) const;
99 virtual bool isGamePad() const = 0;
100 virtual bool isKeyboard() const = 0;
101
102 virtual void save(std::ofstream& stream);
103 virtual bool load(const XMLNode *config);
104
105 // ------------------------------------------------------------------------
108 virtual bool isAnalog(Input::InputType type, int id) const { return false;}
109 // ------------------------------------------------------------------------
112 virtual bool desensitize() const { return false;}
113 // ------------------------------------------------------------------------
116 virtual int getNumberOfButtons() const
117 {
118 assert(false); return 0;
119 } // getNumberOfButtons
120
121 // ------------------------------------------------------------------------
124 virtual int getNumberOfAxes() const
125 {
126 assert(false); return 0;
127 } // getNumberOfAxes
128
129 // ------------------------------------------------------------------------
131 void setName(const std::string &name) { m_name = name; }
132
133 // ------------------------------------------------------------------------
135 const std::string& getName() const { return m_name; };
136
137 // ------------------------------------------------------------------------
139 void setPlugged() { m_plugged++; }
140
141 // ------------------------------------------------------------------------
143 bool isPlugged() const { return m_plugged > 0; }
144
145 // ------------------------------------------------------------------------
148 {
149 m_plugged--;
150 assert(m_plugged >= 0);
151 }
152
153 // ------------------------------------------------------------------------
155 int getNumberOfDevices() const { return m_plugged; }
156
157 // ------------------------------------------------------------------------
159 const Binding& getBinding(int i) const {return m_bindings[i];}
160
161 // ------------------------------------------------------------------------
163 bool isEnabled() const { return m_enabled; }
164
165 // ------------------------------------------------------------------------
167 void setEnabled(bool new_value) { m_enabled = new_value; }
168
169 // ------------------------------------------------------------------------
171 irr::core::stringw getConfigName() const { return m_config_name; }
172
173 // ------------------------------------------------------------------------
175 void setConfigName( irr::core::stringw config_name ) { m_config_name = config_name; }
176}; // class DeviceConfig
177
178#endif
Definition: binding.hpp:37
contains the key bindings information related to one input device
Definition: device_config.hpp:42
int getNumberOfDevices() const
Returns the number of devices using this configuration.
Definition: device_config.hpp:155
bool m_enabled
If set to false, this device will be ignored.
Definition: device_config.hpp:47
bool isPlugged() const
Returns if this config is sed by any devices.
Definition: device_config.hpp:143
void setPlugged()
Increase ref counter.
Definition: device_config.hpp:139
virtual int getNumberOfAxes() const
Should only be called for gamepads, which has its own implementation.
Definition: device_config.hpp:124
bool isEnabled() const
At this time only relevant for gamepads, keyboards are always enabled.
Definition: device_config.hpp:163
void setEnabled(bool new_value)
Sets this config to be enabled or disabled.
Definition: device_config.hpp:167
irr::core::stringw getConfigName() const
Sets the name of this device configuration.
Definition: device_config.hpp:171
virtual void save(std::ofstream &stream)
Saves the configuration to a file.
Definition: device_config.cpp:287
int m_plugged
How many devices connected to the system which uses this config?
Definition: device_config.hpp:50
void setName(const std::string &name)
Sets the internal name of this device.
Definition: device_config.hpp:131
static DeviceConfig * create(const XMLNode *config)
A simple factory that creates either a gamepad or a keyboard configuration.
Definition: device_config.cpp:40
void setBinding(const PlayerAction action, const Input::InputType type, const int id, Input::AxisDirection direction=Input::AD_NEUTRAL, Input::AxisRange range=Input::AR_HALF)
Sets the bindings for an action.
Definition: device_config.cpp:178
virtual bool isAnalog(Input::InputType type, int id) const
Returns true if this device has analog axis, so that steering values will not be affected by time-ful...
Definition: device_config.hpp:108
bool getMenuAction(Input::InputType type, const int id, int *value, PlayerAction *action)
Searches for a game actions associated with the given input event.
Definition: device_config.cpp:212
const Binding & getBinding(int i) const
Returns the binding of a given index.
Definition: device_config.hpp:159
const std::string & getName() const
Returns the internal name for this device configuration.
Definition: device_config.hpp:135
virtual bool load(const XMLNode *config)
Reads a device configuration from input.xml.
Definition: device_config.cpp:310
bool getGameAction(Input::InputType type, const int id, int *value, PlayerAction *action)
Searches for a game actions associated with the given input event.
Definition: device_config.cpp:195
virtual irr::core::stringw getBindingAsString(const PlayerAction action) const
Get a user-readable string describing the bound action.
Definition: device_config.cpp:78
bool doGetAction(Input::InputType type, const int id, int *value, const PlayerAction firstActionToCheck, const PlayerAction lastActionToCheck, PlayerAction *action)
internal helper method for DeviceConfig::getGameAction and DeviceConfig::getMenuAction
Definition: device_config.cpp:225
virtual int getNumberOfButtons() const
Should only be called for gamepads, which has its own implementation.
Definition: device_config.hpp:116
irr::core::stringw getMappingIdString(const PlayerAction action) const
Get an internal unique string describing the bound action.
Definition: device_config.cpp:94
std::string m_name
Internal name of this configuration.
Definition: device_config.hpp:53
virtual bool desensitize() const
Returns true if this device should desensitize its input at values close to 0 (to avoid 'oversteering...
Definition: device_config.hpp:112
void setConfigName(irr::core::stringw config_name)
Returns the name of this device configuration.
Definition: device_config.hpp:175
irr::core::stringw m_config_name
Name of this configuration (given by the user).
Definition: device_config.hpp:56
void unPlugged()
Decrease ref counter.
Definition: device_config.hpp:147
specialisation of Inputdevice for gamepad type devices
Definition: gamepad_device.hpp:33
specialisation of InputDevice for keyboard type devices
Definition: keyboard_device.hpp:34
Utility class, you can inherit from this class to disallow the assignment operator and copy construct...
Definition: no_copy.hpp:26
utility class used to parse XML files
Definition: xml_node.hpp:48
PlayerAction
types of input events / what actions the players can do
Definition: input.hpp:117