mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 23:05:34 +08:00
Implement BeatmapSearchParameters and refactor all the components
This commit is contained in:
parent
20b49bea4b
commit
3c56118f45
@ -11,6 +11,7 @@ using osu.Game.Beatmaps;
|
|||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osu.Game.Overlays.BeatmapListing;
|
using osu.Game.Overlays.BeatmapListing;
|
||||||
|
using osu.Game.Online.API.Requests;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual.UserInterface
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
@ -32,6 +33,8 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
OsuSpriteText query;
|
OsuSpriteText query;
|
||||||
OsuSpriteText ruleset;
|
OsuSpriteText ruleset;
|
||||||
OsuSpriteText category;
|
OsuSpriteText category;
|
||||||
|
OsuSpriteText genre;
|
||||||
|
OsuSpriteText language;
|
||||||
|
|
||||||
Add(section = new BeatmapListingSearchSection
|
Add(section = new BeatmapListingSearchSection
|
||||||
{
|
{
|
||||||
@ -49,12 +52,19 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
query = new OsuSpriteText(),
|
query = new OsuSpriteText(),
|
||||||
ruleset = new OsuSpriteText(),
|
ruleset = new OsuSpriteText(),
|
||||||
category = new OsuSpriteText(),
|
category = new OsuSpriteText(),
|
||||||
|
genre = new OsuSpriteText(),
|
||||||
|
language = new OsuSpriteText(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
section.Query.BindValueChanged(q => query.Text = $"Query: {q.NewValue}", true);
|
section.SearchParameters.BindValueChanged(parameters =>
|
||||||
section.Ruleset.BindValueChanged(r => ruleset.Text = $"Ruleset: {r.NewValue}", true);
|
{
|
||||||
section.Category.BindValueChanged(c => category.Text = $"Category: {c.NewValue}", true);
|
query.Text = $"Query: {parameters.NewValue.Query}";
|
||||||
|
ruleset.Text = $"Ruleset: {parameters.NewValue.Ruleset}";
|
||||||
|
category.Text = $"Category: {parameters.NewValue.Category}";
|
||||||
|
genre.Text = $"Genre: {parameters.NewValue.Genre}";
|
||||||
|
language.Text = $"Language: {parameters.NewValue.Language}";
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Test]
|
[Test]
|
||||||
@ -65,6 +75,17 @@ namespace osu.Game.Tests.Visual.UserInterface
|
|||||||
AddStep("Set null beatmap", () => section.BeatmapSet = null);
|
AddStep("Set null beatmap", () => section.BeatmapSet = null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestParametersSet()
|
||||||
|
{
|
||||||
|
AddStep("Set big black tag", () => section.SetTag("big black"));
|
||||||
|
AddAssert("Check query is big black", () => section.SearchParameters.Value.Query == "big black");
|
||||||
|
AddStep("Set anime genre", () => section.SetGenre(BeatmapSearchGenre.Anime));
|
||||||
|
AddAssert("Check genre is anime", () => section.SearchParameters.Value.Genre == BeatmapSearchGenre.Anime);
|
||||||
|
AddStep("Set japanese language", () => section.SetLanguage(BeatmapSearchLanguage.Japanese));
|
||||||
|
AddAssert("Check language is japanese", () => section.SearchParameters.Value.Language == BeatmapSearchLanguage.Japanese);
|
||||||
|
}
|
||||||
|
|
||||||
private static readonly BeatmapSetInfo beatmap_set = new BeatmapSetInfo
|
private static readonly BeatmapSetInfo beatmap_set = new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
OnlineInfo = new BeatmapSetOnlineInfo
|
OnlineInfo = new BeatmapSetOnlineInfo
|
||||||
|
@ -6,7 +6,6 @@ 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.Online.API.Requests;
|
using osu.Game.Online.API.Requests;
|
||||||
using osu.Game.Rulesets;
|
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Beatmaps.Drawables;
|
using osu.Game.Beatmaps.Drawables;
|
||||||
@ -19,15 +18,7 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
{
|
{
|
||||||
public class BeatmapListingSearchSection : CompositeDrawable
|
public class BeatmapListingSearchSection : CompositeDrawable
|
||||||
{
|
{
|
||||||
public Bindable<string> Query => textBox.Current;
|
public Bindable<BeatmapSearchParameters> SearchParameters = new Bindable<BeatmapSearchParameters>();
|
||||||
|
|
||||||
public Bindable<RulesetInfo> Ruleset => modeFilter.Current;
|
|
||||||
|
|
||||||
public Bindable<BeatmapSearchCategory> Category => categoryFilter.Current;
|
|
||||||
|
|
||||||
public Bindable<BeatmapSearchGenre> Genre => genreFilter.Current;
|
|
||||||
|
|
||||||
public Bindable<BeatmapSearchLanguage> Language => languageFilter.Current;
|
|
||||||
|
|
||||||
public BeatmapSetInfo BeatmapSet
|
public BeatmapSetInfo BeatmapSet
|
||||||
{
|
{
|
||||||
@ -113,7 +104,13 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Category.Value = BeatmapSearchCategory.Leaderboard;
|
categoryFilter.Current.Value = BeatmapSearchCategory.Leaderboard;
|
||||||
|
|
||||||
|
textBox.Current.BindValueChanged(_ => changeSearchParameters());
|
||||||
|
modeFilter.Current.BindValueChanged(_ => changeSearchParameters());
|
||||||
|
categoryFilter.Current.BindValueChanged(_ => changeSearchParameters());
|
||||||
|
genreFilter.Current.BindValueChanged(_ => changeSearchParameters());
|
||||||
|
languageFilter.Current.BindValueChanged(_ => changeSearchParameters(), true);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -122,6 +119,22 @@ namespace osu.Game.Overlays.BeatmapListing
|
|||||||
background.Colour = colourProvider.Dark6;
|
background.Colour = colourProvider.Dark6;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void SetTag(string tag) => textBox.Current.Value = tag;
|
||||||
|
|
||||||
|
public void SetGenre(BeatmapSearchGenre genre) => genreFilter.Current.Value = genre;
|
||||||
|
|
||||||
|
public void SetLanguage(BeatmapSearchLanguage language) => languageFilter.Current.Value = language;
|
||||||
|
|
||||||
|
private void changeSearchParameters()
|
||||||
|
{
|
||||||
|
SearchParameters.Value = new BeatmapSearchParameters(
|
||||||
|
textBox.Current.Value,
|
||||||
|
modeFilter.Current.Value,
|
||||||
|
categoryFilter.Current.Value,
|
||||||
|
genreFilter.Current.Value,
|
||||||
|
languageFilter.Current.Value);
|
||||||
|
}
|
||||||
|
|
||||||
private class BeatmapSearchTextBox : SearchTextBox
|
private class BeatmapSearchTextBox : SearchTextBox
|
||||||
{
|
{
|
||||||
protected override Color4 SelectionColour => Color4.Gray;
|
protected override Color4 SelectionColour => Color4.Gray;
|
||||||
|
30
osu.Game/Overlays/BeatmapListing/BeatmapSearchParameters.cs
Normal file
30
osu.Game/Overlays/BeatmapListing/BeatmapSearchParameters.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 osu.Game.Online.API.Requests;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
|
||||||
|
namespace osu.Game.Overlays.BeatmapListing
|
||||||
|
{
|
||||||
|
public class BeatmapSearchParameters
|
||||||
|
{
|
||||||
|
public readonly string Query;
|
||||||
|
|
||||||
|
public readonly RulesetInfo Ruleset;
|
||||||
|
|
||||||
|
public readonly BeatmapSearchCategory Category;
|
||||||
|
|
||||||
|
public readonly BeatmapSearchGenre Genre;
|
||||||
|
|
||||||
|
public readonly BeatmapSearchLanguage Language;
|
||||||
|
|
||||||
|
public BeatmapSearchParameters(string query, RulesetInfo ruleset, BeatmapSearchCategory category, BeatmapSearchGenre genre, BeatmapSearchLanguage language)
|
||||||
|
{
|
||||||
|
Query = query;
|
||||||
|
Ruleset = ruleset;
|
||||||
|
Category = category;
|
||||||
|
Genre = genre;
|
||||||
|
Language = language;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -144,70 +144,43 @@ namespace osu.Game.Overlays
|
|||||||
var sortCriteria = sortControl.Current;
|
var sortCriteria = sortControl.Current;
|
||||||
var sortDirection = sortControl.SortDirection;
|
var sortDirection = sortControl.SortDirection;
|
||||||
|
|
||||||
searchSection.Query.BindValueChanged(query =>
|
searchSection.SearchParameters.BindValueChanged(parameters =>
|
||||||
{
|
{
|
||||||
sortCriteria.Value = string.IsNullOrEmpty(query.NewValue) ? DirectSortCriteria.Ranked : DirectSortCriteria.Relevance;
|
if (parameters.OldValue.Query != parameters.NewValue.Query)
|
||||||
sortDirection.Value = SortDirection.Descending;
|
{
|
||||||
|
sortCriteria.Value = string.IsNullOrEmpty(parameters.NewValue.Query) ? DirectSortCriteria.Ranked : DirectSortCriteria.Relevance;
|
||||||
|
sortDirection.Value = SortDirection.Descending;
|
||||||
|
|
||||||
queueUpdateSearch(true);
|
queueUpdateSearch(true);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
queueUpdateSearch();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
searchSection.Ruleset.BindValueChanged(_ => queueUpdateSearch());
|
|
||||||
searchSection.Category.BindValueChanged(_ => queueUpdateSearch());
|
|
||||||
searchSection.Genre.BindValueChanged(_ => queueUpdateSearch());
|
|
||||||
searchSection.Language.BindValueChanged(_ => queueUpdateSearch());
|
|
||||||
sortCriteria.BindValueChanged(_ => queueUpdateSearch());
|
sortCriteria.BindValueChanged(_ => queueUpdateSearch());
|
||||||
sortDirection.BindValueChanged(_ => queueUpdateSearch());
|
sortDirection.BindValueChanged(_ => queueUpdateSearch());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowTag(string tag)
|
public void ShowTag(string tag)
|
||||||
{
|
{
|
||||||
var currentQuery = searchSection.Query.Value;
|
searchSection.SetTag(tag);
|
||||||
|
|
||||||
if (currentQuery != tag)
|
|
||||||
{
|
|
||||||
setDefaultSearchValues();
|
|
||||||
searchSection.Query.Value = tag;
|
|
||||||
}
|
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowGenre(BeatmapSearchGenre genre)
|
public void ShowGenre(BeatmapSearchGenre genre)
|
||||||
{
|
{
|
||||||
var currentGenre = searchSection.Genre.Value;
|
searchSection.SetGenre(genre);
|
||||||
|
|
||||||
if (currentGenre != genre)
|
|
||||||
{
|
|
||||||
setDefaultSearchValues();
|
|
||||||
searchSection.Genre.Value = genre;
|
|
||||||
}
|
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShowLanguage(BeatmapSearchLanguage language)
|
public void ShowLanguage(BeatmapSearchLanguage language)
|
||||||
{
|
{
|
||||||
var currentLanguage = searchSection.Language.Value;
|
searchSection.SetLanguage(language);
|
||||||
|
|
||||||
if (currentLanguage != language)
|
|
||||||
{
|
|
||||||
setDefaultSearchValues();
|
|
||||||
searchSection.Language.Value = language;
|
|
||||||
}
|
|
||||||
|
|
||||||
Show();
|
Show();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setDefaultSearchValues()
|
|
||||||
{
|
|
||||||
searchSection.Query.Value = string.Empty;
|
|
||||||
searchSection.Ruleset.Value = new RulesetInfo { Name = @"Any" };
|
|
||||||
searchSection.Category.Value = BeatmapSearchCategory.Leaderboard;
|
|
||||||
searchSection.Genre.Value = BeatmapSearchGenre.Any;
|
|
||||||
searchSection.Language.Value = BeatmapSearchLanguage.Any;
|
|
||||||
}
|
|
||||||
|
|
||||||
private ScheduledDelegate queryChangedDebounce;
|
private ScheduledDelegate queryChangedDebounce;
|
||||||
|
|
||||||
private void queueUpdateSearch(bool queryTextChanged = false)
|
private void queueUpdateSearch(bool queryTextChanged = false)
|
||||||
@ -233,13 +206,13 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
currentContent?.FadeColour(Color4.DimGray, 400, Easing.OutQuint);
|
currentContent?.FadeColour(Color4.DimGray, 400, Easing.OutQuint);
|
||||||
|
|
||||||
getSetsRequest = new SearchBeatmapSetsRequest(searchSection.Query.Value, searchSection.Ruleset.Value)
|
getSetsRequest = new SearchBeatmapSetsRequest(searchSection.SearchParameters.Value.Query, searchSection.SearchParameters.Value.Ruleset)
|
||||||
{
|
{
|
||||||
SearchCategory = searchSection.Category.Value,
|
SearchCategory = searchSection.SearchParameters.Value.Category,
|
||||||
SortCriteria = sortControl.Current.Value,
|
SortCriteria = sortControl.Current.Value,
|
||||||
SortDirection = sortControl.SortDirection.Value,
|
SortDirection = sortControl.SortDirection.Value,
|
||||||
Genre = searchSection.Genre.Value,
|
Genre = searchSection.SearchParameters.Value.Genre,
|
||||||
Language = searchSection.Language.Value,
|
Language = searchSection.SearchParameters.Value.Language
|
||||||
};
|
};
|
||||||
|
|
||||||
getSetsRequest.Success += response => Schedule(() => recreatePanels(response));
|
getSetsRequest.Success += response => Schedule(() => recreatePanels(response));
|
||||||
|
Loading…
Reference in New Issue
Block a user