Skip to content

Commit

Permalink
Merge pull request ppy#18263 from frenzibyte/spotlight-beatmap-badge
Browse files Browse the repository at this point in the history
Add support for "spotlight" label in beatmap overlay/listing
  • Loading branch information
peppy authored May 15, 2022
2 parents 351f5a3 + 4bb0687 commit 328561f
Show file tree
Hide file tree
Showing 12 changed files with 203 additions and 88 deletions.
17 changes: 12 additions & 5 deletions osu.Game.Tests/Visual/Beatmaps/TestSceneBeatmapCard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,20 +84,26 @@ private void load()
explicitMap.Title = someDifficulties.TitleUnicode = "explicit beatmap";
explicitMap.HasExplicitContent = true;

var spotlightMap = CreateAPIBeatmapSet(Ruleset.Value);
spotlightMap.Title = someDifficulties.TitleUnicode = "spotlight beatmap";
spotlightMap.FeaturedInSpotlight = true;

var featuredMap = CreateAPIBeatmapSet(Ruleset.Value);
featuredMap.Title = someDifficulties.TitleUnicode = "featured artist beatmap";
featuredMap.TrackId = 1;

var explicitFeaturedMap = CreateAPIBeatmapSet(Ruleset.Value);
explicitFeaturedMap.Title = someDifficulties.TitleUnicode = "explicit featured artist";
explicitFeaturedMap.HasExplicitContent = true;
explicitFeaturedMap.TrackId = 2;
var allBadgesMap = CreateAPIBeatmapSet(Ruleset.Value);
allBadgesMap.Title = someDifficulties.TitleUnicode = "all-badges beatmap";
allBadgesMap.HasExplicitContent = true;
allBadgesMap.FeaturedInSpotlight = true;
allBadgesMap.TrackId = 2;

var longName = CreateAPIBeatmapSet(Ruleset.Value);
longName.Title = longName.TitleUnicode = "this track has an incredibly and implausibly long title";
longName.Artist = longName.ArtistUnicode = "and this artist! who would have thunk it. it's really such a long name.";
longName.Source = "wow. even the source field has an impossibly long string in it. this really takes the cake, doesn't it?";
longName.HasExplicitContent = true;
longName.FeaturedInSpotlight = true;
longName.TrackId = 444;

testCases = new[]
Expand All @@ -108,8 +114,9 @@ private void load()
someDifficulties,
manyDifficulties,
explicitMap,
spotlightMap,
featuredMap,
explicitFeaturedMap,
allBadgesMap,
longName
};

Expand Down
24 changes: 24 additions & 0 deletions osu.Game.Tests/Visual/Online/TestSceneBeatmapSetOverlay.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ public void TestExplicitBeatmap()
});
}

[Test]
public void TestSpotlightBeatmap()
{
AddStep("show spotlight map", () =>
{
var beatmapSet = getBeatmapSet();
beatmapSet.FeaturedInSpotlight = true;
overlay.ShowBeatmapSet(beatmapSet);
});
}

[Test]
public void TestFeaturedBeatmap()
{
Expand All @@ -176,6 +187,19 @@ public void TestFeaturedBeatmap()
});
}

[Test]
public void TestAllBadgesBeatmap()
{
AddStep("show map with all badges", () =>
{
var beatmapSet = getBeatmapSet();
beatmapSet.HasExplicitContent = true;
beatmapSet.FeaturedInSpotlight = true;
beatmapSet.TrackId = 1;
overlay.ShowBeatmapSet(beatmapSet);
});
}

[Test]
public void TestHide()
{
Expand Down
30 changes: 23 additions & 7 deletions osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private void load(BeatmapSetOverlay? beatmapSetOverlay)
Height = height;

FillFlowContainer leftIconArea = null!;
GridContainer titleContainer = null!;
FillFlowContainer titleBadgeArea = null!;
GridContainer artistContainer = null!;

Child = content.With(c =>
Expand Down Expand Up @@ -93,7 +93,7 @@ private void load(BeatmapSetOverlay? beatmapSetOverlay)
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
titleContainer = new GridContainer
new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Expand All @@ -108,7 +108,7 @@ private void load(BeatmapSetOverlay? beatmapSetOverlay)
},
Content = new[]
{
new[]
new Drawable[]
{
new OsuSpriteText
{
Expand All @@ -117,7 +117,13 @@ private void load(BeatmapSetOverlay? beatmapSetOverlay)
RelativeSizeAxes = Axes.X,
Truncate = true
},
Empty()
titleBadgeArea = new FillFlowContainer
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
}
}
}
},
Expand Down Expand Up @@ -244,19 +250,29 @@ private void load(BeatmapSetOverlay? beatmapSetOverlay)
if (BeatmapSet.HasStoryboard)
leftIconArea.Add(new IconPill(FontAwesome.Solid.Image) { IconSize = new Vector2(20) });

if (BeatmapSet.FeaturedInSpotlight)
{
titleBadgeArea.Add(new SpotlightBeatmapBadge
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding { Left = 5 }
});
}

if (BeatmapSet.HasExplicitContent)
{
titleContainer.Content[0][1] = new ExplicitContentBeatmapPill
titleBadgeArea.Add(new ExplicitContentBeatmapBadge
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding { Left = 5 }
};
});
}

if (BeatmapSet.TrackId != null)
{
artistContainer.Content[0][1] = new FeaturedArtistBeatmapPill
artistContainer.Content[0][1] = new FeaturedArtistBeatmapBadge
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Expand Down
32 changes: 24 additions & 8 deletions osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void load()
Height = height;

FillFlowContainer leftIconArea = null!;
GridContainer titleContainer = null!;
FillFlowContainer titleBadgeArea = null!;
GridContainer artistContainer = null!;

Child = content.With(c =>
Expand Down Expand Up @@ -94,22 +94,22 @@ private void load()
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
titleContainer = new GridContainer
new GridContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
ColumnDimensions = new[]
{
new Dimension(),
new Dimension(GridSizeMode.AutoSize)
new Dimension(GridSizeMode.AutoSize),
},
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize)
},
Content = new[]
{
new[]
new Drawable[]
{
new OsuSpriteText
{
Expand All @@ -118,7 +118,13 @@ private void load()
RelativeSizeAxes = Axes.X,
Truncate = true
},
Empty()
titleBadgeArea = new FillFlowContainer
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
}
}
}
},
Expand Down Expand Up @@ -225,19 +231,29 @@ private void load()
if (BeatmapSet.HasStoryboard)
leftIconArea.Add(new IconPill(FontAwesome.Solid.Image) { IconSize = new Vector2(20) });

if (BeatmapSet.FeaturedInSpotlight)
{
titleBadgeArea.Add(new SpotlightBeatmapBadge
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding { Left = 5 }
});
}

if (BeatmapSet.HasExplicitContent)
{
titleContainer.Content[0][1] = new ExplicitContentBeatmapPill
titleBadgeArea.Add(new ExplicitContentBeatmapBadge
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Margin = new MarginPadding { Left = 5 }
};
});
}

if (BeatmapSet.TrackId != null)
{
artistContainer.Content[0][1] = new FeaturedArtistBeatmapPill
artistContainer.Content[0][1] = new FeaturedArtistBeatmapBadge
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
Expand Down
3 changes: 3 additions & 0 deletions osu.Game/Online/API/Requests/Responses/APIBeatmapSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class APIBeatmapSet : IBeatmapSetOnlineInfo, IBeatmapSetInfo
[JsonProperty(@"nsfw")]
public bool HasExplicitContent { get; set; }

[JsonProperty(@"spotlight")]
public bool FeaturedInSpotlight { get; set; }

[JsonProperty(@"video")]
public bool HasVideo { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,42 +6,62 @@
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Resources.Localisation.Web;

#nullable enable

namespace osu.Game.Overlays.BeatmapSet
{
public class ExplicitContentBeatmapPill : CompositeDrawable
public abstract class BeatmapBadge : CompositeDrawable
{
public ExplicitContentBeatmapPill()
/// <summary>
/// The text displayed on the badge's label.
/// </summary>
public LocalisableString BadgeText
{
AutoSizeAxes = Axes.Both;
set => badgeLabel.Text = value.ToUpper();
}

[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, OverlayColourProvider colourProvider)
/// <summary>
/// The colour of the badge's label.
/// </summary>
public Colour4 BadgeColour
{
set => badgeLabel.Colour = value;
}

private readonly Box background;
private readonly OsuSpriteText badgeLabel;

protected BeatmapBadge()
{
AutoSizeAxes = Axes.Both;

InternalChild = new CircularContainer
{
Masking = true,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new Box
background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider?.Background5 ?? colours.Gray2,
},
new OsuSpriteText
badgeLabel = new OsuSpriteText
{
Margin = new MarginPadding { Horizontal = 10f, Vertical = 2f },
Text = BeatmapsetsStrings.NsfwBadgeLabel.ToUpper(),
Font = OsuFont.GetFont(size: 10, weight: FontWeight.SemiBold),
Colour = colours.Orange2
Margin = new MarginPadding { Horizontal = 10, Vertical = 2 },
}
}
};
}

[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, OverlayColourProvider? colourProvider)
{
background.Colour = colourProvider?.Background5 ?? colours.Gray2;
}
}
}
23 changes: 17 additions & 6 deletions osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,11 @@ public class BeatmapSetHeaderContent : CompositeDrawable
private readonly Box coverGradient;
private readonly OsuSpriteText title, artist;
private readonly AuthorInfo author;
private readonly ExplicitContentBeatmapPill explicitContentPill;
private readonly FeaturedArtistBeatmapPill featuredArtistPill;

private readonly ExplicitContentBeatmapBadge explicitContent;
private readonly SpotlightBeatmapBadge spotlight;
private readonly FeaturedArtistBeatmapBadge featuredArtist;

private readonly FillFlowContainer downloadButtonsContainer;
private readonly BeatmapAvailability beatmapAvailability;
private readonly BeatmapSetOnlineStatusPill onlineStatusPill;
Expand Down Expand Up @@ -126,7 +129,14 @@ public BeatmapSetHeaderContent()
Origin = Anchor.BottomLeft,
Margin = new MarginPadding { Left = 5, Bottom = 4 }, // To better lineup with the font
},
explicitContentPill = new ExplicitContentBeatmapPill
explicitContent = new ExplicitContentBeatmapBadge
{
Alpha = 0f,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Margin = new MarginPadding { Left = 10, Bottom = 4 },
},
spotlight = new SpotlightBeatmapBadge
{
Alpha = 0f,
Anchor = Anchor.BottomLeft,
Expand All @@ -146,7 +156,7 @@ public BeatmapSetHeaderContent()
{
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Medium, italics: true),
},
featuredArtistPill = new FeaturedArtistBeatmapPill
featuredArtist = new FeaturedArtistBeatmapBadge
{
Alpha = 0f,
Anchor = Anchor.BottomLeft,
Expand Down Expand Up @@ -257,8 +267,9 @@ private void load(OverlayColourProvider colourProvider)
title.Text = new RomanisableString(setInfo.NewValue.TitleUnicode, setInfo.NewValue.Title);
artist.Text = new RomanisableString(setInfo.NewValue.ArtistUnicode, setInfo.NewValue.Artist);

explicitContentPill.Alpha = setInfo.NewValue.HasExplicitContent ? 1 : 0;
featuredArtistPill.Alpha = setInfo.NewValue.TrackId != null ? 1 : 0;
explicitContent.Alpha = setInfo.NewValue.HasExplicitContent ? 1 : 0;
spotlight.Alpha = setInfo.NewValue.FeaturedInSpotlight ? 1 : 0;
featuredArtist.Alpha = setInfo.NewValue.TrackId != null ? 1 : 0;

onlineStatusPill.FadeIn(500, Easing.OutQuint);
onlineStatusPill.Status = setInfo.NewValue.Status;
Expand Down
21 changes: 21 additions & 0 deletions osu.Game/Overlays/BeatmapSet/ExplicitContentBeatmapBadge.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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.

using osu.Framework.Allocation;
using osu.Game.Graphics;
using osu.Game.Resources.Localisation.Web;

#nullable enable

namespace osu.Game.Overlays.BeatmapSet
{
public class ExplicitContentBeatmapBadge : BeatmapBadge
{
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BadgeText = BeatmapsetsStrings.NsfwBadgeLabel;
BadgeColour = colours.Orange2;
}
}
}
Loading

0 comments on commit 328561f

Please sign in to comment.