2020-02-18 22:25:12 +08:00
|
|
|
|
// 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.
|
|
|
|
|
|
2020-11-10 15:26:30 +08:00
|
|
|
|
using System;
|
2020-02-18 22:25:12 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2021-09-10 00:57:55 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2020-02-18 22:25:12 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2020-11-10 15:26:30 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-09-10 00:57:55 +08:00
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2021-01-12 16:10:25 +08:00
|
|
|
|
using osu.Game.Configuration;
|
2020-02-18 22:25:12 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-09-10 00:57:55 +08:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2021-10-29 16:58:46 +08:00
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2021-06-16 12:46:13 +08:00
|
|
|
|
using osu.Game.Resources.Localisation.Web;
|
2020-03-06 07:12:30 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2020-10-29 04:35:08 +08:00
|
|
|
|
using osu.Game.Scoring;
|
2021-09-10 00:57:55 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2020-02-18 22:25:12 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.BeatmapListing
|
|
|
|
|
{
|
2020-04-21 14:13:19 +08:00
|
|
|
|
public class BeatmapListingSearchControl : CompositeDrawable
|
2020-02-18 22:25:12 +08:00
|
|
|
|
{
|
2020-11-10 15:26:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Any time the text box receives key events (even while masked).
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Action TypingStarted;
|
|
|
|
|
|
2020-03-06 07:12:30 +08:00
|
|
|
|
public Bindable<string> Query => textBox.Current;
|
|
|
|
|
|
2021-03-26 06:20:10 +08:00
|
|
|
|
public BindableList<SearchGeneral> General => generalFilter.Current;
|
|
|
|
|
|
2020-03-06 07:12:30 +08:00
|
|
|
|
public Bindable<RulesetInfo> Ruleset => modeFilter.Current;
|
|
|
|
|
|
2020-04-21 14:37:50 +08:00
|
|
|
|
public Bindable<SearchCategory> Category => categoryFilter.Current;
|
2020-03-06 07:12:30 +08:00
|
|
|
|
|
2020-04-21 14:37:50 +08:00
|
|
|
|
public Bindable<SearchGenre> Genre => genreFilter.Current;
|
2020-03-06 07:12:30 +08:00
|
|
|
|
|
2020-04-21 14:37:50 +08:00
|
|
|
|
public Bindable<SearchLanguage> Language => languageFilter.Current;
|
2020-02-20 22:56:49 +08:00
|
|
|
|
|
2020-10-29 00:44:13 +08:00
|
|
|
|
public BindableList<SearchExtra> Extra => extraFilter.Current;
|
2020-10-28 02:22:20 +08:00
|
|
|
|
|
2020-10-29 04:35:08 +08:00
|
|
|
|
public BindableList<ScoreRank> Ranks => ranksFilter.Current;
|
2020-10-28 04:14:48 +08:00
|
|
|
|
|
2020-10-28 02:30:53 +08:00
|
|
|
|
public Bindable<SearchPlayed> Played => playedFilter.Current;
|
|
|
|
|
|
2021-01-17 21:40:24 +08:00
|
|
|
|
public Bindable<SearchExplicit> ExplicitContent => explicitContentFilter.Current;
|
2021-01-12 16:09:55 +08:00
|
|
|
|
|
2021-10-29 16:58:46 +08:00
|
|
|
|
public APIBeatmapSet BeatmapSet
|
2020-02-18 22:25:12 +08:00
|
|
|
|
{
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-10-29 16:58:46 +08:00
|
|
|
|
if (value == null || string.IsNullOrEmpty(value.Covers.Cover))
|
2020-02-18 22:25:12 +08:00
|
|
|
|
{
|
|
|
|
|
beatmapCover.FadeOut(600, Easing.OutQuint);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 16:58:46 +08:00
|
|
|
|
beatmapCover.OnlineInfo = value;
|
2020-02-18 22:25:12 +08:00
|
|
|
|
beatmapCover.FadeTo(0.1f, 200, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-18 22:40:12 +08:00
|
|
|
|
private readonly BeatmapSearchTextBox textBox;
|
2021-03-26 06:20:10 +08:00
|
|
|
|
private readonly BeatmapSearchMultipleSelectionFilterRow<SearchGeneral> generalFilter;
|
2020-02-18 22:25:12 +08:00
|
|
|
|
private readonly BeatmapSearchRulesetFilterRow modeFilter;
|
2020-04-21 14:37:50 +08:00
|
|
|
|
private readonly BeatmapSearchFilterRow<SearchCategory> categoryFilter;
|
|
|
|
|
private readonly BeatmapSearchFilterRow<SearchGenre> genreFilter;
|
|
|
|
|
private readonly BeatmapSearchFilterRow<SearchLanguage> languageFilter;
|
2020-10-28 07:28:31 +08:00
|
|
|
|
private readonly BeatmapSearchMultipleSelectionFilterRow<SearchExtra> extraFilter;
|
2020-10-29 04:35:08 +08:00
|
|
|
|
private readonly BeatmapSearchScoreFilterRow ranksFilter;
|
2020-10-28 02:30:53 +08:00
|
|
|
|
private readonly BeatmapSearchFilterRow<SearchPlayed> playedFilter;
|
2021-01-17 21:40:24 +08:00
|
|
|
|
private readonly BeatmapSearchFilterRow<SearchExplicit> explicitContentFilter;
|
2020-02-18 22:25:12 +08:00
|
|
|
|
|
|
|
|
|
private readonly Box background;
|
2021-10-21 15:53:50 +08:00
|
|
|
|
private readonly UpdateableOnlineBeatmapSetCover beatmapCover;
|
2020-02-18 22:25:12 +08:00
|
|
|
|
|
2020-04-21 14:13:19 +08:00
|
|
|
|
public BeatmapListingSearchControl()
|
2020-02-18 22:25:12 +08:00
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y;
|
|
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
AddRangeInternal(new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
background = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Masking = true,
|
2021-05-07 08:36:30 +08:00
|
|
|
|
Child = beatmapCover = new TopSearchBeatmapSetCover
|
2020-02-18 22:25:12 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Padding = new MarginPadding
|
|
|
|
|
{
|
|
|
|
|
Vertical = 20,
|
|
|
|
|
Horizontal = 40,
|
|
|
|
|
},
|
|
|
|
|
Child = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Spacing = new Vector2(0, 20),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2020-02-18 22:40:12 +08:00
|
|
|
|
textBox = new BeatmapSearchTextBox
|
2020-02-18 22:25:12 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2021-09-10 00:57:55 +08:00
|
|
|
|
TextChanged = () => TypingStarted?.Invoke(),
|
2020-02-18 22:25:12 +08:00
|
|
|
|
},
|
|
|
|
|
new ReverseChildIDFillFlowContainer<Drawable>
|
|
|
|
|
{
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
Padding = new MarginPadding { Horizontal = 10 },
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2021-09-07 16:31:54 +08:00
|
|
|
|
generalFilter = new BeatmapSearchGeneralFilterRow(),
|
2020-02-18 22:25:12 +08:00
|
|
|
|
modeFilter = new BeatmapSearchRulesetFilterRow(),
|
2021-06-16 12:46:13 +08:00
|
|
|
|
categoryFilter = new BeatmapSearchFilterRow<SearchCategory>(BeatmapsStrings.ListingSearchFiltersStatus),
|
|
|
|
|
genreFilter = new BeatmapSearchFilterRow<SearchGenre>(BeatmapsStrings.ListingSearchFiltersGenre),
|
|
|
|
|
languageFilter = new BeatmapSearchFilterRow<SearchLanguage>(BeatmapsStrings.ListingSearchFiltersLanguage),
|
|
|
|
|
extraFilter = new BeatmapSearchMultipleSelectionFilterRow<SearchExtra>(BeatmapsStrings.ListingSearchFiltersExtra),
|
2020-10-29 04:35:08 +08:00
|
|
|
|
ranksFilter = new BeatmapSearchScoreFilterRow(),
|
2021-06-16 12:46:13 +08:00
|
|
|
|
playedFilter = new BeatmapSearchFilterRow<SearchPlayed>(BeatmapsStrings.ListingSearchFiltersPlayed),
|
|
|
|
|
explicitContentFilter = new BeatmapSearchFilterRow<SearchExplicit>(BeatmapsStrings.ListingSearchFiltersNsfw),
|
2020-02-18 22:25:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-02-20 09:19:50 +08:00
|
|
|
|
|
2020-04-21 14:37:50 +08:00
|
|
|
|
categoryFilter.Current.Value = SearchCategory.Leaderboard;
|
2020-02-18 22:25:12 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-12 16:10:25 +08:00
|
|
|
|
private IBindable<bool> allowExplicitContent;
|
|
|
|
|
|
2020-02-18 22:25:12 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2021-01-12 16:10:25 +08:00
|
|
|
|
private void load(OverlayColourProvider colourProvider, OsuConfigManager config)
|
2020-02-18 22:25:12 +08:00
|
|
|
|
{
|
|
|
|
|
background.Colour = colourProvider.Dark6;
|
2021-01-12 16:10:25 +08:00
|
|
|
|
|
2021-01-17 21:40:24 +08:00
|
|
|
|
allowExplicitContent = config.GetBindable<bool>(OsuSetting.ShowOnlineExplicitContent);
|
2021-01-12 16:10:25 +08:00
|
|
|
|
allowExplicitContent.BindValueChanged(allow =>
|
|
|
|
|
{
|
2021-01-17 21:40:24 +08:00
|
|
|
|
ExplicitContent.Value = allow.NewValue ? SearchExplicit.Show : SearchExplicit.Hide;
|
2021-01-12 16:10:25 +08:00
|
|
|
|
}, true);
|
2020-02-18 22:25:12 +08:00
|
|
|
|
}
|
2020-02-18 22:40:12 +08:00
|
|
|
|
|
2020-04-21 14:47:43 +08:00
|
|
|
|
public void TakeFocus() => textBox.TakeFocus();
|
|
|
|
|
|
2020-02-18 22:40:12 +08:00
|
|
|
|
private class BeatmapSearchTextBox : SearchTextBox
|
|
|
|
|
{
|
2020-11-10 15:26:30 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Any time the text box receives key events (even while masked).
|
|
|
|
|
/// </summary>
|
2021-09-10 00:57:55 +08:00
|
|
|
|
public Action TextChanged;
|
2020-11-10 15:26:30 +08:00
|
|
|
|
|
2020-02-18 22:40:12 +08:00
|
|
|
|
protected override Color4 SelectionColour => Color4.Gray;
|
|
|
|
|
|
|
|
|
|
public BeatmapSearchTextBox()
|
|
|
|
|
{
|
2021-06-16 12:46:13 +08:00
|
|
|
|
PlaceholderText = BeatmapsStrings.ListingSearchPrompt;
|
2020-02-18 22:40:12 +08:00
|
|
|
|
}
|
2020-11-10 15:26:30 +08:00
|
|
|
|
|
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
|
{
|
2020-11-10 15:32:58 +08:00
|
|
|
|
if (!base.OnKeyDown(e))
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-10 00:57:55 +08:00
|
|
|
|
TextChanged?.Invoke();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 17:26:12 +08:00
|
|
|
|
public override bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2021-09-10 00:57:55 +08:00
|
|
|
|
{
|
2021-09-16 17:26:12 +08:00
|
|
|
|
if (!base.OnPressed(e))
|
2021-09-10 00:57:55 +08:00
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
TextChanged?.Invoke();
|
2020-11-10 15:32:58 +08:00
|
|
|
|
return true;
|
2020-11-10 15:26:30 +08:00
|
|
|
|
}
|
2020-02-18 22:40:12 +08:00
|
|
|
|
}
|
2021-05-07 08:36:30 +08:00
|
|
|
|
|
2021-10-21 15:53:50 +08:00
|
|
|
|
private class TopSearchBeatmapSetCover : UpdateableOnlineBeatmapSetCover
|
2021-05-07 08:36:30 +08:00
|
|
|
|
{
|
|
|
|
|
protected override bool TransformImmediately => true;
|
|
|
|
|
}
|
2020-02-18 22:25:12 +08:00
|
|
|
|
}
|
|
|
|
|
}
|