-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #157 from ac-arcana/main
Base Tab Menu
- Loading branch information
Showing
3 changed files
with
124 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
class_name CogitoTabMenu | ||
extends TabContainer | ||
## This class can be extended to create a tab menu with controller support. | ||
|
||
## Helper for controller input. Sets the node to focus on for each tab. | ||
## The array index corresponds to the tabs. | ||
@export var nodes_to_focus: Array[Control] | ||
|
||
func _input(event): | ||
if !visible: | ||
return | ||
|
||
#Tab navigation | ||
if (event.is_action_pressed("ui_next_tab")): | ||
if current_tab + 1 == get_tab_count(): | ||
current_tab = 0 | ||
else: | ||
current_tab += 1 | ||
|
||
if nodes_to_focus[current_tab]: | ||
#print("Grabbing focus of : ", tab_container.current_tab, " - ", nodes_to_focus[tab_container.current_tab]) | ||
nodes_to_focus[current_tab].grab_focus.call_deferred() | ||
|
||
if (event.is_action_pressed("ui_prev_tab")): | ||
if current_tab == 0: | ||
current_tab = get_tab_count()-1 | ||
else: | ||
current_tab -= 1 | ||
|
||
if nodes_to_focus[current_tab]: | ||
#print("Grabbing focus of : ", tab_container.current_tab, " - ", nodes_to_focus[tab_container.current_tab]) | ||
nodes_to_focus[current_tab].grab_focus.call_deferred() |
Oops, something went wrong.