Fixed settings and updated player view. Fixed many other smaler things
This commit is contained in:
136
MainWindow.gd
136
MainWindow.gd
@@ -1,10 +1,10 @@
|
||||
extends Control
|
||||
|
||||
# 601 LOC 11/9 - 2023
|
||||
# 628 LOC 15/9 - 2023
|
||||
# 631 LOC 16/9 - 2023
|
||||
|
||||
##TODO
|
||||
# 2. Fix reset buttons
|
||||
# 3. Fix settings
|
||||
# 11. Refactor components
|
||||
# 13. Fix graphics in lists
|
||||
# 14. Fix layout
|
||||
@@ -57,6 +57,12 @@ var add_player_button := $Players/VBoxContainer/AddPlayerContainer/AddPlayerButt
|
||||
@onready
|
||||
var new_player_name_field := $Players/VBoxContainer/AddPlayerContainer/PlayerNameField
|
||||
|
||||
@onready
|
||||
var reset_playlist_button := $ResetPlaylistButton
|
||||
|
||||
@onready
|
||||
var reset_points_button := $ResetPointsButton
|
||||
|
||||
@onready
|
||||
var sound_test_button := $SoundTestButton
|
||||
|
||||
@@ -129,7 +135,7 @@ var winner_popup := $WinnerPopupPanel
|
||||
@onready
|
||||
var winner_label := $WinnerPopupPanel/WinnerLabel
|
||||
|
||||
var Player := preload("res://Player.tscn")
|
||||
var player := preload("res://Player.tscn")
|
||||
|
||||
@onready
|
||||
var path = '/Users/sebastian/ResilioSync/Sorterat_test/Metal Gear Solid 4 - Guns of the Patriots/2-16 Metal Gear Saga.mp3'
|
||||
@@ -146,11 +152,14 @@ func _ready():
|
||||
statistics_button.pressed.connect(get_statistics)
|
||||
about_button.pressed.connect(show_about)
|
||||
settings_button.pressed.connect(show_settings)
|
||||
reset_playlist_button.pressed.connect(reset_playlist)
|
||||
reset_points_button.pressed.connect(reset_points)
|
||||
|
||||
progress.drag_started.connect(_on_drag_started)
|
||||
progress.drag_ended.connect(_on_drag_ended)
|
||||
character_select.connect("character_selected", _on_character_selected)
|
||||
new_player_name_field.connect("enter_key_pressed", add_player)
|
||||
|
||||
add_players_button.pressed.connect(add_players)
|
||||
add_player_button.pressed.connect(add_player)
|
||||
|
||||
@@ -158,6 +167,16 @@ func _ready():
|
||||
get_suggestion_list()
|
||||
fetch_full_music_list_at_start()
|
||||
|
||||
func reset_playlist():
|
||||
print("reset_playlist")
|
||||
Settings.make_request2("/music/reset", fetch_full_music_list_at_start, false)
|
||||
|
||||
func reset_points():
|
||||
var players_to_reset := players.get_children()
|
||||
for player_to_reset in players_to_reset:
|
||||
if player_to_reset.has_method("reset_points"):
|
||||
player_to_reset.reset_points()
|
||||
|
||||
func show_about():
|
||||
about_popup.visible = true
|
||||
version_label.text = Settings.version
|
||||
@@ -173,7 +192,7 @@ func get_statistics():
|
||||
statistic_label.text = "Total amount of games in the playlist: " + str(games.size())
|
||||
|
||||
func get_sound_test_song():
|
||||
var play_sound_test_song = func(result, response_code, headers, body):
|
||||
var play_sound_test_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()
|
||||
@@ -187,73 +206,65 @@ func get_sound_test_song():
|
||||
make_request(Settings.default_path + "/music/first", play_sound_test_song)
|
||||
|
||||
func sound_test_local():
|
||||
path = "res://01. Opening.mp3"
|
||||
audio.stream = load_mp3(path)
|
||||
audio.stream = preload("res://01. Opening.mp3")
|
||||
audio.play()
|
||||
stream = audio.stream
|
||||
progress.max_value = round(stream.get_length())
|
||||
progress.tick_count = round(stream.get_length() / 60)
|
||||
|
||||
func sync_games():
|
||||
var http_request = HTTPRequest.new()
|
||||
add_child(http_request)
|
||||
http_request.request_completed.connect(games_synced)
|
||||
|
||||
# Perform a GET request. The URL below returns JSON as of writing.
|
||||
var error = http_request.request(Settings.default_path + "/sync")
|
||||
if error != OK:
|
||||
push_error("An error occurred in the HTTP request.")
|
||||
|
||||
func games_synced(result, response_code, headers, body):
|
||||
if response_code == 200:
|
||||
var games_synced = func():
|
||||
sync_popup.visible = true
|
||||
print("games_synced")
|
||||
reset_playlist()
|
||||
get_suggestion_list()
|
||||
Settings.make_request2("/sync", games_synced, false)
|
||||
|
||||
func get_suggestion_list() -> void:
|
||||
var populate_list = func(array):
|
||||
if typeof(array) == TYPE_ARRAY:
|
||||
games.append_array(array)
|
||||
for game in games:
|
||||
var label := Label.new()
|
||||
label.text = game
|
||||
label.autowrap_mode = TextServer.AUTOWRAP_WORD
|
||||
insperation_list.add_child(label)
|
||||
var insperation_label := Label.new()
|
||||
insperation_label.text = game
|
||||
insperation_label.autowrap_mode = TextServer.AUTOWRAP_WORD
|
||||
insperation_list.add_child(insperation_label)
|
||||
insperation_scroll.scroll_to_bottom()
|
||||
else:
|
||||
print("Unexpected data")
|
||||
Settings.make_request2("/music/all", populate_list)
|
||||
Settings.make_request2("/music/all", populate_list, true)
|
||||
|
||||
func add_players():
|
||||
add_player_container.visible = !add_player_container.visible
|
||||
new_player_name_field.grab_focus()
|
||||
|
||||
func add_player():
|
||||
var new_player := Player.instantiate()
|
||||
new_player.new_name(new_player_name_field.text)
|
||||
var new_player := player.instantiate()
|
||||
new_player.new_name(new_player_name_field.text + ": 0")
|
||||
new_player_name_field.text = ""
|
||||
players.add_child(new_player)
|
||||
new_player.connect("change_character_clicked", _on_player_change_character_clicked.bind(new_player))
|
||||
new_player.connect("first_point_triggerd", _on_point_triggerd.bind("first", ""))
|
||||
new_player.connect("match_point_triggerd", _on_point_triggerd.bind("match", ""))
|
||||
new_player.connect("winner_triggerd", _on_point_triggerd.bind("winner", new_player.player_name))
|
||||
new_player.connect("player_removed", _on_player_removed.bind(new_player))
|
||||
|
||||
func _on_point_triggerd(point: String, name: String):
|
||||
var song_path: String
|
||||
func _on_point_triggerd(point: String, player_name: String):
|
||||
if point == "first":
|
||||
var value = randi_range(0, 10)
|
||||
if value == 0:
|
||||
song_path = "res://sounds/sound1.mp3"
|
||||
audio.stream = preload("res://sounds/sound1.mp3")
|
||||
elif value < 5:
|
||||
song_path = "res://sounds/intro_long.mp3"
|
||||
else:
|
||||
song_path = "res://sounds/intro_short.mp3"
|
||||
audio.stream = preload("res://sounds/intro_long.mp3")
|
||||
else:
|
||||
audio.stream = preload("res://sounds/intro_short.mp3")
|
||||
elif point == "match":
|
||||
song_path = "res://sounds/sound0.mp3"
|
||||
audio.stream = preload("res://sounds/sound0.mp3")
|
||||
elif point == "winner":
|
||||
song_path = "res://sounds/winning.mp3"
|
||||
audio.stream = preload("res://sounds/winning.mp3")
|
||||
winner_popup.visible = true
|
||||
winner_label.text = name + " won!!"
|
||||
winner_label.text = player_name + " won!!"
|
||||
|
||||
audio.stream = load_mp3(song_path)
|
||||
audio.play()
|
||||
play_button.text = "Pause"
|
||||
stream = audio.stream
|
||||
@@ -277,26 +288,30 @@ func show_answer():
|
||||
push_error("An error occurred in the HTTP request.")
|
||||
|
||||
func fetch_full_music_list_at_start():
|
||||
var show_fetched_list = func(data):
|
||||
if data == null: return
|
||||
print("fetch_full_music_list_at_start")
|
||||
var show_music_list_at_start = func(data):
|
||||
if data == null:
|
||||
song_list = []
|
||||
delete_children(music_list)
|
||||
return
|
||||
if typeof(data) == TYPE_ARRAY:
|
||||
song_list = []
|
||||
song_list.append_array(data)
|
||||
for song in song_list:
|
||||
var label := Label.new()
|
||||
var music_list_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)
|
||||
music_list_label.text = actual_string
|
||||
music_list_label.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||
music_list_label.gui_input.connect(song_clicked.bind(music_list_label, song.SongNo))
|
||||
music_list.add_child(music_list_label)
|
||||
else:
|
||||
print("Unexpected data")
|
||||
Settings.make_request2("/music/list", show_fetched_list)
|
||||
Settings.make_request2("/music/list", show_music_list_at_start, true)
|
||||
|
||||
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 show_music_list = func(_result, _response_code, _headers, body):
|
||||
var json = JSON.new()
|
||||
var error = json.parse(body.get_string_from_utf8())
|
||||
|
||||
@@ -321,8 +336,8 @@ func fetch_full_music_list(event, song_no: int):
|
||||
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):
|
||||
make_request(Settings.default_path + "/music/list", show_music_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()
|
||||
@@ -449,7 +464,6 @@ func _on_file_dialog_dir_selected(path):
|
||||
|
||||
var songs := []
|
||||
var games := []
|
||||
#var player = preload("res://Player.gd")
|
||||
|
||||
func dir_contents(path: String) -> void:
|
||||
var dir = DirAccess.open(path)
|
||||
@@ -509,28 +523,39 @@ func format_text(part: float, total: float) -> String:
|
||||
func fetch_next_song() -> void:
|
||||
var http_request = HTTPRequest.new()
|
||||
add_child(http_request)
|
||||
http_request.request_completed.connect(first_song_fetched)
|
||||
http_request.request_completed.connect(song_fetched)
|
||||
|
||||
# Perform a GET request. The URL below returns JSON as of writing.
|
||||
var error = http_request.request(Settings.default_path + "/music/rand")
|
||||
var path = ""
|
||||
if Settings.use_low_played_mode:
|
||||
path = "/music/rand/low"
|
||||
else:
|
||||
path = "/music/rand"
|
||||
var error = http_request.request(Settings.default_path + path)
|
||||
if error != OK:
|
||||
push_error("An error occurred in the HTTP request.")
|
||||
|
||||
func first_song_fetched(result, response_code, headers, body) -> void:
|
||||
game_label.text = "????????"
|
||||
song_label.text = "??????"
|
||||
|
||||
func song_fetched(result, response_code, headers, body) -> void:
|
||||
if result != HTTPRequest.RESULT_SUCCESS:
|
||||
push_error("Song couldn't be downloaded. Try a different song.")
|
||||
var sound = AudioStreamMP3.new()
|
||||
sound.data = body
|
||||
make_request(Settings.default_path + "/music/addQue", add_que)
|
||||
print("play given song")
|
||||
audio.stream = sound
|
||||
audio.play()
|
||||
play_button.text = "Pause"
|
||||
stream = audio.stream
|
||||
make_request(Settings.default_path + "/music/addQue", add_que)
|
||||
progress.max_value = round(stream.get_length())
|
||||
progress.tick_count = round(stream.get_length() / 60)
|
||||
game_label.text = "????????"
|
||||
song_label.text = "??????"
|
||||
if Settings.add_to_stats:
|
||||
Settings.make_request2("/music/played", func(): pass , false)
|
||||
if !Settings.stop_after_current:
|
||||
audio.finished.connect(fetch_next_song)
|
||||
if !Settings.hide_next_track:
|
||||
show_answer()
|
||||
|
||||
func add_que(result, response_code, headers, body) -> void:
|
||||
print("response_code", response_code)
|
||||
@@ -584,6 +609,9 @@ func load_mp3(_path) -> AudioStream:
|
||||
sound.data = file.get_buffer(file.get_length())
|
||||
return sound
|
||||
|
||||
func _on_player_removed(new_player):
|
||||
players.remove_child(new_player)
|
||||
|
||||
var current_player
|
||||
func _on_player_change_character_clicked(new_player):
|
||||
print("_on_player_change_character_clicked")
|
||||
@@ -596,7 +624,7 @@ func _on_character_selected(file_name: String):
|
||||
current_player._on_control_character_selected_clicked(file_name)
|
||||
|
||||
|
||||
static func delete_children(node):
|
||||
func delete_children(node):
|
||||
for n in node.get_children():
|
||||
node.remove_child(n)
|
||||
n.queue_free()
|
||||
|
||||
Reference in New Issue
Block a user