1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 04:07:25 +08:00

Implement MappingSubscribersButton component

This commit is contained in:
Andrei Zavatski 2021-01-21 22:02:54 +03:00
parent 966440f109
commit a7c22ebe88
4 changed files with 39 additions and 13 deletions

View File

@ -49,9 +49,12 @@ namespace osu.Game.Overlays.Profile.Header
Spacing = new Vector2(10, 0),
Children = new Drawable[]
{
new AddFriendButton
new FriendsButton
{
User = { BindTarget = User }
},
new MappingSubscribersButton
{
RelativeSizeAxes = Axes.Y,
User = { BindTarget = User }
},
new MessageUserButton

View File

@ -8,7 +8,7 @@ using osu.Game.Users;
namespace osu.Game.Overlays.Profile.Header.Components
{
public class AddFriendButton : ProfileHeaderStatisticsButton
public class FriendsButton : ProfileHeaderStatisticsButton
{
public readonly Bindable<User> User = new Bindable<User>();
@ -20,9 +20,7 @@ namespace osu.Game.Overlays.Profile.Header.Components
private void load()
{
// todo: when friending/unfriending is implemented, the APIAccess.Friends list should be updated accordingly.
User.BindValueChanged(user => updateFollowers(user.NewValue), true);
User.BindValueChanged(user => SetValue(user.NewValue?.FollowerCount ?? 0), true);
}
private void updateFollowers(User user) => SetValue(user?.FollowerCount.ToString("#,##0"));
}
}

View 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.
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Sprites;
using osu.Game.Users;
namespace osu.Game.Overlays.Profile.Header.Components
{
public class MappingSubscribersButton : ProfileHeaderStatisticsButton
{
public readonly Bindable<User> User = new Bindable<User>();
public override string TooltipText => "mapping subscribers";
protected override IconUsage CreateIcon() => FontAwesome.Solid.Bell;
[BackgroundDependencyLoader]
private void load()
{
User.BindValueChanged(user => SetValue(user.NewValue?.MappingFollowerCount ?? 0), true);
}
}
}

View File

@ -1,7 +1,6 @@
// 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 JetBrains.Annotations;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
@ -17,13 +16,14 @@ namespace osu.Game.Overlays.Profile.Header.Components
protected ProfileHeaderStatisticsButton()
{
RelativeSizeAxes = Axes.Y;
Child = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Direction = FillDirection.Horizontal,
Padding = new MarginPadding { Right = 10 },
Children = new Drawable[]
{
new SpriteIcon
@ -38,15 +38,15 @@ namespace osu.Game.Overlays.Profile.Header.Components
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 10 },
Font = OsuFont.GetFont(weight: FontWeight.Bold)
}
}
};
}
[NotNull]
protected abstract IconUsage CreateIcon();
protected void SetValue(string value) => drawableText.Text = value;
protected void SetValue(int value) => drawableText.Text = value.ToString("#,##0");
}
}