khanat-client/scenes/interfaces/music_manager/music_manager.gd

42 lines
1.1 KiB
GDScript3
Raw Normal View History

2020-03-21 09:10:26 +00:00
extends WindowDialog
func _ready():
var directory = Directory.new()
if not directory.dir_exists( "user://musics/" ):
directory.make_dir_recursive( "user://musics/" )
directory.open( "user://musics/" )
directory.list_dir_begin()
var files = []
while true:
var file = directory.get_next()
if file == "":
break
elif not file.begins_with(".") and not directory.current_is_dir() and not file.ends_with( ".import" ):
files.append(file)
directory.list_dir_end()
for file in files:
var button = preload( "res://scenes/interfaces/music_manager/music_button.tscn" ).instance()
button.music_filename = file
button.text = file
button.connect( "music_selected", self, "_on_music_pressed" )
$window_box/scroll_box/musics_box.add_child( button )
func open():
self.popup()
func close():
self.hide()
func toggle():
if self.visible:
self.close()
else:
self.open()
func _on_music_pressed( p_filename ):
$music.stream = load( "res://assets/musics/" + p_filename )
$music.play()