godotengine / godot-demo-projects

Demonstration and Template Projects
https://godotengine.org
MIT License
5.65k stars 1.58k forks source link

Fix joypad demo for Godot 4.x #943

Closed noidexe closed 4 months ago

noidexe commented 1 year ago

This fixes a number of issues preventing to use the remap feature:

~Input detection only works with native subwindows. I couldn't get it to work when using embedded subwindows. The subwindow seems to stop event propagation even with handle_input_locally disabled. You can workaround it by clicking outside the remap window before pressing a button but it should get a proper fix~ Checking the Godot source code it seems to be by design. Subwindows will always handle input when focused. Managed to fix it by connecting to Window.window_input

Calinou commented 1 year ago

Tested locally. On 4.1.1, when you first start the demo with a controller connected, it's possible to see pressed buttons/axes but the UI appears grayed out (and the controller name doesn't appear):

image

You need to change the SpinBox value back and forth for the UI to look correct:

image

noidexe commented 1 year ago

Tested locally. On 4.1.1, when you first start the demo with a controller connected, it's possible to see pressed buttons/axes but the UI appears grayed out (and the controller name doesn't appear):

I cannot reproduce that, at least on windows and with a couple of xinput and dinput gamepads. I don't have a PS5 one.

Can you add _on_joy_connection_changed(joypad, true) to the for loop in joypads.gd::_ready ? Maybe that'll fix it.

Calinou commented 1 year ago

I've just tested this again (all testing was done on Linux). It looks like it works as-is on 4.2.dev godotengine/godot@6758a7f8c but not on 4.1.1.stable (which also prints lots of threading warnings).

I guess we can assume this to be an engine bug and merge the demo update anyway.