1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 06:57:39 +08:00

Merge pull request #11473 from frenzibyte/explicit-search-control

Add "explicit maps" search filter control to beatmap listing
This commit is contained in:
Dean Herbert 2021-01-17 23:27:15 +09:00 committed by GitHub
commit 5e0fcc4a6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 109 additions and 37 deletions

View File

@ -7,6 +7,7 @@ using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing;
@ -19,9 +20,18 @@ namespace osu.Game.Tests.Visual.UserInterface
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private readonly BeatmapListingSearchControl control;
private BeatmapListingSearchControl control;
public TestSceneBeatmapListingSearchControl()
private OsuConfigManager localConfig;
[BackgroundDependencyLoader]
private void load()
{
Dependencies.Cache(localConfig = new OsuConfigManager(LocalStorage));
}
[SetUp]
public void SetUp() => Schedule(() =>
{
OsuSpriteText query;
OsuSpriteText ruleset;
@ -31,30 +41,34 @@ namespace osu.Game.Tests.Visual.UserInterface
OsuSpriteText extra;
OsuSpriteText ranks;
OsuSpriteText played;
OsuSpriteText explicitMap;
Add(control = new BeatmapListingSearchControl
Children = new Drawable[]
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
});
Add(new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
Children = new Drawable[]
control = new BeatmapListingSearchControl
{
query = new OsuSpriteText(),
ruleset = new OsuSpriteText(),
category = new OsuSpriteText(),
genre = new OsuSpriteText(),
language = new OsuSpriteText(),
extra = new OsuSpriteText(),
ranks = new OsuSpriteText(),
played = new OsuSpriteText()
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Vertical,
Spacing = new Vector2(0, 5),
Children = new Drawable[]
{
query = new OsuSpriteText(),
ruleset = new OsuSpriteText(),
category = new OsuSpriteText(),
genre = new OsuSpriteText(),
language = new OsuSpriteText(),
extra = new OsuSpriteText(),
ranks = new OsuSpriteText(),
played = new OsuSpriteText(),
explicitMap = new OsuSpriteText(),
}
}
});
};
control.Query.BindValueChanged(q => query.Text = $"Query: {q.NewValue}", true);
control.Ruleset.BindValueChanged(r => ruleset.Text = $"Ruleset: {r.NewValue}", true);
@ -64,7 +78,8 @@ namespace osu.Game.Tests.Visual.UserInterface
control.Extra.BindCollectionChanged((u, v) => extra.Text = $"Extra: {(control.Extra.Any() ? string.Join('.', control.Extra.Select(i => i.ToString().ToLowerInvariant())) : "")}", true);
control.Ranks.BindCollectionChanged((u, v) => ranks.Text = $"Ranks: {(control.Ranks.Any() ? string.Join('.', control.Ranks.Select(i => i.ToString())) : "")}", true);
control.Played.BindValueChanged(p => played.Text = $"Played: {p.NewValue}", true);
}
control.ExplicitContent.BindValueChanged(e => explicitMap.Text = $"Explicit Maps: {e.NewValue}", true);
});
[Test]
public void TestCovers()
@ -74,6 +89,22 @@ namespace osu.Game.Tests.Visual.UserInterface
AddStep("Set null beatmap", () => control.BeatmapSet = null);
}
[Test]
public void TestExplicitConfig()
{
AddStep("configure explicit content to allowed", () => localConfig.Set(OsuSetting.ShowOnlineExplicitContent, true));
AddAssert("explicit control set to show", () => control.ExplicitContent.Value == SearchExplicit.Show);
AddStep("configure explicit content to disallowed", () => localConfig.Set(OsuSetting.ShowOnlineExplicitContent, false));
AddAssert("explicit control set to hide", () => control.ExplicitContent.Value == SearchExplicit.Hide);
}
protected override void Dispose(bool isDisposing)
{
localConfig?.Dispose();
base.Dispose(isDisposing);
}
private static readonly BeatmapSetInfo beatmap_set = new BeatmapSetInfo
{
OnlineInfo = new BeatmapSetOnlineInfo

View File

@ -60,6 +60,8 @@ namespace osu.Game.Configuration
Set(OsuSetting.ExternalLinkWarning, true);
Set(OsuSetting.PreferNoVideo, false);
Set(OsuSetting.ShowOnlineExplicitContent, false);
// Audio
Set(OsuSetting.VolumeInactive, 0.25, 0, 1, 0.01);
@ -270,5 +272,6 @@ namespace osu.Game.Configuration
EditorWaveformOpacity,
DiscordRichPresence,
AutomaticallyDownloadWhenSpectating,
ShowOnlineExplicitContent,
}
}

View File

@ -30,6 +30,8 @@ namespace osu.Game.Online.API.Requests
public SearchPlayed Played { get; }
public SearchExplicit ExplicitContent { get; }
[CanBeNull]
public IReadOnlyCollection<ScoreRank> Ranks { get; }
@ -50,7 +52,8 @@ namespace osu.Game.Online.API.Requests
SearchLanguage language = SearchLanguage.Any,
IReadOnlyCollection<SearchExtra> extra = null,
IReadOnlyCollection<ScoreRank> ranks = null,
SearchPlayed played = SearchPlayed.Any)
SearchPlayed played = SearchPlayed.Any,
SearchExplicit explicitContent = SearchExplicit.Hide)
{
this.query = string.IsNullOrEmpty(query) ? string.Empty : System.Uri.EscapeDataString(query);
this.ruleset = ruleset;
@ -64,6 +67,7 @@ namespace osu.Game.Online.API.Requests
Extra = extra;
Ranks = ranks;
Played = played;
ExplicitContent = explicitContent;
}
protected override WebRequest CreateWebRequest()
@ -93,6 +97,8 @@ namespace osu.Game.Online.API.Requests
if (Played != SearchPlayed.Any)
req.AddParameter("played", Played.ToString().ToLowerInvariant());
req.AddParameter("nsfw", ExplicitContent == SearchExplicit.Show ? "true" : "false");
req.AddCursor(cursor);
return req;

View File

@ -141,6 +141,7 @@ namespace osu.Game.Overlays.BeatmapListing
searchControl.Extra.CollectionChanged += (_, __) => queueUpdateSearch();
searchControl.Ranks.CollectionChanged += (_, __) => queueUpdateSearch();
searchControl.Played.BindValueChanged(_ => queueUpdateSearch());
searchControl.ExplicitContent.BindValueChanged(_ => queueUpdateSearch());
sortCriteria.BindValueChanged(_ => queueUpdateSearch());
sortDirection.BindValueChanged(_ => queueUpdateSearch());
@ -193,7 +194,8 @@ namespace osu.Game.Overlays.BeatmapListing
searchControl.Language.Value,
searchControl.Extra,
searchControl.Ranks,
searchControl.Played.Value);
searchControl.Played.Value,
searchControl.ExplicitContent.Value);
getSetsRequest.Success += response =>
{

View File

@ -11,6 +11,7 @@ using osu.Framework.Bindables;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osuTK.Graphics;
@ -42,6 +43,8 @@ namespace osu.Game.Overlays.BeatmapListing
public Bindable<SearchPlayed> Played => playedFilter.Current;
public Bindable<SearchExplicit> ExplicitContent => explicitContentFilter.Current;
public BeatmapSetInfo BeatmapSet
{
set
@ -65,6 +68,7 @@ namespace osu.Game.Overlays.BeatmapListing
private readonly BeatmapSearchMultipleSelectionFilterRow<SearchExtra> extraFilter;
private readonly BeatmapSearchScoreFilterRow ranksFilter;
private readonly BeatmapSearchFilterRow<SearchPlayed> playedFilter;
private readonly BeatmapSearchFilterRow<SearchExplicit> explicitContentFilter;
private readonly Box background;
private readonly UpdateableBeatmapSetCover beatmapCover;
@ -125,7 +129,8 @@ namespace osu.Game.Overlays.BeatmapListing
languageFilter = new BeatmapSearchFilterRow<SearchLanguage>(@"Language"),
extraFilter = new BeatmapSearchMultipleSelectionFilterRow<SearchExtra>(@"Extra"),
ranksFilter = new BeatmapSearchScoreFilterRow(),
playedFilter = new BeatmapSearchFilterRow<SearchPlayed>(@"Played")
playedFilter = new BeatmapSearchFilterRow<SearchPlayed>(@"Played"),
explicitContentFilter = new BeatmapSearchFilterRow<SearchExplicit>(@"Explicit Content"),
}
}
}
@ -136,10 +141,18 @@ namespace osu.Game.Overlays.BeatmapListing
categoryFilter.Current.Value = SearchCategory.Leaderboard;
}
private IBindable<bool> allowExplicitContent;
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
private void load(OverlayColourProvider colourProvider, OsuConfigManager config)
{
background.Colour = colourProvider.Dark6;
allowExplicitContent = config.GetBindable<bool>(OsuSetting.ShowOnlineExplicitContent);
allowExplicitContent.BindValueChanged(allow =>
{
ExplicitContent.Value = allow.NewValue ? SearchExplicit.Show : SearchExplicit.Hide;
}, true);
}
public void TakeFocus() => textBox.TakeFocus();

View File

@ -205,7 +205,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
if (SetInfo.OnlineInfo?.HasExplicitContent ?? false)
{
titleContainer.Add(new ExplicitBeatmapPill
titleContainer.Add(new ExplicitContentBeatmapPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,

View File

@ -219,7 +219,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels
if (SetInfo.OnlineInfo?.HasExplicitContent ?? false)
{
titleContainer.Add(new ExplicitBeatmapPill
titleContainer.Add(new ExplicitContentBeatmapPill
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,

View File

@ -0,0 +1,11 @@
// 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.
namespace osu.Game.Overlays.BeatmapListing
{
public enum SearchExplicit
{
Hide,
Show
}
}

View File

@ -10,9 +10,9 @@ using osu.Game.Graphics.Sprites;
namespace osu.Game.Overlays.BeatmapSet
{
public class ExplicitBeatmapPill : CompositeDrawable
public class ExplicitContentBeatmapPill : CompositeDrawable
{
public ExplicitBeatmapPill()
public ExplicitContentBeatmapPill()
{
AutoSizeAxes = Axes.Both;
}

View File

@ -34,7 +34,7 @@ namespace osu.Game.Overlays.BeatmapSet
private readonly Box coverGradient;
private readonly OsuSpriteText title, artist;
private readonly AuthorInfo author;
private readonly ExplicitBeatmapPill explicitPill;
private readonly ExplicitContentBeatmapPill explicitContentPill;
private readonly FillFlowContainer downloadButtonsContainer;
private readonly BeatmapAvailability beatmapAvailability;
private readonly BeatmapSetOnlineStatusPill onlineStatusPill;
@ -147,7 +147,7 @@ namespace osu.Game.Overlays.BeatmapSet
Origin = Anchor.BottomLeft,
Margin = new MarginPadding { Left = 5, Bottom = 4 }, // To better lineup with the font
},
explicitPill = new ExplicitBeatmapPill
explicitContentPill = new ExplicitContentBeatmapPill
{
Alpha = 0f,
Anchor = Anchor.BottomLeft,
@ -261,7 +261,7 @@ namespace osu.Game.Overlays.BeatmapSet
title.Text = setInfo.NewValue.Metadata.Title ?? string.Empty;
artist.Text = setInfo.NewValue.Metadata.Artist ?? string.Empty;
explicitPill.Alpha = setInfo.NewValue.OnlineInfo.HasExplicitContent ? 1 : 0;
explicitContentPill.Alpha = setInfo.NewValue.OnlineInfo.HasExplicitContent ? 1 : 0;
onlineStatusPill.FadeIn(500, Easing.OutQuint);
onlineStatusPill.Status = setInfo.NewValue.OnlineInfo.Status;

View File

@ -33,6 +33,12 @@ namespace osu.Game.Overlays.Settings.Sections.Online
Keywords = new[] { "spectator" },
Current = config.GetBindable<bool>(OsuSetting.AutomaticallyDownloadWhenSpectating),
},
new SettingsCheckbox
{
LabelText = "Show explicit content in search results",
Keywords = new[] { "nsfw", "18+", "offensive" },
Current = config.GetBindable<bool>(OsuSetting.ShowOnlineExplicitContent),
}
};
}
}

View File

@ -42,7 +42,7 @@ namespace osu.Game.Screens.OnlinePlay
private Container difficultyIconContainer;
private LinkFlowContainer beatmapText;
private LinkFlowContainer authorText;
private ExplicitBeatmapPill explicitPill;
private ExplicitContentBeatmapPill explicitContentPill;
private ModDisplay modDisplay;
private readonly Bindable<BeatmapInfo> beatmap = new Bindable<BeatmapInfo>();
@ -119,7 +119,7 @@ namespace osu.Game.Screens.OnlinePlay
}
bool hasExplicitContent = Item.Beatmap.Value.BeatmapSet.OnlineInfo?.HasExplicitContent == true;
explicitPill.Alpha = hasExplicitContent ? 1 : 0;
explicitContentPill.Alpha = hasExplicitContent ? 1 : 0;
modDisplay.Current.Value = requiredMods.ToArray();
}
@ -181,7 +181,7 @@ namespace osu.Game.Screens.OnlinePlay
Children = new Drawable[]
{
authorText = new LinkFlowContainer { AutoSizeAxes = Axes.Both },
explicitPill = new ExplicitBeatmapPill
explicitContentPill = new ExplicitContentBeatmapPill
{
Alpha = 0f,
Anchor = Anchor.CentreLeft,