mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 06:12:58 +08:00
Safer dependency injection and accessibility levels
This commit is contained in:
parent
f8b69fe632
commit
ad0de27964
@ -311,22 +311,12 @@ namespace osu.Game
|
|||||||
public void ShowBeatmap(int beatmapId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId));
|
public void ShowBeatmap(int beatmapId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId));
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Present a beatmap at song select immediately.
|
/// Present a specific beatmap difficulty at song select immediately.
|
||||||
/// The user should have already requested this interactively.
|
/// The user should have already requested this interactively.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="beatmap">The beatmap to select.</param>
|
/// <param name="beatmap">The beatmap to select.</param>
|
||||||
public void PresentBeatmap(BeatmapSetInfo beatmap)
|
public void PresentBeatmap(BeatmapInfo beatmap)
|
||||||
{
|
{
|
||||||
var databasedSet = beatmap.OnlineBeatmapSetID != null
|
|
||||||
? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID)
|
|
||||||
: BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash);
|
|
||||||
|
|
||||||
if (databasedSet == null)
|
|
||||||
{
|
|
||||||
Logger.Log("The requested beatmap could not be loaded.", LoggingTarget.Information);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
PerformFromScreen(screen =>
|
PerformFromScreen(screen =>
|
||||||
{
|
{
|
||||||
// we might already be at song select, so a check is required before performing the load to solo.
|
// we might already be at song select, so a check is required before performing the load to solo.
|
||||||
@ -334,19 +324,36 @@ namespace osu.Game
|
|||||||
menuScreen.LoadToSolo();
|
menuScreen.LoadToSolo();
|
||||||
|
|
||||||
// we might even already be at the song
|
// we might even already be at the song
|
||||||
if (Beatmap.Value.BeatmapSetInfo.Hash == databasedSet.Hash)
|
if (Beatmap.Value.BeatmapInfo.Hash == beatmap.Hash)
|
||||||
{
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
// Use first beatmap available for current ruleset, else switch ruleset.
|
Ruleset.Value = beatmap.Ruleset;
|
||||||
var first = databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First();
|
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(beatmap);
|
||||||
|
|
||||||
Ruleset.Value = first.Ruleset;
|
|
||||||
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(first);
|
|
||||||
}, validScreens: new[] { typeof(PlaySongSelect) });
|
}, validScreens: new[] { typeof(PlaySongSelect) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// <see cref="PresentBeatmap(BeatmapInfo)"/>
|
||||||
|
/// Instead of selecting a specific difficulty, this will select the first difficulty of the current ruleset in a beatmapset,
|
||||||
|
/// or the first difficulty of the set if there is none.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="beatmapSet">The beatmapset to select.</param>
|
||||||
|
public void PresentBeatmap(BeatmapSetInfo beatmapSet)
|
||||||
|
{
|
||||||
|
var databasedSet = beatmapSet.OnlineBeatmapSetID != null
|
||||||
|
? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmapSet.OnlineBeatmapSetID)
|
||||||
|
: BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmapSet.Hash);
|
||||||
|
|
||||||
|
if (databasedSet == null)
|
||||||
|
{
|
||||||
|
Logger.Log("The requested beatmap could not be loaded.", LoggingTarget.Information);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var first = databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First();
|
||||||
|
PresentBeatmap(first);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Present a score's replay immediately.
|
/// Present a score's replay immediately.
|
||||||
/// The user should have already requested this interactively.
|
/// The user should have already requested this interactively.
|
||||||
|
@ -34,8 +34,6 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
private DialogOverlay dialogOverlay;
|
private DialogOverlay dialogOverlay;
|
||||||
private readonly BeatmapSetInfo beatmapSet;
|
private readonly BeatmapSetInfo beatmapSet;
|
||||||
|
|
||||||
private SongSelect songSelect;
|
|
||||||
|
|
||||||
public DrawableCarouselBeatmapSet(CarouselBeatmapSet set)
|
public DrawableCarouselBeatmapSet(CarouselBeatmapSet set)
|
||||||
: base(set)
|
: base(set)
|
||||||
{
|
{
|
||||||
@ -43,11 +41,8 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(SongSelect songSelect, BeatmapManager manager, BeatmapSetOverlay beatmapOverlay, DialogOverlay overlay)
|
private void load(BeatmapManager manager, BeatmapSetOverlay beatmapOverlay, DialogOverlay overlay)
|
||||||
{
|
{
|
||||||
if (songSelect != null)
|
|
||||||
this.songSelect = songSelect;
|
|
||||||
|
|
||||||
restoreHiddenRequested = s => s.Beatmaps.ForEach(manager.Restore);
|
restoreHiddenRequested = s => s.Beatmaps.ForEach(manager.Restore);
|
||||||
dialogOverlay = overlay;
|
dialogOverlay = overlay;
|
||||||
if (beatmapOverlay != null)
|
if (beatmapOverlay != null)
|
||||||
@ -123,7 +118,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
return beatmaps.Count > maximum_difficulty_icons
|
return beatmaps.Count > maximum_difficulty_icons
|
||||||
? (IEnumerable<DifficultyIcon>)beatmaps.GroupBy(b => b.Beatmap.Ruleset).Select(group => new FilterableGroupedDifficultyIcon(group.ToList(), group.Key))
|
? (IEnumerable<DifficultyIcon>)beatmaps.GroupBy(b => b.Beatmap.Ruleset).Select(group => new FilterableGroupedDifficultyIcon(group.ToList(), group.Key))
|
||||||
: beatmaps.Select(b => new FilterableDifficultyIcon(b, songSelect));
|
: beatmaps.Select(b => new FilterableDifficultyIcon(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
public MenuItem[] ContextMenuItems
|
public MenuItem[] ContextMenuItems
|
||||||
@ -216,17 +211,17 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
{
|
{
|
||||||
private readonly BindableBool filtered = new BindableBool();
|
private readonly BindableBool filtered = new BindableBool();
|
||||||
|
|
||||||
private readonly SongSelect songSelect;
|
private OsuGame game;
|
||||||
|
private SongSelect songSelect;
|
||||||
private readonly BeatmapInfo info;
|
private readonly BeatmapInfo info;
|
||||||
|
|
||||||
public FilterableDifficultyIcon(CarouselBeatmap item, SongSelect songSelect)
|
public FilterableDifficultyIcon(CarouselBeatmap item)
|
||||||
: base(item.Beatmap)
|
: base(item.Beatmap)
|
||||||
{
|
{
|
||||||
filtered.BindTo(item.Filtered);
|
filtered.BindTo(item.Filtered);
|
||||||
filtered.ValueChanged += isFiltered => Schedule(() => this.FadeTo(isFiltered.NewValue ? 0.1f : 1, 100));
|
filtered.ValueChanged += isFiltered => Schedule(() => this.FadeTo(isFiltered.NewValue ? 0.1f : 1, 100));
|
||||||
filtered.TriggerChange();
|
filtered.TriggerChange();
|
||||||
|
|
||||||
this.songSelect = songSelect;
|
|
||||||
info = item.Beatmap;
|
info = item.Beatmap;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -234,7 +229,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
{
|
{
|
||||||
if (!filtered.Value)
|
if (!filtered.Value)
|
||||||
{
|
{
|
||||||
songSelect?.Carousel.SelectBeatmap(info);
|
game.PresentBeatmap(info);
|
||||||
|
|
||||||
if (e.AltPressed)
|
if (e.AltPressed)
|
||||||
songSelect?.FinaliseSelection();
|
songSelect?.FinaliseSelection();
|
||||||
@ -242,6 +237,15 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
return base.OnClick(e);
|
return base.OnClick(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuGame game, SongSelect songSelect)
|
||||||
|
{
|
||||||
|
this.game = game;
|
||||||
|
|
||||||
|
if (songSelect != null)
|
||||||
|
this.songSelect = songSelect;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public class FilterableGroupedDifficultyIcon : GroupedDifficultyIcon
|
public class FilterableGroupedDifficultyIcon : GroupedDifficultyIcon
|
||||||
|
@ -80,7 +80,7 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
|
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap(Beatmap.Value);
|
||||||
|
|
||||||
public BeatmapCarousel Carousel { get; private set; }
|
protected BeatmapCarousel Carousel { get; private set; }
|
||||||
|
|
||||||
private BeatmapInfoWedge beatmapInfoWedge;
|
private BeatmapInfoWedge beatmapInfoWedge;
|
||||||
private DialogOverlay dialogOverlay;
|
private DialogOverlay dialogOverlay;
|
||||||
|
Loading…
Reference in New Issue
Block a user