1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 14:12:55 +08:00

Select specific difficulties using their icons

This commit is contained in:
voidedWarranties 2020-02-11 20:05:26 -08:00
parent 804d210250
commit 2901ec9f26
4 changed files with 37 additions and 4 deletions

View File

@ -53,6 +53,11 @@ namespace osu.Game.Screens.Select
/// </summary>
public Action<BeatmapInfo> SelectionChanged;
/// <summary>
/// Raised when user finalises beatmap selection using <see cref="DrawableCarouselBeatmapSet.FilterableDifficultyIcon"/>
/// </summary>
public Action<BeatmapInfo> SelectionFinalised;
public override bool HandleNonPositionalInput => AllowSelection;
public override bool HandlePositionalInput => AllowSelection;
@ -577,7 +582,7 @@ namespace osu.Game.Screens.Select
b.Metadata = beatmapSet.Metadata;
}
var set = new CarouselBeatmapSet(beatmapSet);
var set = new CarouselBeatmapSet(beatmapSet, this);
foreach (var c in set.Beatmaps)
{

View File

@ -15,8 +15,9 @@ namespace osu.Game.Screens.Select.Carousel
public IEnumerable<CarouselBeatmap> Beatmaps => InternalChildren.OfType<CarouselBeatmap>();
public BeatmapSetInfo BeatmapSet;
public BeatmapCarousel Carousel;
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet)
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet, BeatmapCarousel carousel)
{
BeatmapSet = beatmapSet ?? throw new ArgumentNullException(nameof(beatmapSet));
@ -24,6 +25,8 @@ namespace osu.Game.Screens.Select.Carousel
.Where(b => !b.Hidden)
.Select(b => new CarouselBeatmap(b))
.ForEach(AddChild);
Carousel = carousel;
}
protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmapSet(this);

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
@ -33,10 +34,13 @@ namespace osu.Game.Screens.Select.Carousel
private DialogOverlay dialogOverlay;
private readonly BeatmapSetInfo beatmapSet;
private BeatmapCarousel carousel;
public DrawableCarouselBeatmapSet(CarouselBeatmapSet set)
: base(set)
{
beatmapSet = set.BeatmapSet;
carousel = set.Carousel;
}
[BackgroundDependencyLoader(true)]
@ -117,7 +121,7 @@ namespace osu.Game.Screens.Select.Carousel
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));
: beatmaps.Select(b => new FilterableDifficultyIcon(b, carousel));
}
public MenuItem[] ContextMenuItems
@ -210,12 +214,32 @@ namespace osu.Game.Screens.Select.Carousel
{
private readonly BindableBool filtered = new BindableBool();
public FilterableDifficultyIcon(CarouselBeatmap item)
private BeatmapCarousel carousel;
private BeatmapInfo info;
public FilterableDifficultyIcon(CarouselBeatmap item, BeatmapCarousel carousel)
: base(item.Beatmap)
{
filtered.BindTo(item.Filtered);
filtered.ValueChanged += isFiltered => Schedule(() => this.FadeTo(isFiltered.NewValue ? 0.1f : 1, 100));
filtered.TriggerChange();
this.carousel = carousel;
info = item.Beatmap;
}
protected override bool OnClick(ClickEvent e)
{
if(e.AltPressed || carousel.SelectedBeatmap == info)
{
Schedule(() => carousel.SelectionFinalised?.Invoke(info));
}
else
{
carousel.SelectBeatmap(info);
}
return true;
}
}

View File

@ -155,6 +155,7 @@ namespace osu.Game.Screens.Select
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
SelectionChanged = updateSelectedBeatmap,
SelectionFinalised = beatmapInfo => { FinaliseSelection(beatmapInfo); },
BeatmapSetsChanged = carouselBeatmapsLoaded,
},
}