test-client-godot/gui_scene/GUI/MusicControls/Music.gd

62 lines
No EOL
1.7 KiB
GDScript

extends VBoxContainer
var songs_list = []
var current_song = ""
var current_position = 0.0
var popup
func _ready():
for song in $Songs.get_children():
songs_list.append( song.name )
if $Songs.get_child_count() > 0:
current_song = songs_list[0]
popup = $SongsSelector.get_popup()
for song in songs_list:
popup.add_item( song )
get_node( "Songs" ).get_node( song ).connect( "finished", self, "_on_song_finished" )
$SongsSelector.text = current_song
func set_play():
if get_node( "Songs" ).get_node( current_song ):
get_node( "Songs" ).get_node( current_song ).play( current_position )
$Buttons/Pause.text = "Pause"
$Title.text = "Musiques (Played):"
func set_pause():
if get_node( "Songs" ).get_node( current_song ):
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():
if get_node( "Songs" ).get_node( current_song ):
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()