2020-03-21 09:10:26 +00:00
|
|
|
extends WindowDialog
|
|
|
|
|
2021-05-27 21:56:16 +00:00
|
|
|
onready var audio_player = $music
|
|
|
|
|
|
|
|
func load_external_music(filepath):
|
|
|
|
var stream = null
|
|
|
|
Config.msg_debug("")
|
|
|
|
var file = File.new()
|
|
|
|
file.open(filepath, file.READ)
|
|
|
|
var ext = filepath.split(".")[-1].to_lower()
|
|
|
|
var buffer = file.get_buffer(file.get_len())
|
|
|
|
Config.msg_debug(ext)
|
|
|
|
match ext:
|
|
|
|
"ogg":
|
|
|
|
stream = AudioStreamOGGVorbis.new()
|
|
|
|
"mp3":
|
|
|
|
stream = AudioStreamMP3.new()
|
|
|
|
#"wav":
|
|
|
|
# # We need decode message to get format
|
|
|
|
# stream = AudioStreamSample.new()
|
|
|
|
# stream.format = AudioStreamSample.FORMAT_16_BITS
|
|
|
|
# #stream.stereo = true
|
|
|
|
_:
|
|
|
|
Config.msg_error("Impossible to identify type of file (file:" + filepath + ", ext:" + ext + ")")
|
|
|
|
return
|
|
|
|
stream.data = buffer
|
|
|
|
audio_player.stream = stream
|
|
|
|
Config.msg_debug("")
|
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
func _ready():
|
2021-05-27 21:56:16 +00:00
|
|
|
var directory = Directory.new()
|
|
|
|
get_tree().paused = false
|
|
|
|
Config.msg_debug("")
|
|
|
|
|
|
|
|
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 = "res://assets/musics/" + file
|
|
|
|
button.text = file
|
|
|
|
button.connect( "music_selected", self, "_on_music_pressed" )
|
|
|
|
$window_box/scroll_box/musics_box.add_child( button )
|
|
|
|
|
|
|
|
audio_player.stream = load( "res://assets/musics/sangakanat_ames_voyageuses.ogg" )
|
|
|
|
#add_music(audio_player)
|
|
|
|
#audio_player.set_volume_db(linear2db(0.5))
|
|
|
|
#audio_player.set_volume_db(1.0)
|
|
|
|
audio_player.play()
|
|
|
|
#audio_player.set_volume_db(1.0)
|
|
|
|
#audioPlayer.play()
|
|
|
|
update_volume_db()
|
|
|
|
Config.msg_debug("Load End")
|
|
|
|
|
|
|
|
func update_volume_db():
|
|
|
|
if Config.mute:
|
|
|
|
audio_player.set_volume_db(linear2db(0.0))
|
|
|
|
audio_player.set_pause_mode(true)
|
|
|
|
return
|
|
|
|
var lvl = Config.sound_lvl_global * Config.sound_lvl_music / 10000.0
|
|
|
|
audio_player.set_volume_db(linear2db(lvl))
|
|
|
|
audio_player.set_pause_mode(false)
|
|
|
|
|
|
|
|
func set_sound_mute(value: bool):
|
|
|
|
Config.set_sound_mute(value)
|
|
|
|
update_volume_db()
|
|
|
|
|
|
|
|
func set_level_global(value: int):
|
|
|
|
Config.sound_lvl_global = value
|
|
|
|
update_volume_db()
|
|
|
|
|
|
|
|
func set_level_music(value: int):
|
|
|
|
Config.sound_lvl_music = value
|
|
|
|
update_volume_db()
|
|
|
|
|
|
|
|
func set_level_effect(value: int):
|
|
|
|
Config.sound_lvl_effect = value
|
|
|
|
update_volume_db()
|
|
|
|
|
|
|
|
func add_music(file):
|
|
|
|
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-05-27 21:56:16 +00:00
|
|
|
self.popup()
|
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
func close():
|
2021-05-27 21:56:16 +00:00
|
|
|
self.hide()
|
|
|
|
|
2020-03-21 09:10:26 +00:00
|
|
|
func toggle():
|
2021-05-27 21:56:16 +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-05-27 21:56:16 +00:00
|
|
|
Config.msg_debug(p_filename)
|
|
|
|
#audio_player.stream = load( p_filename )
|
|
|
|
#audio_player.set_volume_db(1.0)
|
|
|
|
#audio_player.play()
|
|
|
|
|
|
|
|
#$music.stream = load( p_filename )
|
|
|
|
#$music.play()
|