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

42 lines
1,012 B
GDScript3
Raw Permalink Normal View History

2020-03-21 09:10:26 +00:00
extends WindowDialog
func _ready():
2021-01-21 21:03:44 +00:00
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 )
2020-03-21 09:10:26 +00:00
func open():
2021-01-21 21:03:44 +00:00
self.popup()
2020-03-21 09:10:26 +00:00
func close():
2021-01-21 21:03:44 +00:00
self.hide()
2020-03-21 09:10:26 +00:00
func toggle():
2021-01-21 21:03:44 +00:00
if self.visible:
self.close()
else:
self.open()
2020-03-21 09:10:26 +00:00
func _on_music_pressed( p_filename ):
2021-01-21 21:03:44 +00:00
$music.stream = load( "res://assets/musics/" + p_filename )
$music.play()