PunchablePlushie/godot-game-settings

Navigate Menus using Keyboard

Closed this issue · 2 comments

Is there a way to make the settings menu navigable with just the keyboard? So users can use either the mouse or the keyboard.

I know GGS isn't responsible for the configuration of the Settings-Menu, so maybe setting Focus on those items isn't an issue for this package?

Maybe I could add functionality to the components' scripts to handle is_focus() cases. The ggs_arrow_list would definitely need to handle that implicitly in order to call "press" on its children buttons

Is there a way to make the settings menu navigable with just the keyboard? So users can use either the mouse or the keyboard.

I know GGS isn't responsible for the configuration of the Settings-Menu, so maybe setting Focus on those items isn't an issue for this package?

The menu should be keyboard navigatable already, thanks to Godot itself. You just gotta handle the focus.
If you want your menu to be navigatable by keyboard, first, you gotta make sure that you have keys assigned to ui_left/right/top/bottom actions in the Input Map. After that, you just need a script that handles focusing on a node when the player enters the settings menu.
For example, let's say you want the focus to be on a node called "FullscreenToggleButton" when someone enters the options menu. So:

extends Control

onready var FirstFocus = $FullscreenToggleButton

func _onready():
    FirstFocus.grab_focus()

That allows the users to navigate the menu using the keyboard. Without doing that, they won't be able to do it because no node has focus to begin with. From there on, you can handle focus targets using the "Focus" section in the Inspector (Neighbour Left, Neighbour Right, etc.).

If you want the nodes to be controllable only with the keyboard, you can set their mouse_filter property to Ignore. Check the "Mouse" section in the Inspector.

Maybe I could add functionality to the components' scripts to handle is_focus() cases. The ggs_arrow_list would definitely need to handle that implicitly in order to call "press" on its children buttons

The components do require a simple change to handle the focus properly when the mouse is hovered over them. Right now, when you hover over a component with a mouse, it doesn't technically gain focus.

connect("mouse_entered", self, "_on_mouse_entered")

func _on_mouse_entered():
   grab_focus()

That's basically all there is to it. I'll go ahead and push the fix in a moment.

Hopefully that helped you achieve what you wanted to do.