2024-01-02 14:33:36 +00:00
|
|
|
|
// 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;
|
2024-01-17 08:00:30 +00:00
|
|
|
|
using osu.Framework.Bindables;
|
2024-01-02 14:33:36 +00:00
|
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Input.Events;
|
2024-01-03 08:32:32 +00:00
|
|
|
|
using osu.Game.Online.API;
|
2024-01-02 14:33:36 +00:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Game.Overlays.Profile.Header.Components;
|
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Users
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// User card that shows user's global and country ranks in the bottom.
|
|
|
|
|
/// Meant to be used in the toolbar login overlay.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public partial class UserRankPanel : UserPanel
|
|
|
|
|
{
|
|
|
|
|
private const int padding = 10;
|
|
|
|
|
private const int main_content_height = 80;
|
|
|
|
|
|
2024-01-03 08:32:32 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
|
|
|
|
|
2024-02-19 20:11:12 +00:00
|
|
|
|
private ProfileValueDisplay globalRankDisplay = null!;
|
2024-01-03 08:32:32 +00:00
|
|
|
|
private ProfileValueDisplay countryRankDisplay = null!;
|
|
|
|
|
|
2024-01-17 08:00:30 +00:00
|
|
|
|
private readonly IBindable<UserStatistics?> statistics = new Bindable<UserStatistics?>();
|
|
|
|
|
|
2024-01-02 14:33:36 +00:00
|
|
|
|
public UserRankPanel(APIUser user)
|
|
|
|
|
: base(user)
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
CornerRadius = 10;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
BorderColour = ColourProvider?.Light1 ?? Colours.GreyVioletLighter;
|
2024-01-03 08:32:32 +00:00
|
|
|
|
|
2024-01-17 08:00:30 +00:00
|
|
|
|
statistics.BindTo(api.Statistics);
|
|
|
|
|
statistics.BindValueChanged(stats =>
|
2024-01-03 08:32:32 +00:00
|
|
|
|
{
|
2024-02-19 20:11:12 +00:00
|
|
|
|
globalRankDisplay.Content = stats.NewValue?.GlobalRank?.ToLocalisableString("\\##,##0") ?? "-";
|
2024-01-17 08:00:30 +00:00
|
|
|
|
countryRankDisplay.Content = stats.NewValue?.CountryRank?.ToLocalisableString("\\##,##0") ?? "-";
|
|
|
|
|
}, true);
|
2024-01-02 14:33:36 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Drawable CreateLayout()
|
|
|
|
|
{
|
|
|
|
|
FillFlowContainer details;
|
|
|
|
|
|
|
|
|
|
var layout = new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
Name = "Main content",
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = main_content_height,
|
|
|
|
|
CornerRadius = 10,
|
|
|
|
|
Masking = true,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new UserCoverBackground
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
User = User,
|
|
|
|
|
Alpha = 0.3f
|
|
|
|
|
},
|
|
|
|
|
new GridContainer
|
|
|
|
|
{
|
2024-02-01 13:33:54 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding(padding),
|
2024-01-02 14:33:36 +00:00
|
|
|
|
ColumnDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension(),
|
|
|
|
|
},
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
2024-02-01 13:33:54 +00:00
|
|
|
|
new Dimension()
|
2024-01-02 14:33:36 +00:00
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
2024-02-01 13:33:54 +00:00
|
|
|
|
new Drawable[]
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
|
|
|
|
CreateAvatar().With(avatar =>
|
|
|
|
|
{
|
|
|
|
|
avatar.Size = new Vector2(60);
|
|
|
|
|
avatar.Masking = true;
|
|
|
|
|
avatar.CornerRadius = 6;
|
|
|
|
|
}),
|
2024-02-01 13:33:54 +00:00
|
|
|
|
new GridContainer
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Padding = new MarginPadding { Left = padding },
|
2024-02-01 13:33:54 +00:00
|
|
|
|
ColumnDimensions = new[]
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
2024-02-01 13:33:54 +00:00
|
|
|
|
new Dimension()
|
|
|
|
|
},
|
|
|
|
|
RowDimensions = new[]
|
|
|
|
|
{
|
|
|
|
|
new Dimension(GridSizeMode.AutoSize),
|
|
|
|
|
new Dimension()
|
|
|
|
|
},
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
2024-02-01 13:33:54 +00:00
|
|
|
|
details = new FillFlowContainer
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
2024-02-01 13:33:54 +00:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(6),
|
|
|
|
|
Children = new Drawable[]
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
2024-02-01 13:33:54 +00:00
|
|
|
|
CreateFlag(),
|
|
|
|
|
// supporter icon is being added later
|
2024-01-02 14:33:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-01 13:33:54 +00:00
|
|
|
|
},
|
|
|
|
|
new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
CreateUsername().With(username =>
|
|
|
|
|
{
|
|
|
|
|
username.Anchor = Anchor.CentreLeft;
|
|
|
|
|
username.Origin = Anchor.CentreLeft;
|
|
|
|
|
})
|
2024-01-02 14:33:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-02-01 13:33:54 +00:00
|
|
|
|
}
|
2024-01-02 14:33:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
2024-02-01 13:33:54 +00:00
|
|
|
|
new GridContainer
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
|
|
|
|
Name = "Bottom content",
|
|
|
|
|
Margin = new MarginPadding { Top = main_content_height },
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2024-10-27 08:40:29 +00:00
|
|
|
|
Padding = new MarginPadding(padding),
|
2024-02-01 13:33:54 +00:00
|
|
|
|
ColumnDimensions = new[]
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
2024-02-01 13:33:54 +00:00
|
|
|
|
new Dimension(),
|
|
|
|
|
new Dimension()
|
|
|
|
|
},
|
|
|
|
|
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
|
|
|
|
|
Content = new[]
|
|
|
|
|
{
|
|
|
|
|
new Drawable[]
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
2024-02-19 20:11:12 +00:00
|
|
|
|
globalRankDisplay = new ProfileValueDisplay(true)
|
2024-01-02 14:33:36 +00:00
|
|
|
|
{
|
2024-02-19 20:11:12 +00:00
|
|
|
|
Title = UsersStrings.ShowRankGlobalSimple,
|
|
|
|
|
// TODO: implement highest rank tooltip
|
|
|
|
|
// `RankHighest` resides in `APIUser`, but `api.LocalUser` doesn't update
|
2024-02-28 22:11:01 +00:00
|
|
|
|
// maybe move to `UserStatistics` in api, so `UserStatisticsWatcher` can update the value
|
2024-02-01 13:33:54 +00:00
|
|
|
|
},
|
|
|
|
|
countryRankDisplay = new ProfileValueDisplay(true)
|
|
|
|
|
{
|
|
|
|
|
Title = UsersStrings.ShowRankCountrySimple,
|
2024-01-02 14:33:36 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if (User.IsSupporter)
|
|
|
|
|
{
|
|
|
|
|
details.Add(new SupporterIcon
|
|
|
|
|
{
|
|
|
|
|
Height = 26,
|
|
|
|
|
SupportLevel = User.SupportLevel
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return layout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
|
{
|
|
|
|
|
BorderThickness = 2;
|
|
|
|
|
return base.OnHover(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
|
{
|
|
|
|
|
BorderThickness = 0;
|
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Drawable? CreateBackground() => null;
|
|
|
|
|
}
|
|
|
|
|
}
|