Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust BeatmapInfoWedge's beatmap length field according to mod rate #26060

Merged
merged 4 commits into from
Dec 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapInfoWedge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#nullable disable

using System;
using System.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
Expand All @@ -14,6 +15,7 @@
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Extensions;
using osu.Game.Graphics.Sprites;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets;
Expand Down Expand Up @@ -194,6 +196,36 @@ private void checkDisplayedBPM(string target)
});
}

[TestCase]
public void TestLengthUpdates()
{
IBeatmap beatmap = createTestBeatmap(new OsuRuleset().RulesetInfo);
double drain = beatmap.CalculateDrainLength();
beatmap.BeatmapInfo.Length = drain;

OsuModDoubleTime doubleTime = null;

selectBeatmap(beatmap);
checkDisplayedLength(drain);

AddStep("select DT", () => SelectedMods.Value = new[] { doubleTime = new OsuModDoubleTime() });
checkDisplayedLength(Math.Round(drain / 1.5f));

AddStep("change DT rate", () => doubleTime.SpeedChange.Value = 2);
checkDisplayedLength(Math.Round(drain / 2));
}

private void checkDisplayedLength(double drain)
{
var displayedLength = drain.ToFormattedDuration();

AddUntilStep($"check map drain ({displayedLength})", () =>
{
var label = infoWedge.DisplayedContent.ChildrenOfType<BeatmapInfoWedge.WedgeInfoText.InfoLabel>().Single(l => l.Statistic.Name == BeatmapsetsStrings.ShowStatsTotalLength(displayedLength));
return label.Statistic.Content == displayedLength.ToString();
});
}

private void setRuleset(RulesetInfo rulesetInfo)
{
Container containerBefore = null;
Expand Down
25 changes: 17 additions & 8 deletions osu.Game/Screens/Select/BeatmapInfoWedge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ public partial class WedgeInfoText : Container
private ILocalisedBindableString artistBinding;
private FillFlowContainer infoLabelContainer;
private Container bpmLabelContainer;
private Container lengthLabelContainer;

private readonly WorkingBeatmap working;
private readonly RulesetInfo ruleset;
Expand Down Expand Up @@ -341,10 +342,10 @@ protected override void LoadComplete()
{
settingChangeTracker?.Dispose();

refreshBPMLabel();
refreshBPMAndLengthLabel();

settingChangeTracker = new ModSettingChangeTracker(m.NewValue);
settingChangeTracker.SettingChanged += _ => refreshBPMLabel();
settingChangeTracker.SettingChanged += _ => refreshBPMAndLengthLabel();
}, true);
}

Expand All @@ -370,12 +371,10 @@ private void addInfoLabels()

infoLabelContainer.Children = new Drawable[]
{
new InfoLabel(new BeatmapStatistic
lengthLabelContainer = new Container
{
Name = BeatmapsetsStrings.ShowStatsTotalLength(playableBeatmap.CalculateDrainLength().ToFormattedDuration()),
CreateIcon = () => new BeatmapStatisticIcon(BeatmapStatisticsIconType.Length),
Content = working.BeatmapInfo.Length.ToFormattedDuration().ToString(),
}),
AutoSizeAxes = Axes.Both,
},
bpmLabelContainer = new Container
{
AutoSizeAxes = Axes.Both,
Expand All @@ -394,7 +393,7 @@ private void addInfoLabels()
}
}

private void refreshBPMLabel()
private void refreshBPMAndLengthLabel()
{
var beatmap = working.Beatmap;

Expand All @@ -420,6 +419,16 @@ private void refreshBPMLabel()
CreateIcon = () => new BeatmapStatisticIcon(BeatmapStatisticsIconType.Bpm),
Content = labelText
});

double drainLength = Math.Round(beatmap.CalculateDrainLength() / rate);
double hitLength = Math.Round(beatmap.BeatmapInfo.Length / rate);

lengthLabelContainer.Child = new InfoLabel(new BeatmapStatistic
{
Name = BeatmapsetsStrings.ShowStatsTotalLength(drainLength.ToFormattedDuration()),
CreateIcon = () => new BeatmapStatisticIcon(BeatmapStatisticsIconType.Length),
Content = hitLength.ToFormattedDuration().ToString(),
});
}

private Drawable getMapper(BeatmapMetadata metadata)
Expand Down
Loading