mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Use CarouselBeatmap action to select beatmap
This commit is contained in:
parent
ad0de27964
commit
c871f07d2e
@ -311,38 +311,15 @@ namespace osu.Game
|
||||
public void ShowBeatmap(int beatmapId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId));
|
||||
|
||||
/// <summary>
|
||||
/// Present a specific beatmap difficulty at song select immediately.
|
||||
/// Present a beatmap at song select immediately.
|
||||
/// The user should have already requested this interactively.
|
||||
/// </summary>
|
||||
/// <param name="beatmap">The beatmap to select.</param>
|
||||
public void PresentBeatmap(BeatmapInfo beatmap)
|
||||
public void PresentBeatmap(BeatmapSetInfo beatmap)
|
||||
{
|
||||
PerformFromScreen(screen =>
|
||||
{
|
||||
// we might already be at song select, so a check is required before performing the load to solo.
|
||||
if (screen is MainMenu)
|
||||
menuScreen.LoadToSolo();
|
||||
|
||||
// we might even already be at the song
|
||||
if (Beatmap.Value.BeatmapInfo.Hash == beatmap.Hash)
|
||||
return;
|
||||
|
||||
Ruleset.Value = beatmap.Ruleset;
|
||||
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(beatmap);
|
||||
}, 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);
|
||||
var databasedSet = beatmap.OnlineBeatmapSetID != null
|
||||
? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID)
|
||||
: BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash);
|
||||
|
||||
if (databasedSet == null)
|
||||
{
|
||||
@ -350,8 +327,24 @@ namespace osu.Game
|
||||
return;
|
||||
}
|
||||
|
||||
var first = databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First();
|
||||
PresentBeatmap(first);
|
||||
PerformFromScreen(screen =>
|
||||
{
|
||||
// we might already be at song select, so a check is required before performing the load to solo.
|
||||
if (screen is MainMenu)
|
||||
menuScreen.LoadToSolo();
|
||||
|
||||
// we might even already be at the song
|
||||
if (Beatmap.Value.BeatmapSetInfo.Hash == databasedSet.Hash)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// Use first beatmap available for current ruleset, else switch ruleset.
|
||||
var first = databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First();
|
||||
|
||||
Ruleset.Value = first.Ruleset;
|
||||
Beatmap.Value = BeatmapManager.GetWorkingBeatmap(first);
|
||||
}, validScreens: new[] { typeof(PlaySongSelect) });
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@ -453,7 +446,7 @@ namespace osu.Game
|
||||
/// </summary>
|
||||
/// <param name="action">The action to perform once we are in the correct state.</param>
|
||||
/// <param name="validScreens">An optional collection of valid screen types. If any of these screens are already current we can perform the action immediately, else the first valid parent will be made current before performing the action. <see cref="MainMenu"/> is used if not specified.</param>
|
||||
protected void PerformFromScreen(Action<IScreen> action, IEnumerable<Type> validScreens = null)
|
||||
public void PerformFromScreen(Action<IScreen> action, IEnumerable<Type> validScreens = null)
|
||||
{
|
||||
performFromMainMenuTask?.Cancel();
|
||||
|
||||
|
@ -592,6 +592,8 @@ namespace osu.Game.Screens.Select
|
||||
scrollPositionCache.Invalidate();
|
||||
}
|
||||
};
|
||||
|
||||
c.Select = () => SelectBeatmap(c.Beatmap);
|
||||
}
|
||||
|
||||
return set;
|
||||
|
@ -13,6 +13,11 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
public readonly BeatmapInfo Beatmap;
|
||||
|
||||
/// <summary>
|
||||
/// Select this beatmap on the carousel.
|
||||
/// </summary>
|
||||
public Action Select;
|
||||
|
||||
public CarouselBeatmap(BeatmapInfo beatmap)
|
||||
{
|
||||
Beatmap = beatmap;
|
||||
|
@ -211,9 +211,7 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
private readonly BindableBool filtered = new BindableBool();
|
||||
|
||||
private OsuGame game;
|
||||
private SongSelect songSelect;
|
||||
private readonly BeatmapInfo info;
|
||||
private readonly Action select;
|
||||
|
||||
public FilterableDifficultyIcon(CarouselBeatmap item)
|
||||
: base(item.Beatmap)
|
||||
@ -222,30 +220,15 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
filtered.ValueChanged += isFiltered => Schedule(() => this.FadeTo(isFiltered.NewValue ? 0.1f : 1, 100));
|
||||
filtered.TriggerChange();
|
||||
|
||||
info = item.Beatmap;
|
||||
select = item.Select;
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (!filtered.Value)
|
||||
{
|
||||
game.PresentBeatmap(info);
|
||||
|
||||
if (e.AltPressed)
|
||||
songSelect?.FinaliseSelection();
|
||||
}
|
||||
select?.Invoke();
|
||||
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user