From 3fabf459850d29be41d5e9fda6aa8a5db59c667a Mon Sep 17 00:00:00 2001 From: Sebastian Date: Fri, 1 Sep 2023 22:12:24 +0200 Subject: [PATCH] Added functionallity to some buttons. Hides answer from start. Updated song que list. --- MainWindow.gd | 34 +++++++++++++++++++++++++++++----- MainWindow.tscn | 17 ++++++++++------- ScrollContainer.gd | 18 ++++++++++++++++++ 3 files changed, 57 insertions(+), 12 deletions(-) create mode 100644 ScrollContainer.gd diff --git a/MainWindow.gd b/MainWindow.gd index d5919fe..58be910 100644 --- a/MainWindow.gd +++ b/MainWindow.gd @@ -37,7 +37,13 @@ var label := $PanelContainer/HBoxContainer/Label var add_player := $Players/VBoxContainer/HBoxContainer/AddPlayer @onready -var test := $Button4 +var show_answer_button := $ShowAnswerButton + +@onready +var next_button := $NextButton + +@onready +var music_list_scroll := $MusicListPanel/ScrollContainer @onready var music_list := $MusicListPanel/ScrollContainer/MusicList @@ -70,9 +76,11 @@ func add_players(): # Called when the node enters the scene tree for the first time. func _ready(): - play_button.pressed.connect(fetch_first_song) + next_button.pressed.connect(fetch_first_song) pause_button.pressed.connect(pause) stop_button.pressed.connect(stop) + show_answer_button.pressed.connect(show_answer) + progress.drag_started.connect(_on_drag_started) progress.drag_ended.connect(_on_drag_ended) character_select.connect("character_selected", _on_character_selected) @@ -82,8 +90,7 @@ func _ready(): open_button.pressed.connect(open) get_suggestion_list() - -func fetched(): +func show_answer(): var http_request = HTTPRequest.new() add_child(http_request) http_request.request_completed.connect(show_fetched) @@ -93,6 +100,7 @@ func fetched(): if error != OK: push_error("An error occurred in the HTTP request.") +func fetched(): var http_request2 = HTTPRequest.new() add_child(http_request2) http_request2.request_completed.connect(show_fetched_list) @@ -124,15 +132,28 @@ func show_fetched_list(result, response_code, headers, body) -> void: song_list = [] song_list.append_array(data_received) delete_children(music_list) + song_list.remove_at(song_list.size() - 1) 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 + label.mouse_filter = Control.MOUSE_FILTER_PASS + label.gui_input.connect(song_clicked.bind(song.SongNo)) music_list.add_child(label) + + var label := Label.new() + label.text = "??? - ???" + label.mouse_filter = Control.MOUSE_FILTER_PASS + label.gui_input.connect(show_fetched) + music_list.add_child(label) + else: print("Unexpected data") - #/music_list + +func song_clicked(event, song_no): + if (event is InputEventMouseButton && event.pressed && event.button_index == 1): + print("Clicked: " + str(song_no)) # Called when the HTTP request is completed. func _http_request_completed(result, response_code, headers, body): @@ -241,6 +262,9 @@ func fetch_first_song() -> void: 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 = "??????" + if result != HTTPRequest.RESULT_SUCCESS: push_error("Song couldn't be downloaded. Try a different song.") var sound = AudioStreamMP3.new() diff --git a/MainWindow.tscn b/MainWindow.tscn index 068c560..11a9521 100644 --- a/MainWindow.tscn +++ b/MainWindow.tscn @@ -1,10 +1,11 @@ -[gd_scene load_steps=8 format=3 uid="uid://xwq863o6uvsu"] +[gd_scene load_steps=9 format=3 uid="uid://xwq863o6uvsu"] [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://w400rnew7453" path="res://volume_slider.tscn" id="3_rxhba"] [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="Script" path="res://ScrollContainer.gd" id="6_7b4jh"] [sub_resource type="LabelSettings" id="LabelSettings_qspbu"] font_size = 70 @@ -145,7 +146,7 @@ layout_mode = 2 size_flags_horizontal = 8 texture_normal = ExtResource("4_op458") -[node name="Button" type="Button" parent="."] +[node name="ResetPlaylistButton" type="Button" parent="."] layout_mode = 0 offset_left = 125.0 offset_top = 1017.0 @@ -153,7 +154,7 @@ offset_right = 236.0 offset_bottom = 1048.0 text = "Reset playlist" -[node name="Button2" type="Button" parent="."] +[node name="ResetPointsButton" type="Button" parent="."] layout_mode = 0 offset_left = 247.0 offset_top = 1018.0 @@ -161,7 +162,7 @@ offset_right = 358.0 offset_bottom = 1049.0 text = "Reset points" -[node name="Button3" type="Button" parent="."] +[node name="SuncButton" type="Button" parent="."] layout_mode = 0 offset_left = 370.0 offset_top = 1016.0 @@ -169,7 +170,7 @@ offset_right = 481.0 offset_bottom = 1047.0 text = "Sync games" -[node name="Button4" type="Button" parent="."] +[node name="SoundTestButton" type="Button" parent="."] layout_mode = 0 offset_left = 491.0 offset_top = 1016.0 @@ -177,7 +178,7 @@ offset_right = 602.0 offset_bottom = 1047.0 text = "Sound test" -[node name="Button5" type="Button" parent="."] +[node name="ShowAnswerButton" type="Button" parent="."] layout_mode = 0 offset_left = 611.0 offset_top = 1016.0 @@ -185,7 +186,7 @@ offset_right = 722.0 offset_bottom = 1047.0 text = "Show answer" -[node name="Button6" type="Button" parent="."] +[node name="NextButton" type="Button" parent="."] layout_mode = 0 offset_left = 729.0 offset_top = 1017.0 @@ -202,6 +203,8 @@ offset_bottom = 845.0 [node name="ScrollContainer" type="ScrollContainer" parent="MusicListPanel"] layout_mode = 2 +follow_focus = true +script = ExtResource("6_7b4jh") [node name="MusicList" type="VBoxContainer" parent="MusicListPanel/ScrollContainer"] layout_mode = 2 diff --git a/ScrollContainer.gd b/ScrollContainer.gd new file mode 100644 index 0000000..bc95426 --- /dev/null +++ b/ScrollContainer.gd @@ -0,0 +1,18 @@ +extends ScrollContainer + +var max = 0; + +# Called when the node enters the scene tree for the first time. +func _ready(): + pass # Replace with function body. + +func _draw(): + if max != self.get_v_scroll_bar().max_value: + max = self.get_v_scroll_bar().max_value + self.scroll_vertical = max + + pass + +# Called every frame. 'delta' is the elapsed time since the previous frame. +func _process(delta): + pass