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:
|
||||
|
||||
Reference in New Issue
Block a user