Only show friend lobbies
This commit is contained in:
parent
2d2f87df88
commit
a996951932
@ -43,23 +43,42 @@ func _on_show_lobbies():
|
||||
|
||||
|
||||
func _on_lobbies_received(these_lobbies: Array):
|
||||
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")
|
||||
var friend_count = Steam.getFriendCount()
|
||||
var friend_steam_ids = []
|
||||
for i in range(friend_count):
|
||||
friend_steam_ids.append(Steam.getFriendByIndex(i, Steam.FRIEND_FLAG_ALL))
|
||||
|
||||
# Get the current number of members
|
||||
var lobby_num_members: int = Steam.getNumLobbyMembers(this_lobby)
|
||||
var friend_lobbies = []
|
||||
for lobby in these_lobbies:
|
||||
if Steam.getLobbyOwner(lobby) in friend_steam_ids:
|
||||
friend_lobbies.append(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))
|
||||
# Clear the lobby list box before adding new lobbies
|
||||
for child in lobby_list_box.get_children():
|
||||
child.queue_free()
|
||||
|
||||
# Add the new lobby to the list
|
||||
lobby_list_box.add_child(lobby_button)
|
||||
if friend_lobbies.size() == 0:
|
||||
var no_lobbies_label = Label.new()
|
||||
no_lobbies_label.text = "No lobbies available"
|
||||
lobby_list_box.add_child(no_lobbies_label)
|
||||
else:
|
||||
for this_lobby in friend_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)
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user