2 Commits

7 changed files with 234 additions and 31 deletions

View File

@@ -3,14 +3,9 @@ extends Control
##TODO ##TODO
# 2. Fix reset buttons # 2. Fix reset buttons
# 3. Fix settings # 3. Fix settings
# 4. Fix top buttons
# 5. Fix player name
# 7. Fix welcome into the game
# 8. Fix match ball sound
# 9. Fix winner # 9. Fix winner
# 10. Fix jump between songs # 10. Fix jump between songs
# 11. Refactor components # 11. Refactor components
# 12. Change add player
# 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
@@ -51,7 +46,16 @@ var progress := $PanelContainer/HBoxContainer/HSlider
var label := $PanelContainer/HBoxContainer/Label var label := $PanelContainer/HBoxContainer/Label
@onready @onready
var add_player := $Players/VBoxContainer/HBoxContainer/AddPlayer var add_player_container := $Players/VBoxContainer/AddPlayerContainer
@onready
var add_players_button := $Players/VBoxContainer/HBoxContainer/AddPlayersButton
@onready
var add_player_button := $Players/VBoxContainer/AddPlayerContainer/AddPlayerButton
@onready
var new_player_name_field := $Players/VBoxContainer/AddPlayerContainer/PlayerNameField
@onready @onready
var sound_test_button := $SoundTestButton var sound_test_button := $SoundTestButton
@@ -62,6 +66,21 @@ var sync_button := $SyncButton
@onready @onready
var sync_popup := $PopupPanel var sync_popup := $PopupPanel
@onready
var statistics_button := $StatisticsButton
@onready
var statistic_popup := $StatisticsPopupPanel
@onready
var statistic_label := $StatisticsPopupPanel/StatisticsLabel
@onready
var about_button := $AboutButton
@onready
var about_popup := $AboutPopupPanel
@onready @onready
var show_answer_button := $ShowAnswerButton var show_answer_button := $ShowAnswerButton
@@ -100,16 +119,26 @@ func _ready():
search_button.pressed.connect(show_search) search_button.pressed.connect(show_search)
sync_button.pressed.connect(sync_games) sync_button.pressed.connect(sync_games)
sound_test_button.pressed.connect(get_sound_test_song) sound_test_button.pressed.connect(get_sound_test_song)
statistics_button.pressed.connect(get_statistics)
about_button.pressed.connect(show_about)
progress.drag_started.connect(_on_drag_started) progress.drag_started.connect(_on_drag_started)
progress.drag_ended.connect(_on_drag_ended) progress.drag_ended.connect(_on_drag_ended)
character_select.connect("character_selected", _on_character_selected) character_select.connect("character_selected", _on_character_selected)
new_player_name_field.connect("enter_key_pressed", add_player)
add_player.pressed.connect(add_players) add_players_button.pressed.connect(add_players)
add_player_button.pressed.connect(add_player)
open_button.pressed.connect(open) open_button.pressed.connect(open)
get_suggestion_list() get_suggestion_list()
func show_about():
about_popup.visible = true
func get_statistics():
statistic_popup.visible = true
statistic_label.text = "Total amount of games in the playlist: " + str(games.size())
func get_sound_test_song(): 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: if result != HTTPRequest.RESULT_SUCCESS:
@@ -122,7 +151,7 @@ func get_sound_test_song():
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)
make_request("https://music.sanplex.tech/music/first", play_sound_test_song) make_request(Settings.default_path + "/music/first", play_sound_test_song)
func sound_test_local(): func sound_test_local():
path = "res://01. Opening.mp3" path = "res://01. Opening.mp3"
@@ -138,7 +167,7 @@ func sync_games():
http_request.request_completed.connect(games_synced) http_request.request_completed.connect(games_synced)
# Perform a GET request. The URL below returns JSON as of writing. # Perform a GET request. The URL below returns JSON as of writing.
var error = http_request.request("https://music.sanplex.tech/sync") var error = http_request.request(Settings.default_path + "/sync")
if error != OK: if error != OK:
push_error("An error occurred in the HTTP request.") push_error("An error occurred in the HTTP request.")
@@ -152,14 +181,44 @@ func get_suggestion_list() -> void:
http_request.request_completed.connect(_http_request_completed) http_request.request_completed.connect(_http_request_completed)
# Perform a GET request. The URL below returns JSON as of writing. # Perform a GET request. The URL below returns JSON as of writing.
var error = http_request.request("https://music.sanplex.tech/music/all") var error = http_request.request(Settings.default_path + "/music/all")
if error != OK: if error != OK:
push_error("An error occurred in the HTTP request.") push_error("An error occurred in the HTTP request.")
func add_players(): 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() var new_player := Player.instantiate()
new_player.new_name(new_player_name_field.text)
new_player_name_field.text = ""
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))
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"))
func _on_point_triggerd(point: String):
var song_path: String
if point == "first":
var value = randi_range(0, 10)
if value == 0:
song_path = "res://sounds/sound1.mp3"
elif value < 5:
song_path = "res://sounds/intro_long.mp3"
else:
song_path = "res://sounds/intro_short.mp3"
elif point == "match":
song_path = "res://sounds/sound0.mp3"
elif point == "winner":
song_path = "res://sounds/winning.mp3"
audio.stream = load_mp3(song_path)
audio.play()
stream = audio.stream
progress.max_value = round(stream.get_length())
progress.tick_count = round(stream.get_length() / 60)
func show_search(): func show_search():
if search_view.visible == false: if search_view.visible == false:
@@ -173,7 +232,7 @@ func show_answer():
http_request.request_completed.connect(show_fetched) http_request.request_completed.connect(show_fetched)
# Perform a GET request. The URL below returns JSON as of writing. # Perform a GET request. The URL below returns JSON as of writing.
var error = http_request.request("https://music.sanplex.tech/music/info") var error = http_request.request(Settings.default_path + "/music/info")
if error != OK: if error != OK:
push_error("An error occurred in the HTTP request.") push_error("An error occurred in the HTTP request.")
@@ -183,7 +242,7 @@ func fetched():
http_request2.request_completed.connect(show_fetched_list) http_request2.request_completed.connect(show_fetched_list)
# Perform a GET request. The URL below returns JSON as of writing. # Perform a GET request. The URL below returns JSON as of writing.
var error2 = http_request2.request("https://music.sanplex.tech/music/list") var error2 = http_request2.request(Settings.default_path + "/music/list")
if error2 != OK: if error2 != OK:
push_error("An error occurred in the HTTP request.") push_error("An error occurred in the HTTP request.")
@@ -335,11 +394,10 @@ func format_text(part: float, total: float) -> String:
func fetch_next_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_request.request_completed.connect(first_song_fetched) http_request.request_completed.connect(first_song_fetched)
# Perform a GET request. The URL below returns JSON as of writing. # Perform a GET request. The URL below returns JSON as of writing.
var error = http_request.request("https://music.sanplex.tech/music/rand") var error = http_request.request(Settings.default_path + "/music/rand")
if error != OK: if error != OK:
push_error("An error occurred in the HTTP request.") push_error("An error occurred in the HTTP request.")
@@ -351,7 +409,7 @@ func first_song_fetched(result, response_code, headers, body) -> void:
push_error("Song couldn't be downloaded. Try a different song.") push_error("Song couldn't be downloaded. Try a different song.")
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(Settings.default_path + "/music/addQue", add_que)
print("play given song") print("play given song")
audio.stream = sound audio.stream = sound
audio.play() audio.play()

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=15 format=3 uid="uid://xwq863o6uvsu"] [gd_scene load_steps=18 format=3 uid="uid://xwq863o6uvsu"]
[ext_resource type="Script" path="res://MainWindow.gd" id="1_eu0t5"] [ext_resource type="Script" path="res://MainWindow.gd" id="1_eu0t5"]
[ext_resource type="PackedScene" uid="uid://b16on0oscg1bv" path="res://CharacterSelect.tscn" id="2_76kf4"] [ext_resource type="PackedScene" uid="uid://b16on0oscg1bv" path="res://CharacterSelect.tscn" id="2_76kf4"]
@@ -7,6 +7,7 @@
[ext_resource type="AudioStream" uid="uid://n2g8jddr85h2" path="res://01. Opening.mp3" id="4_5kvsq"] [ext_resource type="AudioStream" uid="uid://n2g8jddr85h2" path="res://01. Opening.mp3" id="4_5kvsq"]
[ext_resource type="Texture2D" uid="uid://o5go6smk7hm1" path="res://person_add_alt_1-black-36dp.svg" id="4_op458"] [ext_resource type="Texture2D" uid="uid://o5go6smk7hm1" path="res://person_add_alt_1-black-36dp.svg" id="4_op458"]
[ext_resource type="Script" path="res://MusicListScrollContainer.gd" id="7_dj026"] [ext_resource type="Script" path="res://MusicListScrollContainer.gd" id="7_dj026"]
[ext_resource type="Script" path="res://PlayerNameField.gd" id="7_qsdfy"]
[ext_resource type="Theme" uid="uid://rxexo3ur85as" path="res://LightGrayTheme.tres" id="7_wxbv6"] [ext_resource type="Theme" uid="uid://rxexo3ur85as" path="res://LightGrayTheme.tres" id="7_wxbv6"]
[ext_resource type="PackedScene" uid="uid://bxydgil1yifps" path="res://SearchWindow.tscn" id="9_5ijvr"] [ext_resource type="PackedScene" uid="uid://bxydgil1yifps" path="res://SearchWindow.tscn" id="9_5ijvr"]
@@ -19,9 +20,18 @@ font_size = 50
[sub_resource type="LabelSettings" id="LabelSettings_3m52w"] [sub_resource type="LabelSettings" id="LabelSettings_3m52w"]
font_size = 35 font_size = 35
[sub_resource type="InputEventKey" id="InputEventKey_03bm3"]
device = -1
alt_pressed = true
keycode = 65
unicode = 63743
[sub_resource type="Shortcut" id="Shortcut_jafqj"]
events = [SubResource("InputEventKey_03bm3")]
[sub_resource type="InputEventKey" id="InputEventKey_ujjlu"] [sub_resource type="InputEventKey" id="InputEventKey_ujjlu"]
device = -1 device = -1
command_or_control_autoremap = true alt_pressed = true
keycode = 83 keycode = 83
[sub_resource type="Shortcut" id="Shortcut_fbju4"] [sub_resource type="Shortcut" id="Shortcut_fbju4"]
@@ -168,11 +178,36 @@ size_flags_horizontal = 3
text = "Players" text = "Players"
horizontal_alignment = 1 horizontal_alignment = 1
[node name="AddPlayer" type="TextureButton" parent="Players/VBoxContainer/HBoxContainer"] [node name="AddPlayersButton" type="TextureButton" parent="Players/VBoxContainer/HBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 8 size_flags_horizontal = 8
shortcut = SubResource("Shortcut_jafqj")
texture_normal = ExtResource("4_op458") texture_normal = ExtResource("4_op458")
[node name="AddPlayerContainer" type="HBoxContainer" parent="Players/VBoxContainer"]
visible = false
layout_mode = 2
[node name="Panel" type="Panel" parent="Players/VBoxContainer/AddPlayerContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 0
[node name="PlayerNameField" type="TextEdit" parent="Players/VBoxContainer/AddPlayerContainer"]
layout_mode = 2
size_flags_horizontal = 3
placeholder_text = "Player name"
script = ExtResource("7_qsdfy")
[node name="AddPlayerButton" type="Button" parent="Players/VBoxContainer/AddPlayerContainer"]
layout_mode = 2
text = "Add"
[node name="Panel2" type="Panel" parent="Players/VBoxContainer/AddPlayerContainer"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 0
[node name="ResetPlaylistButton" type="Button" parent="."] [node name="ResetPlaylistButton" type="Button" parent="."]
layout_mode = 0 layout_mode = 0
offset_left = 125.0 offset_left = 125.0
@@ -291,4 +326,47 @@ text = "Games synced!"
horizontal_alignment = 1 horizontal_alignment = 1
vertical_alignment = 1 vertical_alignment = 1
[node name="StatisticsPopupPanel" type="PopupPanel" parent="."]
initial_position = 2
size = Vector2i(450, 100)
[node name="Label" type="Label" parent="StatisticsPopupPanel"]
offset_left = 4.0
offset_top = 4.0
offset_right = 446.0
offset_bottom = 96.0
text = "Statistics"
horizontal_alignment = 1
[node name="StatisticsLabel" type="Label" parent="StatisticsPopupPanel"]
offset_left = 4.0
offset_top = 4.0
offset_right = 446.0
offset_bottom = 96.0
text = "Total amount of games in the playlist: 9000"
horizontal_alignment = 1
vertical_alignment = 1
[node name="AboutPopupPanel" type="PopupPanel" parent="."]
initial_position = 2
size = Vector2i(450, 100)
[node name="Label" type="Label" parent="AboutPopupPanel"]
offset_left = 4.0
offset_top = 4.0
offset_right = 446.0
offset_bottom = 96.0
text = "Music Player Randomizer v0.6"
horizontal_alignment = 1
[node name="AboutLabel" type="Label" parent="AboutPopupPanel"]
offset_left = 4.0
offset_top = 4.0
offset_right = 446.0
offset_bottom = 96.0
text = "Try your video game music knowledge with this VGM randomizer, invite your friends and see who is the best."
horizontal_alignment = 1
vertical_alignment = 1
autowrap_mode = 2
[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"]

View File

@@ -1,7 +1,7 @@
extends Control extends Control
@onready @onready
var player_name := $HBoxContainer/Name var player_name_field := $HBoxContainer/Name
@onready @onready
var points := $HBoxContainer/Points var points := $HBoxContainer/Points
@@ -16,28 +16,46 @@ var minus := $HBoxContainer/RemovePoint
var character := $HBoxContainer/Character var character := $HBoxContainer/Character
signal change_character_clicked signal change_character_clicked
signal first_point_triggerd
signal match_point_triggerd
signal winner_triggerd
var player_name: String
var is_first_point: bool = true
# Called when the node enters the scene tree for the first time. # Called when the node enters the scene tree for the first time.
func _ready(): func _ready():
print("_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_field.text = player_name
player_name.gui_input.connect(name_clicked)
func name_clicked(event): func new_name(new_name: String):
if (event is InputEventMouseButton && event.pressed && event.button_index == MOUSE_BUTTON_LEFT): player_name = new_name
print("Clicked: " + player_name.text)
func add_point(): func add_point():
var value := int(points.text) if is_first_point:
points.text = str(value + 1) is_first_point = false
first_point_triggerd.emit()
var new_value := int(points.text) + 1
points.text = str(new_value)
if new_value == Settings.winning_score - 1:
match_point_triggerd.emit()
if new_value == Settings.winning_score:
winner_triggerd.emit()
func minus_point(): func minus_point():
var value := int(points.text) var new_value := int(points.text) - 1
points.text = str(value - 1) points.text = str(new_value)
if new_value == 0:
is_first_point = true
func change_character(): func change_character():
print("change_character") print("change_character")

12
PlayerNameField.gd Normal file
View File

@@ -0,0 +1,12 @@
extends TextEdit
signal enter_key_pressed
signal close_pressed
func _input(event):
if event is InputEventKey and event.pressed:
if event.alt_pressed && event.keycode == KEY_A:
close_pressed.emit()
if event.keycode == KEY_ENTER:
enter_key_pressed.emit()

View File

@@ -21,6 +21,11 @@ func _ready():
close_button.pressed.connect(close) close_button.pressed.connect(close)
search_bar.grab_focus() search_bar.grab_focus()
search_bar.text_changed.connect(search) search_bar.text_changed.connect(search)
visibility_changed.connect(focus)
func focus():
if self.visible == true:
search_bar.grab_focus()
func close(): func close():
clear() clear()
@@ -47,7 +52,7 @@ func get_list_of_games() -> void:
http_request.request_completed.connect(self._http_request_completed) http_request.request_completed.connect(self._http_request_completed)
# Perform a GET request. The URL below returns JSON as of writing. # Perform a GET request. The URL below returns JSON as of writing.
var error = http_request.request("https://music.sanplex.tech/music/all/order") var error = http_request.request(Settings.default_path + "/music/all/order")
if error != OK: if error != OK:
push_error("An error occurred in the HTTP request.") push_error("An error occurred in the HTTP request.")

28
Settings.gd Normal file
View File

@@ -0,0 +1,28 @@
extends Node
#var default_path: String = "http://192.168.86.100:8085"
var default_path: String = "https://music.sanplex.tech"
var is_local: bool = false
var stop_after_current: bool = false
var hide_next_track: bool = false
var add_to_stats: bool = false
var use_low_played_mode: bool = false
var winning_score: int = 20
#play = X
#nästa = c
#visa svar = v
#lägga till poäng? 1, 2, 3, 4, 5, 6
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
pass

View File

@@ -16,6 +16,10 @@ config/features=PackedStringArray("4.1", "Forward Plus")
run/low_processor_mode=true run/low_processor_mode=true
config/icon="res://icon.svg" config/icon="res://icon.svg"
[autoload]
Settings="*res://Settings.gd"
[display] [display]
window/size/viewport_width=1920 window/size/viewport_width=1920