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
|
||||
|
||||
##TODO
|
||||
# 1. Fix sync
|
||||
# 2. Fix reset buttons
|
||||
# 3. Fix settings
|
||||
# 4. Fix top buttons
|
||||
# 5. Fix player name
|
||||
# 6. Fix sound test
|
||||
# 7. Fix welcome into the game
|
||||
# 8. Fix match ball sound
|
||||
# 9. Fix winner
|
||||
@@ -16,6 +14,8 @@ extends Control
|
||||
# 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
|
||||
|
||||
@onready
|
||||
var open_button := $Open
|
||||
@@ -38,9 +38,6 @@ var song_label := $VBoxContainer/SongLabel
|
||||
@onready
|
||||
var play_button := $PanelContainer/HBoxContainer/PlayButton
|
||||
|
||||
@onready
|
||||
var pause_button := $PanelContainer/HBoxContainer/PauseButton
|
||||
|
||||
@onready
|
||||
var stop_button := $PanelContainer/HBoxContainer/StopButton
|
||||
|
||||
@@ -56,6 +53,15 @@ var label := $PanelContainer/HBoxContainer/Label
|
||||
@onready
|
||||
var add_player := $Players/VBoxContainer/HBoxContainer/AddPlayer
|
||||
|
||||
@onready
|
||||
var sound_test_button := $SoundTestButton
|
||||
|
||||
@onready
|
||||
var sync_button := $SyncButton
|
||||
|
||||
@onready
|
||||
var sync_popup := $PopupPanel
|
||||
|
||||
@onready
|
||||
var show_answer_button := $ShowAnswerButton
|
||||
|
||||
@@ -85,6 +91,61 @@ 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'
|
||||
|
||||
# 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:
|
||||
var http_request = HTTPRequest.new()
|
||||
add_child(http_request)
|
||||
@@ -99,23 +160,6 @@ func add_players():
|
||||
var new_player := Player.instantiate()
|
||||
players.add_child(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():
|
||||
if search_view.visible == false:
|
||||
@@ -288,7 +332,7 @@ func format_text(part: float, total: float) -> String:
|
||||
return format_time(part) + " / " + format_time(total)
|
||||
|
||||
|
||||
func fetch_first_song() -> void:
|
||||
func fetch_next_song() -> void:
|
||||
var http_request = HTTPRequest.new()
|
||||
add_child(http_request)
|
||||
#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()
|
||||
sound.data = body
|
||||
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:
|
||||
print("response_code", response_code)
|
||||
fetched()
|
||||
|
||||
func play(song) -> void:
|
||||
if audio.stream_paused:
|
||||
audio.stream_paused = false
|
||||
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]
|
||||
func play_local_song(song) -> void:
|
||||
if songs:
|
||||
path = songs[0]
|
||||
print(path)
|
||||
print(FileAccess.file_exists(path))
|
||||
audio.stream = load_mp3(path)
|
||||
print("play")
|
||||
audio.play()
|
||||
stream = audio.stream
|
||||
progress.max_value = round(stream.get_length())
|
||||
progress.tick_count = round(stream.get_length() / 60)
|
||||
|
||||
func pause() -> void:
|
||||
audio.stream_paused = true
|
||||
playback_position = audio.get_playback_position()
|
||||
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
|
||||
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:
|
||||
audio.stop()
|
||||
audio.stream_paused = false
|
||||
progress.value = 0
|
||||
is_paused = true
|
||||
play_button.text = "Play"
|
||||
|
||||
func _on_drag_started() -> void:
|
||||
is_changing = true
|
||||
|
||||
@@ -126,10 +126,6 @@ size_flags_vertical = 4
|
||||
layout_mode = 2
|
||||
text = "Play"
|
||||
|
||||
[node name="PauseButton" type="Button" parent="PanelContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Pause"
|
||||
|
||||
[node name="StopButton" type="Button" parent="PanelContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
text = "Stop"
|
||||
@@ -193,7 +189,7 @@ offset_right = 358.0
|
||||
offset_bottom = 1049.0
|
||||
text = "Reset points"
|
||||
|
||||
[node name="SuncButton" type="Button" parent="."]
|
||||
[node name="SyncButton" type="Button" parent="."]
|
||||
layout_mode = 0
|
||||
offset_left = 370.0
|
||||
offset_top = 1016.0
|
||||
@@ -282,4 +278,17 @@ offset_top = 81.2367
|
||||
offset_right = 349.196
|
||||
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"]
|
||||
|
||||
13
Player.gd
13
Player.gd
@@ -1,5 +1,8 @@
|
||||
extends Control
|
||||
|
||||
@onready
|
||||
var player_name := $HBoxContainer/Name
|
||||
|
||||
@onready
|
||||
var points := $HBoxContainer/Points
|
||||
|
||||
@@ -21,6 +24,12 @@ func _ready():
|
||||
add.pressed.connect(add_point)
|
||||
minus.pressed.connect(minus_point)
|
||||
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():
|
||||
var value := int(points.text)
|
||||
@@ -34,10 +43,6 @@ func change_character():
|
||||
print("change_character")
|
||||
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):
|
||||
print("Back in player list with: " + file_name)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user