Skip to content

Commit

Permalink
Make labels disappear on null beatmap/no hitobjects
Browse files Browse the repository at this point in the history
  • Loading branch information
smoogipoo committed Feb 25, 2021
1 parent c3eb441 commit 01a4815
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 29 deletions.
7 changes: 4 additions & 3 deletions osu.Game.Tests/Visual/SongSelect/TestSceneBeatmapInfoWedge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets;
Expand Down Expand Up @@ -111,8 +112,8 @@ private void testBeatmapLabels(Ruleset ruleset)

private void testInfoLabels(int expectedCount)
{
AddAssert("check info labels exists", () => infoWedge.Info.InfoLabelContainer.Children.Any());
AddAssert("check info labels count", () => infoWedge.Info.InfoLabelContainer.Children.Count == expectedCount);
AddAssert("check info labels exists", () => infoWedge.Info.ChildrenOfType<BeatmapInfoWedge.BufferedWedgeInfo.InfoLabel>().Any());
AddAssert("check info labels count", () => infoWedge.Info.ChildrenOfType<BeatmapInfoWedge.BufferedWedgeInfo.InfoLabel>().Count() == expectedCount);
}

[Test]
Expand All @@ -123,7 +124,7 @@ public void TestNullBeatmap()
AddAssert("check default title", () => infoWedge.Info.TitleLabel.Current.Value == Beatmap.Default.BeatmapInfo.Metadata.Title);
AddAssert("check default artist", () => infoWedge.Info.ArtistLabel.Current.Value == Beatmap.Default.BeatmapInfo.Metadata.Artist);
AddAssert("check empty author", () => !infoWedge.Info.MapperContainer.Children.Any());
AddAssert("check no info labels", () => !infoWedge.Info.InfoLabelContainer.Children.Any());
AddAssert("check no info labels", () => !infoWedge.Info.ChildrenOfType<BeatmapInfoWedge.BufferedWedgeInfo.InfoLabel>().Any());
}

[Test]
Expand Down
61 changes: 35 additions & 26 deletions osu.Game/Screens/Select/BeatmapInfoWedge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ public class BufferedWedgeInfo : BufferedContainer
public OsuSpriteText ArtistLabel { get; private set; }
public BeatmapSetOnlineStatusPill StatusPill { get; private set; }
public FillFlowContainer MapperContainer { get; private set; }
public FillFlowContainer InfoLabelContainer { get; private set; }

private ILocalisedBindableString titleBinding;
private ILocalisedBindableString artistBinding;
private FillFlowContainer infoLabelContainer;
private Container bpmLabelContainer;

private readonly WorkingBeatmap beatmap;
Expand Down Expand Up @@ -194,9 +194,6 @@ private void load(LocalisationManager localisation)
CacheDrawnFrameBuffer = true;
RelativeSizeAxes = Axes.Both;

settingChangeTracker = new ModSettingChangeTracker(mods);
settingChangeTracker.SettingChanged += _ => updateBPM();

titleBinding = localisation.GetLocalisedString(new RomanisableString(metadata.TitleUnicode, metadata.Title));
artistBinding = localisation.GetLocalisedString(new RomanisableString(metadata.ArtistUnicode, metadata.Artist));

Expand Down Expand Up @@ -312,30 +309,11 @@ private void load(LocalisationManager localisation)
AutoSizeAxes = Axes.Both,
Children = getMapper(metadata)
},
InfoLabelContainer = new FillFlowContainer
infoLabelContainer = new FillFlowContainer
{
Margin = new MarginPadding { Top = 20 },
Spacing = new Vector2(20, 0),
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new InfoLabel(new BeatmapStatistic
{
Name = "Length",
CreateIcon = () => new BeatmapStatisticIcon(BeatmapStatisticsIconType.Length),
Content = TimeSpan.FromMilliseconds(beatmapInfo.Length).ToString(@"m\:ss"),
}),
bpmLabelContainer = new Container
{
AutoSizeAxes = Axes.Both,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(20, 0),
Children = getRulesetInfoLabels()
}
}
}
}
}
Expand All @@ -348,7 +326,7 @@ private void load(LocalisationManager localisation)
if (beatmapInfo.Version == null)
StatusPill.Hide();

updateBPM();
addInfoLabels();
}

private static Drawable createStarRatingDisplay(StarDifficulty difficulty) => difficulty.Stars > 0
Expand All @@ -365,6 +343,37 @@ private void setMetadata(string source)
ForceRedraw();
}

private void addInfoLabels()
{
if (beatmap.Beatmap?.HitObjects?.Any() != true)
return;

infoLabelContainer.Children = new Drawable[]
{
new InfoLabel(new BeatmapStatistic
{
Name = "Length",
CreateIcon = () => new BeatmapStatisticIcon(BeatmapStatisticsIconType.Length),
Content = TimeSpan.FromMilliseconds(beatmap.BeatmapInfo.Length).ToString(@"m\:ss"),
}),
bpmLabelContainer = new Container
{
AutoSizeAxes = Axes.Both,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(20, 0),
Children = getRulesetInfoLabels()
}
};

settingChangeTracker = new ModSettingChangeTracker(mods);
settingChangeTracker.SettingChanged += _ => refreshBPMLabel();

refreshBPMLabel();
}

private InfoLabel[] getRulesetInfoLabels()
{
try
Expand Down Expand Up @@ -392,7 +401,7 @@ private InfoLabel[] getRulesetInfoLabels()
return Array.Empty<InfoLabel>();
}

private void updateBPM()
private void refreshBPMLabel()
{
var b = beatmap.Beatmap;
if (b == null)
Expand Down

0 comments on commit 01a4815

Please sign in to comment.