Adding lobby list
This commit is contained in:
parent
d547d6260b
commit
0ba178da8a
@ -3,7 +3,7 @@
|
||||
[ext_resource type="Script" path="res://assets/core/networking/scripts/lobby.gd" id="1_o4fbq"]
|
||||
[ext_resource type="PackedScene" uid="uid://biryul3n6thlw" path="res://assets/core/networking/scenes/user_box_prefab.tscn" id="2_dpthk"]
|
||||
|
||||
[node name="Lobby" type="Control" node_paths=PackedStringArray("host_button", "leave_button", "start_button", "user_list_box")]
|
||||
[node name="Lobby" type="Control" node_paths=PackedStringArray("host_button", "leave_button", "start_button", "show_lobbies_button", "user_list_box", "lobby_list_box")]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
@ -14,7 +14,9 @@ script = ExtResource("1_o4fbq")
|
||||
host_button = NodePath("Panel/HBoxContainer/Buttons/Host")
|
||||
leave_button = NodePath("Panel/HBoxContainer/Buttons/Leave")
|
||||
start_button = NodePath("Panel/HBoxContainer/Buttons/Start")
|
||||
show_lobbies_button = NodePath("Panel/HBoxContainer/Buttons/ShowLobbies")
|
||||
user_list_box = NodePath("Panel/HBoxContainer/PlayerList")
|
||||
lobby_list_box = NodePath("Panel/HBoxContainer/LobbyList")
|
||||
user_box_prefab = ExtResource("2_dpthk")
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
@ -44,16 +46,25 @@ layout_mode = 2
|
||||
size_flags_vertical = 4
|
||||
text = "Host Lobby"
|
||||
|
||||
[node name="Leave" type="Button" parent="Panel/HBoxContainer/Buttons"]
|
||||
layout_mode = 2
|
||||
disabled = true
|
||||
text = "Leave Lobby"
|
||||
|
||||
[node name="Start" type="Button" parent="Panel/HBoxContainer/Buttons"]
|
||||
layout_mode = 2
|
||||
disabled = true
|
||||
text = "Start"
|
||||
|
||||
[node name="ShowLobbies" type="Button" parent="Panel/HBoxContainer/Buttons"]
|
||||
layout_mode = 2
|
||||
text = "Show Lobbies"
|
||||
|
||||
[node name="Leave" type="Button" parent="Panel/HBoxContainer/Buttons"]
|
||||
layout_mode = 2
|
||||
disabled = true
|
||||
text = "Leave Lobby"
|
||||
|
||||
[node name="PlayerList" type="VBoxContainer" parent="Panel/HBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 3
|
||||
|
||||
[node name="LobbyList" type="VBoxContainer" parent="Panel/HBoxContainer"]
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
|
@ -28,6 +28,7 @@ signal user_joined_lobby(user_id: int)
|
||||
signal user_left_lobby(user_id: int)
|
||||
signal host_left_lobby()
|
||||
signal on_game_started()
|
||||
signal on_lobbies_received(these_lobbies: Array)
|
||||
|
||||
signal property_update_received(node_id: int, property_name: String, value: Variant)
|
||||
|
||||
@ -143,8 +144,8 @@ func _on_lobby_joined(this_lobby_id: int, _permissions: int, _locked: bool, resp
|
||||
print("Failed to join this chat room: %s" % fail_reason)
|
||||
|
||||
|
||||
func _on_lobby_match_list():
|
||||
pass
|
||||
func _on_lobby_match_list(these_lobbies: Array) -> void:
|
||||
on_lobbies_received.emit(these_lobbies)
|
||||
|
||||
|
||||
func _on_lobby_message():
|
||||
@ -224,6 +225,12 @@ func leave_lobby():
|
||||
lobby_members.clear()
|
||||
print("Left lobby.")
|
||||
|
||||
|
||||
|
||||
func get_lobbies():
|
||||
Steam.addRequestLobbyListDistanceFilter(Steam.LOBBY_DISTANCE_FILTER_WORLDWIDE)
|
||||
Steam.requestLobbyList()
|
||||
|
||||
|
||||
func get_lobby_members():
|
||||
lobby_members.clear()
|
||||
|
@ -3,7 +3,9 @@ extends Control
|
||||
@export var host_button: Button
|
||||
@export var leave_button: Button
|
||||
@export var start_button: Button
|
||||
@export var show_lobbies_button: Button
|
||||
@export var user_list_box: VBoxContainer
|
||||
@export var lobby_list_box: VBoxContainer
|
||||
@export var user_box_prefab: PackedScene
|
||||
|
||||
var added_users = []
|
||||
@ -19,8 +21,9 @@ func _ready() -> void:
|
||||
NetworkManager.user_joined_lobby.connect(_on_user_joined_lobby)
|
||||
NetworkManager.user_left_lobby.connect(_on_user_left_lobby)
|
||||
NetworkManager.on_game_started.connect(_on_game_started)
|
||||
NetworkManager.lobbies_received.connect(_on_lobbies_received)
|
||||
|
||||
GameConsole.register_command(Command.new("update", update, [], "Updates the lobby UI"))
|
||||
GameConsole.register_command(Command.new("update", update_ui, [], "Updates the lobby UI"))
|
||||
|
||||
|
||||
func _on_host():
|
||||
@ -29,9 +32,32 @@ func _on_host():
|
||||
|
||||
func _on_leave():
|
||||
NetworkManager.leave_lobby()
|
||||
added_users.clear()
|
||||
for child in user_list_box.get_children():
|
||||
child.queue_free()
|
||||
reset_ui()
|
||||
|
||||
|
||||
func _on_show_lobbies():
|
||||
NetworkManager.get_lobbies()
|
||||
|
||||
|
||||
func _on_lobbies_received(these_lobbies: Array):
|
||||
lobby_list_box.visible = true
|
||||
for this_lobby in these_lobbies:
|
||||
# Pull lobby data from Steam, these are specific to our example
|
||||
var lobby_name: String = Steam.getLobbyData(this_lobby, "name")
|
||||
var lobby_mode: String = Steam.getLobbyData(this_lobby, "mode")
|
||||
|
||||
# Get the current number of members
|
||||
var lobby_num_members: int = Steam.getNumLobbyMembers(this_lobby)
|
||||
|
||||
# Create a button for the lobby
|
||||
var lobby_button: Button = Button.new()
|
||||
lobby_button.set_text("Lobby %s: %s [%s] - %s Player(s)" % [this_lobby, lobby_name, lobby_mode, lobby_num_members])
|
||||
lobby_button.set_size(Vector2(800, 50))
|
||||
lobby_button.set_name("lobby_%s" % this_lobby)
|
||||
lobby_button.connect("pressed", Callable(self, "join_lobby").bind(this_lobby))
|
||||
|
||||
# Add the new lobby to the list
|
||||
lobby_list_box.add_child(lobby_button)
|
||||
|
||||
|
||||
func _on_lobby_created(lobby_id: int):
|
||||
@ -39,23 +65,26 @@ func _on_lobby_created(lobby_id: int):
|
||||
host_button.disabled = true
|
||||
leave_button.disabled = false
|
||||
start_button.disabled = false
|
||||
user_list_box.visible = true
|
||||
|
||||
|
||||
func _on_lobby_joined(lobby_id: int):
|
||||
host_button.disabled = true
|
||||
leave_button.disabled = false
|
||||
user_list_box.visible = true
|
||||
lobby_list_box.visible = false
|
||||
|
||||
|
||||
func _on_user_joined_lobby(user_id: int):
|
||||
if user_id in added_users:
|
||||
return # User already added, skip
|
||||
added_users.append(user_id)
|
||||
update()
|
||||
update_ui()
|
||||
|
||||
|
||||
func _on_user_left_lobby(user_id: int):
|
||||
added_users.erase(user_id)
|
||||
update()
|
||||
update_ui()
|
||||
|
||||
|
||||
func _on_start():
|
||||
@ -67,7 +96,21 @@ func _on_game_started():
|
||||
visible = false
|
||||
|
||||
|
||||
func update() -> void:
|
||||
func reset_ui():
|
||||
host_button.disabled = false
|
||||
leave_button.disabled = true
|
||||
start_button.disabled = true
|
||||
user_list_box.visible = false
|
||||
lobby_list_box.visible = false
|
||||
added_users.clear()
|
||||
for child in user_list_box.get_children():
|
||||
child.queue_free()
|
||||
|
||||
for child in lobby_list_box.get_children():
|
||||
child.queue_free()
|
||||
|
||||
|
||||
func update_ui() -> void:
|
||||
for child in user_list_box.get_children():
|
||||
child.queue_free()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user