Added hopping between songs. Added settings menu, not finished.
This commit is contained in:
169
MainWindow.gd
169
MainWindow.gd
@@ -4,13 +4,13 @@ extends Control
|
||||
# 2. Fix reset buttons
|
||||
# 3. Fix settings
|
||||
# 9. Fix winner
|
||||
# 10. Fix jump between songs
|
||||
# 11. Refactor components
|
||||
# 13. Fix graphics in lists
|
||||
# 14. Fix layout
|
||||
# 15. Fix for local play
|
||||
# 16. Change all calls to make_request and function in function
|
||||
# 17. Change some buttons to icons
|
||||
# 18. Fix shortcuts
|
||||
|
||||
@onready
|
||||
var open_button := $Open
|
||||
@@ -34,7 +34,7 @@ var song_label := $VBoxContainer/SongLabel
|
||||
var play_button := $PanelContainer/HBoxContainer/PlayButton
|
||||
|
||||
@onready
|
||||
var stop_button := $PanelContainer/HBoxContainer/StopButton
|
||||
var restart_button := $PanelContainer/HBoxContainer/RestartButton
|
||||
|
||||
@onready
|
||||
var audio := $AudioStreamPlayer
|
||||
@@ -64,7 +64,13 @@ var sound_test_button := $SoundTestButton
|
||||
var sync_button := $SyncButton
|
||||
|
||||
@onready
|
||||
var sync_popup := $PopupPanel
|
||||
var sync_popup := $SyncPopupPanel
|
||||
|
||||
@onready
|
||||
var settings_button := $SettingsButton
|
||||
|
||||
@onready
|
||||
var settings_popup := $SettingsPopupPanel
|
||||
|
||||
@onready
|
||||
var statistics_button := $StatisticsButton
|
||||
@@ -105,6 +111,15 @@ var search_button := $SearchButton
|
||||
@onready
|
||||
var search_view := $Search
|
||||
|
||||
@onready
|
||||
var version_label := $AboutPopupPanel/VBoxContainer/VersionLabel
|
||||
|
||||
@onready
|
||||
var new_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/NewLabel
|
||||
|
||||
@onready
|
||||
var comming_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/CommingLabel
|
||||
|
||||
var Player := preload("res://Player.tscn")
|
||||
|
||||
@onready
|
||||
@@ -114,13 +129,14 @@ var path = '/Users/sebastian/ResilioSync/Sorterat_test/Metal Gear Solid 4 - Guns
|
||||
func _ready():
|
||||
next_button.pressed.connect(fetch_next_song)
|
||||
play_button.pressed.connect(play_or_pause)
|
||||
stop_button.pressed.connect(stop)
|
||||
restart_button.pressed.connect(restart)
|
||||
show_answer_button.pressed.connect(show_answer)
|
||||
search_button.pressed.connect(show_search)
|
||||
sync_button.pressed.connect(sync_games)
|
||||
sound_test_button.pressed.connect(get_sound_test_song)
|
||||
statistics_button.pressed.connect(get_statistics)
|
||||
about_button.pressed.connect(show_about)
|
||||
settings_button.pressed.connect(show_settings)
|
||||
|
||||
progress.drag_started.connect(_on_drag_started)
|
||||
progress.drag_ended.connect(_on_drag_ended)
|
||||
@@ -131,9 +147,16 @@ func _ready():
|
||||
|
||||
open_button.pressed.connect(open)
|
||||
get_suggestion_list()
|
||||
fetch_full_music_list_at_start()
|
||||
|
||||
func show_about():
|
||||
about_popup.visible = true
|
||||
version_label.text = Settings.version
|
||||
new_label.text = Settings.whats_new
|
||||
comming_label.text = Settings.whats_left
|
||||
|
||||
func show_settings():
|
||||
settings_popup.visible = true
|
||||
|
||||
func get_statistics():
|
||||
statistic_popup.visible = true
|
||||
@@ -235,7 +258,80 @@ func show_answer():
|
||||
var error = http_request.request(Settings.default_path + "/music/info")
|
||||
if error != OK:
|
||||
push_error("An error occurred in the HTTP request.")
|
||||
|
||||
func fetch_full_music_list_at_start():
|
||||
var show_fetched_list = func(result, response_code, headers, body):
|
||||
var json = JSON.new()
|
||||
var error = json.parse(body.get_string_from_utf8())
|
||||
|
||||
if error == OK:
|
||||
var data_received = json.get_data()
|
||||
if typeof(data_received) == TYPE_ARRAY:
|
||||
song_list = []
|
||||
song_list.append_array(data_received)
|
||||
for song in song_list:
|
||||
var label := Label.new()
|
||||
var format_string = "%d. %s - %s"
|
||||
var actual_string = format_string % [(song.SongNo+1), song.Game, song.Song]
|
||||
label.text = actual_string
|
||||
label.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
label.gui_input.connect(song_clicked.bind(label, song.SongNo))
|
||||
music_list.add_child(label)
|
||||
else:
|
||||
print("Unexpected data")
|
||||
make_request(Settings.default_path + "/music/list", show_fetched_list)
|
||||
|
||||
func fetch_full_music_list(event, song_no: int):
|
||||
if (event is InputEventMouseButton && event.pressed && event.button_index == MOUSE_BUTTON_LEFT):
|
||||
var show_fetched_list = func(result, response_code, headers, body):
|
||||
var json = JSON.new()
|
||||
var error = json.parse(body.get_string_from_utf8())
|
||||
|
||||
if error == OK:
|
||||
var data_received = json.get_data()
|
||||
if typeof(data_received) == TYPE_ARRAY:
|
||||
song_list = []
|
||||
song_list.append_array(data_received)
|
||||
delete_children(music_list)
|
||||
for song in song_list:
|
||||
var label := Label.new()
|
||||
game_label.text = song.Game
|
||||
song_label.text = song.Song
|
||||
var format_string = "%d. %s - %s"
|
||||
var actual_string = format_string % [(song.SongNo+1), song.Game, song.Song]
|
||||
label.text = actual_string
|
||||
label.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
label.gui_input.connect(song_clicked.bind(label, song.SongNo))
|
||||
print(str(music_list.get_child_count()) + " | " + str(song_list.size() - 1))
|
||||
if music_list.get_child_count() == song_list.size() - 1:
|
||||
label.add_theme_color_override("font_color", Color(1, 0.5, 0))
|
||||
music_list.add_child(label)
|
||||
else:
|
||||
print("Unexpected data")
|
||||
make_request(Settings.default_path + "/music/list", show_fetched_list)
|
||||
var play_clicked_song = func(result, response_code, headers, body):
|
||||
if result != HTTPRequest.RESULT_SUCCESS:
|
||||
push_error("Song couldn't be downloaded. Try a different song.")
|
||||
var sound = AudioStreamMP3.new()
|
||||
sound.data = body
|
||||
audio.stream = sound
|
||||
audio.play()
|
||||
play_button.text = "Pause"
|
||||
stream = audio.stream
|
||||
progress.max_value = round(stream.get_length())
|
||||
progress.tick_count = round(stream.get_length() / 60)
|
||||
make_request(Settings.default_path + "/music?song=" + str(song_no), play_clicked_song)
|
||||
var show_answer = func(result, response_code, headers, body):
|
||||
var json = JSON.new()
|
||||
var error = json.parse(body.get_string_from_utf8())
|
||||
|
||||
if error == OK:
|
||||
var data_received = json.get_data()
|
||||
game_label.text = data_received.Game
|
||||
song_label.text = data_received.Song
|
||||
make_request(Settings.default_path + "/music/info", show_answer)
|
||||
|
||||
|
||||
func fetched():
|
||||
var http_request2 = HTTPRequest.new()
|
||||
add_child(http_request2)
|
||||
@@ -279,21 +375,50 @@ func show_fetched_list(result, response_code, headers, body) -> void:
|
||||
var actual_string = format_string % [(song.SongNo+1), song.Game, song.Song]
|
||||
label.text = actual_string
|
||||
label.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
label.gui_input.connect(song_clicked.bind(song.SongNo))
|
||||
label.gui_input.connect(song_clicked.bind(label, song.SongNo))
|
||||
music_list.add_child(label)
|
||||
|
||||
|
||||
var songs := music_list.get_children()
|
||||
for song in songs:
|
||||
song.remove_theme_color_override("font_color")
|
||||
next_label = Label.new()
|
||||
next_label.add_theme_color_override("font_color", Color(1, 0.5, 0))
|
||||
next_label.text = "??? - ???"
|
||||
next_label.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
next_label.gui_input.connect(show_fetched)
|
||||
next_label.gui_input.connect(fetch_full_music_list.bind(songs.size()))
|
||||
music_list.add_child(next_label)
|
||||
|
||||
else:
|
||||
print("Unexpected data")
|
||||
|
||||
func song_clicked(event, song_no):
|
||||
func song_clicked(event, label: Label, song_no: int):
|
||||
if (event is InputEventMouseButton && event.pressed && event.button_index == MOUSE_BUTTON_LEFT):
|
||||
print("Clicked: " + str(song_no))
|
||||
print("Song Clicked: " + str(song_no))
|
||||
var songs := music_list.get_children()
|
||||
for song in songs:
|
||||
song.remove_theme_color_override("font_color")
|
||||
label.add_theme_color_override("font_color", Color(1, 0.5, 0))
|
||||
var play_clicked_song = func(result, response_code, headers, body):
|
||||
if result != HTTPRequest.RESULT_SUCCESS:
|
||||
push_error("Song couldn't be downloaded. Try a different song.")
|
||||
var sound = AudioStreamMP3.new()
|
||||
sound.data = body
|
||||
audio.stream = sound
|
||||
audio.play()
|
||||
play_button.text = "Pause"
|
||||
stream = audio.stream
|
||||
progress.max_value = round(stream.get_length())
|
||||
progress.tick_count = round(stream.get_length() / 60)
|
||||
make_request(Settings.default_path + "/music?song=" + str(song_no), play_clicked_song)
|
||||
var show_answer = func(result, response_code, headers, body):
|
||||
var json = JSON.new()
|
||||
var error = json.parse(body.get_string_from_utf8())
|
||||
|
||||
if error == OK:
|
||||
var data_received = json.get_data()
|
||||
game_label.text = data_received.Game
|
||||
song_label.text = data_received.Song
|
||||
make_request(Settings.default_path + "/music/info", show_answer)
|
||||
|
||||
# Called when the HTTP request is completed.
|
||||
func _http_request_completed(result, response_code, headers, body):
|
||||
@@ -433,31 +558,27 @@ func play_local_song(song) -> void:
|
||||
progress.max_value = round(stream.get_length())
|
||||
progress.tick_count = round(stream.get_length() / 60)
|
||||
|
||||
var is_paused: bool = true
|
||||
func play_or_pause():
|
||||
if is_paused:
|
||||
is_paused = false
|
||||
if audio.stream_paused:
|
||||
play_button.text = "Pause"
|
||||
if audio.stream_paused:
|
||||
audio.stream_paused = false
|
||||
audio.seek(playback_position)
|
||||
print("continue")
|
||||
progress.max_value = round(stream.get_length())
|
||||
progress.tick_count = round(stream.get_length() / 60)
|
||||
else:
|
||||
fetch_next_song()
|
||||
audio.stream_paused = false
|
||||
audio.seek(playback_position)
|
||||
print("continue")
|
||||
progress.max_value = round(stream.get_length())
|
||||
progress.tick_count = round(stream.get_length() / 60)
|
||||
else:
|
||||
audio.stream_paused = true
|
||||
playback_position = audio.get_playback_position()
|
||||
is_paused = true
|
||||
play_button.text = "Play"
|
||||
|
||||
func stop() -> void:
|
||||
func restart() -> void:
|
||||
audio.stop()
|
||||
audio.stream_paused = false
|
||||
progress.value = 0
|
||||
is_paused = true
|
||||
play_button.text = "Play"
|
||||
playback_position = audio.get_playback_position()
|
||||
audio.seek(playback_position)
|
||||
play_button.text = "Pause"
|
||||
audio.play()
|
||||
|
||||
func _on_drag_started() -> void:
|
||||
is_changing = true
|
||||
|
||||
Reference in New Issue
Block a user