Skip to content

Commit

Permalink
Merge pull request #45798 from madmiraal/add-new-sdl-keywords-3.2
Browse files Browse the repository at this point in the history
[3.2] Add support for new SDL gamecontroller keywords.
  • Loading branch information
akien-mga authored Feb 8, 2021
2 parents 9fb27eb + 3dd57a2 commit e6101df
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 6 deletions.
6 changes: 6 additions & 0 deletions core/global_constants.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,12 @@ void register_global_constants() {
BIND_GLOBAL_ENUM_CONSTANT(JOY_R);
BIND_GLOBAL_ENUM_CONSTANT(JOY_R2);
BIND_GLOBAL_ENUM_CONSTANT(JOY_R3);
BIND_GLOBAL_ENUM_CONSTANT(JOY_MISC1);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE1);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE2);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE3);
BIND_GLOBAL_ENUM_CONSTANT(JOY_PADDLE4);
BIND_GLOBAL_ENUM_CONSTANT(JOY_TOUCHPAD);

BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_0);
BIND_GLOBAL_ENUM_CONSTANT(JOY_AXIS_1);
Expand Down
14 changes: 13 additions & 1 deletion core/os/input_event.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,13 @@ enum JoystickList {
JOY_BUTTON_13 = 13,
JOY_BUTTON_14 = 14,
JOY_BUTTON_15 = 15,
JOY_BUTTON_MAX = 16,
JOY_BUTTON_16 = 16,
JOY_BUTTON_17 = 17,
JOY_BUTTON_18 = 18,
JOY_BUTTON_19 = 19,
JOY_BUTTON_20 = 20,
JOY_BUTTON_21 = 21,
JOY_BUTTON_MAX = 22,

JOY_L = JOY_BUTTON_4,
JOY_R = JOY_BUTTON_5,
Expand All @@ -93,6 +99,12 @@ enum JoystickList {
JOY_DPAD_DOWN = JOY_BUTTON_13,
JOY_DPAD_LEFT = JOY_BUTTON_14,
JOY_DPAD_RIGHT = JOY_BUTTON_15,
JOY_MISC1 = JOY_BUTTON_16,
JOY_PADDLE1 = JOY_BUTTON_17,
JOY_PADDLE2 = JOY_BUTTON_18,
JOY_PADDLE3 = JOY_BUTTON_19,
JOY_PADDLE4 = JOY_BUTTON_20,
JOY_TOUCHPAD = JOY_BUTTON_21,

JOY_SONY_CIRCLE = JOY_BUTTON_1,
JOY_SONY_X = JOY_BUTTON_0,
Expand Down
38 changes: 37 additions & 1 deletion doc/classes/@GlobalScope.xml
Original file line number Diff line number Diff line change
Expand Up @@ -988,7 +988,25 @@
<constant name="JOY_BUTTON_15" value="15" enum="JoystickList">
Gamepad button 15.
</constant>
<constant name="JOY_BUTTON_MAX" value="16" enum="JoystickList">
<constant name="JOY_BUTTON_16" value="16" enum="JoystickList">
Gamepad button 16.
</constant>
<constant name="JOY_BUTTON_17" value="17" enum="JoystickList">
Gamepad button 17.
</constant>
<constant name="JOY_BUTTON_18" value="18" enum="JoystickList">
Gamepad button 18.
</constant>
<constant name="JOY_BUTTON_19" value="19" enum="JoystickList">
Gamepad button 19.
</constant>
<constant name="JOY_BUTTON_20" value="20" enum="JoystickList">
Gamepad button 20.
</constant>
<constant name="JOY_BUTTON_21" value="21" enum="JoystickList">
Gamepad button 21.
</constant>
<constant name="JOY_BUTTON_MAX" value="22" enum="JoystickList">
Represents the maximum number of joystick buttons supported.
</constant>
<constant name="JOY_SONY_CIRCLE" value="1" enum="JoystickList">
Expand Down Expand Up @@ -1066,6 +1084,24 @@
<constant name="JOY_DPAD_RIGHT" value="15" enum="JoystickList">
Gamepad DPad right.
</constant>
<constant name="JOY_MISC1" value="16" enum="JoyButtonList">
Gamepad SDL miscellaneous button.
</constant>
<constant name="JOY_PADDLE1" value="17" enum="JoyButtonList">
Gamepad SDL paddle 1 button.
</constant>
<constant name="JOY_PADDLE2" value="18" enum="JoyButtonList">
Gamepad SDL paddle 2 button.
</constant>
<constant name="JOY_PADDLE3" value="19" enum="JoyButtonList">
Gamepad SDL paddle 3 button.
</constant>
<constant name="JOY_PADDLE4" value="20" enum="JoyButtonList">
Gamepad SDL paddle 4 button.
</constant>
<constant name="JOY_TOUCHPAD" value="21" enum="JoyButtonList">
Gamepad SDL touchpad button.
</constant>
<constant name="JOY_L" value="4" enum="JoystickList">
Gamepad left Shoulder button.
</constant>
Expand Down
8 changes: 7 additions & 1 deletion editor/project_settings_editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,13 @@ static const char *_button_names[JOY_BUTTON_MAX] = {
"D-Pad Up",
"D-Pad Down",
"D-Pad Left",
"D-Pad Right"
"D-Pad Right",
"Xbox Share, PS5 Microphone, Nintendo Capture",
"Xbox Paddle 1",
"Xbox Paddle 2",
"Xbox Paddle 3",
"Xbox Paddle 4",
"PS4/5 Touchpad",
};

static const char *_axis_names[JOY_AXIS_MAX * 2] = {
Expand Down
8 changes: 7 additions & 1 deletion main/input_default.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ void InputDefault::_get_mapped_hat_events(const JoyDeviceMapping &mapping, int p
}

// string names of the SDL buttons in the same order as input_event.h godot buttons
static const char *_joy_buttons[] = { "a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", nullptr };
static const char *_joy_buttons[] = { "a", "b", "x", "y", "leftshoulder", "rightshoulder", "lefttrigger", "righttrigger", "leftstick", "rightstick", "back", "start", "dpup", "dpdown", "dpleft", "dpright", "guide", "misc1", "paddle1", "paddle2", "paddle3", "paddle4", "touchpad", nullptr };
static const char *_joy_axes[] = { "leftx", "lefty", "rightx", "righty", nullptr };

JoystickList InputDefault::_get_output_button(String output) {
Expand Down Expand Up @@ -1284,6 +1284,12 @@ static const char *_buttons[JOY_BUTTON_MAX] = {
"DPAD Down",
"DPAD Left",
"DPAD Right"
"Misc 1",
"Paddle 1",
"Paddle 2",
"Paddle 3",
"Paddle 4",
"Touchpad",
};

static const char *_axes[JOY_AXIS_MAX] = {
Expand Down
4 changes: 2 additions & 2 deletions main/input_default.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class InputDefault : public Input {
StringName name;
StringName uid;
bool connected;
bool last_buttons[JOY_BUTTON_MAX + 19]; //apparently SDL specifies 35 possible buttons on android
bool last_buttons[JOY_BUTTON_MAX + 13]; //apparently SDL specifies 35 possible buttons on android
float last_axis[JOY_AXIS_MAX];
int last_hat;
int mapping;
Expand All @@ -94,7 +94,7 @@ class InputDefault : public Input {

last_axis[i] = 0.0f;
}
for (int i = 0; i < JOY_BUTTON_MAX + 19; i++) {
for (int i = 0; i < JOY_BUTTON_MAX + 13; i++) {

last_buttons[i] = false;
}
Expand Down

0 comments on commit e6101df

Please sign in to comment.