Compare commits

...

3 Commits

View File

@ -43,24 +43,86 @@ func _on_show_lobbies():
func _on_lobbies_received(these_lobbies: Array): func _on_lobbies_received(these_lobbies: Array):
for this_lobby in these_lobbies: var friend_lobbies = get_lobbies_with_friends()
# 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 # Clear the lobby list box before adding new lobbies
var lobby_num_members: int = Steam.getNumLobbyMembers(this_lobby) for child in lobby_list_box.get_children():
child.queue_free()
# Create a button for the lobby if friend_lobbies.size() == 0:
var lobby_button: Button = Button.new() var no_lobbies_label = Label.new()
lobby_button.set_text("Lobby %s: %s [%s] - %s Player(s)" % [this_lobby, lobby_name, lobby_mode, lobby_num_members]) no_lobbies_label.text = "No lobbies available"
lobby_button.set_size(Vector2(800, 50)) lobby_list_box.add_child(no_lobbies_label)
lobby_button.set_name("lobby_%s" % this_lobby) else:
lobby_button.connect("pressed", Callable(self, "join_lobby").bind(this_lobby)) for lobby_id in friend_lobbies.keys():
# Pull lobby data from Steam, these are specific to our example
var lobby_name: String = Steam.getLobbyData(lobby_id, "name")
var lobby_mode: String = Steam.getLobbyData(lobby_id, "mode")
# Add the new lobby to the list # Get the current number of members
lobby_list_box.add_child(lobby_button) var lobby_num_members: int = Steam.getNumLobbyMembers(lobby_id)
# Create a button for the lobby
var lobby_button: Button = Button.new()
lobby_button.set_text(lobby_name + " " + str(lobby_num_members) + "/" + str(Steam.getLobbyMemberLimit(lobby_id)))
lobby_button.set_size(Vector2(800, 50))
lobby_button.set_name("lobby_%s" % lobby_id)
lobby_button.connect("pressed", Callable(self, "join_lobby").bind(lobby_id))
# Add the new lobby to the list
lobby_list_box.add_child(lobby_button)
func get_lobbies_with_friends() -> Dictionary:
var results: Dictionary = {}
for i in range(0, Steam.getFriendCount()):
var steam_id: int = Steam.getFriendByIndex(i, Steam.FRIEND_FLAG_IMMEDIATE)
var game_info: Dictionary = Steam.getFriendGamePlayed(steam_id)
if game_info.is_empty():
# This friend is not playing a game
continue
else:
# They are playing a game, check if it's the same game as ours
var app_id: int = game_info['id']
var lobby = game_info['lobby']
if app_id != Steam.getAppID() or lobby is String:
# Either not in this game, or not in a lobby
continue
if not results.has(lobby):
results[lobby] = []
results[lobby].append(steam_id)
return results
func get_friends_in_lobbies() -> Dictionary:
var results: Dictionary = {}
for i in range(0, Steam.getFriendCount()):
var steam_id: int = Steam.getFriendByIndex(i, Steam.FRIEND_FLAG_IMMEDIATE)
var game_info: Dictionary = Steam.getFriendGamePlayed(steam_id)
if game_info.is_empty():
# This friend is not playing a game
continue
else:
# They are playing a game, check if it's the same game as ours
var app_id: int = game_info['id']
var lobby = game_info['lobby']
if app_id != Steam.getAppID() or lobby is String:
# Either not in this game, or not in a lobby
continue
results[steam_id] = lobby
return results
func join_lobby(lobby_id: int): func join_lobby(lobby_id: int):