RhythmGame/scenes/SettingsMenu.gd

59 lines
1.5 KiB
GDScript3
Raw Normal View History

extends Control
const DirectorySettingsEntry = preload('res://scenes/DirectorySettingsEntry.tscn')
onready var container_folders = $'%container_folders'
signal exit_mode
var paths = []
var path_entries := []
# Called when the node enters the scene tree for the first time.
func _ready():
paths = Array(Settings.get_library_paths())
generate_entries()
func generate_entries():
paths.append("")
for entry in path_entries:
container_folders.remove_child(entry)
path_entries = []
for path in paths:
var entry = DirectorySettingsEntry.instance()
entry.connect('path_updated', self, '_entry_updated', [len(path_entries)])
path_entries.append(entry)
entry.directory = path
container_folders.add_child(entry)
path_entries[0].removable = false
path_entries[0].readonly = true
func get_paths_from_entries() -> Array:
var paths := []
for entry in path_entries:
var dir = entry.directory
if dir:
paths.append(entry.directory)
return paths
func _save_settings():
var paths = get_paths_from_entries()
var user_path: String = paths[0]
var extra_paths: Array = paths.slice(1, -1)
Settings.set_additional_library_paths(extra_paths)
func _entry_updated(new_path: String, index: int):
paths = get_paths_from_entries()
if (index == len(path_entries)-1):
if new_path:
generate_entries()
elif not new_path:
generate_entries()
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass
func _on_btn_back_pressed():
_save_settings()
emit_signal('exit_mode')