2024-07-28 10:24:29 +08: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;
|
|
|
|
using osu.Framework.Bindables;
|
2024-08-02 14:28:54 +08:00
|
|
|
using osu.Framework.Extensions.LocalisationExtensions;
|
2024-07-28 10:24:29 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2024-08-02 14:37:22 +08:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
using osu.Game.Scoring;
|
2024-08-14 14:10:55 +08:00
|
|
|
using osu.Game.Localisation;
|
2024-07-28 10:24:29 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Profile.Header.Components
|
|
|
|
{
|
2024-08-02 14:31:22 +08:00
|
|
|
public partial class DailyChallengeStatsDisplay : CompositeDrawable, IHasCustomTooltip<DailyChallengeTooltipData>
|
2024-07-28 10:24:29 +08:00
|
|
|
{
|
|
|
|
public readonly Bindable<UserProfileData?> User = new Bindable<UserProfileData?>();
|
|
|
|
|
2024-08-02 14:31:22 +08:00
|
|
|
public DailyChallengeTooltipData? TooltipContent { get; private set; }
|
2024-07-28 10:24:29 +08:00
|
|
|
|
2024-08-02 14:37:22 +08:00
|
|
|
private OsuSpriteText dailyPlayCount = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
2024-07-28 10:24:29 +08:00
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
CornerRadius = 5;
|
|
|
|
Masking = true;
|
|
|
|
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = colourProvider.Background4,
|
|
|
|
},
|
|
|
|
new FillFlowContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Padding = new MarginPadding(5f),
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new OsuTextFlowContainer(s => s.Font = OsuFont.GetFont(size: 12))
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2024-08-03 21:44:51 +08:00
|
|
|
// can't use this because osu-web does weird stuff with \\n.
|
|
|
|
// Text = UsersStrings.ShowDailyChallengeTitle.,
|
|
|
|
Text = "Daily\nChallenge",
|
2024-07-28 10:24:29 +08:00
|
|
|
Margin = new MarginPadding { Horizontal = 5f, Bottom = 2f },
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
CornerRadius = 5f,
|
|
|
|
Masking = true,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = colourProvider.Background6,
|
|
|
|
},
|
2024-08-02 14:37:22 +08:00
|
|
|
dailyPlayCount = new OsuSpriteText
|
2024-07-28 10:24:29 +08:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
UseFullGlyphHeight = false,
|
|
|
|
Colour = colourProvider.Content2,
|
|
|
|
Margin = new MarginPadding { Horizontal = 10f, Vertical = 5f },
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
User.BindValueChanged(_ => updateDisplay(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateDisplay()
|
|
|
|
{
|
2024-07-30 12:05:31 +08:00
|
|
|
if (User.Value == null || User.Value.Ruleset.OnlineID != 0)
|
2024-07-28 10:24:29 +08:00
|
|
|
{
|
2024-07-30 12:05:31 +08:00
|
|
|
Hide();
|
2024-07-28 10:24:29 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-08-02 14:37:22 +08:00
|
|
|
APIUserDailyChallengeStatistics stats = User.Value.User.DailyChallengeStatistics;
|
|
|
|
|
2024-08-14 14:10:55 +08:00
|
|
|
dailyPlayCount.Text = DailyChallengeStatsDisplayStrings.UnitDay(stats.PlayCount.ToLocalisableString("N0"));
|
2024-08-02 14:37:22 +08:00
|
|
|
dailyPlayCount.Colour = colours.ForRankingTier(tierForPlayCount(stats.PlayCount));
|
|
|
|
|
|
|
|
TooltipContent = new DailyChallengeTooltipData(colourProvider, stats);
|
|
|
|
|
2024-07-30 12:05:31 +08:00
|
|
|
Show();
|
2024-08-02 14:37:22 +08:00
|
|
|
|
|
|
|
static RankingTier tierForPlayCount(int playCount) => DailyChallengeStatsTooltip.TierForDaily(playCount / 3);
|
2024-07-28 10:24:29 +08:00
|
|
|
}
|
|
|
|
|
2024-08-02 14:31:22 +08:00
|
|
|
public ITooltip<DailyChallengeTooltipData> GetCustomTooltip() => new DailyChallengeStatsTooltip();
|
2024-07-28 10:24:29 +08:00
|
|
|
}
|
|
|
|
}
|