1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-08 05:12:55 +08:00

Make Populate() accept list of users

This commit is contained in:
Andrei Zavatski 2020-03-03 18:08:51 +03:00
parent 160d64eecf
commit 83dad93b6d
3 changed files with 36 additions and 5 deletions

View File

@ -3,11 +3,13 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using NUnit.Framework; using NUnit.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.Home.Friends; using osu.Game.Overlays.Home.Friends;
using osu.Game.Users;
namespace osu.Game.Tests.Visual.UserInterface namespace osu.Game.Tests.Visual.UserInterface
{ {
@ -41,12 +43,25 @@ namespace osu.Game.Tests.Visual.UserInterface
[Test] [Test]
public void Populate() public void Populate()
{ {
AddStep(@"Populate", () => control.Populate(new List<FriendsBundle> AddStep("Populate", () => control.Populate(new List<User>
{ {
new FriendsBundle(FriendsOnlineStatus.All, 100), new User
new FriendsBundle(FriendsOnlineStatus.Online, 50), {
new FriendsBundle(FriendsOnlineStatus.Offline, 50), IsOnline = true
},
new User
{
IsOnline = false
},
new User
{
IsOnline = false
}
})); }));
AddAssert("3 users", () => control.Items.FirstOrDefault(item => item.Status == FriendsOnlineStatus.All)?.Amount == 3);
AddAssert("1 online user", () => control.Items.FirstOrDefault(item => item.Status == FriendsOnlineStatus.Online)?.Amount == 1);
AddAssert("2 offline users", () => control.Items.FirstOrDefault(item => item.Status == FriendsOnlineStatus.Offline)?.Amount == 2);
} }
} }
} }

View File

@ -1,10 +1,26 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using System.Collections.Generic;
using System.Linq;
using osu.Game.Users;
namespace osu.Game.Overlays.Home.Friends namespace osu.Game.Overlays.Home.Friends
{ {
public class FriendsOnlineStatusControl : OverlayUpdateStreamControl<FriendsBundle> public class FriendsOnlineStatusControl : OverlayUpdateStreamControl<FriendsBundle>
{ {
protected override OverlayUpdateStreamItem<FriendsBundle> CreateStreamItem(FriendsBundle value) => new FriendsOnlineStatusItem(value); protected override OverlayUpdateStreamItem<FriendsBundle> CreateStreamItem(FriendsBundle value) => new FriendsOnlineStatusItem(value);
public void Populate(List<User> users)
{
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();
}
} }
} }

View File

@ -40,7 +40,7 @@ namespace osu.Game.Overlays
private FillFlowContainer<SpriteText> text; private FillFlowContainer<SpriteText> text;
private ExpandingBar expandingBar; private ExpandingBar expandingBar;
public OverlayUpdateStreamItem(T value) protected OverlayUpdateStreamItem(T value)
: base(value) : base(value)
{ {
} }