mirror of
https://github.com/ppy/osu.git
synced 2026-05-21 18:50:16 +08:00
Disallow hiding beatmap difficulties if only one difficulty remains
This commit is contained in:
@@ -309,6 +309,24 @@ namespace osu.Game.Tests.Visual.SongSelectV2
|
||||
checkMatchedBeatmaps(3);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestCantHideAllBeatmaps()
|
||||
{
|
||||
LoadSongSelect();
|
||||
ImportBeatmapForRuleset(0);
|
||||
|
||||
checkMatchedBeatmaps(3);
|
||||
|
||||
AddStep("hide selected", () => Beatmaps.Hide(Beatmap.Value.BeatmapInfo));
|
||||
checkMatchedBeatmaps(2);
|
||||
|
||||
AddStep("hide selected", () => Beatmaps.Hide(Beatmap.Value.BeatmapInfo));
|
||||
checkMatchedBeatmaps(1);
|
||||
|
||||
AddAssert("hide fails", () => Beatmaps.Hide(Beatmap.Value.BeatmapInfo), () => Is.False);
|
||||
checkMatchedBeatmaps(1);
|
||||
}
|
||||
|
||||
private NoResultsPlaceholder? getPlaceholder() => SongSelect.ChildrenOfType<NoResultsPlaceholder>().FirstOrDefault();
|
||||
|
||||
private void checkMatchedBeatmaps(int expected) => AddUntilStep($"{expected} matching shown", () => Carousel.MatchedBeatmapsCount, () => Is.EqualTo(expected));
|
||||
|
||||
@@ -218,24 +218,37 @@ namespace osu.Game.Beatmaps
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Delete a beatmap difficulty.
|
||||
/// Hide a beatmap difficulty.
|
||||
/// Will fail if all difficulties are about to be hidden.
|
||||
/// </summary>
|
||||
/// <param name="beatmapInfo">The beatmap difficulty to hide.</param>
|
||||
public void Hide(BeatmapInfo beatmapInfo)
|
||||
public bool Hide(BeatmapInfo beatmapInfo)
|
||||
{
|
||||
Realm.Run(r =>
|
||||
return Realm.Run(r =>
|
||||
{
|
||||
using (var transaction = r.BeginWrite())
|
||||
{
|
||||
if (!beatmapInfo.IsManaged)
|
||||
beatmapInfo = r.Find<BeatmapInfo>(beatmapInfo.ID)!;
|
||||
|
||||
if (!CanHide(beatmapInfo))
|
||||
return false;
|
||||
|
||||
beatmapInfo.Hidden = true;
|
||||
transaction.Commit();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public bool CanHide(BeatmapInfo beatmapInfo) => Realm.Run(r =>
|
||||
{
|
||||
if (!beatmapInfo.IsManaged)
|
||||
beatmapInfo = r.Find<BeatmapInfo>(beatmapInfo.ID)!;
|
||||
|
||||
return beatmapInfo.BeatmapSet!.Beatmaps.Count(b => !b.Hidden) > 1;
|
||||
});
|
||||
|
||||
/// <summary>
|
||||
/// Restore a beatmap difficulty.
|
||||
/// </summary>
|
||||
|
||||
@@ -112,7 +112,7 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
}
|
||||
|
||||
if (manager != null)
|
||||
hideRequested = manager.Hide;
|
||||
hideRequested = b => manager.Hide(b);
|
||||
|
||||
Header.Children = new Drawable[]
|
||||
{
|
||||
|
||||
@@ -84,7 +84,9 @@ namespace osu.Game.Screens.SelectV2
|
||||
{
|
||||
Icon = FontAwesome.Solid.Eraser
|
||||
};
|
||||
yield return new OsuMenuItem(WebCommonStrings.ButtonsHide.ToSentence(), MenuItemType.Destructive, () => beatmaps.Hide(beatmap));
|
||||
|
||||
if (beatmaps.CanHide(beatmap))
|
||||
yield return new OsuMenuItem(WebCommonStrings.ButtonsHide.ToSentence(), MenuItemType.Destructive, () => beatmaps.Hide(beatmap));
|
||||
}
|
||||
|
||||
protected override void OnStart()
|
||||
|
||||
Reference in New Issue
Block a user