Changed Play/Pause button. Fixed sync games. Fixed sound test, both local and online.
This commit is contained in:
143
MainWindow.gd
143
MainWindow.gd
@@ -1,12 +1,10 @@
|
|||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
##TODO
|
##TODO
|
||||||
# 1. Fix sync
|
|
||||||
# 2. Fix reset buttons
|
# 2. Fix reset buttons
|
||||||
# 3. Fix settings
|
# 3. Fix settings
|
||||||
# 4. Fix top buttons
|
# 4. Fix top buttons
|
||||||
# 5. Fix player name
|
# 5. Fix player name
|
||||||
# 6. Fix sound test
|
|
||||||
# 7. Fix welcome into the game
|
# 7. Fix welcome into the game
|
||||||
# 8. Fix match ball sound
|
# 8. Fix match ball sound
|
||||||
# 9. Fix winner
|
# 9. Fix winner
|
||||||
@@ -16,6 +14,8 @@ extends Control
|
|||||||
# 13. Fix graphics in lists
|
# 13. Fix graphics in lists
|
||||||
# 14. Fix layout
|
# 14. Fix layout
|
||||||
# 15. Fix for local play
|
# 15. Fix for local play
|
||||||
|
# 16. Change all calls to make_request and function in function
|
||||||
|
# 17. Change some buttons to icons
|
||||||
|
|
||||||
@onready
|
@onready
|
||||||
var open_button := $Open
|
var open_button := $Open
|
||||||
@@ -38,9 +38,6 @@ var song_label := $VBoxContainer/SongLabel
|
|||||||
@onready
|
@onready
|
||||||
var play_button := $PanelContainer/HBoxContainer/PlayButton
|
var play_button := $PanelContainer/HBoxContainer/PlayButton
|
||||||
|
|
||||||
@onready
|
|
||||||
var pause_button := $PanelContainer/HBoxContainer/PauseButton
|
|
||||||
|
|
||||||
@onready
|
@onready
|
||||||
var stop_button := $PanelContainer/HBoxContainer/StopButton
|
var stop_button := $PanelContainer/HBoxContainer/StopButton
|
||||||
|
|
||||||
@@ -56,6 +53,15 @@ var label := $PanelContainer/HBoxContainer/Label
|
|||||||
@onready
|
@onready
|
||||||
var add_player := $Players/VBoxContainer/HBoxContainer/AddPlayer
|
var add_player := $Players/VBoxContainer/HBoxContainer/AddPlayer
|
||||||
|
|
||||||
|
@onready
|
||||||
|
var sound_test_button := $SoundTestButton
|
||||||
|
|
||||||
|
@onready
|
||||||
|
var sync_button := $SyncButton
|
||||||
|
|
||||||
|
@onready
|
||||||
|
var sync_popup := $PopupPanel
|
||||||
|
|
||||||
@onready
|
@onready
|
||||||
var show_answer_button := $ShowAnswerButton
|
var show_answer_button := $ShowAnswerButton
|
||||||
|
|
||||||
@@ -85,6 +91,61 @@ var Player := preload("res://Player.tscn")
|
|||||||
@onready
|
@onready
|
||||||
var path = '/Users/sebastian/ResilioSync/Sorterat_test/Metal Gear Solid 4 - Guns of the Patriots/2-16 Metal Gear Saga.mp3'
|
var path = '/Users/sebastian/ResilioSync/Sorterat_test/Metal Gear Solid 4 - Guns of the Patriots/2-16 Metal Gear Saga.mp3'
|
||||||
|
|
||||||
|
# Called when the node enters the scene tree for the first time.
|
||||||
|
func _ready():
|
||||||
|
next_button.pressed.connect(fetch_next_song)
|
||||||
|
play_button.pressed.connect(play_or_pause)
|
||||||
|
stop_button.pressed.connect(stop)
|
||||||
|
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)
|
||||||
|
|
||||||
|
progress.drag_started.connect(_on_drag_started)
|
||||||
|
progress.drag_ended.connect(_on_drag_ended)
|
||||||
|
character_select.connect("character_selected", _on_character_selected)
|
||||||
|
|
||||||
|
add_player.pressed.connect(add_players)
|
||||||
|
|
||||||
|
open_button.pressed.connect(open)
|
||||||
|
get_suggestion_list()
|
||||||
|
|
||||||
|
func get_sound_test_song():
|
||||||
|
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()
|
||||||
|
sound.data = body
|
||||||
|
audio.stream = sound
|
||||||
|
audio.play()
|
||||||
|
stream = audio.stream
|
||||||
|
progress.max_value = round(stream.get_length())
|
||||||
|
progress.tick_count = round(stream.get_length() / 60)
|
||||||
|
|
||||||
|
make_request("https://music.sanplex.tech/music/first", play_sound_test_song)
|
||||||
|
|
||||||
|
func sound_test_local():
|
||||||
|
path = "res://01. Opening.mp3"
|
||||||
|
audio.stream = load_mp3(path)
|
||||||
|
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("https://music.sanplex.tech/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:
|
||||||
|
sync_popup.visible = true
|
||||||
|
|
||||||
func get_suggestion_list() -> void:
|
func get_suggestion_list() -> void:
|
||||||
var http_request = HTTPRequest.new()
|
var http_request = HTTPRequest.new()
|
||||||
add_child(http_request)
|
add_child(http_request)
|
||||||
@@ -99,23 +160,6 @@ func add_players():
|
|||||||
var new_player := Player.instantiate()
|
var new_player := Player.instantiate()
|
||||||
players.add_child(new_player)
|
players.add_child(new_player)
|
||||||
new_player.connect("change_character_clicked", _on_player_change_character_clicked.bind(new_player))
|
new_player.connect("change_character_clicked", _on_player_change_character_clicked.bind(new_player))
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
|
||||||
func _ready():
|
|
||||||
next_button.pressed.connect(fetch_first_song)
|
|
||||||
pause_button.pressed.connect(pause)
|
|
||||||
stop_button.pressed.connect(stop)
|
|
||||||
show_answer_button.pressed.connect(show_answer)
|
|
||||||
search_button.pressed.connect(show_search)
|
|
||||||
|
|
||||||
progress.drag_started.connect(_on_drag_started)
|
|
||||||
progress.drag_ended.connect(_on_drag_ended)
|
|
||||||
character_select.connect("character_selected", _on_character_selected)
|
|
||||||
|
|
||||||
add_player.pressed.connect(add_players)
|
|
||||||
|
|
||||||
open_button.pressed.connect(open)
|
|
||||||
get_suggestion_list()
|
|
||||||
|
|
||||||
func show_search():
|
func show_search():
|
||||||
if search_view.visible == false:
|
if search_view.visible == false:
|
||||||
@@ -288,7 +332,7 @@ func format_text(part: float, total: float) -> String:
|
|||||||
return format_time(part) + " / " + format_time(total)
|
return format_time(part) + " / " + format_time(total)
|
||||||
|
|
||||||
|
|
||||||
func fetch_first_song() -> void:
|
func fetch_next_song() -> void:
|
||||||
var http_request = HTTPRequest.new()
|
var http_request = HTTPRequest.new()
|
||||||
add_child(http_request)
|
add_child(http_request)
|
||||||
#http.set_download_file("https://music.sanplex.tech/music/first")
|
#http.set_download_file("https://music.sanplex.tech/music/first")
|
||||||
@@ -308,43 +352,54 @@ func first_song_fetched(result, response_code, headers, body) -> void:
|
|||||||
var sound = AudioStreamMP3.new()
|
var sound = AudioStreamMP3.new()
|
||||||
sound.data = body
|
sound.data = body
|
||||||
make_request("https://music.sanplex.tech/music/addQue", add_que)
|
make_request("https://music.sanplex.tech/music/addQue", add_que)
|
||||||
play(sound)
|
print("play given song")
|
||||||
|
audio.stream = sound
|
||||||
|
audio.play()
|
||||||
|
stream = audio.stream
|
||||||
|
progress.max_value = round(stream.get_length())
|
||||||
|
progress.tick_count = round(stream.get_length() / 60)
|
||||||
|
|
||||||
func add_que(result, response_code, headers, body) -> void:
|
func add_que(result, response_code, headers, body) -> void:
|
||||||
print("response_code", response_code)
|
print("response_code", response_code)
|
||||||
fetched()
|
fetched()
|
||||||
|
|
||||||
func play(song) -> void:
|
func play_local_song(song) -> void:
|
||||||
if audio.stream_paused:
|
if songs:
|
||||||
audio.stream_paused = false
|
path = songs[0]
|
||||||
audio.seek(playback_position)
|
|
||||||
print("continue")
|
|
||||||
elif song:
|
|
||||||
print("play given song")
|
|
||||||
audio.stream = song
|
|
||||||
audio.play()
|
|
||||||
stream = audio.stream
|
|
||||||
else:
|
|
||||||
if songs:
|
|
||||||
#print(songs)
|
|
||||||
path = songs[0]
|
|
||||||
print(path)
|
print(path)
|
||||||
print(FileAccess.file_exists(path))
|
print(FileAccess.file_exists(path))
|
||||||
audio.stream = load_mp3(path)
|
audio.stream = load_mp3(path)
|
||||||
print("play")
|
print("play")
|
||||||
audio.play()
|
audio.play()
|
||||||
stream = audio.stream
|
stream = audio.stream
|
||||||
progress.max_value = round(stream.get_length())
|
progress.max_value = round(stream.get_length())
|
||||||
progress.tick_count = round(stream.get_length() / 60)
|
progress.tick_count = round(stream.get_length() / 60)
|
||||||
|
|
||||||
func pause() -> void:
|
var is_paused: bool = true
|
||||||
audio.stream_paused = true
|
func play_or_pause():
|
||||||
playback_position = audio.get_playback_position()
|
if is_paused:
|
||||||
|
is_paused = false
|
||||||
|
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()
|
||||||
|
else:
|
||||||
|
audio.stream_paused = true
|
||||||
|
playback_position = audio.get_playback_position()
|
||||||
|
is_paused = true
|
||||||
|
play_button.text = "Play"
|
||||||
|
|
||||||
func stop() -> void:
|
func stop() -> void:
|
||||||
audio.stop()
|
audio.stop()
|
||||||
audio.stream_paused = false
|
audio.stream_paused = false
|
||||||
progress.value = 0
|
progress.value = 0
|
||||||
|
is_paused = true
|
||||||
|
play_button.text = "Play"
|
||||||
|
|
||||||
func _on_drag_started() -> void:
|
func _on_drag_started() -> void:
|
||||||
is_changing = true
|
is_changing = true
|
||||||
|
|||||||
@@ -126,10 +126,6 @@ size_flags_vertical = 4
|
|||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Play"
|
text = "Play"
|
||||||
|
|
||||||
[node name="PauseButton" type="Button" parent="PanelContainer/HBoxContainer"]
|
|
||||||
layout_mode = 2
|
|
||||||
text = "Pause"
|
|
||||||
|
|
||||||
[node name="StopButton" type="Button" parent="PanelContainer/HBoxContainer"]
|
[node name="StopButton" type="Button" parent="PanelContainer/HBoxContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "Stop"
|
text = "Stop"
|
||||||
@@ -193,7 +189,7 @@ offset_right = 358.0
|
|||||||
offset_bottom = 1049.0
|
offset_bottom = 1049.0
|
||||||
text = "Reset points"
|
text = "Reset points"
|
||||||
|
|
||||||
[node name="SuncButton" type="Button" parent="."]
|
[node name="SyncButton" type="Button" parent="."]
|
||||||
layout_mode = 0
|
layout_mode = 0
|
||||||
offset_left = 370.0
|
offset_left = 370.0
|
||||||
offset_top = 1016.0
|
offset_top = 1016.0
|
||||||
@@ -282,4 +278,17 @@ offset_top = 81.2367
|
|||||||
offset_right = 349.196
|
offset_right = 349.196
|
||||||
offset_bottom = 81.2367
|
offset_bottom = 81.2367
|
||||||
|
|
||||||
|
[node name="PopupPanel" type="PopupPanel" parent="."]
|
||||||
|
initial_position = 2
|
||||||
|
size = Vector2i(140, 70)
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="PopupPanel"]
|
||||||
|
offset_left = 4.0
|
||||||
|
offset_top = 4.0
|
||||||
|
offset_right = 136.0
|
||||||
|
offset_bottom = 66.0
|
||||||
|
text = "Games synced!"
|
||||||
|
horizontal_alignment = 1
|
||||||
|
vertical_alignment = 1
|
||||||
|
|
||||||
[connection signal="dir_selected" from="FileDialog" to="." method="_on_file_dialog_dir_selected"]
|
[connection signal="dir_selected" from="FileDialog" to="." method="_on_file_dialog_dir_selected"]
|
||||||
|
|||||||
13
Player.gd
13
Player.gd
@@ -1,5 +1,8 @@
|
|||||||
extends Control
|
extends Control
|
||||||
|
|
||||||
|
@onready
|
||||||
|
var player_name := $HBoxContainer/Name
|
||||||
|
|
||||||
@onready
|
@onready
|
||||||
var points := $HBoxContainer/Points
|
var points := $HBoxContainer/Points
|
||||||
|
|
||||||
@@ -21,6 +24,12 @@ func _ready():
|
|||||||
add.pressed.connect(add_point)
|
add.pressed.connect(add_point)
|
||||||
minus.pressed.connect(minus_point)
|
minus.pressed.connect(minus_point)
|
||||||
character.pressed.connect(change_character)
|
character.pressed.connect(change_character)
|
||||||
|
player_name.mouse_filter = Control.MOUSE_FILTER_PASS
|
||||||
|
player_name.gui_input.connect(name_clicked)
|
||||||
|
|
||||||
|
func name_clicked(event):
|
||||||
|
if (event is InputEventMouseButton && event.pressed && event.button_index == MOUSE_BUTTON_LEFT):
|
||||||
|
print("Clicked: " + player_name.text)
|
||||||
|
|
||||||
func add_point():
|
func add_point():
|
||||||
var value := int(points.text)
|
var value := int(points.text)
|
||||||
@@ -34,10 +43,6 @@ func change_character():
|
|||||||
print("change_character")
|
print("change_character")
|
||||||
change_character_clicked.emit()
|
change_character_clicked.emit()
|
||||||
|
|
||||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
|
||||||
func _process(delta):
|
|
||||||
pass
|
|
||||||
|
|
||||||
func _on_control_character_selected_clicked(file_name: String):
|
func _on_control_character_selected_clicked(file_name: String):
|
||||||
print("Back in player list with: " + file_name)
|
print("Back in player list with: " + file_name)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user