From 7228900361b1f753b3b8e07e0d195eb7675c27e7 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 18 Feb 2020 17:25:12 +0300 Subject: [PATCH 1/4] Implement BeatmapListingSearchSection component --- .../TestSceneBeatmapListingSearchSection.cs | 61 ++++++++++ .../BeatmapListingSearchSection.cs | 114 ++++++++++++++++++ 2 files changed, 175 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs create mode 100644 osu.Game/Overlays/BeatmapListing/BeatmapListingSearchSection.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs new file mode 100644 index 0000000000..24dc013940 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs @@ -0,0 +1,61 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using System; +using System.Collections.Generic; +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Game.Beatmaps; +using osu.Game.Overlays; +using osu.Game.Overlays.BeatmapListing; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneBeatmapListingSearchSection : OsuTestScene + { + public override IReadOnlyList RequiredTypes => new[] + { + typeof(BeatmapListingSearchSection), + }; + + [Cached] + private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); + + public TestSceneBeatmapListingSearchSection() + { + BeatmapListingSearchSection section; + + Add(section = new BeatmapListingSearchSection + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }); + + var beatmapSet = new BeatmapSetInfo + { + OnlineInfo = new BeatmapSetOnlineInfo + { + Covers = new BeatmapSetOnlineCovers + { + Cover = "https://assets.ppy.sh/beatmaps/1094296/covers/cover@2x.jpg?1581416305" + } + } + }; + + var noCoverBeatmapSet = new BeatmapSetInfo + { + OnlineInfo = new BeatmapSetOnlineInfo + { + Covers = new BeatmapSetOnlineCovers + { + Cover = string.Empty + } + } + }; + + AddStep("Set beatmap", () => section.BeatmapSet = beatmapSet); + AddStep("Set beatmap (no cover)", () => section.BeatmapSet = noCoverBeatmapSet); + AddStep("Set null beatmap", () => section.BeatmapSet = null); + } + } +} diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingSearchSection.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingSearchSection.cs new file mode 100644 index 0000000000..16204c3e38 --- /dev/null +++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingSearchSection.cs @@ -0,0 +1,114 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +using osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Game.Online.API.Requests; +using osu.Game.Rulesets; +using osuTK; +using osu.Framework.Bindables; +using osu.Game.Beatmaps.Drawables; +using osu.Game.Beatmaps; +using osu.Game.Graphics.Containers; +using osu.Game.Graphics.UserInterface; + +namespace osu.Game.Overlays.BeatmapListing +{ + public class BeatmapListingSearchSection : CompositeDrawable + { + public Bindable Query => textBox.Current; + + public Bindable Ruleset => modeFilter.Current; + + public Bindable Category => categoryFilter.Current; + + public BeatmapSetInfo BeatmapSet + { + set + { + if (value == null) + { + beatmapCover.FadeOut(600, Easing.OutQuint); + return; + } + + beatmapCover.BeatmapSet = value; + beatmapCover.FadeTo(0.1f, 200, Easing.OutQuint); + } + } + + private readonly SearchTextBox textBox; + private readonly BeatmapSearchRulesetFilterRow modeFilter; + private readonly BeatmapSearchFilterRow categoryFilter; + + private readonly Box background; + private readonly UpdateableBeatmapSetCover beatmapCover; + + public BeatmapListingSearchSection() + { + 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 UpdateableBeatmapSetCover + { + 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[] + { + textBox = new SearchTextBox + { + RelativeSizeAxes = Axes.X, + }, + new ReverseChildIDFillFlowContainer + { + AutoSizeAxes = Axes.Y, + RelativeSizeAxes = Axes.X, + Direction = FillDirection.Vertical, + Padding = new MarginPadding { Horizontal = 10 }, + Children = new Drawable[] + { + modeFilter = new BeatmapSearchRulesetFilterRow(), + categoryFilter = new BeatmapSearchFilterRow(@"Categories"), + } + } + } + } + } + }); + } + + [BackgroundDependencyLoader] + private void load(OverlayColourProvider colourProvider) + { + background.Colour = colourProvider.Dark6; + } + } +} From b6423dd92ed8d30469fd335cc320de9589a5cb6b Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 18 Feb 2020 17:40:12 +0300 Subject: [PATCH 2/4] Small textbox adjustments --- .../Graphics/UserInterface/SearchTextBox.cs | 16 +++++++--------- .../BeatmapListingSearchSection.cs | 17 ++++++++++++++--- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/osu.Game/Graphics/UserInterface/SearchTextBox.cs b/osu.Game/Graphics/UserInterface/SearchTextBox.cs index fe8756a4d2..fe92054d25 100644 --- a/osu.Game/Graphics/UserInterface/SearchTextBox.cs +++ b/osu.Game/Graphics/UserInterface/SearchTextBox.cs @@ -17,18 +17,16 @@ namespace osu.Game.Graphics.UserInterface public SearchTextBox() { Height = 35; - AddRange(new Drawable[] + Add(new SpriteIcon { - new SpriteIcon - { - Icon = FontAwesome.Solid.Search, - Origin = Anchor.CentreRight, - Anchor = Anchor.CentreRight, - Margin = new MarginPadding { Right = 10 }, - Size = new Vector2(20), - } + Icon = FontAwesome.Solid.Search, + Origin = Anchor.CentreRight, + Anchor = Anchor.CentreRight, + Margin = new MarginPadding { Right = 10 }, + Size = new Vector2(20), }); + TextFlow.Padding = new MarginPadding { Right = 35 }; PlaceholderText = "type to search"; } diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingSearchSection.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingSearchSection.cs index 16204c3e38..f47144e5d8 100644 --- a/osu.Game/Overlays/BeatmapListing/BeatmapListingSearchSection.cs +++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingSearchSection.cs @@ -13,6 +13,7 @@ using osu.Game.Beatmaps.Drawables; using osu.Game.Beatmaps; using osu.Game.Graphics.Containers; using osu.Game.Graphics.UserInterface; +using osuTK.Graphics; namespace osu.Game.Overlays.BeatmapListing { @@ -28,7 +29,7 @@ namespace osu.Game.Overlays.BeatmapListing { set { - if (value == null) + if (value == null || string.IsNullOrEmpty(value.OnlineInfo.Covers.Cover)) { beatmapCover.FadeOut(600, Easing.OutQuint); return; @@ -39,7 +40,7 @@ namespace osu.Game.Overlays.BeatmapListing } } - private readonly SearchTextBox textBox; + private readonly BeatmapSearchTextBox textBox; private readonly BeatmapSearchRulesetFilterRow modeFilter; private readonly BeatmapSearchFilterRow categoryFilter; @@ -83,7 +84,7 @@ namespace osu.Game.Overlays.BeatmapListing Spacing = new Vector2(0, 20), Children = new Drawable[] { - textBox = new SearchTextBox + textBox = new BeatmapSearchTextBox { RelativeSizeAxes = Axes.X, }, @@ -110,5 +111,15 @@ namespace osu.Game.Overlays.BeatmapListing { background.Colour = colourProvider.Dark6; } + + private class BeatmapSearchTextBox : SearchTextBox + { + protected override Color4 SelectionColour => Color4.Gray; + + public BeatmapSearchTextBox() + { + PlaceholderText = @"type in keywords..."; + } + } } } From bb22243903bdbaeee9efaca0d2a8fbc41f7657ac Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 18 Feb 2020 17:47:44 +0300 Subject: [PATCH 3/4] TestScene improvements --- .../TestSceneBeatmapListingSearchSection.cs | 69 +++++++++++++------ 1 file changed, 49 insertions(+), 20 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs index 24dc013940..8e9123fe8d 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs @@ -3,11 +3,15 @@ using System; using System.Collections.Generic; +using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; using osu.Game.Beatmaps; +using osu.Game.Graphics.Sprites; using osu.Game.Overlays; using osu.Game.Overlays.BeatmapListing; +using osuTK; namespace osu.Game.Tests.Visual.UserInterface { @@ -21,9 +25,13 @@ namespace osu.Game.Tests.Visual.UserInterface [Cached] private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); + private readonly BeatmapListingSearchSection section; + public TestSceneBeatmapListingSearchSection() { - BeatmapListingSearchSection section; + OsuSpriteText query; + OsuSpriteText ruleset; + OsuSpriteText category; Add(section = new BeatmapListingSearchSection { @@ -31,31 +39,52 @@ namespace osu.Game.Tests.Visual.UserInterface Origin = Anchor.Centre, }); - var beatmapSet = new BeatmapSetInfo + Add(new FillFlowContainer { - OnlineInfo = new BeatmapSetOnlineInfo + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Vertical, + Spacing = new Vector2(0, 5), + Children = new Drawable[] { - Covers = new BeatmapSetOnlineCovers - { - Cover = "https://assets.ppy.sh/beatmaps/1094296/covers/cover@2x.jpg?1581416305" - } + query = new OsuSpriteText(), + ruleset = new OsuSpriteText(), + category = new OsuSpriteText(), } - }; + }); - var noCoverBeatmapSet = new BeatmapSetInfo - { - OnlineInfo = new BeatmapSetOnlineInfo - { - Covers = new BeatmapSetOnlineCovers - { - Cover = string.Empty - } - } - }; + section.Query.BindValueChanged(q => query.Text = $"Query: {q.NewValue}", true); + section.Ruleset.BindValueChanged(r => ruleset.Text = $"Ruleset: {r.NewValue}", true); + section.Category.BindValueChanged(c => category.Text = $"Category: {c.NewValue}", true); + } - AddStep("Set beatmap", () => section.BeatmapSet = beatmapSet); - AddStep("Set beatmap (no cover)", () => section.BeatmapSet = noCoverBeatmapSet); + [Test] + public void TestCovers() + { + AddStep("Set beatmap", () => section.BeatmapSet = beatmap_set); + AddStep("Set beatmap (no cover)", () => section.BeatmapSet = no_cover_beatmap_set); AddStep("Set null beatmap", () => section.BeatmapSet = null); } + + private static BeatmapSetInfo beatmap_set = new BeatmapSetInfo + { + OnlineInfo = new BeatmapSetOnlineInfo + { + Covers = new BeatmapSetOnlineCovers + { + Cover = "https://assets.ppy.sh/beatmaps/1094296/covers/cover@2x.jpg?1581416305" + } + } + }; + + private static BeatmapSetInfo no_cover_beatmap_set = new BeatmapSetInfo + { + OnlineInfo = new BeatmapSetOnlineInfo + { + Covers = new BeatmapSetOnlineCovers + { + Cover = string.Empty + } + } + }; } } From 37003e11b98ca1f70215c9e7706b0d6d1d0478c8 Mon Sep 17 00:00:00 2001 From: Andrei Zavatski Date: Tue, 18 Feb 2020 18:04:39 +0300 Subject: [PATCH 4/4] Make fields readonly --- .../UserInterface/TestSceneBeatmapListingSearchSection.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs index 8e9123fe8d..1d8db71527 100644 --- a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingSearchSection.cs @@ -65,7 +65,7 @@ namespace osu.Game.Tests.Visual.UserInterface AddStep("Set null beatmap", () => section.BeatmapSet = null); } - private static BeatmapSetInfo beatmap_set = new BeatmapSetInfo + private static readonly BeatmapSetInfo beatmap_set = new BeatmapSetInfo { OnlineInfo = new BeatmapSetOnlineInfo { @@ -76,7 +76,7 @@ namespace osu.Game.Tests.Visual.UserInterface } }; - private static BeatmapSetInfo no_cover_beatmap_set = new BeatmapSetInfo + private static readonly BeatmapSetInfo no_cover_beatmap_set = new BeatmapSetInfo { OnlineInfo = new BeatmapSetOnlineInfo {