Added shortcuts. Added dialog for winner. Started cleaning code.

This commit is contained in:
2023-09-11 21:20:48 +02:00
parent 724455b232
commit c5e6366760
5 changed files with 136 additions and 78 deletions

View File

@@ -1,16 +1,16 @@
extends Control extends Control
# 601 LOC 11/9 - 2023
##TODO ##TODO
# 2. Fix reset buttons # 2. Fix reset buttons
# 3. Fix settings # 3. Fix settings
# 9. Fix winner
# 11. Refactor components # 11. Refactor components
# 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
# 16. Change all calls to make_request and function in function # 16. Change all calls to make_request and function in function
# 17. Change some buttons to icons # 17. Change some buttons to icons
# 18. Fix shortcuts
@onready @onready
var open_button := $Open var open_button := $Open
@@ -117,9 +117,18 @@ var version_label := $AboutPopupPanel/VBoxContainer/VersionLabel
@onready @onready
var new_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/NewLabel var new_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/NewLabel
@onready
var shortcut_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/ShortcutsLabel
@onready @onready
var comming_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/CommingLabel var comming_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/CommingLabel
@onready
var winner_popup := $WinnerPopupPanel
@onready
var winner_label := $WinnerPopupPanel/WinnerLabel
var Player := preload("res://Player.tscn") var Player := preload("res://Player.tscn")
@onready @onready
@@ -153,6 +162,7 @@ func show_about():
about_popup.visible = true about_popup.visible = true
version_label.text = Settings.version version_label.text = Settings.version
new_label.text = Settings.whats_new new_label.text = Settings.whats_new
shortcut_label.text = Settings.shortcuts
comming_label.text = Settings.whats_left comming_label.text = Settings.whats_left
func show_settings(): func show_settings():
@@ -199,14 +209,18 @@ func games_synced(result, response_code, headers, body):
sync_popup.visible = true sync_popup.visible = true
func get_suggestion_list() -> void: func get_suggestion_list() -> void:
var http_request = HTTPRequest.new() var populate_list = func(array):
add_child(http_request) if typeof(array) == TYPE_ARRAY:
http_request.request_completed.connect(_http_request_completed) games.append_array(array)
for game in games:
# Perform a GET request. The URL below returns JSON as of writing. var label := Label.new()
var error = http_request.request(Settings.default_path + "/music/all") label.text = game
if error != OK: label.autowrap_mode = TextServer.AUTOWRAP_WORD
push_error("An error occurred in the HTTP request.") insperation_list.add_child(label)
insperation_scroll.scroll_to_bottom()
else:
print("Unexpected data")
Settings.make_request2("/music/all", populate_list)
func add_players(): func add_players():
add_player_container.visible = !add_player_container.visible add_player_container.visible = !add_player_container.visible
@@ -218,11 +232,11 @@ func add_player():
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("first_point_triggerd", _on_point_triggerd.bind("first", ""))
new_player.connect("match_point_triggerd", _on_point_triggerd.bind("match")) new_player.connect("match_point_triggerd", _on_point_triggerd.bind("match", ""))
new_player.connect("winner_triggerd", _on_point_triggerd.bind("winner")) new_player.connect("winner_triggerd", _on_point_triggerd.bind("winner", new_player.player_name))
func _on_point_triggerd(point: String): func _on_point_triggerd(point: String, name: String):
var song_path: String var song_path: String
if point == "first": if point == "first":
var value = randi_range(0, 10) var value = randi_range(0, 10)
@@ -236,9 +250,12 @@ func _on_point_triggerd(point: String):
song_path = "res://sounds/sound0.mp3" song_path = "res://sounds/sound0.mp3"
elif point == "winner": elif point == "winner":
song_path = "res://sounds/winning.mp3" song_path = "res://sounds/winning.mp3"
winner_popup.visible = true
winner_label.text = name + " won!!"
audio.stream = load_mp3(song_path) audio.stream = load_mp3(song_path)
audio.play() audio.play()
play_button.text = "Pause"
stream = audio.stream stream = audio.stream
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)
@@ -260,26 +277,22 @@ func show_answer():
push_error("An error occurred in the HTTP request.") push_error("An error occurred in the HTTP request.")
func fetch_full_music_list_at_start(): func fetch_full_music_list_at_start():
var show_fetched_list = func(result, response_code, headers, body): var show_fetched_list = func(data):
var json = JSON.new() if data == null: return
var error = json.parse(body.get_string_from_utf8()) if typeof(data) == TYPE_ARRAY:
song_list = []
if error == OK: song_list.append_array(data)
var data_received = json.get_data() for song in song_list:
if typeof(data_received) == TYPE_ARRAY: var label := Label.new()
song_list = [] var format_string = "%d. %s - %s"
song_list.append_array(data_received) var actual_string = format_string % [(song.SongNo+1), song.Game, song.Song]
for song in song_list: label.text = actual_string
var label := Label.new() label.mouse_filter = Control.MOUSE_FILTER_PASS
var format_string = "%d. %s - %s" label.gui_input.connect(song_clicked.bind(label, song.SongNo))
var actual_string = format_string % [(song.SongNo+1), song.Game, song.Song] music_list.add_child(label)
label.text = actual_string else:
label.mouse_filter = Control.MOUSE_FILTER_PASS print("Unexpected data")
label.gui_input.connect(song_clicked.bind(label, song.SongNo)) Settings.make_request2("/music/list", show_fetched_list)
music_list.add_child(label)
else:
print("Unexpected data")
make_request(Settings.default_path + "/music/list", show_fetched_list)
func fetch_full_music_list(event, song_no: int): func fetch_full_music_list(event, song_no: int):
if (event is InputEventMouseButton && event.pressed && event.button_index == MOUSE_BUTTON_LEFT): if (event is InputEventMouseButton && event.pressed && event.button_index == MOUSE_BUTTON_LEFT):
@@ -420,33 +433,10 @@ func song_clicked(event, label: Label, song_no: int):
song_label.text = data_received.Song song_label.text = data_received.Song
make_request(Settings.default_path + "/music/info", show_answer) make_request(Settings.default_path + "/music/info", show_answer)
# 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
insperation_list.add_child(label)
insperation_scroll.scroll_to_bottom()
else:
print("Unexpected data")
# Will print the user agent string used by the HTTPRequest node (as recognized by httpbin.org).
#print(response)
func open(): func open():
fileDialog.popup() fileDialog.popup()
# Called every frame. 'delta' is the elapsed time since the previous frame. # Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta): func _process(delta):
if audio.has_stream_playback() && !is_changing && !audio.stream_paused: if audio.has_stream_playback() && !is_changing && !audio.stream_paused:

View File

@@ -1,4 +1,4 @@
[gd_scene load_steps=19 format=3 uid="uid://xwq863o6uvsu"] [gd_scene load_steps=26 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"]
@@ -21,6 +21,15 @@ 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_n2hsq"]
device = -1
alt_pressed = true
keycode = 88
unicode = 8776
[sub_resource type="Shortcut" id="Shortcut_6mgjo"]
events = [SubResource("InputEventKey_n2hsq")]
[sub_resource type="InputEventKey" id="InputEventKey_03bm3"] [sub_resource type="InputEventKey" id="InputEventKey_03bm3"]
device = -1 device = -1
alt_pressed = true alt_pressed = true
@@ -30,6 +39,24 @@ unicode = 63743
[sub_resource type="Shortcut" id="Shortcut_jafqj"] [sub_resource type="Shortcut" id="Shortcut_jafqj"]
events = [SubResource("InputEventKey_03bm3")] events = [SubResource("InputEventKey_03bm3")]
[sub_resource type="InputEventKey" id="InputEventKey_06rl4"]
device = -1
alt_pressed = true
keycode = 86
unicode = 8249
[sub_resource type="Shortcut" id="Shortcut_a7fvb"]
events = [SubResource("InputEventKey_06rl4")]
[sub_resource type="InputEventKey" id="InputEventKey_7dnqw"]
device = -1
alt_pressed = true
keycode = 67
unicode = 231
[sub_resource type="Shortcut" id="Shortcut_d6fml"]
events = [SubResource("InputEventKey_7dnqw")]
[sub_resource type="InputEventKey" id="InputEventKey_ujjlu"] [sub_resource type="InputEventKey" id="InputEventKey_ujjlu"]
device = -1 device = -1
alt_pressed = true alt_pressed = true
@@ -38,6 +65,9 @@ keycode = 83
[sub_resource type="Shortcut" id="Shortcut_fbju4"] [sub_resource type="Shortcut" id="Shortcut_fbju4"]
events = [SubResource("InputEventKey_ujjlu")] events = [SubResource("InputEventKey_ujjlu")]
[sub_resource type="LabelSettings" id="LabelSettings_hr75l"]
font_size = 35
[node name="Control" type="Control"] [node name="Control" type="Control"]
layout_mode = 3 layout_mode = 3
anchors_preset = 0 anchors_preset = 0
@@ -125,6 +155,7 @@ size_flags_vertical = 4
[node name="PlayButton" type="Button" parent="PanelContainer/HBoxContainer"] [node name="PlayButton" type="Button" parent="PanelContainer/HBoxContainer"]
layout_mode = 2 layout_mode = 2
shortcut = SubResource("Shortcut_6mgjo")
text = "Play" text = "Play"
[node name="RestartButton" type="Button" parent="PanelContainer/HBoxContainer"] [node name="RestartButton" type="Button" parent="PanelContainer/HBoxContainer"]
@@ -237,6 +268,7 @@ offset_left = 611.0
offset_top = 1016.0 offset_top = 1016.0
offset_right = 722.0 offset_right = 722.0
offset_bottom = 1047.0 offset_bottom = 1047.0
shortcut = SubResource("Shortcut_a7fvb")
text = "Show answer" text = "Show answer"
[node name="NextButton" type="Button" parent="."] [node name="NextButton" type="Button" parent="."]
@@ -245,6 +277,7 @@ offset_left = 729.0
offset_top = 1017.0 offset_top = 1017.0
offset_right = 904.0 offset_right = 904.0
offset_bottom = 1048.0 offset_bottom = 1048.0
shortcut = SubResource("Shortcut_d6fml")
text = "Randomize new track" text = "Randomize new track"
[node name="MusicListPanel" type="PanelContainer" parent="."] [node name="MusicListPanel" type="PanelContainer" parent="."]
@@ -346,7 +379,7 @@ size = Vector2i(848, 272)
offset_left = 4.0 offset_left = 4.0
offset_top = 4.0 offset_top = 4.0
offset_right = 844.0 offset_right = 844.0
offset_bottom = 268.0 offset_bottom = 273.0
[node name="Label" type="Label" parent="AboutPopupPanel/VBoxContainer"] [node name="Label" type="Label" parent="AboutPopupPanel/VBoxContainer"]
layout_mode = 2 layout_mode = 2
@@ -373,6 +406,9 @@ size_flags_vertical = 0
text = "0.7-Beta: Can now hop between songs" text = "0.7-Beta: Can now hop between songs"
autowrap_mode = 2 autowrap_mode = 2
[node name="ShortcutsLabel" type="Label" parent="AboutPopupPanel/VBoxContainer/HBoxContainer"]
layout_mode = 2
[node name="CommingLabel" type="Label" parent="AboutPopupPanel/VBoxContainer/HBoxContainer"] [node name="CommingLabel" type="Label" parent="AboutPopupPanel/VBoxContainer/HBoxContainer"]
layout_mode = 2 layout_mode = 2
size_flags_horizontal = 3 size_flags_horizontal = 3
@@ -391,10 +427,23 @@ autowrap_mode = 2
initial_position = 2 initial_position = 2
size = Vector2i(268, 233) size = Vector2i(268, 233)
[node name="VBoxContainer" parent="SettingsPopupPanel" instance=ExtResource("11_k62u5")] [node name="SettingsWindow" parent="SettingsPopupPanel" instance=ExtResource("11_k62u5")]
offset_left = 4.0 offset_left = 4.0
offset_top = 4.0 offset_top = 4.0
offset_right = -4.0 offset_right = 264.0
offset_bottom = 19.0 offset_bottom = 252.0
[node name="WinnerPopupPanel" type="PopupPanel" parent="."]
initial_position = 2
size = Vector2i(350, 100)
[node name="WinnerLabel" type="Label" parent="WinnerPopupPanel"]
offset_left = 4.0
offset_top = 4.0
offset_right = 346.0
offset_bottom = 96.0
text = "Sansan won!!"
label_settings = SubResource("LabelSettings_hr75l")
horizontal_alignment = 1
[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

@@ -20,6 +20,7 @@ signal first_point_triggerd
signal match_point_triggerd signal match_point_triggerd
signal winner_triggerd signal winner_triggerd
@export
var player_name: String var player_name: String
var is_first_point: bool = true var is_first_point: bool = true

View File

@@ -13,17 +13,25 @@ var add_to_stats: bool = false
var use_low_played_mode: bool = false var use_low_played_mode: bool = false
var winning_score: int = 20 var winning_score: int = 20
var version: String = "0.7.5-Beta" var version: String = "0.7.8-Beta"
var whats_new: String = "0.7.5-Beta: Added settings menu, most things don't do anythig yet var whats_new: String = "Changelog:
0.7.8-Beta: Added shortcuts. Added dialog for winner. Started cleaning code.
0.7.5-Beta: Added settings menu, most things don't do anythig yet
0.7-Beta: Can now hop between songs" 0.7-Beta: Can now hop between songs"
var whats_left: String = "Fix reset buttons var whats_left: String = "Things left to do:
Fix reset buttons
Fix settings Fix settings
Fix winner
Fix graphics in lists Fix graphics in lists
Fix layout Fix layout
Fix for local play Fix for local play
Change some buttons to icons Change some buttons to icons"
Add shortcuts"
var shortcuts: String = "Shortcuts:
Alt + S = Search
Alt + A = Add Players
Alt + X = Play/Pause
Alt + C = Next Song
Alt + V = Show Answer"
#play = X #play = X
@@ -32,11 +40,21 @@ Add shortcuts"
#lägga till poäng? 1, 2, 3, 4, 5, 6 #lägga till poäng? 1, 2, 3, 4, 5, 6
# Called when the node enters the scene tree for the first time. func make_request2(address: String, func_name: Callable) -> void:
func _ready(): var error_handling = func(result, response_code, headers, body):
pass # Replace with function body. var json = JSON.new()
var error = json.parse(body.get_string_from_utf8())
if error == OK:
# Called every frame. 'delta' is the elapsed time since the previous frame. var data_received = json.get_data()
func _process(delta): print("data_received: ", data_received)
pass func_name.call(data_received)
var http_request = HTTPRequest.new()
add_child(http_request)
http_request.request_completed.connect(error_handling)
# Perform a GET request. The URL below returns JSON as of writing.
var error = http_request.request(default_path + address)
if error != OK:
push_error("An error occurred in the HTTP request.")

View File

@@ -8,7 +8,7 @@ custom_features=""
export_filter="all_resources" export_filter="all_resources"
include_filter="" include_filter=""
exclude_filter="" exclude_filter=""
export_path="./MusicPlayer_0.7.5_Beta.exe" export_path="../../ResilioSync/Sorterat/MusicPlayer_0.7.8_Beta.exe"
encryption_include_filters="" encryption_include_filters=""
encryption_exclude_filters="" encryption_exclude_filters=""
encrypt_pck=false encrypt_pck=false
@@ -18,7 +18,7 @@ encrypt_directory=false
custom_template/debug="" custom_template/debug=""
custom_template/release="" custom_template/release=""
debug/export_console_wrapper=1 debug/export_console_wrapper=0
binary_format/embed_pck=true binary_format/embed_pck=true
texture_format/bptc=true texture_format/bptc=true
texture_format/s3tc=true texture_format/s3tc=true