mirror of
https://github.com/ppy/osu.git
synced 2025-02-20 02:52:58 +08:00
Implement ProfileHeaderStatisticsButton component
This commit is contained in:
parent
05d3914fee
commit
2aa1df9ea4
@ -3,58 +3,26 @@
|
|||||||
|
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using osu.Game.Users;
|
using osu.Game.Users;
|
||||||
using osuTK;
|
|
||||||
|
|
||||||
namespace osu.Game.Overlays.Profile.Header.Components
|
namespace osu.Game.Overlays.Profile.Header.Components
|
||||||
{
|
{
|
||||||
public class AddFriendButton : ProfileHeaderButton
|
public class AddFriendButton : ProfileHeaderStatisticsButton
|
||||||
{
|
{
|
||||||
public readonly Bindable<User> User = new Bindable<User>();
|
public readonly Bindable<User> User = new Bindable<User>();
|
||||||
|
|
||||||
public override string TooltipText => "followers";
|
public override string TooltipText => "followers";
|
||||||
|
|
||||||
private OsuSpriteText followerText;
|
protected override IconUsage CreateIcon() => FontAwesome.Solid.User;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
Child = new FillFlowContainer
|
|
||||||
{
|
|
||||||
AutoSizeAxes = Axes.Both,
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
Direction = FillDirection.Horizontal,
|
|
||||||
Padding = new MarginPadding { Right = 10 },
|
|
||||||
Children = new Drawable[]
|
|
||||||
{
|
|
||||||
new SpriteIcon
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
Icon = FontAwesome.Solid.User,
|
|
||||||
FillMode = FillMode.Fit,
|
|
||||||
Size = new Vector2(50, 14)
|
|
||||||
},
|
|
||||||
followerText = new OsuSpriteText
|
|
||||||
{
|
|
||||||
Anchor = Anchor.CentreLeft,
|
|
||||||
Origin = Anchor.CentreLeft,
|
|
||||||
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// todo: when friending/unfriending is implemented, the APIAccess.Friends list should be updated accordingly.
|
// todo: when friending/unfriending is implemented, the APIAccess.Friends list should be updated accordingly.
|
||||||
|
|
||||||
User.BindValueChanged(user => updateFollowers(user.NewValue), true);
|
User.BindValueChanged(user => updateFollowers(user.NewValue), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateFollowers(User user) => followerText.Text = user?.FollowerCount.ToString("#,##0");
|
private void updateFollowers(User user) => SetValue(user?.FollowerCount.ToString("#,##0"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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 JetBrains.Annotations;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.Profile.Header.Components
|
||||||
|
{
|
||||||
|
public abstract class ProfileHeaderStatisticsButton : ProfileHeaderButton
|
||||||
|
{
|
||||||
|
private readonly OsuSpriteText drawableText;
|
||||||
|
|
||||||
|
protected ProfileHeaderStatisticsButton()
|
||||||
|
{
|
||||||
|
Child = new FillFlowContainer
|
||||||
|
{
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Direction = FillDirection.Horizontal,
|
||||||
|
Padding = new MarginPadding { Right = 10 },
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new SpriteIcon
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Icon = CreateIcon(),
|
||||||
|
FillMode = FillMode.Fit,
|
||||||
|
Size = new Vector2(50, 14)
|
||||||
|
},
|
||||||
|
drawableText = new OsuSpriteText
|
||||||
|
{
|
||||||
|
Anchor = Anchor.CentreLeft,
|
||||||
|
Origin = Anchor.CentreLeft,
|
||||||
|
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[NotNull]
|
||||||
|
protected abstract IconUsage CreateIcon();
|
||||||
|
|
||||||
|
protected void SetValue(string value) => drawableText.Text = value;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user