2018-08-25 08:05:54 +00:00
|
|
|
extends VBoxContainer
|
|
|
|
|
|
|
|
var songs_list = []
|
|
|
|
var current_song = ""
|
|
|
|
var current_position = 0.0
|
|
|
|
var popup
|
|
|
|
|
2018-10-17 12:52:07 +00:00
|
|
|
var musics_path = 'res://assets/musics/'
|
|
|
|
|
|
|
|
func list_music_files_in_directory(path):
|
|
|
|
var files = []
|
|
|
|
var dir = Directory.new()
|
|
|
|
dir.open(path)
|
|
|
|
dir.list_dir_begin()
|
2018-08-25 08:05:54 +00:00
|
|
|
|
2018-10-17 12:52:07 +00:00
|
|
|
while true:
|
|
|
|
var file = dir.get_next()
|
|
|
|
if file == "":
|
|
|
|
break
|
|
|
|
elif not file.begins_with(".") and file.ends_with( '.ogg' ):
|
|
|
|
files.append(file.left(file.length()-4))
|
|
|
|
|
|
|
|
dir.list_dir_end()
|
|
|
|
|
|
|
|
return files
|
|
|
|
|
|
|
|
func _ready():
|
|
|
|
var music_files = list_music_files_in_directory( musics_path )
|
|
|
|
|
2018-08-25 08:05:54 +00:00
|
|
|
popup = $SongsSelector.get_popup()
|
2018-10-17 12:52:07 +00:00
|
|
|
for song in music_files:
|
|
|
|
|
|
|
|
var stream = AudioStreamPlayer.new()
|
|
|
|
stream.name = song
|
|
|
|
stream.stream = load( musics_path+song+".ogg" )
|
|
|
|
stream.connect( "finished", self, "_on_song_finished" )
|
|
|
|
$Songs.add_child( stream )
|
|
|
|
|
2018-08-25 08:05:54 +00:00
|
|
|
popup.add_item( song )
|
2018-10-17 12:52:07 +00:00
|
|
|
|
2018-08-25 08:05:54 +00:00
|
|
|
$SongsSelector.text = current_song
|
|
|
|
|
|
|
|
func set_play():
|
2018-10-17 12:52:07 +00:00
|
|
|
if not current_song == "" and get_node( "Songs" ).get_node( current_song ):
|
2018-08-25 08:05:54 +00:00
|
|
|
get_node( "Songs" ).get_node( current_song ).play( current_position )
|
|
|
|
$Buttons/Pause.text = "Pause"
|
|
|
|
$Title.text = "Musiques (Played):"
|
|
|
|
|
|
|
|
func set_pause():
|
2018-10-17 12:52:07 +00:00
|
|
|
if not current_song == "" and get_node( "Songs" ).get_node( current_song ):
|
2018-08-25 08:05:54 +00:00
|
|
|
current_position = get_node( "Songs" ).get_node( current_song ).get_playback_position()
|
|
|
|
get_node( "Songs" ).get_node( current_song ).stop()
|
|
|
|
else:
|
|
|
|
current_position = 0.0
|
|
|
|
|
|
|
|
$Buttons/Pause.text = "Play"
|
|
|
|
$Title.text = "Musiques (Paused):"
|
|
|
|
|
|
|
|
func set_stop():
|
2018-10-17 12:52:07 +00:00
|
|
|
if not current_song == "" and get_node( "Songs" ).get_node( current_song ):
|
2018-08-25 08:05:54 +00:00
|
|
|
get_node( "Songs" ).get_node( current_song ).stop()
|
|
|
|
current_position = 0.0
|
|
|
|
$Buttons/Pause.pressed = false
|
|
|
|
$Buttons/Pause.text = "Play"
|
|
|
|
$Title.text = "Musiques (Stopped):"
|
|
|
|
|
|
|
|
func _on_Pause_toggled(button_pressed):
|
|
|
|
if button_pressed:
|
|
|
|
set_play()
|
|
|
|
else:
|
|
|
|
set_pause()
|
|
|
|
|
|
|
|
func _on_Stop_pressed():
|
|
|
|
set_stop()
|
|
|
|
|
|
|
|
func _on_SongsSelector_item_selected(ID):
|
|
|
|
var new_song = popup.get_item_text(ID)
|
|
|
|
if not current_song == new_song:
|
|
|
|
set_stop()
|
|
|
|
current_song = popup.get_item_text(ID)
|
|
|
|
|
|
|
|
func _on_song_finished():
|
|
|
|
print("test")
|
|
|
|
set_stop()
|