mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 09:42:54 +08:00
Refactor grouping logic
This commit is contained in:
parent
2b0c267cb9
commit
9482fc5b99
@ -1,23 +1,18 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Dashboard.Friends
|
||||
{
|
||||
public class FriendsBundle
|
||||
{
|
||||
public FriendsOnlineStatus Status { get; }
|
||||
|
||||
public int Count => Users.Count;
|
||||
public int Count { get; }
|
||||
|
||||
public List<User> Users { get; }
|
||||
|
||||
public FriendsBundle(FriendsOnlineStatus status, List<User> users)
|
||||
public FriendsBundle(FriendsOnlineStatus status, int count)
|
||||
{
|
||||
Status = status;
|
||||
Users = users;
|
||||
Count = count;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -172,13 +172,27 @@ namespace osu.Game.Overlays.Dashboard.Friends
|
||||
if (itemsPlaceholder.Any())
|
||||
loading.Show();
|
||||
|
||||
var usersInCurrentGroup = onlineStatusControl.Current.Value?.Users ?? new List<User>();
|
||||
|
||||
var sortedUsers = sortUsers(usersInCurrentGroup);
|
||||
var sortedUsers = sortUsers(getUsersInCurrentGroup());
|
||||
|
||||
LoadComponentAsync(createTable(sortedUsers), addContentToPlaceholder, (cancellationToken = new CancellationTokenSource()).Token);
|
||||
}
|
||||
|
||||
private List<User> getUsersInCurrentGroup()
|
||||
{
|
||||
switch (onlineStatusControl.Current.Value?.Status)
|
||||
{
|
||||
default:
|
||||
case FriendsOnlineStatus.All:
|
||||
return users;
|
||||
|
||||
case FriendsOnlineStatus.Offline:
|
||||
return users.Where(u => !u.IsOnline).ToList();
|
||||
|
||||
case FriendsOnlineStatus.Online:
|
||||
return users.Where(u => u.IsOnline).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
private void addContentToPlaceholder(Drawable content)
|
||||
{
|
||||
loading.Hide();
|
||||
|
@ -15,9 +15,12 @@ namespace osu.Game.Overlays.Dashboard.Friends
|
||||
{
|
||||
Clear();
|
||||
|
||||
AddItem(new FriendsBundle(FriendsOnlineStatus.All, users));
|
||||
AddItem(new FriendsBundle(FriendsOnlineStatus.Online, users.Where(u => u.IsOnline).ToList()));
|
||||
AddItem(new FriendsBundle(FriendsOnlineStatus.Offline, users.Where(u => !u.IsOnline).ToList()));
|
||||
var userCount = users.Count;
|
||||
var onlineUsersCount = users.Count(user => user.IsOnline);
|
||||
|
||||
AddItem(new FriendsBundle(FriendsOnlineStatus.All, userCount));
|
||||
AddItem(new FriendsBundle(FriendsOnlineStatus.Online, onlineUsersCount));
|
||||
AddItem(new FriendsBundle(FriendsOnlineStatus.Offline, userCount - onlineUsersCount));
|
||||
|
||||
Current.Value = Items.FirstOrDefault();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user