summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorRĂ©mi Verschelde <rverschelde@gmail.com>2020-11-19 20:43:44 +0100
committerGitHub <noreply@github.com>2020-11-19 20:43:44 +0100
commit6a683f80169850d1138c38f7182bdcadf4dafd10 (patch)
treeb1afd58754cbf7cb1935ece4d3164c65e6bcac7d /core
parentf69339c2c259bec6f5145da4a3d5c89bfe51653f (diff)
parent20f2b71e214737e7065e4095050ed85c94a5dd7d (diff)
Merge pull request #43591 from madmiraal/fix-43520
Update joy button and stick names, enums and documentation
Diffstat (limited to 'core')
-rw-r--r--core/core_constants.cpp41
-rw-r--r--core/input/input.cpp106
-rw-r--r--core/input/input.h5
-rw-r--r--core/input/input_event.h57
4 files changed, 20 insertions, 189 deletions
diff --git a/core/core_constants.cpp b/core/core_constants.cpp
index 4229436e84..64bfff1c58 100644
--- a/core/core_constants.cpp
+++ b/core/core_constants.cpp
@@ -409,7 +409,7 @@ void register_global_constants() {
BIND_CORE_ENUM_CONSTANT(BUTTON_MASK_XBUTTON2);
// Joypad buttons
- BIND_CORE_ENUM_CONSTANT(JOY_INVALID_BUTTON);
+ BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_INVALID);
BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_A);
BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_B);
BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_X);
@@ -425,51 +425,18 @@ void register_global_constants() {
BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_DOWN);
BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_LEFT);
BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_RIGHT);
- BIND_CORE_ENUM_CONSTANT(JOY_SDL_BUTTONS);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_X);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_CROSS);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_CIRCLE);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_SQUARE);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_TRIANGLE);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_SELECT);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_START);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_PS);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_L1);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_R1);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_L3);
- BIND_CORE_ENUM_CONSTANT(JOY_SONY_R3);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_A);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_B);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_X);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_Y);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_BACK);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_START);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_HOME);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_LS);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_RS);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_LB);
- BIND_CORE_ENUM_CONSTANT(JOY_XBOX_RB);
+ BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_SDL_MAX);
BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_MAX);
// Joypad axes
- BIND_CORE_ENUM_CONSTANT(JOY_INVALID_AXIS);
+ BIND_CORE_ENUM_CONSTANT(JOY_AXIS_INVALID);
BIND_CORE_ENUM_CONSTANT(JOY_AXIS_LEFT_X);
BIND_CORE_ENUM_CONSTANT(JOY_AXIS_LEFT_Y);
BIND_CORE_ENUM_CONSTANT(JOY_AXIS_RIGHT_X);
BIND_CORE_ENUM_CONSTANT(JOY_AXIS_RIGHT_Y);
BIND_CORE_ENUM_CONSTANT(JOY_AXIS_TRIGGER_LEFT);
BIND_CORE_ENUM_CONSTANT(JOY_AXIS_TRIGGER_RIGHT);
- BIND_CORE_ENUM_CONSTANT(JOY_SDL_AXES);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_0_X);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_0_Y);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_1_X);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_1_Y);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_2_X);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_2_Y);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_3_X);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_3_Y);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_4_X);
- BIND_CORE_ENUM_CONSTANT(JOY_AXIS_4_Y);
+ BIND_CORE_ENUM_CONSTANT(JOY_AXIS_SDL_MAX);
BIND_CORE_ENUM_CONSTANT(JOY_AXIS_MAX);
// midi
diff --git a/core/input/input.cpp b/core/input/input.cpp
index aa64ac09a7..00a7e63a73 100644
--- a/core/input/input.cpp
+++ b/core/input/input.cpp
@@ -39,7 +39,7 @@
#include "editor/editor_settings.h"
#endif
-static const char *_joy_buttons[JOY_SDL_BUTTONS + 1] = {
+static const char *_joy_buttons[JOY_BUTTON_SDL_MAX] = {
"a",
"b",
"x",
@@ -55,69 +55,15 @@ static const char *_joy_buttons[JOY_SDL_BUTTONS + 1] = {
"dpdown",
"dpleft",
"dpright",
- nullptr
};
-static const char *_joy_button_names[JOY_BUTTON_MAX] = {
- "Face Bottom",
- "Face Right",
- "Face Left",
- "Face Top",
- "Select",
- "Guide",
- "Start",
- "Left Stick",
- "Right Stick",
- "Left Shoulder",
- "Right Shoulder",
- "D-Pad Up",
- "D-Pad Down",
- "D-Pad Left",
- "D-Pad Right",
- "Button 15",
- "Button 16",
- "Button 17",
- "Button 18",
- "Button 19",
- "Button 20",
- "Button 21",
- "Button 22",
- "Button 23",
- "Button 24",
- "Button 25",
- "Button 26",
- "Button 27",
- "Button 28",
- "Button 29",
- "Button 30",
- "Button 31",
- "Button 32",
- "Button 33",
- "Button 34",
- "Button 35"
-};
-
-static const char *_joy_axes[JOY_SDL_AXES + 1] = {
+static const char *_joy_axes[JOY_AXIS_SDL_MAX] = {
"leftx",
"lefty",
"rightx",
"righty",
"lefttrigger",
"righttrigger",
- nullptr
-};
-
-static const char *_joy_axis_names[JOY_AXIS_MAX] = {
- "Left Stick X",
- "Left Stick Y",
- "Right Stick X",
- "Right Stick Y",
- "Left Trigger",
- "Right Trigger",
- "Joystick 3 Stick X",
- "Joystick 3 Stick Y",
- "Joystick 4 Stick X",
- "Joystick 4 Stick Y"
};
Input *Input::singleton = nullptr;
@@ -162,10 +108,6 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_connected_joypads"), &Input::get_connected_joypads);
ClassDB::bind_method(D_METHOD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength);
ClassDB::bind_method(D_METHOD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration);
- ClassDB::bind_method(D_METHOD("get_joy_button_string", "button_index"), &Input::get_joy_button_string);
- ClassDB::bind_method(D_METHOD("get_joy_button_index_from_string", "button"), &Input::get_joy_button_index_from_string);
- ClassDB::bind_method(D_METHOD("get_joy_axis_string", "axis_index"), &Input::get_joy_axis_string);
- ClassDB::bind_method(D_METHOD("get_joy_axis_index_from_string", "axis"), &Input::get_joy_axis_index_from_string);
ClassDB::bind_method(D_METHOD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0));
ClassDB::bind_method(D_METHOD("stop_joy_vibration", "device"), &Input::stop_joy_vibration);
ClassDB::bind_method(D_METHOD("vibrate_handheld", "duration_ms"), &Input::vibrate_handheld, DEFVAL(500));
@@ -1226,21 +1168,21 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p_hat, J
}
JoyButtonList Input::_get_output_button(String output) {
- for (int i = 0; _joy_buttons[i]; i++) {
+ for (int i = 0; i < JOY_BUTTON_SDL_MAX; i++) {
if (output == _joy_buttons[i]) {
return JoyButtonList(i);
}
}
- return JoyButtonList::JOY_INVALID_BUTTON;
+ return JoyButtonList::JOY_BUTTON_INVALID;
}
JoyAxisList Input::_get_output_axis(String output) {
- for (int i = 0; _joy_axes[i]; i++) {
+ for (int i = 0; i < JOY_AXIS_SDL_MAX; i++) {
if (output == _joy_axes[i]) {
return JoyAxisList(i);
}
}
- return JoyAxisList::JOY_INVALID_AXIS;
+ return JoyAxisList::JOY_AXIS_INVALID;
}
void Input::parse_mapping(String p_mapping) {
@@ -1300,16 +1242,16 @@ void Input::parse_mapping(String p_mapping) {
JoyButtonList output_button = _get_output_button(output);
JoyAxisList output_axis = _get_output_axis(output);
- ERR_CONTINUE_MSG(output_button == JOY_INVALID_BUTTON && output_axis == JOY_INVALID_AXIS,
+ ERR_CONTINUE_MSG(output_button == JOY_BUTTON_INVALID && output_axis == JOY_AXIS_INVALID,
String(entry[idx] + "\nUnrecognised output string: " + output));
- ERR_CONTINUE_MSG(output_button != JOY_INVALID_BUTTON && output_axis != JOY_INVALID_AXIS,
+ ERR_CONTINUE_MSG(output_button != JOY_BUTTON_INVALID && output_axis != JOY_AXIS_INVALID,
String("BUG: Output string matched both button and axis: " + output));
JoyBinding binding;
- if (output_button != JOY_INVALID_BUTTON) {
+ if (output_button != JOY_BUTTON_INVALID) {
binding.outputType = TYPE_BUTTON;
binding.output.button = output_button;
- } else if (output_axis != JOY_INVALID_AXIS) {
+ } else if (output_axis != JOY_AXIS_INVALID) {
binding.outputType = TYPE_AXIS;
binding.output.axis.axis = output_axis;
binding.output.axis.range = output_range;
@@ -1401,20 +1343,6 @@ Array Input::get_connected_joypads() {
return ret;
}
-String Input::get_joy_button_string(int p_button) {
- ERR_FAIL_INDEX_V(p_button, JOY_BUTTON_MAX, "Invalid button");
- return _joy_button_names[p_button];
-}
-
-int Input::get_joy_button_index_from_string(String p_button) {
- for (int i = 0; i < JOY_BUTTON_MAX; i++) {
- if (p_button == _joy_button_names[i]) {
- return i;
- }
- }
- ERR_FAIL_V(JOY_INVALID_BUTTON);
-}
-
int Input::get_unused_joy_id() {
for (int i = 0; i < JOYPADS_MAX; i++) {
if (!joy_names.has(i) || !joy_names[i].connected) {
@@ -1424,20 +1352,6 @@ int Input::get_unused_joy_id() {
return -1;
}
-String Input::get_joy_axis_string(int p_axis) {
- ERR_FAIL_INDEX_V(p_axis, JOY_AXIS_MAX, "Invalid axis");
- return _joy_axis_names[p_axis];
-}
-
-int Input::get_joy_axis_index_from_string(String p_axis) {
- for (int i = 0; i < JOY_AXIS_MAX; i++) {
- if (p_axis == _joy_axis_names[i]) {
- return i;
- }
- }
- ERR_FAIL_V(JOY_INVALID_AXIS);
-}
-
Input::Input() {
singleton = this;
diff --git a/core/input/input.h b/core/input/input.h
index 46e9d24bf2..1b2df49ac0 100644
--- a/core/input/input.h
+++ b/core/input/input.h
@@ -330,11 +330,6 @@ public:
void add_joy_mapping(String p_mapping, bool p_update_existing = false);
void remove_joy_mapping(String p_guid);
- String get_joy_button_string(int p_button);
- String get_joy_axis_string(int p_axis);
- int get_joy_axis_index_from_string(String p_axis);
- int get_joy_button_index_from_string(String p_button);
-
int get_unused_joy_id();
bool is_joy_known(int p_device);
diff --git a/core/input/input_event.h b/core/input/input_event.h
index 52b785c9a1..0eae3a2bbe 100644
--- a/core/input/input_event.h
+++ b/core/input/input_event.h
@@ -60,9 +60,7 @@ enum ButtonList {
};
enum JoyButtonList {
- JOY_INVALID_BUTTON = -1,
-
- // SDL Buttons
+ JOY_BUTTON_INVALID = -1,
JOY_BUTTON_A = 0,
JOY_BUTTON_B = 1,
JOY_BUTTON_X = 2,
@@ -78,63 +76,20 @@ enum JoyButtonList {
JOY_BUTTON_DPAD_DOWN = 12,
JOY_BUTTON_DPAD_LEFT = 13,
JOY_BUTTON_DPAD_RIGHT = 14,
- JOY_SDL_BUTTONS = 15,
-
- // Sony Buttons
- JOY_SONY_X = JOY_BUTTON_A,
- JOY_SONY_CROSS = JOY_BUTTON_A,
- JOY_SONY_CIRCLE = JOY_BUTTON_B,
- JOY_SONY_SQUARE = JOY_BUTTON_X,
- JOY_SONY_TRIANGLE = JOY_BUTTON_Y,
- JOY_SONY_SELECT = JOY_BUTTON_BACK,
- JOY_SONY_START = JOY_BUTTON_START,
- JOY_SONY_PS = JOY_BUTTON_GUIDE,
- JOY_SONY_L1 = JOY_BUTTON_LEFT_SHOULDER,
- JOY_SONY_R1 = JOY_BUTTON_RIGHT_SHOULDER,
- JOY_SONY_L3 = JOY_BUTTON_LEFT_STICK,
- JOY_SONY_R3 = JOY_BUTTON_RIGHT_STICK,
-
- // Xbox Buttons
- JOY_XBOX_A = JOY_BUTTON_A,
- JOY_XBOX_B = JOY_BUTTON_B,
- JOY_XBOX_X = JOY_BUTTON_X,
- JOY_XBOX_Y = JOY_BUTTON_Y,
- JOY_XBOX_BACK = JOY_BUTTON_BACK,
- JOY_XBOX_START = JOY_BUTTON_START,
- JOY_XBOX_HOME = JOY_BUTTON_GUIDE,
- JOY_XBOX_LS = JOY_BUTTON_LEFT_STICK,
- JOY_XBOX_RS = JOY_BUTTON_RIGHT_STICK,
- JOY_XBOX_LB = JOY_BUTTON_LEFT_SHOULDER,
- JOY_XBOX_RB = JOY_BUTTON_RIGHT_SHOULDER,
-
- JOY_BUTTON_MAX = 36 // Apparently Android supports up to 36 buttons.
+ JOY_BUTTON_SDL_MAX = 15,
+ JOY_BUTTON_MAX = 36, // Android supports up to 36 buttons.
};
enum JoyAxisList {
- JOY_INVALID_AXIS = -1,
-
- // SDL Axes
+ JOY_AXIS_INVALID = -1,
JOY_AXIS_LEFT_X = 0,
JOY_AXIS_LEFT_Y = 1,
JOY_AXIS_RIGHT_X = 2,
JOY_AXIS_RIGHT_Y = 3,
JOY_AXIS_TRIGGER_LEFT = 4,
JOY_AXIS_TRIGGER_RIGHT = 5,
- JOY_SDL_AXES = 6,
-
- // Joystick axes.
- JOY_AXIS_0_X = 0,
- JOY_AXIS_0_Y = 1,
- JOY_AXIS_1_X = 2,
- JOY_AXIS_1_Y = 3,
- JOY_AXIS_2_X = 4,
- JOY_AXIS_2_Y = 5,
- JOY_AXIS_3_X = 6,
- JOY_AXIS_3_Y = 7,
- JOY_AXIS_4_X = 8,
- JOY_AXIS_4_Y = 9,
-
- JOY_AXIS_MAX = 10 // OpenVR supports up to 5 Joysticks making a total of 10 axes.
+ JOY_AXIS_SDL_MAX = 6,
+ JOY_AXIS_MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes.
};
enum MidiMessageList {