Add capability to switch between card sizes

This commit is contained in:
Bartłomiej Dach 2021-12-22 13:16:36 +01:00
parent d0427ec85f
commit a49a4329ee
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 60 additions and 21 deletions

View File

@ -23,7 +23,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards
public IBindable<bool> Expanded { get; }
protected readonly APIBeatmapSet BeatmapSet;
public readonly APIBeatmapSet BeatmapSet;
protected readonly Bindable<BeatmapSetFavouriteState> FavouriteState;
protected abstract Drawable IdleContent { get; }

View File

@ -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<BeatmapCard>
{
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<APIBeatmapSet> beatmapSets) => beatmapSets.Select(set => BeatmapCard.Create(set, filterControl.CardSize.Value).With(c =>
{
c.Anchor = Anchor.TopCentre;
c.Origin = Anchor.TopCentre;
})).ToArray();
private static ReverseChildIDFillFlowContainer<BeatmapCard> createCardContainerFor(IEnumerable<BeatmapCard> 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<BeatmapCard>
{
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();