mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 09:07:25 +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));
|
public void ShowBeatmap(int beatmapId) => waitForReady(() => beatmapSetOverlay, _ => beatmapSetOverlay.FetchAndShowBeatmap(beatmapId));
|
||||||
|
|
||||||
/// <summary>
|
/// <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.
|
/// 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(BeatmapInfo beatmap)
|
public void PresentBeatmap(BeatmapSetInfo beatmap)
|
||||||
{
|
{
|
||||||
PerformFromScreen(screen =>
|
var databasedSet = beatmap.OnlineBeatmapSetID != null
|
||||||
{
|
? BeatmapManager.QueryBeatmapSet(s => s.OnlineBeatmapSetID == beatmap.OnlineBeatmapSetID)
|
||||||
// we might already be at song select, so a check is required before performing the load to solo.
|
: BeatmapManager.QueryBeatmapSet(s => s.Hash == beatmap.Hash);
|
||||||
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);
|
|
||||||
|
|
||||||
if (databasedSet == null)
|
if (databasedSet == null)
|
||||||
{
|
{
|
||||||
@ -350,8 +327,24 @@ namespace osu.Game
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var first = databasedSet.Beatmaps.Find(b => b.Ruleset.Equals(Ruleset.Value)) ?? databasedSet.Beatmaps.First();
|
PerformFromScreen(screen =>
|
||||||
PresentBeatmap(first);
|
{
|
||||||
|
// 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>
|
/// <summary>
|
||||||
@ -453,7 +446,7 @@ namespace osu.Game
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="action">The action to perform once we are in the correct state.</param>
|
/// <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>
|
/// <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();
|
performFromMainMenuTask?.Cancel();
|
||||||
|
|
||||||
|
@ -592,6 +592,8 @@ namespace osu.Game.Screens.Select
|
|||||||
scrollPositionCache.Invalidate();
|
scrollPositionCache.Invalidate();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
c.Select = () => SelectBeatmap(c.Beatmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
return set;
|
return set;
|
||||||
|
@ -13,6 +13,11 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
{
|
{
|
||||||
public readonly BeatmapInfo Beatmap;
|
public readonly BeatmapInfo Beatmap;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Select this beatmap on the carousel.
|
||||||
|
/// </summary>
|
||||||
|
public Action Select;
|
||||||
|
|
||||||
public CarouselBeatmap(BeatmapInfo beatmap)
|
public CarouselBeatmap(BeatmapInfo beatmap)
|
||||||
{
|
{
|
||||||
Beatmap = beatmap;
|
Beatmap = beatmap;
|
||||||
|
@ -211,9 +211,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
{
|
{
|
||||||
private readonly BindableBool filtered = new BindableBool();
|
private readonly BindableBool filtered = new BindableBool();
|
||||||
|
|
||||||
private OsuGame game;
|
private readonly Action select;
|
||||||
private SongSelect songSelect;
|
|
||||||
private readonly BeatmapInfo info;
|
|
||||||
|
|
||||||
public FilterableDifficultyIcon(CarouselBeatmap item)
|
public FilterableDifficultyIcon(CarouselBeatmap item)
|
||||||
: base(item.Beatmap)
|
: 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.ValueChanged += isFiltered => Schedule(() => this.FadeTo(isFiltered.NewValue ? 0.1f : 1, 100));
|
||||||
filtered.TriggerChange();
|
filtered.TriggerChange();
|
||||||
|
|
||||||
info = item.Beatmap;
|
select = item.Select;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
if (!filtered.Value)
|
select?.Invoke();
|
||||||
{
|
|
||||||
game.PresentBeatmap(info);
|
|
||||||
|
|
||||||
if (e.AltPressed)
|
|
||||||
songSelect?.FinaliseSelection();
|
|
||||||
}
|
|
||||||
|
|
||||||
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
|
||||||
|
Loading…
Reference in New Issue
Block a user