From 544dfe7dd39266a4e0c4906413fa3b26db161d10 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Mon, 16 Mar 2020 09:42:21 +0300 Subject: [PATCH 01/16] Implement FriendsLayout component --- .../Visual/Online/TestSceneFriendsLayout.cs | 80 ++++++ .../TestSceneFriendsOnlineStatusControl.cs | 12 +- .../UserInterface/TestSceneUserListToolbar.cs | 2 +- .../Online/API/Requests/GetFriendsRequest.cs | 4 +- .../API/Requests/Responses/APIFriend.cs | 14 + .../Friends/FriendsBundle.cs | 13 +- .../Dashboard/Friends/FriendsLayout.cs | 256 ++++++++++++++++++ .../Friends/FriendsOnlineStatusControl.cs | 15 +- .../Friends/FriendsOnlineStatusItem.cs | 2 +- .../Friends/UserListToolbar.cs | 2 +- .../Friends/UserSortTabControl.cs | 2 +- osu.Game/Overlays/SocialOverlay.cs | 2 +- 12 files changed, 379 insertions(+), 25 deletions(-) create mode 100644 osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs create mode 100644 osu.Game/Online/API/Requests/Responses/APIFriend.cs rename osu.Game/Overlays/{Home => Dashboard}/Friends/FriendsBundle.cs (55%) create mode 100644 osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs rename osu.Game/Overlays/{Home => Dashboard}/Friends/FriendsOnlineStatusControl.cs (70%) rename osu.Game/Overlays/{Home => Dashboard}/Friends/FriendsOnlineStatusItem.cs (96%) rename osu.Game/Overlays/{Home => Dashboard}/Friends/UserListToolbar.cs (96%) rename osu.Game/Overlays/{Home => Dashboard}/Friends/UserSortTabControl.cs (90%) diff --git a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs new file mode 100644 index 0000000000..0e9fafb1b6 --- /dev/null +++ b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs @@ -0,0 +1,80 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Graphics.Containers; +using osu.Game.Overlays.Dashboard.Friends; +using osu.Framework.Graphics; +using osu.Game.Users; +using osu.Game.Overlays; +using osu.Framework.Allocation; +using NUnit.Framework; +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Tests.Visual.Online +{ + public class TestSceneFriendsLayout : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(FriendsLayout), + typeof(FriendsOnlineStatusControl), + typeof(UserListToolbar) + }; + + [Cached] + private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); + + private FriendsLayout layout; + + [SetUp] + public void Setup() => Schedule(() => + { + Child = new BasicScrollContainer + { + RelativeSizeAxes = Axes.Both, + Child = layout = new FriendsLayout() + }; + }); + + [Test] + public void TestPopulate() + { + AddStep("Populate", () => layout.Users = getUsers()); + } + + private List getUsers() => new List + { + new APIFriend + { + Username = @"flyte", + Id = 3103765, + IsOnline = true, + CurrentModeRank = 1111, + Country = new Country { FlagName = @"JP" }, + CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg" + }, + new APIFriend + { + Username = @"peppy", + Id = 2, + IsOnline = false, + CurrentModeRank = 2222, + Country = new Country { FlagName = @"AU" }, + CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", + IsSupporter = true, + SupportLevel = 3, + }, + new APIFriend + { + Username = @"Evast", + Id = 8195163, + Country = new Country { FlagName = @"BY" }, + CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg", + IsOnline = false, + LastVisit = DateTimeOffset.Now + } + }; + } +} diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs index 0d841dfef1..8bdf3c5dc1 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs @@ -7,9 +7,9 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays; -using osu.Game.Overlays.Home.Friends; -using osu.Game.Users; +using osu.Game.Overlays.Dashboard.Friends; namespace osu.Game.Tests.Visual.UserInterface { @@ -39,17 +39,17 @@ namespace osu.Game.Tests.Visual.UserInterface [Test] public void Populate() { - AddStep("Populate", () => control.Populate(new List + AddStep("Populate", () => control.Populate(new List { - new User + new APIFriend { IsOnline = true }, - new User + new APIFriend { IsOnline = false }, - new User + new APIFriend { IsOnline = false } diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneUserListToolbar.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneUserListToolbar.cs index 02b8839922..1546972580 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneUserListToolbar.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneUserListToolbar.cs @@ -8,7 +8,7 @@ using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Game.Graphics.Sprites; using osu.Game.Overlays; -using osu.Game.Overlays.Home.Friends; +using osu.Game.Overlays.Dashboard.Friends; using osuTK; namespace osu.Game.Tests.Visual.UserInterface diff --git a/osu.Game/Online/API/Requests/GetFriendsRequest.cs b/osu.Game/Online/API/Requests/GetFriendsRequest.cs index 46890aa889..321f675aae 100644 --- a/osu.Game/Online/API/Requests/GetFriendsRequest.cs +++ b/osu.Game/Online/API/Requests/GetFriendsRequest.cs @@ -2,11 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using osu.Game.Users; +using osu.Game.Online.API.Requests.Responses; namespace osu.Game.Online.API.Requests { - public class GetFriendsRequest : APIRequest> + public class GetFriendsRequest : APIRequest> { protected override string Target => @"friends"; } diff --git a/osu.Game/Online/API/Requests/Responses/APIFriend.cs b/osu.Game/Online/API/Requests/Responses/APIFriend.cs new file mode 100644 index 0000000000..91fed28d44 --- /dev/null +++ b/osu.Game/Online/API/Requests/Responses/APIFriend.cs @@ -0,0 +1,14 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using Newtonsoft.Json; +using osu.Game.Users; + +namespace osu.Game.Online.API.Requests.Responses +{ + public class APIFriend : User + { + [JsonProperty(@"current_mode_rank")] + public int? CurrentModeRank; + } +} diff --git a/osu.Game/Overlays/Home/Friends/FriendsBundle.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs similarity index 55% rename from osu.Game/Overlays/Home/Friends/FriendsBundle.cs rename to osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs index 75d00dfef8..0062c49c91 100644 --- a/osu.Game/Overlays/Home/Friends/FriendsBundle.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs @@ -1,18 +1,23 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -namespace osu.Game.Overlays.Home.Friends +using System.Collections.Generic; +using osu.Game.Online.API.Requests.Responses; + +namespace osu.Game.Overlays.Dashboard.Friends { public class FriendsBundle { public FriendsOnlineStatus Status { get; } - public int Count { get; } + public int Count => Users.Count; - public FriendsBundle(FriendsOnlineStatus status, int count) + public List Users { get; } + + public FriendsBundle(FriendsOnlineStatus status, List users) { Status = status; - Count = count; + Users = users; } } diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs new file mode 100644 index 0000000000..55f394cb78 --- /dev/null +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -0,0 +1,256 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System.Collections.Generic; +using System.Linq; +using System.Threading; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Graphics.UserInterface; +using osu.Game.Online.API; +using osu.Game.Online.API.Requests; +using osu.Game.Online.API.Requests.Responses; +using osu.Game.Users; +using osuTK; + +namespace osu.Game.Overlays.Dashboard.Friends +{ + public class FriendsLayout : CompositeDrawable + { + private List users = new List(); + + public List Users + { + get => users; + set + { + users = value; + + usersLoaded = true; + + onlineStatusControl.Populate(value); + } + } + + [Resolved] + private IAPIProvider api { get; set; } + + private GetFriendsRequest request; + private CancellationTokenSource cancellationToken; + + private Drawable currentContent; + + private readonly Box background; + private readonly Box controlBackground; + private readonly FriendsOnlineStatusControl onlineStatusControl; + private readonly UserListToolbar userListToolbar; + private readonly Container itemsPlaceholder; + private readonly LoadingLayer loading; + + public FriendsLayout() + { + RelativeSizeAxes = Axes.X; + AutoSizeAxes = Axes.Y; + InternalChild = new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Children = new Drawable[] + { + new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Children = new Drawable[] + { + controlBackground = new Box + { + RelativeSizeAxes = Axes.Both + }, + new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Padding = new MarginPadding + { + Top = 20, + Horizontal = 45 + }, + Child = onlineStatusControl = new FriendsOnlineStatusControl(), + } + } + }, + new Container + { + Name = "User List", + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both + }, + new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Direction = FillDirection.Vertical, + Margin = new MarginPadding { Bottom = 20 }, + Children = new Drawable[] + { + new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Padding = new MarginPadding + { + Horizontal = 40, + Vertical = 20 + }, + Child = userListToolbar = new UserListToolbar + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + } + }, + new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Children = new Drawable[] + { + itemsPlaceholder = new Container + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Padding = new MarginPadding { Horizontal = 50 } + }, + loading = new LoadingLayer(itemsPlaceholder) + } + } + } + } + } + } + } + }; + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider) + { + background.Colour = colourProvider.Background4; + controlBackground.Colour = colourProvider.Background5; + } + + private bool usersLoaded; + + protected override void LoadComplete() + { + base.LoadComplete(); + + onlineStatusControl.Current.BindValueChanged(_ => recreatePanels()); + userListToolbar.DisplayStyle.BindValueChanged(_ => recreatePanels()); + userListToolbar.SortCriteria.BindValueChanged(_ => recreatePanels()); + + if (!api.IsLoggedIn) + return; + + request = new GetFriendsRequest(); + request.Success += response => Schedule(() => Users = response); + api.Queue(request); + } + + private void recreatePanels() + { + // Don't allow any changes until we have users loaded + if (!usersLoaded) + return; + + cancellationToken?.Cancel(); + + if (itemsPlaceholder.Any()) + loading.Show(); + + var groupedUsers = onlineStatusControl.Current.Value?.Users ?? new List(); + + var sortedUsers = sortUsers(groupedUsers); + + LoadComponentAsync(createTable(sortedUsers), addContentToPlaceholder, (cancellationToken = new CancellationTokenSource()).Token); + } + + private void addContentToPlaceholder(Drawable content) + { + loading.Hide(); + + var lastContent = currentContent; + + if (lastContent != null) + { + lastContent.FadeOut(100, Easing.OutQuint).Expire(); + lastContent.Delay(25).Schedule(() => lastContent.BypassAutoSizeAxes = Axes.Y); + } + + itemsPlaceholder.Add(currentContent = content); + currentContent.FadeIn(200, Easing.OutQuint); + } + + private FillFlowContainer createTable(List users) + { + var style = userListToolbar.DisplayStyle.Value; + + return new FillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Spacing = new Vector2(style == OverlayPanelDisplayStyle.Card ? 10 : 2), + Children = users.Select(u => createUserPanel(u, style)).ToList() + }; + } + + private UserPanel createUserPanel(User user, OverlayPanelDisplayStyle style) + { + switch (style) + { + default: + case OverlayPanelDisplayStyle.Card: + return new UserGridPanel(user).With(panel => + { + panel.Anchor = Anchor.TopCentre; + panel.Origin = Anchor.TopCentre; + panel.Width = 290; + }); + + case OverlayPanelDisplayStyle.List: + return new UserListPanel(user); + } + } + + private List sortUsers(List unsorted) + { + switch (userListToolbar.SortCriteria.Value) + { + default: + case UserSortCriteria.LastVisit: + return unsorted.OrderBy(u => u.LastVisit).Reverse().ToList(); + + case UserSortCriteria.Rank: + return unsorted.Where(u => u.CurrentModeRank.HasValue).OrderBy(u => u.CurrentModeRank).Concat(unsorted.Where(u => u.CurrentModeRank == null)).ToList(); + + case UserSortCriteria.Username: + return unsorted.OrderBy(u => u.Username).ToList(); + } + } + + protected override void Dispose(bool isDisposing) + { + request?.Cancel(); + cancellationToken?.Cancel(); + + base.Dispose(isDisposing); + } + } +} diff --git a/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs similarity index 70% rename from osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs rename to osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs index 196f01ab4a..2b716f228d 100644 --- a/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs @@ -3,22 +3,21 @@ using System.Collections.Generic; using System.Linq; -using osu.Game.Users; +using osu.Game.Online.API.Requests.Responses; -namespace osu.Game.Overlays.Home.Friends +namespace osu.Game.Overlays.Dashboard.Friends { public class FriendsOnlineStatusControl : OverlayStreamControl { protected override OverlayStreamItem CreateStreamItem(FriendsBundle value) => new FriendsOnlineStatusItem(value); - public void Populate(List users) + public void Populate(List users) { - var userCount = users.Count; - var onlineUsersCount = users.Count(user => user.IsOnline); + Clear(); - AddItem(new FriendsBundle(FriendsOnlineStatus.All, userCount)); - AddItem(new FriendsBundle(FriendsOnlineStatus.Online, onlineUsersCount)); - AddItem(new FriendsBundle(FriendsOnlineStatus.Offline, userCount - onlineUsersCount)); + 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())); Current.Value = Items.FirstOrDefault(); } diff --git a/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusItem.cs similarity index 96% rename from osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs rename to osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusItem.cs index d9b780ce46..eada9420ea 100644 --- a/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusItem.cs @@ -5,7 +5,7 @@ using System; using osu.Game.Graphics; using osuTK.Graphics; -namespace osu.Game.Overlays.Home.Friends +namespace osu.Game.Overlays.Dashboard.Friends { public class FriendsOnlineStatusItem : OverlayStreamItem { diff --git a/osu.Game/Overlays/Home/Friends/UserListToolbar.cs b/osu.Game/Overlays/Dashboard/Friends/UserListToolbar.cs similarity index 96% rename from osu.Game/Overlays/Home/Friends/UserListToolbar.cs rename to osu.Game/Overlays/Dashboard/Friends/UserListToolbar.cs index f7c5e9f4fd..fb4b938183 100644 --- a/osu.Game/Overlays/Home/Friends/UserListToolbar.cs +++ b/osu.Game/Overlays/Dashboard/Friends/UserListToolbar.cs @@ -6,7 +6,7 @@ using osu.Framework.Graphics.Containers; using osuTK; using osu.Framework.Bindables; -namespace osu.Game.Overlays.Home.Friends +namespace osu.Game.Overlays.Dashboard.Friends { public class UserListToolbar : CompositeDrawable { diff --git a/osu.Game/Overlays/Home/Friends/UserSortTabControl.cs b/osu.Game/Overlays/Dashboard/Friends/UserSortTabControl.cs similarity index 90% rename from osu.Game/Overlays/Home/Friends/UserSortTabControl.cs rename to osu.Game/Overlays/Dashboard/Friends/UserSortTabControl.cs index 2479fa4638..3a5f65212d 100644 --- a/osu.Game/Overlays/Home/Friends/UserSortTabControl.cs +++ b/osu.Game/Overlays/Dashboard/Friends/UserSortTabControl.cs @@ -3,7 +3,7 @@ using System.ComponentModel; -namespace osu.Game.Overlays.Home.Friends +namespace osu.Game.Overlays.Dashboard.Friends { public class UserSortTabControl : OverlaySortTabControl { diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index 02f7c9b0d3..ba572b0e78 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -120,7 +120,7 @@ namespace osu.Game.Overlays { case SocialTab.Friends: var friendRequest = new GetFriendsRequest(); // TODO filter arguments? - friendRequest.Success += users => Users = users.ToArray(); + friendRequest.Success += users => Users = users.Select(u => (User)u).ToArray(); API.Queue(getUsersRequest = friendRequest); break; From cc5833db80568e8e300dd434f4ad636c9582f573 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 01:36:48 +0300 Subject: [PATCH 02/16] Remove string prefixes in the test scene --- .../Visual/Online/TestSceneFriendsLayout.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs index 0e9fafb1b6..46f22073f2 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs @@ -48,30 +48,30 @@ namespace osu.Game.Tests.Visual.Online { new APIFriend { - Username = @"flyte", + Username = "flyte", Id = 3103765, IsOnline = true, CurrentModeRank = 1111, - Country = new Country { FlagName = @"JP" }, - CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c6.jpg" + Country = new Country { FlagName = "JP" }, + CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c6.jpg" }, new APIFriend { - Username = @"peppy", + Username = "peppy", Id = 2, IsOnline = false, CurrentModeRank = 2222, - Country = new Country { FlagName = @"AU" }, - CoverUrl = @"https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", + Country = new Country { FlagName = "AU" }, + CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg", IsSupporter = true, SupportLevel = 3, }, new APIFriend { - Username = @"Evast", + Username = "Evast", Id = 8195163, - Country = new Country { FlagName = @"BY" }, - CoverUrl = @"https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg", + Country = new Country { FlagName = "BY" }, + CoverUrl = "https://assets.ppy.sh/user-profile-covers/8195163/4a8e2ad5a02a2642b631438cfa6c6bd7e2f9db289be881cb27df18331f64144c.jpeg", IsOnline = false, LastVisit = DateTimeOffset.Now } From 6ec01a67af0d3d3a7af3db542e00dd69e725b008 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 01:38:45 +0300 Subject: [PATCH 03/16] Use cast in SocialOverlay --- osu.Game/Overlays/SocialOverlay.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index ba572b0e78..ff6f7de436 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -120,7 +120,7 @@ namespace osu.Game.Overlays { case SocialTab.Friends: var friendRequest = new GetFriendsRequest(); // TODO filter arguments? - friendRequest.Success += users => Users = users.Select(u => (User)u).ToArray(); + friendRequest.Success += users => Users = users.Cast().ToArray(); API.Queue(getUsersRequest = friendRequest); break; From 6a151b8e75a4bcc3ed48d2dfd6c8f2f2ddd393b1 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 01:50:19 +0300 Subject: [PATCH 04/16] Add online test --- .../Visual/Online/TestSceneFriendsLayout.cs | 18 ++++++++++++++++-- .../Dashboard/Friends/FriendsLayout.cs | 12 +++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs index 46f22073f2..90474e5178 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs @@ -11,6 +11,7 @@ using osu.Game.Overlays; using osu.Framework.Allocation; using NUnit.Framework; using osu.Game.Online.API.Requests.Responses; +using System.Linq; namespace osu.Game.Tests.Visual.Online { @@ -23,10 +24,12 @@ namespace osu.Game.Tests.Visual.Online typeof(UserListToolbar) }; + protected override bool UseOnlineAPI => true; + [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); - private FriendsLayout layout; + private TestFriendsLayout layout; [SetUp] public void Setup() => Schedule(() => @@ -34,10 +37,16 @@ namespace osu.Game.Tests.Visual.Online Child = new BasicScrollContainer { RelativeSizeAxes = Axes.Both, - Child = layout = new FriendsLayout() + Child = layout = new TestFriendsLayout() }; }); + [Test] + public void TestOnline() + { + AddUntilStep("Users loaded", () => layout?.StatusControl.Items.Any() ?? false); + } + [Test] public void TestPopulate() { @@ -76,5 +85,10 @@ namespace osu.Game.Tests.Visual.Online LastVisit = DateTimeOffset.Now } }; + + private class TestFriendsLayout : FriendsLayout + { + public FriendsOnlineStatusControl StatusControl => OnlineStatusControl; + } } } diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs index 55f394cb78..cd358bcf84 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -26,11 +26,13 @@ namespace osu.Game.Overlays.Dashboard.Friends get => users; set { + request?.Cancel(); + users = value; usersLoaded = true; - onlineStatusControl.Populate(value); + OnlineStatusControl.Populate(value); } } @@ -42,9 +44,9 @@ namespace osu.Game.Overlays.Dashboard.Friends private Drawable currentContent; + protected readonly FriendsOnlineStatusControl OnlineStatusControl; private readonly Box background; private readonly Box controlBackground; - private readonly FriendsOnlineStatusControl onlineStatusControl; private readonly UserListToolbar userListToolbar; private readonly Container itemsPlaceholder; private readonly LoadingLayer loading; @@ -78,7 +80,7 @@ namespace osu.Game.Overlays.Dashboard.Friends Top = 20, Horizontal = 45 }, - Child = onlineStatusControl = new FriendsOnlineStatusControl(), + Child = OnlineStatusControl = new FriendsOnlineStatusControl(), } } }, @@ -152,7 +154,7 @@ namespace osu.Game.Overlays.Dashboard.Friends { base.LoadComplete(); - onlineStatusControl.Current.BindValueChanged(_ => recreatePanels()); + OnlineStatusControl.Current.BindValueChanged(_ => recreatePanels()); userListToolbar.DisplayStyle.BindValueChanged(_ => recreatePanels()); userListToolbar.SortCriteria.BindValueChanged(_ => recreatePanels()); @@ -175,7 +177,7 @@ namespace osu.Game.Overlays.Dashboard.Friends if (itemsPlaceholder.Any()) loading.Show(); - var groupedUsers = onlineStatusControl.Current.Value?.Users ?? new List(); + var groupedUsers = OnlineStatusControl.Current.Value?.Users ?? new List(); var sortedUsers = sortUsers(groupedUsers); From da97a02e6660ef516762d9f0c742df3eb39f7247 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 01:53:53 +0300 Subject: [PATCH 05/16] Remove pointless flag --- osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs index cd358bcf84..1098fdee8f 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -30,8 +30,6 @@ namespace osu.Game.Overlays.Dashboard.Friends users = value; - usersLoaded = true; - OnlineStatusControl.Populate(value); } } @@ -148,8 +146,6 @@ namespace osu.Game.Overlays.Dashboard.Friends controlBackground.Colour = colourProvider.Background5; } - private bool usersLoaded; - protected override void LoadComplete() { base.LoadComplete(); @@ -168,8 +164,7 @@ namespace osu.Game.Overlays.Dashboard.Friends private void recreatePanels() { - // Don't allow any changes until we have users loaded - if (!usersLoaded) + if (!users.Any()) return; cancellationToken?.Cancel(); From bd84980aa61af03d6c398db2942d8d5998d049ab Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 01:56:10 +0300 Subject: [PATCH 06/16] Simplify order by last visit --- osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs index 1098fdee8f..1c56227521 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -232,7 +232,7 @@ namespace osu.Game.Overlays.Dashboard.Friends { default: case UserSortCriteria.LastVisit: - return unsorted.OrderBy(u => u.LastVisit).Reverse().ToList(); + return unsorted.OrderByDescending(u => u.LastVisit).ToList(); case UserSortCriteria.Rank: return unsorted.Where(u => u.CurrentModeRank.HasValue).OrderBy(u => u.CurrentModeRank).Concat(unsorted.Where(u => u.CurrentModeRank == null)).ToList(); From f816479ff8972c4e2fb139b55746b36432a05f34 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 02:03:57 +0300 Subject: [PATCH 07/16] Simplify order by rank --- osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs index 1c56227521..f069d3f384 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -235,7 +235,7 @@ namespace osu.Game.Overlays.Dashboard.Friends return unsorted.OrderByDescending(u => u.LastVisit).ToList(); case UserSortCriteria.Rank: - return unsorted.Where(u => u.CurrentModeRank.HasValue).OrderBy(u => u.CurrentModeRank).Concat(unsorted.Where(u => u.CurrentModeRank == null)).ToList(); + return unsorted.OrderByDescending(u => u.CurrentModeRank.HasValue).ThenBy(u => u.CurrentModeRank ?? 0).ToList(); case UserSortCriteria.Username: return unsorted.OrderBy(u => u.Username).ToList(); From d9d812a8fe09d7006c0e64bd20a79dd9f049efec Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 02:10:20 +0300 Subject: [PATCH 08/16] Fix status icon flash on first status change --- osu.Game/Users/UserPanel.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/osu.Game/Users/UserPanel.cs b/osu.Game/Users/UserPanel.cs index 289244cdc3..d5e6d5f13e 100644 --- a/osu.Game/Users/UserPanel.cs +++ b/osu.Game/Users/UserPanel.cs @@ -99,6 +99,9 @@ namespace osu.Game.Users { base.LoadComplete(); Status.TriggerChange(); + + // Colour should be applied immediately on first load. + statusIcon.FinishTransforms(); } protected override bool OnHover(HoverEvent e) From bf9c6f8a3b0f36f1fb984ddc7894cb00d2ec0a8d Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 02:19:03 +0300 Subject: [PATCH 09/16] Skip online test if user is not logged-in --- osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs index 90474e5178..788cbd82c9 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs @@ -12,6 +12,7 @@ using osu.Framework.Allocation; using NUnit.Framework; using osu.Game.Online.API.Requests.Responses; using System.Linq; +using osu.Game.Online.API; namespace osu.Game.Tests.Visual.Online { @@ -29,6 +30,9 @@ namespace osu.Game.Tests.Visual.Online [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); + [Resolved] + private IAPIProvider api { get; set; } + private TestFriendsLayout layout; [SetUp] @@ -44,7 +48,8 @@ namespace osu.Game.Tests.Visual.Online [Test] public void TestOnline() { - AddUntilStep("Users loaded", () => layout?.StatusControl.Items.Any() ?? false); + // Skip online test if user is not logged-in + AddUntilStep("Users loaded", () => !api.IsLoggedIn || (layout?.StatusControl.Items.Any() ?? false)); } [Test] From 4ac740b12baceb300e3c582e37804587568acb8c Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 08:51:54 +0300 Subject: [PATCH 10/16] Remove APIFriend --- .../Visual/Online/TestSceneFriendsLayout.cs | 9 ++++----- .../TestSceneFriendsOnlineStatusControl.cs | 10 +++++----- osu.Game/Online/API/Requests/GetFriendsRequest.cs | 4 ++-- .../Online/API/Requests/Responses/APIFriend.cs | 14 -------------- .../Overlays/Dashboard/Friends/FriendsBundle.cs | 6 +++--- .../Overlays/Dashboard/Friends/FriendsLayout.cs | 11 +++++------ .../Friends/FriendsOnlineStatusControl.cs | 4 ++-- osu.Game/Overlays/SocialOverlay.cs | 2 +- osu.Game/Users/User.cs | 3 +++ 9 files changed, 25 insertions(+), 38 deletions(-) delete mode 100644 osu.Game/Online/API/Requests/Responses/APIFriend.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs index 788cbd82c9..c6971a971d 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs @@ -10,7 +10,6 @@ using osu.Game.Users; using osu.Game.Overlays; using osu.Framework.Allocation; using NUnit.Framework; -using osu.Game.Online.API.Requests.Responses; using System.Linq; using osu.Game.Online.API; @@ -58,9 +57,9 @@ namespace osu.Game.Tests.Visual.Online AddStep("Populate", () => layout.Users = getUsers()); } - private List getUsers() => new List + private List getUsers() => new List { - new APIFriend + new User { Username = "flyte", Id = 3103765, @@ -69,7 +68,7 @@ namespace osu.Game.Tests.Visual.Online Country = new Country { FlagName = "JP" }, CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c6.jpg" }, - new APIFriend + new User { Username = "peppy", Id = 2, @@ -80,7 +79,7 @@ namespace osu.Game.Tests.Visual.Online IsSupporter = true, SupportLevel = 3, }, - new APIFriend + new User { Username = "Evast", Id = 8195163, diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs index 8bdf3c5dc1..d72818ed89 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs @@ -7,9 +7,9 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays; using osu.Game.Overlays.Dashboard.Friends; +using osu.Game.Users; namespace osu.Game.Tests.Visual.UserInterface { @@ -39,17 +39,17 @@ namespace osu.Game.Tests.Visual.UserInterface [Test] public void Populate() { - AddStep("Populate", () => control.Populate(new List + AddStep("Populate", () => control.Populate(new List { - new APIFriend + new User { IsOnline = true }, - new APIFriend + new User { IsOnline = false }, - new APIFriend + new User { IsOnline = false } diff --git a/osu.Game/Online/API/Requests/GetFriendsRequest.cs b/osu.Game/Online/API/Requests/GetFriendsRequest.cs index 321f675aae..46890aa889 100644 --- a/osu.Game/Online/API/Requests/GetFriendsRequest.cs +++ b/osu.Game/Online/API/Requests/GetFriendsRequest.cs @@ -2,11 +2,11 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using osu.Game.Online.API.Requests.Responses; +using osu.Game.Users; namespace osu.Game.Online.API.Requests { - public class GetFriendsRequest : APIRequest> + public class GetFriendsRequest : APIRequest> { protected override string Target => @"friends"; } diff --git a/osu.Game/Online/API/Requests/Responses/APIFriend.cs b/osu.Game/Online/API/Requests/Responses/APIFriend.cs deleted file mode 100644 index 91fed28d44..0000000000 --- a/osu.Game/Online/API/Requests/Responses/APIFriend.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. -// See the LICENCE file in the repository root for full licence text. - -using Newtonsoft.Json; -using osu.Game.Users; - -namespace osu.Game.Online.API.Requests.Responses -{ - public class APIFriend : User - { - [JsonProperty(@"current_mode_rank")] - public int? CurrentModeRank; - } -} diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs index 0062c49c91..772d9c67a0 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs @@ -2,7 +2,7 @@ // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; -using osu.Game.Online.API.Requests.Responses; +using osu.Game.Users; namespace osu.Game.Overlays.Dashboard.Friends { @@ -12,9 +12,9 @@ namespace osu.Game.Overlays.Dashboard.Friends public int Count => Users.Count; - public List Users { get; } + public List Users { get; } - public FriendsBundle(FriendsOnlineStatus status, List users) + public FriendsBundle(FriendsOnlineStatus status, List users) { Status = status; Users = users; diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs index f069d3f384..c02f07fe4a 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -11,7 +11,6 @@ using osu.Framework.Graphics.Shapes; using osu.Game.Graphics.UserInterface; using osu.Game.Online.API; using osu.Game.Online.API.Requests; -using osu.Game.Online.API.Requests.Responses; using osu.Game.Users; using osuTK; @@ -19,9 +18,9 @@ namespace osu.Game.Overlays.Dashboard.Friends { public class FriendsLayout : CompositeDrawable { - private List users = new List(); + private List users = new List(); - public List Users + public List Users { get => users; set @@ -172,7 +171,7 @@ namespace osu.Game.Overlays.Dashboard.Friends if (itemsPlaceholder.Any()) loading.Show(); - var groupedUsers = OnlineStatusControl.Current.Value?.Users ?? new List(); + var groupedUsers = OnlineStatusControl.Current.Value?.Users ?? new List(); var sortedUsers = sortUsers(groupedUsers); @@ -195,7 +194,7 @@ namespace osu.Game.Overlays.Dashboard.Friends currentContent.FadeIn(200, Easing.OutQuint); } - private FillFlowContainer createTable(List users) + private FillFlowContainer createTable(List users) { var style = userListToolbar.DisplayStyle.Value; @@ -226,7 +225,7 @@ namespace osu.Game.Overlays.Dashboard.Friends } } - private List sortUsers(List unsorted) + private List sortUsers(List unsorted) { switch (userListToolbar.SortCriteria.Value) { diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs index 2b716f228d..88035e0a34 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs @@ -3,7 +3,7 @@ using System.Collections.Generic; using System.Linq; -using osu.Game.Online.API.Requests.Responses; +using osu.Game.Users; namespace osu.Game.Overlays.Dashboard.Friends { @@ -11,7 +11,7 @@ namespace osu.Game.Overlays.Dashboard.Friends { protected override OverlayStreamItem CreateStreamItem(FriendsBundle value) => new FriendsOnlineStatusItem(value); - public void Populate(List users) + public void Populate(List users) { Clear(); diff --git a/osu.Game/Overlays/SocialOverlay.cs b/osu.Game/Overlays/SocialOverlay.cs index ff6f7de436..02f7c9b0d3 100644 --- a/osu.Game/Overlays/SocialOverlay.cs +++ b/osu.Game/Overlays/SocialOverlay.cs @@ -120,7 +120,7 @@ namespace osu.Game.Overlays { case SocialTab.Friends: var friendRequest = new GetFriendsRequest(); // TODO filter arguments? - friendRequest.Success += users => Users = users.Cast().ToArray(); + friendRequest.Success += users => Users = users.ToArray(); API.Queue(getUsersRequest = friendRequest); break; diff --git a/osu.Game/Users/User.cs b/osu.Game/Users/User.cs index d25c552160..2a6f7844a2 100644 --- a/osu.Game/Users/User.cs +++ b/osu.Game/Users/User.cs @@ -69,6 +69,9 @@ namespace osu.Game.Users [JsonProperty(@"support_level")] public int SupportLevel; + [JsonProperty(@"current_mode_rank")] + public int? CurrentModeRank; + [JsonProperty(@"is_gmt")] public bool IsGMT; From e951979a12ec05aadce4e4c0b68435d2a24f9f75 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 17 Mar 2020 22:34:46 +0300 Subject: [PATCH 11/16] Remove assert from online test --- .../Visual/Online/TestSceneFriendsLayout.cs | 18 +++++------------- .../Dashboard/Friends/FriendsLayout.cs | 10 +++++----- 2 files changed, 10 insertions(+), 18 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs index c6971a971d..e6b2a41c1c 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs @@ -10,7 +10,6 @@ using osu.Game.Users; using osu.Game.Overlays; using osu.Framework.Allocation; using NUnit.Framework; -using System.Linq; using osu.Game.Online.API; namespace osu.Game.Tests.Visual.Online @@ -32,7 +31,7 @@ namespace osu.Game.Tests.Visual.Online [Resolved] private IAPIProvider api { get; set; } - private TestFriendsLayout layout; + private FriendsLayout layout; [SetUp] public void Setup() => Schedule(() => @@ -40,21 +39,19 @@ namespace osu.Game.Tests.Visual.Online Child = new BasicScrollContainer { RelativeSizeAxes = Axes.Both, - Child = layout = new TestFriendsLayout() + Child = layout = new FriendsLayout() }; }); [Test] - public void TestOnline() + public void TestOffline() { - // Skip online test if user is not logged-in - AddUntilStep("Users loaded", () => !api.IsLoggedIn || (layout?.StatusControl.Items.Any() ?? false)); + AddStep("Populate", () => layout.Users = getUsers()); } [Test] - public void TestPopulate() + public void TestOnline() { - AddStep("Populate", () => layout.Users = getUsers()); } private List getUsers() => new List @@ -89,10 +86,5 @@ namespace osu.Game.Tests.Visual.Online LastVisit = DateTimeOffset.Now } }; - - private class TestFriendsLayout : FriendsLayout - { - public FriendsOnlineStatusControl StatusControl => OnlineStatusControl; - } } } diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs index c02f07fe4a..55a5081435 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -29,7 +29,7 @@ namespace osu.Game.Overlays.Dashboard.Friends users = value; - OnlineStatusControl.Populate(value); + onlineStatusControl.Populate(value); } } @@ -41,7 +41,7 @@ namespace osu.Game.Overlays.Dashboard.Friends private Drawable currentContent; - protected readonly FriendsOnlineStatusControl OnlineStatusControl; + private readonly FriendsOnlineStatusControl onlineStatusControl; private readonly Box background; private readonly Box controlBackground; private readonly UserListToolbar userListToolbar; @@ -77,7 +77,7 @@ namespace osu.Game.Overlays.Dashboard.Friends Top = 20, Horizontal = 45 }, - Child = OnlineStatusControl = new FriendsOnlineStatusControl(), + Child = onlineStatusControl = new FriendsOnlineStatusControl(), } } }, @@ -149,7 +149,7 @@ namespace osu.Game.Overlays.Dashboard.Friends { base.LoadComplete(); - OnlineStatusControl.Current.BindValueChanged(_ => recreatePanels()); + onlineStatusControl.Current.BindValueChanged(_ => recreatePanels()); userListToolbar.DisplayStyle.BindValueChanged(_ => recreatePanels()); userListToolbar.SortCriteria.BindValueChanged(_ => recreatePanels()); @@ -171,7 +171,7 @@ namespace osu.Game.Overlays.Dashboard.Friends if (itemsPlaceholder.Any()) loading.Show(); - var groupedUsers = OnlineStatusControl.Current.Value?.Users ?? new List(); + var groupedUsers = onlineStatusControl.Current.Value?.Users ?? new List(); var sortedUsers = sortUsers(groupedUsers); From d241f7c55fece40263c582e0dd6f89ceb3a60d2e Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sat, 21 Mar 2020 20:32:55 +0300 Subject: [PATCH 12/16] Better variable naming --- osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs index 55a5081435..c2f0917e29 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -171,9 +171,9 @@ namespace osu.Game.Overlays.Dashboard.Friends if (itemsPlaceholder.Any()) loading.Show(); - var groupedUsers = onlineStatusControl.Current.Value?.Users ?? new List(); + var usersInCurrentGroup = onlineStatusControl.Current.Value?.Users ?? new List(); - var sortedUsers = sortUsers(groupedUsers); + var sortedUsers = sortUsers(usersInCurrentGroup); LoadComponentAsync(createTable(sortedUsers), addContentToPlaceholder, (cancellationToken = new CancellationTokenSource()).Token); } From 2b0c267cb902a8c9667a7e6afba57fb351fb1deb Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sat, 21 Mar 2020 20:37:21 +0300 Subject: [PATCH 13/16] Expose Fetch method --- osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs | 5 +---- osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs | 5 +++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs index e6b2a41c1c..1d8238dd40 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs @@ -10,7 +10,6 @@ using osu.Game.Users; using osu.Game.Overlays; using osu.Framework.Allocation; using NUnit.Framework; -using osu.Game.Online.API; namespace osu.Game.Tests.Visual.Online { @@ -28,9 +27,6 @@ namespace osu.Game.Tests.Visual.Online [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); - [Resolved] - private IAPIProvider api { get; set; } - private FriendsLayout layout; [SetUp] @@ -52,6 +48,7 @@ namespace osu.Game.Tests.Visual.Online [Test] public void TestOnline() { + AddStep("Fetch online", () => layout?.Fetch()); } private List getUsers() => new List diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs index c2f0917e29..94c8230d8e 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -25,8 +25,6 @@ namespace osu.Game.Overlays.Dashboard.Friends get => users; set { - request?.Cancel(); - users = value; onlineStatusControl.Populate(value); @@ -152,7 +150,10 @@ namespace osu.Game.Overlays.Dashboard.Friends onlineStatusControl.Current.BindValueChanged(_ => recreatePanels()); userListToolbar.DisplayStyle.BindValueChanged(_ => recreatePanels()); userListToolbar.SortCriteria.BindValueChanged(_ => recreatePanels()); + } + public void Fetch() + { if (!api.IsLoggedIn) return; From 9482fc5b9990af7a53611539332e81cc1d5d79d5 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Sun, 22 Mar 2020 20:13:54 +0300 Subject: [PATCH 14/16] Refactor grouping logic --- .../Dashboard/Friends/FriendsBundle.cs | 11 +++------- .../Dashboard/Friends/FriendsLayout.cs | 20 ++++++++++++++++--- .../Friends/FriendsOnlineStatusControl.cs | 9 ++++++--- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs index 772d9c67a0..d5fad1ffd3 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs @@ -1,23 +1,18 @@ // Copyright (c) ppy Pty Ltd . 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 Users { get; } - - public FriendsBundle(FriendsOnlineStatus status, List users) + public FriendsBundle(FriendsOnlineStatus status, int count) { Status = status; - Users = users; + Count = count; } } diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs index 94c8230d8e..3514bf7ff7 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs @@ -172,13 +172,27 @@ namespace osu.Game.Overlays.Dashboard.Friends if (itemsPlaceholder.Any()) loading.Show(); - var usersInCurrentGroup = onlineStatusControl.Current.Value?.Users ?? new List(); - - var sortedUsers = sortUsers(usersInCurrentGroup); + var sortedUsers = sortUsers(getUsersInCurrentGroup()); LoadComponentAsync(createTable(sortedUsers), addContentToPlaceholder, (cancellationToken = new CancellationTokenSource()).Token); } + private List 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(); diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs index 88035e0a34..c54e9e2a06 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs @@ -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(); } From bfd643dd1659179186a5d26982b58bcbfcd3d5e9 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Mar 2020 10:47:27 +0900 Subject: [PATCH 15/16] Rename classes --- .../Visual/Online/TestSceneFriendsLayout.cs | 12 +++++------ .../TestSceneFriendsOnlineStatusControl.cs | 14 ++++++------- .../{FriendsLayout.cs => FriendDisplay.cs} | 20 +++++++++---------- ...ontrol.cs => FriendOnlineStreamControl.cs} | 10 +++++----- .../{FriendsBundle.cs => FriendStream.cs} | 13 +++--------- .../Friends/FriendsOnlineStatusItem.cs | 10 +++++----- .../Dashboard/Friends/OnlineStatus.cs | 12 +++++++++++ 7 files changed, 48 insertions(+), 43 deletions(-) rename osu.Game/Overlays/Dashboard/Friends/{FriendsLayout.cs => FriendDisplay.cs} (94%) rename osu.Game/Overlays/Dashboard/Friends/{FriendsOnlineStatusControl.cs => FriendOnlineStreamControl.cs} (53%) rename osu.Game/Overlays/Dashboard/Friends/{FriendsBundle.cs => FriendStream.cs} (57%) create mode 100644 osu.Game/Overlays/Dashboard/Friends/OnlineStatus.cs diff --git a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs index 1d8238dd40..c0a617fe57 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs @@ -17,8 +17,8 @@ namespace osu.Game.Tests.Visual.Online { public override IReadOnlyList RequiredTypes => new[] { - typeof(FriendsLayout), - typeof(FriendsOnlineStatusControl), + typeof(FriendDisplay), + typeof(FriendOnlineStreamControl), typeof(UserListToolbar) }; @@ -27,7 +27,7 @@ namespace osu.Game.Tests.Visual.Online [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Purple); - private FriendsLayout layout; + private FriendDisplay display; [SetUp] public void Setup() => Schedule(() => @@ -35,20 +35,20 @@ namespace osu.Game.Tests.Visual.Online Child = new BasicScrollContainer { RelativeSizeAxes = Axes.Both, - Child = layout = new FriendsLayout() + Child = display = new FriendDisplay() }; }); [Test] public void TestOffline() { - AddStep("Populate", () => layout.Users = getUsers()); + AddStep("Populate", () => display.Users = getUsers()); } [Test] public void TestOnline() { - AddStep("Fetch online", () => layout?.Fetch()); + AddStep("Fetch online", () => display?.Fetch()); } private List getUsers() => new List diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs index d72818ed89..f6dcf78d55 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs @@ -17,20 +17,20 @@ namespace osu.Game.Tests.Visual.UserInterface { public override IReadOnlyList RequiredTypes => new[] { - typeof(FriendsOnlineStatusControl), + typeof(FriendOnlineStreamControl), typeof(FriendsOnlineStatusItem), typeof(OverlayStreamControl<>), typeof(OverlayStreamItem<>), - typeof(FriendsBundle) + typeof(FriendStream) }; [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); - private FriendsOnlineStatusControl control; + private FriendOnlineStreamControl control; [SetUp] - public void SetUp() => Schedule(() => Child = control = new FriendsOnlineStatusControl + public void SetUp() => Schedule(() => Child = control = new FriendOnlineStreamControl { Anchor = Anchor.Centre, Origin = Anchor.Centre, @@ -55,9 +55,9 @@ namespace osu.Game.Tests.Visual.UserInterface } })); - AddAssert("3 users", () => control.Items.FirstOrDefault(item => item.Status == FriendsOnlineStatus.All)?.Count == 3); - AddAssert("1 online user", () => control.Items.FirstOrDefault(item => item.Status == FriendsOnlineStatus.Online)?.Count == 1); - AddAssert("2 offline users", () => control.Items.FirstOrDefault(item => item.Status == FriendsOnlineStatus.Offline)?.Count == 2); + AddAssert("3 users", () => control.Items.FirstOrDefault(item => item.Status == OnlineStatus.All)?.Count == 3); + AddAssert("1 online user", () => control.Items.FirstOrDefault(item => item.Status == OnlineStatus.Online)?.Count == 1); + AddAssert("2 offline users", () => control.Items.FirstOrDefault(item => item.Status == OnlineStatus.Offline)?.Count == 2); } } } diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs b/osu.Game/Overlays/Dashboard/Friends/FriendDisplay.cs similarity index 94% rename from osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs rename to osu.Game/Overlays/Dashboard/Friends/FriendDisplay.cs index 3514bf7ff7..3c9b31daae 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsLayout.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendDisplay.cs @@ -16,7 +16,7 @@ using osuTK; namespace osu.Game.Overlays.Dashboard.Friends { - public class FriendsLayout : CompositeDrawable + public class FriendDisplay : CompositeDrawable { private List users = new List(); @@ -27,7 +27,7 @@ namespace osu.Game.Overlays.Dashboard.Friends { users = value; - onlineStatusControl.Populate(value); + onlineStreamControl.Populate(value); } } @@ -39,14 +39,14 @@ namespace osu.Game.Overlays.Dashboard.Friends private Drawable currentContent; - private readonly FriendsOnlineStatusControl onlineStatusControl; + private readonly FriendOnlineStreamControl onlineStreamControl; private readonly Box background; private readonly Box controlBackground; private readonly UserListToolbar userListToolbar; private readonly Container itemsPlaceholder; private readonly LoadingLayer loading; - public FriendsLayout() + public FriendDisplay() { RelativeSizeAxes = Axes.X; AutoSizeAxes = Axes.Y; @@ -75,7 +75,7 @@ namespace osu.Game.Overlays.Dashboard.Friends Top = 20, Horizontal = 45 }, - Child = onlineStatusControl = new FriendsOnlineStatusControl(), + Child = onlineStreamControl = new FriendOnlineStreamControl(), } } }, @@ -147,7 +147,7 @@ namespace osu.Game.Overlays.Dashboard.Friends { base.LoadComplete(); - onlineStatusControl.Current.BindValueChanged(_ => recreatePanels()); + onlineStreamControl.Current.BindValueChanged(_ => recreatePanels()); userListToolbar.DisplayStyle.BindValueChanged(_ => recreatePanels()); userListToolbar.SortCriteria.BindValueChanged(_ => recreatePanels()); } @@ -179,16 +179,16 @@ namespace osu.Game.Overlays.Dashboard.Friends private List getUsersInCurrentGroup() { - switch (onlineStatusControl.Current.Value?.Status) + switch (onlineStreamControl.Current.Value?.Status) { default: - case FriendsOnlineStatus.All: + case OnlineStatus.All: return users; - case FriendsOnlineStatus.Offline: + case OnlineStatus.Offline: return users.Where(u => !u.IsOnline).ToList(); - case FriendsOnlineStatus.Online: + case OnlineStatus.Online: return users.Where(u => u.IsOnline).ToList(); } } diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs b/osu.Game/Overlays/Dashboard/Friends/FriendOnlineStreamControl.cs similarity index 53% rename from osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs rename to osu.Game/Overlays/Dashboard/Friends/FriendOnlineStreamControl.cs index c54e9e2a06..28546ceab8 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusControl.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendOnlineStreamControl.cs @@ -7,9 +7,9 @@ using osu.Game.Users; namespace osu.Game.Overlays.Dashboard.Friends { - public class FriendsOnlineStatusControl : OverlayStreamControl + public class FriendOnlineStreamControl : OverlayStreamControl { - protected override OverlayStreamItem CreateStreamItem(FriendsBundle value) => new FriendsOnlineStatusItem(value); + protected override OverlayStreamItem CreateStreamItem(FriendStream value) => new FriendsOnlineStatusItem(value); public void Populate(List users) { @@ -18,9 +18,9 @@ namespace osu.Game.Overlays.Dashboard.Friends 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)); + AddItem(new FriendStream(OnlineStatus.All, userCount)); + AddItem(new FriendStream(OnlineStatus.Online, onlineUsersCount)); + AddItem(new FriendStream(OnlineStatus.Offline, userCount - onlineUsersCount)); Current.Value = Items.FirstOrDefault(); } diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs b/osu.Game/Overlays/Dashboard/Friends/FriendStream.cs similarity index 57% rename from osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs rename to osu.Game/Overlays/Dashboard/Friends/FriendStream.cs index d5fad1ffd3..4abece9a8d 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsBundle.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendStream.cs @@ -3,23 +3,16 @@ namespace osu.Game.Overlays.Dashboard.Friends { - public class FriendsBundle + public class FriendStream { - public FriendsOnlineStatus Status { get; } + public OnlineStatus Status { get; } public int Count { get; } - public FriendsBundle(FriendsOnlineStatus status, int count) + public FriendStream(OnlineStatus status, int count) { Status = status; Count = count; } } - - public enum FriendsOnlineStatus - { - All, - Online, - Offline - } } diff --git a/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusItem.cs b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusItem.cs index eada9420ea..7e902203f8 100644 --- a/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusItem.cs +++ b/osu.Game/Overlays/Dashboard/Friends/FriendsOnlineStatusItem.cs @@ -7,9 +7,9 @@ using osuTK.Graphics; namespace osu.Game.Overlays.Dashboard.Friends { - public class FriendsOnlineStatusItem : OverlayStreamItem + public class FriendsOnlineStatusItem : OverlayStreamItem { - public FriendsOnlineStatusItem(FriendsBundle value) + public FriendsOnlineStatusItem(FriendStream value) : base(value) { } @@ -22,13 +22,13 @@ namespace osu.Game.Overlays.Dashboard.Friends { switch (Value.Status) { - case FriendsOnlineStatus.All: + case OnlineStatus.All: return Color4.White; - case FriendsOnlineStatus.Online: + case OnlineStatus.Online: return colours.GreenLight; - case FriendsOnlineStatus.Offline: + case OnlineStatus.Offline: return Color4.Black; default: diff --git a/osu.Game/Overlays/Dashboard/Friends/OnlineStatus.cs b/osu.Game/Overlays/Dashboard/Friends/OnlineStatus.cs new file mode 100644 index 0000000000..6f2f55a6ed --- /dev/null +++ b/osu.Game/Overlays/Dashboard/Friends/OnlineStatus.cs @@ -0,0 +1,12 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Overlays.Dashboard.Friends +{ + public enum OnlineStatus + { + All, + Online, + Offline + } +} From 98e6896e934d5aa0f88a3977c7edc0a6e8005d92 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Mon, 23 Mar 2020 15:37:34 +0900 Subject: [PATCH 16/16] Rename test class --- .../{TestSceneFriendsLayout.cs => TestSceneFriendDisplay.cs} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename osu.Game.Tests/Visual/Online/{TestSceneFriendsLayout.cs => TestSceneFriendDisplay.cs} (97%) diff --git a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs b/osu.Game.Tests/Visual/Online/TestSceneFriendDisplay.cs similarity index 97% rename from osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs rename to osu.Game.Tests/Visual/Online/TestSceneFriendDisplay.cs index c0a617fe57..cf365a7614 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneFriendsLayout.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneFriendDisplay.cs @@ -13,7 +13,7 @@ using NUnit.Framework; namespace osu.Game.Tests.Visual.Online { - public class TestSceneFriendsLayout : OsuTestScene + public class TestSceneFriendDisplay : OsuTestScene { public override IReadOnlyList RequiredTypes => new[] {