-
-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Input.get_joy_type()
to get controller type
#8519
Comments
These controllers have easily recognizable names when used with Which means that you can use this code: |
I don't think it's that easy. Here is another plugin that tries to recognize controller type by name: https://github.com/rsubtil/controller_icons/blob/38d66dd664840c7b7148533dcc67e336da886073/addons/controller_icons/Mapper.gd#L35 Godot recognizes 4051 controllers. You guys disagree with each other for at least 45 of them if unknown result returned from the latter is treated as XBox. Otherwise, you only reach an agreement for 11% of these controllers. And both of these two plugins recognize my "8BitDo SN30 Pro", which is in the list of controllers recognized by Godot, as an XBox controller, but it's in fact a Nintendo controller. No matter whether name parsing is the only way to implement this:
Footnotes
|
Indeed, many 3rd-party controller brands like SCUF feature layouts that are 100% compatible with a standard controller type (Xbox in SCUF's case). However, I don't think Also, it begs the question of how accurate the controller type should be. Should it report the precise generation (e.g. distinguish PS4 and PS51, Xbox 360 and Xbox One/Series2)? These should preferably have different button prompt icons to best match the actual controller. Footnotes |
I came to the same conclusion (@timothyqiu) that it's not as trivial. A while ago I opened a discussion on a related topic. A few remarks: 1.) Interplay between InputMap, Input and ActionAnother argument why this should be core is that InputMap, Input (Device) and Action need to work together here:
2.) joy_type also for joypads, not just input:get_joy_type() should exist as well for joypads 3.) Additonals details, not just typeThe returned value could also be a class that contains more details. Something like:
→ If you only want to differentiate between Playstation, Xbox and Nintendo the family is enough. If you want to be more precise, you can use the other values. (Related to what @Calinou wrote) 4.) All lowercase vs. common writingI am not sure yet but it might be good to store values how they are normally/officially written: 5.) Get the button nameSome functionality should exist to get the button's name. It could be based on Input but more likely it would be should be based on InputMap by joy_type/platform. Note: Actions can be bound to multiple buttons so this would likely be an array, so take it as a simplification
→ This would allow to display correct input prompts even without images I currently have it the other way round where I have images called 6.) SticksIt gets even more complicated when it comes to sticks because 1 stick is normally split into Final thoughts
|
Turns out it's currently possible to extract the vendor id ( var dict : Dictionary = Input.get_joy_info(0)
print("nVID: 0x%04x" % dict["vendor_id"])
print("nPID: 0x%04x" % dict["product_id"]) In Windows this is not currently exposed, but I believe those values are already extracted in joypad_windows.cpp. Seems like it's a matter of passing those values through the joy_connection_changed call through a dictionary for consistency. |
Describe the project you are working on
Platformer.
Describe the problem or limitation you are having in your project
When interaction is available, an interaction key icon is shown above the player.
I want it to display A when Switch controller is used, display B when XBox controller is used, and display Circle when PlayStation controller is used. Otherwise defaults to a generic icon (highlighted east key among the four keys).
The only way to distinguish between these controller types seems to be
Input.get_joy_name()
.Describe the feature / enhancement and how it helps to overcome the problem or limitation
Add
Input.get_joy_type()
that returns either:JOY_TYPE_UNKNOWN
,JOY_TYPE_XBOX
,JOY_TYPE_PLAYSTATION
, andJOY_TYPE_NINTENDO
.{family}-{model}
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Use something like this mapping: https://github.com/libsdl-org/SDL/blob/main/src/joystick/controller_list.h
But I'm not sure what the
CONTROLLER_ID
is in Godot.If this enhancement will not be used often, can it be worked around with a few lines of script?
Partially. Using good old way of parsing
Input.get_joy_name()
can detect some controllers.Controller icon libraries using this method already exist in AssetLib. But how they parse the name differ and are quite basic (e.g. not able to detect common non-official controllers).
Is there a reason why this should be core and not an add-on in the asset library?
Parsing names are not reliable. Probably needs information that is not exposed.
The text was updated successfully, but these errors were encountered: