Compare commits
No commits in common. "defd05a826ccb6f10660a0e2d8be7699d4270e67" and "359e4554badf29dd36f43865a5a6901dfc98ef06" have entirely different histories.
defd05a826
...
359e4554ba
@ -43,87 +43,25 @@ func _on_show_lobbies():
|
|||||||
|
|
||||||
|
|
||||||
func _on_lobbies_received(these_lobbies: Array):
|
func _on_lobbies_received(these_lobbies: Array):
|
||||||
var friend_lobbies = get_lobbies_with_friends()
|
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")
|
||||||
|
|
||||||
# Clear the lobby list box before adding new lobbies
|
# Get the current number of members
|
||||||
for child in lobby_list_box.get_children():
|
var lobby_num_members: int = Steam.getNumLobbyMembers(this_lobby)
|
||||||
child.queue_free()
|
|
||||||
|
|
||||||
if friend_lobbies.size() == 0:
|
# Create a button for the lobby
|
||||||
var no_lobbies_label = Label.new()
|
var lobby_button: Button = Button.new()
|
||||||
no_lobbies_label.text = "No lobbies available"
|
lobby_button.set_text("Lobby %s: %s [%s] - %s Player(s)" % [this_lobby, lobby_name, lobby_mode, lobby_num_members])
|
||||||
lobby_list_box.add_child(no_lobbies_label)
|
lobby_button.set_size(Vector2(800, 50))
|
||||||
else:
|
lobby_button.set_name("lobby_%s" % this_lobby)
|
||||||
for lobby_id in friend_lobbies.keys():
|
lobby_button.connect("pressed", Callable(self, "join_lobby").bind(this_lobby))
|
||||||
# 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")
|
|
||||||
|
|
||||||
# Get the current number of members
|
# Add the new lobby to the list
|
||||||
var lobby_num_members: int = Steam.getNumLobbyMembers(lobby_id)
|
lobby_list_box.add_child(lobby_button)
|
||||||
|
|
||||||
# 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):
|
||||||
NetworkManager.join_lobby(lobby_id)
|
NetworkManager.join_lobby(lobby_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user