extends Control # emmitted when "back" is pressed signal exit export (StyleBox) var tab_selected_style onready var tabs = $Tabs onready var confirm_dialog = $ConfirmDialog # option controls # # game onready var rumble = $"%Rumble" # video onready var fullscreen = $"%Fullscreen" onready var window_size = $"%WindowSize" onready var scaling_mode = $"%ScalingMode" onready var transition_speed = $"%TransitionSpeed" # audio onready var master_volume = $"%MasterSlider" onready var music_volume = $"%MusicSlider" onready var sound_volume = $"%SoundSlider" # flagged when options have been changed var dirty = false func focus(): load_options(Options) dirty = false visible = true confirm_dialog.visible = false grab_focus() func load_options(options): # game rumble.select(options.rumble) # video fullscreen.select(1 if options.fullscreen else 0) # index 1 is the "on" button # window_size.select(options.window_size) scaling_mode.select(options.scaling_mode) transition_speed.select(options.transition_speed) # audio master_volume.value = options.master_volume music_volume.value = options.music_volume sound_volume.value = options.sound_volume func apply_options(): # game Options.rumble = rumble.get_selection() # video Options.fullscreen = fullscreen.get_selection() == 1 # true if 1, otherwise false # Options.window_size = window_size.get_selection() Options.scaling_mode = scaling_mode.get_selection() Options.transition_speed = transition_speed.get_selection() # audio Options.master_volume = master_volume.value Options.music_volume = music_volume.value Options.sound_volume = sound_volume.value Options.save_options() func _gui_input(event): if event.is_action_pressed("ui_left"): tabs.current_tab = posmod(tabs.current_tab - 1, tabs.get_child_count()) elif event.is_action_pressed("ui_right"): tabs.current_tab = posmod(tabs.current_tab + 1, tabs.get_child_count()) elif event.is_action_pressed("ui_down"): var current_tab = tabs.get_current_tab_control() current_tab.get_node(current_tab.focus_neighbour_bottom).grab_focus() accept_event() func _unhandled_input(event): if !visible: return if event.is_action_pressed("ui_accept"): apply_options() dirty = false elif event.is_action_pressed("ui_cancel"): if dirty: confirm_dialog.visible = true confirm_dialog.grab_focus() else: emit_signal("exit") elif event.is_action_pressed("ui_reset"): load_options(Options.defaults) dirty = true # "_unused" is a dirty hack, # but it means we can connect signals that provide parameters func _mark_dirty(_unused = null, _unused2 = null): dirty = true func _on_ConfirmDialog_gui_input(event): if event.is_action_pressed("ui_accept"): apply_options() confirm_dialog.visible = false emit_signal("exit") elif event.is_action_pressed("ui_cancel"): confirm_dialog.visible = false emit_signal("exit") func _on_tabs_focus_entered(): tabs.set("custom_styles/tab_fg", tab_selected_style) func _on_tabs_focus_exited(): tabs.set("custom_styles/tab_fg", null)