1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 16:30:05 +08:00
osu-lazer/osu.Game/Overlays/BeatmapListing/BeatmapListingSearchControl.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

209 lines
8.2 KiB
C#
Raw Normal View History

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