2019-01-24 08:43:03 +00: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 09:19:50 +00:00
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2017-01-09 22:18:47 +00:00
|
|
|
|
using System;
|
2017-01-30 04:35:40 +00:00
|
|
|
|
using System.Collections.Generic;
|
2020-10-13 10:20:46 +00:00
|
|
|
|
using System.Diagnostics;
|
2017-08-31 06:49:56 +00:00
|
|
|
|
using System.Linq;
|
2021-01-05 09:41:45 +00:00
|
|
|
|
using System.Threading.Tasks;
|
2021-01-06 12:15:15 +00:00
|
|
|
|
using JetBrains.Annotations;
|
2017-01-09 22:18:47 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-08-30 11:41:41 +00:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2020-11-26 09:32:43 +00:00
|
|
|
|
using osu.Framework.Utils;
|
2017-12-12 08:48:38 +00:00
|
|
|
|
using osu.Game.Beatmaps;
|
2020-09-02 12:08:31 +00:00
|
|
|
|
using osu.Game.Collections;
|
2017-08-30 11:41:41 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2017-12-21 10:42:44 +00:00
|
|
|
|
using osu.Game.Overlays;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-12-12 08:48:38 +00:00
|
|
|
|
namespace osu.Game.Screens.Select.Carousel
|
2016-10-27 02:55:55 +00:00
|
|
|
|
{
|
2017-12-12 08:48:38 +00:00
|
|
|
|
public class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasContextMenu
|
2017-01-09 22:18:47 +00:00
|
|
|
|
{
|
2020-10-12 03:37:41 +00:00
|
|
|
|
public const float HEIGHT = MAX_HEIGHT;
|
|
|
|
|
|
2017-12-18 02:13:16 +00:00
|
|
|
|
private Action<BeatmapSetInfo> restoreHiddenRequested;
|
2017-12-21 10:42:44 +00:00
|
|
|
|
private Action<int> viewDetails;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-02-14 13:59:51 +00:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
2022-04-18 09:09:14 +00:00
|
|
|
|
private IDialogOverlay dialogOverlay { get; set; }
|
2020-02-14 13:30:27 +00:00
|
|
|
|
|
2020-09-09 06:39:15 +00:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
2020-09-09 06:31:08 +00:00
|
|
|
|
private CollectionManager collectionManager { get; set; }
|
2020-09-02 12:08:31 +00:00
|
|
|
|
|
2020-09-04 18:52:07 +00:00
|
|
|
|
[Resolved(CanBeNull = true)]
|
2020-09-07 12:08:48 +00:00
|
|
|
|
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
|
2020-09-04 18:52:07 +00:00
|
|
|
|
|
2021-05-27 07:58:01 +00:00
|
|
|
|
public IEnumerable<DrawableCarouselItem> DrawableBeatmaps => beatmapContainer?.IsLoaded != true ? Enumerable.Empty<DrawableCarouselItem>() : beatmapContainer.AliveChildren;
|
2020-10-12 05:23:18 +00:00
|
|
|
|
|
2021-01-06 12:15:15 +00:00
|
|
|
|
[CanBeNull]
|
2020-10-12 06:55:47 +00:00
|
|
|
|
private Container<DrawableCarouselItem> beatmapContainer;
|
2020-10-12 05:23:18 +00:00
|
|
|
|
|
2020-10-13 10:20:46 +00:00
|
|
|
|
private BeatmapSetInfo beatmapSet;
|
|
|
|
|
|
2021-01-06 12:15:15 +00:00
|
|
|
|
[CanBeNull]
|
2021-01-05 09:41:45 +00:00
|
|
|
|
private Task beatmapsLoadTask;
|
|
|
|
|
|
2020-10-12 06:36:03 +00:00
|
|
|
|
[Resolved]
|
|
|
|
|
private BeatmapManager manager { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-10-12 09:50:10 +00:00
|
|
|
|
protected override void FreeAfterUse()
|
|
|
|
|
{
|
|
|
|
|
base.FreeAfterUse();
|
2020-10-13 04:25:45 +00:00
|
|
|
|
|
2020-10-12 09:50:10 +00:00
|
|
|
|
Item = null;
|
2020-10-13 07:04:37 +00:00
|
|
|
|
|
2020-10-13 04:25:45 +00:00
|
|
|
|
ClearTransforms();
|
2020-10-12 09:50:10 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-12-21 10:42:44 +00:00
|
|
|
|
[BackgroundDependencyLoader(true)]
|
2020-10-12 06:36:03 +00:00
|
|
|
|
private void load(BeatmapSetOverlay beatmapOverlay)
|
2017-11-21 13:27:56 +00:00
|
|
|
|
{
|
2021-12-14 10:47:11 +00:00
|
|
|
|
restoreHiddenRequested = s =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var b in s.Beatmaps)
|
|
|
|
|
manager.Restore(b);
|
|
|
|
|
};
|
2020-04-16 03:13:26 +00:00
|
|
|
|
|
2017-12-21 10:42:44 +00:00
|
|
|
|
if (beatmapOverlay != null)
|
2018-04-18 07:04:02 +00:00
|
|
|
|
viewDetails = beatmapOverlay.FetchAndShowBeatmapSet;
|
2020-10-12 06:36:03 +00:00
|
|
|
|
}
|
|
|
|
|
|
2020-11-26 09:32:43 +00:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
// 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;
|
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-12 06:36:03 +00:00
|
|
|
|
protected override void UpdateItem()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateItem();
|
|
|
|
|
|
2020-10-13 07:04:37 +00:00
|
|
|
|
Content.Clear();
|
2021-01-05 09:41:45 +00:00
|
|
|
|
|
2020-10-13 07:04:37 +00:00
|
|
|
|
beatmapContainer = null;
|
2021-01-05 09:41:45 +00:00
|
|
|
|
beatmapsLoadTask = null;
|
2020-10-12 09:13:39 +00:00
|
|
|
|
|
2020-10-12 09:50:10 +00:00
|
|
|
|
if (Item == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2020-10-13 10:20:46 +00:00
|
|
|
|
beatmapSet = ((CarouselBeatmapSet)Item).BeatmapSet;
|
|
|
|
|
|
2020-10-13 09:47:35 +00:00
|
|
|
|
DelayedLoadWrapper background;
|
|
|
|
|
DelayedLoadWrapper mainFlow;
|
|
|
|
|
|
2020-10-13 06:19:32 +00:00
|
|
|
|
Header.Children = new Drawable[]
|
2017-01-09 22:18:47 +00:00
|
|
|
|
{
|
2020-10-14 06:10:50 +00:00
|
|
|
|
background = new DelayedLoadWrapper(() => new SetPanelBackground(manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()))
|
2017-01-09 22:18:47 +00:00
|
|
|
|
{
|
2020-10-13 09:47:35 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-12-03 06:13:20 +00:00
|
|
|
|
}, 300)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
|
|
|
|
mainFlow = new DelayedLoadWrapper(() => new SetPanelContent((CarouselBeatmapSet)Item), 100)
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both
|
|
|
|
|
},
|
2020-10-13 09:47:35 +00:00
|
|
|
|
};
|
2020-10-12 06:55:47 +00:00
|
|
|
|
|
2022-02-05 07:12:58 +00:00
|
|
|
|
background.DelayedLoadComplete += fadeContentIn;
|
|
|
|
|
mainFlow.DelayedLoadComplete += fadeContentIn;
|
2022-01-30 05:07:29 +00:00
|
|
|
|
}
|
2020-10-12 05:23:18 +00:00
|
|
|
|
|
2022-02-05 07:12:58 +00:00
|
|
|
|
private void fadeContentIn(Drawable d) => d.FadeInFromZero(750, Easing.OutQuint);
|
|
|
|
|
|
2020-10-12 10:55:33 +00:00
|
|
|
|
protected override void Deselected()
|
2020-10-12 05:23:18 +00:00
|
|
|
|
{
|
2020-10-12 10:55:33 +00:00
|
|
|
|
base.Deselected();
|
2020-10-12 09:19:10 +00:00
|
|
|
|
|
2020-10-13 06:19:32 +00:00
|
|
|
|
MovementContainer.MoveToX(0, 500, Easing.OutExpo);
|
2020-10-12 05:23:18 +00:00
|
|
|
|
|
2021-01-05 09:41:45 +00:00
|
|
|
|
updateBeatmapYPositions();
|
2020-10-12 10:55:33 +00:00
|
|
|
|
}
|
2020-10-12 05:23:18 +00:00
|
|
|
|
|
2020-10-12 10:55:33 +00:00
|
|
|
|
protected override void Selected()
|
|
|
|
|
{
|
|
|
|
|
base.Selected();
|
2020-10-12 06:36:03 +00:00
|
|
|
|
|
2020-10-13 06:19:32 +00:00
|
|
|
|
MovementContainer.MoveToX(-100, 500, Easing.OutExpo);
|
2020-10-12 06:36:03 +00:00
|
|
|
|
|
2020-10-13 08:24:41 +00:00
|
|
|
|
updateBeatmapDifficulties();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateBeatmapDifficulties()
|
|
|
|
|
{
|
|
|
|
|
var carouselBeatmapSet = (CarouselBeatmapSet)Item;
|
|
|
|
|
|
2022-07-21 07:06:06 +00:00
|
|
|
|
var visibleBeatmaps = carouselBeatmapSet.Items.Where(c => c.Visible).ToArray();
|
2020-10-13 08:24:41 +00: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.
|
|
|
|
|
if (beatmapContainer != null && visibleBeatmaps.Length == beatmapContainer.Count && visibleBeatmaps.All(b => beatmapContainer.Any(c => c.Item == b)))
|
2020-10-13 07:04:37 +00:00
|
|
|
|
{
|
2020-10-13 08:24:41 +00:00
|
|
|
|
updateBeatmapYPositions();
|
2020-10-13 07:04:37 +00: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.
|
|
|
|
|
beatmapContainer = new Container<DrawableCarouselItem>
|
|
|
|
|
{
|
|
|
|
|
X = 100,
|
2020-10-13 07:33:37 +00:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2020-10-13 10:17:23 +00:00
|
|
|
|
ChildrenEnumerable = visibleBeatmaps.Select(c => c.CreateDrawableRepresentation())
|
2020-10-13 07:04:37 +00:00
|
|
|
|
};
|
2020-10-12 06:36:03 +00:00
|
|
|
|
|
2021-01-05 09:41:45 +00:00
|
|
|
|
beatmapsLoadTask = LoadComponentAsync(beatmapContainer, loaded =>
|
2020-10-13 07:04:37 +00:00
|
|
|
|
{
|
|
|
|
|
// make sure the pooled target hasn't changed.
|
2020-10-25 11:28:24 +00:00
|
|
|
|
if (beatmapContainer != loaded)
|
2020-10-13 07:04:37 +00:00
|
|
|
|
return;
|
2020-10-12 09:13:39 +00:00
|
|
|
|
|
2020-10-13 07:04:37 +00:00
|
|
|
|
Content.Child = loaded;
|
2020-10-13 08:24:41 +00:00
|
|
|
|
updateBeatmapYPositions();
|
2020-10-13 07:04:37 +00:00
|
|
|
|
});
|
|
|
|
|
}
|
2021-01-05 09:41:45 +00:00
|
|
|
|
}
|
2020-10-13 03:47:12 +00:00
|
|
|
|
|
2021-01-05 09:41:45 +00:00
|
|
|
|
private void updateBeatmapYPositions()
|
|
|
|
|
{
|
2021-01-06 12:06:33 +00:00
|
|
|
|
if (beatmapContainer == null)
|
|
|
|
|
return;
|
|
|
|
|
|
2021-01-05 09:41:45 +00:00
|
|
|
|
if (beatmapsLoadTask == null || !beatmapsLoadTask.IsCompleted)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
float yPos = DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING;
|
2020-10-12 05:23:18 +00:00
|
|
|
|
|
2021-01-05 09:41:45 +00:00
|
|
|
|
bool isSelected = Item.State.Value == CarouselItemState.Selected;
|
|
|
|
|
|
|
|
|
|
foreach (var panel in beatmapContainer.Children)
|
|
|
|
|
{
|
|
|
|
|
if (isSelected)
|
2020-10-12 10:55:33 +00:00
|
|
|
|
{
|
2020-10-13 08:24:41 +00:00
|
|
|
|
panel.MoveToY(yPos, 800, Easing.OutQuint);
|
2020-10-13 09:13:36 +00:00
|
|
|
|
yPos += panel.Item.TotalHeight;
|
2020-10-12 10:55:33 +00:00
|
|
|
|
}
|
2021-01-05 09:41:45 +00:00
|
|
|
|
else
|
|
|
|
|
panel.MoveToY(0, 800, Easing.OutQuint);
|
2020-10-13 07:04:37 +00:00
|
|
|
|
}
|
2016-11-22 10:48:03 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-12-13 03:46:02 +00:00
|
|
|
|
public MenuItem[] ContextMenuItems
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
2020-10-13 10:20:46 +00:00
|
|
|
|
Debug.Assert(beatmapSet != null);
|
|
|
|
|
|
2017-12-13 03:46:02 +00:00
|
|
|
|
List<MenuItem> items = new List<MenuItem>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
|
if (Item.State.Value == CarouselItemState.NotSelected)
|
2017-12-13 03:46:02 +00:00
|
|
|
|
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-12-14 10:47:11 +00:00
|
|
|
|
if (beatmapSet.OnlineID > 0 && viewDetails != null)
|
|
|
|
|
items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => viewDetails(beatmapSet.OnlineID)));
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-09-09 06:39:15 +00:00
|
|
|
|
if (collectionManager != null)
|
|
|
|
|
{
|
|
|
|
|
var collectionItems = collectionManager.Collections.Select(createCollectionMenuItem).ToList();
|
|
|
|
|
if (manageCollectionsDialog != null)
|
|
|
|
|
collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show));
|
2020-09-04 18:52:07 +00:00
|
|
|
|
|
2020-09-09 06:39:15 +00:00
|
|
|
|
items.Add(new OsuMenuItem("Collections") { Items = collectionItems });
|
|
|
|
|
}
|
2020-09-02 12:08:31 +00:00
|
|
|
|
|
2020-09-08 03:04:35 +00:00
|
|
|
|
if (beatmapSet.Beatmaps.Any(b => b.Hidden))
|
|
|
|
|
items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => restoreHiddenRequested(beatmapSet)));
|
|
|
|
|
|
|
|
|
|
if (dialogOverlay != null)
|
2020-09-08 03:18:08 +00:00
|
|
|
|
items.Add(new OsuMenuItem("Delete...", MenuItemType.Destructive, () => dialogOverlay.Push(new BeatmapDeleteDialog(beatmapSet))));
|
2017-12-13 03:46:02 +00:00
|
|
|
|
return items.ToArray();
|
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2020-09-02 12:08:31 +00:00
|
|
|
|
private MenuItem createCollectionMenuItem(BeatmapCollection collection)
|
|
|
|
|
{
|
2020-10-13 10:20:46 +00:00
|
|
|
|
Debug.Assert(beatmapSet != null);
|
|
|
|
|
|
2020-09-02 12:08:31 +00:00
|
|
|
|
TernaryState state;
|
|
|
|
|
|
2022-06-10 05:03:51 +00:00
|
|
|
|
int countExisting = beatmapSet.Beatmaps.Count(b => collection.BeatmapHashes.Contains(b.MD5Hash));
|
2020-09-02 12:08:31 +00:00
|
|
|
|
|
|
|
|
|
if (countExisting == beatmapSet.Beatmaps.Count)
|
|
|
|
|
state = TernaryState.True;
|
|
|
|
|
else if (countExisting > 0)
|
|
|
|
|
state = TernaryState.Indeterminate;
|
|
|
|
|
else
|
|
|
|
|
state = TernaryState.False;
|
|
|
|
|
|
2021-05-20 10:34:53 +00:00
|
|
|
|
return new TernaryStateToggleMenuItem(collection.Name.Value, MenuItemType.Standard, s =>
|
2020-09-02 12:08:31 +00:00
|
|
|
|
{
|
|
|
|
|
foreach (var b in beatmapSet.Beatmaps)
|
|
|
|
|
{
|
|
|
|
|
switch (s)
|
|
|
|
|
{
|
|
|
|
|
case TernaryState.True:
|
2022-06-10 05:03:51 +00:00
|
|
|
|
if (collection.BeatmapHashes.Contains(b.MD5Hash))
|
2020-09-02 12:08:31 +00:00
|
|
|
|
continue;
|
|
|
|
|
|
2022-06-10 05:03:51 +00:00
|
|
|
|
collection.BeatmapHashes.Add(b.MD5Hash);
|
2020-09-02 12:08:31 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case TernaryState.False:
|
2022-06-10 05:03:51 +00:00
|
|
|
|
collection.BeatmapHashes.Remove(b.MD5Hash);
|
2020-09-02 12:08:31 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
{
|
|
|
|
|
State = { Value = state }
|
|
|
|
|
};
|
|
|
|
|
}
|
2016-10-27 02:55:55 +00:00
|
|
|
|
}
|
2017-11-21 15:17:33 +00:00
|
|
|
|
}
|