mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 08:12:56 +08:00
Add capability to switch between card sizes
This commit is contained in:
parent
d0427ec85f
commit
a49a4329ee
@ -23,7 +23,8 @@ namespace osu.Game.Beatmaps.Drawables.Cards
|
|||||||
|
|
||||||
public IBindable<bool> Expanded { get; }
|
public IBindable<bool> Expanded { get; }
|
||||||
|
|
||||||
protected readonly APIBeatmapSet BeatmapSet;
|
public readonly APIBeatmapSet BeatmapSet;
|
||||||
|
|
||||||
protected readonly Bindable<BeatmapSetFavouriteState> FavouriteState;
|
protected readonly Bindable<BeatmapSetFavouriteState> FavouriteState;
|
||||||
|
|
||||||
protected abstract Drawable IdleContent { get; }
|
protected abstract Drawable IdleContent { get; }
|
||||||
|
@ -19,6 +19,7 @@ using osu.Game.Beatmaps.Drawables.Cards;
|
|||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.Containers;
|
using osu.Game.Graphics.Containers;
|
||||||
|
using osu.Game.Online.API.Requests.Responses;
|
||||||
using osu.Game.Overlays.BeatmapListing;
|
using osu.Game.Overlays.BeatmapListing;
|
||||||
using osu.Game.Resources.Localisation.Web;
|
using osu.Game.Resources.Localisation.Web;
|
||||||
using osuTK;
|
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)
|
public void ShowWithSearch(string query)
|
||||||
{
|
{
|
||||||
filterControl.Search(query);
|
filterControl.Search(query);
|
||||||
@ -135,38 +142,24 @@ namespace osu.Game.Overlays
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var newPanels = searchResult.Results.Select(b => BeatmapCard.Create(b, filterControl.CardSize.Value).With(card =>
|
var newCards = createCardsFor(searchResult.Results);
|
||||||
{
|
|
||||||
card.Anchor = Anchor.TopCentre;
|
|
||||||
card.Origin = Anchor.TopCentre;
|
|
||||||
}));
|
|
||||||
|
|
||||||
if (filterControl.CurrentPage == 0)
|
if (filterControl.CurrentPage == 0)
|
||||||
{
|
{
|
||||||
//No matches case
|
//No matches case
|
||||||
if (!newPanels.Any())
|
if (!newCards.Any())
|
||||||
{
|
{
|
||||||
addContentToPlaceholder(notFoundContent);
|
addContentToPlaceholder(notFoundContent);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// spawn new children with the contained so we only clear old content at the last moment.
|
var content = createCardContainerFor(newCards);
|
||||||
// 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
|
|
||||||
};
|
|
||||||
|
|
||||||
panelLoadDelegate = LoadComponentAsync(foundContent = content, addContentToPlaceholder, (cancellationToken = new CancellationTokenSource()).Token);
|
panelLoadDelegate = LoadComponentAsync(foundContent = content, addContentToPlaceholder, (cancellationToken = new CancellationTokenSource()).Token);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
panelLoadDelegate = LoadComponentsAsync(newPanels, loaded =>
|
panelLoadDelegate = LoadComponentsAsync(newCards, loaded =>
|
||||||
{
|
{
|
||||||
lastFetchDisplayedTime = Time.Current;
|
lastFetchDisplayedTime = Time.Current;
|
||||||
foundContent.AddRange(loaded);
|
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)
|
private void addContentToPlaceholder(Drawable content)
|
||||||
{
|
{
|
||||||
Loading.Hide();
|
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.
|
// 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);
|
var sequence = lastContent.Delay(25).Schedule(() => lastContent.BypassAutoSizeAxes = Axes.Y);
|
||||||
|
|
||||||
if (lastContent != notFoundContent && lastContent != supporterRequiredContent)
|
if (lastContent == foundContent)
|
||||||
sequence.Then().Schedule(() => lastContent.Expire());
|
{
|
||||||
|
sequence.Then().Schedule(() =>
|
||||||
|
{
|
||||||
|
foundContent.Expire();
|
||||||
|
foundContent = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!content.IsAlive)
|
if (!content.IsAlive)
|
||||||
@ -209,6 +230,23 @@ namespace osu.Game.Overlays
|
|||||||
currentContent.BypassAutoSizeAxes = Axes.None;
|
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)
|
protected override void Dispose(bool isDisposing)
|
||||||
{
|
{
|
||||||
cancellationToken?.Cancel();
|
cancellationToken?.Cancel();
|
||||||
|
Loading…
Reference in New Issue
Block a user