1 //
2 //  SuperTuxKart - a fun racing game with go-kart
3 //  Copyright (C) 2007-2015 Robert Schuster <robertschuster@fsfe.org>
4 //  Copyright (C) 2012-2015 SuperTuxKart-Team
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 3
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
19 
20 #ifndef HEADER_INPUT_HPP
21 #define HEADER_INPUT_HPP
22 
23 /**
24   * \defgroup input
25   * Contains classes for input management (keyboard and gamepad)
26   */
27 
28 #include <string>
29 #include <irrString.h>
30 
31 /**
32   * \ingroup input
33   */
34 struct Input
35 {
36     static const int MAX_VALUE = 32768;
37 
38     static const int HAT_H_ID = 100;
39     static const int HAT_V_ID = 101;
40 
41     enum AxisDirection
42     {
43         AD_NEGATIVE,
44         AD_POSITIVE,
45         AD_NEUTRAL
46     };
47 
48     enum AxisRange
49     {
50         AR_HALF,
51         AR_FULL
52     };
53 
54     enum InputType
55     {
56         IT_NONE = 0,
57         IT_KEYBOARD,
58         IT_STICKMOTION,
59         IT_STICKBUTTON,
60         //IT_STICKHAT,
61         IT_MOUSEMOTION,
62         IT_MOUSEBUTTON
63     };
64     static const int IT_LAST = IT_MOUSEBUTTON;
65 
66     InputType m_type;
67     int       m_device_id;
68     int       m_button_id; // or axis ID for gamepads axes
69     int       m_axis_direction;
70     int       m_axis_range;
71     wchar_t   m_character;
72 
InputInput73     Input()
74         : m_type(IT_NONE), m_device_id(0), m_button_id(0),
75         m_axis_direction(0), m_axis_range(Input::AR_FULL), m_character(0)
76     {
77         // Nothing to do.
78     }
79 
80     /** Creates an Input instance which represents an arbitrary way of getting
81      * game input using a type specifier and 3 integers.
82      *
83      * Meaning of the 3 integers for each InputType:
84      * IT_NONE: This means nothing. In certain cases this is regarded as an
85      * unset binding.
86      * IT_KEYBOARD: id0 is a irrLicht value.
87      * IT_STICKMOTION: id0 - stick index, id1 - axis index, id2 - axis direction
88      * (negative, positive). You can assume that axis 0 is the X-Axis where the
89      * negative direction is to the left and that axis 1 is the Y-Axis with the
90      * negative direction being upwards.
91      * IT_STICKBUTTON: id0 - stick index, id1 - button index. Button 0 and 1 are
92      * usually reached most easily.
93      * IT_STICKHAT: This is not yet implemented.
94      * IT_MOUSEMOTION: id0 - axis index (0 -> X, 1 -> Y). Mouse wheel is
95      * represented as buttons!
96      * IT_MOUSEBUTTON: id0 - button number (1 -> left, 2 -> middle, 3 -> right,
97      * ...)
98      *
99      * Note: For joystick bindings that are actice in the menu the joystick's
100      * index should be zero. The binding will react to all joysticks connected
101      * to the system.
102      */
InputInput103     Input(InputType ntype, int deviceID , int btnID = 0, int axisDirection= 0)
104         : m_type(ntype), m_device_id(deviceID), m_button_id(btnID),
105           m_axis_direction(axisDirection), m_axis_range(Input::AR_FULL)
106     {
107         // Nothing to do.
108     }
109 
110 };   // struct Input
111 
112 /**
113   * \brief types of input events / what actions the players can do
114   * \ingroup input
115   */
116 enum PlayerAction
117 {
118     PA_BEFORE_FIRST = -1,
119 
120     PA_STEER_LEFT = 0,
121     PA_STEER_RIGHT,
122     PA_ACCEL,
123     PA_BRAKE,
124     PA_NITRO,
125     PA_DRIFT,
126     PA_RESCUE,
127     PA_FIRE,
128     PA_LOOK_BACK,
129     PA_PAUSE_RACE,
130 
131     PA_MENU_UP,
132     PA_MENU_DOWN,
133     PA_MENU_LEFT,
134     PA_MENU_RIGHT,
135     PA_MENU_SELECT,
136     PA_MENU_CANCEL,
137 
138     PA_COUNT
139 };
140 
141 const PlayerAction PA_FIRST_GAME_ACTION = PA_STEER_LEFT;
142 const PlayerAction PA_LAST_GAME_ACTION = PA_PAUSE_RACE;
143 const PlayerAction PA_FIRST_MENU_ACTION = PA_MENU_UP;
144 const PlayerAction PA_LAST_MENU_ACTION = PA_MENU_CANCEL;
145 
146 /**
147   * \brief  human-readable strings for each PlayerAction
148   * \ingroup input
149   */
150 static std::string KartActionStrings[PA_COUNT] = {std::string("steerLeft"),
151                                                   std::string("steerRight"),
152                                                   std::string("accel"),
153                                                   std::string("brake"),
154                                                   std::string("nitro"),
155                                                   std::string("drift"),
156                                                   std::string("rescue"),
157                                                   std::string("fire"),
158                                                   std::string("lookBack"),
159                                                   std::string("pauserace"),
160                                                   std::string("menuUp"),
161                                                   std::string("menuDown"),
162                                                   std::string("menuLeft"),
163                                                   std::string("menuRight"),
164                                                   std::string("menuSelect"),
165                                                   std::string("menuCancel")
166                                                   };
167 
168 #endif
169