Added shortcuts. Added dialog for winner. Started cleaning code.
This commit is contained in:
104
MainWindow.gd
104
MainWindow.gd
@@ -1,16 +1,16 @@
|
||||
extends Control
|
||||
|
||||
# 601 LOC 11/9 - 2023
|
||||
|
||||
##TODO
|
||||
# 2. Fix reset buttons
|
||||
# 3. Fix settings
|
||||
# 9. Fix winner
|
||||
# 11. Refactor components
|
||||
# 13. Fix graphics in lists
|
||||
# 14. Fix layout
|
||||
# 15. Fix for local play
|
||||
# 16. Change all calls to make_request and function in function
|
||||
# 17. Change some buttons to icons
|
||||
# 18. Fix shortcuts
|
||||
|
||||
@onready
|
||||
var open_button := $Open
|
||||
@@ -117,9 +117,18 @@ var version_label := $AboutPopupPanel/VBoxContainer/VersionLabel
|
||||
@onready
|
||||
var new_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/NewLabel
|
||||
|
||||
@onready
|
||||
var shortcut_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/ShortcutsLabel
|
||||
|
||||
@onready
|
||||
var comming_label := $AboutPopupPanel/VBoxContainer/HBoxContainer/CommingLabel
|
||||
|
||||
@onready
|
||||
var winner_popup := $WinnerPopupPanel
|
||||
|
||||
@onready
|
||||
var winner_label := $WinnerPopupPanel/WinnerLabel
|
||||
|
||||
var Player := preload("res://Player.tscn")
|
||||
|
||||
@onready
|
||||
@@ -153,6 +162,7 @@ func show_about():
|
||||
about_popup.visible = true
|
||||
version_label.text = Settings.version
|
||||
new_label.text = Settings.whats_new
|
||||
shortcut_label.text = Settings.shortcuts
|
||||
comming_label.text = Settings.whats_left
|
||||
|
||||
func show_settings():
|
||||
@@ -199,14 +209,18 @@ func games_synced(result, response_code, headers, body):
|
||||
sync_popup.visible = true
|
||||
|
||||
func get_suggestion_list() -> void:
|
||||
var http_request = HTTPRequest.new()
|
||||
add_child(http_request)
|
||||
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(Settings.default_path + "/music/all")
|
||||
if error != OK:
|
||||
push_error("An error occurred in the HTTP request.")
|
||||
var populate_list = func(array):
|
||||
if typeof(array) == TYPE_ARRAY:
|
||||
games.append_array(array)
|
||||
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")
|
||||
Settings.make_request2("/music/all", populate_list)
|
||||
|
||||
func add_players():
|
||||
add_player_container.visible = !add_player_container.visible
|
||||
@@ -218,11 +232,11 @@ func add_player():
|
||||
new_player_name_field.text = ""
|
||||
players.add_child(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"))
|
||||
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", new_player.player_name))
|
||||
|
||||
func _on_point_triggerd(point: String):
|
||||
func _on_point_triggerd(point: String, name: String):
|
||||
var song_path: String
|
||||
if point == "first":
|
||||
var value = randi_range(0, 10)
|
||||
@@ -236,9 +250,12 @@ func _on_point_triggerd(point: String):
|
||||
song_path = "res://sounds/sound0.mp3"
|
||||
elif point == "winner":
|
||||
song_path = "res://sounds/winning.mp3"
|
||||
winner_popup.visible = true
|
||||
winner_label.text = name + " won!!"
|
||||
|
||||
audio.stream = load_mp3(song_path)
|
||||
audio.play()
|
||||
play_button.text = "Pause"
|
||||
stream = audio.stream
|
||||
progress.max_value = round(stream.get_length())
|
||||
progress.tick_count = round(stream.get_length() / 60)
|
||||
@@ -260,26 +277,22 @@ func show_answer():
|
||||
push_error("An error occurred in the HTTP request.")
|
||||
|
||||
func fetch_full_music_list_at_start():
|
||||
var show_fetched_list = func(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:
|
||||
song_list = []
|
||||
song_list.append_array(data_received)
|
||||
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(label, song.SongNo))
|
||||
music_list.add_child(label)
|
||||
else:
|
||||
print("Unexpected data")
|
||||
make_request(Settings.default_path + "/music/list", show_fetched_list)
|
||||
var show_fetched_list = func(data):
|
||||
if data == null: return
|
||||
if typeof(data) == TYPE_ARRAY:
|
||||
song_list = []
|
||||
song_list.append_array(data)
|
||||
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(label, song.SongNo))
|
||||
music_list.add_child(label)
|
||||
else:
|
||||
print("Unexpected data")
|
||||
Settings.make_request2("/music/list", show_fetched_list)
|
||||
|
||||
func fetch_full_music_list(event, song_no: int):
|
||||
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
|
||||
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():
|
||||
fileDialog.popup()
|
||||
|
||||
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta):
|
||||
if audio.has_stream_playback() && !is_changing && !audio.stream_paused:
|
||||
|
||||
@@ -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="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"]
|
||||
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"]
|
||||
device = -1
|
||||
alt_pressed = true
|
||||
@@ -30,6 +39,24 @@ unicode = 63743
|
||||
[sub_resource type="Shortcut" id="Shortcut_jafqj"]
|
||||
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"]
|
||||
device = -1
|
||||
alt_pressed = true
|
||||
@@ -38,6 +65,9 @@ keycode = 83
|
||||
[sub_resource type="Shortcut" id="Shortcut_fbju4"]
|
||||
events = [SubResource("InputEventKey_ujjlu")]
|
||||
|
||||
[sub_resource type="LabelSettings" id="LabelSettings_hr75l"]
|
||||
font_size = 35
|
||||
|
||||
[node name="Control" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 0
|
||||
@@ -125,6 +155,7 @@ size_flags_vertical = 4
|
||||
|
||||
[node name="PlayButton" type="Button" parent="PanelContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
shortcut = SubResource("Shortcut_6mgjo")
|
||||
text = "Play"
|
||||
|
||||
[node name="RestartButton" type="Button" parent="PanelContainer/HBoxContainer"]
|
||||
@@ -237,6 +268,7 @@ offset_left = 611.0
|
||||
offset_top = 1016.0
|
||||
offset_right = 722.0
|
||||
offset_bottom = 1047.0
|
||||
shortcut = SubResource("Shortcut_a7fvb")
|
||||
text = "Show answer"
|
||||
|
||||
[node name="NextButton" type="Button" parent="."]
|
||||
@@ -245,6 +277,7 @@ offset_left = 729.0
|
||||
offset_top = 1017.0
|
||||
offset_right = 904.0
|
||||
offset_bottom = 1048.0
|
||||
shortcut = SubResource("Shortcut_d6fml")
|
||||
text = "Randomize new track"
|
||||
|
||||
[node name="MusicListPanel" type="PanelContainer" parent="."]
|
||||
@@ -346,7 +379,7 @@ size = Vector2i(848, 272)
|
||||
offset_left = 4.0
|
||||
offset_top = 4.0
|
||||
offset_right = 844.0
|
||||
offset_bottom = 268.0
|
||||
offset_bottom = 273.0
|
||||
|
||||
[node name="Label" type="Label" parent="AboutPopupPanel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
@@ -373,6 +406,9 @@ size_flags_vertical = 0
|
||||
text = "0.7-Beta: Can now hop between songs"
|
||||
autowrap_mode = 2
|
||||
|
||||
[node name="ShortcutsLabel" type="Label" parent="AboutPopupPanel/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="CommingLabel" type="Label" parent="AboutPopupPanel/VBoxContainer/HBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
@@ -391,10 +427,23 @@ autowrap_mode = 2
|
||||
initial_position = 2
|
||||
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_top = 4.0
|
||||
offset_right = -4.0
|
||||
offset_bottom = 19.0
|
||||
offset_right = 264.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"]
|
||||
|
||||
@@ -20,6 +20,7 @@ signal first_point_triggerd
|
||||
signal match_point_triggerd
|
||||
signal winner_triggerd
|
||||
|
||||
@export
|
||||
var player_name: String
|
||||
|
||||
var is_first_point: bool = true
|
||||
|
||||
46
Settings.gd
46
Settings.gd
@@ -13,17 +13,25 @@ var add_to_stats: bool = false
|
||||
var use_low_played_mode: bool = false
|
||||
var winning_score: int = 20
|
||||
|
||||
var version: String = "0.7.5-Beta"
|
||||
var whats_new: String = "0.7.5-Beta: Added settings menu, most things don't do anythig yet
|
||||
var version: String = "0.7.8-Beta"
|
||||
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"
|
||||
var whats_left: String = "Fix reset buttons
|
||||
var whats_left: String = "Things left to do:
|
||||
Fix reset buttons
|
||||
Fix settings
|
||||
Fix winner
|
||||
Fix graphics in lists
|
||||
Fix layout
|
||||
Fix for local play
|
||||
Change some buttons to icons
|
||||
Add shortcuts"
|
||||
Change some buttons to icons"
|
||||
|
||||
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
|
||||
@@ -32,11 +40,21 @@ Add shortcuts"
|
||||
#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
|
||||
func make_request2(address: String, func_name: Callable) -> void:
|
||||
var error_handling = func(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()
|
||||
print("data_received: ", data_received)
|
||||
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.")
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ custom_features=""
|
||||
export_filter="all_resources"
|
||||
include_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_exclude_filters=""
|
||||
encrypt_pck=false
|
||||
@@ -18,7 +18,7 @@ encrypt_directory=false
|
||||
|
||||
custom_template/debug=""
|
||||
custom_template/release=""
|
||||
debug/export_console_wrapper=1
|
||||
debug/export_console_wrapper=0
|
||||
binary_format/embed_pck=true
|
||||
texture_format/bptc=true
|
||||
texture_format/s3tc=true
|
||||
|
||||
Reference in New Issue
Block a user