Merge remote-tracking branch 'upstream/master' into carousel

This commit is contained in:
OliBomby
2023-01-16 00:27:56 +01:00
653 changed files with 7369 additions and 4031 deletions

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using System.Linq;
using osu.Game.Beatmaps;

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
@ -33,7 +31,7 @@ namespace osu.Game.Screens.Select.Carousel
public BeatmapSetInfo BeatmapSet;
public Func<IEnumerable<BeatmapInfo>, BeatmapInfo> GetRecommendedBeatmap;
public Func<IEnumerable<BeatmapInfo>, BeatmapInfo?>? GetRecommendedBeatmap;
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet)
{
@ -47,7 +45,7 @@ namespace osu.Game.Screens.Select.Carousel
.ForEach(AddItem);
}
protected override CarouselItem GetNextToSelect()
protected override CarouselItem? GetNextToSelect()
{
if (LastSelected == null || LastSelected.Filtered.Value)
{
@ -132,8 +130,8 @@ namespace osu.Game.Screens.Select.Carousel
bool filtered = Items.All(i => i.Filtered.Value);
filtered |= criteria.Sort == SortMode.DateRanked && BeatmapSet?.DateRanked == null;
filtered |= criteria.Sort == SortMode.DateSubmitted && BeatmapSet?.DateSubmitted == null;
filtered |= criteria.Sort == SortMode.DateRanked && BeatmapSet.DateRanked == null;
filtered |= criteria.Sort == SortMode.DateSubmitted && BeatmapSet.DateSubmitted == null;
Filtered.Value = filtered;
}

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
@ -26,7 +24,7 @@ namespace osu.Game.Screens.Select.Carousel
/// <summary>
/// The last selected item.
/// </summary>
protected CarouselItem LastSelected { get; private set; }
protected CarouselItem? LastSelected { get; private set; }
/// <summary>
/// We need to keep track of the index for cases where the selection is removed but we want to select a new item based on its old location.
@ -112,7 +110,7 @@ namespace osu.Game.Screens.Select.Carousel
/// Finds the item this group would select next if it attempted selection
/// </summary>
/// <returns>An unfiltered item nearest to the last selected one or null if all items are filtered</returns>
protected virtual CarouselItem GetNextToSelect()
protected virtual CarouselItem? GetNextToSelect()
{
if (Items.Count == 0)
return null;
@ -141,7 +139,7 @@ namespace osu.Game.Screens.Select.Carousel
protected virtual void PerformSelection()
{
CarouselItem nextToSelect = GetNextToSelect();
CarouselItem? nextToSelect = GetNextToSelect();
if (nextToSelect != null)
nextToSelect.State.Value = CarouselItemState.Selected;
@ -149,7 +147,7 @@ namespace osu.Game.Screens.Select.Carousel
updateSelected(null);
}
private void updateSelected(CarouselItem newSelection)
private void updateSelected(CarouselItem? newSelection)
{
if (newSelection != null)
LastSelected = newSelection;

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
@ -95,9 +93,9 @@ namespace osu.Game.Screens.Select.Carousel
public partial class HoverLayer : HoverSampleDebounceComponent
{
private Sample sampleHover;
private Sample? sampleHover;
private Box box;
private Box box = null!;
public HoverLayer()
{

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using osu.Framework.Bindables;
@ -43,7 +41,7 @@ namespace osu.Game.Screens.Select.Carousel
/// <summary>
/// Create a fresh drawable version of this item.
/// </summary>
public abstract DrawableCarouselItem CreateDrawableRepresentation();
public abstract DrawableCarouselItem? CreateDrawableRepresentation();
public virtual void Filter(FilterCriteria criteria)
{
@ -51,7 +49,12 @@ namespace osu.Game.Screens.Select.Carousel
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => ItemID.CompareTo(other.ItemID);
public int CompareTo(CarouselItem other) => CarouselYPosition.CompareTo(other.CarouselYPosition);
public int CompareTo(CarouselItem? other)
{
if (other == null) return 1;
return CarouselYPosition.CompareTo(other.CarouselYPosition);
}
}
public enum CarouselItemState

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
@ -47,32 +45,32 @@ namespace osu.Game.Screens.Select.Carousel
private readonly BeatmapInfo beatmapInfo;
private Sprite background;
private Sprite background = null!;
private MenuItem[] customMenuItems;
private Action<BeatmapInfo> selectRequested;
private Action<BeatmapInfo> hideRequested;
private Triangles triangles;
private Triangles triangles = null!;
private StarCounter starCounter;
private DifficultyIcon difficultyIcon;
[Resolved(CanBeNull = true)]
private BeatmapSetOverlay beatmapOverlay { get; set; }
private StarCounter starCounter = null!;
private DifficultyIcon difficultyIcon = null!;
[Resolved]
private BeatmapDifficultyCache difficultyCache { get; set; }
[Resolved(CanBeNull = true)]
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
private BeatmapSetOverlay? beatmapOverlay { get; set; }
[Resolved]
private RealmAccess realm { get; set; }
private BeatmapDifficultyCache difficultyCache { get; set; } = null!;
private IBindable<StarDifficulty?> starDifficultyBindable;
private CancellationTokenSource starDifficultyCancellationSource;
[Resolved]
private ManageCollectionsDialog? manageCollectionsDialog { get; set; }
[Resolved]
private RealmAccess realm { get; set; } = null!;
private IBindable<StarDifficulty?> starDifficultyBindable = null!;
private CancellationTokenSource? starDifficultyCancellationSource;
public DrawableCarouselBeatmap(CarouselBeatmap panel)
{
@ -80,8 +78,8 @@ namespace osu.Game.Screens.Select.Carousel
Item = panel;
}
[BackgroundDependencyLoader(true)]
private void load(BeatmapManager manager, SongSelect songSelect)
[BackgroundDependencyLoader]
private void load(BeatmapManager? manager, SongSelect? songSelect)
{
Header.Height = height;
@ -202,13 +200,13 @@ namespace osu.Game.Screens.Select.Carousel
protected override void ApplyState()
{
if (Item.State.Value != CarouselItemState.Collapsed && Alpha == 0)
if (Item?.State.Value != CarouselItemState.Collapsed && Alpha == 0)
starCounter.ReplayAnimation();
starDifficultyCancellationSource?.Cancel();
// Only compute difficulty when the item is visible.
if (Item.State.Value != CarouselItemState.Collapsed)
if (Item?.State.Value != CarouselItemState.Collapsed)
{
// We've potentially cancelled the computation above so a new bindable is required.
starDifficultyBindable = difficultyCache.GetBindableDifficulty(beatmapInfo, (starDifficultyCancellationSource = new CancellationTokenSource()).Token);

View File

@ -1,14 +1,11 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -27,30 +24,28 @@ namespace osu.Game.Screens.Select.Carousel
{
public const float HEIGHT = MAX_HEIGHT;
private Action<BeatmapSetInfo> restoreHiddenRequested;
private Action<int> viewDetails;
[Resolved(CanBeNull = true)]
private IDialogOverlay dialogOverlay { get; set; }
[Resolved(CanBeNull = true)]
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
private Action<BeatmapSetInfo> restoreHiddenRequested = null!;
private Action<int>? viewDetails;
[Resolved]
private RealmAccess realm { get; set; }
private IDialogOverlay? dialogOverlay { get; set; }
[Resolved]
private ManageCollectionsDialog? manageCollectionsDialog { get; set; }
[Resolved]
private RealmAccess realm { get; set; } = null!;
public IEnumerable<DrawableCarouselItem> DrawableBeatmaps => beatmapContainer?.IsLoaded != true ? Enumerable.Empty<DrawableCarouselItem>() : beatmapContainer.AliveChildren;
[CanBeNull]
private Container<DrawableCarouselItem> beatmapContainer;
private Container<DrawableCarouselItem>? beatmapContainer;
private BeatmapSetInfo beatmapSet;
private BeatmapSetInfo beatmapSet = null!;
[CanBeNull]
private Task beatmapsLoadTask;
private Task? beatmapsLoadTask;
[Resolved]
private BeatmapManager manager { get; set; }
private BeatmapManager manager { get; set; } = null!;
protected override void FreeAfterUse()
{
@ -61,8 +56,8 @@ namespace osu.Game.Screens.Select.Carousel
ClearTransforms();
}
[BackgroundDependencyLoader(true)]
private void load(BeatmapSetOverlay beatmapOverlay)
[BackgroundDependencyLoader]
private void load(BeatmapSetOverlay? beatmapOverlay)
{
restoreHiddenRequested = s =>
{
@ -78,10 +73,11 @@ namespace osu.Game.Screens.Select.Carousel
{
base.Update();
Debug.Assert(Item != null);
// position updates should not occur if the item is filtered away.
// this avoids panels flying across the screen only to be eventually off-screen or faded out.
if (!Item.Visible)
return;
if (!Item.Visible) return;
float targetY = Item.CarouselYPosition;
@ -151,6 +147,8 @@ namespace osu.Game.Screens.Select.Carousel
private void updateBeatmapDifficulties()
{
Debug.Assert(Item != null);
var carouselBeatmapSet = (CarouselBeatmapSet)Item;
var visibleBeatmaps = carouselBeatmapSet.Items.Where(c => c.Visible).ToArray();
@ -171,7 +169,7 @@ namespace osu.Game.Screens.Select.Carousel
{
X = 100,
RelativeSizeAxes = Axes.Both,
ChildrenEnumerable = visibleBeatmaps.Select(c => c.CreateDrawableRepresentation())
ChildrenEnumerable = visibleBeatmaps.Select(c => c.CreateDrawableRepresentation()!)
};
beatmapsLoadTask = LoadComponentAsync(beatmapContainer, loaded =>
@ -196,10 +194,12 @@ namespace osu.Game.Screens.Select.Carousel
float yPos = DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING;
bool isSelected = Item.State.Value == CarouselItemState.Selected;
bool isSelected = Item?.State.Value == CarouselItemState.Selected;
foreach (var panel in beatmapContainer.Children)
{
Debug.Assert(panel.Item != null);
if (isSelected)
{
panel.MoveToY(yPos, 800, Easing.OutQuint);
@ -218,7 +218,7 @@ namespace osu.Game.Screens.Select.Carousel
List<MenuItem> items = new List<MenuItem>();
if (Item.State.Value == CarouselItemState.NotSelected)
if (Item?.State.Value == CarouselItemState.NotSelected)
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected));
if (beatmapSet.OnlineID > 0 && viewDetails != null)

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System.Diagnostics;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
@ -34,9 +32,9 @@ namespace osu.Game.Screens.Select.Carousel
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) =>
Header.ReceivePositionalInputAt(screenSpacePos);
private CarouselItem item;
private CarouselItem? item;
public CarouselItem Item
public CarouselItem? Item
{
get => item;
set
@ -105,7 +103,7 @@ namespace osu.Game.Screens.Select.Carousel
protected virtual void UpdateItem()
{
if (item == null)
if (Item == null)
return;
Scheduler.AddOnce(ApplyState);
@ -128,12 +126,12 @@ namespace osu.Game.Screens.Select.Carousel
protected virtual void ApplyState()
{
Debug.Assert(Item != null);
// Use the fact that we know the precise height of the item from the model to avoid the need for AutoSize overhead.
// Additionally, AutoSize doesn't work well due to content starting off-screen and being masked away.
Height = Item.TotalHeight;
Debug.Assert(Item != null);
switch (Item.State.Value)
{
case CarouselItemState.NotSelected:
@ -162,6 +160,8 @@ namespace osu.Game.Screens.Select.Carousel
protected override bool OnClick(ClickEvent e)
{
Debug.Assert(Item != null);
Item.State.Value = CarouselItemState.Selected;
return true;
}

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Input.Events;

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Graphics;

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
@ -23,6 +21,8 @@ namespace osu.Game.Screens.Select.Carousel
private readonly CarouselBeatmapSet carouselSet;
private FillFlowContainer<DifficultyIcon> iconFlow = null!;
public SetPanelContent(CarouselBeatmapSet carouselSet)
{
this.carouselSet = carouselSet;
@ -84,13 +84,12 @@ namespace osu.Game.Screens.Select.Carousel
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Status = beatmapSet.Status
},
new FillFlowContainer<DifficultyIcon>
iconFlow = new FillFlowContainer<DifficultyIcon>
{
AutoSizeAxes = Axes.Both,
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Spacing = new Vector2(3),
ChildrenEnumerable = getDifficultyIcons(),
},
}
}
@ -98,6 +97,12 @@ namespace osu.Game.Screens.Select.Carousel
};
}
protected override void LoadComplete()
{
base.LoadComplete();
iconFlow.ChildrenEnumerable = getDifficultyIcons();
}
private const int maximum_difficulty_icons = 18;
private IEnumerable<DifficultyIcon> getDifficultyIcons()