Added some buttons and added search view

This commit is contained in:
2023-09-02 23:14:19 +02:00
parent 1045bf2f9e
commit 90ce661982
4 changed files with 220 additions and 7 deletions

View File

@@ -1,5 +1,22 @@
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
# 10. Fix jump between songs
# 11. Refactor components
# 12. Change add player
# 13. Fix graphics in lists
# 14. Fix layout
# 15. Fix for local play
@onready
var open_button := $Open
@@ -57,6 +74,12 @@ var players := $Players/VBoxContainer
@onready
var character_select := $CharacterSelect
@onready
var search_button := $SearchButton
@onready
var search_view := $Search
var Player := preload("res://Player.tscn")
@onready
@@ -65,7 +88,7 @@ var path = '/Users/sebastian/ResilioSync/Sorterat_test/Metal Gear Solid 4 - Guns
func get_suggestion_list() -> void:
var http_request = HTTPRequest.new()
add_child(http_request)
http_request.request_completed.connect(self._http_request_completed)
http_request.request_completed.connect(_http_request_completed)
# Perform a GET request. The URL below returns JSON as of writing.
var error = http_request.request("https://music.sanplex.tech/music/all")
@@ -83,6 +106,7 @@ func _ready():
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)
@@ -93,6 +117,12 @@ func _ready():
open_button.pressed.connect(open)
get_suggestion_list()
func show_search():
if search_view.visible == false:
search_view.visible = true
else:
search_view.visible = false
func show_answer():
var http_request = HTTPRequest.new()
add_child(http_request)

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=11 format=3 uid="uid://xwq863o6uvsu"]
[gd_scene load_steps=15 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"]
@@ -8,6 +8,10 @@
[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="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"]
[sub_resource type="LabelSettings" id="LabelSettings_ychxr"]
font_size = 25
[sub_resource type="LabelSettings" id="LabelSettings_qspbu"]
font_size = 50
@@ -15,6 +19,14 @@ font_size = 50
[sub_resource type="LabelSettings" id="LabelSettings_3m52w"]
font_size = 35
[sub_resource type="InputEventKey" id="InputEventKey_ujjlu"]
device = -1
command_or_control_autoremap = true
keycode = 83
[sub_resource type="Shortcut" id="Shortcut_fbju4"]
events = [SubResource("InputEventKey_ujjlu")]
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 0
@@ -23,15 +35,17 @@ script = ExtResource("1_eu0t5")
[node name="TopPanelContainer" type="PanelContainer" parent="."]
layout_mode = 0
offset_right = 1920.0
offset_bottom = 52.0
offset_bottom = 56.0
[node name="HBoxContainer" type="HBoxContainer" parent="TopPanelContainer"]
layout_mode = 2
[node name="Label" type="Label" parent="TopPanelContainer/HBoxContainer"]
[node name="Title" type="Label" parent="."]
layout_mode = 2
offset_left = 32.0
offset_top = 8.0
offset_right = 337.0
offset_bottom = 46.0
size_flags_horizontal = 0
text = "Music Player Randomizer"
label_settings = SubResource("LabelSettings_ychxr")
[node name="Open" type="Button" parent="."]
layout_mode = 2
@@ -227,4 +241,45 @@ script = ExtResource("7_dj026")
[node name="MusicList" type="VBoxContainer" parent="MusicListPanel/ScrollContainer"]
layout_mode = 2
[node name="SearchButton" type="Button" parent="."]
layout_mode = 0
offset_left = 1528.0
offset_top = 8.0
offset_right = 1598.0
offset_bottom = 48.0
shortcut = SubResource("Shortcut_fbju4")
text = "Search"
[node name="SettingsButton" type="Button" parent="."]
layout_mode = 0
offset_left = 1624.0
offset_top = 8.0
offset_right = 1694.0
offset_bottom = 48.0
text = "Settings"
[node name="StatisticsButton" type="Button" parent="."]
layout_mode = 0
offset_left = 1720.0
offset_top = 8.0
offset_right = 1798.0
offset_bottom = 48.0
text = "Statistics"
[node name="AboutButton" type="Button" parent="."]
layout_mode = 0
offset_left = 1824.0
offset_top = 8.0
offset_right = 1894.0
offset_bottom = 48.0
text = "About"
[node name="Search" parent="." instance=ExtResource("9_5ijvr")]
visible = false
layout_mode = 1
offset_left = 349.196
offset_top = 81.2367
offset_right = 349.196
offset_bottom = 81.2367
[connection signal="dir_selected" from="FileDialog" to="." method="_on_file_dialog_dir_selected"]

73
SearchWindow.gd Normal file
View File

@@ -0,0 +1,73 @@
extends Control
@onready
var search_list := $ScrollContainer/VBoxContainer
@onready
var clear_button := $ClearButton
@onready
var close_button := $CloseButton
@onready
var search_bar := $Searchbar
var games := []
# Called when the node enters the scene tree for the first time.
func _ready():
get_list_of_games()
clear_button.pressed.connect(clear)
close_button.pressed.connect(close)
search_bar.grab_focus()
search_bar.text_changed.connect(search)
func close():
clear()
self.visible = false
func search():
print(search_bar.text)
delete_children(search_list)
for game in games:
if search_bar.text == "" || game.replace(" ", "").to_lower().contains(search_bar.text.replace(" ", "").to_lower()):
var label := Label.new()
label.text = game
label.autowrap_mode = TextServer.AUTOWRAP_WORD
search_list.add_child(label)
static func delete_children(node):
for n in node.get_children():
node.remove_child(n)
n.queue_free()
func get_list_of_games() -> void:
var http_request = HTTPRequest.new()
add_child(http_request)
http_request.request_completed.connect(self._http_request_completed)
# Perform a GET request. The URL below returns JSON as of writing.
var error = http_request.request("https://music.sanplex.tech/music/all/order")
if error != OK:
push_error("An error occurred in the HTTP request.")
# Called when the HTTP request is completed.
func _http_request_completed(result, response_code, headers, body):
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:
games.append_array(data_received)
for game in games:
var label := Label.new()
label.text = game
label.autowrap_mode = TextServer.AUTOWRAP_WORD
search_list.add_child(label)
else:
print("Unexpected data")
func clear():
search_bar.text = ""
search_bar.grab_focus()

55
SearchWindow.tscn Normal file
View File

@@ -0,0 +1,55 @@
[gd_scene load_steps=2 format=3 uid="uid://bxydgil1yifps"]
[ext_resource type="Script" path="res://SearchWindow.gd" id="1_m7bij"]
[node name="Control" type="Control"]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_m7bij")
[node name="Panel" type="Panel" parent="."]
layout_mode = 0
offset_right = 1152.0
offset_bottom = 640.0
[node name="ClearButton" type="Button" parent="."]
layout_mode = 0
offset_left = 880.0
offset_top = 24.0
offset_right = 944.0
offset_bottom = 64.0
scale = Vector2(2, 2)
text = "Clear"
[node name="CloseButton" type="Button" parent="."]
layout_mode = 2
offset_left = 1032.0
offset_top = 24.0
offset_right = 1082.0
offset_bottom = 64.0
scale = Vector2(2, 2)
text = "Close"
[node name="Searchbar" type="TextEdit" parent="."]
layout_mode = 0
offset_left = 64.0
offset_top = 24.0
offset_right = 448.0
offset_bottom = 64.0
scale = Vector2(2, 2)
placeholder_text = "Search"
[node name="ScrollContainer" type="ScrollContainer" parent="."]
layout_mode = 2
offset_top = 128.0
offset_right = 576.0
offset_bottom = 384.0
scale = Vector2(2, 2)
[node name="VBoxContainer" type="VBoxContainer" parent="ScrollContainer"]
layout_mode = 2
size_flags_horizontal = 3