1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-14 20:13:22 +08:00

Apply NRT to BeatmapCarousel

This commit is contained in:
Dean Herbert 2022-09-07 14:04:51 +09:00
parent 13efa819ae
commit 241d33d415

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
#nullable disable
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
@ -49,31 +47,31 @@ namespace osu.Game.Screens.Select
/// <summary> /// <summary>
/// Triggered when the <see cref="BeatmapSets"/> loaded change and are completely loaded. /// Triggered when the <see cref="BeatmapSets"/> loaded change and are completely loaded.
/// </summary> /// </summary>
public Action BeatmapSetsChanged; public Action? BeatmapSetsChanged;
/// <summary> /// <summary>
/// The currently selected beatmap. /// The currently selected beatmap.
/// </summary> /// </summary>
public BeatmapInfo SelectedBeatmapInfo => selectedBeatmap?.BeatmapInfo; public BeatmapInfo? SelectedBeatmapInfo => selectedBeatmap?.BeatmapInfo;
private CarouselBeatmap selectedBeatmap => selectedBeatmapSet?.Beatmaps.FirstOrDefault(s => s.State.Value == CarouselItemState.Selected); private CarouselBeatmap? selectedBeatmap => selectedBeatmapSet?.Beatmaps.FirstOrDefault(s => s.State.Value == CarouselItemState.Selected);
/// <summary> /// <summary>
/// The currently selected beatmap set. /// The currently selected beatmap set.
/// </summary> /// </summary>
public BeatmapSetInfo SelectedBeatmapSet => selectedBeatmapSet?.BeatmapSet; public BeatmapSetInfo? SelectedBeatmapSet => selectedBeatmapSet?.BeatmapSet;
/// <summary> /// <summary>
/// A function to optionally decide on a recommended difficulty from a beatmap set. /// A function to optionally decide on a recommended difficulty from a beatmap set.
/// </summary> /// </summary>
public Func<IEnumerable<BeatmapInfo>, BeatmapInfo> GetRecommendedBeatmap; public Func<IEnumerable<BeatmapInfo>, BeatmapInfo>? GetRecommendedBeatmap;
private CarouselBeatmapSet selectedBeatmapSet; private CarouselBeatmapSet? selectedBeatmapSet;
/// <summary> /// <summary>
/// Raised when the <see cref="SelectedBeatmapInfo"/> is changed. /// Raised when the <see cref="SelectedBeatmapInfo"/> is changed.
/// </summary> /// </summary>
public Action<BeatmapInfo> SelectionChanged; public Action<BeatmapInfo?>? SelectionChanged;
public override bool HandleNonPositionalInput => AllowSelection; public override bool HandleNonPositionalInput => AllowSelection;
public override bool HandlePositionalInput => AllowSelection; public override bool HandlePositionalInput => AllowSelection;
@ -151,15 +149,15 @@ namespace osu.Game.Screens.Select
private CarouselRoot root; private CarouselRoot root;
private IDisposable subscriptionSets; private IDisposable? subscriptionSets;
private IDisposable subscriptionDeletedSets; private IDisposable? subscriptionDeletedSets;
private IDisposable subscriptionBeatmaps; private IDisposable? subscriptionBeatmaps;
private IDisposable subscriptionHiddenBeatmaps; private IDisposable? subscriptionHiddenBeatmaps;
private readonly DrawablePool<DrawableCarouselBeatmapSet> setPool = new DrawablePool<DrawableCarouselBeatmapSet>(100); private readonly DrawablePool<DrawableCarouselBeatmapSet> setPool = new DrawablePool<DrawableCarouselBeatmapSet>(100);
private Sample spinSample; private Sample? spinSample;
private Sample randomSelectSample; private Sample? randomSelectSample;
private int visibleSetsCount; private int visibleSetsCount;
@ -200,7 +198,7 @@ namespace osu.Game.Screens.Select
} }
[Resolved] [Resolved]
private RealmAccess realm { get; set; } private RealmAccess realm { get; set; } = null!;
protected override void LoadComplete() protected override void LoadComplete()
{ {
@ -215,7 +213,7 @@ namespace osu.Game.Screens.Select
subscriptionHiddenBeatmaps = realm.RegisterForNotifications(r => r.All<BeatmapInfo>().Where(b => b.Hidden), beatmapsChanged); subscriptionHiddenBeatmaps = realm.RegisterForNotifications(r => r.All<BeatmapInfo>().Where(b => b.Hidden), beatmapsChanged);
} }
private void deletedBeatmapSetsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error) private void deletedBeatmapSetsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet? changes, Exception? error)
{ {
// If loading test beatmaps, avoid overwriting with realm subscription callbacks. // If loading test beatmaps, avoid overwriting with realm subscription callbacks.
if (loadedTestBeatmaps) if (loadedTestBeatmaps)
@ -228,7 +226,7 @@ namespace osu.Game.Screens.Select
removeBeatmapSet(sender[i].ID); removeBeatmapSet(sender[i].ID);
} }
private void beatmapSetsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error) private void beatmapSetsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet? changes, Exception? error)
{ {
// If loading test beatmaps, avoid overwriting with realm subscription callbacks. // If loading test beatmaps, avoid overwriting with realm subscription callbacks.
if (loadedTestBeatmaps) if (loadedTestBeatmaps)
@ -304,7 +302,7 @@ namespace osu.Game.Screens.Select
} }
} }
private void beatmapsChanged(IRealmCollection<BeatmapInfo> sender, ChangeSet changes, Exception error) private void beatmapsChanged(IRealmCollection<BeatmapInfo> sender, ChangeSet? changes, Exception? error)
{ {
// we only care about actual changes in hidden status. // we only care about actual changes in hidden status.
if (changes == null) if (changes == null)
@ -367,7 +365,7 @@ namespace osu.Game.Screens.Select
// check if we can/need to maintain our current selection. // check if we can/need to maintain our current selection.
if (previouslySelectedID != null) if (previouslySelectedID != null)
select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.BeatmapInfo.ID == previouslySelectedID) ?? newSet); select((CarouselItem?)newSet.Beatmaps.FirstOrDefault(b => b.BeatmapInfo.ID == previouslySelectedID) ?? newSet);
} }
itemsCache.Invalidate(); itemsCache.Invalidate();
@ -384,7 +382,7 @@ namespace osu.Game.Screens.Select
/// <param name="beatmapInfo">The beatmap to select.</param> /// <param name="beatmapInfo">The beatmap to select.</param>
/// <param name="bypassFilters">Whether to select the beatmap even if it is filtered (i.e., not visible on carousel).</param> /// <param name="bypassFilters">Whether to select the beatmap even if it is filtered (i.e., not visible on carousel).</param>
/// <returns>True if a selection was made, False if it wasn't.</returns> /// <returns>True if a selection was made, False if it wasn't.</returns>
public bool SelectBeatmap(BeatmapInfo beatmapInfo, bool bypassFilters = true) public bool SelectBeatmap(BeatmapInfo? beatmapInfo, bool bypassFilters = true)
{ {
// ensure that any pending events from BeatmapManager have been run before attempting a selection. // ensure that any pending events from BeatmapManager have been run before attempting a selection.
Scheduler.Update(); Scheduler.Update();
@ -549,7 +547,7 @@ namespace osu.Game.Screens.Select
randomSelectSample?.Play(); randomSelectSample?.Play();
} }
private void select(CarouselItem item) private void select(CarouselItem? item)
{ {
if (!AllowSelection) if (!AllowSelection)
return; return;
@ -561,7 +559,7 @@ namespace osu.Game.Screens.Select
private FilterCriteria activeCriteria = new FilterCriteria(); private FilterCriteria activeCriteria = new FilterCriteria();
protected ScheduledDelegate PendingFilter; protected ScheduledDelegate? PendingFilter;
public bool AllowSelection = true; public bool AllowSelection = true;
@ -593,7 +591,7 @@ namespace osu.Game.Screens.Select
} }
} }
public void Filter(FilterCriteria newCriteria, bool debounce = true) public void Filter(FilterCriteria? newCriteria, bool debounce = true)
{ {
if (newCriteria != null) if (newCriteria != null)
activeCriteria = newCriteria; activeCriteria = newCriteria;
@ -796,7 +794,7 @@ namespace osu.Game.Screens.Select
return (firstIndex, lastIndex); return (firstIndex, lastIndex);
} }
private CarouselBeatmapSet createCarouselSet(BeatmapSetInfo beatmapSet) private CarouselBeatmapSet? createCarouselSet(BeatmapSetInfo beatmapSet)
{ {
// This can be moved to the realm query if required using: // This can be moved to the realm query if required using:
// .Filter("DeletePending == false && Protected == false && ANY Beatmaps.Hidden == false") // .Filter("DeletePending == false && Protected == false && ANY Beatmaps.Hidden == false")
@ -962,7 +960,7 @@ namespace osu.Game.Screens.Select
/// </summary> /// </summary>
/// <param name="item">The item to be updated.</param> /// <param name="item">The item to be updated.</param>
/// <param name="parent">For nested items, the parent of the item to be updated.</param> /// <param name="parent">For nested items, the parent of the item to be updated.</param>
private void updateItem(DrawableCarouselItem item, DrawableCarouselItem parent = null) private void updateItem(DrawableCarouselItem item, DrawableCarouselItem? parent = null)
{ {
Vector2 posInScroll = Scroll.ScrollContent.ToLocalSpace(item.Header.ScreenSpaceDrawQuad.Centre); Vector2 posInScroll = Scroll.ScrollContent.ToLocalSpace(item.Header.ScreenSpaceDrawQuad.Centre);
float itemDrawY = posInScroll.Y - visibleUpperBound; float itemDrawY = posInScroll.Y - visibleUpperBound;
@ -990,8 +988,7 @@ namespace osu.Game.Screens.Select
/// </summary> /// </summary>
private class CarouselBoundsItem : CarouselItem private class CarouselBoundsItem : CarouselItem
{ {
public override DrawableCarouselItem CreateDrawableRepresentation() => public override DrawableCarouselItem CreateDrawableRepresentation() => throw new NotImplementedException();
throw new NotImplementedException();
} }
private class CarouselRoot : CarouselGroupEagerSelect private class CarouselRoot : CarouselGroupEagerSelect
@ -1017,7 +1014,7 @@ namespace osu.Game.Screens.Select
base.AddItem(i); base.AddItem(i);
} }
public CarouselBeatmapSet RemoveChild(Guid beatmapSetID) public CarouselBeatmapSet? RemoveChild(Guid beatmapSetID)
{ {
if (BeatmapSetsByID.TryGetValue(beatmapSetID, out var carouselBeatmapSet)) if (BeatmapSetsByID.TryGetValue(beatmapSetID, out var carouselBeatmapSet))
{ {
@ -1039,7 +1036,7 @@ namespace osu.Game.Screens.Select
protected override void PerformSelection() protected override void PerformSelection()
{ {
if (LastSelected == null || LastSelected.Filtered.Value) if (LastSelected == null || LastSelected.Filtered.Value)
carousel?.SelectNextRandom(); carousel.SelectNextRandom();
else else
base.PerformSelection(); base.PerformSelection();
} }