mirror of
https://github.com/ppy/osu.git
synced 2024-12-05 10:23:20 +08:00
Merge pull request #8108 from EVAST9919/friends-update-streams
Implement FriendsOnlineStatusControl component
This commit is contained in:
commit
35ae8aa29f
@ -17,8 +17,8 @@ namespace osu.Game.Tests.Visual.Online
|
||||
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(UpdateStreamBadgeArea),
|
||||
typeof(UpdateStreamBadge),
|
||||
typeof(ChangelogUpdateStreamControl),
|
||||
typeof(ChangelogUpdateStreamItem),
|
||||
typeof(ChangelogHeader),
|
||||
typeof(ChangelogContent),
|
||||
typeof(ChangelogListing),
|
||||
|
@ -0,0 +1,63 @@
|
||||
// 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 System.Linq;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.Home.Friends;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneFriendsOnlineStatusControl : OsuTestScene
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new[]
|
||||
{
|
||||
typeof(FriendsOnlineStatusControl),
|
||||
typeof(FriendsOnlineStatusItem),
|
||||
typeof(OverlayStreamControl<>),
|
||||
typeof(OverlayStreamItem<>),
|
||||
typeof(FriendsBundle)
|
||||
};
|
||||
|
||||
[Cached]
|
||||
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
|
||||
|
||||
private FriendsOnlineStatusControl control;
|
||||
|
||||
[SetUp]
|
||||
public void SetUp() => Schedule(() => Child = control = new FriendsOnlineStatusControl
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
});
|
||||
|
||||
[Test]
|
||||
public void Populate()
|
||||
{
|
||||
AddStep("Populate", () => control.Populate(new List<User>
|
||||
{
|
||||
new User
|
||||
{
|
||||
IsOnline = true
|
||||
},
|
||||
new User
|
||||
{
|
||||
IsOnline = false
|
||||
},
|
||||
new User
|
||||
{
|
||||
IsOnline = false
|
||||
}
|
||||
}));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
@ -20,7 +20,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
|
||||
public Action ListingSelected;
|
||||
|
||||
public UpdateStreamBadgeArea Streams;
|
||||
public ChangelogUpdateStreamControl Streams;
|
||||
|
||||
private const string listing_string = "listing";
|
||||
|
||||
@ -95,7 +95,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
Horizontal = 65,
|
||||
Vertical = 20
|
||||
},
|
||||
Child = Streams = new UpdateStreamBadgeArea()
|
||||
Child = Streams = new ChangelogUpdateStreamControl()
|
||||
}
|
||||
}
|
||||
};
|
||||
|
12
osu.Game/Overlays/Changelog/ChangelogUpdateStreamControl.cs
Normal file
12
osu.Game/Overlays/Changelog/ChangelogUpdateStreamControl.cs
Normal file
@ -0,0 +1,12 @@
|
||||
// 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 osu.Game.Online.API.Requests.Responses;
|
||||
|
||||
namespace osu.Game.Overlays.Changelog
|
||||
{
|
||||
public class ChangelogUpdateStreamControl : OverlayStreamControl<APIUpdateStream>
|
||||
{
|
||||
protected override OverlayStreamItem<APIUpdateStream> CreateStreamItem(APIUpdateStream value) => new ChangelogUpdateStreamItem(value);
|
||||
}
|
||||
}
|
28
osu.Game/Overlays/Changelog/ChangelogUpdateStreamItem.cs
Normal file
28
osu.Game/Overlays/Changelog/ChangelogUpdateStreamItem.cs
Normal file
@ -0,0 +1,28 @@
|
||||
// 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 Humanizer;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Changelog
|
||||
{
|
||||
public class ChangelogUpdateStreamItem : OverlayStreamItem<APIUpdateStream>
|
||||
{
|
||||
public ChangelogUpdateStreamItem(APIUpdateStream stream)
|
||||
: base(stream)
|
||||
{
|
||||
if (stream.IsFeatured)
|
||||
Width *= 2;
|
||||
}
|
||||
|
||||
protected override string MainText => Value.DisplayName;
|
||||
|
||||
protected override string AdditionalText => Value.LatestBuild.DisplayVersion;
|
||||
|
||||
protected override string InfoText => Value.LatestBuild.Users > 0 ? $"{"user".ToQuantity(Value.LatestBuild.Users, "N0")} online" : null;
|
||||
|
||||
protected override Color4 GetBarColour(OsuColour colours) => Value.Colour;
|
||||
}
|
||||
}
|
25
osu.Game/Overlays/Home/Friends/FriendsBundle.cs
Normal file
25
osu.Game/Overlays/Home/Friends/FriendsBundle.cs
Normal file
@ -0,0 +1,25 @@
|
||||
// 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 FriendsBundle
|
||||
{
|
||||
public FriendsOnlineStatus Status { get; }
|
||||
|
||||
public int Count { get; }
|
||||
|
||||
public FriendsBundle(FriendsOnlineStatus status, int count)
|
||||
{
|
||||
Status = status;
|
||||
Count = count;
|
||||
}
|
||||
}
|
||||
|
||||
public enum FriendsOnlineStatus
|
||||
{
|
||||
All,
|
||||
Online,
|
||||
Offline
|
||||
}
|
||||
}
|
26
osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs
Normal file
26
osu.Game/Overlays/Home/Friends/FriendsOnlineStatusControl.cs
Normal file
@ -0,0 +1,26 @@
|
||||
// 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 System.Linq;
|
||||
using osu.Game.Users;
|
||||
|
||||
namespace osu.Game.Overlays.Home.Friends
|
||||
{
|
||||
public class FriendsOnlineStatusControl : OverlayStreamControl<FriendsBundle>
|
||||
{
|
||||
protected override OverlayStreamItem<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();
|
||||
}
|
||||
}
|
||||
}
|
39
osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs
Normal file
39
osu.Game/Overlays/Home/Friends/FriendsOnlineStatusItem.cs
Normal file
@ -0,0 +1,39 @@
|
||||
// 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 osu.Game.Graphics;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Home.Friends
|
||||
{
|
||||
public class FriendsOnlineStatusItem : OverlayStreamItem<FriendsBundle>
|
||||
{
|
||||
public FriendsOnlineStatusItem(FriendsBundle value)
|
||||
: base(value)
|
||||
{
|
||||
}
|
||||
|
||||
protected override string MainText => Value.Status.ToString();
|
||||
|
||||
protected override string AdditionalText => Value.Count.ToString();
|
||||
|
||||
protected override Color4 GetBarColour(OsuColour colours)
|
||||
{
|
||||
switch (Value.Status)
|
||||
{
|
||||
case FriendsOnlineStatus.All:
|
||||
return Color4.White;
|
||||
|
||||
case FriendsOnlineStatus.Online:
|
||||
return colours.GreenLight;
|
||||
|
||||
case FriendsOnlineStatus.Offline:
|
||||
return Color4.Black;
|
||||
|
||||
default:
|
||||
throw new ArgumentException($@"{Value.Status} status does not provide a colour in {nameof(GetBarColour)}.");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -3,42 +3,32 @@
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using JetBrains.Annotations;
|
||||
|
||||
namespace osu.Game.Overlays.Changelog
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public class UpdateStreamBadgeArea : TabControl<APIUpdateStream>
|
||||
public abstract class OverlayStreamControl<T> : TabControl<T>
|
||||
{
|
||||
public UpdateStreamBadgeArea()
|
||||
protected OverlayStreamControl()
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
}
|
||||
|
||||
public void Populate(List<APIUpdateStream> streams)
|
||||
public void Populate(List<T> streams) => streams.ForEach(AddItem);
|
||||
|
||||
protected override Dropdown<T> CreateDropdown() => null;
|
||||
|
||||
protected override TabItem<T> CreateTabItem(T value) => CreateStreamItem(value).With(item =>
|
||||
{
|
||||
foreach (var updateStream in streams)
|
||||
AddItem(updateStream);
|
||||
}
|
||||
item.SelectedItem.BindTo(Current);
|
||||
});
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
foreach (var streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
|
||||
streamBadge.UserHoveringArea = true;
|
||||
|
||||
return base.OnHover(e);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
foreach (var streamBadge in TabContainer.Children.OfType<UpdateStreamBadge>())
|
||||
streamBadge.UserHoveringArea = false;
|
||||
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
[NotNull]
|
||||
protected abstract OverlayStreamItem<T> CreateStreamItem(T value);
|
||||
|
||||
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
|
||||
{
|
||||
@ -47,9 +37,20 @@ namespace osu.Game.Overlays.Changelog
|
||||
AllowMultiline = true,
|
||||
};
|
||||
|
||||
protected override Dropdown<APIUpdateStream> CreateDropdown() => null;
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
foreach (var streamBadge in TabContainer.Children.OfType<OverlayStreamItem<T>>())
|
||||
streamBadge.UserHoveringArea = true;
|
||||
|
||||
protected override TabItem<APIUpdateStream> CreateTabItem(APIUpdateStream value) =>
|
||||
new UpdateStreamBadge(value) { SelectedTab = { BindTarget = Current } };
|
||||
return base.OnHover(e);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
foreach (var streamBadge in TabContainer.Children.OfType<OverlayStreamItem<T>>())
|
||||
streamBadge.UserHoveringArea = false;
|
||||
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,46 +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 Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Changelog
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public class UpdateStreamBadge : TabItem<APIUpdateStream>
|
||||
public abstract class OverlayStreamItem<T> : TabItem<T>
|
||||
{
|
||||
private const float badge_width = 100;
|
||||
private const float transition_duration = 100;
|
||||
public readonly Bindable<T> SelectedItem = new Bindable<T>();
|
||||
|
||||
public readonly Bindable<APIUpdateStream> SelectedTab = new Bindable<APIUpdateStream>();
|
||||
private bool userHoveringArea;
|
||||
|
||||
private readonly APIUpdateStream stream;
|
||||
public bool UserHoveringArea
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == userHoveringArea)
|
||||
return;
|
||||
|
||||
userHoveringArea = value;
|
||||
updateState();
|
||||
}
|
||||
}
|
||||
|
||||
private FillFlowContainer<SpriteText> text;
|
||||
private ExpandingBar expandingBar;
|
||||
|
||||
public UpdateStreamBadge(APIUpdateStream stream)
|
||||
: base(stream)
|
||||
protected OverlayStreamItem(T value)
|
||||
: base(value)
|
||||
{
|
||||
this.stream = stream;
|
||||
Height = 60;
|
||||
Width = 100;
|
||||
Padding = new MarginPadding(5);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OverlayColourProvider colourProvider)
|
||||
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
||||
{
|
||||
Size = new Vector2(stream.IsFeatured ? badge_width * 2 : badge_width, 60);
|
||||
Padding = new MarginPadding(5);
|
||||
|
||||
AddRange(new Drawable[]
|
||||
{
|
||||
text = new FillFlowContainer<SpriteText>
|
||||
@ -52,17 +58,17 @@ namespace osu.Game.Overlays.Changelog
|
||||
{
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = stream.DisplayName,
|
||||
Text = MainText,
|
||||
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Black),
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = stream.LatestBuild.DisplayVersion,
|
||||
Text = AdditionalText,
|
||||
Font = OsuFont.GetFont(size: 16, weight: FontWeight.Regular),
|
||||
},
|
||||
new OsuSpriteText
|
||||
{
|
||||
Text = stream.LatestBuild.Users > 0 ? $"{"user".ToQuantity(stream.LatestBuild.Users, "N0")} online" : null,
|
||||
Text = InfoText,
|
||||
Font = OsuFont.GetFont(size: 10),
|
||||
Colour = colourProvider.Foreground1
|
||||
},
|
||||
@ -71,7 +77,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
expandingBar = new ExpandingBar
|
||||
{
|
||||
Anchor = Anchor.TopCentre,
|
||||
Colour = stream.Colour,
|
||||
Colour = GetBarColour(colours),
|
||||
ExpandedSize = 4,
|
||||
CollapsedSize = 2,
|
||||
Expanded = true
|
||||
@ -79,9 +85,17 @@ namespace osu.Game.Overlays.Changelog
|
||||
new HoverClickSounds()
|
||||
});
|
||||
|
||||
SelectedTab.BindValueChanged(_ => updateState(), true);
|
||||
SelectedItem.BindValueChanged(_ => updateState(), true);
|
||||
}
|
||||
|
||||
protected abstract string MainText { get; }
|
||||
|
||||
protected abstract string AdditionalText { get; }
|
||||
|
||||
protected virtual string InfoText => string.Empty;
|
||||
|
||||
protected abstract Color4 GetBarColour(OsuColour colours);
|
||||
|
||||
protected override void OnActivated() => updateState();
|
||||
|
||||
protected override void OnDeactivated() => updateState();
|
||||
@ -104,7 +118,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
bool textHighlighted = IsHovered;
|
||||
bool barExpanded = IsHovered;
|
||||
|
||||
if (SelectedTab.Value == null)
|
||||
if (SelectedItem.Value == null)
|
||||
{
|
||||
// at listing, all badges are highlighted when user is not hovering any badge.
|
||||
textHighlighted |= !userHoveringArea;
|
||||
@ -120,21 +134,7 @@ namespace osu.Game.Overlays.Changelog
|
||||
}
|
||||
|
||||
expandingBar.Expanded = barExpanded;
|
||||
text.FadeTo(textHighlighted ? 1 : 0.5f, transition_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
private bool userHoveringArea;
|
||||
|
||||
public bool UserHoveringArea
|
||||
{
|
||||
set
|
||||
{
|
||||
if (value == userHoveringArea)
|
||||
return;
|
||||
|
||||
userHoveringArea = value;
|
||||
updateState();
|
||||
}
|
||||
text.FadeTo(textHighlighted ? 1 : 0.5f, 100, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user