diff options
author | tpart <tpart120@proton.me> | 2024-09-21 23:24:38 +0200 |
---|---|---|
committer | tpart <tpart120@proton.me> | 2024-09-21 23:24:44 +0200 |
commit | 007cd84766a196d69bbfe6412d6eeab507861119 (patch) | |
tree | d0fafe3308261e3c40b79b26c414a6e57ae141d4 /client | |
parent | 14572c5cac2e16d10a29b1cf527037be7b72ab1c (diff) | |
download | hurrycurry-007cd84766a196d69bbfe6412d6eeab507861119.tar hurrycurry-007cd84766a196d69bbfe6412d6eeab507861119.tar.bz2 hurrycurry-007cd84766a196d69bbfe6412d6eeab507861119.tar.zst |
Add server list in play menu
Diffstat (limited to 'client')
-rw-r--r-- | client/global.gd | 2 | ||||
-rw-r--r-- | client/menu/play.gd | 31 | ||||
-rw-r--r-- | client/menu/play.tscn | 32 |
3 files changed, 60 insertions, 5 deletions
diff --git a/client/global.gd b/client/global.gd index 4a40264c..c3f1ef55 100644 --- a/client/global.gd +++ b/client/global.gd @@ -22,6 +22,8 @@ extends Node signal using_joypad_change(using: bool) signal using_touch_change(using: bool) +const VERSION := "2.0.0" + var default_profile := { "username": "Giovanni", "character": 0, diff --git a/client/menu/play.gd b/client/menu/play.gd index ee35975e..0bd13669 100644 --- a/client/menu/play.gd +++ b/client/menu/play.gd @@ -19,6 +19,9 @@ extends Menu var url_regex: RegEx = RegEx.new() +@onready var req: HTTPRequest = $HTTPRequest +@onready var server_list: VBoxContainer = $side/margin/options/second/ScrollContainerCustom/ServerList +@onready var server_list_loading: Label = $side/margin/options/second/Loading @onready var connect_uri = $side/margin/options/second/connect/uri @onready var server = $side/margin/options/second/server @onready var server_control = $side/margin/options/second/server/control @@ -31,6 +34,34 @@ func _ready(): server.hide() connect_uri.text = Global.get_profile("last_server_url") Sound.play_music("MainMenu") + update_server_list() + +func update_server_list(): + server_list_loading.visible = true + req.request_completed.connect(_on_request_completed) + req.request("https://hurrycurry-registry.metamuffin.org/v1/list", [ + "Accept: application/json", + "User-Agent: Hurry Curry! %s" % Global.VERSION + ]) + +func _on_request_completed(result: int, _response_code: int, _headers: PackedStringArray, body: PackedByteArray): + server_list_loading.visible = false + if result != 0: + push_warning("Fetching server list failed with code %d" % result) + return + var json = JSON.parse_string(body.get_string_from_utf8()) + if json == null: + push_error("Server list response invalid") + return + for c in server_list.get_children(): + c.queue_free() + for i in json: + var b := Button.new() + b.text_overrun_behavior = TextServer.OVERRUN_TRIM_WORD_ELLIPSIS + b.text = "%s (%d players)" % [i.name, i.players_online] + # TODO: Implement fallback address correctly + b.pressed.connect(connect_to.bind(i.address[0])) + server_list.add_child(b) func _menu_cover(state): $side.visible = not state diff --git a/client/menu/play.tscn b/client/menu/play.tscn index b91f7bda..8a705629 100644 --- a/client/menu/play.tscn +++ b/client/menu/play.tscn @@ -1,8 +1,9 @@ -[gd_scene load_steps=7 format=3 uid="uid://c8url5fpttbem"] +[gd_scene load_steps=8 format=3 uid="uid://c8url5fpttbem"] [ext_resource type="Theme" uid="uid://b0qmvo504e457" path="res://menu/theme/theme.tres" id="1_cckds"] [ext_resource type="Script" path="res://menu/play.gd" id="2_phxx0"] [ext_resource type="Material" uid="uid://2j8a0c0a2ta5" path="res://menu/theme/blur_material.tres" id="3_fsbt7"] +[ext_resource type="Script" path="res://menu/scroll_container_custom.gd" id="5_cm120"] [ext_resource type="FontFile" uid="uid://bo4vh5xkpvrh1" path="res://menu/theme/font-sansita-swashed.woff2" id="5_ojpbf"] [sub_resource type="StyleBoxFlat" id="StyleBoxFlat_ukani"] @@ -56,11 +57,28 @@ layout_mode = 2 [node name="second" type="VBoxContainer" parent="side/margin/options"] layout_mode = 2 +size_flags_vertical = 3 -[node name="quick_connect" type="Button" parent="side/margin/options/second"] +[node name="Loading" type="Label" parent="side/margin/options/second"] +visible = false +layout_mode = 2 +size_flags_horizontal = 3 +text = "Fetching server list..." +horizontal_alignment = 1 + +[node name="ScrollContainerCustom" type="ScrollContainer" parent="side/margin/options/second"] +layout_mode = 2 +size_flags_vertical = 3 +horizontal_scroll_mode = 0 +script = ExtResource("5_cm120") + +[node name="ServerList" type="VBoxContainer" parent="side/margin/options/second/ScrollContainerCustom"] +layout_mode = 2 +size_flags_horizontal = 3 + +[node name="spacer" type="Control" parent="side/margin/options/second"] +custom_minimum_size = Vector2(0, 10) layout_mode = 2 -text = "c.menu.play.quick_connect" -alignment = 0 [node name="connect" type="HBoxContainer" parent="side/margin/options/second"] layout_mode = 2 @@ -97,7 +115,11 @@ layout_mode = 2 text = "c.menu.back" alignment = 0 -[connection signal="pressed" from="side/margin/options/second/quick_connect" to="." method="_on_quick_connect_pressed"] +[node name="VBoxContainer" type="VBoxContainer" parent="side/margin/options/second"] +layout_mode = 2 + +[node name="HTTPRequest" type="HTTPRequest" parent="."] + [connection signal="text_changed" from="side/margin/options/second/connect/uri" to="." method="_on_uri_text_changed"] [connection signal="pressed" from="side/margin/options/second/connect/connect" to="." method="_on_connect_pressed"] [connection signal="pressed" from="side/margin/options/second/server/control" to="." method="_on_server_pressed"] |