Tabs
This commit is contained in:
@@ -67,6 +67,11 @@ func _onFocusLost() -> void:
|
||||
func _onViewportFocusChanged(control:Control) -> void:
|
||||
if control == null or is_ancestor_of(control):
|
||||
return
|
||||
var node:Node = control
|
||||
while node != null:
|
||||
if node is Popup:
|
||||
return
|
||||
node = node.get_parent()
|
||||
if _savedFocusNode != null and is_instance_valid(_savedFocusNode):
|
||||
_savedFocusNode.grab_focus()
|
||||
else:
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
class_name TabMenu extends Control
|
||||
|
||||
@export var tabs:TabBar
|
||||
@export var tabControls:Array[Control]
|
||||
|
||||
func _ready() -> void:
|
||||
tabs.tab_changed.connect(_onTabChanged)
|
||||
_onTabChanged(tabs.current_tab)
|
||||
|
||||
func _notification(what:int) -> void:
|
||||
if what == NOTIFICATION_VISIBILITY_CHANGED and visible:
|
||||
tabs.grab_focus()
|
||||
|
||||
func _input(event:InputEvent) -> void:
|
||||
if !is_visible_in_tree():
|
||||
return
|
||||
if event.is_action_pressed("tab_next"):
|
||||
tabs.current_tab = (tabs.current_tab + 1) % tabs.tab_count
|
||||
get_viewport().set_input_as_handled()
|
||||
elif event.is_action_pressed("tab_prev"):
|
||||
tabs.current_tab = (tabs.current_tab - 1 + tabs.tab_count) % tabs.tab_count
|
||||
get_viewport().set_input_as_handled()
|
||||
elif tabs.has_focus() and event.is_action_pressed("ui_accept"):
|
||||
var idx:int = tabs.current_tab
|
||||
if idx >= 0 and idx < tabControls.size() and _focusFirstIn(tabControls[idx]):
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
func _onTabChanged(tabIndex:int) -> void:
|
||||
for control in tabControls:
|
||||
control.visible = false
|
||||
if tabIndex >= 0 and tabIndex < tabControls.size():
|
||||
tabControls[tabIndex].visible = true
|
||||
|
||||
func _focusFirstIn(container:Control) -> bool:
|
||||
for child in container.get_children():
|
||||
if not child is Control:
|
||||
continue
|
||||
if child.focus_mode != Control.FOCUS_NONE and child.is_visible_in_tree():
|
||||
child.grab_focus()
|
||||
return true
|
||||
if _focusFirstIn(child):
|
||||
return true
|
||||
return false
|
||||
@@ -0,0 +1 @@
|
||||
uid://dacm5qwmmkcsm
|
||||
@@ -14,8 +14,6 @@ func _ready() -> void:
|
||||
btnSettings.pressed.connect(settingsRequested.emit)
|
||||
btnMainMenu.pressed.connect(_showMainMenuConfirm)
|
||||
btnQuit.pressed.connect(_showQuitConfirm)
|
||||
UI.QUIT_DIALOG.closed.connect(_onQuitDialogClosed)
|
||||
UI.MAIN_MENU_DIALOG.closed.connect(_onMainMenuDialogClosed)
|
||||
|
||||
func _showQuitConfirm() -> void:
|
||||
UI.QUIT_DIALOG.open()
|
||||
@@ -23,14 +21,6 @@ func _showQuitConfirm() -> void:
|
||||
func _showMainMenuConfirm() -> void:
|
||||
UI.MAIN_MENU_DIALOG.open()
|
||||
|
||||
func _onQuitDialogClosed() -> void:
|
||||
if isOpen():
|
||||
btnQuit.grab_focus()
|
||||
|
||||
func _onMainMenuDialogClosed() -> void:
|
||||
if isOpen():
|
||||
btnMainMenu.grab_focus()
|
||||
|
||||
func open() -> void:
|
||||
visible = true
|
||||
btnResume.grab_focus()
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
class_name SettingsMenu extends Control
|
||||
class_name SettingsMenu extends TabMenu
|
||||
|
||||
const TEXT_SPEED_VALUES:Array[float] = [0.2, 1.0, 2.0]
|
||||
|
||||
@export var tabs:TabBar
|
||||
@export var tabControls:Array[Control]
|
||||
@export var checkInvertX:CheckBox
|
||||
@export var checkInvertY:CheckBox
|
||||
@export var sliderControllerSpeed:HSlider
|
||||
@@ -11,7 +9,7 @@ const TEXT_SPEED_VALUES:Array[float] = [0.2, 1.0, 2.0]
|
||||
@export var optionTextSpeed:OptionButton
|
||||
|
||||
func _ready() -> void:
|
||||
tabs.tab_changed.connect(onTabChanged)
|
||||
super._ready()
|
||||
checkInvertX.button_pressed = SETTINGS.invertCameraX
|
||||
checkInvertY.button_pressed = SETTINGS.invertCameraY
|
||||
checkInvertX.toggled.connect(func(v:bool): SETTINGS.invertCameraX = v)
|
||||
@@ -22,39 +20,9 @@ func _ready() -> void:
|
||||
sliderMouseSpeed.value_changed.connect(func(v:float): SETTINGS.cameraSpeedMouse = v)
|
||||
optionTextSpeed.select(_textSpeedToIndex(SETTINGS.textSpeed))
|
||||
optionTextSpeed.item_selected.connect(func(idx:int): SETTINGS.textSpeed = TEXT_SPEED_VALUES[idx])
|
||||
onTabChanged(tabs.current_tab)
|
||||
|
||||
func _textSpeedToIndex(speed:float) -> int:
|
||||
match speed:
|
||||
0.2: return 0
|
||||
2.0: return 2
|
||||
_: return 1
|
||||
|
||||
func _notification(what:int) -> void:
|
||||
if what == NOTIFICATION_VISIBILITY_CHANGED and visible:
|
||||
tabs.grab_focus()
|
||||
|
||||
func _input(event:InputEvent) -> void:
|
||||
if !is_visible_in_tree():
|
||||
return
|
||||
if event.is_action_pressed("tab_next"):
|
||||
tabs.current_tab = (tabs.current_tab + 1) % tabs.tab_count
|
||||
get_viewport().set_input_as_handled()
|
||||
elif event.is_action_pressed("tab_prev"):
|
||||
tabs.current_tab = (tabs.current_tab - 1 + tabs.tab_count) % tabs.tab_count
|
||||
get_viewport().set_input_as_handled()
|
||||
|
||||
func onTabChanged(tabIndex:int) -> void:
|
||||
for control in tabControls:
|
||||
control.visible = false
|
||||
if tabIndex >= 0 and tabIndex < tabControls.size():
|
||||
tabControls[tabIndex].visible = true
|
||||
_focusFirstIn(tabControls[tabIndex])
|
||||
|
||||
func _focusFirstIn(container:Control) -> void:
|
||||
if !is_visible_in_tree():
|
||||
return
|
||||
for child in container.get_children():
|
||||
if child is Control and child.focus_mode != Control.FOCUS_NONE:
|
||||
child.grab_focus()
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user