1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 15:17:44 +08:00
osu-lazer/osu.Game/Overlays/BeatmapSet/SuccessRate.cs

136 lines
4.6 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Extensions.LocalisationExtensions;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Localisation;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests.Responses;
2021-08-13 01:19:03 +08:00
using osu.Game.Resources.Localisation.Web;
2018-04-13 17:19:50 +08:00
using osu.Game.Screens.Select.Details;
namespace osu.Game.Overlays.BeatmapSet
{
2022-11-24 13:32:20 +08:00
public partial class SuccessRate : Container
2018-04-13 17:19:50 +08:00
{
2019-06-13 17:44:00 +08:00
protected readonly FailRetryGraph Graph;
2018-04-13 17:19:50 +08:00
private readonly FillFlowContainer header;
private readonly SuccessRatePercentage successPercent;
2018-04-13 17:19:50 +08:00
private readonly Bar successRate;
private readonly Container percentContainer;
private APIBeatmap beatmap;
2019-02-28 12:31:40 +08:00
public APIBeatmap Beatmap
2018-04-13 17:19:50 +08:00
{
get => beatmap;
2018-04-13 17:19:50 +08:00
set
{
if (value == beatmap) return;
2019-02-28 12:31:40 +08:00
beatmap = value;
2018-04-13 17:19:50 +08:00
updateDisplay();
}
}
private void updateDisplay()
{
int passCount = beatmap?.PassCount ?? 0;
int playCount = beatmap?.PlayCount ?? 0;
2018-04-13 17:19:50 +08:00
float rate = playCount != 0 ? (float)passCount / playCount : 0;
2021-08-16 18:46:41 +08:00
successPercent.Text = rate.ToLocalisableString(@"0.#%");
successPercent.TooltipText = $"{passCount} / {playCount}";
successRate.Length = rate;
percentContainer.ResizeWidthTo(successRate.Length, 250, Easing.InOutCubic);
2018-04-13 17:19:50 +08:00
Graph.FailTimes = beatmap?.FailTimes;
2018-04-13 17:19:50 +08:00
}
public SuccessRate()
{
Children = new Drawable[]
{
header = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
2020-02-04 19:00:18 +08:00
new OsuSpriteText
2018-04-13 17:19:50 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
2021-08-13 01:19:03 +08:00
Text = BeatmapsetsStrings.ShowInfoSuccessRate,
Font = OsuFont.GetFont(size: 12)
2018-04-13 17:19:50 +08:00
},
successRate = new Bar
{
RelativeSizeAxes = Axes.X,
Height = 5,
Margin = new MarginPadding { Top = 5 },
},
percentContainer = new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Width = 0f,
Child = successPercent = new SuccessRatePercentage
2018-04-13 17:19:50 +08:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopCentre,
Font = OsuFont.GetFont(size: 12),
2018-04-13 17:19:50 +08:00
},
},
2020-02-04 19:00:18 +08:00
new OsuSpriteText
2018-04-13 17:19:50 +08:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
2021-08-13 01:19:03 +08:00
Text = BeatmapsetsStrings.ShowInfoPointsOfFailure,
Font = OsuFont.GetFont(size: 12),
2018-04-13 17:19:50 +08:00
Margin = new MarginPadding { Vertical = 20 },
},
},
},
2019-06-13 17:44:00 +08:00
Graph = new FailRetryGraph
2018-04-13 17:19:50 +08:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
},
};
}
[BackgroundDependencyLoader]
2020-02-05 02:55:19 +08:00
private void load(OsuColour colours, OverlayColourProvider colourProvider)
2018-04-13 17:19:50 +08:00
{
successRate.AccentColour = colours.Green;
2020-02-05 02:55:19 +08:00
successRate.BackgroundColour = colourProvider.Background6;
updateDisplay();
2018-04-13 17:19:50 +08:00
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
2019-06-13 17:44:00 +08:00
Graph.Padding = new MarginPadding { Top = header.DrawHeight };
2018-04-13 17:19:50 +08:00
}
2022-11-24 13:32:20 +08:00
private partial class SuccessRatePercentage : OsuSpriteText, IHasTooltip
{
public LocalisableString TooltipText { get; set; }
}
2018-04-13 17:19:50 +08:00
}
}