Merge pull request #24358 from peppy/song-select-drain-length

Show break time in tooltip at song select
This commit is contained in:
Bartłomiej Dach 2023-07-25 23:22:18 +02:00 committed by GitHub
commit 0b5be51ee0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 34 additions and 35 deletions

View File

@ -14,14 +14,14 @@ using osu.Game.Tests.Beatmaps;
namespace osu.Game.Tests.Editing.Checks
{
public class CheckDrainTimeTest
public class CheckDrainLengthTest
{
private CheckDrainTime check = null!;
private CheckDrainLength check = null!;
[SetUp]
public void Setup()
{
check = new CheckDrainTime();
check = new CheckDrainLength();
}
[Test]
@ -40,7 +40,7 @@ namespace osu.Game.Tests.Editing.Checks
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckDrainTime.IssueTemplateTooShort);
Assert.That(issues.Single().Template is CheckDrainLength.IssueTemplateTooShort);
}
[Test]
@ -63,7 +63,7 @@ namespace osu.Game.Tests.Editing.Checks
var issues = check.Run(context).ToList();
Assert.That(issues, Has.Count.EqualTo(1));
Assert.That(issues.Single().Template is CheckDrainTime.IssueTemplateTooShort);
Assert.That(issues.Single().Template is CheckDrainLength.IssueTemplateTooShort);
}
[Test]

View File

@ -110,6 +110,11 @@ namespace osu.Game.Beatmaps
/// </remarks>
public static double CalculatePlayableLength(this IBeatmap beatmap) => CalculatePlayableLength(beatmap.HitObjects);
/// <summary>
/// Find the total milliseconds between the first and last hittable objects, excluding any break time.
/// </summary>
public static double CalculateDrainLength(this IBeatmap beatmap) => CalculatePlayableLength(beatmap.HitObjects) - beatmap.TotalBreakTime;
/// <summary>
/// Find the timestamps in milliseconds of the start and end of the playable region.
/// </summary>

View File

@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Edit
new CheckUnsnappedObjects(),
new CheckConcurrentObjects(),
new CheckZeroLengthObjects(),
new CheckDrainTime(),
new CheckDrainLength(),
// Timing
new CheckPreviewTime(),

View File

@ -7,10 +7,11 @@ using osu.Game.Rulesets.Edit.Checks.Components;
namespace osu.Game.Rulesets.Edit.Checks
{
public class CheckDrainTime : ICheck
public class CheckDrainLength : ICheck
{
private const int min_drain_threshold = 30 * 1000;
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Compose, "Too short drain time");
public CheckMetadata Metadata => new CheckMetadata(CheckCategory.Compose, "Drain length is too short");
public IEnumerable<IssueTemplate> PossibleTemplates => new IssueTemplate[]
{
@ -19,7 +20,7 @@ namespace osu.Game.Rulesets.Edit.Checks
public IEnumerable<Issue> Run(BeatmapVerifierContext context)
{
double drainTime = context.Beatmap.CalculatePlayableLength() - context.Beatmap.TotalBreakTime;
double drainTime = context.Beatmap.CalculateDrainLength();
if (drainTime < min_drain_threshold)
yield return new IssueTemplateTooShort(this).Create((int)(drainTime / 1000));

View File

@ -352,29 +352,6 @@ namespace osu.Game.Screens.Select
if (working.Beatmap?.HitObjects.Any() != true)
return;
infoLabelContainer.Children = new Drawable[]
{
new InfoLabel(new BeatmapStatistic
{
Name = "Length",
CreateIcon = () => new BeatmapStatisticIcon(BeatmapStatisticsIconType.Length),
Content = working.BeatmapInfo.Length.ToFormattedDuration().ToString(),
}),
bpmLabelContainer = new Container
{
AutoSizeAxes = Axes.Both,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(20, 0),
Children = getRulesetInfoLabels()
}
};
}
private InfoLabel[] getRulesetInfoLabels()
{
try
{
IBeatmap playableBeatmap;
@ -390,14 +367,30 @@ namespace osu.Game.Screens.Select
playableBeatmap = working.GetPlayableBeatmap(working.BeatmapInfo.Ruleset, Array.Empty<Mod>());
}
return playableBeatmap.GetStatistics().Select(s => new InfoLabel(s)).ToArray();
infoLabelContainer.Children = new Drawable[]
{
new InfoLabel(new BeatmapStatistic
{
Name = $"Length (Drain: {playableBeatmap.CalculateDrainLength().ToFormattedDuration().ToString()})",
CreateIcon = () => new BeatmapStatisticIcon(BeatmapStatisticsIconType.Length),
Content = working.BeatmapInfo.Length.ToFormattedDuration().ToString(),
}),
bpmLabelContainer = new Container
{
AutoSizeAxes = Axes.Both,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(20, 0),
Children = playableBeatmap.GetStatistics().Select(s => new InfoLabel(s)).ToArray()
}
};
}
catch (Exception e)
{
Logger.Error(e, "Could not load beatmap successfully!");
}
return Array.Empty<InfoLabel>();
}
private void refreshBPMLabel()