osu/osu.Game/Overlays/BeatmapSet/SuccessRate.cs

124 lines
4.1 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 09:19:50 +00:00
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Screens.Select.Details;
namespace osu.Game.Overlays.BeatmapSet
{
public class SuccessRate : Container
{
2019-06-13 09:44:00 +00:00
protected readonly FailRetryGraph Graph;
2018-04-13 09:19:50 +00:00
private readonly FillFlowContainer header;
2020-02-04 11:00:18 +00:00
private readonly OsuSpriteText successPercent;
2018-04-13 09:19:50 +00:00
private readonly Bar successRate;
private readonly Container percentContainer;
private BeatmapInfo beatmap;
2019-02-28 04:31:40 +00:00
2018-04-13 09:19:50 +00:00
public BeatmapInfo Beatmap
{
get => beatmap;
2018-04-13 09:19:50 +00:00
set
{
if (value == beatmap) return;
2019-02-28 04:31:40 +00:00
2018-04-13 09:19:50 +00:00
beatmap = value;
updateDisplay();
}
}
private void updateDisplay()
{
2019-06-13 09:43:51 +00:00
int passCount = beatmap?.OnlineInfo?.PassCount ?? 0;
int playCount = beatmap?.OnlineInfo?.PlayCount ?? 0;
2018-04-13 09:19:50 +00:00
var rate = playCount != 0 ? (float)passCount / playCount : 0;
2020-02-05 15:15:55 +00:00
successPercent.Text = rate.ToString("0.#%");
successRate.Length = rate;
percentContainer.ResizeWidthTo(successRate.Length, 250, Easing.InOutCubic);
2018-04-13 09:19:50 +00:00
2019-06-13 09:44:00 +00:00
Graph.Metrics = beatmap?.Metrics;
2018-04-13 09:19:50 +00:00
}
public SuccessRate()
{
Children = new Drawable[]
{
header = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
2020-02-04 11:00:18 +00:00
new OsuSpriteText
2018-04-13 09:19:50 +00:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = "Success Rate",
Font = OsuFont.GetFont(size: 13)
2018-04-13 09:19:50 +00: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 OsuSpriteText
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopCentre,
Font = OsuFont.GetFont(size: 13),
2018-04-13 09:19:50 +00:00
},
},
2020-02-04 11:00:18 +00:00
new OsuSpriteText
2018-04-13 09:19:50 +00:00
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = "Points of Failure",
Font = OsuFont.GetFont(size: 13),
2018-04-13 09:19:50 +00:00
Margin = new MarginPadding { Vertical = 20 },
},
},
},
2019-06-13 09:44:00 +00:00
Graph = new FailRetryGraph
2018-04-13 09:19:50 +00:00
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
},
};
}
[BackgroundDependencyLoader]
2020-02-04 18:55:19 +00:00
private void load(OsuColour colours, OverlayColourProvider colourProvider)
2018-04-13 09:19:50 +00:00
{
successRate.AccentColour = colours.Green;
2020-02-04 18:55:19 +00:00
successRate.BackgroundColour = colourProvider.Background6;
updateDisplay();
2018-04-13 09:19:50 +00:00
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
2019-06-13 09:44:00 +00:00
Graph.Padding = new MarginPadding { Top = header.DrawHeight };
2018-04-13 09:19:50 +00:00
}
}
}