Photon Room List - Sort By & Filter

Options
Hello everyone.

So i've hit a snag and hoping to get some advice as i'm only a hobbist when it comes to coding.

I've currently setup up Playfab for authentication and Photon for my multiplayer servers. I've got the whole UI menu working great, I can create rooms with custom options for PvE and PvP, public or private servers etc. Now when it comes to showing the list of current servers I've got that working as I want as well BUT now comes the tricky part.

I want to be able to sort the list of rooms alphabetically by either name, game mode or server type. Optionally I want to be able to sort the rooms numerically by the amount of players in each room.

The other things I want to be able to do is then search the rooms by name.

Oh and to make things even more complicated I want to be able to then filter either by game mode, server type or full/not full rooms.

I've tried hunting for tutorials or hints everywhere but coming up short.

This is my UI;

https://ibb.co/c6dXCD7

As you can see im using a Scroll Rect with Prefabs for the list with each room being instantiated as a button so I can select and join that room.

My code so far is;

public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
base.OnRoomListUpdate(roomList);
int tempIndex;
foreach(RoomInfo room in roomList)
{
if(joinRoomListings != null)
{
tempIndex = joinRoomListings.FindIndex(ByName(room.Name));
}
else
{
tempIndex = -1;
}
if(tempIndex != -1)
{
joinRoomListings.RemoveAt(tempIndex);
Destroy(joinRoomPanel.GetChild(tempIndex).gameObject);
}
else
{
joinRoomListings.Add(room);
ListRoom(room);
}
}
}

public void RemoveRoomListings()
{
int i = 0;
while (joinRoomPanel.childCount != 0)
{
Destroy(joinRoomPanel.GetChild(i).gameObject);
i++;
}
}

static System.Predicate<RoomInfo> ByName(string name)
{
return delegate (RoomInfo room)
{
return room.Name == name;
};
}

public void ListRoom(RoomInfo room)
{
//if(room.IsOpen && room.IsVisible)
if ((string)room.CustomProperties["GameMode"] == "PvP")
{
GameObject tempListing = Instantiate(joinRoomPrefab, joinRoomPanel);
RoomButton tempButton = tempListing.GetComponent<RoomButton>();
tempButton.roomName = room.Name;
tempButton.gameMode = (string)room.CustomProperties["GameMode"];
tempButton.playerCount = room.PlayerCount + "/" + room.MaxPlayers;
tempButton.server = (string)room.CustomProperties["Server"];
tempButton.SetRoom();
}
}

public void FilterOptions()
{
Room.Name == Variable;
(string)room.CustomProperties["GameMode"] == "PvE"
(string)room.CustomProperties["GameMode"] == "PvP"
room.PlayerCount < room.MaxPlayers
room.PlayerCount == room.MaxPlayers
(string)room.CustomProperties["Server"] == "Public"
(string)room.CustomProperties["Server"] == "Private"
}

Any help, hints or tips etc would be appreciated on the most efficient way to do this.

Thanks all.

Comments

  • Tobias
    Options
    I would recommend to not put so much work into this.
    Let's say all this is working fine, you present users with (let's say) 100 rooms, which are all on the same server. Most will select a random top 10 room and be done with it. They want to play, not browse room names.
    So, we would suggest to use JoinRandomRoom() and some filters. Let the server find a suitable room, once the user selected some important values (which level, mode, etc).

    That aside, we can't really help here. The problem is how to sort and present a list of values. In the end, this is independent from Photon and you will probably get a better answer in generic development / UI forums.

    Sorry for forwarding you "somewhere". This is simply not our scope here.