diff options
-rw-r--r-- | core/os/input.cpp | 1 | ||||
-rw-r--r-- | core/os/input.h | 1 | ||||
-rw-r--r-- | doc/base/classes.xml | 7 | ||||
-rw-r--r-- | main/input_default.cpp | 18 | ||||
-rw-r--r-- | main/input_default.h | 3 |
5 files changed, 27 insertions, 3 deletions
diff --git a/core/os/input.cpp b/core/os/input.cpp index dacddc0928..efbae57950 100644 --- a/core/os/input.cpp +++ b/core/os/input.cpp @@ -59,6 +59,7 @@ void Input::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_joy_axis","device","axis"),&Input::get_joy_axis); ObjectTypeDB::bind_method(_MD("get_joy_name","device"),&Input::get_joy_name); ObjectTypeDB::bind_method(_MD("get_joy_guid","device"),&Input::get_joy_guid); + ObjectTypeDB::bind_method(_MD("get_connected_joysticks"),&Input::get_connected_joysticks); ObjectTypeDB::bind_method(_MD("get_joy_vibration_strength", "device"), &Input::get_joy_vibration_strength); ObjectTypeDB::bind_method(_MD("get_joy_vibration_duration", "device"), &Input::get_joy_vibration_duration); ObjectTypeDB::bind_method(_MD("start_joy_vibration", "device", "weak_magnitude", "strong_magnitude", "duration"), &Input::start_joy_vibration, DEFVAL(0)); diff --git a/core/os/input.h b/core/os/input.h index fa2cef5467..d11703470b 100644 --- a/core/os/input.h +++ b/core/os/input.h @@ -62,6 +62,7 @@ public: virtual float get_joy_axis(int p_device,int p_axis)=0; virtual String get_joy_name(int p_idx)=0; + virtual Array get_connected_joysticks()=0; virtual void joy_connection_changed(int p_idx, bool p_connected, String p_name, String p_guid)=0; virtual void add_joy_mapping(String p_mapping, bool p_update_existing=false)=0; virtual void remove_joy_mapping(String p_guid)=0; diff --git a/doc/base/classes.xml b/doc/base/classes.xml index 4b5c424d4b..978df96a81 100644 --- a/doc/base/classes.xml +++ b/doc/base/classes.xml @@ -15965,6 +15965,13 @@ Example: (content-length:12), (Content-Type:application/json; charset=UTF-8) If the device has an accelerometer, this will return the movement. </description> </method> + <method name="get_connected_joysticks"> + <return type="Array"> + </return> + <description> + Returns an [Array] containing the device IDs of all currently connected joysticks. + </description> + </method> <method name="get_joy_axis"> <return type="float"> </return> diff --git a/main/input_default.cpp b/main/input_default.cpp index 4fcb450bce..68356b7811 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -101,7 +101,7 @@ bool InputDefault::is_action_pressed(const StringName& p_action) { const List<InputEvent> *alist = InputMap::get_singleton()->get_action_list(p_action); if (!alist) - return NULL; + return false; for (const List<InputEvent>::Element *E=alist->front();E;E=E->next()) { @@ -220,18 +220,18 @@ void InputDefault::joy_connection_changed(int p_idx, bool p_connected, String p_ }; }; js.uid = uidname; - //printf("looking for mappings for guid %ls\n", uidname.c_str()); + js.connected = true; int mapping = fallback_mapping; for (int i=0; i < map_db.size(); i++) { if (js.uid == map_db[i].uid) { mapping = i; js.name = map_db[i].name; - //printf("found mapping\n"); }; }; js.mapping = mapping; } else { + js.connected = false; for (int i = 0; i < JOY_BUTTON_MAX; i++) { if (i < JOY_AXIS_MAX) @@ -1039,3 +1039,15 @@ bool InputDefault::is_joy_mapped(int p_device) { String InputDefault::get_joy_guid_remapped(int p_device) const { return joy_names[p_device].uid; } + +Array InputDefault::get_connected_joysticks() { + Array ret; + Map<int, Joystick>::Element *elem = joy_names.front(); + while (elem) { + if (elem->get().connected) { + ret.push_back(elem->key()); + } + elem = elem->next(); + } + return ret; +} diff --git a/main/input_default.h b/main/input_default.h index c7fef8374c..644af15e3b 100644 --- a/main/input_default.h +++ b/main/input_default.h @@ -75,6 +75,7 @@ class InputDefault : public Input { struct Joystick { StringName name; StringName uid; + bool connected; bool last_buttons[JOY_BUTTON_MAX + 19]; //apparently SDL specifies 35 possible buttons on android float last_axis[JOY_AXIS_MAX]; float filter; @@ -93,6 +94,7 @@ class InputDefault : public Input { last_buttons[i] = false; } + connected = false; last_hat = HAT_MASK_CENTER; filter = 0.01f; mapping = -1; @@ -168,6 +170,7 @@ public: virtual float get_joy_axis(int p_device,int p_axis); String get_joy_name(int p_idx); + virtual Array get_connected_joysticks(); virtual Vector2 get_joy_vibration_strength(int p_device); virtual float get_joy_vibration_duration(int p_device); virtual uint64_t get_joy_vibration_timestamp(int p_device); |