2019-01-24 16:43:03 +08:00
|
|
|
|
// 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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-01-10 06:18:47 +08:00
|
|
|
|
using System;
|
2017-01-30 12:35:40 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-10-13 18:20:46 +08:00
|
|
|
|
using System.Diagnostics;
|
2017-08-31 14:49:56 +08:00
|
|
|
|
using System.Linq;
|
2024-01-04 17:48:13 +08:00
|
|
|
|
using System.Threading;
|
2021-01-05 17:41:45 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2017-01-10 06:18:47 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2024-08-20 22:48:11 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2024-01-04 18:13:36 +08:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2017-01-10 06:18:47 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-08-30 19:41:41 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
2024-01-04 18:13:36 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2017-08-30 19:41:41 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-11-26 17:32:43 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2017-12-12 16:48:38 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-09-02 20:08:31 +08:00
|
|
|
|
using osu.Game.Collections;
|
2022-07-27 14:59:36 +08:00
|
|
|
|
using osu.Game.Database;
|
2017-08-30 19:41:41 +08:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2024-11-04 20:44:25 +08:00
|
|
|
|
using osu.Game.Localisation;
|
2024-08-20 22:48:11 +08:00
|
|
|
|
using osu.Game.Online.API;
|
2017-12-21 18:42:44 +08:00
|
|
|
|
using osu.Game.Overlays;
|
2024-08-20 22:48:11 +08:00
|
|
|
|
using osu.Game.Rulesets;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-12 16:48:38 +08:00
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
2016-10-27 10:55:55 +08:00
|
|
|
|
{
|
2017-12-12 16:48:38 +08:00
|
|
|
|
public partial class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasContextMenu
|
2017-01-10 06:18:47 +08:00
|
|
|
|
{
|
2020-10-12 11:37:41 +08:00
|
|
|
|
public const float HEIGHT = MAX_HEIGHT;
|
|
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
|
private Action<BeatmapSetInfo> restoreHiddenRequested = null!;
|
|
|
|
|
private Action<int>? viewDetails;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private IDialogOverlay? dialogOverlay { get; set; }
|
2020-02-14 21:30:27 +08:00
|
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private ManageCollectionsDialog? manageCollectionsDialog { get; set; }
|
2020-09-05 02:52:07 +08:00
|
|
|
|
|
2022-07-27 14:59:36 +08:00
|
|
|
|
[Resolved]
|
2023-01-09 02:02:48 +08:00
|
|
|
|
private RealmAccess realm { get; set; } = null!;
|
2022-07-27 14:59:36 +08:00
|
|
|
|
|
2024-08-22 01:08:01 +08:00
|
|
|
|
[Resolved]
|
2024-08-22 12:43:10 +08:00
|
|
|
|
private IAPIProvider api { get; set; } = null!;
|
2024-08-22 01:08:01 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
2024-08-22 12:43:10 +08:00
|
|
|
|
private OsuGame? game { get; set; }
|
2024-08-22 01:08:01 +08:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private IBindable<RulesetInfo> ruleset { get; set; } = null!;
|
|
|
|
|
|
2024-09-04 14:25:36 +08:00
|
|
|
|
public IReadOnlyList<DrawableCarouselItem> DrawableBeatmaps => beatmapContainer?.IsLoaded != true ? Array.Empty<DrawableCarouselItem>() : beatmapContainer;
|
|
|
|
|
|
|
|
|
|
private Container<DrawableCarouselItem>? beatmapContainer;
|
2020-10-12 13:23:18 +08:00
|
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
|
private BeatmapSetInfo beatmapSet = null!;
|
2020-10-13 18:20:46 +08:00
|
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
|
private Task? beatmapsLoadTask;
|
2021-01-05 17:41:45 +08:00
|
|
|
|
|
2023-12-19 18:58:49 +08:00
|
|
|
|
private MenuItem[]? mainMenuItems;
|
|
|
|
|
|
2024-01-04 17:48:13 +08:00
|
|
|
|
private double timeSinceUnpool;
|
|
|
|
|
|
2020-10-12 14:36:03 +08:00
|
|
|
|
[Resolved]
|
2023-01-09 02:02:48 +08:00
|
|
|
|
private BeatmapManager manager { get; set; } = null!;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2020-10-12 17:50:10 +08:00
|
|
|
|
protected override void FreeAfterUse()
|
|
|
|
|
{
|
|
|
|
|
base.FreeAfterUse();
|
2020-10-13 12:25:45 +08:00
|
|
|
|
|
2020-10-12 17:50:10 +08:00
|
|
|
|
Item = null;
|
2024-01-04 17:48:13 +08:00
|
|
|
|
timeSinceUnpool = 0;
|
2020-10-13 15:04:37 +08:00
|
|
|
|
|
2020-10-13 12:25:45 +08:00
|
|
|
|
ClearTransforms();
|
2020-10-12 17:50:10 +08:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-09 02:02:48 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
2024-08-22 01:08:01 +08:00
|
|
|
|
private void load(BeatmapSetOverlay? beatmapOverlay, SongSelect? songSelect)
|
2017-11-21 21:27:56 +08:00
|
|
|
|
{
|
2023-12-19 18:58:49 +08:00
|
|
|
|
if (songSelect != null)
|
|
|
|
|
mainMenuItems = songSelect.CreateForwardNavigationMenuItemsForBeatmap(() => (((CarouselBeatmapSet)Item!).GetNextToSelect() as CarouselBeatmap)!.BeatmapInfo);
|
|
|
|
|
|
2021-12-14 18:47:11 +08:00
|
|
|
|
restoreHiddenRequested = s =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var b in s.Beatmaps)
|
|
|
|
|
manager.Restore(b);
|
|
|
|
|
};
|
2020-04-16 11:13:26 +08:00
|
|
|
|
|
2017-12-21 18:42:44 +08:00
|
|
|
|
if (beatmapOverlay != null)
|
2018-04-18 15:04:02 +08:00
|
|
|
|
viewDetails = beatmapOverlay.FetchAndShowBeatmapSet;
|
2020-10-12 14:36:03 +08:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-26 17:32:43 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2023-01-10 01:36:55 +08:00
|
|
|
|
Debug.Assert(Item != null);
|
2023-01-10 17:03:17 +08:00
|
|
|
|
|
2020-11-26 17:32:43 +08:00
|
|
|
|
// 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.
|
2023-01-10 01:36:55 +08:00
|
|
|
|
if (!Item.Visible) return;
|
2020-11-26 17:32:43 +08:00
|
|
|
|
|
|
|
|
|
float targetY = Item.CarouselYPosition;
|
|
|
|
|
|
|
|
|
|
if (Precision.AlmostEquals(targetY, Y))
|
|
|
|
|
Y = targetY;
|
|
|
|
|
else
|
|
|
|
|
// algorithm for this is taken from ScrollContainer.
|
|
|
|
|
// while it doesn't necessarily need to match 1:1, as we are emulating scroll in some cases this feels most correct.
|
|
|
|
|
Y = (float)Interpolation.Lerp(targetY, Y, Math.Exp(-0.01 * Time.Elapsed));
|
2024-01-04 17:48:13 +08:00
|
|
|
|
|
|
|
|
|
loadContentIfRequired();
|
2020-11-26 17:32:43 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-04 17:48:13 +08:00
|
|
|
|
private CancellationTokenSource? loadCancellation;
|
|
|
|
|
|
2020-10-12 14:36:03 +08:00
|
|
|
|
protected override void UpdateItem()
|
|
|
|
|
{
|
2024-01-04 17:48:13 +08:00
|
|
|
|
loadCancellation?.Cancel();
|
|
|
|
|
loadCancellation = null;
|
|
|
|
|
|
2020-10-12 14:36:03 +08:00
|
|
|
|
base.UpdateItem();
|
|
|
|
|
|
2020-10-13 15:04:37 +08:00
|
|
|
|
Content.Clear();
|
2024-01-04 17:48:13 +08:00
|
|
|
|
Header.Clear();
|
2021-01-05 17:41:45 +08:00
|
|
|
|
|
2024-09-04 14:25:36 +08:00
|
|
|
|
beatmapContainer = null;
|
2021-01-05 17:41:45 +08:00
|
|
|
|
beatmapsLoadTask = null;
|
2020-10-12 17:13:39 +08:00
|
|
|
|
|
2020-10-12 17:50:10 +08:00
|
|
|
|
if (Item == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-10-13 18:20:46 +08:00
|
|
|
|
beatmapSet = ((CarouselBeatmapSet)Item).BeatmapSet;
|
2022-01-30 13:07:29 +08:00
|
|
|
|
}
|
2020-10-12 13:23:18 +08:00
|
|
|
|
|
2020-10-12 18:55:33 +08:00
|
|
|
|
protected override void Deselected()
|
2020-10-12 13:23:18 +08:00
|
|
|
|
{
|
2020-10-12 18:55:33 +08:00
|
|
|
|
base.Deselected();
|
2020-10-12 17:19:10 +08:00
|
|
|
|
|
2020-10-13 14:19:32 +08:00
|
|
|
|
MovementContainer.MoveToX(0, 500, Easing.OutExpo);
|
2020-10-12 13:23:18 +08:00
|
|
|
|
|
2021-01-05 17:41:45 +08:00
|
|
|
|
updateBeatmapYPositions();
|
2020-10-12 18:55:33 +08:00
|
|
|
|
}
|
2020-10-12 13:23:18 +08:00
|
|
|
|
|
2020-10-12 18:55:33 +08:00
|
|
|
|
protected override void Selected()
|
|
|
|
|
{
|
|
|
|
|
base.Selected();
|
2020-10-12 14:36:03 +08:00
|
|
|
|
|
2020-10-13 14:19:32 +08:00
|
|
|
|
MovementContainer.MoveToX(-100, 500, Easing.OutExpo);
|
2020-10-12 14:36:03 +08:00
|
|
|
|
|
2020-10-13 16:24:41 +08:00
|
|
|
|
updateBeatmapDifficulties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateBeatmapDifficulties()
|
|
|
|
|
{
|
2023-01-10 03:59:28 +08:00
|
|
|
|
Debug.Assert(Item != null);
|
2023-01-10 01:36:55 +08:00
|
|
|
|
|
|
|
|
|
var carouselBeatmapSet = (CarouselBeatmapSet)Item;
|
2020-10-13 16:24:41 +08:00
|
|
|
|
|
2022-07-21 15:06:06 +08:00
|
|
|
|
var visibleBeatmaps = carouselBeatmapSet.Items.Where(c => c.Visible).ToArray();
|
2020-10-13 16:24:41 +08:00
|
|
|
|
|
|
|
|
|
// if we are already displaying all the correct beatmaps, only run animation updates.
|
|
|
|
|
// note that the displayed beatmaps may change due to the applied filter.
|
|
|
|
|
// a future optimisation could add/remove only changed difficulties rather than reinitialise.
|
2024-09-04 14:25:36 +08:00
|
|
|
|
if (beatmapContainer != null && visibleBeatmaps.Length == beatmapContainer.Count && visibleBeatmaps.All(b => beatmapContainer.Any(c => c.Item == b)))
|
2020-10-13 15:04:37 +08:00
|
|
|
|
{
|
2020-10-13 16:24:41 +08:00
|
|
|
|
updateBeatmapYPositions();
|
2020-10-13 15:04:37 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// on selection we show our child beatmaps.
|
|
|
|
|
// for now this is a simple drawable construction each selection.
|
|
|
|
|
// can be improved in the future.
|
2024-09-04 14:25:36 +08:00
|
|
|
|
beatmapContainer = new Container<DrawableCarouselItem>
|
2020-10-13 15:04:37 +08:00
|
|
|
|
{
|
|
|
|
|
X = 100,
|
2020-10-13 15:33:37 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-01-10 01:36:55 +08:00
|
|
|
|
ChildrenEnumerable = visibleBeatmaps.Select(c => c.CreateDrawableRepresentation()!)
|
2020-10-13 15:04:37 +08:00
|
|
|
|
};
|
2020-10-12 14:36:03 +08:00
|
|
|
|
|
2024-09-04 14:25:36 +08:00
|
|
|
|
beatmapsLoadTask = LoadComponentAsync(beatmapContainer, loaded =>
|
2020-10-13 15:04:37 +08:00
|
|
|
|
{
|
|
|
|
|
// make sure the pooled target hasn't changed.
|
2024-09-04 14:25:36 +08:00
|
|
|
|
if (beatmapContainer != loaded)
|
2020-10-13 15:04:37 +08:00
|
|
|
|
return;
|
2020-10-12 17:13:39 +08:00
|
|
|
|
|
2020-10-13 15:04:37 +08:00
|
|
|
|
Content.Child = loaded;
|
2020-10-13 16:24:41 +08:00
|
|
|
|
updateBeatmapYPositions();
|
2020-10-13 15:04:37 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
2024-01-04 17:48:13 +08:00
|
|
|
|
}
|
|
|
|
|
|
2024-01-04 18:13:36 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapCarousel.CarouselScrollContainer scrollContainer { get; set; } = null!;
|
|
|
|
|
|
2024-01-04 17:48:13 +08:00
|
|
|
|
private void loadContentIfRequired()
|
|
|
|
|
{
|
2024-01-04 18:13:36 +08:00
|
|
|
|
Quad containingSsdq = scrollContainer.ScreenSpaceDrawQuad;
|
|
|
|
|
|
2024-01-04 17:48:13 +08:00
|
|
|
|
// Using DelayedLoadWrappers would only allow us to load content when on screen, but we want to preload while off-screen
|
|
|
|
|
// to provide a better user experience.
|
|
|
|
|
|
|
|
|
|
// This is tracking time that this drawable is updating since the last pool.
|
|
|
|
|
// This is intended to provide a debounce so very fast scrolls (from one end to the other of the carousel)
|
|
|
|
|
// don't cause huge overheads.
|
2024-01-04 18:13:36 +08:00
|
|
|
|
//
|
|
|
|
|
// We increase the delay based on distance from centre, so the beatmaps the user is currently looking at load first.
|
|
|
|
|
float timeUpdatingBeforeLoad = 50 + Math.Abs(containingSsdq.Centre.Y - ScreenSpaceDrawQuad.Centre.Y) / containingSsdq.Height * 100;
|
2024-01-04 17:48:13 +08:00
|
|
|
|
|
|
|
|
|
Debug.Assert(Item != null);
|
|
|
|
|
|
2024-01-09 00:08:17 +08:00
|
|
|
|
// A load is already in progress if the cancellation token is non-null.
|
|
|
|
|
if (loadCancellation != null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
timeSinceUnpool += Time.Elapsed;
|
|
|
|
|
|
|
|
|
|
// We only trigger a load after this set has been in an updating state for a set amount of time.
|
|
|
|
|
if (timeSinceUnpool <= timeUpdatingBeforeLoad)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
loadCancellation = new CancellationTokenSource();
|
2024-01-04 17:48:13 +08:00
|
|
|
|
|
2024-01-09 00:08:17 +08:00
|
|
|
|
LoadComponentsAsync(new CompositeDrawable[]
|
|
|
|
|
{
|
2024-01-09 00:08:47 +08:00
|
|
|
|
// Choice of background image matches BSS implementation (always uses the lowest `beatmap_id` from the set).
|
2024-01-09 00:08:17 +08:00
|
|
|
|
new SetPanelBackground(manager.GetWorkingBeatmap(beatmapSet.Beatmaps.MinBy(b => b.OnlineID)))
|
2024-01-04 17:48:13 +08:00
|
|
|
|
{
|
2024-01-09 00:08:17 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
|
|
|
|
new SetPanelContent((CarouselBeatmapSet)Item)
|
2024-01-04 17:48:13 +08:00
|
|
|
|
{
|
2024-01-09 00:08:17 +08:00
|
|
|
|
Depth = float.MinValue,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
}
|
|
|
|
|
}, drawables =>
|
|
|
|
|
{
|
|
|
|
|
Header.AddRange(drawables);
|
|
|
|
|
drawables.ForEach(d => d.FadeInFromZero(150));
|
|
|
|
|
}, loadCancellation.Token);
|
2021-01-05 17:41:45 +08:00
|
|
|
|
}
|
2020-10-13 11:47:12 +08:00
|
|
|
|
|
2021-01-05 17:41:45 +08:00
|
|
|
|
private void updateBeatmapYPositions()
|
|
|
|
|
{
|
2024-09-04 14:25:36 +08:00
|
|
|
|
if (beatmapContainer == null)
|
2021-01-06 20:06:33 +08:00
|
|
|
|
return;
|
|
|
|
|
|
2021-01-05 17:41:45 +08:00
|
|
|
|
if (beatmapsLoadTask == null || !beatmapsLoadTask.IsCompleted)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
float yPos = DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING;
|
2020-10-12 13:23:18 +08:00
|
|
|
|
|
2023-01-10 01:36:55 +08:00
|
|
|
|
bool isSelected = Item?.State.Value == CarouselItemState.Selected;
|
2021-01-05 17:41:45 +08:00
|
|
|
|
|
2024-09-04 14:25:36 +08:00
|
|
|
|
foreach (var panel in beatmapContainer)
|
2021-01-05 17:41:45 +08:00
|
|
|
|
{
|
2023-01-10 03:59:28 +08:00
|
|
|
|
Debug.Assert(panel.Item != null);
|
|
|
|
|
|
2021-01-05 17:41:45 +08:00
|
|
|
|
if (isSelected)
|
2020-10-12 18:55:33 +08:00
|
|
|
|
{
|
2020-10-13 16:24:41 +08:00
|
|
|
|
panel.MoveToY(yPos, 800, Easing.OutQuint);
|
2023-01-10 03:59:28 +08:00
|
|
|
|
yPos += panel.Item.TotalHeight;
|
2020-10-12 18:55:33 +08:00
|
|
|
|
}
|
2021-01-05 17:41:45 +08:00
|
|
|
|
else
|
|
|
|
|
panel.MoveToY(0, 800, Easing.OutQuint);
|
2020-10-13 15:04:37 +08:00
|
|
|
|
}
|
2016-11-22 18:48:03 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-12-13 11:46:02 +08:00
|
|
|
|
public MenuItem[] ContextMenuItems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-10-13 18:20:46 +08:00
|
|
|
|
Debug.Assert(beatmapSet != null);
|
|
|
|
|
|
2017-12-13 11:46:02 +08:00
|
|
|
|
List<MenuItem> items = new List<MenuItem>();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-01-10 01:36:55 +08:00
|
|
|
|
if (Item?.State.Value == CarouselItemState.NotSelected)
|
2017-12-13 11:46:02 +08:00
|
|
|
|
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-19 18:58:49 +08:00
|
|
|
|
if (mainMenuItems != null)
|
|
|
|
|
items.AddRange(mainMenuItems);
|
|
|
|
|
|
2021-12-14 18:47:11 +08:00
|
|
|
|
if (beatmapSet.OnlineID > 0 && viewDetails != null)
|
|
|
|
|
items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => viewDetails(beatmapSet.OnlineID)));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-10-16 14:53:40 +08:00
|
|
|
|
var collectionItems = realm.Realm.All<BeatmapCollection>()
|
|
|
|
|
.OrderBy(c => c.Name)
|
|
|
|
|
.AsEnumerable()
|
|
|
|
|
.Select(createCollectionMenuItem)
|
|
|
|
|
.ToList();
|
|
|
|
|
|
2022-07-27 14:59:36 +08:00
|
|
|
|
if (manageCollectionsDialog != null)
|
|
|
|
|
collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show));
|
2020-09-05 02:52:07 +08:00
|
|
|
|
|
2022-07-27 14:59:36 +08:00
|
|
|
|
items.Add(new OsuMenuItem("Collections") { Items = collectionItems });
|
2020-09-02 20:08:31 +08:00
|
|
|
|
|
2020-09-08 11:04:35 +08:00
|
|
|
|
if (beatmapSet.Beatmaps.Any(b => b.Hidden))
|
|
|
|
|
items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => restoreHiddenRequested(beatmapSet)));
|
|
|
|
|
|
2024-08-22 01:08:01 +08:00
|
|
|
|
if (beatmapSet.GetOnlineURL(api, ruleset.Value) is string url)
|
2024-11-04 20:44:25 +08:00
|
|
|
|
items.Add(new OsuMenuItem(CommonStrings.CopyLink, MenuItemType.Standard, () => game?.CopyUrlToClipboard(url)));
|
2024-08-20 22:48:11 +08:00
|
|
|
|
|
2020-09-08 11:04:35 +08:00
|
|
|
|
if (dialogOverlay != null)
|
2020-09-08 11:18:08 +08:00
|
|
|
|
items.Add(new OsuMenuItem("Delete...", MenuItemType.Destructive, () => dialogOverlay.Push(new BeatmapDeleteDialog(beatmapSet))));
|
2017-12-13 11:46:02 +08:00
|
|
|
|
return items.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-07-27 15:46:23 +08:00
|
|
|
|
private MenuItem createCollectionMenuItem(BeatmapCollection collection)
|
2020-09-02 20:08:31 +08:00
|
|
|
|
{
|
2020-10-13 18:20:46 +08:00
|
|
|
|
Debug.Assert(beatmapSet != null);
|
|
|
|
|
|
2020-09-02 20:08:31 +08:00
|
|
|
|
TernaryState state;
|
|
|
|
|
|
2022-07-27 14:59:36 +08:00
|
|
|
|
int countExisting = beatmapSet.Beatmaps.Count(b => collection.BeatmapMD5Hashes.Contains(b.MD5Hash));
|
2020-09-02 20:08:31 +08:00
|
|
|
|
|
|
|
|
|
if (countExisting == beatmapSet.Beatmaps.Count)
|
|
|
|
|
state = TernaryState.True;
|
|
|
|
|
else if (countExisting > 0)
|
|
|
|
|
state = TernaryState.Indeterminate;
|
|
|
|
|
else
|
|
|
|
|
state = TernaryState.False;
|
|
|
|
|
|
2022-07-27 16:17:43 +08:00
|
|
|
|
var liveCollection = collection.ToLive(realm);
|
|
|
|
|
|
2022-07-27 14:59:36 +08:00
|
|
|
|
return new TernaryStateToggleMenuItem(collection.Name, MenuItemType.Standard, s =>
|
2020-09-02 20:08:31 +08:00
|
|
|
|
{
|
2022-07-27 16:17:43 +08:00
|
|
|
|
liveCollection.PerformWrite(c =>
|
2020-09-02 20:08:31 +08:00
|
|
|
|
{
|
2022-07-27 16:17:43 +08:00
|
|
|
|
foreach (var b in beatmapSet.Beatmaps)
|
2020-09-02 20:08:31 +08:00
|
|
|
|
{
|
2022-07-27 16:17:43 +08:00
|
|
|
|
switch (s)
|
|
|
|
|
{
|
|
|
|
|
case TernaryState.True:
|
|
|
|
|
if (c.BeatmapMD5Hashes.Contains(b.MD5Hash))
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
c.BeatmapMD5Hashes.Add(b.MD5Hash);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TernaryState.False:
|
|
|
|
|
c.BeatmapMD5Hashes.Remove(b.MD5Hash);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-02 20:08:31 +08:00
|
|
|
|
}
|
2022-07-27 16:17:43 +08:00
|
|
|
|
});
|
2020-09-02 20:08:31 +08:00
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
State = { Value = state }
|
|
|
|
|
};
|
|
|
|
|
}
|
2016-10-27 10:55:55 +08:00
|
|
|
|
}
|
2017-11-21 23:17:33 +08:00
|
|
|
|
}
|