mirror of
https://github.com/ppy/osu.git
synced 2025-01-08 05:12:55 +08:00
FriendsOnlineStatusControl basic implementation
This commit is contained in:
parent
c0f7a83f6f
commit
160d64eecf
@ -0,0 +1,52 @@
|
|||||||
|
// 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;
|
||||||
|
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<Type> 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<FriendsBundle>
|
||||||
|
{
|
||||||
|
new FriendsBundle(FriendsOnlineStatus.All, 100),
|
||||||
|
new FriendsBundle(FriendsOnlineStatus.Online, 50),
|
||||||
|
new FriendsBundle(FriendsOnlineStatus.Offline, 50),
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
48
osu.Game/Overlays/Home/Friends/FriendsBundle.cs
Normal file
48
osu.Game/Overlays/Home/Friends/FriendsBundle.cs
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
// 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;
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
10
osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs
Normal file
10
osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
// 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.
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Home.Friends
|
||||||
|
{
|
||||||
|
public class FriendsOnlineStatusControl : OverlayUpdateStreamControl<FriendsBundle>
|
||||||
|
{
|
||||||
|
protected override OverlayUpdateStreamItem<FriendsBundle> CreateStreamItem(FriendsBundle value) => new FriendsOnlineStatusItem(value);
|
||||||
|
}
|
||||||
|
}
|
21
osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs
Normal file
21
osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
// 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 osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Home.Friends
|
||||||
|
{
|
||||||
|
public class FriendsOnlineStatusItem : OverlayUpdateStreamItem<FriendsBundle>
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user