From cd4c1bc678e9d36fb33b69bbc711df676bead5e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 27 Nov 2021 16:20:51 +0100 Subject: [PATCH 1/8] Add factory method for various card sizes --- .../Beatmaps/Drawables/Cards/BeatmapCard.cs | 19 +++++++++++++++++++ .../Drawables/Cards/BeatmapCardSize.cs | 14 ++++++++++++++ 2 files changed, 33 insertions(+) create mode 100644 osu.Game/Beatmaps/Drawables/Cards/BeatmapCardSize.cs diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs index 6adcdcfcb2..d6dfd8cb17 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs @@ -3,6 +3,7 @@ #nullable enable +using System; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; @@ -76,5 +77,23 @@ namespace osu.Game.Beatmaps.Drawables.Cards IdleContent.FadeTo(showProgress ? 0 : 1, TRANSITION_DURATION, Easing.OutQuint); DownloadInProgressContent.FadeTo(showProgress ? 1 : 0, TRANSITION_DURATION, Easing.OutQuint); } + + /// + /// Creates a beatmap card of the given for the supplied . + /// + public static BeatmapCard Create(APIBeatmapSet beatmapSet, BeatmapCardSize size, bool allowExpansion = true) + { + switch (size) + { + case BeatmapCardSize.Normal: + return new BeatmapCardNormal(beatmapSet, allowExpansion); + + case BeatmapCardSize.Extra: + return new BeatmapCardExtra(beatmapSet, allowExpansion); + + default: + throw new ArgumentOutOfRangeException(nameof(size), size, @"Unsupported card size"); + } + } } } diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardSize.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardSize.cs new file mode 100644 index 0000000000..098265506d --- /dev/null +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardSize.cs @@ -0,0 +1,14 @@ +// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. +// See the LICENCE file in the repository root for full licence text. + +namespace osu.Game.Beatmaps.Drawables.Cards +{ + /// + /// Enumeration for all available sizes of . + /// + public enum BeatmapCardSize + { + Normal, + Extra + } +} From 1876617d8e1a030520feb075bc0b03004f160688 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 27 Nov 2021 17:25:54 +0100 Subject: [PATCH 2/8] Implement beatmap card size tab control --- ...stSceneBeatmapListingCardSizeTabControl.cs | 55 +++++++ .../BeatmapListingCardSizeTabControl.cs | 134 ++++++++++++++++++ 2 files changed, 189 insertions(+) create mode 100644 osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingCardSizeTabControl.cs create mode 100644 osu.Game/Overlays/BeatmapListing/BeatmapListingCardSizeTabControl.cs diff --git a/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingCardSizeTabControl.cs b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingCardSizeTabControl.cs new file mode 100644 index 0000000000..e3d47f08c6 --- /dev/null +++ b/osu.Game.Tests/Visual/UserInterface/TestSceneBeatmapListingCardSizeTabControl.cs @@ -0,0 +1,55 @@ +// 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.Bindables; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Game.Beatmaps.Drawables.Cards; +using osu.Game.Graphics; +using osu.Game.Graphics.Sprites; +using osu.Game.Overlays; +using osu.Game.Overlays.BeatmapListing; + +namespace osu.Game.Tests.Visual.UserInterface +{ + public class TestSceneBeatmapListingCardSizeTabControl : OsuTestScene + { + [Cached] + private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue); + + private readonly Bindable cardSize = new Bindable(); + + private SpriteText cardSizeText; + + [BackgroundDependencyLoader] + private void load() + { + Child = new Container + { + RelativeSizeAxes = Axes.Both, + Children = new Drawable[] + { + cardSizeText = new OsuSpriteText + { + Font = OsuFont.Default.With(size: 24) + }, + new BeatmapListingCardSizeTabControl + { + Current = cardSize, + Anchor = Anchor.Centre, + Origin = Anchor.Centre + } + } + }; + } + + protected override void LoadComplete() + { + base.LoadComplete(); + + cardSize.BindValueChanged(size => cardSizeText.Text = $"Current size: {size.NewValue}", true); + } + } +} diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingCardSizeTabControl.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingCardSizeTabControl.cs new file mode 100644 index 0000000000..e4fda9d9c3 --- /dev/null +++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingCardSizeTabControl.cs @@ -0,0 +1,134 @@ +// 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 osu.Framework.Allocation; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Shapes; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.UserInterface; +using osu.Framework.Input.Events; +using osu.Game.Beatmaps.Drawables.Cards; +using osu.Game.Graphics.UserInterface; +using osuTK; + +namespace osu.Game.Overlays.BeatmapListing +{ + public class BeatmapListingCardSizeTabControl : OsuTabControl + { + public BeatmapListingCardSizeTabControl() + { + AutoSizeAxes = Axes.Both; + } + + protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer + { + AutoSizeAxes = Axes.Both, + Direction = FillDirection.Horizontal, + Spacing = new Vector2(10, 0), + }; + + protected override Dropdown CreateDropdown() => null; + + protected override TabItem CreateTabItem(BeatmapCardSize value) => new TabItem(value); + + private class TabItem : TabItem + { + private Box background; + private SpriteIcon icon; + + [Resolved] + private OverlayColourProvider colourProvider { get; set; } + + public TabItem(BeatmapCardSize value) + : base(value) + { + } + + [BackgroundDependencyLoader] + private void load() + { + AutoSizeAxes = Axes.Both; + Masking = true; + CornerRadius = 4; + Children = new Drawable[] + { + background = new Box + { + RelativeSizeAxes = Axes.Both, + Colour = colourProvider.Background3 + }, + new Container + { + AutoSizeAxes = Axes.Both, + Padding = new MarginPadding + { + Horizontal = 10, + Vertical = 5, + }, + Child = icon = new SpriteIcon + { + Size = new Vector2(12), + Icon = getIconForCardSize(Value) + } + } + }; + } + + private static IconUsage getIconForCardSize(BeatmapCardSize cardSize) + { + switch (cardSize) + { + case BeatmapCardSize.Normal: + return FontAwesome.Solid.Th; + + case BeatmapCardSize.Extra: + return FontAwesome.Solid.ThLarge; + + default: + throw new ArgumentOutOfRangeException(nameof(cardSize), cardSize, "Unsupported card size"); + } + } + + protected override void LoadComplete() + { + base.LoadComplete(); + updateState(); + FinishTransforms(true); + } + + protected override void OnActivated() + { + if (IsLoaded) + updateState(); + } + + protected override void OnDeactivated() + { + if (IsLoaded) + updateState(); + } + + protected override bool OnHover(HoverEvent e) + { + updateState(); + return base.OnHover(e); + } + + protected override void OnHoverLost(HoverLostEvent e) + { + updateState(); + base.OnHoverLost(e); + } + + private const double fade_time = 200; + + private void updateState() + { + background.FadeTo(IsHovered || Active.Value ? 1 : 0, fade_time, Easing.OutQuint); + icon.FadeColour(Active.Value && !IsHovered ? colourProvider.Light1 : colourProvider.Content1, fade_time, Easing.OutQuint); + } + } + } +} From d0427ec85f93ab7276a7593153d0f8fd77ce2b7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Sat, 27 Nov 2021 17:53:57 +0100 Subject: [PATCH 3/8] Add support card size tab control to beatmap listing --- .../BeatmapListingFilterControl.cs | 22 ++++++++++++++++--- osu.Game/Overlays/BeatmapListingOverlay.cs | 14 ++++++------ 2 files changed, 26 insertions(+), 10 deletions(-) diff --git a/osu.Game/Overlays/BeatmapListing/BeatmapListingFilterControl.cs b/osu.Game/Overlays/BeatmapListing/BeatmapListingFilterControl.cs index f5b4785264..157753c09f 100644 --- a/osu.Game/Overlays/BeatmapListing/BeatmapListingFilterControl.cs +++ b/osu.Game/Overlays/BeatmapListing/BeatmapListingFilterControl.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Allocation; +using osu.Framework.Bindables; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; @@ -12,6 +13,7 @@ using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Shapes; using osu.Framework.Localisation; using osu.Framework.Threading; +using osu.Game.Beatmaps.Drawables.Cards; using osu.Game.Online.API; using osu.Game.Online.API.Requests; using osu.Game.Online.API.Requests.Responses; @@ -48,6 +50,11 @@ namespace osu.Game.Overlays.BeatmapListing /// public int CurrentPage { get; private set; } + /// + /// The currently selected . + /// + public IBindable CardSize { get; } = new Bindable(); + private readonly BeatmapListingSearchControl searchControl; private readonly BeatmapListingSortTabControl sortControl; private readonly Box sortControlBackground; @@ -105,6 +112,13 @@ namespace osu.Game.Overlays.BeatmapListing Anchor = Anchor.CentreLeft, Origin = Anchor.CentreLeft, Margin = new MarginPadding { Left = 20 } + }, + new BeatmapListingCardSizeTabControl + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + Margin = new MarginPadding { Right = 20 }, + Current = { BindTarget = CardSize } } } } @@ -227,12 +241,14 @@ namespace osu.Game.Overlays.BeatmapListing if (filters.Any()) { - SearchFinished?.Invoke(SearchResult.SupporterOnlyFilters(filters)); + var supporterOnlyFilters = SearchResult.SupporterOnlyFilters(filters); + SearchFinished?.Invoke(supporterOnlyFilters); return; } } - SearchFinished?.Invoke(SearchResult.ResultsReturned(sets)); + var resultsReturned = SearchResult.ResultsReturned(sets); + SearchFinished?.Invoke(resultsReturned); }; api.Queue(getSetsRequest); @@ -296,7 +312,7 @@ namespace osu.Game.Overlays.BeatmapListing public static SearchResult ResultsReturned(List results) => new SearchResult { Type = SearchResultType.ResultsReturned, - Results = results + Results = results, }; public static SearchResult SupporterOnlyFilters(List filters) => new SearchResult diff --git a/osu.Game/Overlays/BeatmapListingOverlay.cs b/osu.Game/Overlays/BeatmapListingOverlay.cs index d07f7c8f8f..dd726ed010 100644 --- a/osu.Game/Overlays/BeatmapListingOverlay.cs +++ b/osu.Game/Overlays/BeatmapListingOverlay.cs @@ -33,7 +33,7 @@ namespace osu.Game.Overlays private Drawable currentContent; private Container panelTarget; - private FillFlowContainer foundContent; + private FillFlowContainer foundContent; private NotFoundDrawable notFoundContent; private SupporterRequiredDrawable supporterRequiredContent; private BeatmapListingFilterControl filterControl; @@ -78,7 +78,7 @@ namespace osu.Game.Overlays Padding = new MarginPadding { Horizontal = 20 }, Children = new Drawable[] { - foundContent = new FillFlowContainer(), + foundContent = new FillFlowContainer(), notFoundContent = new NotFoundDrawable(), supporterRequiredContent = new SupporterRequiredDrawable(), } @@ -135,11 +135,11 @@ namespace osu.Game.Overlays return; } - var newPanels = searchResult.Results.Select(b => new BeatmapCardNormal(b) + var newPanels = searchResult.Results.Select(b => BeatmapCard.Create(b, filterControl.CardSize.Value).With(card => { - Anchor = Anchor.TopCentre, - Origin = Anchor.TopCentre, - }); + card.Anchor = Anchor.TopCentre; + card.Origin = Anchor.TopCentre; + })); if (filterControl.CurrentPage == 0) { @@ -152,7 +152,7 @@ namespace osu.Game.Overlays // spawn new children with the contained so we only clear old content at the last moment. // reverse ID flow is required for correct Z-ordering of the cards' expandable content (last card should be front-most). - var content = new ReverseChildIDFillFlowContainer + var content = new ReverseChildIDFillFlowContainer { RelativeSizeAxes = Axes.X, AutoSizeAxes = Axes.Y, From a49a4329eef88c8b89b5cba38be989ad1aca2dd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 22 Dec 2021 13:16:36 +0100 Subject: [PATCH 4/8] Add capability to switch between card sizes --- .../Beatmaps/Drawables/Cards/BeatmapCard.cs | 3 +- osu.Game/Overlays/BeatmapListingOverlay.cs | 78 ++++++++++++++----- 2 files changed, 60 insertions(+), 21 deletions(-) diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs index d6dfd8cb17..af537b9e44 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs @@ -23,7 +23,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards public IBindable Expanded { get; } - protected readonly APIBeatmapSet BeatmapSet; + public readonly APIBeatmapSet BeatmapSet; + protected readonly Bindable FavouriteState; protected abstract Drawable IdleContent { get; } diff --git a/osu.Game/Overlays/BeatmapListingOverlay.cs b/osu.Game/Overlays/BeatmapListingOverlay.cs index dd726ed010..074db5cef9 100644 --- a/osu.Game/Overlays/BeatmapListingOverlay.cs +++ b/osu.Game/Overlays/BeatmapListingOverlay.cs @@ -19,6 +19,7 @@ using osu.Game.Beatmaps.Drawables.Cards; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Containers; +using osu.Game.Online.API.Requests.Responses; using osu.Game.Overlays.BeatmapListing; using osu.Game.Resources.Localisation.Web; using osuTK; @@ -89,6 +90,12 @@ namespace osu.Game.Overlays }; } + protected override void LoadComplete() + { + base.LoadComplete(); + filterControl.CardSize.BindValueChanged(_ => onCardSizeChanged()); + } + public void ShowWithSearch(string query) { filterControl.Search(query); @@ -135,38 +142,24 @@ namespace osu.Game.Overlays return; } - var newPanels = searchResult.Results.Select(b => BeatmapCard.Create(b, filterControl.CardSize.Value).With(card => - { - card.Anchor = Anchor.TopCentre; - card.Origin = Anchor.TopCentre; - })); + var newCards = createCardsFor(searchResult.Results); if (filterControl.CurrentPage == 0) { //No matches case - if (!newPanels.Any()) + if (!newCards.Any()) { addContentToPlaceholder(notFoundContent); return; } - // spawn new children with the contained so we only clear old content at the last moment. - // reverse ID flow is required for correct Z-ordering of the cards' expandable content (last card should be front-most). - var content = new ReverseChildIDFillFlowContainer - { - RelativeSizeAxes = Axes.X, - AutoSizeAxes = Axes.Y, - Spacing = new Vector2(10), - Alpha = 0, - Margin = new MarginPadding { Vertical = 15 }, - ChildrenEnumerable = newPanels - }; + var content = createCardContainerFor(newCards); panelLoadDelegate = LoadComponentAsync(foundContent = content, addContentToPlaceholder, (cancellationToken = new CancellationTokenSource()).Token); } else { - panelLoadDelegate = LoadComponentsAsync(newPanels, loaded => + panelLoadDelegate = LoadComponentsAsync(newCards, loaded => { lastFetchDisplayedTime = Time.Current; foundContent.AddRange(loaded); @@ -175,6 +168,28 @@ namespace osu.Game.Overlays } } + private BeatmapCard[] createCardsFor(IEnumerable beatmapSets) => beatmapSets.Select(set => BeatmapCard.Create(set, filterControl.CardSize.Value).With(c => + { + c.Anchor = Anchor.TopCentre; + c.Origin = Anchor.TopCentre; + })).ToArray(); + + private static ReverseChildIDFillFlowContainer createCardContainerFor(IEnumerable newCards) + { + // spawn new children with the contained so we only clear old content at the last moment. + // reverse ID flow is required for correct Z-ordering of the cards' expandable content (last card should be front-most). + var content = new ReverseChildIDFillFlowContainer + { + RelativeSizeAxes = Axes.X, + AutoSizeAxes = Axes.Y, + Spacing = new Vector2(10), + Alpha = 0, + Margin = new MarginPadding { Vertical = 15 }, + ChildrenEnumerable = newCards + }; + return content; + } + private void addContentToPlaceholder(Drawable content) { Loading.Hide(); @@ -195,8 +210,14 @@ namespace osu.Game.Overlays // To resolve both of these issues, the bypass is delayed until a point when the content transitions (fade-in and fade-out) overlap and it looks good to do so. var sequence = lastContent.Delay(25).Schedule(() => lastContent.BypassAutoSizeAxes = Axes.Y); - if (lastContent != notFoundContent && lastContent != supporterRequiredContent) - sequence.Then().Schedule(() => lastContent.Expire()); + if (lastContent == foundContent) + { + sequence.Then().Schedule(() => + { + foundContent.Expire(); + foundContent = null; + }); + } } if (!content.IsAlive) @@ -209,6 +230,23 @@ namespace osu.Game.Overlays currentContent.BypassAutoSizeAxes = Axes.None; } + private void onCardSizeChanged() + { + if (foundContent == null || !foundContent.Any()) + return; + + Loading.Show(); + + var newCards = createCardsFor(foundContent.Reverse().Select(card => card.BeatmapSet)); + + panelLoadDelegate = LoadComponentsAsync(newCards, cards => + { + foundContent.Clear(); + foundContent.AddRange(cards); + Loading.Hide(); + }, (cancellationToken = new CancellationTokenSource()).Token); + } + protected override void Dispose(bool isDisposing) { cancellationToken?.Cancel(); From 27c5cc5bd82dc79c86a558c9406e359ffe93e49e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Wed, 22 Dec 2021 14:27:11 +0100 Subject: [PATCH 5/8] Add testing for beatmap card size switching --- .../Online/TestSceneBeatmapListingOverlay.cs | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/osu.Game.Tests/Visual/Online/TestSceneBeatmapListingOverlay.cs b/osu.Game.Tests/Visual/Online/TestSceneBeatmapListingOverlay.cs index 966f2f3610..ee8794ae87 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneBeatmapListingOverlay.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneBeatmapListingOverlay.cs @@ -107,6 +107,27 @@ namespace osu.Game.Tests.Visual.Online AddUntilStep("is hidden", () => overlay.State.Value == Visibility.Hidden); } + [Test] + public void TestCardSizeSwitching() + { + AddAssert("is visible", () => overlay.State.Value == Visibility.Visible); + + AddStep("show many results", () => fetchFor(Enumerable.Repeat(CreateAPIBeatmapSet(Ruleset.Value), 100).ToArray())); + assertAllCardsOfType(); + + setCardSize(BeatmapCardSize.Extra); + assertAllCardsOfType(); + + setCardSize(BeatmapCardSize.Normal); + assertAllCardsOfType(); + + AddStep("fetch for 0 beatmaps", () => fetchFor()); + AddUntilStep("placeholder shown", () => overlay.ChildrenOfType().SingleOrDefault()?.IsPresent == true); + + setCardSize(BeatmapCardSize.Extra); + AddAssert("placeholder shown", () => overlay.ChildrenOfType().SingleOrDefault()?.IsPresent == true); + } + [Test] public void TestNoBeatmapsPlaceholder() { @@ -299,5 +320,16 @@ namespace osu.Game.Tests.Visual.Online AddUntilStep("\"supporter required\" placeholder not shown", () => !overlay.ChildrenOfType().Any(d => d.IsPresent)); AddUntilStep("\"no maps found\" placeholder not shown", () => !overlay.ChildrenOfType().Any(d => d.IsPresent)); } + + private void setCardSize(BeatmapCardSize cardSize) => AddStep($"set card size to {cardSize}", () => overlay.ChildrenOfType().Single().Current.Value = cardSize); + + private void assertAllCardsOfType() + where T : BeatmapCard => + AddUntilStep($"all loaded beatmap cards are {typeof(T)}", () => + { + int loadedCorrectCount = this.ChildrenOfType().Count(card => card.IsLoaded && card.GetType() == typeof(T)); + int totalCount = this.ChildrenOfType().Count(); + return loadedCorrectCount > 0 && loadedCorrectCount == totalCount; + }); } } From 3ca238825bef871a90e890df7c76b5c5c5797447 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bart=C5=82omiej=20Dach?= Date: Fri, 24 Dec 2021 09:17:07 +0100 Subject: [PATCH 6/8] Unify width of normal and extra card sizes --- osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs | 2 ++ osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs | 5 ++--- osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs | 5 ++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs index af537b9e44..9a17d6dc9b 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCard.cs @@ -21,6 +21,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards public const float TRANSITION_DURATION = 400; public const float CORNER_RADIUS = 10; + protected const float WIDTH = 430; + public IBindable Expanded { get; } public readonly APIBeatmapSet BeatmapSet; diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs index 7f70423ff9..535f222228 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardExtra.cs @@ -25,7 +25,6 @@ namespace osu.Game.Beatmaps.Drawables.Cards protected override Drawable IdleContent => idleBottomContent; protected override Drawable DownloadInProgressContent => downloadProgressBar; - private const float width = 475; private const float height = 140; [Cached] @@ -51,7 +50,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards [BackgroundDependencyLoader(true)] private void load(BeatmapSetOverlay? beatmapSetOverlay) { - Width = width; + Width = WIDTH; Height = height; FillFlowContainer leftIconArea = null!; @@ -81,7 +80,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards buttonContainer = new CollapsibleButtonContainer(BeatmapSet) { X = height - CORNER_RADIUS, - Width = width - height + CORNER_RADIUS, + Width = WIDTH - height + CORNER_RADIUS, FavouriteState = { BindTarget = FavouriteState }, ButtonsCollapsedWidth = CORNER_RADIUS, ButtonsExpandedWidth = 30, diff --git a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs index edca310db9..08befd5340 100644 --- a/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs +++ b/osu.Game/Beatmaps/Drawables/Cards/BeatmapCardNormal.cs @@ -26,7 +26,6 @@ namespace osu.Game.Beatmaps.Drawables.Cards protected override Drawable IdleContent => idleBottomContent; protected override Drawable DownloadInProgressContent => downloadProgressBar; - private const float width = 408; private const float height = 100; [Cached] @@ -52,7 +51,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards [BackgroundDependencyLoader] private void load() { - Width = width; + Width = WIDTH; Height = height; FillFlowContainer leftIconArea = null!; @@ -82,7 +81,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards buttonContainer = new CollapsibleButtonContainer(BeatmapSet) { X = height - CORNER_RADIUS, - Width = width - height + CORNER_RADIUS, + Width = WIDTH - height + CORNER_RADIUS, FavouriteState = { BindTarget = FavouriteState }, ButtonsCollapsedWidth = CORNER_RADIUS, ButtonsExpandedWidth = 30, From d602aebebbf01c8952c5d27f1eaa9a90e441fb83 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 24 Dec 2021 18:58:31 +0900 Subject: [PATCH 7/8] Add missing cancellation token and rename load task variable to match purpose --- osu.Game/Overlays/BeatmapListingOverlay.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/BeatmapListingOverlay.cs b/osu.Game/Overlays/BeatmapListingOverlay.cs index 074db5cef9..ab4ff3edc2 100644 --- a/osu.Game/Overlays/BeatmapListingOverlay.cs +++ b/osu.Game/Overlays/BeatmapListingOverlay.cs @@ -131,7 +131,7 @@ namespace osu.Game.Overlays Loading.Show(); } - private Task panelLoadDelegate; + private Task panelLoadTask; private void onSearchFinished(BeatmapListingFilterControl.SearchResult searchResult) { @@ -155,16 +155,16 @@ namespace osu.Game.Overlays var content = createCardContainerFor(newCards); - panelLoadDelegate = LoadComponentAsync(foundContent = content, addContentToPlaceholder, (cancellationToken = new CancellationTokenSource()).Token); + panelLoadTask = LoadComponentAsync(foundContent = content, addContentToPlaceholder, (cancellationToken = new CancellationTokenSource()).Token); } else { - panelLoadDelegate = LoadComponentsAsync(newCards, loaded => + panelLoadTask = LoadComponentsAsync(newCards, loaded => { lastFetchDisplayedTime = Time.Current; foundContent.AddRange(loaded); loaded.ForEach(p => p.FadeIn(200, Easing.OutQuint)); - }); + }, (cancellationToken = new CancellationTokenSource()).Token); } } @@ -239,7 +239,7 @@ namespace osu.Game.Overlays var newCards = createCardsFor(foundContent.Reverse().Select(card => card.BeatmapSet)); - panelLoadDelegate = LoadComponentsAsync(newCards, cards => + panelLoadTask = LoadComponentsAsync(newCards, cards => { foundContent.Clear(); foundContent.AddRange(cards); @@ -374,7 +374,7 @@ namespace osu.Game.Overlays const int pagination_scroll_distance = 500; - bool shouldShowMore = panelLoadDelegate?.IsCompleted != false + bool shouldShowMore = panelLoadTask?.IsCompleted != false && Time.Current - lastFetchDisplayedTime > time_between_fetches && (ScrollFlow.ScrollableExtent > 0 && ScrollFlow.IsScrolledToEnd(pagination_scroll_distance)); From cc7089c3f4ce3706cdccd483ae0b2bf1911952ed Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Fri, 24 Dec 2021 19:00:09 +0900 Subject: [PATCH 8/8] Cancel more liberally --- osu.Game/Overlays/BeatmapListingOverlay.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/BeatmapListingOverlay.cs b/osu.Game/Overlays/BeatmapListingOverlay.cs index ab4ff3edc2..0c2bad95d6 100644 --- a/osu.Game/Overlays/BeatmapListingOverlay.cs +++ b/osu.Game/Overlays/BeatmapListingOverlay.cs @@ -121,6 +121,8 @@ namespace osu.Game.Overlays private CancellationTokenSource cancellationToken; + private Task panelLoadTask; + private void onSearchStarted() { cancellationToken?.Cancel(); @@ -131,10 +133,10 @@ namespace osu.Game.Overlays Loading.Show(); } - private Task panelLoadTask; - private void onSearchFinished(BeatmapListingFilterControl.SearchResult searchResult) { + cancellationToken?.Cancel(); + if (searchResult.Type == BeatmapListingFilterControl.SearchResultType.SupporterOnlyFilters) { supporterRequiredContent.UpdateText(searchResult.SupporterOnlyFiltersUsed); @@ -239,6 +241,8 @@ namespace osu.Game.Overlays var newCards = createCardsFor(foundContent.Reverse().Select(card => card.BeatmapSet)); + cancellationToken?.Cancel(); + panelLoadTask = LoadComponentsAsync(newCards, cards => { foundContent.Clear();