1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 10:33:01 +08:00

Use dependency loader to get SongSelect instance

This commit is contained in:
voidedWarranties 2020-02-12 19:05:08 -08:00
parent 2901ec9f26
commit b126c00292
4 changed files with 18 additions and 24 deletions

View File

@ -53,11 +53,6 @@ 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;
@ -582,7 +577,7 @@ namespace osu.Game.Screens.Select
b.Metadata = beatmapSet.Metadata;
}
var set = new CarouselBeatmapSet(beatmapSet, this);
var set = new CarouselBeatmapSet(beatmapSet);
foreach (var c in set.Beatmaps)
{

View File

@ -15,9 +15,8 @@ namespace osu.Game.Screens.Select.Carousel
public IEnumerable<CarouselBeatmap> Beatmaps => InternalChildren.OfType<CarouselBeatmap>();
public BeatmapSetInfo BeatmapSet;
public BeatmapCarousel Carousel;
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet, BeatmapCarousel carousel)
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet)
{
BeatmapSet = beatmapSet ?? throw new ArgumentNullException(nameof(beatmapSet));
@ -25,8 +24,6 @@ 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

@ -34,18 +34,20 @@ namespace osu.Game.Screens.Select.Carousel
private DialogOverlay dialogOverlay;
private readonly BeatmapSetInfo beatmapSet;
private BeatmapCarousel carousel;
private SongSelect songSelect;
public DrawableCarouselBeatmapSet(CarouselBeatmapSet set)
: base(set)
{
beatmapSet = set.BeatmapSet;
carousel = set.Carousel;
}
[BackgroundDependencyLoader(true)]
private void load(BeatmapManager manager, BeatmapSetOverlay beatmapOverlay, DialogOverlay overlay)
private void load(SongSelect songSelect, BeatmapManager manager, BeatmapSetOverlay beatmapOverlay, DialogOverlay overlay)
{
if(songSelect != null)
this.songSelect = songSelect;
restoreHiddenRequested = s => s.Beatmaps.ForEach(manager.Restore);
dialogOverlay = overlay;
if (beatmapOverlay != null)
@ -121,7 +123,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, carousel));
: beatmaps.Select(b => new FilterableDifficultyIcon(b, songSelect, songSelect.Carousel));
}
public MenuItem[] ContextMenuItems
@ -214,32 +216,33 @@ namespace osu.Game.Screens.Select.Carousel
{
private readonly BindableBool filtered = new BindableBool();
private SongSelect songSelect;
private BeatmapCarousel carousel;
private BeatmapInfo info;
public FilterableDifficultyIcon(CarouselBeatmap item, BeatmapCarousel carousel)
public FilterableDifficultyIcon(CarouselBeatmap item, SongSelect songSelect, BeatmapCarousel carousel)
: base(item.Beatmap)
{
filtered.BindTo(item.Filtered);
filtered.ValueChanged += isFiltered => Schedule(() => this.FadeTo(isFiltered.NewValue ? 0.1f : 1, 100));
filtered.TriggerChange();
this.songSelect = songSelect;
this.carousel = carousel;
info = item.Beatmap;
}
protected override bool OnClick(ClickEvent e)
{
if(e.AltPressed || carousel.SelectedBeatmap == info)
if(!filtered.Value)
{
Schedule(() => carousel.SelectionFinalised?.Invoke(info));
}
else
{
carousel.SelectBeatmap(info);
carousel?.SelectBeatmap(info);
if (e.AltPressed)
songSelect?.FinaliseSelection();
}
return true;
return base.OnClick(e);
}
}

View File

@ -80,7 +80,7 @@ namespace osu.Game.Screens.Select
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
protected BeatmapCarousel Carousel { get; private set; }
public BeatmapCarousel Carousel { get; private set; }
private BeatmapInfoWedge beatmapInfoWedge;
private DialogOverlay dialogOverlay;
@ -155,7 +155,6 @@ namespace osu.Game.Screens.Select
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Both,
SelectionChanged = updateSelectedBeatmap,
SelectionFinalised = beatmapInfo => { FinaliseSelection(beatmapInfo); },
BeatmapSetsChanged = carouselBeatmapsLoaded,
},
}