From 160d64eecf1cff32ed662fbfcbc129fcfe2b928f Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 3 Mar 2020 17:37:01 +0300 Subject: [PATCH] FriendsOnlineStatusControl basic implementation --- .../TestSceneFriendsOnlineStatusControl.cs | 52 +++++++++++++++++++ .../Overlays/Home/Friends/FriendsBundle.cs | 48 +++++++++++++++++ .../Friends/FriendsOnlineStatusControl.cs | 10 ++++ .../Home/Friends/FriendsOnlineStatusItem.cs | 21 ++++++++ 4 files changed, 131 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs create mode 100644 osu.Game/Overlays/Home/Friends/FriendsBundle.cs create mode 100644 osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs create mode 100644 osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs new file mode 100644 index 0000000000..bb64593088 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneFriendsOnlineStatusControl.cs @@ -0,0 +1,52 @@ +// 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 NUnit.Framework; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Overlays; +using osu.Game.Overlays.Home.Friends; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneFriendsOnlineStatusControl : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(FriendsOnlineStatusControl), + typeof(FriendsOnlineStatusItem), + typeof(OverlayUpdateStreamControl<>), + typeof(OverlayUpdateStreamItem<>), + typeof(FriendsBundle) + }; + + [Cached] + private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); + + private FriendsOnlineStatusControl control; + + [SetUp] + public void SetUp() => Schedule(() => + { + Clear(); + Add(control = new FriendsOnlineStatusControl + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }); + }); + + [Test] + public void Populate() + { + AddStep(@"Populate", () => control.Populate(new List + { + new FriendsBundle(FriendsOnlineStatus.All, 100), + new FriendsBundle(FriendsOnlineStatus.Online, 50), + new FriendsBundle(FriendsOnlineStatus.Offline, 50), + })); + } + } +} diff --git a/osu.Game/Overlays/Home/Friends/FriendsBundle.cs b/osu.Game/Overlays/Home/Friends/FriendsBundle.cs new file mode 100644 index 0000000000..e0f841da9a --- /dev/null +++ b/osu.Game/Overlays/Home/Friends/FriendsBundle.cs @@ -0,0 +1,48 @@ +// 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 osuTK.Graphics; + +namespace osu.Game.Overlays.Home.Friends +{ + public class FriendsBundle + { + public FriendsOnlineStatus Status { get; } + + public int Amount { get; } + + public Color4 Colour => getColour(); + + public FriendsBundle(FriendsOnlineStatus status, int amount) + { + Status = status; + Amount = amount; + } + + private Color4 getColour() + { + switch (Status) + { + default: + throw new ArgumentException($@"{Status} status does not provide a colour in {nameof(getColour)}."); + + case FriendsOnlineStatus.All: + return Color4.White; + + case FriendsOnlineStatus.Online: + return Color4.Lime; + + case FriendsOnlineStatus.Offline: + return Color4.Black; + } + } + } + + public enum FriendsOnlineStatus + { + All, + Online, + Offline + } +} diff --git a/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs b/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs new file mode 100644 index 0000000000..abcd04bb0e --- /dev/null +++ b/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs @@ -0,0 +1,10 @@ +// 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 +{ + public class FriendsOnlineStatusControl : OverlayUpdateStreamControl + { + protected override OverlayUpdateStreamItem CreateStreamItem(FriendsBundle value) => new FriendsOnlineStatusItem(value); + } +} diff --git a/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs b/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs new file mode 100644 index 0000000000..0c77ef20b9 --- /dev/null +++ b/osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs @@ -0,0 +1,21 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osuTK.Graphics; + +namespace osu.Game.Overlays.Home.Friends +{ + public class FriendsOnlineStatusItem : OverlayUpdateStreamItem + { + public FriendsOnlineStatusItem(FriendsBundle value) + : base(value) + { + } + + protected override string GetMainText() => Value.Status.ToString(); + + protected override string GetAdditionalText() => Value.Amount.ToString(); + + protected override Color4 GetBarColour() => Value.Colour; + } +}