You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-08 12:40:44 +00:00
Merge pull request #3428 from Hinsbart/android-gamepad
support gamepad remapping on android
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user