mirror of
https://github.com/ppy/osu
synced 2024-12-27 01:12:45 +00: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:
commit
6b009adf04
@ -54,6 +54,8 @@ namespace osu.Game.Tests.Visual.Online
|
||||
{
|
||||
overlay.ShowBeatmapSet(new APIBeatmapSet
|
||||
{
|
||||
Genre = new BeatmapSetOnlineGenre { Id = 15, Name = "Future genre" },
|
||||
Language = new BeatmapSetOnlineLanguage { Id = 15, Name = "Future language" },
|
||||
OnlineID = 1235,
|
||||
Title = @"an awesome beatmap",
|
||||
Artist = @"naru narusegawa",
|
||||
|
@ -341,6 +341,8 @@ namespace osu.Game.Online.Chat
|
||||
OpenWiki,
|
||||
Custom,
|
||||
OpenChangelog,
|
||||
FilterBeatmapSetGenre,
|
||||
FilterBeatmapSetLanguage,
|
||||
}
|
||||
|
||||
public class Link : IComparable<Link>
|
||||
|
@ -46,6 +46,7 @@ using osu.Game.Online;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Online.Chat;
|
||||
using osu.Game.Overlays;
|
||||
using osu.Game.Overlays.BeatmapListing;
|
||||
using osu.Game.Overlays.Music;
|
||||
using osu.Game.Overlays.Notifications;
|
||||
using osu.Game.Overlays.Toolbar;
|
||||
@ -359,6 +360,14 @@ namespace osu.Game
|
||||
SearchBeatmapSet(argString);
|
||||
break;
|
||||
|
||||
case LinkAction.FilterBeatmapSetGenre:
|
||||
FilterBeatmapSetGenre((SearchGenre)link.Argument);
|
||||
break;
|
||||
|
||||
case LinkAction.FilterBeatmapSetLanguage:
|
||||
FilterBeatmapSetLanguage((SearchLanguage)link.Argument);
|
||||
break;
|
||||
|
||||
case LinkAction.OpenEditorTimestamp:
|
||||
case LinkAction.JoinMultiplayerMatch:
|
||||
case LinkAction.Spectate:
|
||||
@ -463,6 +472,10 @@ namespace osu.Game
|
||||
/// <param name="query">The query to search for.</param>
|
||||
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>
|
||||
/// Show a wiki's page as an overlay
|
||||
/// </summary>
|
||||
|
@ -145,6 +145,12 @@ namespace osu.Game.Overlays.BeatmapListing
|
||||
public void Search(string 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()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
@ -110,6 +110,18 @@ namespace osu.Game.Overlays
|
||||
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 Color4 BackgroundColour => ColourProvider.Background6;
|
||||
|
@ -8,9 +8,11 @@ using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.API.Requests.Responses;
|
||||
using osu.Game.Overlays.BeatmapListing;
|
||||
|
||||
namespace osu.Game.Overlays.BeatmapSet
|
||||
{
|
||||
@ -34,7 +36,9 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
|
||||
public Info()
|
||||
{
|
||||
MetadataSection source, tags, genre, language;
|
||||
MetadataSection source, tags;
|
||||
MetadataSectionGenre genre;
|
||||
MetadataSectionLanguage language;
|
||||
OsuSpriteText notRankedPlaceholder;
|
||||
|
||||
RelativeSizeAxes = Axes.X;
|
||||
@ -59,7 +63,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
Child = new Container
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new MetadataSection(MetadataType.Description),
|
||||
Child = new MetadataSectionDescription(),
|
||||
},
|
||||
},
|
||||
new Container
|
||||
@ -76,12 +80,12 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Direction = FillDirection.Full,
|
||||
Children = new[]
|
||||
Children = new Drawable[]
|
||||
{
|
||||
source = new MetadataSection(MetadataType.Source),
|
||||
genre = new MetadataSection(MetadataType.Genre) { Width = 0.5f },
|
||||
language = new MetadataSection(MetadataType.Language) { Width = 0.5f },
|
||||
tags = new MetadataSection(MetadataType.Tags),
|
||||
source = new MetadataSectionSource(),
|
||||
genre = new MetadataSectionGenre { Width = 0.5f },
|
||||
language = new MetadataSectionLanguage { Width = 0.5f },
|
||||
tags = new MetadataSectionTags(),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -118,10 +122,10 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
|
||||
BeatmapSet.ValueChanged += b =>
|
||||
{
|
||||
source.Text = b.NewValue?.Source ?? string.Empty;
|
||||
tags.Text = b.NewValue?.Tags ?? string.Empty;
|
||||
genre.Text = b.NewValue?.Genre.Name ?? string.Empty;
|
||||
language.Text = b.NewValue?.Language.Name ?? string.Empty;
|
||||
source.Metadata = b.NewValue?.Source ?? string.Empty;
|
||||
tags.Metadata = b.NewValue?.Tags ?? string.Empty;
|
||||
genre.Metadata = b.NewValue?.Genre ?? new BeatmapSetOnlineGenre { Id = (int)SearchGenre.Unspecified };
|
||||
language.Metadata = b.NewValue?.Language ?? new BeatmapSetOnlineLanguage { Id = (int)SearchLanguage.Unspecified };
|
||||
bool setHasLeaderboard = b.NewValue?.Status > 0;
|
||||
successRate.Alpha = setHasLeaderboard ? 1 : 0;
|
||||
notRankedPlaceholder.Alpha = setHasLeaderboard ? 0 : 1;
|
||||
|
@ -1,8 +1,6 @@
|
||||
// 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.
|
||||
|
||||
#nullable disable
|
||||
|
||||
using System;
|
||||
using osu.Framework.Extensions;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
@ -11,26 +9,45 @@ using osu.Framework.Graphics.Containers;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Online.Chat;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
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 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;
|
||||
this.searchAction = searchAction;
|
||||
SearchAction = searchAction;
|
||||
|
||||
Alpha = 0;
|
||||
|
||||
@ -53,7 +70,7 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Child = new OsuSpriteText
|
||||
{
|
||||
Text = this.type.GetLocalisableDescription(),
|
||||
Text = type.GetLocalisableDescription(),
|
||||
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
|
||||
{
|
||||
if (string.IsNullOrEmpty(value))
|
||||
if (value == null)
|
||||
{
|
||||
this.FadeOut(transition_duration);
|
||||
this.FadeOut(TRANSITION_DURATION);
|
||||
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))
|
||||
{
|
||||
@ -88,44 +105,15 @@ namespace osu.Game.Overlays.BeatmapSet
|
||||
{
|
||||
textFlow?.Expire();
|
||||
|
||||
switch (type)
|
||||
{
|
||||
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;
|
||||
}
|
||||
AddMetadata(metadata, loaded);
|
||||
|
||||
textContainer.Add(textFlow = loaded);
|
||||
|
||||
// fade in if we haven't yet.
|
||||
textContainer.FadeIn(transition_duration);
|
||||
textContainer.FadeIn(TRANSITION_DURATION);
|
||||
});
|
||||
}
|
||||
|
||||
protected abstract void AddMetadata(T metadata, LinkFlowContainer loaded);
|
||||
}
|
||||
}
|
||||
|
21
osu.Game/Overlays/BeatmapSet/MetadataSectionDescription.cs
Normal file
21
osu.Game/Overlays/BeatmapSet/MetadataSectionDescription.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
30
osu.Game/Overlays/BeatmapSet/MetadataSectionGenre.cs
Normal file
30
osu.Game/Overlays/BeatmapSet/MetadataSectionGenre.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
30
osu.Game/Overlays/BeatmapSet/MetadataSectionLanguage.cs
Normal file
30
osu.Game/Overlays/BeatmapSet/MetadataSectionLanguage.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
25
osu.Game/Overlays/BeatmapSet/MetadataSectionSource.cs
Normal file
25
osu.Game/Overlays/BeatmapSet/MetadataSectionSource.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
35
osu.Game/Overlays/BeatmapSet/MetadataSectionTags.cs
Normal file
35
osu.Game/Overlays/BeatmapSet/MetadataSectionTags.cs
Normal 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(" ");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -141,9 +141,9 @@ namespace osu.Game.Screens.Select
|
||||
LayoutEasing = Easing.OutQuad,
|
||||
Children = new[]
|
||||
{
|
||||
description = new MetadataSection(MetadataType.Description, searchOnSongSelect),
|
||||
source = new MetadataSection(MetadataType.Source, searchOnSongSelect),
|
||||
tags = new MetadataSection(MetadataType.Tags, searchOnSongSelect),
|
||||
description = new MetadataSectionDescription(searchOnSongSelect),
|
||||
source = new MetadataSectionSource(searchOnSongSelect),
|
||||
tags = new MetadataSectionTags(searchOnSongSelect),
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -187,9 +187,9 @@ namespace osu.Game.Screens.Select
|
||||
private void updateStatistics()
|
||||
{
|
||||
advanced.BeatmapInfo = BeatmapInfo;
|
||||
description.Text = BeatmapInfo?.DifficultyName;
|
||||
source.Text = BeatmapInfo?.Metadata.Source;
|
||||
tags.Text = BeatmapInfo?.Metadata.Tags;
|
||||
description.Metadata = BeatmapInfo?.DifficultyName ?? string.Empty;
|
||||
source.Metadata = BeatmapInfo?.Metadata.Source ?? string.Empty;
|
||||
tags.Metadata = BeatmapInfo?.Metadata.Tags ?? string.Empty;
|
||||
|
||||
// failTimes may have been previously fetched
|
||||
if (ratings != null && failTimes != null)
|
||||
|
Loading…
Reference in New Issue
Block a user