Added volume bar and song list and refactored character select

This commit is contained in:
2023-08-29 21:06:19 +02:00
parent a48fc04e3b
commit c15afc3dc5
8 changed files with 274 additions and 69 deletions

View File

@@ -10,13 +10,10 @@ var fileDialog := $FileDialog
var list := $ScrollContainer/VBoxContainer
@onready
var game_label := $GameLabel
var game_label := $VBoxContainer/GameLabel
@onready
var character_grid_container := $ScrollContainer2
@onready
var character_grid := $ScrollContainer2/GridContainer
var song_label := $VBoxContainer/SongLabel
@onready
var play_button := $PanelContainer/HBoxContainer/PlayButton
@@ -39,9 +36,18 @@ var label := $PanelContainer/HBoxContainer/Label
@onready
var add_player := $Players/VBoxContainer/HBoxContainer/AddPlayer
@onready
var test := $Button4
@onready
var music_list := $MusicListPanel/ScrollContainer/MusicList
@onready
var players := $Players/VBoxContainer
@onready
var character_select := $CharacterSelect
var Player := preload("res://Player.tscn")
@onready
@@ -69,35 +75,12 @@ func _ready():
stop_button.pressed.connect(stop)
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()
var characters := DirAccess.open("res://characters/")
if characters:
characters.list_dir_begin()
var file_name = characters.get_next()
while file_name != "":
if !file_name.ends_with(".import"):
var texture = load("res://characters/" + file_name)
var texture_btn := TextureButton.new()
character_grid.add_child(texture_btn)
texture_btn.custom_minimum_size = Vector2(80, 40)
texture_btn.ignore_texture_size = true
texture_btn.stretch_mode = TextureButton.STRETCH_KEEP_ASPECT
texture_btn.texture_normal = texture
texture_btn.pressed.connect(select_character.bind(file_name))
file_name = characters.get_next()
func fetched():
@@ -109,6 +92,16 @@ func fetched():
var error = http_request.request("https://music.sanplex.tech/music/info")
if error != OK:
push_error("An error occurred in the HTTP request.")
var http_request2 = HTTPRequest.new()
add_child(http_request2)
http_request2.request_completed.connect(show_fetched_list)
# Perform a GET request. The URL below returns JSON as of writing.
var error2 = http_request2.request("https://music.sanplex.tech/music/list")
if error2 != OK:
push_error("An error occurred in the HTTP request.")
func show_fetched(result, response_code, headers, body) -> void:
var json = JSON.new()
@@ -118,6 +111,28 @@ func show_fetched(result, response_code, headers, body) -> void:
var data_received = json.get_data()
print("data_received: ", data_received)
game_label.text = data_received.Game
song_label.text = data_received.Song
var song_list = []
func show_fetched_list(result, response_code, headers, body) -> void:
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()
var format_string = "%d. %s - %s"
var actual_string = format_string % [(song.SongNo+1), song.Game, song.Song]
label.text = actual_string
music_list.add_child(label)
else:
print("Unexpected data")
#/music_list
# Called when the HTTP request is completed.
func _http_request_completed(result, response_code, headers, body):
@@ -287,9 +302,15 @@ var current_player
func _on_player_change_character_clicked(new_player):
print("_on_player_change_character_clicked")
current_player = new_player
character_grid_container.visible = true
character_select.visible = true
func select_character(file_name: String):
print("select_character")
character_grid_container.visible = false
func _on_character_selected(file_name: String):
print("_on_character_selected")
character_select.visible = false
current_player._on_control_character_selected_clicked(file_name)
static func delete_children(node):
for n in node.get_children():
node.remove_child(n)
n.queue_free()