Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions core/input/input.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ void Input::_bind_methods() {
ClassDB::bind_method(D_METHOD("parse_input_event", "event"), &Input::parse_input_event);
ClassDB::bind_method(D_METHOD("set_use_accumulated_input", "enable"), &Input::set_use_accumulated_input);
ClassDB::bind_method(D_METHOD("is_using_accumulated_input"), &Input::is_using_accumulated_input);
ClassDB::bind_method(D_METHOD("set_joypad_enabled", "enable"), &Input::set_joypad_enabled);
ClassDB::bind_method(D_METHOD("is_joypad_enabled"), &Input::is_joypad_enabled);
ClassDB::bind_method(D_METHOD("flush_buffered_events"), &Input::flush_buffered_events);
ClassDB::bind_method(D_METHOD("set_emulate_mouse_from_touch", "enable"), &Input::set_emulate_mouse_from_touch);
ClassDB::bind_method(D_METHOD("is_emulating_mouse_from_touch"), &Input::is_emulating_mouse_from_touch);
Expand All @@ -173,6 +175,7 @@ void Input::_bind_methods() {

ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_mode"), "set_mouse_mode", "get_mouse_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_accumulated_input"), "set_use_accumulated_input", "is_using_accumulated_input");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "joypad_enabled"), "set_joypad_enabled", "is_joypad_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emulate_mouse_from_touch"), "set_emulate_mouse_from_touch", "is_emulating_mouse_from_touch");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "emulate_touch_from_mouse"), "set_emulate_touch_from_mouse", "is_emulating_touch_from_mouse");

Expand Down Expand Up @@ -362,7 +365,7 @@ static JoyButton _combine_device(JoyButton p_value, int p_device) {
bool Input::is_joy_button_pressed(int p_device, JoyButton p_button) const {
_THREAD_SAFE_METHOD_

if (disable_input) {
if (disable_input || !joypad_enabled) {
return false;
}

Expand Down Expand Up @@ -507,7 +510,7 @@ Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_po
float Input::get_joy_axis(int p_device, JoyAxis p_axis) const {
_THREAD_SAFE_METHOD_

if (disable_input) {
if (disable_input || !joypad_enabled) {
return 0;
}

Expand Down Expand Up @@ -914,6 +917,9 @@ void Input::set_joy_axis(int p_device, JoyAxis p_axis, float p_value) {

void Input::start_joy_vibration(int p_device, float p_weak_magnitude, float p_strong_magnitude, float p_duration) {
_THREAD_SAFE_METHOD_
if (!joypad_enabled) {
return;
}
if (p_weak_magnitude < 0.f || p_weak_magnitude > 1.f || p_strong_magnitude < 0.f || p_strong_magnitude > 1.f) {
return;
}
Expand All @@ -927,6 +933,9 @@ void Input::start_joy_vibration(int p_device, float p_weak_magnitude, float p_st

void Input::stop_joy_vibration(int p_device) {
_THREAD_SAFE_METHOD_
if (!joypad_enabled) {
return;
}
VibrationInfo vibration;
vibration.weak_magnitude = 0;
vibration.strong_magnitude = 0;
Expand Down Expand Up @@ -1202,6 +1211,14 @@ bool Input::is_using_accumulated_input() {
return use_accumulated_input;
}

void Input::set_joypad_enabled(bool p_enable) {
joypad_enabled = p_enable;
}

bool Input::is_joypad_enabled() {
return joypad_enabled;
}

void Input::release_pressed_events() {
flush_buffered_events(); // this is needed to release actions strengths

Expand All @@ -1224,6 +1241,9 @@ void Input::set_event_dispatch_function(EventDispatchFunc p_function) {

void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) {
_THREAD_SAFE_METHOD_;
if (!joypad_enabled) {
return;
}
Joypad &joy = joy_names[p_device];
ERR_FAIL_INDEX((int)p_button, (int)JoyButton::MAX);

Expand Down Expand Up @@ -1251,7 +1271,9 @@ void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) {

void Input::joy_axis(int p_device, JoyAxis p_axis, float p_value) {
_THREAD_SAFE_METHOD_;

if (!joypad_enabled) {
return;
}
ERR_FAIL_INDEX((int)p_axis, (int)JoyAxis::MAX);

Joypad &joy = joy_names[p_device];
Expand Down Expand Up @@ -1891,6 +1913,7 @@ Input::Input() {
gravity_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_gravity", false);
gyroscope_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_gyroscope", false);
magnetometer_enabled = GLOBAL_DEF_RST_BASIC("input_devices/sensors/enable_magnetometer", false);
joypad_enabled = GLOBAL_DEF_BASIC("input_devices/joypad/joypad_enabled", true);
}

Input::~Input() {
Expand Down
3 changes: 3 additions & 0 deletions core/input/input.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ class Input : public Object {
bool emulate_mouse_from_touch = false;
bool agile_input_event_flushing = false;
bool use_accumulated_input = true;
bool joypad_enabled = true;

int mouse_from_touch_index = -1;

Expand Down Expand Up @@ -388,6 +389,8 @@ class Input : public Object {
void set_agile_input_event_flushing(bool p_enable);
void set_use_accumulated_input(bool p_enable);
bool is_using_accumulated_input();
void set_joypad_enabled(bool p_enable);
bool is_joypad_enabled();

void release_pressed_events();

Expand Down
5 changes: 5 additions & 0 deletions doc/classes/Input.xml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,11 @@
<member name="emulate_touch_from_mouse" type="bool" setter="set_emulate_touch_from_mouse" getter="is_emulating_touch_from_mouse">
If [code]true[/code], sends touch input events when clicking or dragging the mouse. See also [member ProjectSettings.input_devices/pointing/emulate_touch_from_mouse].
</member>
<member name="joypad_enabled" type="bool" setter="set_joypad_enabled" getter="is_joypad_enabled">
If [code]true[/code], enables joypad input events and allows the use of joypad-related functions such as [method Input.is_joy_button_pressed], [method Input.get_joy_axis], [method Input.start_joy_vibration], and [method Input.stop_joy_vibration].
See also [member ProjectSettings.input_devices/joypad/joypad_enabled].
[b]Note:[/b] Disabling this option does not stop Godot from capturing/connecting to the joypad itself.
</member>
<member name="mouse_mode" type="int" setter="set_mouse_mode" getter="get_mouse_mode" enum="Input.MouseMode">
Controls the mouse mode. See [enum MouseMode] for more information.
</member>
Expand Down
6 changes: 6 additions & 0 deletions doc/classes/ProjectSettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1548,6 +1548,12 @@
If [code]false[/code], no input will be lost.
[b]Note:[/b] You should in nearly all cases prefer the [code]false[/code] setting. The legacy behavior is to enable supporting old projects that rely on the old logic, without changes to script.
</member>
<member name="input_devices/joypad/joypad_enabled" type="bool" setter="" getter="" default="true">
If [code]true[/code], enables joypad input events and allows the use of joypad-related functions such as [method Input.is_joy_button_pressed], [method Input.get_joy_axis], [method Input.start_joy_vibration], and [method Input.stop_joy_vibration].
This also affects [method Input.is_action_just_pressed], [method Input.is_action_just_released], and [method Input.is_action_pressed].
To control this at runtime, use [member Input.joypad_enabled].
[b]Note:[/b] Disabling this option does not stop Godot from capturing/connecting to the joypad itself.
</member>
<member name="input_devices/pen_tablet/driver" type="String" setter="" getter="">
Specifies the tablet driver to use. If left empty, the default driver will be used.
[b]Note:[/b] The driver in use can be overridden at runtime via the [code]--tablet-driver[/code] [url=$DOCS_URL/tutorials/editor/command_line_tutorial.html]command line argument[/url].
Expand Down
2 changes: 2 additions & 0 deletions main/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,8 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph
}
} else if (arg == "--single-threaded-scene") {
single_threaded_scene = true;
} else if (arg == "--disable-joypad") {
GLOBAL_DEF_BASIC("input_devices/joypad/joypad_enabled", false);
} else if (arg == "--build-solutions") { // Build the scripting solution such C#

auto_build_solutions = true;
Expand Down