1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-23 12:07:25 +08:00
osu-lazer/osu.Game/Screens/Select/Carousel/DrawableCarouselBeatmapSet.cs

285 lines
11 KiB
C#
Raw Normal View History

// 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
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Primitives;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
2020-10-13 12:11:47 +08:00
using osu.Framework.Logging;
2018-04-13 17:19:50 +08:00
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
2020-09-02 20:08:31 +08:00
using osu.Game.Collections;
using osu.Game.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
2018-11-20 15:51:59 +08:00
using osuTK;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Select.Carousel
{
public class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasContextMenu
{
public const float HEIGHT = MAX_HEIGHT;
// TODO: don't do this. need to split out the base class' style so our height isn't fixed to the panel display height (and autosize?).
protected override bool ComputeIsMaskedAway(RectangleF maskingBounds) => false;
2018-04-13 17:19:50 +08:00
private Action<BeatmapSetInfo> restoreHiddenRequested;
private Action<int> viewDetails;
2020-02-14 21:59:51 +08:00
[Resolved(CanBeNull = true)]
2020-02-14 21:14:00 +08:00
private DialogOverlay dialogOverlay { get; set; }
2020-02-14 21:30:27 +08:00
2020-09-09 14:39:15 +08:00
[Resolved(CanBeNull = true)]
private CollectionManager collectionManager { get; set; }
2020-09-02 20:08:31 +08:00
2020-09-05 02:52:07 +08:00
[Resolved(CanBeNull = true)]
2020-09-07 20:08:48 +08:00
private ManageCollectionsDialog manageCollectionsDialog { get; set; }
2020-09-05 02:52:07 +08:00
public override IEnumerable<DrawableCarouselItem> ChildItems => beatmapContainer?.Children ?? base.ChildItems;
2020-10-12 14:36:03 +08:00
private BeatmapSetInfo beatmapSet => (Item as CarouselBeatmapSet)?.BeatmapSet;
2018-04-13 17:19:50 +08:00
private Container<DrawableCarouselItem> beatmapContainer;
2020-10-12 14:36:03 +08:00
[Resolved]
private BeatmapManager manager { get; set; }
2018-04-13 17:19:50 +08:00
protected override void FreeAfterUse()
{
base.FreeAfterUse();
Item = null;
ClearTransforms();
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader(true)]
2020-10-12 14:36:03 +08:00
private void load(BeatmapSetOverlay beatmapOverlay)
2018-04-13 17:19:50 +08:00
{
restoreHiddenRequested = s => s.Beatmaps.ForEach(manager.Restore);
2018-04-13 17:19:50 +08:00
if (beatmapOverlay != null)
viewDetails = beatmapOverlay.FetchAndShowBeatmapSet;
2018-04-13 17:19:50 +08:00
Content.Add(beatmapContainer = new Container<DrawableCarouselItem>
2020-10-12 14:36:03 +08:00
{
X = 50,
Y = MAX_HEIGHT,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
2020-10-12 14:36:03 +08:00
});
}
protected override void UpdateItem()
{
base.UpdateItem();
beatmapContainer.Clear();
if (Item == null)
return;
2020-10-13 12:11:47 +08:00
Logger.Log($"updating item {beatmapSet}");
Header.Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new DelayedLoadUnloadWrapper(() =>
{
2020-10-13 12:11:47 +08:00
Logger.Log($"loaded background item {beatmapSet}");
var background = new PanelBackground(manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()))
2019-03-17 12:43:23 +08:00
{
RelativeSizeAxes = Axes.Both,
};
2019-03-17 12:43:23 +08:00
background.OnLoadComplete += d => d.FadeInFromZero(1000, Easing.OutQuint);
2019-03-17 12:43:23 +08:00
return background;
}, 300, 5000),
new DelayedLoadUnloadWrapper(() =>
2018-04-13 17:19:50 +08:00
{
var mainFlow = new FillFlowContainer
2018-04-13 17:19:50 +08:00
{
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Top = 5, Left = 18, Right = 10, Bottom = 10 },
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
2018-04-13 17:19:50 +08:00
{
new OsuSpriteText
{
Text = new LocalisedString((beatmapSet.Metadata.TitleUnicode, beatmapSet.Metadata.Title)),
Font = OsuFont.GetFont(weight: FontWeight.Bold, size: 22, italics: true),
Shadow = true,
},
new OsuSpriteText
{
Text = new LocalisedString((beatmapSet.Metadata.ArtistUnicode, beatmapSet.Metadata.Artist)),
Font = OsuFont.GetFont(weight: FontWeight.SemiBold, size: 17, italics: true),
Shadow = true,
},
new FillFlowContainer
{
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Margin = new MarginPadding { Top = 5 },
Children = new Drawable[]
{
new BeatmapSetOnlineStatusPill
{
Origin = Anchor.CentreLeft,
Anchor = Anchor.CentreLeft,
Margin = new MarginPadding { Right = 5 },
TextSize = 11,
TextPadding = new MarginPadding { Horizontal = 8, Vertical = 2 },
Status = beatmapSet.Status
},
new FillFlowContainer<DifficultyIcon>
{
AutoSizeAxes = Axes.Both,
Spacing = new Vector2(3),
ChildrenEnumerable = getDifficultyIcons(),
},
}
}
2018-04-13 17:19:50 +08:00
}
};
mainFlow.OnLoadComplete += d => d.FadeInFromZero(1000, Easing.OutQuint);
return mainFlow;
}, 100, 5000)
2018-04-13 17:19:50 +08:00
};
}
protected override void Deselected()
{
base.Deselected();
2020-10-12 17:19:10 +08:00
MovementContainer.MoveToX(0, 500, Easing.OutExpo);
foreach (var beatmap in beatmapContainer)
{
beatmap.MoveToY(0, 800, Easing.OutQuint);
beatmap.FadeOut(80).Expire();
}
}
protected override void Selected()
{
base.Selected();
2020-10-12 14:36:03 +08:00
MovementContainer.MoveToX(-100, 500, Easing.OutExpo);
2020-10-12 14:36:03 +08:00
// on selection we show our child beatmaps.
// for now this is a simple drawable construction each selection.
// can be improved in the future.
var carouselBeatmapSet = (CarouselBeatmapSet)Item;
2020-10-12 14:36:03 +08:00
// ToArray() in this line is required due to framework oversight: https://github.com/ppy/osu-framework/pull/3929
var visibleBeatmaps = carouselBeatmapSet.Children
.Where(c => c.Visible)
.Select(c => c.CreateDrawableRepresentation())
.ToArray();
LoadComponentsAsync(visibleBeatmaps, loaded =>
{
// make sure the pooled target hasn't changed.
if (carouselBeatmapSet != Item)
return;
beatmapContainer.ChildrenEnumerable = loaded;
2020-10-12 19:26:20 +08:00
float yPos = DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING;
foreach (var item in loaded)
{
item.MoveToY(yPos, 800, Easing.OutQuint);
2020-10-12 19:26:20 +08:00
yPos += item.Item.TotalHeight + DrawableCarouselBeatmap.CAROUSEL_BEATMAP_SPACING;
}
});
2018-04-13 17:19:50 +08:00
}
private const int maximum_difficulty_icons = 18;
2019-08-25 11:05:46 +08:00
private IEnumerable<DifficultyIcon> getDifficultyIcons()
{
var beatmaps = ((CarouselBeatmapSet)Item).Beatmaps.ToList();
2019-08-25 11:05:46 +08:00
return beatmaps.Count > maximum_difficulty_icons
? (IEnumerable<DifficultyIcon>)beatmaps.GroupBy(b => b.Beatmap.Ruleset).Select(group => new FilterableGroupedDifficultyIcon(group.ToList(), group.Key))
: beatmaps.Select(b => new FilterableDifficultyIcon(b));
}
2018-04-13 17:19:50 +08:00
public MenuItem[] ContextMenuItems
{
get
{
List<MenuItem> items = new List<MenuItem>();
2019-02-21 17:56:34 +08:00
if (Item.State.Value == CarouselItemState.NotSelected)
2018-04-13 17:19:50 +08:00
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected));
if (beatmapSet.OnlineBeatmapSetID != null && viewDetails != null)
items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => viewDetails(beatmapSet.OnlineBeatmapSetID.Value)));
2018-04-13 17:19:50 +08:00
2020-09-09 14:39:15 +08: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-05 02:52:07 +08:00
2020-09-09 14:39:15 +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)));
if (dialogOverlay != null)
items.Add(new OsuMenuItem("Delete...", MenuItemType.Destructive, () => dialogOverlay.Push(new BeatmapDeleteDialog(beatmapSet))));
2018-04-13 17:19:50 +08:00
return items.ToArray();
}
}
2020-09-02 20:08:31 +08:00
private MenuItem createCollectionMenuItem(BeatmapCollection collection)
{
TernaryState state;
var countExisting = beatmapSet.Beatmaps.Count(b => collection.Beatmaps.Contains(b));
if (countExisting == beatmapSet.Beatmaps.Count)
state = TernaryState.True;
else if (countExisting > 0)
state = TernaryState.Indeterminate;
else
state = TernaryState.False;
2020-09-05 03:43:51 +08:00
return new TernaryStateMenuItem(collection.Name.Value, MenuItemType.Standard, s =>
2020-09-02 20:08:31 +08:00
{
foreach (var b in beatmapSet.Beatmaps)
{
switch (s)
{
case TernaryState.True:
if (collection.Beatmaps.Contains(b))
continue;
collection.Beatmaps.Add(b);
break;
case TernaryState.False:
collection.Beatmaps.Remove(b);
break;
}
}
})
{
State = { Value = state }
};
}
2018-04-13 17:19:50 +08:00
}
}