1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 14:25:05 +08:00

Merge pull request #21727 from Joehuu/beatmap-set-link-genre-language

Link beatmap set genre and language to listing filters
This commit is contained in:
Dean Herbert 2023-01-06 17:57:45 +08:00 committed by GitHub
commit 6b009adf04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 236 additions and 68 deletions

View File

@ -54,6 +54,8 @@ namespace osu.Game.Tests.Visual.Online
{ {
overlay.ShowBeatmapSet(new APIBeatmapSet overlay.ShowBeatmapSet(new APIBeatmapSet
{ {
Genre = new BeatmapSetOnlineGenre { Id = 15, Name = "Future genre" },
Language = new BeatmapSetOnlineLanguage { Id = 15, Name = "Future language" },
OnlineID = 1235, OnlineID = 1235,
Title = @"an awesome beatmap", Title = @"an awesome beatmap",
Artist = @"naru narusegawa", Artist = @"naru narusegawa",

View File

@ -341,6 +341,8 @@ namespace osu.Game.Online.Chat
OpenWiki, OpenWiki,
Custom, Custom,
OpenChangelog, OpenChangelog,
FilterBeatmapSetGenre,
FilterBeatmapSetLanguage,
} }
public class Link : IComparable<Link> public class Link : IComparable<Link>

View File

@ -46,6 +46,7 @@ using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Chat; using osu.Game.Online.Chat;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing;
using osu.Game.Overlays.Music; using osu.Game.Overlays.Music;
using osu.Game.Overlays.Notifications; using osu.Game.Overlays.Notifications;
using osu.Game.Overlays.Toolbar; using osu.Game.Overlays.Toolbar;
@ -359,6 +360,14 @@ namespace osu.Game
SearchBeatmapSet(argString); SearchBeatmapSet(argString);
break; break;
case LinkAction.FilterBeatmapSetGenre:
FilterBeatmapSetGenre((SearchGenre)link.Argument);
break;
case LinkAction.FilterBeatmapSetLanguage:
FilterBeatmapSetLanguage((SearchLanguage)link.Argument);
break;
case LinkAction.OpenEditorTimestamp: case LinkAction.OpenEditorTimestamp:
case LinkAction.JoinMultiplayerMatch: case LinkAction.JoinMultiplayerMatch:
case LinkAction.Spectate: case LinkAction.Spectate:
@ -463,6 +472,10 @@ namespace osu.Game
/// <param name="query">The query to search for.</param> /// <param name="query">The query to search for.</param>
public void SearchBeatmapSet(string query) => waitForReady(() => beatmapListing, _ => beatmapListing.ShowWithSearch(query)); public void SearchBeatmapSet(string query) => waitForReady(() => beatmapListing, _ => beatmapListing.ShowWithSearch(query));
public void FilterBeatmapSetGenre(SearchGenre genre) => waitForReady(() => beatmapListing, _ => beatmapListing.ShowWithGenreFilter(genre));
public void FilterBeatmapSetLanguage(SearchLanguage language) => waitForReady(() => beatmapListing, _ => beatmapListing.ShowWithLanguageFilter(language));
/// <summary> /// <summary>
/// Show a wiki's page as an overlay /// Show a wiki's page as an overlay
/// </summary> /// </summary>

View File

@ -145,6 +145,12 @@ namespace osu.Game.Overlays.BeatmapListing
public void Search(string query) public void Search(string query)
=> Schedule(() => searchControl.Query.Value = query); => Schedule(() => searchControl.Query.Value = query);
public void FilterGenre(SearchGenre genre)
=> Schedule(() => searchControl.Genre.Value = genre);
public void FilterLanguage(SearchLanguage language)
=> Schedule(() => searchControl.Language.Value = language);
protected override void LoadComplete() protected override void LoadComplete()
{ {
base.LoadComplete(); base.LoadComplete();

View File

@ -110,6 +110,18 @@ namespace osu.Game.Overlays
ScrollFlow.ScrollToStart(); ScrollFlow.ScrollToStart();
} }
public void ShowWithGenreFilter(SearchGenre genre)
{
ShowWithSearch(string.Empty);
filterControl.FilterGenre(genre);
}
public void ShowWithLanguageFilter(SearchLanguage language)
{
ShowWithSearch(string.Empty);
filterControl.FilterLanguage(language);
}
protected override BeatmapListingHeader CreateHeader() => new BeatmapListingHeader(); protected override BeatmapListingHeader CreateHeader() => new BeatmapListingHeader();
protected override Color4 BackgroundColour => ColourProvider.Background6; protected override Color4 BackgroundColour => ColourProvider.Background6;

View File

@ -8,9 +8,11 @@ using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays.BeatmapListing;
namespace osu.Game.Overlays.BeatmapSet namespace osu.Game.Overlays.BeatmapSet
{ {
@ -34,7 +36,9 @@ namespace osu.Game.Overlays.BeatmapSet
public Info() public Info()
{ {
MetadataSection source, tags, genre, language; MetadataSection source, tags;
MetadataSectionGenre genre;
MetadataSectionLanguage language;
OsuSpriteText notRankedPlaceholder; OsuSpriteText notRankedPlaceholder;
RelativeSizeAxes = Axes.X; RelativeSizeAxes = Axes.X;
@ -59,7 +63,7 @@ namespace osu.Game.Overlays.BeatmapSet
Child = new Container Child = new Container
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = new MetadataSection(MetadataType.Description), Child = new MetadataSectionDescription(),
}, },
}, },
new Container new Container
@ -76,12 +80,12 @@ namespace osu.Game.Overlays.BeatmapSet
RelativeSizeAxes = Axes.X, RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Direction = FillDirection.Full, Direction = FillDirection.Full,
Children = new[] Children = new Drawable[]
{ {
source = new MetadataSection(MetadataType.Source), source = new MetadataSectionSource(),
genre = new MetadataSection(MetadataType.Genre) { Width = 0.5f }, genre = new MetadataSectionGenre { Width = 0.5f },
language = new MetadataSection(MetadataType.Language) { Width = 0.5f }, language = new MetadataSectionLanguage { Width = 0.5f },
tags = new MetadataSection(MetadataType.Tags), tags = new MetadataSectionTags(),
}, },
}, },
}, },
@ -118,10 +122,10 @@ namespace osu.Game.Overlays.BeatmapSet
BeatmapSet.ValueChanged += b => BeatmapSet.ValueChanged += b =>
{ {
source.Text = b.NewValue?.Source ?? string.Empty; source.Metadata = b.NewValue?.Source ?? string.Empty;
tags.Text = b.NewValue?.Tags ?? string.Empty; tags.Metadata = b.NewValue?.Tags ?? string.Empty;
genre.Text = b.NewValue?.Genre.Name ?? string.Empty; genre.Metadata = b.NewValue?.Genre ?? new BeatmapSetOnlineGenre { Id = (int)SearchGenre.Unspecified };
language.Text = b.NewValue?.Language.Name ?? string.Empty; language.Metadata = b.NewValue?.Language ?? new BeatmapSetOnlineLanguage { Id = (int)SearchLanguage.Unspecified };
bool setHasLeaderboard = b.NewValue?.Status > 0; bool setHasLeaderboard = b.NewValue?.Status > 0;
successRate.Alpha = setHasLeaderboard ? 1 : 0; successRate.Alpha = setHasLeaderboard ? 1 : 0;
notRankedPlaceholder.Alpha = setHasLeaderboard ? 0 : 1; notRankedPlaceholder.Alpha = setHasLeaderboard ? 0 : 1;

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using osu.Framework.Extensions; using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
@ -11,26 +9,45 @@ using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Online.Chat;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
namespace osu.Game.Overlays.BeatmapSet namespace osu.Game.Overlays.BeatmapSet
{ {
public partial class MetadataSection : Container public abstract partial class MetadataSection : MetadataSection<string>
{
public override string Metadata
{
set
{
if (string.IsNullOrEmpty(value))
{
this.FadeOut(TRANSITION_DURATION);
return;
}
base.Metadata = value;
}
}
protected MetadataSection(MetadataType type, Action<string>? searchAction = null)
: base(type, searchAction)
{
}
}
public abstract partial class MetadataSection<T> : Container
{ {
private readonly FillFlowContainer textContainer; private readonly FillFlowContainer textContainer;
private readonly MetadataType type; private TextFlowContainer? textFlow;
private TextFlowContainer textFlow;
private readonly Action<string> searchAction; protected readonly Action<T>? SearchAction;
private const float transition_duration = 250; protected const float TRANSITION_DURATION = 250;
public MetadataSection(MetadataType type, Action<string> searchAction = null) protected MetadataSection(MetadataType type, Action<T>? searchAction = null)
{ {
this.type = type; SearchAction = searchAction;
this.searchAction = searchAction;
Alpha = 0; Alpha = 0;
@ -53,7 +70,7 @@ namespace osu.Game.Overlays.BeatmapSet
AutoSizeAxes = Axes.Y, AutoSizeAxes = Axes.Y,
Child = new OsuSpriteText Child = new OsuSpriteText
{ {
Text = this.type.GetLocalisableDescription(), Text = type.GetLocalisableDescription(),
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14), Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 14),
}, },
}, },
@ -61,23 +78,23 @@ namespace osu.Game.Overlays.BeatmapSet
}; };
} }
public string Text public virtual T Metadata
{ {
set set
{ {
if (string.IsNullOrEmpty(value)) if (value == null)
{ {
this.FadeOut(transition_duration); this.FadeOut(TRANSITION_DURATION);
return; return;
} }
this.FadeIn(transition_duration); this.FadeIn(TRANSITION_DURATION);
setTextAsync(value); setTextFlowAsync(value);
} }
} }
private void setTextAsync(string text) private void setTextFlowAsync(T metadata)
{ {
LoadComponentAsync(new LinkFlowContainer(s => s.Font = s.Font.With(size: 14)) LoadComponentAsync(new LinkFlowContainer(s => s.Font = s.Font.With(size: 14))
{ {
@ -88,44 +105,15 @@ namespace osu.Game.Overlays.BeatmapSet
{ {
textFlow?.Expire(); textFlow?.Expire();
switch (type) AddMetadata(metadata, loaded);
{
case MetadataType.Tags:
string[] tags = text.Split(" ");
for (int i = 0; i <= tags.Length - 1; i++)
{
string tag = tags[i];
if (searchAction != null)
loaded.AddLink(tag, () => searchAction(tag));
else
loaded.AddLink(tag, LinkAction.SearchBeatmapSet, tag);
if (i != tags.Length - 1)
loaded.AddText(" ");
}
break;
case MetadataType.Source:
if (searchAction != null)
loaded.AddLink(text, () => searchAction(text));
else
loaded.AddLink(text, LinkAction.SearchBeatmapSet, text);
break;
default:
loaded.AddText(text);
break;
}
textContainer.Add(textFlow = loaded); textContainer.Add(textFlow = loaded);
// fade in if we haven't yet. // fade in if we haven't yet.
textContainer.FadeIn(transition_duration); textContainer.FadeIn(TRANSITION_DURATION);
}); });
} }
protected abstract void AddMetadata(T metadata, LinkFlowContainer loaded);
} }
} }

View File

@ -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 System;
using osu.Game.Graphics.Containers;
namespace osu.Game.Overlays.BeatmapSet
{
public partial class MetadataSectionDescription : MetadataSection
{
public MetadataSectionDescription(Action<string>? searchAction = null)
: base(MetadataType.Description, searchAction)
{
}
protected override void AddMetadata(string metadata, LinkFlowContainer loaded)
{
loaded.AddText(metadata);
}
}
}

View File

@ -0,0 +1,30 @@
// 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 System;
using osu.Framework.Extensions;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Online.Chat;
using osu.Game.Overlays.BeatmapListing;
namespace osu.Game.Overlays.BeatmapSet
{
public partial class MetadataSectionGenre : MetadataSection<BeatmapSetOnlineGenre>
{
public MetadataSectionGenre(Action<BeatmapSetOnlineGenre>? searchAction = null)
: base(MetadataType.Genre, searchAction)
{
}
protected override void AddMetadata(BeatmapSetOnlineGenre metadata, LinkFlowContainer loaded)
{
var genre = (SearchGenre)metadata.Id;
if (Enum.IsDefined(genre))
loaded.AddLink(genre.GetLocalisableDescription(), LinkAction.FilterBeatmapSetGenre, genre);
else
loaded.AddText(metadata.Name);
}
}
}

View File

@ -0,0 +1,30 @@
// 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 System;
using osu.Framework.Extensions;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Online.Chat;
using osu.Game.Overlays.BeatmapListing;
namespace osu.Game.Overlays.BeatmapSet
{
public partial class MetadataSectionLanguage : MetadataSection<BeatmapSetOnlineLanguage>
{
public MetadataSectionLanguage(Action<BeatmapSetOnlineLanguage>? searchAction = null)
: base(MetadataType.Language, searchAction)
{
}
protected override void AddMetadata(BeatmapSetOnlineLanguage metadata, LinkFlowContainer loaded)
{
var language = (SearchLanguage)metadata.Id;
if (Enum.IsDefined(language))
loaded.AddLink(language.GetLocalisableDescription(), LinkAction.FilterBeatmapSetLanguage, language);
else
loaded.AddText(metadata.Name);
}
}
}

View File

@ -0,0 +1,25 @@
// 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 System;
using osu.Game.Graphics.Containers;
using osu.Game.Online.Chat;
namespace osu.Game.Overlays.BeatmapSet
{
public partial class MetadataSectionSource : MetadataSection
{
public MetadataSectionSource(Action<string>? searchAction = null)
: base(MetadataType.Source, searchAction)
{
}
protected override void AddMetadata(string metadata, LinkFlowContainer loaded)
{
if (SearchAction != null)
loaded.AddLink(metadata, () => SearchAction(metadata));
else
loaded.AddLink(metadata, LinkAction.SearchBeatmapSet, metadata);
}
}
}

View File

@ -0,0 +1,35 @@
// 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 System;
using osu.Game.Graphics.Containers;
using osu.Game.Online.Chat;
namespace osu.Game.Overlays.BeatmapSet
{
public partial class MetadataSectionTags : MetadataSection
{
public MetadataSectionTags(Action<string>? searchAction = null)
: base(MetadataType.Tags, searchAction)
{
}
protected override void AddMetadata(string metadata, LinkFlowContainer loaded)
{
string[] tags = metadata.Split(" ");
for (int i = 0; i <= tags.Length - 1; i++)
{
string tag = tags[i];
if (SearchAction != null)
loaded.AddLink(tag, () => SearchAction(tag));
else
loaded.AddLink(tag, LinkAction.SearchBeatmapSet, tag);
if (i != tags.Length - 1)
loaded.AddText(" ");
}
}
}
}

View File

@ -141,9 +141,9 @@ namespace osu.Game.Screens.Select
LayoutEasing = Easing.OutQuad, LayoutEasing = Easing.OutQuad,
Children = new[] Children = new[]
{ {
description = new MetadataSection(MetadataType.Description, searchOnSongSelect), description = new MetadataSectionDescription(searchOnSongSelect),
source = new MetadataSection(MetadataType.Source, searchOnSongSelect), source = new MetadataSectionSource(searchOnSongSelect),
tags = new MetadataSection(MetadataType.Tags, searchOnSongSelect), tags = new MetadataSectionTags(searchOnSongSelect),
}, },
}, },
}, },
@ -187,9 +187,9 @@ namespace osu.Game.Screens.Select
private void updateStatistics() private void updateStatistics()
{ {
advanced.BeatmapInfo = BeatmapInfo; advanced.BeatmapInfo = BeatmapInfo;
description.Text = BeatmapInfo?.DifficultyName; description.Metadata = BeatmapInfo?.DifficultyName ?? string.Empty;
source.Text = BeatmapInfo?.Metadata.Source; source.Metadata = BeatmapInfo?.Metadata.Source ?? string.Empty;
tags.Text = BeatmapInfo?.Metadata.Tags; tags.Metadata = BeatmapInfo?.Metadata.Tags ?? string.Empty;
// failTimes may have been previously fetched // failTimes may have been previously fetched
if (ratings != null && failTimes != null) if (ratings != null && failTimes != null)