Files
Dawn-Godot/ui/settings/SettingsMenu.gd
T

59 lines
2.2 KiB
GDScript

class_name SettingsMenu extends Control
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
@export var sliderMouseSpeed:HSlider
@export var optionTextSpeed:OptionButton
func _ready() -> void:
tabs.tab_changed.connect(onTabChanged)
checkInvertX.button_pressed = SETTINGS.invertCameraX
checkInvertY.button_pressed = SETTINGS.invertCameraY
checkInvertX.toggled.connect(func(v:bool): SETTINGS.invertCameraX = v)
checkInvertY.toggled.connect(func(v:bool): SETTINGS.invertCameraY = v)
sliderControllerSpeed.value = SETTINGS.cameraSpeedController
sliderMouseSpeed.value = SETTINGS.cameraSpeedMouse
sliderControllerSpeed.value_changed.connect(func(v:float): SETTINGS.cameraSpeedController = v)
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:
for child in container.get_children():
if child is Control and child.focus_mode != Control.FOCUS_NONE:
child.grab_focus()
return