diff options
Diffstat (limited to 'main')
-rw-r--r-- | main/input_default.cpp | 19 | ||||
-rw-r--r-- | main/input_default.h | 8 |
2 files changed, 20 insertions, 7 deletions
diff --git a/main/input_default.cpp b/main/input_default.cpp index f62f794b33..260af7528b 100644 --- a/main/input_default.cpp +++ b/main/input_default.cpp @@ -157,7 +157,7 @@ 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()); - int mapping = -1; + int mapping = fallback_mapping; for (int i=0; i < map_db.size(); i++) { if (js.uid == map_db[i].uid) { mapping = i; @@ -499,6 +499,7 @@ static const char *s_ControllerMappings [] = #endif #if defined(__ANDROID__) + "Default Android Gamepad,Default Controller,leftx:a0,lefty:a1,dpdown:h0.4,rightstick:b8,rightshoulder:b10,rightx:a2,start:b6,righty:a3,dpleft:h0.8,lefttrigger:a4,x:b2,dpup:h0.1,back:b4,leftstick:b7,leftshoulder:b9,y:b3,a:b0,dpright:h0.2,righttrigger:a5,b:b1,", "4e564944494120436f72706f72617469,NVIDIA Controller,a:b0,b:b1,dpdown:h0.4,dpleft:h0.8,dpright:h0.2,dpup:h0.1,leftshoulder:b9,leftstick:b7,lefttrigger:a4,leftx:a0,lefty:a1,rightshoulder:b10,rightstick:b8,righttrigger:a5,rightx:a2,righty:a3,start:b6,x:b2,y:b3,", #endif @@ -536,6 +537,8 @@ InputDefault::InputDefault() { hat_map_default[HAT_LEFT].index = JOY_DPAD_LEFT; hat_map_default[HAT_LEFT].value = 0; + fallback_mapping = -1; + String env_mapping = OS::get_singleton()->get_environment("SDL_GAMECONTROLLERCONFIG"); if (env_mapping != "") { @@ -876,6 +879,16 @@ void InputDefault::remove_joy_mapping(String p_guid) { } } +void InputDefault::set_fallback_mapping(String p_guid) { + + for (int i = 0; i < map_db.size(); i++) { + if (map_db[i].uid == p_guid) { + fallback_mapping = i; + return; + } + } +} + //Defaults to simple implementation for platforms with a fixed gamepad layout, like consoles. bool InputDefault::is_joy_known(int p_device) { @@ -888,10 +901,10 @@ String InputDefault::get_joy_guid(int p_device) const { //platforms that use the remapping system can override and call to these ones bool InputDefault::is_joy_mapped(int p_device) { - return joy_names[p_device].mapping != -1 ? true : false; + int mapping = joy_names[p_device].mapping; + return mapping != -1 ? (mapping == fallback_mapping) : false; } String InputDefault::get_joy_guid_remapped(int p_device) const { return joy_names[p_device].uid; } - diff --git a/main/input_default.h b/main/input_default.h index a75865e0cb..2f98d279d6 100644 --- a/main/input_default.h +++ b/main/input_default.h @@ -18,7 +18,6 @@ class InputDefault : public Input { MainLoop *main_loop; bool emulate_touch; - struct SpeedTrack { uint64_t last_tick; @@ -36,7 +35,7 @@ class InputDefault : public Input { struct Joystick { StringName name; StringName uid; - bool last_buttons[JOY_BUTTON_MAX + 2]; //html5 needs support for 18 buttons to map some devices correctly + bool last_buttons[JOY_BUTTON_MAX + 19]; //apparently SDL specifies 35 possible buttons on android float last_axis[JOY_AXIS_MAX]; float filter; int last_hat; @@ -50,7 +49,7 @@ class InputDefault : public Input { last_axis[i] = 0.0f; } - for (int i = 0; i < JOY_BUTTON_MAX + 2; i++) { + for (int i = 0; i < JOY_BUTTON_MAX + 19; i++) { last_buttons[i] = false; } @@ -62,6 +61,7 @@ class InputDefault : public Input { SpeedTrack mouse_speed_track; Map<int, Joystick> joy_names; + int fallback_mapping; RES custom_cursor; public: enum HatMask { @@ -169,7 +169,7 @@ public: bool is_joy_mapped(int p_device); String get_joy_guid_remapped(int p_device) const; - + void set_fallback_mapping(String p_guid); InputDefault(); }; |